From 77a7b2d85cb18f0ab4fde3ff7daf0e81ecd46128 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Wed, 5 Oct 2011 05:13:54 -0500 Subject: [PATCH] New Spout feature, for Spoutcraft client users only: current territory info will now be permanently shown at top of screen, instead of being echoed out to chat as you move around New conf.json setting "spoutTerritoryDisplayPosition" to set the screen position at which the current territory is shown. 0 = disabled, 1 = top left, 2 = top center, 3 (default) = top right. Moved all integration code to separate package, ofr better code organization. Also moved EssentialsChat integration code out to separate file in there, allowing us to safely remove our copy IEssentialsChatListener.java file (which is otherwise needed to prevent a nasty NoClassDefFoundError). --- .../chat/IEssentialsChatListener.java | 12 --- src/com/massivecraft/factions/Conf.java | 1 + src/com/massivecraft/factions/FPlayer.java | 6 ++ src/com/massivecraft/factions/Factions.java | 38 ++++--- .../factions/commands/FBaseCommand.java | 2 +- .../factions/commands/FCommandBalance.java | 2 +- .../factions/commands/FCommandConfig.java | 2 +- .../factions/commands/FCommandDeposit.java | 2 +- .../factions/commands/FCommandDisband.java | 4 +- .../factions/commands/FCommandHelp.java | 2 +- .../factions/commands/FCommandPay.java | 2 +- .../factions/commands/FCommandPeaceful.java | 2 +- .../factions/commands/FCommandShow.java | 2 +- .../factions/commands/FCommandTag.java | 2 +- .../factions/commands/FCommandTitle.java | 2 +- .../factions/commands/FCommandUnclaim.java | 2 +- .../factions/commands/FCommandUnclaimall.java | 2 +- .../factions/commands/FCommandWithdraw.java | 2 +- .../factions/commands/FRelationCommand.java | 2 +- .../factions/{ => integration}/Econ.java | 4 +- .../integration/EssentialsFeatures.java | 41 ++++++++ .../{ => integration}/SpoutFeatures.java | 98 ++++++++++++++++--- .../{ => integration}/Worldguard.java | 3 +- .../listeners/FactionsPlayerListener.java | 28 +++--- .../listeners/FactionsServerListener.java | 4 +- 25 files changed, 189 insertions(+), 78 deletions(-) delete mode 100644 src/com/earth2me/essentials/chat/IEssentialsChatListener.java rename src/com/massivecraft/factions/{ => integration}/Econ.java (98%) create mode 100644 src/com/massivecraft/factions/integration/EssentialsFeatures.java rename src/com/massivecraft/factions/{ => integration}/SpoutFeatures.java (62%) rename src/com/massivecraft/factions/{ => integration}/Worldguard.java (94%) diff --git a/src/com/earth2me/essentials/chat/IEssentialsChatListener.java b/src/com/earth2me/essentials/chat/IEssentialsChatListener.java deleted file mode 100644 index 5c9c5c21..00000000 --- a/src/com/earth2me/essentials/chat/IEssentialsChatListener.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.earth2me.essentials.chat; - -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerChatEvent; - - -public interface IEssentialsChatListener -{ - boolean shouldHandleThisChat(PlayerChatEvent event); - - String modifyMessage(PlayerChatEvent event, Player target, String message); -} diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index e84e8bed..fbb6ddc4 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -185,6 +185,7 @@ public class Conf { public static boolean spoutFactionTitlesOverNames = true; public static boolean spoutFactionAdminCapes = true; public static boolean spoutFactionModeratorCapes = true; + public static int spoutTerritoryDisplayPosition = 3; public static String capeAlly = "https://github.com/MassiveCraft/Factions/raw/master/capes/ally.png"; public static String capeEnemy = "https://github.com/MassiveCraft/Factions/raw/master/capes/enemy.png"; public static String capeMember = "https://github.com/MassiveCraft/Factions/raw/master/capes/member.png"; diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 4b1cddc2..813aed4d 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -11,6 +11,9 @@ import org.bukkit.Location; import org.bukkit.entity.Player; import com.google.gson.reflect.TypeToken; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.factions.integration.SpoutFeatures; +import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.struct.ChatMode; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Role; @@ -471,6 +474,9 @@ public class FPlayer { } public void sendFactionHereMessage() { + if (SpoutFeatures.updateTerritoryDisplay(this)) { + return; + } Faction factionHere = Board.getFactionAt(new FLocation(this)); String msg = Conf.colorSystem+" ~ "+factionHere.getTag(this); if (factionHere.getDescription().length() > 0) { diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 5bebbcc8..dd478bd5 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -25,6 +25,9 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import com.massivecraft.factions.commands.*; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.factions.integration.SpoutFeatures; +import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.listeners.FactionsBlockListener; import com.massivecraft.factions.listeners.FactionsChatEarlyListener; import com.massivecraft.factions.listeners.FactionsEntityListener; @@ -37,10 +40,10 @@ import com.massivecraft.factions.util.MyLocationTypeAdapter; import com.nijiko.permissions.PermissionHandler; import com.nijikokun.bukkit.Permissions.Permissions; import com.earth2me.essentials.chat.EssentialsChat; -import com.earth2me.essentials.chat.IEssentialsChatListener; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; +import com.massivecraft.factions.integration.EssentialsFeatures; /** * The data is saved to disk every 30min and on plugin disable. @@ -155,7 +158,7 @@ public class Factions extends JavaPlugin { setupPermissions(); integrateEssentialsChat(); - SpoutFeatures.setup(this); + setupSpout(this); Econ.setup(this); Econ.monitorPlugins(); @@ -230,6 +233,14 @@ public class Factions extends JavaPlugin { } } + private void setupSpout(Factions factions) { + Plugin test = factions.getServer().getPluginManager().getPlugin("Spout"); + + if (test != null && test.isEnabled()) { + SpoutFeatures.setAvailable(true, test.getDescription().getFullName()); + } + } + private void integrateEssentialsChat() { if (essChat != null) { return; @@ -237,29 +248,14 @@ public class Factions extends JavaPlugin { Plugin test = this.getServer().getPluginManager().getPlugin("EssentialsChat"); - if (test != null) { - try { - essChat = (EssentialsChat)test; - essChat.addEssentialsChatListener("Factions", new IEssentialsChatListener() { - public boolean shouldHandleThisChat(PlayerChatEvent event) - { - return shouldLetFactionsHandleThisChat(event); - } - public String modifyMessage(PlayerChatEvent event, Player target, String message) - { - return message.replace("{FACTION}", getPlayerFactionTagRelation(event.getPlayer(), target)).replace("{FACTION_TITLE}", getPlayerTitle(event.getPlayer())); - } - }); - Factions.log("Found and will integrate chat with "+test.getDescription().getFullName()); - } - catch (NoSuchMethodError ex) { - essChat = null; - } + if (test != null && test.isEnabled()) { + essChat = (EssentialsChat)test; + EssentialsFeatures.integrateChat(essChat); } } private void unhookEssentialsChat() { if (essChat != null) { - essChat.removeEssentialsChatListener("Factions"); + EssentialsFeatures.unhookChat(); } } diff --git a/src/com/massivecraft/factions/commands/FBaseCommand.java b/src/com/massivecraft/factions/commands/FBaseCommand.java index c9af83fe..9bf0aabc 100644 --- a/src/com/massivecraft/factions/commands/FBaseCommand.java +++ b/src/com/massivecraft/factions/commands/FBaseCommand.java @@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.Econ; +import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; diff --git a/src/com/massivecraft/factions/commands/FCommandBalance.java b/src/com/massivecraft/factions/commands/FCommandBalance.java index b17b3504..d511ba65 100644 --- a/src/com/massivecraft/factions/commands/FCommandBalance.java +++ b/src/com/massivecraft/factions/commands/FCommandBalance.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.commands; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.Econ; +import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; diff --git a/src/com/massivecraft/factions/commands/FCommandConfig.java b/src/com/massivecraft/factions/commands/FCommandConfig.java index 61217450..5aa5fd45 100644 --- a/src/com/massivecraft/factions/commands/FCommandConfig.java +++ b/src/com/massivecraft/factions/commands/FCommandConfig.java @@ -13,7 +13,7 @@ import org.bukkit.entity.Player; import com.massivecraft.factions.Conf; import com.massivecraft.factions.Factions; -import com.massivecraft.factions.SpoutFeatures; +import com.massivecraft.factions.integration.SpoutFeatures; public class FCommandConfig extends FBaseCommand { diff --git a/src/com/massivecraft/factions/commands/FCommandDeposit.java b/src/com/massivecraft/factions/commands/FCommandDeposit.java index b3866c23..900124af 100644 --- a/src/com/massivecraft/factions/commands/FCommandDeposit.java +++ b/src/com/massivecraft/factions/commands/FCommandDeposit.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.commands; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.Econ; +import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; import com.massivecraft.factions.FPlayer; diff --git a/src/com/massivecraft/factions/commands/FCommandDisband.java b/src/com/massivecraft/factions/commands/FCommandDisband.java index 93b24f11..688decec 100644 --- a/src/com/massivecraft/factions/commands/FCommandDisband.java +++ b/src/com/massivecraft/factions/commands/FCommandDisband.java @@ -1,11 +1,11 @@ package com.massivecraft.factions.commands; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.Econ; +import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.SpoutFeatures; +import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.struct.Role; diff --git a/src/com/massivecraft/factions/commands/FCommandHelp.java b/src/com/massivecraft/factions/commands/FCommandHelp.java index dc8f6650..291918b1 100644 --- a/src/com/massivecraft/factions/commands/FCommandHelp.java +++ b/src/com/massivecraft/factions/commands/FCommandHelp.java @@ -5,7 +5,7 @@ import java.util.ArrayList; import org.bukkit.command.CommandSender; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.Econ; +import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.util.TextUtil; diff --git a/src/com/massivecraft/factions/commands/FCommandPay.java b/src/com/massivecraft/factions/commands/FCommandPay.java index e49e4509..24e4e9b0 100644 --- a/src/com/massivecraft/factions/commands/FCommandPay.java +++ b/src/com/massivecraft/factions/commands/FCommandPay.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.commands; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.Econ; +import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; import com.massivecraft.factions.FPlayer; diff --git a/src/com/massivecraft/factions/commands/FCommandPeaceful.java b/src/com/massivecraft/factions/commands/FCommandPeaceful.java index 4e5eb66d..aeeac60f 100644 --- a/src/com/massivecraft/factions/commands/FCommandPeaceful.java +++ b/src/com/massivecraft/factions/commands/FCommandPeaceful.java @@ -6,7 +6,7 @@ import com.massivecraft.factions.Conf; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.SpoutFeatures; +import com.massivecraft.factions.integration.SpoutFeatures; public class FCommandPeaceful extends FBaseCommand { diff --git a/src/com/massivecraft/factions/commands/FCommandShow.java b/src/com/massivecraft/factions/commands/FCommandShow.java index b1e98527..b6d99e1c 100644 --- a/src/com/massivecraft/factions/commands/FCommandShow.java +++ b/src/com/massivecraft/factions/commands/FCommandShow.java @@ -6,7 +6,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.Econ; +import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.struct.Role; diff --git a/src/com/massivecraft/factions/commands/FCommandTag.java b/src/com/massivecraft/factions/commands/FCommandTag.java index dd372b22..e66a1cfa 100644 --- a/src/com/massivecraft/factions/commands/FCommandTag.java +++ b/src/com/massivecraft/factions/commands/FCommandTag.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import com.massivecraft.factions.Conf; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.SpoutFeatures; +import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.util.TextUtil; diff --git a/src/com/massivecraft/factions/commands/FCommandTitle.java b/src/com/massivecraft/factions/commands/FCommandTitle.java index 7e67b38b..cdf74f02 100644 --- a/src/com/massivecraft/factions/commands/FCommandTitle.java +++ b/src/com/massivecraft/factions/commands/FCommandTitle.java @@ -3,7 +3,7 @@ package com.massivecraft.factions.commands; import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.SpoutFeatures; +import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.util.TextUtil; public class FCommandTitle extends FBaseCommand { diff --git a/src/com/massivecraft/factions/commands/FCommandUnclaim.java b/src/com/massivecraft/factions/commands/FCommandUnclaim.java index 1ede9c40..d7991a96 100644 --- a/src/com/massivecraft/factions/commands/FCommandUnclaim.java +++ b/src/com/massivecraft/factions/commands/FCommandUnclaim.java @@ -2,7 +2,7 @@ package com.massivecraft.factions.commands; import com.massivecraft.factions.Board; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.Econ; +import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; diff --git a/src/com/massivecraft/factions/commands/FCommandUnclaimall.java b/src/com/massivecraft/factions/commands/FCommandUnclaimall.java index 42491852..3420c707 100644 --- a/src/com/massivecraft/factions/commands/FCommandUnclaimall.java +++ b/src/com/massivecraft/factions/commands/FCommandUnclaimall.java @@ -2,7 +2,7 @@ package com.massivecraft.factions.commands; import com.massivecraft.factions.Board; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.Econ; +import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.Faction; import com.massivecraft.factions.struct.Role; diff --git a/src/com/massivecraft/factions/commands/FCommandWithdraw.java b/src/com/massivecraft/factions/commands/FCommandWithdraw.java index 9ac4f558..5272e057 100644 --- a/src/com/massivecraft/factions/commands/FCommandWithdraw.java +++ b/src/com/massivecraft/factions/commands/FCommandWithdraw.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.commands; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.Econ; +import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; import com.massivecraft.factions.FPlayer; diff --git a/src/com/massivecraft/factions/commands/FRelationCommand.java b/src/com/massivecraft/factions/commands/FRelationCommand.java index 0eeb6231..7993904d 100644 --- a/src/com/massivecraft/factions/commands/FRelationCommand.java +++ b/src/com/massivecraft/factions/commands/FRelationCommand.java @@ -5,7 +5,7 @@ import org.bukkit.ChatColor; import com.massivecraft.factions.Conf; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; -import com.massivecraft.factions.SpoutFeatures; +import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Role; diff --git a/src/com/massivecraft/factions/Econ.java b/src/com/massivecraft/factions/integration/Econ.java similarity index 98% rename from src/com/massivecraft/factions/Econ.java rename to src/com/massivecraft/factions/integration/Econ.java index 9858da5a..31f0d369 100644 --- a/src/com/massivecraft/factions/Econ.java +++ b/src/com/massivecraft/factions/integration/Econ.java @@ -1,4 +1,4 @@ -package com.massivecraft.factions; +package com.massivecraft.factions.integration; import org.bukkit.event.Event; import org.bukkit.plugin.Plugin; @@ -11,6 +11,8 @@ import com.nijikokun.register.payment.Methods; import com.nijikokun.register.payment.Method.MethodAccount; import com.iConomy.*; import com.iConomy.system.*; +import com.massivecraft.factions.Conf; +import com.massivecraft.factions.Factions; public class Econ { diff --git a/src/com/massivecraft/factions/integration/EssentialsFeatures.java b/src/com/massivecraft/factions/integration/EssentialsFeatures.java new file mode 100644 index 00000000..cbb212cc --- /dev/null +++ b/src/com/massivecraft/factions/integration/EssentialsFeatures.java @@ -0,0 +1,41 @@ +package com.massivecraft.factions.integration; + +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerChatEvent; +import org.bukkit.plugin.Plugin; + +import com.massivecraft.factions.Factions; + +import com.earth2me.essentials.chat.EssentialsChat; +import com.earth2me.essentials.chat.IEssentialsChatListener; + + +public class EssentialsFeatures { + private static EssentialsChat essChat; + + public static void integrateChat(EssentialsChat instance) { + essChat = instance; + try { + essChat.addEssentialsChatListener("Factions", new IEssentialsChatListener() { + public boolean shouldHandleThisChat(PlayerChatEvent event) + { + return Factions.instance.shouldLetFactionsHandleThisChat(event); + } + public String modifyMessage(PlayerChatEvent event, Player target, String message) + { + return message.replace("{FACTION}", Factions.instance.getPlayerFactionTagRelation(event.getPlayer(), target)).replace("{FACTION_TITLE}", Factions.instance.getPlayerTitle(event.getPlayer())); + } + }); + Factions.log("Found and will integrate chat with "+essChat.getDescription().getFullName()); + } + catch (NoSuchMethodError ex) { + essChat = null; + } + } + + public static void unhookChat() { + if (essChat != null) { + essChat.removeEssentialsChatListener("Factions"); + } + } +} diff --git a/src/com/massivecraft/factions/SpoutFeatures.java b/src/com/massivecraft/factions/integration/SpoutFeatures.java similarity index 62% rename from src/com/massivecraft/factions/SpoutFeatures.java rename to src/com/massivecraft/factions/integration/SpoutFeatures.java index 7a9335e0..d1ff0aa6 100644 --- a/src/com/massivecraft/factions/SpoutFeatures.java +++ b/src/com/massivecraft/factions/integration/SpoutFeatures.java @@ -1,32 +1,33 @@ -package com.massivecraft.factions; +package com.massivecraft.factions.integration; +import com.massivecraft.factions.Board; +import com.massivecraft.factions.Conf; +import com.massivecraft.factions.FLocation; +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.Factions; +import java.util.HashMap; +import java.util.Map; import java.util.Set; -import org.bukkit.plugin.Plugin; +import org.bukkit.ChatColor; import org.bukkit.entity.Player; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Role; +import org.getspout.spoutapi.gui.Color; +import org.getspout.spoutapi.gui.GenericLabel; import org.getspout.spoutapi.player.AppearanceManager; import org.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.SpoutManager; +import org.getspout.spoutapi.gui.WidgetAnchor; public class SpoutFeatures { private transient static AppearanceManager spoutApp; private transient static boolean spoutMe = false; - - public static void setup(Factions factions) { - Plugin test = factions.getServer().getPluginManager().getPlugin("Spout"); - - if (test != null && test.isEnabled()) { - setAvailable(true, test.getDescription().getFullName()); - } - else { - setAvailable(false, ""); - } - } + private transient static Map territoryLabels = new HashMap(); // set integration availability public static void setAvailable(boolean enable, String pluginName) { @@ -47,10 +48,57 @@ public class SpoutFeatures { || Conf.spoutFactionTitlesOverNames || Conf.spoutFactionAdminCapes || Conf.spoutFactionModeratorCapes + || Conf.spoutTerritoryDisplayPosition > 0 ); } + // update displayed current territory for specified player; returns false if unsuccessful + public static boolean updateTerritoryDisplay(FPlayer player) { + if (!spoutMe || Conf.spoutTerritoryDisplayPosition == 0) { + return false; + } + + SpoutPlayer sPlayer = SpoutManager.getPlayer(player.getPlayer()); + if (!sPlayer.isSpoutCraftEnabled()) { + return false; + } + + GenericLabel label; + if (territoryLabels.containsKey(player.getName())) { + label = territoryLabels.get(player.getName()); + } + else { + label = new GenericLabel(); + sPlayer.getMainScreen().attachWidget(Factions.instance, label); + switch (Conf.spoutTerritoryDisplayPosition) { + case 1: label.setAlign(WidgetAnchor.TOP_LEFT).setAnchor(WidgetAnchor.TOP_LEFT); break; + case 2: label.setAlign(WidgetAnchor.TOP_CENTER).setAnchor(WidgetAnchor.TOP_CENTER); break; + default: label.setAlign(WidgetAnchor.TOP_RIGHT).setAnchor(WidgetAnchor.TOP_RIGHT); + } + territoryLabels.put(player.getName(), label); + } + + Faction factionHere = Board.getFactionAt(new FLocation(player)); + String msg = factionHere.getTag(); + if (factionHere.getDescription().length() > 0) { + msg += " - "+factionHere.getDescription(); + } + label.setTextColor(getSpoutColor(player.getRelationColor(factionHere), 0)); + label.setText(msg); + label.setDirty(true); + + return true; + } + + public static void playerDisconnect(FPlayer player) { + if (!enabled()) { + return; + } + territoryLabels.remove(player.getName()); + } + + // update all appearances between every player public static void updateAppearances() { if (!enabled()) { @@ -186,4 +234,28 @@ public class SpoutFeatures { } } + // method to convert a Bukkit ChatColor to a Spout Color + private static Color getSpoutColor(ChatColor inColor, int alpha) { + if (inColor == null) { + return new Color(191, 191, 191, alpha); + } + switch (inColor.getCode()) { + case 0x1: return new Color(0, 0, 191, alpha); + case 0x2: return new Color(0, 191, 0, alpha); + case 0x3: return new Color(0, 191, 191, alpha); + case 0x4: return new Color(191, 0, 0, alpha); + case 0x5: return new Color(191, 0, 191, alpha); + case 0x6: return new Color(191, 191, 0, alpha); + case 0x7: return new Color(191, 191, 191, alpha); + case 0x8: return new Color(64, 64, 64, alpha); + case 0x9: return new Color(64, 64, 255, alpha); + case 0xA: return new Color(64, 255, 64, alpha); + case 0xB: return new Color(64, 255, 255, alpha); + case 0xC: return new Color(255, 64, 64, alpha); + case 0xD: return new Color(255, 64, 255, alpha); + case 0xE: return new Color(255, 255, 64, alpha); + case 0xF: return new Color(255, 255, 255, alpha); + default: return new Color(0, 0, 0, alpha); + } + } } diff --git a/src/com/massivecraft/factions/Worldguard.java b/src/com/massivecraft/factions/integration/Worldguard.java similarity index 94% rename from src/com/massivecraft/factions/Worldguard.java rename to src/com/massivecraft/factions/integration/Worldguard.java index adb79b91..0bb640bf 100644 --- a/src/com/massivecraft/factions/Worldguard.java +++ b/src/com/massivecraft/factions/integration/Worldguard.java @@ -1,5 +1,6 @@ -package com.massivecraft.factions; +package com.massivecraft.factions.integration; +import com.massivecraft.factions.Factions; import java.util.ArrayList; import java.util.List; import java.util.Map; diff --git a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 6fd49e8f..57d18b20 100644 --- a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -25,12 +25,12 @@ import org.bukkit.event.player.PlayerRespawnEvent; import com.massivecraft.factions.Board; import com.massivecraft.factions.Conf; -import com.massivecraft.factions.Econ; +import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; -import com.massivecraft.factions.SpoutFeatures; +import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.util.TextUtil; @@ -126,10 +126,8 @@ public class FactionsPlayerListener extends PlayerListener{ @Override public void onPlayerJoin(PlayerJoinEvent event) { - final Player player = event.getPlayer(); - // Make sure that all online players do have a fplayer. - FPlayer me = FPlayer.get(player); + final FPlayer me = FPlayer.get(event.getPlayer()); // Update the lastLoginTime for this fplayer me.setLastLoginTime(System.currentTimeMillis()); @@ -138,12 +136,15 @@ public class FactionsPlayerListener extends PlayerListener{ FPlayer.autoLeaveOnInactivityRoutine(); FPlayer.autoLeaveOnInactivityRoutine(); + SpoutFeatures.updateTerritoryDisplay(me); + // Appearance updates which are run when a player joins don't apply properly for other clients, so they need to be delayed slightly Factions.instance.getServer().getScheduler().scheduleSyncDelayedTask(Factions.instance, new Runnable() { public void run() { - SpoutFeatures.updateAppearances(player); + SpoutFeatures.updateAppearances(me.getPlayer()); + SpoutFeatures.updateTerritoryDisplay(me); } - }); + }, 20); } @Override @@ -155,6 +156,7 @@ public class FactionsPlayerListener extends PlayerListener{ if (myFaction != null) { myFaction.memberLoggedOff(); } + SpoutFeatures.playerDisconnect(me); } @Override @@ -517,13 +519,15 @@ public class FactionsPlayerListener extends PlayerListener{ return; } + FPlayer badGuy = FPlayer.get(event.getPlayer()); + if (badGuy == null) { + return; + } + + SpoutFeatures.playerDisconnect(badGuy); + // if player was banned (not just kicked), get rid of their stored info if (event.getReason().equals("Banned by admin.")) { - FPlayer badGuy = FPlayer.get(event.getPlayer()); - if (badGuy == null) { - return; - } - badGuy.leave(false); badGuy.markForDeletion(true); } diff --git a/src/com/massivecraft/factions/listeners/FactionsServerListener.java b/src/com/massivecraft/factions/listeners/FactionsServerListener.java index 5563a3ff..d5bbdded 100644 --- a/src/com/massivecraft/factions/listeners/FactionsServerListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsServerListener.java @@ -5,8 +5,8 @@ import org.bukkit.event.server.ServerListener; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginEnableEvent; -import com.massivecraft.factions.Econ; -import com.massivecraft.factions.SpoutFeatures; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.factions.integration.SpoutFeatures; public class FactionsServerListener extends ServerListener {