From de4124aa7382cbbc9af8196f7bc13cdc44dabdd4 Mon Sep 17 00:00:00 2001 From: youhavetrouble Date: Thu, 8 Jun 2023 01:04:18 +0200 Subject: [PATCH] the great cleanup --- CommandWhitelistBukkit/.gitignore | 113 ------------ CommandWhitelistBukkit/pom.xml | 129 -------------- .../bukkit/CommandWhitelistBukkit.java | 166 ------------------ .../bukkit/command/BukkitCommandExecutor.java | 96 ---------- .../AsyncTabCompleteBlockerListener.java | 31 ---- .../PlayerCommandPreProcessListener.java | 48 ----- .../listeners/PlayerCommandSendListener.java | 20 --- .../listeners/TabCompleteBlockerListener.java | 36 ---- .../PacketCommandPreProcessListener.java | 60 ------- CommandWhitelistCommon/pom.xml | 108 ------------ .../commandwhitelist/common/CWGroup.java | 65 ------- CommandWhitelistVelocity/.gitignore | 113 ------------ CommandWhitelistVelocity/pom.xml | 111 ------------ .../velocity/CommandWhitelistVelocity.java | 145 --------------- .../velocity/command/VelocityMainCommand.java | 143 --------------- .../src/main/resources/velocity-plugin.json | 9 - CommandWhitelistWaterfall/.gitignore | 113 ------------ CommandWhitelistWaterfall/pom.xml | 113 ------------ .../waterfall/CommandWhitelistWaterfall.java | 132 -------------- .../waterfall/command/BungeeMainCommand.java | 106 ----------- .../listeners/BungeeChatEventListener.java | 48 ----- .../listeners/BungeeTabcompleteListener.java | 25 --- .../WaterfallDefineCommandsListener.java | 28 --- .../src/main/resources/bungee.yml | 5 - pom.xml | 82 +++++++-- readme.md | 3 +- .../bukkit/CommandWhitelistBukkit.java | 69 ++++++++ .../bukkit/listeners/CommandSendListener.java | 37 ++++ .../common/CWCommandEntry.java | 67 +++++++ .../commandwhitelist/common/CWGroup.java | 46 +++++ .../commandwhitelist/common/CWPermission.java | 11 +- .../commandwhitelist/common/CommandUtil.java | 42 ++--- .../commandwhitelist/common/ConfigCache.java | 29 ++- .../common/commands/CWCommand.java | 12 +- .../common/commands/CWCommandInterface.java | 13 ++ src/main/resources/config.yml | 5 + .../src => src}/main/resources/plugin.yml | 12 +- 37 files changed, 346 insertions(+), 2045 deletions(-) delete mode 100644 CommandWhitelistBukkit/.gitignore delete mode 100644 CommandWhitelistBukkit/pom.xml delete mode 100644 CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/CommandWhitelistBukkit.java delete mode 100644 CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/command/BukkitCommandExecutor.java delete mode 100644 CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/AsyncTabCompleteBlockerListener.java delete mode 100644 CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/PlayerCommandPreProcessListener.java delete mode 100644 CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/PlayerCommandSendListener.java delete mode 100644 CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/TabCompleteBlockerListener.java delete mode 100644 CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/protocollib/PacketCommandPreProcessListener.java delete mode 100644 CommandWhitelistCommon/pom.xml delete mode 100644 CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/CWGroup.java delete mode 100644 CommandWhitelistVelocity/.gitignore delete mode 100644 CommandWhitelistVelocity/pom.xml delete mode 100644 CommandWhitelistVelocity/src/main/java/eu/endermite/commandwhitelist/velocity/CommandWhitelistVelocity.java delete mode 100644 CommandWhitelistVelocity/src/main/java/eu/endermite/commandwhitelist/velocity/command/VelocityMainCommand.java delete mode 100644 CommandWhitelistVelocity/src/main/resources/velocity-plugin.json delete mode 100644 CommandWhitelistWaterfall/.gitignore delete mode 100644 CommandWhitelistWaterfall/pom.xml delete mode 100644 CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/CommandWhitelistWaterfall.java delete mode 100644 CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/command/BungeeMainCommand.java delete mode 100644 CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/listeners/BungeeChatEventListener.java delete mode 100644 CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/listeners/BungeeTabcompleteListener.java delete mode 100644 CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/listeners/WaterfallDefineCommandsListener.java delete mode 100644 CommandWhitelistWaterfall/src/main/resources/bungee.yml create mode 100644 src/main/java/me/youhavetrouble/commandwhitelist/bukkit/CommandWhitelistBukkit.java create mode 100644 src/main/java/me/youhavetrouble/commandwhitelist/bukkit/listeners/CommandSendListener.java create mode 100644 src/main/java/me/youhavetrouble/commandwhitelist/common/CWCommandEntry.java create mode 100644 src/main/java/me/youhavetrouble/commandwhitelist/common/CWGroup.java rename {CommandWhitelistCommon/src/main/java/eu/endermite => src/main/java/me/youhavetrouble}/commandwhitelist/common/CWPermission.java (53%) rename {CommandWhitelistCommon/src/main/java/eu/endermite => src/main/java/me/youhavetrouble}/commandwhitelist/common/CommandUtil.java (57%) rename {CommandWhitelistCommon/src/main/java/eu/endermite => src/main/java/me/youhavetrouble}/commandwhitelist/common/ConfigCache.java (87%) rename {CommandWhitelistCommon/src/main/java/eu/endermite => src/main/java/me/youhavetrouble}/commandwhitelist/common/commands/CWCommand.java (94%) create mode 100644 src/main/java/me/youhavetrouble/commandwhitelist/common/commands/CWCommandInterface.java create mode 100644 src/main/resources/config.yml rename {CommandWhitelistBukkit/src => src}/main/resources/plugin.yml (59%) diff --git a/CommandWhitelistBukkit/.gitignore b/CommandWhitelistBukkit/.gitignore deleted file mode 100644 index 4788b4b..0000000 --- a/CommandWhitelistBukkit/.gitignore +++ /dev/null @@ -1,113 +0,0 @@ -# User-specific stuff -.idea/ - -*.iml -*.ipr -*.iws - -# IntelliJ -out/ - -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -# Windows thumbnail cache files -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -target/ - -pom.xml.tag -pom.xml.releaseBackup -pom.xml.versionsBackup -pom.xml.next - -release.properties -dependency-reduced-pom.xml -buildNumber.properties -.mvn/timing.properties -.mvn/wrapper/maven-wrapper.jar -.flattened-pom.xml - -# Common working directory -run/ diff --git a/CommandWhitelistBukkit/pom.xml b/CommandWhitelistBukkit/pom.xml deleted file mode 100644 index 1feab97..0000000 --- a/CommandWhitelistBukkit/pom.xml +++ /dev/null @@ -1,129 +0,0 @@ - - - 4.0.0 - - eu.endermite.commandwhitelist - CommandWhitelist - 2.7.0 - - - Bukkit - jar - CommandWhitelist-Bukkit - - You decide what commands players can use or tab complete on your server! - - 1.8 - UTF-8 - - youhavetrouble.me - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - ${java.version} - ${java.version} - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - ${project.name}-${project.parent.version} - false - - - org.bstats - eu.endermite.bstats - - - net.kyori - eu.endermite - - - - - - - - - - src/main/resources - true - - - - - - - sonatype - https://oss.sonatype.org/content/groups/public/ - - - dmulloy2-repo - https://repo.dmulloy2.net/nexus/repository/public/ - - - papermc - https://papermc.io/repo/repository/maven-public/ - - - - - - io.papermc.paper - paper-api - 1.19-R0.1-SNAPSHOT - provided - - - net.kyori - adventure-platform-bukkit - 4.1.1 - compile - - - net.kyori - adventure-text-minimessage - 4.11.0 - compile - - - eu.endermite.commandwhitelist - Common - ${project.parent.version} - compile - - - com.comphenix.protocol - ProtocolLib - 5.0.0-SNAPSHOT - provided - - - org.bstats - bstats-bukkit - 3.0.0 - compile - - - com.mojang - brigadier - 1.0.17 - provided - - - diff --git a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/CommandWhitelistBukkit.java b/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/CommandWhitelistBukkit.java deleted file mode 100644 index 9577e20..0000000 --- a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/CommandWhitelistBukkit.java +++ /dev/null @@ -1,166 +0,0 @@ -package eu.endermite.commandwhitelist.bukkit; - -import eu.endermite.commandwhitelist.bukkit.command.BukkitCommandExecutor; -import eu.endermite.commandwhitelist.bukkit.listeners.AsyncTabCompleteBlockerListener; -import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandPreProcessListener; -import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandSendListener; -import eu.endermite.commandwhitelist.bukkit.listeners.TabCompleteBlockerListener; -import eu.endermite.commandwhitelist.bukkit.listeners.protocollib.PacketCommandPreProcessListener; -import eu.endermite.commandwhitelist.common.CWGroup; -import eu.endermite.commandwhitelist.common.ConfigCache; -import eu.endermite.commandwhitelist.common.commands.CWCommand; -import net.kyori.adventure.platform.bukkit.BukkitAudiences; -import org.bstats.bukkit.Metrics; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.command.PluginCommand; -import org.bukkit.entity.Player; -import org.bukkit.help.HelpTopic; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.File; -import java.util.*; -import java.util.concurrent.CompletableFuture; - -public class CommandWhitelistBukkit extends JavaPlugin { - - private static CommandWhitelistBukkit commandWhitelist; - private static ConfigCache configCache; - private static BukkitAudiences audiences; - - @Override - public void onEnable() { - - commandWhitelist = this; - audiences = BukkitAudiences.create(this); - - reloadPluginConfig(); - - Plugin protocollib = getServer().getPluginManager().getPlugin("ProtocolLib"); - - if (!getConfigCache().useProtocolLib || protocollib == null || !protocollib.isEnabled()) { - getServer().getPluginManager().registerEvents(new PlayerCommandPreProcessListener(), this); - } else { - PacketCommandPreProcessListener.protocol(this); - getLogger().warning("Using ProtocolLib for command filter!"); - getLogger().warning("Please make sure you actually need this. This is not a \"better way to do it\"."); - } - try { - // Use paper's async tab completions if possible - Class.forName("com.destroystokyo.paper.event.server.AsyncTabCompleteEvent"); - getServer().getPluginManager().registerEvents(new AsyncTabCompleteBlockerListener(), this); - } catch (ClassNotFoundException ignored) { - } - getServer().getPluginManager().registerEvents(new TabCompleteBlockerListener(), this); - getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), this); - - PluginCommand command = getCommand("commandwhitelist"); - if (command != null) { - BukkitCommandExecutor executor = new BukkitCommandExecutor(); - command.setExecutor(executor); - command.setTabCompleter(executor); - } - - new Metrics(this, 8705); - } - - private void reloadPluginConfig() { - File configFile = new File("plugins/CommandWhitelist/config.yml"); - if (configCache == null) { - try { - configCache = new ConfigCache(configFile, true, getSLF4JLogger()); - } catch (NoSuchMethodError e) { - configCache = new ConfigCache(configFile, true, null); - } - return; - } - configCache.reloadConfig(); - } - - public void reloadPluginConfig(CommandSender sender) { - CompletableFuture.runAsync(() -> { - reloadPluginConfig(); - try { - for (Player p : Bukkit.getOnlinePlayers()) { - p.updateCommands(); - } - } catch (Exception ignored) {} - audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.config_reloaded)); - }); - } - - public static CommandWhitelistBukkit getPlugin() { - return commandWhitelist; - } - - public static ConfigCache getConfigCache() { - return configCache; - } - - public static BukkitAudiences getAudiences() { - return audiences; - } - - /** - * @param player Bukkit Player - * @return commands available to the player - */ - public static HashSet getCommands(org.bukkit.entity.Player player) { - HashSet commandList = new HashSet<>(); - HashMap groups = configCache.getGroupList(); - for (Map.Entry s : groups.entrySet()) { - if (s.getKey().equalsIgnoreCase("default")) - commandList.addAll(s.getValue().getCommands()); - else if (player.hasPermission(s.getValue().getPermission())) - commandList.addAll(s.getValue().getCommands()); - } - return commandList; - } - - /** - * @param player Bukkit Player - * @return subcommands unavailable for the player - */ - public static HashSet getSuggestions(org.bukkit.entity.Player player) { - HashSet suggestionList = new HashSet<>(); - HashMap groups = configCache.getGroupList(); - for (Map.Entry s : groups.entrySet()) { - if (s.getKey().equalsIgnoreCase("default")) - suggestionList.addAll(s.getValue().getSubCommands()); - if (player.hasPermission(s.getValue().getPermission())) continue; - suggestionList.addAll(s.getValue().getSubCommands()); - } - return suggestionList; - } - - /** - * @return Command denied message. Will use custom if command exists in any group. - */ - public static String getCommandDeniedMessage(String command) { - String commandDeniedMessage = configCache.command_denied; - HashMap groups = configCache.getGroupList(); - for (CWGroup group : groups.values()) { - if (group.getCommands().contains(command)) { - if (group.getCommandDeniedMessage() == null || group.getCommandDeniedMessage().isEmpty()) continue; - commandDeniedMessage = group.getCommandDeniedMessage(); - break; // get first message we find - } - } - return commandDeniedMessage; - } - - public static ArrayList getServerCommands() { - try { - return new ArrayList<>(Bukkit.getCommandMap().getKnownCommands().keySet()); - } catch (NoSuchMethodError error) { - HashSet commands = new HashSet<>(); - for (HelpTopic topic : Bukkit.getHelpMap().getHelpTopics()) { - String cmd = topic.getName(); - if (Character.isUpperCase(cmd.charAt(0))) continue; - commands.add(topic.getName()); - } - return new ArrayList<>(commands); - } - } -} diff --git a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/command/BukkitCommandExecutor.java b/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/command/BukkitCommandExecutor.java deleted file mode 100644 index 664482d..0000000 --- a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/command/BukkitCommandExecutor.java +++ /dev/null @@ -1,96 +0,0 @@ -package eu.endermite.commandwhitelist.bukkit.command; - -import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit; -import eu.endermite.commandwhitelist.common.CWPermission; -import eu.endermite.commandwhitelist.common.CommandUtil; -import eu.endermite.commandwhitelist.common.commands.CWCommand; -import net.kyori.adventure.platform.bukkit.BukkitAudiences; -import net.kyori.adventure.text.Component; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabExecutor; - -import java.io.File; -import java.util.List; - -public class BukkitCommandExecutor implements TabExecutor { - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - - BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences(); - - if (args.length == 0) { - audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()))); - return true; - } - try { - CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0].toUpperCase()); - switch (commandType) { - case RELOAD: - if (!sender.hasPermission(CWPermission.RELOAD.permission())) { - audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission)); - return true; - } - CommandWhitelistBukkit.getPlugin().reloadPluginConfig(sender); - return true; - case ADD: - if (!sender.hasPermission(CWPermission.ADMIN.permission())) { - audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission)); - return true; - } - if (args.length == 3) { - if (CWCommand.addToWhitelist(CommandWhitelistBukkit.getConfigCache(), args[2], args[1])) - audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().added_to_whitelist, args[2], args[1]))); - else - audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().group_doesnt_exist, args[1]))); - } else - audiences.sender(sender).sendMessage(Component.text("/" + label + " add ")); - return true; - case REMOVE: - if (!sender.hasPermission(CWPermission.ADMIN.permission())) { - audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission)); - return true; - } - if (args.length == 3) { - if (CWCommand.removeFromWhitelist(CommandWhitelistBukkit.getConfigCache(), args[2], args[1])) - audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().removed_from_whitelist, args[2], args[1]))); - else - audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().group_doesnt_exist, args[1]))); - } else - audiences.sender(sender).sendMessage(Component.text("/" + label + " remove ")); - return true; - case DUMP: - if (!sender.hasPermission(CWPermission.ADMIN.permission())) { - audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission)); - return true; - } - audiences.sender(sender).sendMessage(Component.text("Dumping all available commands to a file...")); - if (CommandUtil.dumpAllBukkitCommands(CommandWhitelistBukkit.getServerCommands(), new File("plugins/CommandWhitelist/command_dump.yml"))) { - audiences.sender(sender).sendMessage(Component.text("Commands dumped to command_dump.yml")); - } else { - audiences.sender(sender).sendMessage(Component.text("Failed to save the file.")); - } - return true; - case HELP: - default: - audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()))); - } - } catch (IllegalArgumentException e) { - audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()))); - } - return true; - } - - @Override - public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { - return CWCommand.commandSuggestions( - CommandWhitelistBukkit.getConfigCache(), - CommandWhitelistBukkit.getServerCommands(), - args, - sender.hasPermission(CWPermission.RELOAD.permission()), - sender.hasPermission(CWPermission.ADMIN.permission()), - CWCommand.ImplementationType.BUKKIT - ); - } -} diff --git a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/AsyncTabCompleteBlockerListener.java b/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/AsyncTabCompleteBlockerListener.java deleted file mode 100644 index 2001da2..0000000 --- a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/AsyncTabCompleteBlockerListener.java +++ /dev/null @@ -1,31 +0,0 @@ -package eu.endermite.commandwhitelist.bukkit.listeners; - -import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent; -import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit; -import eu.endermite.commandwhitelist.common.CWPermission; -import eu.endermite.commandwhitelist.common.CommandUtil; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; - -public class AsyncTabCompleteBlockerListener implements Listener { - - @EventHandler(priority = EventPriority.HIGHEST) - public void onCommandTabComplete(AsyncTabCompleteEvent event) { - if (!(event.getSender() instanceof Player)) return; - Player player = (Player) event.getSender(); - if (player.hasPermission(CWPermission.BYPASS.permission())) return; - String buffer = event.getBuffer(); - if ((buffer.split(" ").length == 1 && !buffer.endsWith(" ")) || !buffer.startsWith("/")) { - CommandWhitelistBukkit.getConfigCache().debug("Actively prevented "+event.getSender().getName()+"'s tab completion (sus packet)"); - event.setCancelled(true); - return; - } - if (event.getCompletions().isEmpty()) { - return; - } - event.setCompletions(CommandUtil.filterSuggestions(buffer, event.getCompletions(), CommandWhitelistBukkit.getSuggestions(player))); - } - -} diff --git a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/PlayerCommandPreProcessListener.java b/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/PlayerCommandPreProcessListener.java deleted file mode 100644 index 82fbad7..0000000 --- a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/PlayerCommandPreProcessListener.java +++ /dev/null @@ -1,48 +0,0 @@ -package eu.endermite.commandwhitelist.bukkit.listeners; - -import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit; -import eu.endermite.commandwhitelist.common.CWPermission; -import eu.endermite.commandwhitelist.common.CommandUtil; -import eu.endermite.commandwhitelist.common.ConfigCache; -import eu.endermite.commandwhitelist.common.commands.CWCommand; -import net.kyori.adventure.platform.bukkit.BukkitAudiences; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; - -import java.util.HashSet; - -public class PlayerCommandPreProcessListener implements Listener { - @EventHandler(priority = EventPriority.HIGHEST) - public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) { - Player player = event.getPlayer(); - if (player.hasPermission(CWPermission.BYPASS.permission())) return; - String caseSensitiveLabel = CommandUtil.getCommandLabel(event.getMessage()); - String label = caseSensitiveLabel.toLowerCase(); - - String fullCommand = event.getMessage().substring(label.length()+1); - fullCommand = "/"+label+fullCommand; - - event.setMessage(fullCommand); - BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences(); - ConfigCache config = CommandWhitelistBukkit.getConfigCache(); - - HashSet commands = CommandWhitelistBukkit.getCommands(player); - if (!commands.contains(label)) { - event.setCancelled(true); - audiences.player(player).sendMessage(CWCommand.miniMessage.deserialize(config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label))); - return; - } - - HashSet bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player); - for (String bannedSubCommand : bannedSubCommands) { - if (event.getMessage().toLowerCase().substring(1).startsWith(bannedSubCommand)) { - event.setCancelled(true); - audiences.player(player).sendMessage(CWCommand.miniMessage.deserialize(config.prefix + config.subcommand_denied)); - return; - } - } - - } -} \ No newline at end of file diff --git a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/PlayerCommandSendListener.java b/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/PlayerCommandSendListener.java deleted file mode 100644 index d8ba91b..0000000 --- a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/PlayerCommandSendListener.java +++ /dev/null @@ -1,20 +0,0 @@ -package eu.endermite.commandwhitelist.bukkit.listeners; - -import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit; -import eu.endermite.commandwhitelist.common.CWPermission; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; - -import java.util.HashSet; - -public class PlayerCommandSendListener implements Listener { - @EventHandler(priority = EventPriority.NORMAL) - public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandSendEvent event) { - Player player = event.getPlayer(); - if (player.hasPermission(CWPermission.BYPASS.permission())) return; - HashSet commandList = CommandWhitelistBukkit.getCommands(player); - event.getCommands().removeIf((cmd) -> !commandList.contains(cmd)); - } -} diff --git a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/TabCompleteBlockerListener.java b/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/TabCompleteBlockerListener.java deleted file mode 100644 index 9ea1088..0000000 --- a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/TabCompleteBlockerListener.java +++ /dev/null @@ -1,36 +0,0 @@ -package eu.endermite.commandwhitelist.bukkit.listeners; - -import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit; -import eu.endermite.commandwhitelist.common.CWPermission; -import eu.endermite.commandwhitelist.common.CommandUtil; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.server.TabCompleteEvent; - -public class TabCompleteBlockerListener implements Listener { - - @EventHandler(priority = EventPriority.NORMAL) - public void onCommandTabComplete(TabCompleteEvent event) { - if (!(event.getSender() instanceof Player)) return; - Player player = (Player) event.getSender(); - if (player.hasPermission(CWPermission.BYPASS.permission())) return; - String buffer = event.getBuffer(); - if ((buffer.split(" ").length == 1 && !buffer.endsWith(" ")) || !buffer.startsWith("/")) { - CommandWhitelistBukkit.getConfigCache().debug("Actively prevented "+event.getSender().getName()+"'s tab completion (sus packet)"); - event.setCancelled(true); - return; - } - if (event.getCompletions().isEmpty()) { - return; - } - event.setCompletions( - CommandUtil.filterSuggestions( - buffer, - event.getCompletions(), - CommandWhitelistBukkit.getSuggestions(player) - ) - ); - } -} diff --git a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/protocollib/PacketCommandPreProcessListener.java b/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/protocollib/PacketCommandPreProcessListener.java deleted file mode 100644 index a54bdaf..0000000 --- a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/protocollib/PacketCommandPreProcessListener.java +++ /dev/null @@ -1,60 +0,0 @@ -package eu.endermite.commandwhitelist.bukkit.listeners.protocollib; - -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.bukkit.CommandWhitelistBukkit; -import eu.endermite.commandwhitelist.common.CWPermission; -import eu.endermite.commandwhitelist.common.CommandUtil; -import eu.endermite.commandwhitelist.common.ConfigCache; -import eu.endermite.commandwhitelist.common.commands.CWCommand; -import net.kyori.adventure.platform.bukkit.BukkitAudiences; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -import java.util.HashSet; - -public class PacketCommandPreProcessListener { - - public static void protocol(CommandWhitelistBukkit 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(CWPermission.BYPASS.permission())) return; - ConfigCache config = CommandWhitelistBukkit.getConfigCache(); - String caseSensitiveLabel = CommandUtil.getCommandLabel(string); - String label = caseSensitiveLabel.toLowerCase(); - packet.getStrings().write(0, string.replaceFirst(caseSensitiveLabel, label)); - - HashSet commands = CommandWhitelistBukkit.getCommands(player); - BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences(); - if (!commands.contains(label)) { - event.setCancelled(true); - audiences.player(player).sendMessage(CWCommand.miniMessage.deserialize(config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label))); - return; - } - HashSet bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player); - for (String bannedSubCommand : bannedSubCommands) { - if (string.toLowerCase().substring(1).startsWith(bannedSubCommand)) { - event.setCancelled(true); - CommandWhitelistBukkit.getAudiences().player(player).sendMessage(CWCommand.miniMessage.deserialize(config.prefix + config.subcommand_denied)); - return; - } - } - } - }); - } -} diff --git a/CommandWhitelistCommon/pom.xml b/CommandWhitelistCommon/pom.xml deleted file mode 100644 index 7f7b834..0000000 --- a/CommandWhitelistCommon/pom.xml +++ /dev/null @@ -1,108 +0,0 @@ - - - 4.0.0 - - eu.endermite.commandwhitelist - CommandWhitelist - 2.7.0 - - - Common - jar - CommandWhitelist-Common - - You decide what commands players can use or tab complete on your server! - - 1.8 - UTF-8 - - youhavetrouble.me - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - ${java.version} - ${java.version} - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - false - ${project.name}-${project.parent.version} - - - - - - - - src/main/resources - true - - - - - - - pluginwiki-repo - https://ci.pluginwiki.us/plugin/repository/everything/ - - - velocitypowered-repo - https://repo.velocitypowered.com/releases/ - - - papermc - https://papermc.io/repo/repository/maven-public/ - - - - - - com.github.thatsmusic99 - ConfigurationMaster-API - v2.0.0-BETA-1 - compile - - - com.velocitypowered - velocity-api - 3.1.2-SNAPSHOT - provided - - - net.kyori - adventure-text-minimessage - 4.13.1 - provided - - - io.papermc.paper - paper-api - 1.19-R0.1-SNAPSHOT - provided - - - io.github.waterfallmc - waterfall-api - 1.17-R0.1-SNAPSHOT - provided - - - - \ No newline at end of file diff --git a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/CWGroup.java b/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/CWGroup.java deleted file mode 100644 index 86e8581..0000000 --- a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/CWGroup.java +++ /dev/null @@ -1,65 +0,0 @@ -package eu.endermite.commandwhitelist.common; - -import org.jetbrains.annotations.Nullable; - -import java.util.*; - -public class CWGroup { - - private final String id, permission, commandDeniedMessage; - private final HashSet commands = new HashSet<>(); - private final HashSet subCommands = new HashSet<>(); - - public CWGroup(String id, Collection commands, Collection subCommands, String custom_command_denied_message) { - this.id = id; - this.permission = "commandwhitelist.group." + id; - this.commands.addAll(commands); - this.commandDeniedMessage = custom_command_denied_message; - this.subCommands.addAll(subCommands); - } - - public String getId() { - return id; - } - - public String getPermission() { - return permission; - } - - public HashSet getCommands() { - return commands; - } - - public @Nullable String getCommandDeniedMessage() { - return commandDeniedMessage; - } - - public void addCommand(String command) { - commands.add(command); - } - - public void removeCommand(String command) { - commands.remove(command); - } - - public HashSet getSubCommands() { - return subCommands; - } - - public void addSubCommand(String subCommand) { - subCommands.add(subCommand); - } - - public void removeSubCommand(String subCommand) { - subCommands.remove(subCommand); - } - - public HashMap serialize() { - HashMap serializedGroup = new LinkedHashMap<>(); - List commands = new ArrayList<>(this.commands); - List subCommands = new ArrayList<>(this.subCommands); - serializedGroup.put("commands", commands); - serializedGroup.put("subcommands", subCommands); - return serializedGroup; - } -} diff --git a/CommandWhitelistVelocity/.gitignore b/CommandWhitelistVelocity/.gitignore deleted file mode 100644 index 4788b4b..0000000 --- a/CommandWhitelistVelocity/.gitignore +++ /dev/null @@ -1,113 +0,0 @@ -# User-specific stuff -.idea/ - -*.iml -*.ipr -*.iws - -# IntelliJ -out/ - -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -# Windows thumbnail cache files -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -target/ - -pom.xml.tag -pom.xml.releaseBackup -pom.xml.versionsBackup -pom.xml.next - -release.properties -dependency-reduced-pom.xml -buildNumber.properties -.mvn/timing.properties -.mvn/wrapper/maven-wrapper.jar -.flattened-pom.xml - -# Common working directory -run/ diff --git a/CommandWhitelistVelocity/pom.xml b/CommandWhitelistVelocity/pom.xml deleted file mode 100644 index a5dc8df..0000000 --- a/CommandWhitelistVelocity/pom.xml +++ /dev/null @@ -1,111 +0,0 @@ - - - 4.0.0 - - eu.endermite.commandwhitelist - CommandWhitelist - 2.7.0 - - - Velocity - jar - CommandWhitelist-Velocity - - You decide what commands players can use or tab complete on your server! - - 1.8 - UTF-8 - - youhavetrouble.me - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - ${java.version} - ${java.version} - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - false - ${project.name}-${project.parent.version} - - - org.bstats - eu.endermite.bstats - - - - - net.kyori:adventure-api - net.kyori:adventure-key - net.kyori:examination-api - net.kyori:examination-string - org.jetbrains:annotations - org.intellij.lang:annotations - - - - - - - - - - src/main/resources - true - - - - - - - papermc - https://papermc.io/repo/repository/maven-public/ - - - minecraft-libraries - https://libraries.minecraft.net/ - - - spongepowered-repo - https://repo.spongepowered.org/maven - - - - - - com.velocitypowered - velocity-api - 3.1.2-SNAPSHOT - provided - - - eu.endermite.commandwhitelist - Common - ${project.parent.version} - compile - - - org.bstats - bstats-velocity - 3.0.0 - compile - - - diff --git a/CommandWhitelistVelocity/src/main/java/eu/endermite/commandwhitelist/velocity/CommandWhitelistVelocity.java b/CommandWhitelistVelocity/src/main/java/eu/endermite/commandwhitelist/velocity/CommandWhitelistVelocity.java deleted file mode 100644 index cd6e04d..0000000 --- a/CommandWhitelistVelocity/src/main/java/eu/endermite/commandwhitelist/velocity/CommandWhitelistVelocity.java +++ /dev/null @@ -1,145 +0,0 @@ -package eu.endermite.commandwhitelist.velocity; - -import com.google.inject.Injector; -import com.mojang.brigadier.Command; -import com.velocitypowered.api.command.CommandSource; -import com.velocitypowered.api.event.Subscribe; -import com.velocitypowered.api.event.command.CommandExecuteEvent; -import com.velocitypowered.api.event.command.PlayerAvailableCommandsEvent; -import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; -import com.velocitypowered.api.plugin.annotation.DataDirectory; -import com.velocitypowered.api.proxy.Player; -import com.velocitypowered.api.proxy.ProxyServer; -import eu.endermite.commandwhitelist.common.CWGroup; -import eu.endermite.commandwhitelist.common.CWPermission; -import eu.endermite.commandwhitelist.common.CommandUtil; -import eu.endermite.commandwhitelist.common.ConfigCache; -import eu.endermite.commandwhitelist.common.commands.CWCommand; -import eu.endermite.commandwhitelist.velocity.command.VelocityMainCommand; -import org.bstats.charts.SimplePie; -import org.bstats.velocity.Metrics; -import org.slf4j.Logger; - -import javax.inject.Inject; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; - -public class CommandWhitelistVelocity { - - private final ProxyServer server; - private ConfigCache configCache; - private final Path folder; - private final Logger logger; - private final Metrics.Factory metricsFactory; - private final Injector injector; - - @Inject - public CommandWhitelistVelocity( - ProxyServer server, - Logger logger, - @DataDirectory final Path folder, - Metrics.Factory metricsFactory, - Injector injector - ) { - this.server = server; - this.folder = folder; - this.logger = logger; - this.metricsFactory = metricsFactory; - this.injector = injector; - } - - private void reloadConfig() { - if (configCache == null) - configCache = new ConfigCache(folder.resolve("config.yml").toFile(), false, logger); - else - configCache.reloadConfig(); - } - - public int reloadConfig(CommandSource source) { - server.getScheduler().buildTask(this, () -> { - reloadConfig(); - source.sendMessage(CWCommand.miniMessage.deserialize(getConfigCache().prefix + getConfigCache().config_reloaded)); - }).schedule(); - return Command.SINGLE_SUCCESS; - } - - @Subscribe - public void onProxyInitialization(ProxyInitializeEvent event) { - reloadConfig(); - injector.getInstance(VelocityMainCommand.class).register(); - Metrics metrics = metricsFactory.make(this, 8704); - metrics.addCustomChart(new SimplePie("proxy", () -> "Velocity")); - } - - @Subscribe - @SuppressWarnings("UnstableApiUsage") - public void onUserCommandSendEvent(PlayerAvailableCommandsEvent event) { - Player player = event.getPlayer(); - if (player.hasPermission(CWPermission.BYPASS.permission())) return; - HashSet allowedCommands = getCommands(player); - event.getRootNode().getChildren().removeIf((commandNode) -> - server.getCommandManager().hasCommand(commandNode.getName()) - && !allowedCommands.contains(commandNode.getName()) - ); - } - - @Subscribe - public void onUserCommandExecuteEvent(CommandExecuteEvent event) { - if (!(event.getCommandSource() instanceof Player)) return; - Player player = (Player) event.getCommandSource(); - - if (player.hasPermission(CWPermission.BYPASS.permission())) return; - - // Workaround for velocity executing "/ command" as valid command - String command = event.getCommand().trim(); - - HashSet allowedCommands = getCommands(player); - String label = CommandUtil.getCommandLabel(command); - if (server.getCommandManager().hasCommand(label) && !allowedCommands.contains(label)) - event.setResult(CommandExecuteEvent.CommandResult.forwardToServer()); - } - - public ConfigCache getConfigCache() { - return configCache; - } - - /** - * @param player Velocity Player - * @return commands available to the player - */ - public HashSet getCommands(Player player) { - HashMap groups = configCache.getGroupList(); - HashSet commandList = new HashSet<>(); - for (Map.Entry s : groups.entrySet()) { - CWGroup group = s.getValue(); - if (s.getKey().equalsIgnoreCase("default")) - commandList.addAll(group.getCommands()); - else if (player.hasPermission(group.getPermission())) - commandList.addAll(group.getCommands()); - } - return commandList; - } - - /** - * @param player Velocity Player - * @return subcommands unavailable for the player - */ - public HashSet getSuggestions(Player player, HashMap groups) { - HashSet suggestionList = new HashSet<>(); - for (Map.Entry s : groups.entrySet()) { - if (s.getKey().equalsIgnoreCase("default")) - suggestionList.addAll(s.getValue().getSubCommands()); - if (player.hasPermission(s.getValue().getPermission())) continue; - suggestionList.addAll(s.getValue().getSubCommands()); - } - return suggestionList; - } - - public ArrayList getServerCommands() { - return new ArrayList<>(server.getCommandManager().getAliases()); - } - -} diff --git a/CommandWhitelistVelocity/src/main/java/eu/endermite/commandwhitelist/velocity/command/VelocityMainCommand.java b/CommandWhitelistVelocity/src/main/java/eu/endermite/commandwhitelist/velocity/command/VelocityMainCommand.java deleted file mode 100644 index c00b953..0000000 --- a/CommandWhitelistVelocity/src/main/java/eu/endermite/commandwhitelist/velocity/command/VelocityMainCommand.java +++ /dev/null @@ -1,143 +0,0 @@ -package eu.endermite.commandwhitelist.velocity.command; - -import com.google.inject.Inject; -import com.mojang.brigadier.Command; -import com.mojang.brigadier.arguments.StringArgumentType; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.tree.LiteralCommandNode; -import com.velocitypowered.api.command.BrigadierCommand; -import com.velocitypowered.api.command.CommandManager; -import com.velocitypowered.api.command.CommandSource; -import com.velocitypowered.api.permission.Tristate; -import com.velocitypowered.api.plugin.annotation.DataDirectory; -import eu.endermite.commandwhitelist.common.CWGroup; -import eu.endermite.commandwhitelist.common.CWPermission; -import eu.endermite.commandwhitelist.common.CommandUtil; -import eu.endermite.commandwhitelist.common.ConfigCache; -import eu.endermite.commandwhitelist.common.commands.CWCommand; -import eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity; -import net.kyori.adventure.text.Component; - -import java.nio.file.Path; - -public final class VelocityMainCommand { - @Inject - private CommandManager commandManager; - @Inject - private CommandWhitelistVelocity plugin; - @Inject - @DataDirectory - private Path dataDirectory; - - public void register() { - LiteralCommandNode node = LiteralArgumentBuilder - .literal("vcw") - .requires(src -> src.getPermissionValue("commandwhitelist.command") != Tristate.FALSE) - .executes(ctx -> { - CommandSource source = ctx.getSource(); - source.sendMessage(CWCommand.helpComponent("vcw", source.hasPermission(CWPermission.RELOAD.permission()), source.hasPermission(CWPermission.ADMIN.permission()))); - return Command.SINGLE_SUCCESS; - }) - .then(LiteralArgumentBuilder.literal("reload") - .requires(src -> src.hasPermission(CWPermission.RELOAD.permission())) - .executes(ctx -> plugin.reloadConfig(ctx.getSource())) - ) - .then(LiteralArgumentBuilder.literal("add") - .requires(src -> src.hasPermission(CWPermission.ADMIN.permission())) - .then(RequiredArgumentBuilder.argument("group", StringArgumentType.word()) - .suggests((ctx, builder) -> { - plugin.getConfigCache().getGroupList().keySet().forEach(builder::suggest); - return builder.buildFuture(); - }) - .then(RequiredArgumentBuilder.argument("command", StringArgumentType.word()) - .suggests((ctx, builder) -> { - CWGroup group = plugin.getConfigCache().getGroupList().get(ctx.getArgument("group", String.class)); - if (group == null) return builder.buildFuture(); - - for (String cmd : plugin.getServerCommands()) { - if (cmd.charAt(0) == '/') - cmd = cmd.substring(1); - if (cmd.indexOf(':') != -1) { - String[] cmdSplit = cmd.split(":"); - if (cmdSplit.length < 2) continue; - cmd = cmdSplit[1]; - } - if (group.getCommands().contains(cmd)) continue; - builder.suggest(cmd); - } - return builder.buildFuture(); - }) - .executes(ctx -> { - CommandSource source = ctx.getSource(); - ConfigCache configCache = plugin.getConfigCache(); - String arg1 = ctx.getArgument("group", String.class); - String arg2 = ctx.getArgument("command", String.class); - - if (CWCommand.addToWhitelist(configCache, arg2, arg1)) - source.sendMessage(CWCommand.miniMessage.deserialize(String.format(configCache.prefix + configCache.added_to_whitelist, arg2, arg1))); - else - source.sendMessage(CWCommand.miniMessage.deserialize(String.format(configCache.prefix + configCache.group_doesnt_exist, arg1))); - return Command.SINGLE_SUCCESS; - }) - ) - ) - ) - .then(LiteralArgumentBuilder.literal("remove") - .requires(src -> src.hasPermission(CWPermission.ADMIN.permission())) - .then(RequiredArgumentBuilder.argument("group", StringArgumentType.word()) - .suggests((ctx, builder) -> { - plugin.getConfigCache().getGroupList().keySet().forEach(builder::suggest); - return builder.buildFuture(); - }) - .then(RequiredArgumentBuilder.argument("command", StringArgumentType.word()) - .suggests((ctx, builder) -> { - CWGroup group = plugin.getConfigCache().getGroupList().get(ctx.getArgument("group", String.class)); - if (group == null) return builder.buildFuture(); - - for (String s : group.getCommands()) { - builder.suggest(s); - } - return builder.buildFuture(); - }) - .executes(ctx -> { - CommandSource source = ctx.getSource(); - ConfigCache configCache = plugin.getConfigCache(); - String arg1 = ctx.getArgument("group", String.class); - String arg2 = ctx.getArgument("command", String.class); - - if (CWCommand.removeFromWhitelist(configCache, arg2, arg1)) - source.sendMessage(CWCommand.miniMessage.deserialize(String.format(configCache.prefix + configCache.removed_from_whitelist, arg2, arg1))); - else - source.sendMessage(CWCommand.miniMessage.deserialize(String.format(configCache.prefix + configCache.group_doesnt_exist, arg1))); - return Command.SINGLE_SUCCESS; - }) - ) - ) - ) - .then(LiteralArgumentBuilder.literal("dump") - .requires(src -> src.hasPermission(CWPermission.ADMIN.permission())) - .executes(ctx -> { - CommandSource source = ctx.getSource(); - source.sendMessage(Component.text("Dumping all available commands to a file...")); - if (CommandUtil.dumpAllBukkitCommands(plugin.getServerCommands(), dataDirectory.resolve("command_dump.yml").toFile())) { - source.sendMessage(Component.text("Commands dumped to command_dump.yml")); - } else { - source.sendMessage(Component.text("Failed to save the file.")); - } - return Command.SINGLE_SUCCESS; - }) - ) - .then(LiteralArgumentBuilder.literal("help") - .executes(ctx -> { - CommandSource source = ctx.getSource(); - source.sendMessage(CWCommand.helpComponent("cw", source.hasPermission(CWPermission.RELOAD.permission()), source.hasPermission(CWPermission.ADMIN.permission()))); - return Command.SINGLE_SUCCESS; - }) - ) - .build(); - - final BrigadierCommand command = new BrigadierCommand(node); - commandManager.register(commandManager.metaBuilder(command).plugin(plugin).build(), command); - } -} diff --git a/CommandWhitelistVelocity/src/main/resources/velocity-plugin.json b/CommandWhitelistVelocity/src/main/resources/velocity-plugin.json deleted file mode 100644 index 735a687..0000000 --- a/CommandWhitelistVelocity/src/main/resources/velocity-plugin.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "id": "commandwhitelist", - "name": "CommandWhitelist", - "version": "${project.version}", - "description": "You decide what commands players can use or tab complete on your server!", - "authors": ["YouHaveTrouble"], - "dependencies": [], - "main": "eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity" -} \ No newline at end of file diff --git a/CommandWhitelistWaterfall/.gitignore b/CommandWhitelistWaterfall/.gitignore deleted file mode 100644 index 4788b4b..0000000 --- a/CommandWhitelistWaterfall/.gitignore +++ /dev/null @@ -1,113 +0,0 @@ -# User-specific stuff -.idea/ - -*.iml -*.ipr -*.iws - -# IntelliJ -out/ - -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -# Windows thumbnail cache files -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -target/ - -pom.xml.tag -pom.xml.releaseBackup -pom.xml.versionsBackup -pom.xml.next - -release.properties -dependency-reduced-pom.xml -buildNumber.properties -.mvn/timing.properties -.mvn/wrapper/maven-wrapper.jar -.flattened-pom.xml - -# Common working directory -run/ diff --git a/CommandWhitelistWaterfall/pom.xml b/CommandWhitelistWaterfall/pom.xml deleted file mode 100644 index 59b61f2..0000000 --- a/CommandWhitelistWaterfall/pom.xml +++ /dev/null @@ -1,113 +0,0 @@ - - - 4.0.0 - - eu.endermite.commandwhitelist - CommandWhitelist - 2.7.0 - - - Waterfall - jar - CommandWhitelist-Waterfall - - You decide what commands players can use or tab complete on your server! - - 1.8 - UTF-8 - - youhavetrouble.me - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - ${java.version} - ${java.version} - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - false - ${project.name}-${project.parent.version} - - - org.bstats - eu.endermite.bstats - - - net.kyori - eu.endermite - - - - - - - - - - src/main/resources - true - - - - - - - sonatype - https://oss.sonatype.org/content/groups/public/ - - - papermc - https://papermc.io/repo/repository/maven-public/ - - - - - - eu.endermite.commandwhitelist - Common - ${project.parent.version} - compile - - - io.github.waterfallmc - waterfall-api - 1.17-R0.1-SNAPSHOT - provided - - - net.kyori - adventure-platform-bungeecord - 4.1.0 - compile - - - net.kyori - adventure-text-minimessage - 4.10.1 - compile - - - org.bstats - bstats-bungeecord - 3.0.0 - compile - - - diff --git a/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/CommandWhitelistWaterfall.java b/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/CommandWhitelistWaterfall.java deleted file mode 100644 index fd6be02..0000000 --- a/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/CommandWhitelistWaterfall.java +++ /dev/null @@ -1,132 +0,0 @@ -package eu.endermite.commandwhitelist.waterfall; - -import eu.endermite.commandwhitelist.common.CWGroup; -import eu.endermite.commandwhitelist.common.ConfigCache; -import eu.endermite.commandwhitelist.common.commands.CWCommand; -import eu.endermite.commandwhitelist.waterfall.command.BungeeMainCommand; -import eu.endermite.commandwhitelist.waterfall.listeners.BungeeChatEventListener; -import eu.endermite.commandwhitelist.waterfall.listeners.BungeeTabcompleteListener; -import eu.endermite.commandwhitelist.waterfall.listeners.WaterfallDefineCommandsListener; -import net.kyori.adventure.platform.bungeecord.BungeeAudiences; -import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Command; -import net.md_5.bungee.api.plugin.Plugin; -import org.bstats.bungeecord.Metrics; -import org.bstats.charts.SimplePie; - -import java.io.File; -import java.util.*; - -public final class CommandWhitelistWaterfall extends Plugin { - - private static CommandWhitelistWaterfall plugin; - private static ConfigCache configCache; - private static BungeeAudiences audiences; - - @Override - public void onEnable() { - plugin = this; - getLogger().info("Running on " + ChatColor.DARK_AQUA + getProxy().getName()); - loadConfig(); - audiences = BungeeAudiences.create(this); - Metrics metrics = new Metrics(this, 8704); - - this.getProxy().getPluginManager().registerListener(this, new BungeeChatEventListener()); - try { - Class.forName("io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent"); - metrics.addCustomChart(new SimplePie("proxy", () -> "Waterfall")); - this.getProxy().getPluginManager().registerListener(this, new WaterfallDefineCommandsListener()); - } catch (ClassNotFoundException e) { - metrics.addCustomChart(new SimplePie("proxy", () -> "Bungee")); - getLogger().severe("Bungee command completion blocker requires Waterfall other Waterfall fork."); - } - this.getProxy().getPluginManager().registerListener(this, new BungeeTabcompleteListener()); - getProxy().getPluginManager().registerCommand(this, new BungeeMainCommand("bcw")); - - - } - - public static CommandWhitelistWaterfall getPlugin() { - return plugin; - } - - public static ConfigCache getConfigCache() { - return configCache; - } - - public static BungeeAudiences getAudiences() { - return audiences; - } - - public void loadConfig() { - if (configCache == null) - configCache = new ConfigCache(new File(getDataFolder(), "config.yml"), false, getLogger()); - else - configCache.reloadConfig(); - } - - public void loadConfigAsync(CommandSender sender) { - getProxy().getScheduler().runAsync(this, () -> { - loadConfig(); - audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().config_reloaded)); - }); - } - - /** - * @param player Bungee Player - * @return commands available to the player - */ - public static HashSet getCommands(ProxiedPlayer player) { - HashSet commandList = new HashSet<>(); - HashMap groups = configCache.getGroupList(); - for (Map.Entry s : groups.entrySet()) { - if (s.getKey().equalsIgnoreCase("default")) - commandList.addAll(s.getValue().getCommands()); - else if (player.hasPermission(s.getValue().getPermission())) - commandList.addAll(s.getValue().getCommands()); - } - return commandList; - } - - /** - * @param player Bungee Player - * @return subcommands unavailable for the player - */ - public static HashSet getSuggestions(ProxiedPlayer player) { - HashMap groups = configCache.getGroupList(); - HashSet suggestionList = new HashSet<>(); - for (Map.Entry s : groups.entrySet()) { - if (s.getKey().equalsIgnoreCase("default")) - suggestionList.addAll(s.getValue().getSubCommands()); - if (player.hasPermission(s.getValue().getPermission())) continue; - suggestionList.addAll(s.getValue().getSubCommands()); - } - return suggestionList; - } - - /** - * @return Command denied message. Will use custom if command exists in any group. - */ - public static String getCommandDeniedMessage(String command) { - String commandDeniedMessage = configCache.command_denied; - HashMap groups = configCache.getGroupList(); - for (CWGroup group : groups.values()) { - if (group.getCommands().contains(command)) { - if (group.getCommandDeniedMessage() == null || group.getCommandDeniedMessage().isEmpty()) continue; - commandDeniedMessage = group.getCommandDeniedMessage(); - break; // get first message we find - } - } - return commandDeniedMessage; - } - - public static ArrayList getServerCommands() { - ArrayList serverCommands = new ArrayList<>(); - for (Map.Entry command : CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()) { - serverCommands.add(command.getValue().getName()); - } - return serverCommands; - } -} diff --git a/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/command/BungeeMainCommand.java b/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/command/BungeeMainCommand.java deleted file mode 100644 index b318182..0000000 --- a/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/command/BungeeMainCommand.java +++ /dev/null @@ -1,106 +0,0 @@ -package eu.endermite.commandwhitelist.waterfall.command; - -import eu.endermite.commandwhitelist.common.CWPermission; -import eu.endermite.commandwhitelist.common.CommandUtil; -import eu.endermite.commandwhitelist.common.ConfigCache; -import eu.endermite.commandwhitelist.common.commands.CWCommand; -import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall; -import net.kyori.adventure.platform.bungeecord.BungeeAudiences; -import net.kyori.adventure.text.Component; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.plugin.Command; -import net.md_5.bungee.api.plugin.TabExecutor; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class BungeeMainCommand extends Command implements TabExecutor { - - public BungeeMainCommand(String name) { - super(name); - } - - public void execute(CommandSender sender, String[] args) { - - String label = getName(); - ConfigCache configCache = CommandWhitelistWaterfall.getConfigCache(); - BungeeAudiences audiences = CommandWhitelistWaterfall.getAudiences(); - - if (args.length == 0) { - audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()))); - return; - } - - try { - CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0].toUpperCase()); - switch (commandType) { - case RELOAD: - if (!sender.hasPermission(CWPermission.RELOAD.permission())) { - audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistWaterfall.getConfigCache().prefix + configCache.no_permission)); - return; - } - CommandWhitelistWaterfall.getPlugin().loadConfigAsync(sender); - return; - case ADD: - if (!sender.hasPermission(CWPermission.ADMIN.permission())) { - audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.no_permission)); - return; - } - if (args.length == 3) { - if (CWCommand.addToWhitelist(configCache, args[2], args[1])) - audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.added_to_whitelist)); - else - audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.group_doesnt_exist)); - } else - audiences.sender(sender).sendMessage(Component.text("/" + label + " add ")); - return; - case REMOVE: - if (!sender.hasPermission(CWPermission.ADMIN.permission())) { - audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.no_permission)); - return; - } - if (args.length == 3) { - if (CWCommand.removeFromWhitelist(configCache, args[2], args[1])) - audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.removed_from_whitelist)); - else - audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.group_doesnt_exist)); - } else - audiences.sender(sender).sendMessage(Component.text("/" + label + " remove ")); - return; - case DUMP: - if (!sender.hasPermission(CWPermission.ADMIN.permission())) { - audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().no_permission)); - return; - } - audiences.sender(sender).sendMessage(Component.text("Dumping all available commands to a file...")); - if (CommandUtil.dumpAllBukkitCommands(CommandWhitelistWaterfall.getServerCommands(), new File("plugins/CommandWhitelist/command_dump.yml"))) { - audiences.sender(sender).sendMessage(Component.text("Commands dumped to command_dump.yml")); - } else { - audiences.sender(sender).sendMessage(Component.text("Failed to save the file.")); - } - return; - case HELP: - default: - audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()))); - } - - } catch (IllegalArgumentException e) { - audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()))); - } - return; - } - - @Override - public Iterable onTabComplete(CommandSender sender, String[] args) { - return CWCommand.commandSuggestions( - CommandWhitelistWaterfall.getConfigCache(), - CommandWhitelistWaterfall.getServerCommands(), - args, - sender.hasPermission(CWPermission.RELOAD.permission()), - sender.hasPermission(CWPermission.ADMIN.permission()), - CWCommand.ImplementationType.WATERFALL - ); - } -} diff --git a/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/listeners/BungeeChatEventListener.java b/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/listeners/BungeeChatEventListener.java deleted file mode 100644 index 9dfcd9c..0000000 --- a/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/listeners/BungeeChatEventListener.java +++ /dev/null @@ -1,48 +0,0 @@ -package eu.endermite.commandwhitelist.waterfall.listeners; - -import eu.endermite.commandwhitelist.common.CWPermission; -import eu.endermite.commandwhitelist.common.CommandUtil; -import eu.endermite.commandwhitelist.common.ConfigCache; -import eu.endermite.commandwhitelist.common.commands.CWCommand; -import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall; -import net.kyori.adventure.platform.bungeecord.BungeeAudiences; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Listener; -import net.md_5.bungee.event.EventHandler; - -import java.util.HashSet; - -public class BungeeChatEventListener implements Listener { - - @EventHandler - public void onChatEvent(net.md_5.bungee.api.event.ChatEvent event) { - if (event.isCancelled()) return; - if (!(event.getSender() instanceof ProxiedPlayer)) return; - if (!event.isProxyCommand()) return; - ProxiedPlayer player = (ProxiedPlayer) event.getSender(); - if (player.hasPermission(CWPermission.BYPASS.permission())) return; - - String command = event.getMessage().toLowerCase(); - if (command.startsWith("/")) - command = command.substring(1); - ConfigCache configCache = CommandWhitelistWaterfall.getConfigCache(); - BungeeAudiences audiences = CommandWhitelistWaterfall.getAudiences(); - - String label = CommandUtil.getCommandLabel(command); - HashSet commands = CommandWhitelistWaterfall.getCommands(player); - if (!commands.contains(label)) { - event.setCancelled(true); - CommandWhitelistWaterfall.getAudiences().player(player).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + CommandWhitelistWaterfall.getCommandDeniedMessage(label))); - return; - } - - HashSet bannedSubCommands = CommandWhitelistWaterfall.getSuggestions(player); - for (String bannedSubCommand : bannedSubCommands) { - if (command.startsWith(bannedSubCommand)) { - event.setCancelled(true); - audiences.player(player).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.subcommand_denied)); - return; - } - } - } -} diff --git a/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/listeners/BungeeTabcompleteListener.java b/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/listeners/BungeeTabcompleteListener.java deleted file mode 100644 index a9b22ec..0000000 --- a/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/listeners/BungeeTabcompleteListener.java +++ /dev/null @@ -1,25 +0,0 @@ -package eu.endermite.commandwhitelist.waterfall.listeners; - -import eu.endermite.commandwhitelist.common.CWPermission; -import eu.endermite.commandwhitelist.common.CommandUtil; -import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Listener; -import net.md_5.bungee.event.EventHandler; - -public class BungeeTabcompleteListener implements Listener { - - @EventHandler - public void onTabcomplete(net.md_5.bungee.api.event.TabCompleteEvent event) { - if (!(event.getReceiver() instanceof ProxiedPlayer)) return; - ProxiedPlayer player = (ProxiedPlayer) event.getReceiver(); - if (event.getSuggestions().isEmpty()) return; - if (player.hasPermission(CWPermission.BYPASS.permission())) return; - CommandUtil.filterSuggestions( - event.getCursor(), - event.getSuggestions(), - CommandWhitelistWaterfall.getSuggestions(player) - ); - } - -} diff --git a/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/listeners/WaterfallDefineCommandsListener.java b/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/listeners/WaterfallDefineCommandsListener.java deleted file mode 100644 index 7f26aae..0000000 --- a/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/listeners/WaterfallDefineCommandsListener.java +++ /dev/null @@ -1,28 +0,0 @@ -package eu.endermite.commandwhitelist.waterfall.listeners; - -import eu.endermite.commandwhitelist.common.CWPermission; -import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Command; -import net.md_5.bungee.api.plugin.Listener; -import net.md_5.bungee.event.EventHandler; - -import java.util.HashMap; - -public class WaterfallDefineCommandsListener implements Listener { - - @EventHandler - public void onProxyDefineCommandsEvent(io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent event) { - if (event.getReceiver() instanceof ProxiedPlayer) { - ProxiedPlayer player = (ProxiedPlayer) event.getReceiver(); - if (player.hasPermission(CWPermission.BYPASS.permission())) return; - HashMap commandHashMap = new HashMap<>(); - CommandWhitelistWaterfall.getCommands(player).forEach(cmdName -> - CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands() - .stream() - .filter(commandEntry -> cmdName.equalsIgnoreCase(commandEntry.getValue().getName())) - .forEach(commandEntry -> commandHashMap.put(commandEntry.getKey(), commandEntry.getValue()))); - event.getCommands().values().removeIf((cmd) -> !commandHashMap.containsValue(cmd)); - } - } -} diff --git a/CommandWhitelistWaterfall/src/main/resources/bungee.yml b/CommandWhitelistWaterfall/src/main/resources/bungee.yml deleted file mode 100644 index 90938fe..0000000 --- a/CommandWhitelistWaterfall/src/main/resources/bungee.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: CommandWhitelist -author: YouHaveTrouble -version: ${project.version} -main: eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall -description: You decide what commands players can use or tab complete on your server! diff --git a/pom.xml b/pom.xml index 0f58d11..6908523 100644 --- a/pom.xml +++ b/pom.xml @@ -6,21 +6,15 @@ eu.endermite.commandwhitelist CommandWhitelist - 2.7.0 - - CommandWhitelistCommon - CommandWhitelistBukkit - CommandWhitelistVelocity - CommandWhitelistWaterfall - - pom + 3.0.0 CommandWhitelist - Control what commands players can use + 1.8 UTF-8 + https://youhavetrouble.me @@ -47,6 +41,16 @@ false ${project.name}-${project.version} + + + net.kyori + me.youhavetrouble + + + com.github.thatsmusic99 + me.youhavetrouble + + @@ -61,18 +65,76 @@ + + pluginwiki-repo + https://ci.pluginwiki.us/plugin/repository/everything/ + sonatype https://oss.sonatype.org/content/groups/public/ + + velocitypowered-repo + https://repo.velocitypowered.com/releases/ + + + papermc + https://papermc.io/repo/repository/maven-public/ + + + dmulloy2-repo + https://repo.dmulloy2.net/nexus/repository/public/ + + + com.github.thatsmusic99 + ConfigurationMaster-API + v2.0.0-BETA-6 + compile + net.kyori adventure-api - 4.11.0 + 4.13.1 compile + + net.kyori + adventure-platform-bukkit + 4.2.0 + compile + + + net.kyori + adventure-text-minimessage + 4.13.1 + compile + + + com.velocitypowered + velocity-api + 3.1.2-SNAPSHOT + provided + + + io.papermc.paper + paper-api + 1.19-R0.1-SNAPSHOT + provided + + + io.github.waterfallmc + waterfall-api + 1.19-R0.1-SNAPSHOT + provided + + + com.comphenix.protocol + ProtocolLib + 5.0.0 + provided + diff --git a/readme.md b/readme.md index f70f20b..f56bd32 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,8 @@ Command Whitelist is a plugin that allows you to control precisely what commands players can see and use. +

WARNING: This is an experimental branch, literally everything here is subject to change

+ [![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/youhavetrouble/commandwhitelist?style=flat-square)](https://www.codefactor.io/repository/github/youhavetrouble/commandwhitelist) [![GitHub all releases](https://img.shields.io/github/downloads/youhavetrouble/commandwhitelist/total?style=flat-square&label=direct%20release%20downloads)](https://github.com/YouHaveTrouble/CommandWhitelist/releases) [![Discord](https://img.shields.io/discord/821565102108573706?style=flat-square&color=%237289da&label=Discord)](https://discord.gg/j8KK5dGBps) @@ -15,7 +17,6 @@ precisely what commands players can see and use.
  • Overwrite default "no such command" message with your branding
  • Block tab completion
  • Block command execution
  • -
  • Block completion and execution of specified subcommands
  • Compatible versions: 1.13+ diff --git a/src/main/java/me/youhavetrouble/commandwhitelist/bukkit/CommandWhitelistBukkit.java b/src/main/java/me/youhavetrouble/commandwhitelist/bukkit/CommandWhitelistBukkit.java new file mode 100644 index 0000000..8046fc7 --- /dev/null +++ b/src/main/java/me/youhavetrouble/commandwhitelist/bukkit/CommandWhitelistBukkit.java @@ -0,0 +1,69 @@ +package me.youhavetrouble.commandwhitelist.bukkit; + +import me.youhavetrouble.commandwhitelist.bukkit.listeners.CommandSendListener; +import me.youhavetrouble.commandwhitelist.common.CWCommandEntry; +import me.youhavetrouble.commandwhitelist.common.CWGroup; +import me.youhavetrouble.commandwhitelist.common.ConfigCache; +import me.youhavetrouble.commandwhitelist.common.commands.CWCommand; +import net.kyori.adventure.platform.bukkit.BukkitAudiences; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CompletableFuture; + +public class CommandWhitelistBukkit extends JavaPlugin { + + private ConfigCache configCache; + private BukkitAudiences audiences; + + @Override + public void onEnable() { + reloadPluginConfig(); + audiences = BukkitAudiences.create(this); + getServer().getPluginManager().registerEvents(new CommandSendListener(this), this); + } + + public Set getCommands(Player player) { + HashSet commands = new HashSet<>(); + Map groups = configCache.getGroupList(); + for (Map.Entry groupEntry : groups.entrySet()) { + CWGroup group = groupEntry.getValue(); + String groupId = groupEntry.getKey(); + if (groupId.equalsIgnoreCase("default")) commands.addAll(group.getCommands()); + else if (player.hasPermission(group.getPermission())) commands.addAll(group.getCommands()); + } + return commands; + } + + private void reloadPluginConfig() { + File configFile = new File("plugins/CommandWhitelist/config.yml"); + if (configCache != null) { + configCache.reloadConfig(); + return; + } + try { + configCache = new ConfigCache(configFile, true, getSLF4JLogger()); + } catch (NoSuchMethodError e) { + configCache = new ConfigCache(configFile, true, null); + } + } + + public CompletableFuture reloadPluginConfig(CommandSender sender) { + return CompletableFuture.runAsync(() -> { + reloadPluginConfig(); + try { + for (Player p : Bukkit.getOnlinePlayers()) { + p.updateCommands(); + } + } catch (Exception ignored) {} + audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.config_reloaded)); + }); + } + +} diff --git a/src/main/java/me/youhavetrouble/commandwhitelist/bukkit/listeners/CommandSendListener.java b/src/main/java/me/youhavetrouble/commandwhitelist/bukkit/listeners/CommandSendListener.java new file mode 100644 index 0000000..f58f0cd --- /dev/null +++ b/src/main/java/me/youhavetrouble/commandwhitelist/bukkit/listeners/CommandSendListener.java @@ -0,0 +1,37 @@ +package me.youhavetrouble.commandwhitelist.bukkit.listeners; + +import me.youhavetrouble.commandwhitelist.bukkit.CommandWhitelistBukkit; +import me.youhavetrouble.commandwhitelist.common.CWCommandEntry; +import me.youhavetrouble.commandwhitelist.common.CWPermission; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandSendEvent; + +import java.util.Iterator; + +public class CommandSendListener implements Listener { + + private final CommandWhitelistBukkit plugin; + + public CommandSendListener(CommandWhitelistBukkit plugin) { + this.plugin = plugin; + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) + public void onCommandSend(PlayerCommandSendEvent event) { + Player player = event.getPlayer(); + if (player.hasPermission(CWPermission.BYPASS.permission())) return; + Iterator iterator = event.getCommands().iterator(); + while (iterator.hasNext()) { + String command = iterator.next(); + for (CWCommandEntry entry : plugin.getCommands(player)) { + if (entry.argumentMatches(command, 0)) continue; + iterator.remove(); + break; + } + } + } + +} diff --git a/src/main/java/me/youhavetrouble/commandwhitelist/common/CWCommandEntry.java b/src/main/java/me/youhavetrouble/commandwhitelist/common/CWCommandEntry.java new file mode 100644 index 0000000..208ccf8 --- /dev/null +++ b/src/main/java/me/youhavetrouble/commandwhitelist/common/CWCommandEntry.java @@ -0,0 +1,67 @@ +package me.youhavetrouble.commandwhitelist.common; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.regex.Pattern; + +public class CWCommandEntry { + + private final String rawEntry; + private final List parts; + + protected CWCommandEntry(String command) { + this.rawEntry = command; + String[] parts = command.split(" "); + this.parts = new ArrayList<>(parts.length); + for (String part : parts) { + Pattern pattern = Pattern.compile(part); + this.parts.add(pattern); + } + } + + /** + * Gets the command parts. + * @return command parts + */ + public List getParts() { + return Collections.unmodifiableList(parts); + } + + /** + * Gets the raw command entry as given in the constructor. + * @return raw command entry + */ + public String getRawEntry() { + return rawEntry; + } + + /** + * Checks if a full command input matches this command entry. + * @param command full command input + * @return true if the command matches this command entry + */ + public boolean matches(String command) { + if (command == null) return false; + if (command.startsWith("/")) command = command.substring(1); // Remove leading slash (if present) + String[] parts = command.split(" "); + if (parts.length != this.parts.size()) return false; + for (int i = 0; i < parts.length; i++) { + if (!this.parts.get(i).matcher(parts[i]).matches()) return false; + } + return true; + } + + /** + * Checks if a command argument matches this command entry. + * @param argument command argument + * @param index argument index + * @return true if the argument matches this command entry + */ + public boolean argumentMatches(String argument, int index) { + if (index < 0 || index >= parts.size()) return false; + return parts.get(index).matcher(argument).matches(); + } + + +} diff --git a/src/main/java/me/youhavetrouble/commandwhitelist/common/CWGroup.java b/src/main/java/me/youhavetrouble/commandwhitelist/common/CWGroup.java new file mode 100644 index 0000000..e3a9e66 --- /dev/null +++ b/src/main/java/me/youhavetrouble/commandwhitelist/common/CWGroup.java @@ -0,0 +1,46 @@ +package me.youhavetrouble.commandwhitelist.common; + +import java.util.*; + +public class CWGroup { + + private final String id; + private final HashSet commands = new HashSet<>(); + + public CWGroup(String id, Collection commands) { + this.id = id; + for (String command : commands) { + this.commands.add(new CWCommandEntry(command)); + } + } + + public String getId() { + return id; + } + + public String getPermission() { + return "commandwhitelist.group." + id; + } + + public Set getCommands() { + return commands; + } + + public void addCommand(String command) { + this.commands.add(new CWCommandEntry(command)); + } + + public void removeCommand(String command) { + commands.removeIf(cwCommandEntry -> cwCommandEntry.getRawEntry().equals(command)); + } + + public HashMap serialize() { + HashMap serializedGroup = new LinkedHashMap<>(); + List commands = new ArrayList<>(); + for (CWCommandEntry command : this.commands) { + commands.add(command.getRawEntry()); + } + serializedGroup.put("commands", commands); + return serializedGroup; + } +} diff --git a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/CWPermission.java b/src/main/java/me/youhavetrouble/commandwhitelist/common/CWPermission.java similarity index 53% rename from CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/CWPermission.java rename to src/main/java/me/youhavetrouble/commandwhitelist/common/CWPermission.java index 57cf792..9a61d38 100644 --- a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/CWPermission.java +++ b/src/main/java/me/youhavetrouble/commandwhitelist/common/CWPermission.java @@ -1,4 +1,4 @@ -package eu.endermite.commandwhitelist.common; +package me.youhavetrouble.commandwhitelist.common; public enum CWPermission { @@ -19,14 +19,9 @@ public enum CWPermission { /** * Allows to check specific group permission * - * @param configCache - * @param groupId - * @return */ - public static String getGroupPermission(ConfigCache configCache, String groupId) { - if (configCache.getGroupList().containsKey(groupId)) - return configCache.getGroupList().get(groupId).getPermission(); - return null; + public static String getGroupPermission(String groupId) { + return "commandwhitelist.group." + groupId; } } diff --git a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/CommandUtil.java b/src/main/java/me/youhavetrouble/commandwhitelist/common/CommandUtil.java similarity index 57% rename from CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/CommandUtil.java rename to src/main/java/me/youhavetrouble/commandwhitelist/common/CommandUtil.java index 1bc9e0a..77a8736 100644 --- a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/CommandUtil.java +++ b/src/main/java/me/youhavetrouble/commandwhitelist/common/CommandUtil.java @@ -1,4 +1,4 @@ -package eu.endermite.commandwhitelist.common; +package me.youhavetrouble.commandwhitelist.common; import io.github.thatsmusic99.configurationmaster.api.ConfigFile; @@ -10,28 +10,13 @@ import java.util.List; public class CommandUtil { - /** - * Filters blocked command suggestions from provided collection of strings - * - * @param buffer Command buffer - * @param suggestions Full suggestions list - * @param blockedSubCommands Subcommands to filter out - * @return Filtered list of suggestions - */ - public static List filterSuggestions(String buffer, Collection suggestions, Collection blockedSubCommands) { - if (buffer.startsWith("/")) - buffer = buffer.substring(1); - List suggestionsList = new ArrayList<>(suggestions); - if (suggestions.isEmpty() || blockedSubCommands.isEmpty()) return suggestionsList; - for (String s : blockedSubCommands) { - String scommand = cutLastArgument(s); - if (buffer.startsWith(scommand)) { - String slast = getLastArgument(s); - while (suggestionsList.contains(slast)) - suggestionsList.remove(slast); - } - } - return suggestionsList; + + public static List filterCommandList(Collection allCommands, Collection allowedCommands) { + List filteredCommands = new ArrayList<>(); + + + + return filteredCommands; } /** @@ -80,15 +65,10 @@ public class CommandUtil { parent.mkdir(); if (!file.exists()) file.createNewFile(); - } catch (IOException e) { - return false; - } - - ConfigFile dumpFile = ConfigFile.loadConfig(file); - dumpFile.set("commands", serverCommands); - try { + ConfigFile dumpFile = ConfigFile.loadConfig(file); + dumpFile.set("commands", serverCommands); dumpFile.save(); - } catch (IOException e) { + } catch (Exception e) { return false; } return true; diff --git a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/ConfigCache.java b/src/main/java/me/youhavetrouble/commandwhitelist/common/ConfigCache.java similarity index 87% rename from CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/ConfigCache.java rename to src/main/java/me/youhavetrouble/commandwhitelist/common/ConfigCache.java index 1ce6db2..5ac2fc8 100644 --- a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/ConfigCache.java +++ b/src/main/java/me/youhavetrouble/commandwhitelist/common/ConfigCache.java @@ -1,4 +1,4 @@ -package eu.endermite.commandwhitelist.common; +package me.youhavetrouble.commandwhitelist.common; import io.github.thatsmusic99.configurationmaster.api.ConfigFile; import io.github.thatsmusic99.configurationmaster.api.ConfigSection; @@ -30,11 +30,14 @@ public class ConfigCache { public boolean reloadConfig() { createFiles(); - config = ConfigFile.loadConfig(configFile); + try { + config = ConfigFile.loadConfig(configFile); + } catch (Exception e) { + throw new RuntimeException(e); + } config.addDefault("messages.prefix", "CommandWhitelist > "); config.addDefault("messages.command_denied", "No such command."); - config.addDefault("messages.subcommand_denied", "You cannot use this subcommand"); config.addDefault("messages.no_permission", "You don't have permission to do this."); config.addDefault("messages.no_such_subcommand", "No subcommand by that name."); config.addDefault("messages.config_reloaded", "Configuration reloaded."); @@ -75,12 +78,8 @@ public class ConfigCache { defaultCommands.add("tpaccept"); defaultCommands.add("tpdeny"); defaultCommands.add("warp"); - List defaultSubcommands = new ArrayList<>(); - defaultSubcommands.add("help about"); - String defaultCustomCommandDeniedMessage = ""; - - config.addDefault("groups.default", new CWGroup("default", defaultCommands, defaultSubcommands, defaultCustomCommandDeniedMessage).serialize()); + config.addDefault("groups.default", new CWGroup("default", defaultCommands).serialize()); prefix = config.getString("messages.prefix"); command_denied = config.getString("messages.command_denied"); @@ -106,7 +105,7 @@ public class ConfigCache { try { config.save(); return true; - } catch (IOException e) { + } catch (Exception e) { return false; } } @@ -134,16 +133,8 @@ public class ConfigCache { if (commands.contains(cmd)) continue; commands.add(cmd); } - List subCommands = new ArrayList<>(); - for (String subCmd : section.getStringList(id + ".subcommands")) { - if (!subCmd.contains(" ")) { - warn("CommandWhitelist - \"" + subCmd + "\" is not a subcommand. Skipping it."); - continue; - } - subCommands.add(subCmd); - } - String customCommandDeniedMessage = section.getString(id + ".custom_command_denied_message"); - return new CWGroup(id, commands, subCommands, customCommandDeniedMessage); + + return new CWGroup(id, commands); } public void saveCWGroup(String id, CWGroup group) { diff --git a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/commands/CWCommand.java b/src/main/java/me/youhavetrouble/commandwhitelist/common/commands/CWCommand.java similarity index 94% rename from CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/commands/CWCommand.java rename to src/main/java/me/youhavetrouble/commandwhitelist/common/commands/CWCommand.java index 94416bc..79a1011 100644 --- a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/commands/CWCommand.java +++ b/src/main/java/me/youhavetrouble/commandwhitelist/common/commands/CWCommand.java @@ -1,7 +1,8 @@ -package eu.endermite.commandwhitelist.common.commands; +package me.youhavetrouble.commandwhitelist.common.commands; -import eu.endermite.commandwhitelist.common.CWGroup; -import eu.endermite.commandwhitelist.common.ConfigCache; +import me.youhavetrouble.commandwhitelist.common.CWCommandEntry; +import me.youhavetrouble.commandwhitelist.common.CWGroup; +import me.youhavetrouble.commandwhitelist.common.ConfigCache; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.format.NamedTextColor; @@ -104,10 +105,7 @@ public class CWCommand { if (!adminPerm) return list; CWGroup group = config.getGroupList().get(args[1]); if (group == null) return list; - for (String s : group.getCommands()) { - if (s.startsWith(args[2])) - list.add(s); - } + // TODO return list; } if (args[0].equalsIgnoreCase("add")) { diff --git a/src/main/java/me/youhavetrouble/commandwhitelist/common/commands/CWCommandInterface.java b/src/main/java/me/youhavetrouble/commandwhitelist/common/commands/CWCommandInterface.java new file mode 100644 index 0000000..661bb23 --- /dev/null +++ b/src/main/java/me/youhavetrouble/commandwhitelist/common/commands/CWCommandInterface.java @@ -0,0 +1,13 @@ +package me.youhavetrouble.commandwhitelist.common.commands; + +import java.util.Collection; + +public interface CWCommandInterface { + + void execute(String[] args); + + Collection tabComplete(String[] args); + + String getPermission(); + +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..838d896 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,5 @@ +groups: + default: + commands: + - "spawn" + - "help version" \ No newline at end of file diff --git a/CommandWhitelistBukkit/src/main/resources/plugin.yml b/src/main/resources/plugin.yml similarity index 59% rename from CommandWhitelistBukkit/src/main/resources/plugin.yml rename to src/main/resources/plugin.yml index deaa1d7..569b90d 100644 --- a/CommandWhitelistBukkit/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,14 +1,14 @@ -name: CommandWhitelist -prefix: CommandWhitelist +name: "${project.name}" version: ${project.version} api-version: 1.13 -main: eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit -authors: [YouHaveTrouble] -website: youhavetrouble.me +main: "${project.groupId}.bukkit.CommandWhitelistBukkit" +authors: + - "YouHaveTrouble" +website: "${project.url}" folia-supported: true softdepend: - ProtocolLib -description: Control what commands players can use +description: "${project.description}" commands: commandwhitelist: aliases: