Made changes according to conversation in PR 5.
parent
9ec045dbfe
commit
97161694db
|
@ -28,7 +28,6 @@ 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
|
||||||
|
@ -150,10 +149,6 @@ 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")) {
|
||||||
|
@ -243,8 +238,6 @@ public class QoL extends JavaPlugin {
|
||||||
|
|
||||||
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() {
|
public static List<LinkCommand> getLinks() {
|
||||||
return links;
|
return links;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,13 @@ import xyz.etztech.qol.other.LinkCommand;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class CommandPreprocessListener implements Listener {
|
public class CommandPreprocessListener implements Listener {
|
||||||
|
|
||||||
|
|
||||||
QoL plugin;
|
QoL plugin;
|
||||||
private Map<Player, String> confirm_tp = new HashMap<>();
|
private Map<UUID, String> confirmTpMap = new HashMap<>();
|
||||||
|
|
||||||
public CommandPreprocessListener(QoL plugin) {
|
public CommandPreprocessListener(QoL plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
@ -38,7 +39,26 @@ 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;
|
||||||
|
boolean isTpCommand = false;
|
||||||
|
|
||||||
|
//check if the command is a tp command
|
||||||
|
if (noSlash(command).startsWith("tp") || noSlash(command).startsWith("teleport") || noSlash(command).startsWith("lagg tpchunk")) {
|
||||||
|
//If the user is in the confirm tp map, remove them and let the command run
|
||||||
|
if (command.equals(confirmTpMap.get(sender.getUniqueId()))) {
|
||||||
|
confirmTpMap.remove(sender.getUniqueId());
|
||||||
|
}
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//Add the user to the tp confirm map
|
||||||
|
confirmTpMap.put(sender.getUniqueId(), command);
|
||||||
|
|
||||||
|
TextComponent message = new TextComponent(ChatColor.GREEN + "You are TPing out of spec, run command again to confirm.");
|
||||||
|
sender.spigot().sendMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (String audit : QoL.getAudits()) {
|
for (String audit : QoL.getAudits()) {
|
||||||
if (noSlash(command).startsWith(noSlash(audit))) {
|
if (noSlash(command).startsWith(noSlash(audit))) {
|
||||||
|
@ -47,11 +67,9 @@ public class CommandPreprocessListener implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
|
@ -60,35 +78,6 @@ public class CommandPreprocessListener implements Listener {
|
||||||
CoreWeb.asyncPost(plugin, webhook, post);
|
CoreWeb.asyncPost(plugin, webhook, post);
|
||||||
}
|
}
|
||||||
|
|
||||||
//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);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,12 +99,4 @@ public class CommandPreprocessListener implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,6 @@ 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