mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 10:05:59 +00:00
Revert command blocker as the one pushed was not working whatsoever
This commit is contained in:
parent
4a5032bb4c
commit
925fe4a4b2
@ -71,20 +71,21 @@ public class CommandBlocker extends FreedomService
|
|||||||
|
|
||||||
final CommandBlockerRank rank = CommandBlockerRank.fromToken(parts[0]);
|
final CommandBlockerRank rank = CommandBlockerRank.fromToken(parts[0]);
|
||||||
final CommandBlockerAction action = CommandBlockerAction.fromToken(parts[1]);
|
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);
|
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);
|
FLog.warning("Invalid command blocker entry: " + rawEntry);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String[] commandParts = strCommand.split(" ");
|
final String[] commandParts = commandName.split(" ");
|
||||||
String commandName = strCommand.toLowerCase();
|
String subCommand = null;
|
||||||
if (commandParts.length > 1)
|
if (commandParts.length > 1)
|
||||||
{
|
{
|
||||||
commandName = commandParts[0];
|
commandName = commandParts[0];
|
||||||
|
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).trim().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
final Command command = commandMap.getCommand(commandName);
|
final Command command = commandMap.getCommand(commandName);
|
||||||
@ -94,21 +95,25 @@ public class CommandBlocker extends FreedomService
|
|||||||
{
|
{
|
||||||
unknownCommands.add(commandName);
|
unknownCommands.add(commandName);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (entryList.containsKey(strCommand))
|
|
||||||
{
|
{
|
||||||
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;
|
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);
|
entryList.put(blockedCommandEntry.getCommand(), blockedCommandEntry);
|
||||||
|
|
||||||
if (command != null)
|
if (command != null)
|
||||||
{
|
{
|
||||||
for (String alias : command.getAliases())
|
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
|
// Format
|
||||||
command = command.toLowerCase().trim();
|
command = command.toLowerCase().trim();
|
||||||
command = command.startsWith("/") ? command.substring(1) : command;
|
command = command.startsWith("/") ? command.substring(1) : command;
|
||||||
command = command.replaceAll("\"", "");
|
|
||||||
|
|
||||||
// Check for plugin specific commands
|
// Check for plugin specific commands
|
||||||
final String[] commandParts = command.split(" ");
|
final String[] commandParts = command.split(" ");
|
||||||
@ -180,13 +184,29 @@ public class CommandBlocker extends FreedomService
|
|||||||
return true;
|
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
|
// Obtain entry
|
||||||
final CommandBlockerEntry entry = entryList.get(command);
|
final CommandBlockerEntry entry = entryList.get(commandParts[0]);
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate sub command
|
||||||
|
if (entry.getSubCommand() != null)
|
||||||
|
{
|
||||||
|
if (subCommand == null || !subCommand.startsWith(entry.getSubCommand()))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (entry.getRank().hasPermission(sender))
|
if (entry.getRank().hasPermission(sender))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -18,13 +18,21 @@ public class CommandBlockerEntry
|
|||||||
@Getter
|
@Getter
|
||||||
private final String command;
|
private final String command;
|
||||||
@Getter
|
@Getter
|
||||||
|
private final String subCommand;
|
||||||
|
@Getter
|
||||||
private final String message;
|
private final String message;
|
||||||
|
|
||||||
public CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, 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.rank = rank;
|
||||||
this.action = action;
|
this.action = action;
|
||||||
this.command = command;
|
this.command = command;
|
||||||
|
this.subCommand = ((subCommand == null) ? null : subCommand.toLowerCase().trim());
|
||||||
this.message = ((message == null || message.equals("_")) ? "That command is blocked." : message);
|
this.message = ((message == null || message.equals("_")) ? "That command is blocked." : message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user