From 5f7a89d7cd3bab3013a7fd72311cd314c534a871 Mon Sep 17 00:00:00 2001 From: 9378062 Date: Fri, 8 Apr 2022 10:17:39 -0400 Subject: [PATCH] mOre FEATURES!! (+fixes) --- .../cmdblocker/CommandBlockerManager.java | 27 ++++++++++++++++--- .../plex/listener/impl/CommandListener.java | 2 +- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/main/java/dev/plex/cmdblocker/CommandBlockerManager.java b/src/main/java/dev/plex/cmdblocker/CommandBlockerManager.java index 8821876..7b26bf7 100644 --- a/src/main/java/dev/plex/cmdblocker/CommandBlockerManager.java +++ b/src/main/java/dev/plex/cmdblocker/CommandBlockerManager.java @@ -4,9 +4,13 @@ import dev.plex.Plex; import dev.plex.rank.enums.Rank; import dev.plex.util.PlexUtils; import lombok.Getter; +import org.bukkit.command.Command; import org.bukkit.command.PluginCommand; +import org.bukkit.command.PluginCommandYamlParser; +import org.bukkit.plugin.Plugin; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.regex.Pattern; @@ -73,15 +77,30 @@ public class CommandBlockerManager } else if (rawType.equals("m")) { - String blockedArgs = regexOrMatch.substring(regexOrMatch.indexOf(' ') + 1); - PluginCommand pluginCommand = Plex.get().getServer().getPluginCommand(regexOrMatch.substring(0, regexOrMatch.indexOf(' '))); + int ind = regexOrMatch.indexOf(' '); + if (ind == -1 && regexOrMatch.endsWith(":")) + { + //block all commands from this plugin for the specified rank + Plugin plugin = Arrays.stream(Plex.get().getServer().getPluginManager().getPlugins()).findAny().orElse(null); + if (plugin != null) + { + List commandList = PluginCommandYamlParser.parse(plugin); + for (Command command : commandList) + { + blockedCommands.add(new MatchCommand(command.getName(), rank, message)); + } + } + } + String blockedArgs = ind == -1 ? "" : regexOrMatch.substring(ind + 1); + if (!blockedArgs.isEmpty()) blockedArgs = " " + blockedArgs; // necessary in case no args + PluginCommand pluginCommand = Plex.get().getServer().getPluginCommand(ind == -1 ? regexOrMatch : regexOrMatch.substring(0, ind)); if (pluginCommand != null) { - blockedCommands.add(new MatchCommand(pluginCommand.getName() + " " + blockedArgs, rank, message)); + blockedCommands.add(new MatchCommand(pluginCommand.getName() + blockedArgs, rank, message)); List aliases = pluginCommand.getAliases(); for (String alias : aliases) { - blockedCommands.add(new MatchCommand(alias + " " + blockedArgs, rank, message)); + blockedCommands.add(new MatchCommand(alias + blockedArgs, rank, message)); } } } diff --git a/src/main/java/dev/plex/listener/impl/CommandListener.java b/src/main/java/dev/plex/listener/impl/CommandListener.java index 1009f0e..6abb6ff 100644 --- a/src/main/java/dev/plex/listener/impl/CommandListener.java +++ b/src/main/java/dev/plex/listener/impl/CommandListener.java @@ -36,7 +36,7 @@ public class CommandListener extends PlexListener return; } Player player = event.getPlayer(); - String message = event.getMessage().substring(1); + String message = event.getMessage().substring(1).stripLeading(); // stripLeading() is VITAL for workaround blocking (/ minecraft:summon) for (BaseCommand blockedCommand : plugin.getCommandBlockerManager().getBlockedCommands()) { if (DataUtils.getPlayer(player.getUniqueId()).getRankFromString().ordinal() > blockedCommand.getRank().ordinal()) {