Prevent muted players from using chat commands

By chat commands I mean commands for chatting
This commit is contained in:
Chipmunk 2022-12-08 12:09:06 -05:00
parent baddda61aa
commit 8c90e54511
3 changed files with 47 additions and 0 deletions

12
pom.xml
View file

@ -18,6 +18,13 @@
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.essentialsx</groupId>
<artifactId>EssentialsX</artifactId>
<version>2.19.7</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
@ -25,6 +32,11 @@
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>essentialsx</id>
<url>https://repo.essentialsx.net/releases/</url>
</repository>
</repositories>
<build>

View file

@ -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();
}
}

View file

@ -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;
}