Merge branch 'master' of ZeroHD/QoL into master

master
Etzelia 2018-09-28 15:19:55 +02:00 committed by Gitea
commit 8691743af9
2 changed files with 49 additions and 20 deletions

View File

@ -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<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 +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<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();

View File

@ -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