mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-12 06:26:57 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 12ed028460 | |||
| 66e6bff28e | |||
| 332e98f4a0 | |||
| 2085002c59 |
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>eu.endermite</groupId>
|
<groupId>eu.endermite</groupId>
|
||||||
<artifactId>CommandWhitelist</artifactId>
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
<version>1.7.2</version>
|
<version>1.7.5</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>CommandWhitelist</name>
|
<name>CommandWhitelist</name>
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
Command Whitelist is a plugin that allows you to control
|
Command Whitelist is a plugin that allows you to control
|
||||||
precisely what commands players can see and use.
|
precisely what commands players can see and use.
|
||||||
|
|
||||||
|
<img src="https://img.shields.io/bstats/servers/8705?label=Spigot%20servers%20using%20CommandWhitelist&style=for-the-badge">
|
||||||
|
<img src="https://img.shields.io/bstats/servers/8704?label=Proxy%20servers%20using%20CommandWhitelist&style=for-the-badge">
|
||||||
|
|
||||||
<h3>Plugin Features</h3>
|
<h3>Plugin Features</h3>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
|
|||||||
@@ -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];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,9 +28,10 @@ public class CommandWhitelist extends JavaPlugin {
|
|||||||
|
|
||||||
Plugin protocollib = getServer().getPluginManager().getPlugin("ProtocolLib");
|
Plugin protocollib = getServer().getPluginManager().getPlugin("ProtocolLib");
|
||||||
|
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcessListener(), this);
|
||||||
if (!isLegacy) {
|
if (!isLegacy) {
|
||||||
if (!getConfigCache().isUseProtocolLib() || protocollib == null || !protocollib.isEnabled()) {
|
if (!getConfigCache().isUseProtocolLib() || protocollib == null || !protocollib.isEnabled()) {
|
||||||
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcessListener(), this);
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), this);
|
getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), this);
|
||||||
} else {
|
} else {
|
||||||
PacketCommandSendListener.protocol(this);
|
PacketCommandSendListener.protocol(this);
|
||||||
|
|||||||
+30
@@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -19,16 +19,18 @@ public class PlayerCommandPreProcessListener implements Listener {
|
|||||||
if (player.hasPermission("commandwhitelist.bypass"))
|
if (player.hasPermission("commandwhitelist.bypass"))
|
||||||
return;
|
return;
|
||||||
String command = event.getMessage().toLowerCase();
|
String command = event.getMessage().toLowerCase();
|
||||||
|
if (command.startsWith("/"))
|
||||||
|
command = command.substring(1);
|
||||||
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
|
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
|
||||||
if (!player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
if (!player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
||||||
continue;
|
continue;
|
||||||
for (String comm : s.getValue()) {
|
for (String comm : s.getValue()) {
|
||||||
comm = comm.toLowerCase();
|
comm = comm.toLowerCase();
|
||||||
if (command.equalsIgnoreCase("/" + comm) || command.startsWith("/" + comm + " ")) {
|
if (command.equalsIgnoreCase(comm) || command.startsWith(comm + " ")) {
|
||||||
String rawCmd = event.getMessage();
|
String rawCmd = event.getMessage();
|
||||||
List<String> bannedSubCommands = CommandsList.getSuggestions(player);
|
List<String> bannedSubCommands = CommandsList.getSuggestions(player);
|
||||||
for (String bannedSubCommand : bannedSubCommands) {
|
for (String bannedSubCommand : bannedSubCommands) {
|
||||||
if (rawCmd.startsWith("/"+bannedSubCommand)) {
|
if (rawCmd.startsWith(bannedSubCommand)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
ConfigCache config = CommandWhitelist.getConfigCache();
|
ConfigCache config = CommandWhitelist.getConfigCache();
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getSubCommandDenied())));
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getSubCommandDenied())));
|
||||||
|
|||||||
Reference in New Issue
Block a user