From 18e36727f2ec9e7a24e951cf32df7ce0b57b4e7a Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 23 Sep 2018 14:49:17 -0500 Subject: [PATCH 1/4] Added check in CommandPreprocessListener to hide a user when they go into spec and put them back into the same visibility after they come out of spec. --- pom.xml | 9 +++++ src/main/java/xyz/etztech/qol/QoL.java | 14 ++++++-- .../listeners/CommandPreprocessListener.java | 34 +++++++++++++++++-- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 6aa771c..911ef55 100644 --- a/pom.xml +++ b/pom.xml @@ -68,6 +68,11 @@ Essentials 2.14-SNAPSHOT + + us.dynmap + dynmap-api + 1.9.4 + commons-lang commons-lang @@ -90,6 +95,10 @@ etztech-repo http://repo.etztech.xyz + + dynmap-repo + http://repo.mikeprimm.com/ + ess-repo http://repo.ess3.net/content/groups/essentials diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index 1ba18d1..2b753c3 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -11,6 +11,7 @@ import xyz.etztech.qol.commands.*; import xyz.etztech.qol.listeners.*; import xyz.etztech.qol.other.LinkCommand; import xyz.etztech.qol.other.TPSRunnable; +import org.dynmap.DynmapAPI; import java.util.ArrayList; import java.util.List; @@ -20,6 +21,7 @@ public class QoL extends JavaPlugin { private static QoL instance; private static IEssentials essentials = null; + private static DynmapAPI dynmap = null; public static FileConfiguration config; private Logger log = Logger.getLogger( "Minecraft" ); @@ -43,6 +45,12 @@ public class QoL extends JavaPlugin { essentials = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials"); } + //Dynmap hook + if (Bukkit.getPluginManager().isPluginEnabled("dynmap")) { + log("Hooked into Essentials for TPS alert."); + dynmap = (DynmapAPI) Bukkit.getPluginManager().getPlugin("dynmap"); + } + if( isEnabled() ) { // Add listeners @@ -240,9 +248,9 @@ public class QoL extends JavaPlugin { return links; } - public static IEssentials getEssentials() { - return essentials; - } + public static IEssentials getEssentials() { return essentials; } + + public static DynmapAPI getDynmap() { return dynmap; } private void runTask(final String command) { diff --git a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java index 0c9d7bb..ae379f7 100644 --- a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java @@ -13,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 org.dynmap.DynmapAPI; import java.util.HashMap; import java.util.Map; @@ -20,14 +21,19 @@ import java.util.UUID; public class CommandPreprocessListener implements Listener { - QoL plugin; private Map confirmTpMap = new HashMap<>(); + private Map dynmapVisibleStatusMap = new HashMap<>(); + private DynmapAPI dynmap; public CommandPreprocessListener(QoL plugin) { this.plugin = plugin; - } + if (plugin.getDynmap() != null) { + this.dynmap = plugin.getDynmap(); + } + + } @EventHandler public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { @@ -36,9 +42,27 @@ public class CommandPreprocessListener implements Listener { String base = command.split(" ")[0].substring(1).toLowerCase(); // Strip the slash Player sender = event.getPlayer(); + // Spec dynmap hide + if (base.equals("spec") && this.dynmap != null) { + boolean visibleStatus; + if (sender.getGameMode() != GameMode.SPECTATOR){ + dynmapVisibleStatusMap.put(sender.getUniqueId(), dynmap.getPlayerVisbility(sender.getDisplayName())); + visibleStatus = false; + } + else if (dynmapVisibleStatusMap.containsKey(sender.getUniqueId())){ + visibleStatus = dynmapVisibleStatusMap.remove(sender.getUniqueId()); + } + else { + visibleStatus = true; + } + + dynmap.setPlayerVisiblity(sender.getDisplayName(), visibleStatus); + } + + // Spec TP confirmation 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 (noSlash(base).equals("tp") || noSlash(base).startsWith("tele") || noSlash(command).toLowerCase().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()); @@ -81,6 +105,10 @@ public class CommandPreprocessListener implements Listener { } } + if (noSlash(base).equals("spec")) { + + } + // Links for (LinkCommand linkCommand : QoL.getLinks()) { if (base.equalsIgnoreCase(linkCommand.getCommand())) { From 0f477917959927f367a339237d821a1a28d69858 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 23 Sep 2018 16:20:08 -0500 Subject: [PATCH 2/4] Added check if the user has the QoLAudit perm. --- .../xyz/etztech/qol/listeners/CommandPreprocessListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java index ae379f7..c405c5a 100644 --- a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java @@ -43,7 +43,7 @@ public class CommandPreprocessListener implements Listener { Player sender = event.getPlayer(); // Spec dynmap hide - if (base.equals("spec") && this.dynmap != null) { + if (base.equals("spec") && this.dynmap != null && sender.hasPermission("qol.audit")) { boolean visibleStatus; if (sender.getGameMode() != GameMode.SPECTATOR){ dynmapVisibleStatusMap.put(sender.getUniqueId(), dynmap.getPlayerVisbility(sender.getDisplayName())); From 408a5e00456233981c1dacc129c3235699e961ac Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 23 Sep 2018 17:19:22 -0500 Subject: [PATCH 3/4] Made changes based on the conversation of Issue #6. --- .../listeners/CommandPreprocessListener.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java index c405c5a..13aba4b 100644 --- a/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java @@ -24,15 +24,9 @@ public class CommandPreprocessListener implements Listener { QoL plugin; private Map confirmTpMap = new HashMap<>(); private Map dynmapVisibleStatusMap = new HashMap<>(); - private DynmapAPI dynmap; public CommandPreprocessListener(QoL plugin) { this.plugin = plugin; - - if (plugin.getDynmap() != null) { - this.dynmap = plugin.getDynmap(); - } - } @EventHandler @@ -41,12 +35,13 @@ public class CommandPreprocessListener implements Listener { String command = event.getMessage(); String base = command.split(" ")[0].substring(1).toLowerCase(); // Strip the slash Player sender = event.getPlayer(); + DynmapAPI dynmap = plugin.getDynmap(); // Spec dynmap hide - if (base.equals("spec") && this.dynmap != null && sender.hasPermission("qol.audit")) { + if (base.equals("spec") && sender.hasPermission("SafeSpectate.spectate") && dynmap != null) { boolean visibleStatus; if (sender.getGameMode() != GameMode.SPECTATOR){ - dynmapVisibleStatusMap.put(sender.getUniqueId(), dynmap.getPlayerVisbility(sender.getDisplayName())); + dynmapVisibleStatusMap.put(sender.getUniqueId(), dynmap.getPlayerVisbility(sender.getName())); visibleStatus = false; } else if (dynmapVisibleStatusMap.containsKey(sender.getUniqueId())){ @@ -62,7 +57,7 @@ public class CommandPreprocessListener implements Listener { // Spec TP confirmation if (sender.hasPermission("qol.tpconfirm")) { //check if the command is a tp command - if (noSlash(base).equals("tp") || noSlash(base).startsWith("tele") || noSlash(command).toLowerCase().startsWith("lagg tpchunk")) { + if (noSlash(base).equals("tp") || noSlash(base).toLowerCase().startsWith("tele") || noSlash(command).toLowerCase().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()); @@ -105,10 +100,6 @@ public class CommandPreprocessListener implements Listener { } } - if (noSlash(base).equals("spec")) { - - } - // Links for (LinkCommand linkCommand : QoL.getLinks()) { if (base.equalsIgnoreCase(linkCommand.getCommand())) { From 56b6da012ba3589a9ee411ec91e3ec3d9687263f Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 23 Sep 2018 17:23:53 -0500 Subject: [PATCH 4/4] do i even read my code --- src/main/java/xyz/etztech/qol/QoL.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index 2b753c3..c2cc943 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -47,7 +47,7 @@ public class QoL extends JavaPlugin { //Dynmap hook if (Bukkit.getPluginManager().isPluginEnabled("dynmap")) { - log("Hooked into Essentials for TPS alert."); + log("Hooked into Dynmap."); dynmap = (DynmapAPI) Bukkit.getPluginManager().getPlugin("dynmap"); }