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 whitelist = false;
|
||||||
private static boolean timeout = false;
|
private static boolean timeout = false;
|
||||||
private static List<String> audits = new ArrayList<>();
|
private static List<String> audits = new ArrayList<>();
|
||||||
|
private static List<String> tpCommands = new ArrayList<>();
|
||||||
private static List<LinkCommand> links = new ArrayList<>();
|
private static List<LinkCommand> links = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -149,6 +150,11 @@ public class QoL extends JavaPlugin {
|
||||||
for (String command : config.getStringList("audit.commands")) {
|
for (String command : config.getStringList("audit.commands")) {
|
||||||
audits.add(command.toLowerCase());
|
audits.add(command.toLowerCase());
|
||||||
}
|
}
|
||||||
|
tpCommands = new ArrayList<>();
|
||||||
|
for (String command : config.getStringList("audit.tp_commands")) {
|
||||||
|
tpCommands.add(command.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
links = new ArrayList<>();
|
links = new ArrayList<>();
|
||||||
for (String raw : config.getStringList("links")) {
|
for (String raw : config.getStringList("links")) {
|
||||||
links.add(LinkCommand.fromString(raw));
|
links.add(LinkCommand.fromString(raw));
|
||||||
|
@ -235,9 +241,9 @@ public class QoL extends JavaPlugin {
|
||||||
timeout = enabled;
|
timeout = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getAudits() {
|
public static List<String> getAudits() { return audits; }
|
||||||
return audits;
|
|
||||||
}
|
public static List<String> getTpCommands() {return tpCommands;}
|
||||||
|
|
||||||
public static List<LinkCommand> getLinks() {
|
public static List<LinkCommand> getLinks() {
|
||||||
return links;
|
return links;
|
||||||
|
|
|
@ -13,7 +13,6 @@ import xyz.etztech.core.CoreUtils;
|
||||||
import xyz.etztech.core.web.CoreWeb;
|
import xyz.etztech.core.web.CoreWeb;
|
||||||
import xyz.etztech.qol.QoL;
|
import xyz.etztech.qol.QoL;
|
||||||
import xyz.etztech.qol.other.LinkCommand;
|
import xyz.etztech.qol.other.LinkCommand;
|
||||||
;import xyz.etztech.qol.EtzTechUtil;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -22,7 +21,7 @@ public class CommandPreprocessListener implements Listener {
|
||||||
|
|
||||||
|
|
||||||
QoL plugin;
|
QoL plugin;
|
||||||
Map<Player, String> confirm_tp = new HashMap<>();
|
private Map<Player, String> confirm_tp = new HashMap<>();
|
||||||
|
|
||||||
public CommandPreprocessListener(QoL plugin) {
|
public CommandPreprocessListener(QoL plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
@ -39,14 +38,21 @@ public class CommandPreprocessListener implements Listener {
|
||||||
// Command Auditing
|
// Command Auditing
|
||||||
if (sender.hasPermission("qol.audit") && plugin.getConfig().getBoolean("audit.enabled")) {
|
if (sender.hasPermission("qol.audit") && plugin.getConfig().getBoolean("audit.enabled")) {
|
||||||
boolean auditable = false;
|
boolean auditable = false;
|
||||||
|
|
||||||
|
|
||||||
for (String audit : QoL.getAudits()) {
|
for (String audit : QoL.getAudits()) {
|
||||||
if (noSlash(command).startsWith(noSlash(audit))) {
|
if (noSlash(command).startsWith(noSlash(audit))) {
|
||||||
auditable = true;
|
auditable = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (auditable) {
|
if (auditable) {
|
||||||
Map<String, String> post = new HashMap<>();
|
Map<String, String> post = new HashMap<>();
|
||||||
|
boolean is_tp_command = false;
|
||||||
|
|
||||||
post.put("username", "QoL Auditor");
|
post.put("username", "QoL Auditor");
|
||||||
post.put("content", "[" + StringUtils.capitalize(sender.getGameMode().name().toLowerCase()) + "] " + sender.getName() + " executed command: " + command);
|
post.put("content", "[" + StringUtils.capitalize(sender.getGameMode().name().toLowerCase()) + "] " + sender.getName() + " executed command: " + command);
|
||||||
String webhook = plugin.getConfig().getString("audit.webhook");
|
String webhook = plugin.getConfig().getString("audit.webhook");
|
||||||
|
@ -54,17 +60,31 @@ public class CommandPreprocessListener implements Listener {
|
||||||
CoreWeb.asyncPost(plugin, webhook, post);
|
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))) {
|
if (command.equals(confirm_tp.get(sender))) {
|
||||||
confirm_tp.remove(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) {
|
else if (sender.getGameMode() != GameMode.SPECTATOR) {
|
||||||
|
//Cancel the command
|
||||||
event.setCancelled(true);
|
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);
|
confirm_tp.remove(sender);
|
||||||
|
|
||||||
|
//Add the user to the tp confirm hash map
|
||||||
confirm_tp.put(sender, command);
|
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);
|
sender.spigot().sendMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,8 @@ audit:
|
||||||
- teleport
|
- teleport
|
||||||
- mute
|
- mute
|
||||||
- unban
|
- unban
|
||||||
|
tp_commands:
|
||||||
|
- tp
|
||||||
|
|
||||||
# TPS alert
|
# TPS alert
|
||||||
# Set to 0 to cancel
|
# Set to 0 to cancel
|
||||||
|
|
Loading…
Reference in New Issue