diff --git a/src/main/java/dev/plex/Plex.java b/src/main/java/dev/plex/Plex.java index cdbf957..8d356e4 100644 --- a/src/main/java/dev/plex/Plex.java +++ b/src/main/java/dev/plex/Plex.java @@ -164,6 +164,7 @@ public class Plex extends JavaPlugin PlexLog.log("Punishment System initialized"); commandBlockerManager = new CommandBlockerManager(); + getServer().getScheduler().scheduleSyncDelayedTask(this, () -> commandBlockerManager.syncCommands()); PlexLog.log("Command Blocker initialized"); generateWorlds(); diff --git a/src/main/java/dev/plex/cmdblocker/CommandBlockerManager.java b/src/main/java/dev/plex/cmdblocker/CommandBlockerManager.java index 10a13a9..43fa5f7 100644 --- a/src/main/java/dev/plex/cmdblocker/CommandBlockerManager.java +++ b/src/main/java/dev/plex/cmdblocker/CommandBlockerManager.java @@ -4,7 +4,6 @@ import dev.plex.Plex; import dev.plex.rank.enums.Rank; import dev.plex.util.PlexUtils; import lombok.Getter; -import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.command.PluginCommand; import java.util.ArrayList; @@ -16,6 +15,8 @@ public class CommandBlockerManager { private List blockedCommands = new ArrayList<>(); + public boolean loadedYet = false; + public void syncCommands() { blockedCommands.clear(); @@ -41,7 +42,31 @@ public class CommandBlockerManager pieces.set(3, PlexUtils.messageString("commandBlocked")); } - Rank rank = Plex.get().getRankManager().getRankFromString(pieces.get(1)); + Rank rank; + + switch (pieces.get(1)) + { + case "i": + rank = Rank.IMPOSTOR; + break; + case "n": + rank = Rank.NONOP; + break; + case "o": + rank = Rank.OP; + break; + case "a": + rank = Rank.ADMIN; + break; + case "s": + rank = Rank.SENIOR_ADMIN; + break; + case "e": + rank = Rank.EXECUTIVE; + break; + default: + rank = Rank.EXECUTIVE; + } if (pieces.get(0).equals("r")) { @@ -49,11 +74,11 @@ public class CommandBlockerManager } else if (pieces.get(0).equals("m")) { - blockedCommands.add(new MatchCommand(pieces.get(2), rank, pieces.get(3))); String blockedArgs = pieces.get(2).substring(pieces.get(2).indexOf(' ') + 1); PluginCommand pluginCommand = Plex.get().getServer().getPluginCommand(pieces.get(2).substring(0, pieces.get(2).indexOf(' '))); if (pluginCommand != null) { + blockedCommands.add(new MatchCommand(pluginCommand.getName() + " " + blockedArgs, rank, pieces.get(3))); List aliases = pluginCommand.getAliases(); for (String alias : aliases) { @@ -62,5 +87,7 @@ public class CommandBlockerManager } } } + + loadedYet = true; } } diff --git a/src/main/java/dev/plex/listener/impl/CmdBlockerListener.java b/src/main/java/dev/plex/listener/impl/CmdBlockerListener.java index b7b1723..5576ae3 100644 --- a/src/main/java/dev/plex/listener/impl/CmdBlockerListener.java +++ b/src/main/java/dev/plex/listener/impl/CmdBlockerListener.java @@ -1,9 +1,11 @@ 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; @@ -16,17 +18,21 @@ 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); - // check if commands are blocked here - // DEFAULT message is named "commandBlocked" for (BaseCommand blockedCommand : plugin.getCommandBlockerManager().getBlockedCommands()) { - //first check rank for if it applies - //then check if command is blocked + if (DataUtils.getPlayer(player.getUniqueId()).getRankFromString().ordinal() > blockedCommand.getRank().ordinal()) + { + return; + } boolean isBlocked = false; if (blockedCommand instanceof RegexCommand regexCommand) { - // regex if (regexCommand.getRegex().matcher(message).matches()) { isBlocked = true; @@ -34,7 +40,6 @@ public class CmdBlockerListener extends PlexListener } else if(blockedCommand instanceof MatchCommand matchCommand) { - // match command if (message.equalsIgnoreCase(matchCommand.getMessage()) || message.toLowerCase().startsWith(matchCommand.getMessage().toLowerCase() + " ")) { isBlocked = true; diff --git a/src/main/java/dev/plex/services/ServiceManager.java b/src/main/java/dev/plex/services/ServiceManager.java index 10e9b83..f822215 100644 --- a/src/main/java/dev/plex/services/ServiceManager.java +++ b/src/main/java/dev/plex/services/ServiceManager.java @@ -45,7 +45,16 @@ public class ServiceManager { if (!service.isRepeating()) { - BukkitTask task = Bukkit.getScheduler().runTask(Plex.get(), service::run); + int time = service.repeatInSeconds(); + BukkitTask task; + if (time == 0) + { + task = Bukkit.getScheduler().runTask(Plex.get(), service::run); + } + else + { + task = Bukkit.getScheduler().runTaskLater(Plex.get(), service::run, time); + } service.setTaskId(task.getTaskId()); } else if (service.isRepeating() && service.isAsynchronous()) diff --git a/src/main/resources/commands.yml b/src/main/resources/commands.yml index 1e0d279..6103b84 100644 --- a/src/main/resources/commands.yml +++ b/src/main/resources/commands.yml @@ -7,7 +7,8 @@ # Symbols to use: # - r for RegEx # - m for matching -# - The ranks are "e" for everyone, "a" for admin and "s" for senior admin +# - The ranks are "e" for executive and below, "a" for admin and below, "s" for senior admin and below, +######## TODO: DOCUMENT ALL OTHER LETTERS!! ^^^^ # - The command is just the command without slashes. Optional arguments are specified as well # - Finally the block message. MUST NOT CONTAIN ":". Use _ to use the default command blocked message as specified in messages.yml, or you can optionally put your own in # @@ -16,4 +17,4 @@ # - "r:e:(.*:):Plugin specific commands are disabled" blockedCommands: - "m:e:mail sendall:You cannot send messages to everyone on the server" - - "r:e:[^ ]+:.*:Plugin specific commands are disabled" \ No newline at end of file + - "r:e:^[^ ]+::Plugin specific commands are disabled" \ No newline at end of file