final update before looking into...

...reusing preexisting plex code for different parts. dont merge until review has been done.
This commit is contained in:
9378062 2022-04-08 12:26:46 -04:00
parent 797372f4b6
commit d756dcb2f4
7 changed files with 35 additions and 2 deletions

View File

@ -14,4 +14,9 @@ public class BaseCommand
rank = r;
message = m;
}
public String toString()
{
return "BaseCommand (Rank: " + rank.name() + ", Message: " + message + ")";
}
}

View File

@ -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;
}
}

View File

@ -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() + ")";
}
}

View File

@ -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() + ")";
}
}

View File

@ -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)
{

View File

@ -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)

View File

@ -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);