mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-12 06:26:57 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b7d7646641 | |||
| 697a5e5720 | |||
| 598756fec0 | |||
| 95ea1d8319 | |||
| 9da87b2769 | |||
| 12ed028460 | |||
| 66e6bff28e | |||
| 332e98f4a0 |
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>eu.endermite</groupId>
|
||||
<artifactId>CommandWhitelist</artifactId>
|
||||
<version>1.7.3</version>
|
||||
<version>1.7.8</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>CommandWhitelist</name>
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
Command Whitelist is a plugin that allows you to control
|
||||
precisely what commands players can see and use.
|
||||
|
||||
<img src="https://img.shields.io/bstats/servers/8705?label=Spigot%20servers%20using%20CommandWhitelist&style=for-the-badge">
|
||||
<img src="https://img.shields.io/bstats/servers/8704?label=Proxy%20servers%20using%20CommandWhitelist&style=for-the-badge">
|
||||
|
||||
<h3>Plugin Features</h3>
|
||||
|
||||
<ul>
|
||||
|
||||
@@ -63,4 +63,11 @@ public class CommandsList {
|
||||
return last;
|
||||
}
|
||||
|
||||
public static String getCommandLabel(String cmd) {
|
||||
String[] parts = cmd.split(" ");
|
||||
if (parts[0].startsWith("/"))
|
||||
parts[0] = parts[0].substring(1);
|
||||
return parts[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+30
@@ -19,6 +19,7 @@ public class LegacyPlayerTabChatCompleteListener {
|
||||
public static void protocol(CommandWhitelist plugin) {
|
||||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
tabCompleteServerBound(protocolManager, plugin);
|
||||
tabCompleteClientBound(protocolManager, plugin);
|
||||
}
|
||||
|
||||
public static void tabCompleteServerBound(ProtocolManager protocolManager, Plugin plugin) {
|
||||
@@ -52,4 +53,33 @@ public class LegacyPlayerTabChatCompleteListener {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void tabCompleteClientBound(ProtocolManager protocolManager, Plugin plugin) {
|
||||
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.TAB_COMPLETE) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
try {
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission("commandwhitelist.bypass")) {
|
||||
return;
|
||||
}
|
||||
PacketContainer packet = event.getPacket();
|
||||
String command = packet.getSpecificModifier(String.class).read(0);
|
||||
String label = CommandsList.getCommandLabel(command);
|
||||
List<String> commandList = CommandsList.getCommands(player);
|
||||
if (command.equals("/"))
|
||||
return;
|
||||
for (String cmd : commandList) {
|
||||
if (cmd.startsWith("/"+label+" "))
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -13,22 +13,23 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PlayerCommandPreProcessListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission("commandwhitelist.bypass"))
|
||||
return;
|
||||
String command = event.getMessage().toLowerCase();
|
||||
if (command.startsWith("/"))
|
||||
command = command.substring(1);
|
||||
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
|
||||
if (!player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
||||
continue;
|
||||
for (String comm : s.getValue()) {
|
||||
comm = comm.toLowerCase();
|
||||
if (command.equalsIgnoreCase("/" + comm) || command.startsWith("/" + comm + " ")) {
|
||||
String rawCmd = event.getMessage();
|
||||
if (command.equalsIgnoreCase(comm) || command.startsWith(comm + " ")) {
|
||||
List<String> bannedSubCommands = CommandsList.getSuggestions(player);
|
||||
for (String bannedSubCommand : bannedSubCommands) {
|
||||
if (rawCmd.startsWith("/"+bannedSubCommand)) {
|
||||
if (command.startsWith(bannedSubCommand)) {
|
||||
event.setCancelled(true);
|
||||
ConfigCache config = CommandWhitelist.getConfigCache();
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getSubCommandDenied())));
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import org.bukkit.event.Listener;
|
||||
import java.util.*;
|
||||
|
||||
public class PlayerCommandSendListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandSendEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission("commandwhitelist.bypass"))
|
||||
|
||||
+10
-2
@@ -14,14 +14,22 @@ public class TabCompleteBlockerListener implements Listener {
|
||||
return;
|
||||
Player player = (Player) event.getSender();
|
||||
String buffer = event.getBuffer();
|
||||
String cmd = buffer.replace(CommandsList.getLastArgument(buffer), "");
|
||||
|
||||
List<String> blockedCommands = CommandsList.getSuggestions(player);
|
||||
List<String> suggestions = event.getCompletions();
|
||||
|
||||
for (String s : blockedCommands) {
|
||||
String slast = CommandsList.getLastArgument(s);
|
||||
String scommand = s.replace(slast, "");
|
||||
cmd = cmd.replace(CommandsList.getLastArgument(cmd), "");
|
||||
String[] cmdSplit = buffer.split(" ");
|
||||
StringBuilder cmdBuilder = new StringBuilder();
|
||||
for (int i = 0; i <= cmdSplit.length-1; i++)
|
||||
cmdBuilder.append(cmdSplit[i]).append(" ");
|
||||
|
||||
String cmd = cmdBuilder.toString();
|
||||
if (cmd.startsWith("/"+scommand)) {
|
||||
// This sometimes throws exceptions. No clue why, it just does. try/catch is the only fix.
|
||||
// Probably happening when plugin adds suggestions in this event on the same priority - not confirmed.
|
||||
try {
|
||||
while (suggestions.contains(slast))
|
||||
suggestions.remove(slast);
|
||||
|
||||
Reference in New Issue
Block a user