From d0e0dc8d7f21007bb8c237a8a80cc3bd834d6cb4 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Wed, 26 Sep 2018 15:43:44 -0500 Subject: [PATCH 1/6] Updated qol.auditor description in plugin.yml --- src/main/resources/plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 91cafdf..05091c3 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -69,7 +69,7 @@ permissions: description: Audits command usage default: op qol.auditor: - description: Audits command usage + 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 From 6a8535142c477bfa7b3a13f487c49202fff2f0a9 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Thu, 27 Sep 2018 13:51:36 -0500 Subject: [PATCH 2/6] Pulled out webhook code and audit command check code into their own functions. --- .../listeners/CommandPreprocessListener.java | 55 ++++++++++++------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java index f5b2fca..6bd3b98 100644 --- a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java @@ -83,25 +83,8 @@ public class CommandPreprocessListener implements Listener { if (sender.hasPermission("qol.auditor") && targetIsAuditable(command)) { return; } else { - boolean auditable = false; - - 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); - } - + if (commandIsAuditable(command)) { + sendAuditWebhook(sender.getName(), sender.getGameMode(), command); } } } @@ -119,6 +102,40 @@ public class CommandPreprocessListener implements Listener { } + public boolean commandIsAuditable(String command) { + for (String audit : QoL.getAudits()) { + if (noSlash(command).startsWith(noSlash(audit))) { + return true; + } + } + + return false; + } + + public void sendAuditWebhook(String commandSource, GameMode gamemode, String command) { + + String content = ""; + + if (gamemode != null) { + content += "[" + StringUtils.capitalize(gamemode.name().toLowerCase()) + "] "; + } + + content += commandSource + " executed command: " + command; + + sendWebhook("QoL Auditor", content); + } + + public void sendWebhook(String username, String content) { + String webhook = plugin.getConfig().getString("audit.webhook"); + + if (StringUtils.isNotEmpty(webhook)) { + Map post = new HashMap<>(); + post.put("username", username); + post.put("content", content); + CoreWeb.asyncPost(plugin, webhook, post); + } + } + public boolean targetIsAuditable(String command) { String[] commandSplit = command.split(" "); Collection players = plugin.getServer().getOnlinePlayers(); From c6981f7838c6151d27eb6ff53bd7362e3a634c72 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Thu, 27 Sep 2018 14:50:08 -0500 Subject: [PATCH 3/6] Added console auditing --- src/main/java/xyz/etztech/qol/QoL.java | 1 + .../qol/listeners/CommandPreprocessListener.java | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index 3b4cd21..ee59d38 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -19,6 +19,7 @@ import java.util.logging.Logger; @MavenLibrary(group = "net.ess3", artifact = "Essentials", version = "2.13.1", repository = "http://repo.ess3.net/content/groups/essentials") @MavenLibrary(group = "us.dynmap", artifact = "dynmap-api", version = "1.9.4", repository = "http://repo.mikeprimm.com/") @MavenLibrary(group = "commons-lang", artifact = "commons-lang", version = "2.6") + public class QoL extends MavenPlugin { private static QoL instance; diff --git a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java index 61345f5..58bb7ab 100644 --- a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java @@ -9,6 +9,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.server.ServerCommandEvent; import xyz.etztech.core.CoreUtils; import xyz.etztech.core.web.CoreWeb; import xyz.etztech.qol.QoL; @@ -30,6 +31,18 @@ public class CommandPreprocessListener implements Listener { this.plugin = plugin; } + @EventHandler + public void onServerCommandEvent(ServerCommandEvent event) { + if (plugin.getConfig().getBoolean("audit.enabled")) { + String command = event.getCommand(); + + if (commandIsAuditable(command)) { + sendAuditWebhook("Console", null, command); + return; + } + } + } + @EventHandler public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { From b0643aa0e1a8cc22c4b0ecf7290a1221c9a837eb Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Thu, 27 Sep 2018 15:29:59 -0500 Subject: [PATCH 4/6] renamed onServerCommandEvent to onServerCommand --- .../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 58bb7ab..5185aa3 100644 --- a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java @@ -32,7 +32,7 @@ public class CommandPreprocessListener implements Listener { } @EventHandler - public void onServerCommandEvent(ServerCommandEvent event) { + public void onServerCommand(ServerCommandEvent event) { if (plugin.getConfig().getBoolean("audit.enabled")) { String command = event.getCommand(); From 3997b6bebc4c07aea7c39f70f9f507c8cd9e936d Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Thu, 27 Sep 2018 15:34:12 -0500 Subject: [PATCH 5/6] Removed unnecessary return --- .../xyz/etztech/qol/listeners/CommandPreprocessListener.java | 1 - 1 file changed, 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 5185aa3..e626b6f 100644 --- a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java @@ -38,7 +38,6 @@ public class CommandPreprocessListener implements Listener { if (commandIsAuditable(command)) { sendAuditWebhook("Console", null, command); - return; } } } From e0cf87da3718fa5297a208af50c911b929b1c685 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Thu, 27 Sep 2018 18:58:45 -0500 Subject: [PATCH 6/6] Added back in dependencies --- src/main/java/xyz/etztech/qol/QoL.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index b560e4b..7c567b8 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -20,6 +20,7 @@ import java.util.logging.Logger; @MavenLibrary(group = "net.ess3", artifact = "Essentials", version = "2.13.1", repository = "http://repo.ess3.net/content/groups/essentials") @MavenLibrary(group = "us.dynmap", artifact = "dynmap-api", version = "1.9.4", repository = "http://repo.mikeprimm.com/") @MavenLibrary(group = "commons-lang", artifact = "commons-lang", version = "2.6") +@MavenLibrary(group = "commons-logging", artifact = "commons-logging", version = "1.2") public class QoL extends MavenPlugin { private static QoL instance;