diff --git a/pom.xml b/pom.xml index 0b02e8e..138ec0a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ eu.endermite CommandWhitelist - 1.7.4 + 1.7.5 jar CommandWhitelist diff --git a/src/main/java/eu/endermite/commandwhitelist/api/CommandsList.java b/src/main/java/eu/endermite/commandwhitelist/api/CommandsList.java index 8cd5b06..1f4c09f 100644 --- a/src/main/java/eu/endermite/commandwhitelist/api/CommandsList.java +++ b/src/main/java/eu/endermite/commandwhitelist/api/CommandsList.java @@ -63,4 +63,11 @@ public static String getLastArgument(String cmd) { 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]; + } + } diff --git a/src/main/java/eu/endermite/commandwhitelist/spigot/listeners/LegacyPlayerTabChatCompleteListener.java b/src/main/java/eu/endermite/commandwhitelist/spigot/listeners/LegacyPlayerTabChatCompleteListener.java index 2c5977f..698070b 100644 --- a/src/main/java/eu/endermite/commandwhitelist/spigot/listeners/LegacyPlayerTabChatCompleteListener.java +++ b/src/main/java/eu/endermite/commandwhitelist/spigot/listeners/LegacyPlayerTabChatCompleteListener.java @@ -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 void onPacketSending(PacketEvent event) { } }); } + + 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 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(); + } + + } + }); + } }