mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-11 22:16:57 +00:00
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".
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>eu.endermite</groupId>
|
<groupId>eu.endermite</groupId>
|
||||||
<artifactId>CommandWhitelist</artifactId>
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
<version>1.7.7</version>
|
<version>1.7.8</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>CommandWhitelist</name>
|
<name>CommandWhitelist</name>
|
||||||
|
|||||||
+1
-2
@@ -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())));
|
||||||
|
|||||||
+11
-3
@@ -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(" ");
|
||||||
if (cmd.startsWith("/" + scommand)) {
|
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 {
|
try {
|
||||||
while (suggestions.contains(slast))
|
while (suggestions.contains(slast))
|
||||||
suggestions.remove(slast);
|
suggestions.remove(slast);
|
||||||
|
|||||||
Reference in New Issue
Block a user