Make spec confirmation configurable (#39)
parent
ee0867d5cc
commit
d55fb1112a
|
@ -16,12 +16,15 @@ Additions
|
||||||
``**bold**`` |br|
|
``**bold**`` |br|
|
||||||
``~~strikethrough~~``
|
``~~strikethrough~~``
|
||||||
|
|
||||||
|
* `Spec Confirm`_ - Updates the TP confirmation to allow for a configurable list of commands
|
||||||
* `Dynmap Link Command`_ - Allows a user to get a link to dynmap pointing to their current location
|
* `Dynmap Link Command`_ - Allows a user to get a link to dynmap pointing to their current location
|
||||||
|
|
||||||
.. _Checkup Command: https://git.etztech.xyz/24CarrotCraft/QoL/pulls/33
|
.. _Checkup Command: https://git.etztech.xyz/24CarrotCraft/QoL/pulls/33
|
||||||
.. _Discord Syntax: https://git.etztech.xyz/24CarrotCraft/QoL/pulls/36
|
.. _Discord Syntax: https://git.etztech.xyz/24CarrotCraft/QoL/pulls/36
|
||||||
|
.. _Spec Confirm: https://git.etztech.xyz/24CarrotCraft/QoL/pulls/39
|
||||||
.. _Dynmap Link Command: https://git.etztech.xyz/24CarrotCraft/QoL/pulls/40
|
.. _Dynmap Link Command: https://git.etztech.xyz/24CarrotCraft/QoL/pulls/40
|
||||||
|
|
||||||
|
|
||||||
Bug Fixes
|
Bug Fixes
|
||||||
---------
|
---------
|
||||||
None
|
None
|
|
@ -24,7 +24,7 @@ Permissions
|
||||||
|
|
||||||
``qol.auditor`` - Ability to bypass auditing when running commands on auditable
|
``qol.auditor`` - Ability to bypass auditing when running commands on auditable
|
||||||
|
|
||||||
``qol.tpconfirm`` - Forces a player to confirm teleports when outside spectator mode
|
``qol.specconfirm`` - Forces a player to confirm a (configurable) command(s) when outside spectator mode
|
||||||
|
|
||||||
``qol.whitelist.bypass`` - Allows someone into the server when Whitelist mode is enabled
|
``qol.whitelist.bypass`` - Allows someone into the server when Whitelist mode is enabled
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,26 @@
|
||||||
package xyz.etztech.qol.listeners;
|
package xyz.etztech.qol.listeners;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
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.GameMode;
|
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;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import org.bukkit.event.server.ServerCommandEvent;
|
import org.bukkit.event.server.ServerCommandEvent;
|
||||||
import xyz.etztech.core.CoreUtils;
|
import org.dynmap.DynmapAPI;
|
||||||
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 org.dynmap.DynmapAPI;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
public class CommandPreprocessListener implements Listener {
|
public class CommandPreprocessListener implements Listener {
|
||||||
|
|
||||||
QoL plugin;
|
QoL plugin;
|
||||||
private Map<UUID, String> confirmTpMap = new HashMap<>();
|
private Map<UUID, String> confirmMap = new HashMap<>();
|
||||||
private Map<UUID, Boolean> dynmapVisibleStatusMap = new HashMap<>();
|
private Map<UUID, Boolean> dynmapVisibleStatusMap = new HashMap<>();
|
||||||
|
|
||||||
public CommandPreprocessListener(QoL plugin) {
|
public CommandPreprocessListener(QoL plugin) {
|
||||||
|
@ -73,27 +69,39 @@ public class CommandPreprocessListener implements Listener {
|
||||||
visibleStatus = true;
|
visibleStatus = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.spigot().sendMessage(new TextComponent(ChatColor.GREEN + message));
|
TextComponent textComponent = new TextComponent(message);
|
||||||
|
textComponent.setColor(ChatColor.GREEN);
|
||||||
|
sender.spigot().sendMessage(textComponent);
|
||||||
dynmap.setPlayerVisiblity(sender.getName(), visibleStatus);
|
dynmap.setPlayerVisiblity(sender.getName(), visibleStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spec TP confirmation
|
// Spec confirmation
|
||||||
if (sender.hasPermission("qol.tpconfirm")) {
|
List<String> specConfirm = plugin.getConfig().getStringList("spec-confirm");
|
||||||
//check if the command is a tp command
|
if (sender.hasPermission("qol.specconfirm")) {
|
||||||
if (noSlash(base).equals("tp") || noSlash(base).toLowerCase().startsWith("tele") || noSlash(command).toLowerCase().startsWith("lagg tpchunk")) {
|
boolean confirm = false;
|
||||||
//If the user is in the confirm tp map, remove them and let the command run
|
for (String confirmable : specConfirm) {
|
||||||
if (command.equals(confirmTpMap.get(sender.getUniqueId()))) {
|
// If the player command either starts with a confirmable command and space (meaning confirmation is needed regardless of arguments)
|
||||||
confirmTpMap.remove(sender.getUniqueId());
|
// Or the player command is a full match to the confirmable command
|
||||||
|
if (noSlash(command).toLowerCase().startsWith(confirmable.toLowerCase() + " ") || noSlash(command).toLowerCase().equals(confirmable.toLowerCase())) {
|
||||||
|
confirm = true;
|
||||||
}
|
}
|
||||||
//If the user is running the tp command for the first time outside of spec
|
}
|
||||||
|
//check if the command is a spec confirm command
|
||||||
|
if (confirm) {
|
||||||
|
//If the user is in the confirm map, remove them and let the command run
|
||||||
|
if (command.equals(confirmMap.get(sender.getUniqueId()))) {
|
||||||
|
confirmMap.remove(sender.getUniqueId());
|
||||||
|
}
|
||||||
|
//If the user is running the command for the first time outside of spec
|
||||||
else if (sender.getGameMode() != GameMode.SPECTATOR) {
|
else if (sender.getGameMode() != GameMode.SPECTATOR) {
|
||||||
//Cancel the command
|
//Cancel the command
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
//Add the user to the tp confirm map
|
//Add the user to the spec confirm map
|
||||||
confirmTpMap.put(sender.getUniqueId(), command);
|
confirmMap.put(sender.getUniqueId(), command);
|
||||||
|
|
||||||
TextComponent message = new TextComponent(ChatColor.GREEN + "You are TPing out of spec, run command again to confirm.");
|
TextComponent message = new TextComponent("You are running this command out of spec, run again to confirm.");
|
||||||
|
message.setColor(ChatColor.GREEN);
|
||||||
sender.spigot().sendMessage(message);
|
sender.spigot().sendMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,7 +122,8 @@ public class CommandPreprocessListener implements Listener {
|
||||||
for (LinkCommand linkCommand : QoL.getLinks()) {
|
for (LinkCommand linkCommand : QoL.getLinks()) {
|
||||||
if (base.equalsIgnoreCase(linkCommand.getCommand())) {
|
if (base.equalsIgnoreCase(linkCommand.getCommand())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
TextComponent link = new TextComponent(ChatColor.GREEN + linkCommand.getMessage());
|
TextComponent link = new TextComponent(linkCommand.getMessage());
|
||||||
|
link.setColor(ChatColor.GREEN);
|
||||||
link.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, linkCommand.getUrl()));
|
link.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, linkCommand.getUrl()));
|
||||||
sender.spigot().sendMessage(link);
|
sender.spigot().sendMessage(link);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -94,6 +94,12 @@ disable-fire:
|
||||||
view-distances:
|
view-distances:
|
||||||
world: 2
|
world: 2
|
||||||
|
|
||||||
|
# A list of commands to confirm before using if the user isn't in spectator mode
|
||||||
|
spec-confirm:
|
||||||
|
- "tp"
|
||||||
|
- "checkup"
|
||||||
|
- "lagg tpchunk"
|
||||||
|
|
||||||
# Dynmap link
|
# Dynmap link
|
||||||
# Leave url blank to disable
|
# Leave url blank to disable
|
||||||
dynmap:
|
dynmap:
|
||||||
|
|
|
@ -97,8 +97,8 @@ permissions:
|
||||||
qol.auditor:
|
qol.auditor:
|
||||||
description: Ability to bypass auditing when running commands on auditable
|
description: Ability to bypass auditing when running commands on auditable
|
||||||
default: op
|
default: op
|
||||||
qol.tpconfirm:
|
qol.specconfirm:
|
||||||
description: Makes the user confirm they want to TP out of spec
|
description: Makes the user confirm they want to run (configurable) command(s) out of spec
|
||||||
default: op
|
default: op
|
||||||
qol.griefalert:
|
qol.griefalert:
|
||||||
description: Alerts the user when monitored actions are encountered
|
description: Alerts the user when monitored actions are encountered
|
||||||
|
|
Loading…
Reference in New Issue