Skip to content

Commit

Permalink
fixed command list filter for legacy mode
Browse files Browse the repository at this point in the history
  • Loading branch information
YouHaveTrouble committed Oct 21, 2020
1 parent 7591d00 commit 411aba6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 37 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.1-R0.1-SNAPSHOT</version>
<version>1.16.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -92,7 +92,7 @@
<dependency>
<groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-api</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.4-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
import org.bukkit.plugin.Plugin;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

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 All @@ -35,9 +33,7 @@ public void onPacketSending(PacketEvent event) {
}
PacketContainer packet = event.getPacket();
String[] message = packet.getSpecificModifier(String[].class).read(0);

List<String> commandList = CommandsList.getCommands(player);

List<String> finalList = new ArrayList<>();
int components = 0;
for (String cmd : message) {
Expand All @@ -62,35 +58,4 @@ 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);

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))
return;
else if (command.startsWith("/" + comm + " ")) {
return;
}
}
}
event.setCancelled(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}

0 comments on commit 411aba6

Please sign in to comment.