Revert command blocker as the one pushed was not working whatsoever

This commit is contained in:
Ivan 2020-03-27 19:53:00 -04:00
parent 4a5032bb4c
commit 925fe4a4b2
2 changed files with 40 additions and 12 deletions

View file

@ -71,20 +71,21 @@ public class CommandBlocker extends FreedomService
final CommandBlockerRank rank = CommandBlockerRank.fromToken(parts[0]);
final CommandBlockerAction action = CommandBlockerAction.fromToken(parts[1]);
String strCommand = parts[2].toLowerCase().substring(1);
String commandName = parts[2].toLowerCase().substring(1);
final String message = (parts.length > 3 ? parts[3] : null);
if (rank == null || action == null || strCommand == null || strCommand.isEmpty())
if (rank == null || action == null || commandName == null || commandName.isEmpty())
{
FLog.warning("Invalid command blocker entry: " + rawEntry);
continue;
}
final String[] commandParts = strCommand.split(" ");
String commandName = strCommand.toLowerCase();
final String[] commandParts = commandName.split(" ");
String subCommand = null;
if (commandParts.length > 1)
{
commandName = commandParts[0];
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).trim().toLowerCase();
}
final Command command = commandMap.getCommand(commandName);
@ -94,21 +95,25 @@ public class CommandBlocker extends FreedomService
{
unknownCommands.add(commandName);
}
if (entryList.containsKey(strCommand))
else
{
FLog.warning("Not blocking: /" + strCommand + " - Duplicate entry exists!");
commandName = command.getName().toLowerCase();
}
if (entryList.containsKey(commandName))
{
FLog.warning("Not blocking: /" + commandName + " - Duplicate entry exists!");
continue;
}
final CommandBlockerEntry blockedCommandEntry = new CommandBlockerEntry(rank, action, strCommand, message);
final CommandBlockerEntry blockedCommandEntry = new CommandBlockerEntry(rank, action, commandName, subCommand, message);
entryList.put(blockedCommandEntry.getCommand(), blockedCommandEntry);
if (command != null)
{
for (String alias : command.getAliases())
{
entryList.put(strCommand.replaceFirst(commandName, alias), blockedCommandEntry);
entryList.put(alias.toLowerCase(), blockedCommandEntry);
}
}
}
@ -148,7 +153,6 @@ 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(" ");
@ -180,13 +184,29 @@ 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(command);
final CommandBlockerEntry entry = entryList.get(commandParts[0]);
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,13 +18,21 @@ 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);
}
@ -43,4 +51,4 @@ public class CommandBlockerEntry
}
FUtil.playerMsg(sender, FUtil.colorize(message));
}
}
}