From c8c2c01d94cd264ac4ef83cfaddda5e0f9507736 Mon Sep 17 00:00:00 2001 From: RayzsYT <51991564+RayzsYT@users.noreply.github.com> Date: Sun, 12 May 2024 01:22:20 +0200 Subject: [PATCH] Add Message --- .../pat/plugin/process/CommandProcess.java | 45 +++++++++++++------ .../de/rayzs/pat/utils/CommandSender.java | 4 +- src/main/resources/files/bukkit-config.yml | 4 +- src/main/resources/files/bungee-config.yml | 4 +- src/main/resources/files/velocity-config.yml | 4 +- 5 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/main/java/de/rayzs/pat/plugin/process/CommandProcess.java b/src/main/java/de/rayzs/pat/plugin/process/CommandProcess.java index 5dc74a4e..328abe9e 100644 --- a/src/main/java/de/rayzs/pat/plugin/process/CommandProcess.java +++ b/src/main/java/de/rayzs/pat/plugin/process/CommandProcess.java @@ -7,13 +7,17 @@ import de.rayzs.pat.utils.*; import de.rayzs.pat.utils.communication.ClientCommunication; import de.rayzs.pat.utils.group.*; import java.util.*; +import java.util.concurrent.TimeUnit; public class CommandProcess { + private static final ExpireCache CONFIRMATION = new ExpireCache<>(4, TimeUnit.SECONDS); + public static void handleCommand(Object senderObj, String[] args, String label) { CommandSender sender = new CommandSender(senderObj); + UUID uuid = sender.getUniqueId(); int length = args.length; - String task, sub, extra; + String task, sub, extra, confirmationString; Group group; boolean bool; if(!PermissionUtil.hasPermissionWithResponse(sender, "use")) return; @@ -43,13 +47,20 @@ public class CommandProcess { return; case "clear": if(!PermissionUtil.hasPermissionWithResponse(sender, "clear")) return; - Storage.BLOCKED_COMMANDS_LIST.clear(); - Storage.save(); - if(Reflection.isVelocityServer()) VelocityAntiTabListener.updateCommands(); - else if(!Reflection.isProxyServer()) { - if(Reflection.getMinor() >= 18) BukkitAntiTabListener.updateCommands(); - } else ClientCommunication.synchronizeInformation(); - sender.sendMessage(Storage.BLACKLIST_CLEAR_MESSAGE); + confirmationString = "clear"; + + if(CONFIRMATION.getOrDefault(sender.getUniqueId(), "").equals(confirmationString)) { + Storage.BLOCKED_COMMANDS_LIST.clear(); + Storage.save(); + if (Reflection.isVelocityServer()) VelocityAntiTabListener.updateCommands(); + else if (!Reflection.isProxyServer()) { + if (Reflection.getMinor() >= 18) BukkitAntiTabListener.updateCommands(); + } else ClientCommunication.synchronizeInformation(); + sender.sendMessage(Storage.BLACKLIST_CLEAR_MESSAGE); + } else { + CONFIRMATION.put(uuid, confirmationString); + sender.sendMessage(Storage.BLACKLIST_CLEAR_CONFIRM_MESSAGE); + } return; case "notify": if(!PermissionUtil.hasPermissionWithResponse(sender, "notify")) return; @@ -143,13 +154,19 @@ public class CommandProcess { sender.sendMessage(Storage.GROUP_NOT_EXIST_MESSAGE.replace("%group%", sub)); return; } + confirmationString = "clear " + group.getGroupName(); - group.clear(); - if(Reflection.isVelocityServer()) VelocityAntiTabListener.updateCommands(); - else if(!Reflection.isProxyServer()) { - if(Reflection.getMinor() >= 18) BukkitAntiTabListener.updateCommands(); - } else ClientCommunication.synchronizeInformation(); - sender.sendMessage(Storage.GROUP_CLEAR_MESSAGE.replace("%group%", group.getGroupName())); + if(CONFIRMATION.getOrDefault(sender.getUniqueId(), "").equals(confirmationString)) { + group.clear(); + if (Reflection.isVelocityServer()) VelocityAntiTabListener.updateCommands(); + else if (!Reflection.isProxyServer()) { + if (Reflection.getMinor() >= 18) BukkitAntiTabListener.updateCommands(); + } else ClientCommunication.synchronizeInformation(); + sender.sendMessage(Storage.GROUP_CLEAR_MESSAGE.replace("%group%", group.getGroupName())); + } else { + CONFIRMATION.put(uuid, confirmationString); + sender.sendMessage(Storage.GROUP_CLEAR_CONFIRM_MESSAGE); + } return; case "add": diff --git a/src/main/java/de/rayzs/pat/utils/CommandSender.java b/src/main/java/de/rayzs/pat/utils/CommandSender.java index 1ebf0de3..1a209232 100644 --- a/src/main/java/de/rayzs/pat/utils/CommandSender.java +++ b/src/main/java/de/rayzs/pat/utils/CommandSender.java @@ -10,6 +10,7 @@ import java.util.UUID; public class CommandSender { private final Object sender; + private static final UUID CONSOLE_UUID = UUID.randomUUID(); public CommandSender(Object sender) { this.sender = sender; @@ -51,6 +52,7 @@ public class CommandSender { public UUID getUniqueId() { if(Reflection.isVelocityServer()) return ((com.velocitypowered.api.proxy.Player) sender).getUniqueId(); else if(Reflection.isProxyServer()) return ((ProxiedPlayer) sender).getUniqueId(); - else return ((Player) sender).getUniqueId(); + else if(sender instanceof Player) ((Player) sender).getUniqueId(); + return CONSOLE_UUID; } } \ No newline at end of file diff --git a/src/main/resources/files/bukkit-config.yml b/src/main/resources/files/bukkit-config.yml index 636c84cc..2b1dc651 100644 --- a/src/main/resources/files/bukkit-config.yml +++ b/src/main/resources/files/bukkit-config.yml @@ -34,7 +34,7 @@ reload: blacklist: clear: '&aList has been cleared!' - clear-confirmation: '&4&lWarning! &7This command will &cclear the entire list&7! &eRepeat the &nsame command &eto confirm this action.' + clear-confirmation: '&4Warning! &7This command will &cclear the entire list&7! &7Repeat the &esame command &7to confirm this action.' list: message: '&7Listed commands (&f%size%&7)&8: &f%commands%' @@ -54,7 +54,7 @@ group: already-exist: '&cGroup %group% already exist!' does-not-exist: '&cGroup %group% does not exist!' clear: '&aList of group %group% has been cleared!' - clear-confirmation: '&4&lWarning! &7This command will &cclear the entire list&7 of this group! &eRepeat the &nsame command &eto confirm this action.' + clear-confirmation: '&4Warning! &7This command will &cclear the entire list&7 of this group! &7Repeat the &esame command &7to confirm this action.' list-groups: message: '&7All groups (&f%size%&7)&8: &f%groups%' diff --git a/src/main/resources/files/bungee-config.yml b/src/main/resources/files/bungee-config.yml index 7e76f71f..7336f2ff 100644 --- a/src/main/resources/files/bungee-config.yml +++ b/src/main/resources/files/bungee-config.yml @@ -26,7 +26,7 @@ reload: blacklist: clear: '&aList has been cleared!' - clear-confirmation: '&4&lWarning! &7This command will &cclear the entire list&7! &eRepeat the &nsame command &eto confirm this action.' + clear-confirmation: '&4Warning! &7This command will &cclear the entire list&7! &7Repeat the &esame command &7to confirm this action.' list: message: '&7Listed commands (&f%size%&7)&8: &f%commands%' @@ -45,7 +45,7 @@ group: does-not-exist: '&cGroup %group% does not exist!' delete: '&cGroup %group% has been deleted!' clear: '&aList of group %group% has been cleared!' - clear-confirmation: '&4&lWarning! &7This command will &cclear the entire list&7 of this group! &eRepeat the &nsame command &eto confirm this action.' + clear-confirmation: '&4Warning! &7This command will &cclear the entire list&7 of this group! &7Repeat the &esame command &7to confirm this action.' list-groups: message: '&7All groups (&f%size%&7)&8: &f%groups%' diff --git a/src/main/resources/files/velocity-config.yml b/src/main/resources/files/velocity-config.yml index b9492644..6c4cb478 100644 --- a/src/main/resources/files/velocity-config.yml +++ b/src/main/resources/files/velocity-config.yml @@ -24,7 +24,7 @@ reload: blacklist: clear: '&aList has been cleared!' - clear-confirmation: '&4&lWarning! &7This command will &cclear the entire list&7! &eRepeat the &nsame command &eto confirm this action.' + clear-confirmation: '&4Warning! &7This command will &cclear the entire list&7! &7Repeat the &esame command &7to confirm this action.' list: message: '&7Listed commands (&f%size%&7)&8: &f%commands%' @@ -43,7 +43,7 @@ group: does-not-exist: '&cGroup %group% does not exist!' delete: '&cGroup %group% has been deleted!' clear: '&aList of group %group% has been cleared!' - clear-confirmation: '&4&lWarning! &7This command will &cclear the entire list&7 of this group! &eRepeat the &nsame command &eto confirm this action.' + clear-confirmation: '&4Warning! &7This command will &cclear the entire list&7 of this group! &7Repeat the &esame command &7to confirm this action.' list-groups: message: '&7All groups (&f%size%&7)&8: &f%groups%'