From 5988eba06b3e48faaf552d94d471ed7b690019db Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Sun, 10 Apr 2022 13:44:36 -0400 Subject: [PATCH 1/8] 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); From 391677596af4e71f6029bdd03478b96c50c91c3e Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Sun, 10 Apr 2022 13:45:52 -0400 Subject: [PATCH 2/8] i forgor :skull: --- src/main/java/dev/plex/util/PlexUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dev/plex/util/PlexUtils.java b/src/main/java/dev/plex/util/PlexUtils.java index b3b54c2..84508d9 100644 --- a/src/main/java/dev/plex/util/PlexUtils.java +++ b/src/main/java/dev/plex/util/PlexUtils.java @@ -165,7 +165,7 @@ public class PlexUtils extends PlexBase aprilFools = plugin.config.getBoolean("april_fools"); } LocalDateTime date = LocalDateTime.now(); - if (true/*aprilFools && date.getMonth() == Month.APRIL && date.getDayOfMonth() == 1*/) + if (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)); From 0fc2aa68b0a3fa4e70b77a66f4b92be0bd35a894 Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Sun, 10 Apr 2022 14:10:15 -0400 Subject: [PATCH 3/8] remove separated color --- src/main/java/dev/plex/listener/impl/CommandListener.java | 2 +- src/main/resources/commands.yml | 6 +++--- src/main/resources/messages.yml | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/dev/plex/listener/impl/CommandListener.java b/src/main/java/dev/plex/listener/impl/CommandListener.java index 68bc3d7..7672858 100644 --- a/src/main/java/dev/plex/listener/impl/CommandListener.java +++ b/src/main/java/dev/plex/listener/impl/CommandListener.java @@ -64,7 +64,7 @@ public class CommandListener extends PlexListener { event.setCancelled(true); //PlexLog.debug("Command blocked."); - player.sendMessage(PlexUtils.mmDeserialize(PlexUtils.messageString("blockedCommandColor") + blockedCommand.getMessage())); + player.sendMessage(PlexUtils.mmDeserialize(blockedCommand.getMessage())); return; } } diff --git a/src/main/resources/commands.yml b/src/main/resources/commands.yml index 79d17e9..2761305 100644 --- a/src/main/resources/commands.yml +++ b/src/main/resources/commands.yml @@ -16,6 +16,6 @@ # - "m:e:mail sendall:You cannot send messages to everyone on the server" # - "r:e:^[^ :]+::Plugin specific commands are disabled" blockedCommands: - - "r:e:^[^ :]+::Plugin specific commands are disabled." - - "m:e:mail sendall:You cannot send messages to everyone on the server." - - "m:e:mail sendtempall:You cannot send messages to everyone on the server." \ No newline at end of file + - "r:e:^[^ :]+::Plugin specific commands are disabled." + - "m:e:mail sendall:You cannot send messages to everyone on the server." + - "m:e:mail sendtempall:You cannot send messages to everyone on the server." \ No newline at end of file diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 2894798..c6e410c 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -167,8 +167,7 @@ removedMobs: "{0} - Removed {1} mobs" autoWipeDisabled: "Item wiping is currently disabled in the config!" allowDropsDisabled: "No longer allowing drops from players." allowDropsEnabled: "Now allowing drops from players." -blockedCommandColor: "" -commandBlocked: "That command is blocked." +commandBlocked: "That command is blocked." # 0 - The command sender # 1 - The message being said sayCommand: "[Server: {0}] {1}" \ No newline at end of file From 8866f44aa2ff5ab130389e221b70a5e615fa2d67 Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Sun, 10 Apr 2022 14:21:34 -0400 Subject: [PATCH 4/8] fix issue where matcher would match partial commands --- src/main/java/dev/plex/listener/impl/CommandListener.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/plex/listener/impl/CommandListener.java b/src/main/java/dev/plex/listener/impl/CommandListener.java index 7672858..eb0355b 100644 --- a/src/main/java/dev/plex/listener/impl/CommandListener.java +++ b/src/main/java/dev/plex/listener/impl/CommandListener.java @@ -7,6 +7,7 @@ import dev.plex.command.blocker.MatchCommand; import dev.plex.command.blocker.RegexCommand; import dev.plex.listener.PlexListener; import dev.plex.player.PlexPlayer; +import dev.plex.util.PlexLog; import dev.plex.util.PlexUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -55,7 +56,7 @@ public class CommandListener extends PlexListener } else if (blockedCommand instanceof MatchCommand matchCommand) { - if (message.toLowerCase().startsWith(matchCommand.getMatch().toLowerCase())) + if (message.equalsIgnoreCase(matchCommand.getMatch()) || message.toLowerCase().startsWith(matchCommand.getMatch().toLowerCase() + " ")) { isBlocked = true; } @@ -63,7 +64,7 @@ public class CommandListener extends PlexListener if (isBlocked) { event.setCancelled(true); - //PlexLog.debug("Command blocked."); + PlexLog.debug("Command blocked: " + blockedCommand); player.sendMessage(PlexUtils.mmDeserialize(blockedCommand.getMessage())); return; } From f78edc55d478a51014085ee88f34c9528095705b Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Sun, 10 Apr 2022 14:23:34 -0400 Subject: [PATCH 5/8] re remove debug logging lmao --- src/main/java/dev/plex/listener/impl/CommandListener.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/dev/plex/listener/impl/CommandListener.java b/src/main/java/dev/plex/listener/impl/CommandListener.java index eb0355b..6987ad9 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.command.blocker.MatchCommand; import dev.plex.command.blocker.RegexCommand; import dev.plex.listener.PlexListener; import dev.plex.player.PlexPlayer; -import dev.plex.util.PlexLog; import dev.plex.util.PlexUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -64,7 +63,7 @@ public class CommandListener extends PlexListener if (isBlocked) { event.setCancelled(true); - PlexLog.debug("Command blocked: " + blockedCommand); + //PlexLog.debug("Command blocked: " + blockedCommand); player.sendMessage(PlexUtils.mmDeserialize(blockedCommand.getMessage())); return; } From d79890439408993475ec439dac103a32282bf9a7 Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Sun, 10 Apr 2022 13:33:49 -0500 Subject: [PATCH 6/8] Update Plex.java --- src/main/java/dev/plex/Plex.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/plex/Plex.java b/src/main/java/dev/plex/Plex.java index 27c4d70..b055563 100644 --- a/src/main/java/dev/plex/Plex.java +++ b/src/main/java/dev/plex/Plex.java @@ -248,7 +248,7 @@ public class Plex extends JavaPlugin { final Properties props; - try (InputStream in = plugin.getResource("resources/build.properties")) + try (InputStream in = plugin.getResource("build.properties")) { props = new Properties(); props.load(in); @@ -265,4 +265,4 @@ public class Plex extends JavaPlugin } } } -} \ No newline at end of file +} From aa9f306586fd5a813fff5994c2bccb9aa1c8c073 Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Sun, 10 Apr 2022 17:56:15 -0400 Subject: [PATCH 7/8] fix entitywipe not actually wiping entities --- src/main/java/dev/plex/command/impl/EntityWipeCMD.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dev/plex/command/impl/EntityWipeCMD.java b/src/main/java/dev/plex/command/impl/EntityWipeCMD.java index d22179d..204b227 100644 --- a/src/main/java/dev/plex/command/impl/EntityWipeCMD.java +++ b/src/main/java/dev/plex/command/impl/EntityWipeCMD.java @@ -54,7 +54,7 @@ public class EntityWipeCMD extends PlexCommand { if (entity.getType() != EntityType.PLAYER) { - String type = entity.getName(); + String type = entity.getType().name(); if (useBlacklist ? entityBlacklist.stream().noneMatch(entityName -> entityName.equalsIgnoreCase(type)) : entityWhitelist.stream().anyMatch(entityName -> entityName.equalsIgnoreCase(type))) { From 6b7bfacbfd2320179b48bc916a1072111ac715d5 Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Sun, 10 Apr 2022 17:01:02 -0500 Subject: [PATCH 8/8] Update EntityWipeCMD.java --- src/main/java/dev/plex/command/impl/EntityWipeCMD.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dev/plex/command/impl/EntityWipeCMD.java b/src/main/java/dev/plex/command/impl/EntityWipeCMD.java index 204b227..f5d0809 100644 --- a/src/main/java/dev/plex/command/impl/EntityWipeCMD.java +++ b/src/main/java/dev/plex/command/impl/EntityWipeCMD.java @@ -99,7 +99,7 @@ public class EntityWipeCMD extends PlexCommand { if (entity.getType() != EntityType.PLAYER) { - entities.add(entity.getName()); + entities.add(entity.getType().name()); } } }