From 8c90e54511d0f54bcc796092c274fb43f3db0181 Mon Sep 17 00:00:00 2001 From: Chip <65827213+ChipmunkMC@users.noreply.github.com> Date: Thu, 8 Dec 2022 12:09:06 -0500 Subject: [PATCH] Prevent muted players from using chat commands By chat commands I mean commands for chatting --- pom.xml | 12 ++++++++++++ .../kaboom/extras/helpers/PlayerMuting.java | 16 ++++++++++++++++ .../extras/modules/server/ServerCommand.java | 19 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 src/main/java/pw/kaboom/extras/helpers/PlayerMuting.java diff --git a/pom.xml b/pom.xml index 8519cc4..72ee08c 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,13 @@ 1.18.2-R0.1-SNAPSHOT provided + + + net.essentialsx + EssentialsX + 2.19.7 + provided + @@ -25,6 +32,11 @@ papermc https://repo.papermc.io/repository/maven-public/ + + + essentialsx + https://repo.essentialsx.net/releases/ + diff --git a/src/main/java/pw/kaboom/extras/helpers/PlayerMuting.java b/src/main/java/pw/kaboom/extras/helpers/PlayerMuting.java new file mode 100644 index 0000000..f4041ae --- /dev/null +++ b/src/main/java/pw/kaboom/extras/helpers/PlayerMuting.java @@ -0,0 +1,16 @@ +package pw.kaboom.extras.helpers; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import com.earth2me.essentials.IEssentials; + +public class PlayerMuting { + private static IEssentials essentials = (IEssentials) Bukkit.getServer() + .getPluginManager() + .getPlugin("Essentials"); + + public static boolean isMuted(Player player) { + return essentials != null && essentials.getUser(player).isMuted(); + } +} diff --git a/src/main/java/pw/kaboom/extras/modules/server/ServerCommand.java b/src/main/java/pw/kaboom/extras/modules/server/ServerCommand.java index 03a5dbc..4210484 100644 --- a/src/main/java/pw/kaboom/extras/modules/server/ServerCommand.java +++ b/src/main/java/pw/kaboom/extras/modules/server/ServerCommand.java @@ -14,6 +14,9 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.server.ServerCommandEvent; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.entity.Player; + +import pw.kaboom.extras.helpers.PlayerMuting; import pw.kaboom.extras.Main; @@ -200,6 +203,22 @@ public final class ServerCommand implements Listener { return "cancel"; } break; + case "/minecraft:say": + case "/minecraft:me": + case "/minecraft:tell": + case "/minecraft:msg": + case "/minecraft:w": + case "/say": + case "/me": + case "/tell": + case "/msg": + case "/w": + if (isConsoleCommand) break; + Player player = (Player) sender; + + if (!player.isOp() && PlayerMuting.isMuted(player)) { + return "cancel"; + } default: break; }