Added auditor and auditable perms. Users with the auditor perm can run audited commands on auditable players without being audited.

master
Joey Hines 2018-09-26 15:11:36 -05:00
parent cae4925511
commit 762346cf37
2 changed files with 87 additions and 66 deletions

View File

@ -18,6 +18,7 @@ import org.dynmap.DynmapAPI;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.Collection;
public class CommandPreprocessListener implements Listener { public class CommandPreprocessListener implements Listener {
@ -34,7 +35,6 @@ public class CommandPreprocessListener implements Listener {
String command = event.getMessage(); String command = event.getMessage();
String base = command.split(" ")[0].substring(1).toLowerCase(); // Strip the slash String base = command.split(" ")[0].substring(1).toLowerCase(); // Strip the slash
String auditBypassPerm = "qol.audit.bypass." + base;
Player sender = event.getPlayer(); Player sender = event.getPlayer();
DynmapAPI dynmap = plugin.getDynmap(); DynmapAPI dynmap = plugin.getDynmap();
@ -79,26 +79,29 @@ public class CommandPreprocessListener implements Listener {
} }
// Command Auditing // Command Auditing
if (sender.hasPermission("qol.audit") && !sender.hasPermission(auditBypassPerm) && plugin.getConfig().getBoolean("audit.enabled")) { if (sender.hasPermission("qol.audit") && plugin.getConfig().getBoolean("audit.enabled")) {
boolean auditable = false; if (!sender.hasPermission("qol.auditor") && !targetIsAuditable(command)) {
for (String audit : QoL.getAudits()) { boolean auditable = false;
if (noSlash(command).startsWith(noSlash(audit))) {
auditable = true;
break;
}
}
if (auditable) { for (String audit : QoL.getAudits()) {
Map<String, String> post = new HashMap<>(); if (noSlash(command).startsWith(noSlash(audit))) {
auditable = true;
post.put("username", "QoL Auditor"); break;
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 (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);
}
}
} }
} }
@ -115,6 +118,21 @@ public class CommandPreprocessListener implements Listener {
} }
public boolean targetIsAuditable(String command) {
String[] commandSplit = command.split(" ");
Collection<? extends Player> 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) { public String noSlash(String command) {
return command.startsWith("/") ? command.substring(1) : command; return command.startsWith("/") ? command.substring(1) : command;
} }

View File

@ -38,53 +38,56 @@ commands:
timeout: timeout:
description: Timeout command description: Timeout command
permissions: permissions:
qol.admin: qol.admin:
description: Ability to reload the plugin description: Ability to reload the plugin
default: op default: op
qol.priority: qol.priority:
description: Allows a player on past the player cap description: Allows a player on past the player cap
default: op default: op
qol.uuid: qol.uuid:
description: Ability to use the UUID command description: Ability to use the UUID command
default: op default: op
qol.history: qol.history:
description: Ability to use the Name History command description: Ability to use the Name History command
default: op default: op
qol.portal: qol.portal:
description: Ability to use the Portal command description: Ability to use the Portal command
default: op default: op
qol.worldinfo: qol.worldinfo:
description: Ability to use the World Info command description: Ability to use the World Info command
deafult: op deafult: op
qol.sudo: qol.sudo:
description: Ability to use the Sudo command description: Ability to use the Sudo command
default: op default: op
qol.makeme: qol.makeme:
description: Ability to use the MakeMe command description: Ability to use the MakeMe command
default: true default: true
qol.shadowmute: qol.shadowmute:
description: Ability to use the Shadow Mute command description: Ability to use the Shadow Mute command
default: op default: op
qol.audit: qol.auditable:
description: Audits command usage description: Audits command usage
default: op default: op
qol.tpconfirm: qol.auditor:
description: Makes the user confirm they want to TP out of spec description: Audits command usage
default: op default: op
qol.whitelist.bypass: qol.tpconfirm:
description: Allows someone into the server when Whitelist is enabled description: Makes the user confirm they want to TP out of spec
default: op default: op
qol.whitelist.command: qol.whitelist.bypass:
description: Ability to use the Whitelist command description: Allows someone into the server when Whitelist is enabled
default: op default: op
children: qol.whitelist.command:
qol.whitelist.bypass: true description: Ability to use the Whitelist command
qol.timeout.bypass: default: op
description: Allows someone to chat while a Timeout is active children:
default: op qol.whitelist.bypass: true
qol.timeout.command: qol.timeout.bypass:
description: Ability to use the Timeout command description: Allows someone to chat while a Timeout is active
default: op default: op
children: qol.timeout.command:
qol.timeout.bypass: true description: Ability to use the Timeout command
default: op
children:
qol.timeout.bypass: true