Pulled out webhook code and audit command check code into their own functions.

master
Joey Hines 2018-09-27 13:51:36 -05:00
parent a46c7a6e56
commit 6a8535142c
1 changed files with 36 additions and 19 deletions

View File

@ -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<String, String> 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<String, String> 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<? extends Player> players = plugin.getServer().getOnlinePlayers();