forked from Minecraft/QoL
Added a way to specify tp commands in the config
parent
a548ef779a
commit
9ec045dbfe
|
@ -28,6 +28,7 @@ public class QoL extends JavaPlugin {
|
|||
private static boolean whitelist = false;
|
||||
private static boolean timeout = false;
|
||||
private static List<String> audits = new ArrayList<>();
|
||||
private static List<String> tpCommands = new ArrayList<>();
|
||||
private static List<LinkCommand> links = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
|
@ -149,6 +150,11 @@ public class QoL extends JavaPlugin {
|
|||
for (String command : config.getStringList("audit.commands")) {
|
||||
audits.add(command.toLowerCase());
|
||||
}
|
||||
tpCommands = new ArrayList<>();
|
||||
for (String command : config.getStringList("audit.tp_commands")) {
|
||||
tpCommands.add(command.toLowerCase());
|
||||
}
|
||||
|
||||
links = new ArrayList<>();
|
||||
for (String raw : config.getStringList("links")) {
|
||||
links.add(LinkCommand.fromString(raw));
|
||||
|
@ -235,9 +241,9 @@ public class QoL extends JavaPlugin {
|
|||
timeout = enabled;
|
||||
}
|
||||
|
||||
public static List<String> getAudits() {
|
||||
return audits;
|
||||
}
|
||||
public static List<String> getAudits() { return audits; }
|
||||
|
||||
public static List<String> getTpCommands() {return tpCommands;}
|
||||
|
||||
public static List<LinkCommand> getLinks() {
|
||||
return links;
|
||||
|
|
|
@ -13,7 +13,6 @@ import xyz.etztech.core.CoreUtils;
|
|||
import xyz.etztech.core.web.CoreWeb;
|
||||
import xyz.etztech.qol.QoL;
|
||||
import xyz.etztech.qol.other.LinkCommand;
|
||||
;import xyz.etztech.qol.EtzTechUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -22,7 +21,7 @@ public class CommandPreprocessListener implements Listener {
|
|||
|
||||
|
||||
QoL plugin;
|
||||
Map<Player, String> confirm_tp = new HashMap<>();
|
||||
private Map<Player, String> confirm_tp = new HashMap<>();
|
||||
|
||||
public CommandPreprocessListener(QoL plugin) {
|
||||
this.plugin = plugin;
|
||||
|
@ -39,14 +38,21 @@ public class CommandPreprocessListener implements Listener {
|
|||
// Command Auditing
|
||||
if (sender.hasPermission("qol.audit") && plugin.getConfig().getBoolean("audit.enabled")) {
|
||||
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<>();
|
||||
boolean is_tp_command = false;
|
||||
|
||||
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");
|
||||
|
@ -54,17 +60,31 @@ public class CommandPreprocessListener implements Listener {
|
|||
CoreWeb.asyncPost(plugin, webhook, post);
|
||||
}
|
||||
|
||||
if (base.equals("tp")) {
|
||||
//Check if the command is a tp_command
|
||||
for (String tp_command : QoL.getTpCommands()) {
|
||||
if (noSlash(command).startsWith(noSlash(tp_command))) {
|
||||
is_tp_command = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_tp_command) {
|
||||
//If the user is in the confirm tp map, remove them and let the command run
|
||||
if (command.equals(confirm_tp.get(sender))) {
|
||||
confirm_tp.remove(sender);
|
||||
}
|
||||
//If the user is running the tp command for the first time outside of spec
|
||||
else if (sender.getGameMode() != GameMode.SPECTATOR) {
|
||||
//Cancel the command
|
||||
event.setCancelled(true);
|
||||
TextComponent message = new TextComponent(ChatColor.GREEN + "You are TPing out of spec, run command again to confirm.");
|
||||
|
||||
//Remove the user from the confirm tp map if they are already on it
|
||||
confirm_tp.remove(sender);
|
||||
|
||||
//Add the user to the tp confirm hash map
|
||||
confirm_tp.put(sender, command);
|
||||
|
||||
TextComponent message = new TextComponent(ChatColor.GREEN + "You are TPing out of spec, run command again to confirm.");
|
||||
sender.spigot().sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ audit:
|
|||
- teleport
|
||||
- mute
|
||||
- unban
|
||||
tp_commands:
|
||||
- tp
|
||||
|
||||
# TPS alert
|
||||
# Set to 0 to cancel
|
||||
|
|
Loading…
Reference in New Issue