mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-12 14:36:56 +00:00
fixed command list filter for legacy mode
This commit is contained in:
@@ -80,7 +80,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.16.1-R0.1-SNAPSHOT</version>
|
<version>1.16.3-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -92,7 +92,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.waterfallmc</groupId>
|
<groupId>io.github.waterfallmc</groupId>
|
||||||
<artifactId>waterfall-api</artifactId>
|
<artifactId>waterfall-api</artifactId>
|
||||||
<version>1.15-SNAPSHOT</version>
|
<version>1.16-R0.4-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
-35
@@ -13,14 +13,12 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class LegacyPlayerTabChatCompleteListener {
|
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) {
|
||||||
@@ -35,9 +33,7 @@ public class LegacyPlayerTabChatCompleteListener {
|
|||||||
}
|
}
|
||||||
PacketContainer packet = event.getPacket();
|
PacketContainer packet = event.getPacket();
|
||||||
String[] message = packet.getSpecificModifier(String[].class).read(0);
|
String[] message = packet.getSpecificModifier(String[].class).read(0);
|
||||||
|
|
||||||
List<String> commandList = CommandsList.getCommands(player);
|
List<String> commandList = CommandsList.getCommands(player);
|
||||||
|
|
||||||
List<String> finalList = new ArrayList<>();
|
List<String> finalList = new ArrayList<>();
|
||||||
int components = 0;
|
int components = 0;
|
||||||
for (String cmd : message) {
|
for (String cmd : message) {
|
||||||
@@ -62,35 +58,4 @@ 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);
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user