From 9ec045dbfe612a412000d1154e6b1d8348398be6 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 22 Sep 2018 14:50:07 -0500 Subject: [PATCH] Added a way to specify tp commands in the config --- src/main/java/xyz/etztech/qol/QoL.java | 12 ++++++-- .../listeners/CommandPreprocessListener.java | 28 ++++++++++++++++--- src/main/resources/config.yml | 2 ++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index ae931a6..36ab8ae 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -28,6 +28,7 @@ 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 @@ -149,6 +150,11 @@ 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")) { links.add(LinkCommand.fromString(raw)); @@ -235,9 +241,9 @@ public class QoL extends JavaPlugin { timeout = enabled; } - public static List getAudits() { - return audits; - } + 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 a891031..b4ce139 100644 --- a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java @@ -13,7 +13,6 @@ import xyz.etztech.core.CoreUtils; import xyz.etztech.core.web.CoreWeb; import xyz.etztech.qol.QoL; import xyz.etztech.qol.other.LinkCommand; -;import xyz.etztech.qol.EtzTechUtil; import java.util.HashMap; import java.util.Map; @@ -22,7 +21,7 @@ public class CommandPreprocessListener implements Listener { QoL plugin; - Map confirm_tp = new HashMap<>(); + private Map confirm_tp = new HashMap<>(); public CommandPreprocessListener(QoL plugin) { this.plugin = plugin; @@ -39,14 +38,21 @@ public class CommandPreprocessListener implements Listener { // Command Auditing if (sender.hasPermission("qol.audit") && plugin.getConfig().getBoolean("audit.enabled")) { boolean auditable = false; + + for (String audit : QoL.getAudits()) { if (noSlash(command).startsWith(noSlash(audit))) { auditable = true; break; } } + + + 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); String webhook = plugin.getConfig().getString("audit.webhook"); @@ -54,17 +60,31 @@ public class CommandPreprocessListener implements Listener { CoreWeb.asyncPost(plugin, webhook, post); } - if (base.equals("tp")) { + //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); - TextComponent message = new TextComponent(ChatColor.GREEN + "You are TPing out of spec, run command again to confirm."); + //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); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 3e19f32..2e8f7cc 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -33,6 +33,8 @@ audit: - teleport - mute - unban + tp_commands: + - tp # TPS alert # Set to 0 to cancel