From 5988eba06b3e48faaf552d94d471ed7b690019db Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Sun, 10 Apr 2022 13:44:36 -0400 Subject: [PATCH] cleanup & fix --- .../blocker/CommandBlockerManager.java | 20 ++-------- src/main/java/dev/plex/util/PlexUtils.java | 37 ++++--------------- 2 files changed, 12 insertions(+), 45 deletions(-) diff --git a/src/main/java/dev/plex/command/blocker/CommandBlockerManager.java b/src/main/java/dev/plex/command/blocker/CommandBlockerManager.java index f44feab..f54c6d3 100644 --- a/src/main/java/dev/plex/command/blocker/CommandBlockerManager.java +++ b/src/main/java/dev/plex/command/blocker/CommandBlockerManager.java @@ -2,15 +2,11 @@ package dev.plex.command.blocker; import dev.plex.PlexBase; import dev.plex.rank.enums.Rank; -import dev.plex.util.PlexLog; import dev.plex.util.PlexUtils; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.command.*; import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.SimplePluginManager; - -import java.lang.reflect.Field; import java.util.*; import java.util.regex.Pattern; @@ -21,18 +17,11 @@ public class CommandBlockerManager extends PlexBase public boolean loadedYet; - private static CommandMap getCommandMap() - { - return plugin.getServer().getCommandMap(); - } - public void syncCommands() { loadedYet = false; blockedCommands.clear(); - CommandMap commandMap = getCommandMap(); - List raw = plugin.blockedCommands.getStringList("blockedCommands"); for (String cmd : raw) @@ -93,13 +82,12 @@ public class CommandBlockerManager extends PlexBase } String cmdForSearch = ind == -1 ? regexOrMatch : regexOrMatch.substring(0, ind); PluginCommand pluginCommand = Bukkit.getServer().getPluginCommand(cmdForSearch); - Plugin plugin = null; - if (pluginCommand != null) plugin = pluginCommand.getPlugin(); - Command command = null; - if (commandMap != null) command = commandMap.getCommand(cmdForSearch); + Plugin pl = null; + if (pluginCommand != null) pl = pluginCommand.getPlugin(); + Command command = plugin.getServer().getCommandMap().getCommand(cmdForSearch); if (command != null) { - String pluginName = plugin == null ? null : plugin.getName(); + String pluginName = pl == null ? null : pl.getName(); blockedCommands.add(new MatchCommand(command.getName() + blockedArgs, rank, message)); if (pluginName != null) blockedCommands.add(new MatchCommand(pluginName + ":" + command.getName() + blockedArgs, rank, message)); List aliases = command.getAliases(); diff --git a/src/main/java/dev/plex/util/PlexUtils.java b/src/main/java/dev/plex/util/PlexUtils.java index 218abb3..b3b54c2 100644 --- a/src/main/java/dev/plex/util/PlexUtils.java +++ b/src/main/java/dev/plex/util/PlexUtils.java @@ -7,11 +7,7 @@ import dev.plex.PlexBase; import dev.plex.config.Config; import dev.plex.storage.StorageType; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.minimessage.Context; import net.kyori.adventure.text.minimessage.MiniMessage; -import net.kyori.adventure.text.minimessage.ParsingException; -import net.kyori.adventure.text.minimessage.tag.Tag; -import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.kyori.adventure.text.minimessage.tag.standard.*; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; @@ -22,8 +18,6 @@ import org.bukkit.command.Command; import org.bukkit.command.PluginCommandYamlParser; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; @@ -163,32 +157,17 @@ public class PlexUtils extends PlexBase StandardTags.reset() ).build()).build(); - private static final MiniMessage eggMessage = MiniMessage.builder().tags(new TagResolver() - { - @Override - public @Nullable Tag resolve(@NotNull String name, @NotNull ArgumentQueue arguments, @NotNull Context ctx) throws ParsingException - { - return StandardTags.rainbow().resolve("rainbow", arguments, ctx); - } - - @Override - public boolean has(@NotNull String name) - { - return true; - } - } - ).build(); - public static Component mmDeserialize(String input) { - /*Calendar calendar = Calendar.getInstance(); - MiniMessage mm = (calendar.get(Calendar.MONTH) == Calendar.APRIL && calendar.get(Calendar.DAY_OF_MONTH) == 1 && (!plugin.config.contains("april_fools") || plugin.config.getBoolean("april_fools"))) ? eggMessage : safeMessage; - return mm.deserialize(PlainTextComponentSerializer.plainText().serialize(LegacyComponentSerializer.legacySection().deserialize(input)));*/ - boolean aprilFools = plugin.config.getBoolean("april_fools"); - LocalDateTime date = LocalDateTime.now(); - if (aprilFools && date.getMonth() == Month.APRIL && date.getDayOfMonth() == 1) + boolean aprilFools = true; // true by default + if (plugin.config.contains("april_fools")) { - Component component = PlainTextComponentSerializer.plainText().deserialize(input); + aprilFools = plugin.config.getBoolean("april_fools"); + } + LocalDateTime date = LocalDateTime.now(); + if (true/*aprilFools && date.getMonth() == Month.APRIL && date.getDayOfMonth() == 1*/) + { + Component component = MiniMessage.miniMessage().deserialize(input); // removes existing tags return MiniMessage.miniMessage().deserialize("" + PlainTextComponentSerializer.plainText().serialize(component)); } return MiniMessage.miniMessage().deserialize(input);