From 97161694db150bd69591d11faf9db14d3c5988d2 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 22 Sep 2018 22:27:02 -0500 Subject: [PATCH] Made changes according to conversation in PR 5. --- src/main/java/xyz/etztech/qol/QoL.java | 7 --- .../listeners/CommandPreprocessListener.java | 63 +++++++------------ src/main/resources/config.yml | 2 - 3 files changed, 22 insertions(+), 50 deletions(-) diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index 36ab8ae..c078495 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -28,7 +28,6 @@ public class QoL extends JavaPlugin { private static boolean whitelist = false; private static boolean timeout = false; private static List audits = new ArrayList<>(); - private static List tpCommands = new ArrayList<>(); private static List links = new ArrayList<>(); @Override @@ -150,10 +149,6 @@ public class QoL extends JavaPlugin { for (String command : config.getStringList("audit.commands")) { audits.add(command.toLowerCase()); } - tpCommands = new ArrayList<>(); - for (String command : config.getStringList("audit.tp_commands")) { - tpCommands.add(command.toLowerCase()); - } links = new ArrayList<>(); for (String raw : config.getStringList("links")) { @@ -243,8 +238,6 @@ public class QoL extends JavaPlugin { public static List getAudits() { return audits; } - public static List getTpCommands() {return tpCommands;} - public static List getLinks() { return links; } diff --git a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java index b4ce139..758285c 100644 --- a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java @@ -16,12 +16,13 @@ import xyz.etztech.qol.other.LinkCommand; import java.util.HashMap; import java.util.Map; +import java.util.UUID; public class CommandPreprocessListener implements Listener { QoL plugin; - private Map confirm_tp = new HashMap<>(); + private Map confirmTpMap = new HashMap<>(); public CommandPreprocessListener(QoL plugin) { this.plugin = plugin; @@ -38,7 +39,26 @@ public class CommandPreprocessListener implements Listener { // Command Auditing if (sender.hasPermission("qol.audit") && plugin.getConfig().getBoolean("audit.enabled")) { boolean auditable = false; + boolean isTpCommand = false; + //check if the command is a tp command + if (noSlash(command).startsWith("tp") || noSlash(command).startsWith("teleport") || noSlash(command).startsWith("lagg tpchunk")) { + //If the user is in the confirm tp map, remove them and let the command run + if (command.equals(confirmTpMap.get(sender.getUniqueId()))) { + confirmTpMap.remove(sender.getUniqueId()); + } + //If the user is running the tp command for the first time outside of spec + else if (sender.getGameMode() != GameMode.SPECTATOR) { + //Cancel the command + event.setCancelled(true); + + //Add the user to the tp confirm map + confirmTpMap.put(sender.getUniqueId(), command); + + TextComponent message = new TextComponent(ChatColor.GREEN + "You are TPing out of spec, run command again to confirm."); + sender.spigot().sendMessage(message); + } + } for (String audit : QoL.getAudits()) { if (noSlash(command).startsWith(noSlash(audit))) { @@ -47,11 +67,9 @@ public class CommandPreprocessListener implements Listener { } } - - if (auditable) { Map post = new HashMap<>(); - boolean is_tp_command = false; + post.put("username", "QoL Auditor"); post.put("content", "[" + StringUtils.capitalize(sender.getGameMode().name().toLowerCase()) + "] " + sender.getName() + " executed command: " + command); @@ -60,35 +78,6 @@ public class CommandPreprocessListener implements Listener { CoreWeb.asyncPost(plugin, webhook, post); } - //Check if the command is a tp_command - for (String tp_command : QoL.getTpCommands()) { - if (noSlash(command).startsWith(noSlash(tp_command))) { - is_tp_command = true; - break; - } - } - - if (is_tp_command) { - //If the user is in the confirm tp map, remove them and let the command run - if (command.equals(confirm_tp.get(sender))) { - confirm_tp.remove(sender); - } - //If the user is running the tp command for the first time outside of spec - else if (sender.getGameMode() != GameMode.SPECTATOR) { - //Cancel the command - event.setCancelled(true); - - //Remove the user from the confirm tp map if they are already on it - confirm_tp.remove(sender); - - //Add the user to the tp confirm hash map - confirm_tp.put(sender, command); - - TextComponent message = new TextComponent(ChatColor.GREEN + "You are TPing out of spec, run command again to confirm."); - sender.spigot().sendMessage(message); - } - } - } } @@ -110,12 +99,4 @@ public class CommandPreprocessListener implements Listener { } - - - - - - - - } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2e8f7cc..3e19f32 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -33,8 +33,6 @@ audit: - teleport - mute - unban - tp_commands: - - tp # TPS alert # Set to 0 to cancel