diff --git a/src/main/java/dev/plex/Plex.java b/src/main/java/dev/plex/Plex.java index 8d356e4..e127af2 100644 --- a/src/main/java/dev/plex/Plex.java +++ b/src/main/java/dev/plex/Plex.java @@ -164,7 +164,11 @@ public class Plex extends JavaPlugin PlexLog.log("Punishment System initialized"); commandBlockerManager = new CommandBlockerManager(); - getServer().getScheduler().scheduleSyncDelayedTask(this, () -> commandBlockerManager.syncCommands()); + // todo: make this a service lmao --v + getServer().getScheduler().scheduleSyncDelayedTask(this, () -> { + commandBlockerManager.syncCommands(); + PlexLog.log("Command Blocker commands loaded"); + }); PlexLog.log("Command Blocker initialized"); generateWorlds(); diff --git a/src/main/java/dev/plex/listener/impl/CmdBlockerListener.java b/src/main/java/dev/plex/listener/impl/CmdBlockerListener.java deleted file mode 100644 index 5576ae3..0000000 --- a/src/main/java/dev/plex/listener/impl/CmdBlockerListener.java +++ /dev/null @@ -1,55 +0,0 @@ -package dev.plex.listener.impl; - -import dev.plex.cache.DataUtils; -import dev.plex.cmdblocker.BaseCommand; -import dev.plex.cmdblocker.MatchCommand; -import dev.plex.cmdblocker.RegexCommand; -import dev.plex.listener.PlexListener; -import dev.plex.player.PlexPlayer; -import dev.plex.util.PlexUtils; -import net.kyori.adventure.text.minimessage.MiniMessage; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; - -public class CmdBlockerListener extends PlexListener -{ - @EventHandler(priority = EventPriority.HIGHEST) - public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) - { - if (!plugin.getCommandBlockerManager().loadedYet) - { - event.setCancelled(true); - return; - } - Player player = event.getPlayer(); - String message = event.getMessage().substring(1); - for (BaseCommand blockedCommand : plugin.getCommandBlockerManager().getBlockedCommands()) { - if (DataUtils.getPlayer(player.getUniqueId()).getRankFromString().ordinal() > blockedCommand.getRank().ordinal()) - { - return; - } - boolean isBlocked = false; - if (blockedCommand instanceof RegexCommand regexCommand) - { - if (regexCommand.getRegex().matcher(message).matches()) - { - isBlocked = true; - } - } - else if(blockedCommand instanceof MatchCommand matchCommand) - { - if (message.equalsIgnoreCase(matchCommand.getMessage()) || message.toLowerCase().startsWith(matchCommand.getMessage().toLowerCase() + " ")) - { - isBlocked = true; - } - } - if (isBlocked) - { - event.setCancelled(true); - player.sendMessage(MiniMessage.miniMessage().deserialize(PlexUtils.messageString("blockedCommandColor") + blockedCommand.getMessage())); - } - } - } -} diff --git a/src/main/java/dev/plex/listener/impl/CommandListener.java b/src/main/java/dev/plex/listener/impl/CommandListener.java index b393952..9b6270c 100644 --- a/src/main/java/dev/plex/listener/impl/CommandListener.java +++ b/src/main/java/dev/plex/listener/impl/CommandListener.java @@ -1,7 +1,13 @@ package dev.plex.listener.impl; +import dev.plex.cache.DataUtils; import dev.plex.cache.player.PlayerCache; +import dev.plex.cmdblocker.BaseCommand; +import dev.plex.cmdblocker.MatchCommand; +import dev.plex.cmdblocker.RegexCommand; import dev.plex.listener.PlexListener; +import dev.plex.util.PlexUtils; +import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -23,5 +29,44 @@ public class CommandListener extends PlexListener pl.sendMessage(ChatColor.GRAY + player.getName() + ": " + command); } }); + + if (!plugin.getCommandBlockerManager().loadedYet) + { + event.setCancelled(true); + return; + } + Player player = event.getPlayer(); + String message = event.getMessage().substring(1); + for (BaseCommand blockedCommand : plugin.getCommandBlockerManager().getBlockedCommands()) { + if (DataUtils.getPlayer(player.getUniqueId()).getRankFromString().ordinal() > blockedCommand.getRank().ordinal()) + { + continue; + } + boolean isBlocked = false; + if (blockedCommand instanceof RegexCommand regexCommand) + { + System.out.println(regexCommand.getRegex()); + System.out.println(message); + System.out.println(regexCommand.getRegex().matcher(message).results()); + if (regexCommand.getRegex().matcher(message).matches()) + { + isBlocked = true; + } + } + else if(blockedCommand instanceof MatchCommand matchCommand) + { + if (message.equalsIgnoreCase(matchCommand.getMatch()) || message.toLowerCase().startsWith(matchCommand.getMatch().toLowerCase() + " ")) + { + isBlocked = true; + } + } + if (isBlocked) + { + System.out.println("BLOCKED?!??!???!!!"); + event.setCancelled(true); + player.sendMessage(MiniMessage.miniMessage().deserialize(PlexUtils.messageString("blockedCommandColor") + blockedCommand.getMessage())); + return; + } + } } }