Compare commits

...

4 Commits

Author SHA1 Message Date
YouHaveTrouble b7d7646641 fix subcommand blocker
subcommandblocker broke when command included part of the subcommand, so for ex. /help he would remove "he" from the command and it would return as "/lp".
2021-07-02 16:14:20 +02:00
YouHaveTrouble 697a5e5720 priority shift 2021-06-02 21:22:12 +02:00
YouHaveTrouble 598756fec0 version bump 2021-06-02 16:00:36 +02:00
YouHaveTrouble 95ea1d8319 this probably needs to be handled anyway
ignoreCancelled seems to introduce the issue of completions not being filtered in some cases, and it shouldn't cause problems by running anyway
2021-06-02 15:52:13 +02:00
4 changed files with 14 additions and 7 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>eu.endermite</groupId> <groupId>eu.endermite</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>1.7.6</version> <version>1.7.8</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>CommandWhitelist</name> <name>CommandWhitelist</name>
@@ -27,10 +27,9 @@ public class PlayerCommandPreProcessListener implements Listener {
for (String comm : s.getValue()) { for (String comm : s.getValue()) {
comm = comm.toLowerCase(); comm = comm.toLowerCase();
if (command.equalsIgnoreCase(comm) || command.startsWith(comm + " ")) { if (command.equalsIgnoreCase(comm) || command.startsWith(comm + " ")) {
String rawCmd = event.getMessage();
List<String> bannedSubCommands = CommandsList.getSuggestions(player); List<String> bannedSubCommands = CommandsList.getSuggestions(player);
for (String bannedSubCommand : bannedSubCommands) { for (String bannedSubCommand : bannedSubCommands) {
if (rawCmd.startsWith(bannedSubCommand)) { if (command.startsWith(bannedSubCommand)) {
event.setCancelled(true); event.setCancelled(true);
ConfigCache config = CommandWhitelist.getConfigCache(); ConfigCache config = CommandWhitelist.getConfigCache();
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getSubCommandDenied()))); player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getSubCommandDenied())));
@@ -8,7 +8,7 @@ import org.bukkit.event.Listener;
import java.util.*; import java.util.*;
public class PlayerCommandSendListener implements Listener { public class PlayerCommandSendListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL)
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandSendEvent event) { public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandSendEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player.hasPermission("commandwhitelist.bypass")) if (player.hasPermission("commandwhitelist.bypass"))
@@ -14,14 +14,22 @@ public class TabCompleteBlockerListener implements Listener {
return; return;
Player player = (Player) event.getSender(); Player player = (Player) event.getSender();
String buffer = event.getBuffer(); String buffer = event.getBuffer();
String cmd = buffer.replace(CommandsList.getLastArgument(buffer), "");
List<String> blockedCommands = CommandsList.getSuggestions(player); List<String> blockedCommands = CommandsList.getSuggestions(player);
List<String> suggestions = event.getCompletions(); List<String> suggestions = event.getCompletions();
for (String s : blockedCommands) { for (String s : blockedCommands) {
String slast = CommandsList.getLastArgument(s); String slast = CommandsList.getLastArgument(s);
String scommand = s.replace(slast, ""); String scommand = s.replace(slast, "");
cmd = cmd.replace(CommandsList.getLastArgument(cmd), ""); String[] cmdSplit = buffer.split(" ");
StringBuilder cmdBuilder = new StringBuilder();
for (int i = 0; i <= cmdSplit.length-1; i++)
cmdBuilder.append(cmdSplit[i]).append(" ");
String cmd = cmdBuilder.toString();
if (cmd.startsWith("/"+scommand)) { if (cmd.startsWith("/"+scommand)) {
// This sometimes throws exceptions. No clue why, it just does. try/catch is the only fix.
// Probably happening when plugin adds suggestions in this event on the same priority - not confirmed.
try { try {
while (suggestions.contains(slast)) while (suggestions.contains(slast))
suggestions.remove(slast); suggestions.remove(slast);