switch statements look cleaner here

This commit is contained in:
Taah 2022-04-08 00:32:53 -07:00
parent 38e79fd917
commit 9c5a557316

View File

@ -1,6 +1,5 @@
package dev.plex.listener.impl; package dev.plex.listener.impl;
import com.google.gson.Gson;
import dev.plex.cache.DataUtils; import dev.plex.cache.DataUtils;
import dev.plex.cache.player.PlayerCache; import dev.plex.cache.player.PlayerCache;
import dev.plex.command.blocking.BlockedCommand; import dev.plex.command.blocking.BlockedCommand;
@ -19,7 +18,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import java.util.Arrays;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -89,28 +87,19 @@ public class CommandListener extends PlexListener
if (cmdRef.get() != null) if (cmdRef.get() != null)
{ {
BlockedCommand cmd = cmdRef.get(); BlockedCommand cmd = cmdRef.get();
if (cmd.getRequiredLevel().equalsIgnoreCase("e")) switch (cmd.getRequiredLevel().toLowerCase(Locale.ROOT))
{ {
case "e" -> {
event.setCancelled(true); event.setCancelled(true);
event.getPlayer().sendMessage(Component.text(cmd.getMessage()).color(NamedTextColor.GRAY)); event.getPlayer().sendMessage(Component.text(cmd.getMessage()).color(NamedTextColor.GRAY));
return;
} }
if (cmd.getRequiredLevel().equalsIgnoreCase("a")) case "a" -> {
{
if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN) && plexPlayer.isAdminActive())
{
event.setCancelled(true); event.setCancelled(true);
event.getPlayer().sendMessage(Component.text(cmd.getMessage()).color(NamedTextColor.GRAY)); event.getPlayer().sendMessage(Component.text(cmd.getMessage()).color(NamedTextColor.GRAY));
return;
} }
} case "s" -> {
if (cmd.getRequiredLevel().equalsIgnoreCase("s"))
{
if (plexPlayer.getRankFromString().isAtLeast(Rank.SENIOR_ADMIN) && plexPlayer.isAdminActive())
{
event.setCancelled(true); event.setCancelled(true);
event.getPlayer().sendMessage(Component.text(cmd.getMessage()).color(NamedTextColor.GRAY)); event.getPlayer().sendMessage(Component.text(cmd.getMessage()).color(NamedTextColor.GRAY));
return;
} }
} }
} }