mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-12 06:26:57 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e823aa91aa | |||
| eb0f53f19d |
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>eu.endermite</groupId>
|
<groupId>eu.endermite</groupId>
|
||||||
<artifactId>CommandWhitelist</artifactId>
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
<version>1.6.0-BETA</version>
|
<version>1.7.0</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>CommandWhitelist</name>
|
<name>CommandWhitelist</name>
|
||||||
|
|||||||
@@ -2,15 +2,13 @@ package eu.endermite.commandwhitelist.spigot;
|
|||||||
|
|
||||||
import eu.endermite.commandwhitelist.spigot.command.MainCommand;
|
import eu.endermite.commandwhitelist.spigot.command.MainCommand;
|
||||||
import eu.endermite.commandwhitelist.spigot.config.ConfigCache;
|
import eu.endermite.commandwhitelist.spigot.config.ConfigCache;
|
||||||
import eu.endermite.commandwhitelist.spigot.listeners.LegacyPlayerTabChatCompleteListener;
|
import eu.endermite.commandwhitelist.spigot.listeners.*;
|
||||||
import eu.endermite.commandwhitelist.spigot.listeners.PlayerCommandPreProcessListener;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.listeners.PlayerCommandSendListener;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.listeners.TabCompleteBlockerListener;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.metrics.BukkitMetrics;
|
import eu.endermite.commandwhitelist.spigot.metrics.BukkitMetrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class CommandWhitelist extends JavaPlugin {
|
public class CommandWhitelist extends JavaPlugin {
|
||||||
@@ -28,12 +26,20 @@ public class CommandWhitelist extends JavaPlugin {
|
|||||||
|
|
||||||
reloadPluginConfig();
|
reloadPluginConfig();
|
||||||
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcessListener(), this);
|
Plugin protocollib = getServer().getPluginManager().getPlugin("ProtocolLib");
|
||||||
if (!isLegacy) {
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), this);
|
getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), this);
|
||||||
|
if (!isLegacy) {
|
||||||
|
if (!getConfigCache().isUseProtocolLib() || protocollib == null || !protocollib.isEnabled()) {
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcessListener(), this);
|
||||||
|
} else {
|
||||||
|
PacketCommandSendListener.protocol(this);
|
||||||
|
getLogger().info(ChatColor.AQUA+"Using ProtocolLib for command filter!");
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
getLogger().info(ChatColor.AQUA+"Running in legacy mode...");
|
getLogger().info(ChatColor.AQUA+"Running in legacy mode...");
|
||||||
if (getServer().getPluginManager().getPlugin("ProtocolLib") != null) {
|
if (protocollib != null) {
|
||||||
LegacyPlayerTabChatCompleteListener.protocol(this);
|
LegacyPlayerTabChatCompleteListener.protocol(this);
|
||||||
} else {
|
} else {
|
||||||
getLogger().info(ChatColor.YELLOW+"ProtocolLib is required for tab completion blocking!");
|
getLogger().info(ChatColor.YELLOW+"ProtocolLib is required for tab completion blocking!");
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public class ConfigCache {
|
|||||||
private final String prefix, commandDenied, noPermission, noSubCommand, configReloaded, whitelistedCommand,
|
private final String prefix, commandDenied, noPermission, noSubCommand, configReloaded, whitelistedCommand,
|
||||||
removedWhitelistedCommand, noSuchGroup, subCommandDenied;
|
removedWhitelistedCommand, noSuchGroup, subCommandDenied;
|
||||||
private final List<String> commandDeniedList;
|
private final List<String> commandDeniedList;
|
||||||
|
private boolean useProtocolLib;
|
||||||
|
|
||||||
public ConfigCache(FileConfiguration config) {
|
public ConfigCache(FileConfiguration config) {
|
||||||
|
|
||||||
@@ -33,6 +34,8 @@ public class ConfigCache {
|
|||||||
removedWhitelistedCommand = config.getString("messages.removed-from-whitelist", "&eRemoved command &6%s &efrom permission &6%s");
|
removedWhitelistedCommand = config.getString("messages.removed-from-whitelist", "&eRemoved command &6%s &efrom permission &6%s");
|
||||||
noSuchGroup = config.getString("messages.group-doesnt-exist", "&cGroup %s doesn't exist");
|
noSuchGroup = config.getString("messages.group-doesnt-exist", "&cGroup %s doesn't exist");
|
||||||
|
|
||||||
|
useProtocolLib = config.getBoolean("use-protocollib-to-detect-commands", false);
|
||||||
|
|
||||||
Set<String> perms = config.getConfigurationSection("commands").getKeys(false);
|
Set<String> perms = config.getConfigurationSection("commands").getKeys(false);
|
||||||
for (String s : perms) {
|
for (String s : perms) {
|
||||||
this.permList.put(s, config.getStringList("commands."+s));
|
this.permList.put(s, config.getStringList("commands."+s));
|
||||||
@@ -99,4 +102,7 @@ public class ConfigCache {
|
|||||||
public String getSubCommandDenied() {
|
public String getSubCommandDenied() {
|
||||||
return subCommandDenied;
|
return subCommandDenied;
|
||||||
}
|
}
|
||||||
|
public boolean isUseProtocolLib() {
|
||||||
|
return useProtocolLib;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+68
@@ -0,0 +1,68 @@
|
|||||||
|
package eu.endermite.commandwhitelist.spigot.listeners;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
|
import com.comphenix.protocol.ProtocolManager;
|
||||||
|
import com.comphenix.protocol.events.ListenerPriority;
|
||||||
|
import com.comphenix.protocol.events.PacketAdapter;
|
||||||
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
|
import eu.endermite.commandwhitelist.api.CommandsList;
|
||||||
|
import eu.endermite.commandwhitelist.api.RandomStuff;
|
||||||
|
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
|
||||||
|
import eu.endermite.commandwhitelist.spigot.config.ConfigCache;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PacketCommandSendListener {
|
||||||
|
|
||||||
|
public static void protocol(CommandWhitelist plugin) {
|
||||||
|
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||||
|
commandExecListener(protocolManager, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void commandExecListener(ProtocolManager protocolManager, Plugin plugin) {
|
||||||
|
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.CHAT) {
|
||||||
|
@Override
|
||||||
|
public void onPacketReceiving(PacketEvent event) {
|
||||||
|
PacketContainer packet = event.getPacket();
|
||||||
|
String string = packet.getStrings().read(0);
|
||||||
|
if (!string.startsWith("/"))
|
||||||
|
return;
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (player.hasPermission("commandwhitelist.bypass"))
|
||||||
|
return;
|
||||||
|
String cmd = string.replace("/", "");
|
||||||
|
String[] split = cmd.split("\\s+");
|
||||||
|
String command = split[0].toLowerCase();
|
||||||
|
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) || command.startsWith(comm + " ")) {
|
||||||
|
List<String> bannedSubCommands = CommandsList.getSuggestions(player);
|
||||||
|
for (String bannedSubCommand : bannedSubCommands) {
|
||||||
|
if (cmd.startsWith(bannedSubCommand)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
ConfigCache config = CommandWhitelist.getConfigCache();
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getSubCommandDenied())));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
ConfigCache config = CommandWhitelist.getConfigCache();
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getCommandDenied())));
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,11 @@ messages:
|
|||||||
removed-from-whitelist: "&eRemoved command &6%s &efrom permission &6%s"
|
removed-from-whitelist: "&eRemoved command &6%s &efrom permission &6%s"
|
||||||
group-doesnt-exist: "&cGroup doesn't exist or error occured"
|
group-doesnt-exist: "&cGroup doesn't exist or error occured"
|
||||||
|
|
||||||
|
# To cover the 1% of plugins that don't register their commands and/or aliases properly.
|
||||||
|
# Do not enable if you don't have issues with aliased commands.
|
||||||
|
# This requires server restart to take effect.
|
||||||
|
use-protocollib-to-detect-commands: false
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
# Permissions that control what commands players can use
|
# Permissions that control what commands players can use
|
||||||
# you can add unlimited amount of whitelists
|
# you can add unlimited amount of whitelists
|
||||||
|
|||||||
Reference in New Issue
Block a user