diff --git a/src/main/java/dev/plex/cmdblocker/BaseCommand.java b/src/main/java/dev/plex/cmdblocker/BaseCommand.java index 95bc913..9618431 100644 --- a/src/main/java/dev/plex/cmdblocker/BaseCommand.java +++ b/src/main/java/dev/plex/cmdblocker/BaseCommand.java @@ -14,4 +14,9 @@ public class BaseCommand rank = r; message = m; } + + public String toString() + { + return "BaseCommand (Rank: " + rank.name() + ", Message: " + message + ")"; + } } diff --git a/src/main/java/dev/plex/cmdblocker/CommandBlockerManager.java b/src/main/java/dev/plex/cmdblocker/CommandBlockerManager.java index 35ff998..8dfdd39 100644 --- a/src/main/java/dev/plex/cmdblocker/CommandBlockerManager.java +++ b/src/main/java/dev/plex/cmdblocker/CommandBlockerManager.java @@ -2,6 +2,7 @@ package dev.plex.cmdblocker; import dev.plex.Plex; import dev.plex.rank.enums.Rank; +import dev.plex.util.PlexLog; import dev.plex.util.PlexUtils; import lombok.Getter; import org.bukkit.command.Command; @@ -114,6 +115,11 @@ public class CommandBlockerManager } } + PlexLog.debug("Blocked commands:"); + for (BaseCommand blockedCommand : blockedCommands) { + PlexLog.debug(" - {0}", blockedCommand); + } + loadedYet = true; } } diff --git a/src/main/java/dev/plex/cmdblocker/MatchCommand.java b/src/main/java/dev/plex/cmdblocker/MatchCommand.java index 7d98ed9..7b8721a 100644 --- a/src/main/java/dev/plex/cmdblocker/MatchCommand.java +++ b/src/main/java/dev/plex/cmdblocker/MatchCommand.java @@ -13,4 +13,9 @@ public class MatchCommand extends BaseCommand super(r2, m1); match = r1; } + + public String toString() + { + return "MatchCommand (Rank: " + getRank().name() + ", Match: " + match + ", Message: " + getMessage() + ")"; + } } diff --git a/src/main/java/dev/plex/cmdblocker/RegexCommand.java b/src/main/java/dev/plex/cmdblocker/RegexCommand.java index 84d2e30..9ade48f 100644 --- a/src/main/java/dev/plex/cmdblocker/RegexCommand.java +++ b/src/main/java/dev/plex/cmdblocker/RegexCommand.java @@ -15,4 +15,9 @@ public class RegexCommand extends BaseCommand super(r2, m1); regex = r1; } + + public String toString() + { + return "RegexCommand (Rank: " + getRank().name() + ", Regex: " + regex.toString() + ", Message: " + getMessage() + ")"; + } } \ No newline at end of file diff --git a/src/main/java/dev/plex/listener/impl/CommandListener.java b/src/main/java/dev/plex/listener/impl/CommandListener.java index e2a67ca..60c7f69 100644 --- a/src/main/java/dev/plex/listener/impl/CommandListener.java +++ b/src/main/java/dev/plex/listener/impl/CommandListener.java @@ -7,7 +7,6 @@ import dev.plex.cmdblocker.MatchCommand; import dev.plex.cmdblocker.RegexCommand; import dev.plex.listener.PlexListener; import dev.plex.player.PlexPlayer; -import dev.plex.rank.enums.Rank; import dev.plex.util.PlexUtils; import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.Bukkit; @@ -41,10 +40,11 @@ public class CommandListener extends PlexListener String message = event.getMessage().substring(1).stripLeading(); // stripLeading() is VITAL for workaround blocking (/ minecraft:summon) for (BaseCommand blockedCommand : plugin.getCommandBlockerManager().getBlockedCommands()) { PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId()); - if (Math.min(plexPlayer.getRankFromString().ordinal(), (plexPlayer.isAdminActive() ? Rank.EXECUTIVE : Rank.OP).ordinal()) > blockedCommand.getRank().ordinal()) + if (!plexPlayer.getRepresentedRank().isAtMost(blockedCommand.getRank())) { continue; } + boolean isBlocked = false; if (blockedCommand instanceof RegexCommand regexCommand) { diff --git a/src/main/java/dev/plex/player/PlexPlayer.java b/src/main/java/dev/plex/player/PlexPlayer.java index 62502b9..1a3657f 100644 --- a/src/main/java/dev/plex/player/PlexPlayer.java +++ b/src/main/java/dev/plex/player/PlexPlayer.java @@ -115,6 +115,13 @@ public class PlexPlayer } } + public Rank getRepresentedRank() + { + int representedLevel = this.getRankFromString().getLevel(); + if (!this.adminActive) representedLevel = Math.min(Rank.ADMIN.getLevel(), representedLevel); + return Rank.values()[representedLevel]; + } + public void loadPunishments() { if (Plex.get().getStorageType() != StorageType.MONGODB) diff --git a/src/main/java/dev/plex/rank/enums/Rank.java b/src/main/java/dev/plex/rank/enums/Rank.java index 177b9a0..8df56a5 100644 --- a/src/main/java/dev/plex/rank/enums/Rank.java +++ b/src/main/java/dev/plex/rank/enums/Rank.java @@ -45,6 +45,11 @@ public enum Rank return this.level >= rank.getLevel(); } + public boolean isAtMost(Rank rank) + { + return this.level <= rank.getLevel(); + } + public Component getPrefix() { return MiniMessage.miniMessage().deserialize(this.prefix);