From 255549099f9c8efce3902d3b80a648c850a1e156 Mon Sep 17 00:00:00 2001 From: gravitylow Date: Tue, 15 Apr 2014 13:18:13 -0400 Subject: [PATCH] Store and lookup from UUID --- .../java/com/massivecraft/factions/P.java | 3 - .../massivecraft/factions/cmd/CmdHome.java | 5 -- .../integration/EssentialsFeatures.java | 86 ------------------- .../factions/zcore/persist/PlayerEntity.java | 5 +- .../zcore/persist/PlayerEntityCollection.java | 2 +- 5 files changed, 5 insertions(+), 96 deletions(-) delete mode 100644 src/main/java/com/massivecraft/factions/integration/EssentialsFeatures.java diff --git a/src/main/java/com/massivecraft/factions/P.java b/src/main/java/com/massivecraft/factions/P.java index 350d6795..8118ff1b 100644 --- a/src/main/java/com/massivecraft/factions/P.java +++ b/src/main/java/com/massivecraft/factions/P.java @@ -3,7 +3,6 @@ package com.massivecraft.factions; import com.massivecraft.factions.cmd.CmdAutoHelp; import com.massivecraft.factions.cmd.FCmdRoot; import com.massivecraft.factions.integration.Econ; -import com.massivecraft.factions.integration.EssentialsFeatures; import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.listeners.*; import com.massivecraft.factions.struct.ChatMode; @@ -98,7 +97,6 @@ public class P extends MPlugin { this.cmdAutoHelp = new CmdAutoHelp(); this.getBaseCommands().add(cmdBase); - EssentialsFeatures.setup(); Econ.setup(); if (Conf.worldGuardChecking || Conf.worldGuardBuildPriority) { @@ -143,7 +141,6 @@ public class P extends MPlugin { Board.save(); Conf.save(); } - EssentialsFeatures.unhookChat(); if (AutoLeaveTask != null) { this.getServer().getScheduler().cancelTask(AutoLeaveTask); AutoLeaveTask = null; diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdHome.java b/src/main/java/com/massivecraft/factions/cmd/CmdHome.java index 42d1db71..15d5f850 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdHome.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdHome.java @@ -1,7 +1,6 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.*; -import com.massivecraft.factions.integration.EssentialsFeatures; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Role; @@ -108,10 +107,6 @@ public class CmdHome extends FCommand { return; } } - - // if Essentials teleport handling is enabled and available, pass the teleport off to it (for delay and cooldown) - if (EssentialsFeatures.handleTeleport(me, myFaction.getHome())) return; - // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay if (!payForCommand(Conf.econCostHome, "to teleport to your faction home", "for teleporting to your faction home")) return; diff --git a/src/main/java/com/massivecraft/factions/integration/EssentialsFeatures.java b/src/main/java/com/massivecraft/factions/integration/EssentialsFeatures.java deleted file mode 100644 index de9a6ae8..00000000 --- a/src/main/java/com/massivecraft/factions/integration/EssentialsFeatures.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.massivecraft.factions.integration; - -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.Teleport; -import com.earth2me.essentials.Trade; -import com.earth2me.essentials.chat.EssentialsChat; -import com.massivecraft.factions.Conf; -import com.massivecraft.factions.P; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - - -/* - * This Essentials integration handler is for newer 3.x.x versions of Essentials which don't have "IEssentialsChatListener" - * If an older version is detected in the setup() method below, handling is passed off to EssentialsOldVersionFeatures - */ - -// silence deprecation warnings with this old interface -@SuppressWarnings("deprecation") -public class EssentialsFeatures { - private static EssentialsChat essChat; - private static IEssentials essentials; - - public static void setup() { - // integrate main essentials plugin - // TODO: this is the old Essentials method not supported in 3.0... probably needs to eventually be moved to EssentialsOldVersionFeatures and new method implemented - if (essentials == null) { - Plugin ess = Bukkit.getPluginManager().getPlugin("Essentials"); - if (ess != null && ess.isEnabled()) - essentials = (IEssentials) ess; - } - - // integrate chat - if (essChat != null) return; - - Plugin test = Bukkit.getServer().getPluginManager().getPlugin("EssentialsChat"); - if (test == null || !test.isEnabled()) return; - - essChat = (EssentialsChat) test; - - // try newer Essentials 3.x integration method - try { - Class.forName("com.earth2me.essentials.chat.EssentialsLocalChatEvent"); - integrateChat(essChat); - } catch (ClassNotFoundException ex) { - } - } - - public static void unhookChat() { - if (essChat == null) return; - } - - - // return false if feature is disabled or Essentials isn't available - public static boolean handleTeleport(Player player, Location loc) { - if (!Conf.homesTeleportCommandEssentialsIntegration || essentials == null) return false; - - Teleport teleport = (Teleport) essentials.getUser(player).getTeleport(); - Trade trade = new Trade(Conf.econCostHome, essentials); - try { - teleport.teleport(loc, trade); - } catch (Exception e) { - player.sendMessage(ChatColor.RED.toString() + e.getMessage()); - } - return true; - } - - - public static void integrateChat(EssentialsChat instance) { - essChat = instance; - try { - P.p.log("Found and will integrate chat with newer " + essChat.getDescription().getFullName()); - - // curly braces used to be accepted by the format string EssentialsChat but no longer are, so... deal with chatTagReplaceString which might need updating - if (Conf.chatTagReplaceString.contains("{")) { - Conf.chatTagReplaceString = Conf.chatTagReplaceString.replace("{", "[").replace("}", "]"); - P.p.log("NOTE: as of Essentials 2.8+, we've had to switch the default chat replacement tag from \"{FACTION}\" to \"[FACTION]\". This has automatically been updated for you."); - } - } catch (NoSuchMethodError ex) { - essChat = null; - } - } -} diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/PlayerEntity.java b/src/main/java/com/massivecraft/factions/zcore/persist/PlayerEntity.java index 25722f56..e5f944ec 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/PlayerEntity.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/PlayerEntity.java @@ -7,7 +7,10 @@ import java.util.List; public class PlayerEntity extends Entity { public Player getPlayer() { - return Bukkit.getPlayerExact(this.getId()); + for (Player player : Bukkit.getServer().getOnlinePlayers()) { + if (player.getUniqueId().toString().equals(this.getId())) return player; + } + return null; } public boolean isOnline() { diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/PlayerEntityCollection.java b/src/main/java/com/massivecraft/factions/zcore/persist/PlayerEntityCollection.java index f3af64e0..84d6ac80 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/PlayerEntityCollection.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/PlayerEntityCollection.java @@ -25,7 +25,7 @@ public abstract class PlayerEntityCollection extends EntityCol } public E get(Player player) { - return this.get(player.getName()); + return this.get(player.getUniqueId().toString()); } public Set getOnline() {