From 762346cf379d73d8c63edbc4f05a0881fdd6fe73 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Wed, 26 Sep 2018 15:11:36 -0500 Subject: [PATCH 1/2] Added auditor and auditable perms. Users with the auditor perm can run audited commands on auditable players without being audited. --- .../listeners/CommandPreprocessListener.java | 52 ++++++--- src/main/resources/plugin.yml | 101 +++++++++--------- 2 files changed, 87 insertions(+), 66 deletions(-) diff --git a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java index 4ce0dc8..110ec9c 100644 --- a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java @@ -18,6 +18,7 @@ import org.dynmap.DynmapAPI; import java.util.HashMap; import java.util.Map; import java.util.UUID; +import java.util.Collection; public class CommandPreprocessListener implements Listener { @@ -34,7 +35,6 @@ public class CommandPreprocessListener implements Listener { String command = event.getMessage(); String base = command.split(" ")[0].substring(1).toLowerCase(); // Strip the slash - String auditBypassPerm = "qol.audit.bypass." + base; Player sender = event.getPlayer(); DynmapAPI dynmap = plugin.getDynmap(); @@ -79,26 +79,29 @@ public class CommandPreprocessListener implements Listener { } // Command Auditing - if (sender.hasPermission("qol.audit") && !sender.hasPermission(auditBypassPerm) && plugin.getConfig().getBoolean("audit.enabled")) { - boolean auditable = false; + if (sender.hasPermission("qol.audit") && plugin.getConfig().getBoolean("audit.enabled")) { + if (!sender.hasPermission("qol.auditor") && !targetIsAuditable(command)) { - for (String audit : QoL.getAudits()) { - if (noSlash(command).startsWith(noSlash(audit))) { - auditable = true; - break; - } - } + boolean auditable = false; - 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"); - if (StringUtils.isNotEmpty(webhook)) { - CoreWeb.asyncPost(plugin, webhook, post); + for (String audit : QoL.getAudits()) { + if (noSlash(command).startsWith(noSlash(audit))) { + auditable = true; + break; + } } + 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"); + if (StringUtils.isNotEmpty(webhook)) { + CoreWeb.asyncPost(plugin, webhook, post); + } + + } } } @@ -115,6 +118,21 @@ public class CommandPreprocessListener implements Listener { } + public boolean targetIsAuditable(String command) { + String[] commandSplit = command.split(" "); + Collection players = plugin.getServer().getOnlinePlayers(); + + for (String param : commandSplit) { + for (Player p : players) { + if (p.getName().toLowerCase().equals(param)) { + return p.hasPermission("qol.auditable"); + } + } + } + + return false; + } + public String noSlash(String command) { return command.startsWith("/") ? command.substring(1) : command; } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4943f31..91cafdf 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -38,53 +38,56 @@ commands: timeout: description: Timeout command permissions: - qol.admin: - description: Ability to reload the plugin - default: op - qol.priority: - description: Allows a player on past the player cap - default: op - qol.uuid: - description: Ability to use the UUID command - default: op - qol.history: - description: Ability to use the Name History command - default: op - qol.portal: - description: Ability to use the Portal command - default: op - qol.worldinfo: - description: Ability to use the World Info command - deafult: op - qol.sudo: - description: Ability to use the Sudo command - default: op - qol.makeme: - description: Ability to use the MakeMe command - default: true - qol.shadowmute: - description: Ability to use the Shadow Mute command - default: op - 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 - qol.whitelist.command: - description: Ability to use the Whitelist command - default: op - children: - qol.whitelist.bypass: true - qol.timeout.bypass: - description: Allows someone to chat while a Timeout is active - default: op - qol.timeout.command: - description: Ability to use the Timeout command - default: op - children: - qol.timeout.bypass: true + qol.admin: + description: Ability to reload the plugin + default: op + qol.priority: + description: Allows a player on past the player cap + default: op + qol.uuid: + description: Ability to use the UUID command + default: op + qol.history: + description: Ability to use the Name History command + default: op + qol.portal: + description: Ability to use the Portal command + default: op + qol.worldinfo: + description: Ability to use the World Info command + deafult: op + qol.sudo: + description: Ability to use the Sudo command + default: op + qol.makeme: + description: Ability to use the MakeMe command + default: true + qol.shadowmute: + description: Ability to use the Shadow Mute command + default: op + qol.auditable: + description: Audits command usage + default: op + qol.auditor: + 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 + qol.whitelist.command: + description: Ability to use the Whitelist command + default: op + children: + qol.whitelist.bypass: true + qol.timeout.bypass: + description: Allows someone to chat while a Timeout is active + default: op + qol.timeout.command: + description: Ability to use the Timeout command + default: op + children: + qol.timeout.bypass: true From 0f42d6c32014a437d367d115c4379cfde38f8886 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Wed, 26 Sep 2018 15:40:59 -0500 Subject: [PATCH 2/2] Removed audit rank --- .../qol/listeners/CommandPreprocessListener.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java index 110ec9c..f5b2fca 100644 --- a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java @@ -79,9 +79,10 @@ public class CommandPreprocessListener implements Listener { } // Command Auditing - if (sender.hasPermission("qol.audit") && plugin.getConfig().getBoolean("audit.enabled")) { - if (!sender.hasPermission("qol.auditor") && !targetIsAuditable(command)) { - + if (sender.hasPermission("qol.auditable") && plugin.getConfig().getBoolean("audit.enabled")) { + if (sender.hasPermission("qol.auditor") && targetIsAuditable(command)) { + return; + } else { boolean auditable = false; for (String audit : QoL.getAudits()) { @@ -123,8 +124,10 @@ public class CommandPreprocessListener implements Listener { Collection players = plugin.getServer().getOnlinePlayers(); for (String param : commandSplit) { + String lowerCaseParam = param.toLowerCase(); for (Player p : players) { - if (p.getName().toLowerCase().equals(param)) { + + if (p.getName().toLowerCase().equals(lowerCaseParam)) { return p.hasPermission("qol.auditable"); } }