diff --git a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java index 798055b..e626b6f 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,17 @@ public class CommandPreprocessListener implements Listener { this.plugin = plugin; } + @EventHandler + public void onServerCommand(ServerCommandEvent event) { + if (plugin.getConfig().getBoolean("audit.enabled")) { + String command = event.getCommand(); + + if (commandIsAuditable(command)) { + sendAuditWebhook("Console", null, command); + } + } + } + @EventHandler public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { @@ -83,25 +95,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 +114,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(); 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