mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
instead of checking if a command starts with the message, check if each argument of the command is equal to the message until you can't check anymore
This commit is contained in:
parent
9f7ac310d9
commit
06fcf531af
@ -8,6 +8,7 @@ import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.services.impl.CommandBlockerService;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@ -44,14 +45,36 @@ public class CommandListener extends PlexListener
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||
String commandName = event.getMessage().split(" ")[0].replace("/", "");
|
||||
String arguments = StringUtils.normalizeSpace(event.getMessage().replace(event.getMessage().split(" ")[0], ""));
|
||||
String commandName = StringUtils.normalizeSpace(event.getMessage()).split(" ")[0].replace("/", "");
|
||||
String arguments = StringUtils.normalizeSpace(StringUtils.normalizeSpace(event.getMessage()).replace(event.getMessage().split(" ")[0], ""));
|
||||
PlexLog.debug("Checking Command: {0} with args {1}", commandName, arguments);
|
||||
AtomicReference<BlockedCommand> cmdRef = new AtomicReference<>();
|
||||
PlexLog.debug("Blocked Commands List: " + CommandBlockerService.getBLOCKED_COMMANDS().size());
|
||||
CommandBlockerService.getBLOCKED_COMMANDS().stream().filter(blockedCommand -> blockedCommand.getCommand() != null).forEach(blockedCommand ->
|
||||
{
|
||||
if (event.getMessage().replace("/", "").toLowerCase(Locale.ROOT).startsWith(blockedCommand.getCommand().toLowerCase(Locale.ROOT)))
|
||||
/*if (event.getMessage().replace("/", "").toLowerCase(Locale.ROOT).startsWith(blockedCommand.getCommand().toLowerCase(Locale.ROOT)))
|
||||
{
|
||||
PlexLog.debug("Used blocked command exactly matched");
|
||||
cmdRef.set(blockedCommand);
|
||||
return;
|
||||
}*/
|
||||
boolean matches = true;
|
||||
String[] args = blockedCommand.getCommand().split(" ");
|
||||
String[] cmdArgs = event.getMessage().replace("/", "").split(" ");
|
||||
for (int i = 0; i < args.length; i++)
|
||||
{
|
||||
if (i+1 > cmdArgs.length)
|
||||
{
|
||||
matches = false;
|
||||
break;
|
||||
}
|
||||
if (!args[i].equalsIgnoreCase(cmdArgs[i]))
|
||||
{
|
||||
matches = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (matches)
|
||||
{
|
||||
PlexLog.debug("Used blocked command exactly matched");
|
||||
cmdRef.set(blockedCommand);
|
||||
@ -92,15 +115,15 @@ public class CommandListener extends PlexListener
|
||||
{
|
||||
case "e" -> {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(Component.text(cmd.getMessage()).color(NamedTextColor.GRAY));
|
||||
event.getPlayer().sendMessage(PlexUtils.messageComponent("commandBlocked"));
|
||||
}
|
||||
case "a" -> {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(Component.text(cmd.getMessage()).color(NamedTextColor.GRAY));
|
||||
event.getPlayer().sendMessage(PlexUtils.messageComponent("commandBlocked"));
|
||||
}
|
||||
case "s" -> {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(Component.text(cmd.getMessage()).color(NamedTextColor.GRAY));
|
||||
event.getPlayer().sendMessage(PlexUtils.messageComponent("commandBlocked"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,10 +39,10 @@ public class CommandBlockerService extends AbstractService
|
||||
command.setRequiredLevel(args[1]);
|
||||
command.setRegex(args[2]);
|
||||
command.setMessage(s.substring(lastDelim + 1));
|
||||
PlexLog.debug("=Found regex blocked=");
|
||||
/*PlexLog.debug("=Found regex blocked=");
|
||||
PlexLog.debug(" Regex: " + command.getRegex());
|
||||
PlexLog.debug(" Message: " + command.getMessage());
|
||||
PlexLog.debug("====================");
|
||||
PlexLog.debug("====================");*/
|
||||
} else if (s.toLowerCase(Locale.ROOT).startsWith("m"))
|
||||
{
|
||||
command.setRequiredLevel(args[1]);
|
||||
@ -56,12 +56,12 @@ public class CommandBlockerService extends AbstractService
|
||||
}
|
||||
command.setCommandAliases(cmd.getAliases());
|
||||
command.getCommandAliases().add(command.getCommand().split(" ")[0]);
|
||||
PlexLog.debug("=Found command blocked=");
|
||||
/*PlexLog.debug("=Found command blocked=");
|
||||
PlexLog.debug(" Required Level: " + command.getRequiredLevel());
|
||||
PlexLog.debug(" Command: " + command.getCommand());
|
||||
PlexLog.debug(" Message: " + command.getMessage());
|
||||
PlexLog.debug(" Aliases: " + Arrays.toString(command.getCommandAliases().toArray(new String[0])));
|
||||
PlexLog.debug("====================");
|
||||
PlexLog.debug("====================");*/
|
||||
}
|
||||
if (command.getMessage().equalsIgnoreCase("_"))
|
||||
{
|
||||
@ -69,6 +69,7 @@ public class CommandBlockerService extends AbstractService
|
||||
}
|
||||
BLOCKED_COMMANDS.add(command);
|
||||
});
|
||||
PlexLog.log("Command Blocker has loaded {0} entries!", BLOCKED_COMMANDS.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -167,8 +167,7 @@ removedMobs: "<red>{0} - Removed {1} mobs"
|
||||
autoWipeDisabled: "<gray>Item wiping is currently disabled in the config!"
|
||||
allowDropsDisabled: "<gray>No longer allowing drops from players."
|
||||
allowDropsEnabled: "<gray>Now allowing drops from players."
|
||||
blockedCommandColor: "<gray>"
|
||||
commandBlocked: "That command is blocked."
|
||||
commandBlocked: "<gray>That command is blocked."
|
||||
# 0 - The command sender
|
||||
# 1 - The message being said
|
||||
sayCommand: "[Server: {0}] {1}"
|
Loading…
Reference in New Issue
Block a user