From 1637e43bc87ef07a37bcb9d7f98055c62dadcc9d Mon Sep 17 00:00:00 2001 From: Etzelia Date: Fri, 4 Oct 2019 10:21:54 -0500 Subject: [PATCH] Make spec confirmation configurable Signed-off-by: Etzelia --- docs/source/changelog/v1.8.rst | 3 ++ docs/source/permissions.rst | 2 +- .../listeners/CommandPreprocessListener.java | 36 ++++++++++--------- src/main/resources/config.yml | 6 ++++ src/main/resources/plugin.yml | 4 +-- 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/docs/source/changelog/v1.8.rst b/docs/source/changelog/v1.8.rst index 4aa1f0a..bace249 100644 --- a/docs/source/changelog/v1.8.rst +++ b/docs/source/changelog/v1.8.rst @@ -16,8 +16,11 @@ Additions ``**bold**`` |br| ``~~strikethrough~~`` +* `Spec Confirm`_ - Updates the TP confirmation to allow for a configurable list of commands + .. _Checkup Command: https://git.etztech.xyz/24CarrotCraft/QoL/pulls/33 .. _Discord Syntax: https://git.etztech.xyz/24CarrotCraft/QoL/pulls/36 +.. _Spec Confirm: https://git.etztech.xyz/24CarrotCraft/QoL/pulls/39 Bug Fixes --------- diff --git a/docs/source/permissions.rst b/docs/source/permissions.rst index 9755d33..7633ebd 100644 --- a/docs/source/permissions.rst +++ b/docs/source/permissions.rst @@ -24,7 +24,7 @@ Permissions ``qol.auditor`` - Ability to bypass auditing when running commands on auditable -``qol.tpconfirm`` - Forces a player to confirm teleports when outside spectator mode +``qol.specconfirm`` - Forces a player to confirm a (configurable) command(s) when outside spectator mode ``qol.whitelist.bypass`` - Allows someone into the server when Whitelist mode is enabled diff --git a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java index 685e310..fd7ef80 100644 --- a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java @@ -16,15 +16,12 @@ import xyz.etztech.qol.QoL; import xyz.etztech.qol.other.LinkCommand; import org.dynmap.DynmapAPI; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import java.util.Collection; +import java.util.*; public class CommandPreprocessListener implements Listener { QoL plugin; - private Map confirmTpMap = new HashMap<>(); + private Map confirmMap = new HashMap<>(); private Map dynmapVisibleStatusMap = new HashMap<>(); public CommandPreprocessListener(QoL plugin) { @@ -77,23 +74,30 @@ public class CommandPreprocessListener implements Listener { dynmap.setPlayerVisiblity(sender.getName(), visibleStatus); } - // Spec TP confirmation - if (sender.hasPermission("qol.tpconfirm")) { - //check if the command is a tp command - if (noSlash(base).equals("tp") || noSlash(base).toLowerCase().startsWith("tele") || noSlash(command).toLowerCase().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()); + // Spec confirmation + List specConfirm = plugin.getConfig().getStringList("spec-confirm"); + if (sender.hasPermission("qol.specconfirm")) { + boolean confirm = false; + for (String confirmable : specConfirm) { + if (noSlash(command).toLowerCase().startsWith(confirmable.toLowerCase())) { + confirm = true; } - //If the user is running the tp command for the first time outside of spec + } + //check if the command is a spec confirm command + if (confirm) { + //If the user is in the confirm map, remove them and let the command run + if (command.equals(confirmMap.get(sender.getUniqueId()))) { + confirmMap.remove(sender.getUniqueId()); + } + //If the user is running the 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); + //Add the user to the spec confirm map + confirmMap.put(sender.getUniqueId(), command); - TextComponent message = new TextComponent(ChatColor.GREEN + "You are TPing out of spec, run command again to confirm."); + TextComponent message = new TextComponent(ChatColor.GREEN + "You are running this command out of spec, run again to confirm."); sender.spigot().sendMessage(message); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index aaa9b13..86a84ad 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -93,3 +93,9 @@ disable-fire: # Overrides view distance per world, format is [World Name]: [View Distance] view-distances: world: 2 + +# A list of commands to confirm before using if the user isn't in spectator mode +spec-confirm: + - "tp" + - "checkup" + - "lagg tpchunk" diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ce6acc7..6d38deb 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -91,8 +91,8 @@ permissions: qol.auditor: description: Ability to bypass auditing when running commands on auditable default: op - qol.tpconfirm: - description: Makes the user confirm they want to TP out of spec + qol.specconfirm: + description: Makes the user confirm they want to run (configurable) command(s) out of spec default: op qol.griefalert: description: Alerts the user when monitored actions are encountered