Skip to content

Commit

Permalink
guess what, legacy issues again.
Browse files Browse the repository at this point in the history
  • Loading branch information
YouHaveTrouble committed May 16, 2021
1 parent 66e6bff commit 12ed028
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>eu.endermite</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>1.7.4</version>
<version>1.7.5</version>
<packaging>jar</packaging>

<name>CommandWhitelist</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<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();
}

}
});
}
}

0 comments on commit 12ed028

Please sign in to comment.