Skip to content

Commit

Permalink
fix subcommand blocker
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
YouHaveTrouble committed Jul 2, 2021
1 parent 697a5e5 commit b7d7646
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>eu.endermite</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>1.7.7</version>
<version>1.7.8</version>
<packaging>jar</packaging>

<name>CommandWhitelist</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreproce
for (String comm : s.getValue()) {
comm = comm.toLowerCase();
if (command.equalsIgnoreCase(comm) || command.startsWith(comm + " ")) {
String rawCmd = event.getMessage();
List<String> bannedSubCommands = CommandsList.getSuggestions(player);
for (String bannedSubCommand : bannedSubCommands) {
if (rawCmd.startsWith(bannedSubCommand)) {
if (command.startsWith(bannedSubCommand)) {
event.setCancelled(true);
ConfigCache config = CommandWhitelist.getConfigCache();
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getSubCommandDenied())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ public void onCommandTabComplete(org.bukkit.event.server.TabCompleteEvent event)
return;
Player player = (Player) event.getSender();
String buffer = event.getBuffer();
String cmd = buffer.replace(CommandsList.getLastArgument(buffer), "");

List<String> blockedCommands = CommandsList.getSuggestions(player);
List<String> suggestions = event.getCompletions();

for (String s : blockedCommands) {
String slast = CommandsList.getLastArgument(s);
String scommand = s.replace(slast, "");
cmd = cmd.replace(CommandsList.getLastArgument(cmd), "");
if (cmd.startsWith("/" + scommand)) {
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)) {
// 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 {
while (suggestions.contains(slast))
suggestions.remove(slast);
Expand Down

0 comments on commit b7d7646

Please sign in to comment.