From a548ef779a0290d92d183ccc943a5a4c35743a74 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 22 Sep 2018 14:18:06 -0500 Subject: [PATCH 1/6] Added confirmation for tping when out of spec. --- .../listeners/CommandPreprocessListener.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java index 64c0a2b..a891031 100644 --- a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java @@ -4,6 +4,7 @@ import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.TextComponent; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; +import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -12,6 +13,7 @@ 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; @@ -20,6 +22,7 @@ public class CommandPreprocessListener implements Listener { QoL plugin; + Map confirm_tp = new HashMap<>(); public CommandPreprocessListener(QoL plugin) { this.plugin = plugin; @@ -50,6 +53,22 @@ public class CommandPreprocessListener implements Listener { if (StringUtils.isNotEmpty(webhook)) { CoreWeb.asyncPost(plugin, webhook, post); } + + if (base.equals("tp")) { + if (command.equals(confirm_tp.get(sender))) { + confirm_tp.remove(sender); + } + else if (sender.getGameMode() != GameMode.SPECTATOR) { + event.setCancelled(true); + TextComponent message = new TextComponent(ChatColor.GREEN + "You are TPing out of spec, run command again to confirm."); + + confirm_tp.remove(sender); + confirm_tp.put(sender, command); + + sender.spigot().sendMessage(message); + } + } + } } From 9ec045dbfe612a412000d1154e6b1d8348398be6 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 22 Sep 2018 14:50:07 -0500 Subject: [PATCH 2/6] 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 From 97161694db150bd69591d11faf9db14d3c5988d2 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 22 Sep 2018 22:27:02 -0500 Subject: [PATCH 3/6] 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 From 85391029dccf9c4a4f21e9c7ba37a555cf244744 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 22 Sep 2018 22:35:14 -0500 Subject: [PATCH 4/6] fix issue where tps was getting caught in tp check --- .../xyz/etztech/qol/listeners/CommandPreprocessListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java index 758285c..1593250 100644 --- a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java @@ -42,7 +42,7 @@ public class CommandPreprocessListener implements Listener { 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 (noSlash(base).equals("tp") || noSlash(base).equals("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()); From b796e3d66761a94ee5461a5da4a5701fd69c2bff Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 22 Sep 2018 22:42:08 -0500 Subject: [PATCH 5/6] added tele to teleport commands --- .../xyz/etztech/qol/listeners/CommandPreprocessListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java index 1593250..4e85829 100644 --- a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java @@ -42,7 +42,7 @@ public class CommandPreprocessListener implements Listener { boolean isTpCommand = false; //check if the command is a tp command - if (noSlash(base).equals("tp") || noSlash(base).equals("teleport") || noSlash(command).startsWith("lagg tpchunk")) { + if (noSlash(base).equals("tp") || noSlash(base).startsWith("tele") || 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()); From fef5ab6b5f9c6368f49fb7cdec6dc30c156eb507 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 23 Sep 2018 07:34:25 -0500 Subject: [PATCH 6/6] Added tpconfirm permission node to split out tp confirm from the rest of the audit checking --- src/main/java/xyz/etztech/qol/QoL.java | 2 -- .../qol/listeners/CommandPreprocessListener.java | 12 ++++++------ src/main/resources/plugin.yml | 3 +++ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index c078495..1ba18d1 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -43,8 +43,6 @@ public class QoL extends JavaPlugin { essentials = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials"); } - - if( isEnabled() ) { // Add listeners diff --git a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java index 4e85829..0c9d7bb 100644 --- a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java @@ -36,11 +36,7 @@ public class CommandPreprocessListener implements Listener { String base = command.split(" ")[0].substring(1).toLowerCase(); // Strip the slash Player sender = event.getPlayer(); - // Command Auditing - if (sender.hasPermission("qol.audit") && plugin.getConfig().getBoolean("audit.enabled")) { - boolean auditable = false; - boolean isTpCommand = false; - + if (sender.hasPermission("qol.tpconfirm")) { //check if the command is a tp command if (noSlash(base).equals("tp") || noSlash(base).startsWith("tele") || noSlash(command).startsWith("lagg tpchunk")) { //If the user is in the confirm tp map, remove them and let the command run @@ -59,6 +55,11 @@ public class CommandPreprocessListener implements Listener { sender.spigot().sendMessage(message); } } + } + + // 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))) { @@ -70,7 +71,6 @@ public class CommandPreprocessListener implements Listener { if (auditable) { Map post = new HashMap<>(); - 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"); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 14289ac..4943f31 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -68,6 +68,9 @@ permissions: qol.audit: description: Audits command usage default: op + qol.tpconfirm: + description: Makes the user confirm they want to TP out of spec + default: op qol.whitelist.bypass: description: Allows someone into the server when Whitelist is enabled default: op