From a548ef779a0290d92d183ccc943a5a4c35743a74 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 22 Sep 2018 14:18:06 -0500 Subject: [PATCH] Added confirmation for tping when out of spec. --- .../listeners/CommandPreprocessListener.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java index 64c0a2b..a891031 100644 --- a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java @@ -4,6 +4,7 @@ import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.TextComponent; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; +import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -12,6 +13,7 @@ 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; @@ -20,6 +22,7 @@ public class CommandPreprocessListener implements Listener { QoL plugin; + Map confirm_tp = new HashMap<>(); public CommandPreprocessListener(QoL plugin) { this.plugin = plugin; @@ -50,6 +53,22 @@ public class CommandPreprocessListener implements Listener { if (StringUtils.isNotEmpty(webhook)) { CoreWeb.asyncPost(plugin, webhook, post); } + + if (base.equals("tp")) { + if (command.equals(confirm_tp.get(sender))) { + confirm_tp.remove(sender); + } + else if (sender.getGameMode() != GameMode.SPECTATOR) { + event.setCancelled(true); + TextComponent message = new TextComponent(ChatColor.GREEN + "You are TPing out of spec, run command again to confirm."); + + confirm_tp.remove(sender); + confirm_tp.put(sender, command); + + sender.spigot().sendMessage(message); + } + } + } }