Compare commits

...

5 Commits

Author SHA1 Message Date
YouHaveTrouble 697a5e5720 priority shift 2021-06-02 21:22:12 +02:00
YouHaveTrouble 598756fec0 version bump 2021-06-02 16:00:36 +02:00
YouHaveTrouble 95ea1d8319 this probably needs to be handled anyway
ignoreCancelled seems to introduce the issue of completions not being filtered in some cases, and it shouldn't cause problems by running anyway
2021-06-02 15:52:13 +02:00
YouHaveTrouble 9da87b2769 fixed missing ignoreCancelled 2021-05-22 15:53:11 +02:00
YouHaveTrouble 12ed028460 guess what, legacy issues again. 2021-05-16 19:17:45 +02:00
5 changed files with 40 additions and 3 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>eu.endermite</groupId> <groupId>eu.endermite</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>1.7.4</version> <version>1.7.7</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>CommandWhitelist</name> <name>CommandWhitelist</name>
@@ -63,4 +63,11 @@ public class CommandsList {
return last; 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];
}
} }
@@ -19,6 +19,7 @@ public class LegacyPlayerTabChatCompleteListener {
public static void protocol(CommandWhitelist plugin) { public static void protocol(CommandWhitelist plugin) {
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
tabCompleteServerBound(protocolManager, plugin); tabCompleteServerBound(protocolManager, plugin);
tabCompleteClientBound(protocolManager, plugin);
} }
public static void tabCompleteServerBound(ProtocolManager protocolManager, Plugin 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();
}
}
});
}
} }
@@ -13,7 +13,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public class PlayerCommandPreProcessListener implements Listener { public class PlayerCommandPreProcessListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) { public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player.hasPermission("commandwhitelist.bypass")) if (player.hasPermission("commandwhitelist.bypass"))
@@ -8,7 +8,7 @@ import org.bukkit.event.Listener;
import java.util.*; import java.util.*;
public class PlayerCommandSendListener implements Listener { public class PlayerCommandSendListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.NORMAL)
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandSendEvent event) { public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandSendEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player.hasPermission("commandwhitelist.bypass")) if (player.hasPermission("commandwhitelist.bypass"))