Merge branch 'master' of ZeroHD/QoL into master
Adds confirmation when attempting to TP outside of Spectator mode.master
commit
6ef47e7804
|
@ -43,8 +43,6 @@ public class QoL extends JavaPlugin {
|
||||||
essentials = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials");
|
essentials = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if( isEnabled() ) {
|
if( isEnabled() ) {
|
||||||
|
|
||||||
// Add listeners
|
// Add listeners
|
||||||
|
@ -149,6 +147,7 @@ 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
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 +234,7 @@ 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<LinkCommand> getLinks() {
|
public static List<LinkCommand> getLinks() {
|
||||||
return links;
|
return links;
|
||||||
|
|
|
@ -4,6 +4,7 @@ import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
@ -15,11 +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<UUID, String> confirmTpMap = new HashMap<>();
|
||||||
|
|
||||||
public CommandPreprocessListener(QoL plugin) {
|
public CommandPreprocessListener(QoL plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
@ -33,23 +36,48 @@ public class CommandPreprocessListener implements Listener {
|
||||||
String base = command.split(" ")[0].substring(1).toLowerCase(); // Strip the slash
|
String base = command.split(" ")[0].substring(1).toLowerCase(); // Strip the slash
|
||||||
Player sender = event.getPlayer();
|
Player sender = event.getPlayer();
|
||||||
|
|
||||||
|
if (sender.hasPermission("qol.tpconfirm")) {
|
||||||
|
//check if the command is a tp command
|
||||||
|
if (noSlash(base).equals("tp") || noSlash(base).startsWith("tele") || 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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<>();
|
||||||
|
|
||||||
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");
|
||||||
if (StringUtils.isNotEmpty(webhook)) {
|
if (StringUtils.isNotEmpty(webhook)) {
|
||||||
CoreWeb.asyncPost(plugin, webhook, post);
|
CoreWeb.asyncPost(plugin, webhook, post);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,12 +99,4 @@ public class CommandPreprocessListener implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,9 @@ permissions:
|
||||||
qol.audit:
|
qol.audit:
|
||||||
description: Audits command usage
|
description: Audits command usage
|
||||||
default: op
|
default: op
|
||||||
|
qol.tpconfirm:
|
||||||
|
description: Makes the user confirm they want to TP out of spec
|
||||||
|
default: op
|
||||||
qol.whitelist.bypass:
|
qol.whitelist.bypass:
|
||||||
description: Allows someone into the server when Whitelist is enabled
|
description: Allows someone into the server when Whitelist is enabled
|
||||||
default: op
|
default: op
|
||||||
|
|
Loading…
Reference in New Issue