The command blocker is now functioning as per normal (#187)

This commit is contained in:
Nathan Curran 2020-02-27 14:31:21 +11:00 committed by GitHub
parent ce804ac23b
commit ecc907b535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 39 deletions

View File

@ -71,21 +71,20 @@ public class CommandBlocker extends FreedomService
final CommandBlockerRank rank = CommandBlockerRank.fromToken(parts[0]);
final CommandBlockerAction action = CommandBlockerAction.fromToken(parts[1]);
String commandName = parts[2].toLowerCase().substring(1);
String strCommand = parts[2].toLowerCase().substring(1);
final String message = (parts.length > 3 ? parts[3] : null);
if (rank == null || action == null || commandName == null || commandName.isEmpty())
if (rank == null || action == null || strCommand == null || strCommand.isEmpty())
{
FLog.warning("Invalid command blocker entry: " + rawEntry);
continue;
}
final String[] commandParts = commandName.split(" ");
String subCommand = null;
final String[] commandParts = strCommand.split(" ");
String commandName = strCommand.toLowerCase();
if (commandParts.length > 1)
{
commandName = commandParts[0];
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).trim().toLowerCase();
}
final Command command = commandMap.getCommand(commandName);
@ -95,25 +94,21 @@ public class CommandBlocker extends FreedomService
{
unknownCommands.add(commandName);
}
else
{
commandName = command.getName().toLowerCase();
}
if (entryList.containsKey(commandName))
if (entryList.containsKey(strCommand))
{
FLog.warning("Not blocking: /" + commandName + " - Duplicate entry exists!");
FLog.warning("Not blocking: /" + strCommand + " - Duplicate entry exists!");
continue;
}
final CommandBlockerEntry blockedCommandEntry = new CommandBlockerEntry(rank, action, commandName, subCommand, message);
final CommandBlockerEntry blockedCommandEntry = new CommandBlockerEntry(rank, action, strCommand, message);
entryList.put(blockedCommandEntry.getCommand(), blockedCommandEntry);
if (command != null)
{
for (String alias : command.getAliases())
{
entryList.put(alias.toLowerCase(), blockedCommandEntry);
entryList.put(strCommand.replaceFirst(commandName, alias), blockedCommandEntry);
}
}
}
@ -153,6 +148,7 @@ public class CommandBlocker extends FreedomService
// Format
command = command.toLowerCase().trim();
command = command.startsWith("/") ? command.substring(1) : command;
command = command.replaceAll("\"", "");
// Check for plugin specific commands
final String[] commandParts = command.split(" ");
@ -184,29 +180,13 @@ public class CommandBlocker extends FreedomService
return true;
}
// Obtain sub command, if it exists
String subCommand = null;
if (commandParts.length > 1)
{
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).toLowerCase();
}
// Obtain entry
final CommandBlockerEntry entry = entryList.get(commandParts[0]);
final CommandBlockerEntry entry = entryList.get(command);
if (entry == null)
{
return false;
}
// Validate sub command
if (entry.getSubCommand() != null)
{
if (subCommand == null || !subCommand.startsWith(entry.getSubCommand()))
{
return false;
}
}
if (entry.getRank().hasPermission(sender))
{
return false;

View File

@ -18,21 +18,13 @@ public class CommandBlockerEntry
@Getter
private final String command;
@Getter
private final String subCommand;
@Getter
private final String message;
public CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String message)
{
this(rank, action, command, null, message);
}
public CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String subCommand, String message)
{
this.rank = rank;
this.action = action;
this.command = command;
this.subCommand = ((subCommand == null) ? null : subCommand.toLowerCase().trim());
this.message = ((message == null || message.equals("_")) ? "That command is blocked." : message);
}