Skip to content

Commit b7d7646

Browse files
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".
1 parent 697a5e5 commit b7d7646

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>eu.endermite</groupId>
88
<artifactId>CommandWhitelist</artifactId>
9-
<version>1.7.7</version>
9+
<version>1.7.8</version>
1010
<packaging>jar</packaging>
1111

1212
<name>CommandWhitelist</name>

src/main/java/eu/endermite/commandwhitelist/spigot/listeners/PlayerCommandPreProcessListener.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreproce
2727
for (String comm : s.getValue()) {
2828
comm = comm.toLowerCase();
2929
if (command.equalsIgnoreCase(comm) || command.startsWith(comm + " ")) {
30-
String rawCmd = event.getMessage();
3130
List<String> bannedSubCommands = CommandsList.getSuggestions(player);
3231
for (String bannedSubCommand : bannedSubCommands) {
33-
if (rawCmd.startsWith(bannedSubCommand)) {
32+
if (command.startsWith(bannedSubCommand)) {
3433
event.setCancelled(true);
3534
ConfigCache config = CommandWhitelist.getConfigCache();
3635
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getSubCommandDenied())));

src/main/java/eu/endermite/commandwhitelist/spigot/listeners/TabCompleteBlockerListener.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,22 @@ public void onCommandTabComplete(org.bukkit.event.server.TabCompleteEvent event)
1414
return;
1515
Player player = (Player) event.getSender();
1616
String buffer = event.getBuffer();
17-
String cmd = buffer.replace(CommandsList.getLastArgument(buffer), "");
17+
1818
List<String> blockedCommands = CommandsList.getSuggestions(player);
1919
List<String> suggestions = event.getCompletions();
20+
2021
for (String s : blockedCommands) {
2122
String slast = CommandsList.getLastArgument(s);
2223
String scommand = s.replace(slast, "");
23-
cmd = cmd.replace(CommandsList.getLastArgument(cmd), "");
24-
if (cmd.startsWith("/" + scommand)) {
24+
String[] cmdSplit = buffer.split(" ");
25+
StringBuilder cmdBuilder = new StringBuilder();
26+
for (int i = 0; i <= cmdSplit.length-1; i++)
27+
cmdBuilder.append(cmdSplit[i]).append(" ");
28+
29+
String cmd = cmdBuilder.toString();
30+
if (cmd.startsWith("/"+scommand)) {
31+
// This sometimes throws exceptions. No clue why, it just does. try/catch is the only fix.
32+
// Probably happening when plugin adds suggestions in this event on the same priority - not confirmed.
2533
try {
2634
while (suggestions.contains(slast))
2735
suggestions.remove(slast);

0 commit comments

Comments
 (0)