From 3e8faad156feef1451e58302005d9a2026513194 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Sun, 23 Oct 2011 09:03:28 -0500 Subject: [PATCH] Updated Spout features to improve consistency (of code, and of displayed information) --- src/com/massivecraft/factions/FPlayer.java | 1 + .../massivecraft/factions/cmd/CmdOwner.java | 5 + .../massivecraft/factions/cmd/CmdUnclaim.java | 5 + .../factions/cmd/CmdUnclaimall.java | 2 + .../factions/cmd/FRelationCommand.java | 2 +- .../factions/integration/SpoutFeatures.java | 147 +++++++++++------- .../integration/SpoutMainListener.java | 12 +- .../listeners/FactionsPlayerListener.java | 2 + 8 files changed, 113 insertions(+), 63 deletions(-) diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 52b28f4a..463f8d16 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -771,6 +771,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator } Board.setFactionAt(forFaction, flocation); + SpoutFeatures.updateTerritoryDisplayLoc(flocation); return true; } diff --git a/src/com/massivecraft/factions/cmd/CmdOwner.java b/src/com/massivecraft/factions/cmd/CmdOwner.java index 8d81ab42..4b8636d5 100644 --- a/src/com/massivecraft/factions/cmd/CmdOwner.java +++ b/src/com/massivecraft/factions/cmd/CmdOwner.java @@ -5,6 +5,7 @@ import com.massivecraft.factions.Conf; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.Faction; import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Role; @@ -90,6 +91,7 @@ public class CmdOwner extends FCommand if (args.isEmpty() && myFaction.doesLocationHaveOwnersSet(flocation)) { myFaction.clearClaimOwnership(flocation); + SpoutFeatures.updateOwnerListLoc(flocation); fme.msg("You have cleared ownership for this claimed area."); return; } @@ -97,6 +99,7 @@ public class CmdOwner extends FCommand if (myFaction.isPlayerInOwnerList(playerName, flocation)) { myFaction.removePlayerAsOwner(playerName, flocation); + SpoutFeatures.updateOwnerListLoc(flocation); fme.msg("You have removed ownership of this claimed land from %s.", playerName); return; } @@ -105,6 +108,8 @@ public class CmdOwner extends FCommand if ( ! payForCommand(Conf.econCostOwner, "to set ownership of claimed land", "for setting ownership of claimed land")) return; myFaction.setPlayerAsOwner(playerName, flocation); + SpoutFeatures.updateOwnerListLoc(flocation); + fme.msg("You have added %s to the owner list for this claimed land.", playerName); } } diff --git a/src/com/massivecraft/factions/cmd/CmdUnclaim.java b/src/com/massivecraft/factions/cmd/CmdUnclaim.java index 22a2478d..f203fd04 100644 --- a/src/com/massivecraft/factions/cmd/CmdUnclaim.java +++ b/src/com/massivecraft/factions/cmd/CmdUnclaim.java @@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Board; import com.massivecraft.factions.Conf; import com.massivecraft.factions.integration.Econ; +import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.Faction; import com.massivecraft.factions.struct.Permission; @@ -38,6 +39,7 @@ public class CmdUnclaim extends FCommand if (Permission.MANAGE_SAFE_ZONE.has(sender)) { Board.removeAt(flocation); + SpoutFeatures.updateTerritoryDisplayLoc(flocation); msg("Safe zone was unclaimed."); } else @@ -51,6 +53,7 @@ public class CmdUnclaim extends FCommand if (Permission.MANAGE_WAR_ZONE.has(sender)) { Board.removeAt(flocation); + SpoutFeatures.updateTerritoryDisplayLoc(flocation); msg("War zone was unclaimed."); } else @@ -63,6 +66,7 @@ public class CmdUnclaim extends FCommand if (fme.isAdminBypassing()) { Board.removeAt(flocation); + SpoutFeatures.updateTerritoryDisplayLoc(flocation); otherFaction.msg("%s unclaimed some of your land.", fme.describeTo(otherFaction, true)); msg("You unclaimed this land."); @@ -148,6 +152,7 @@ public class CmdUnclaim extends FCommand } Board.removeAt(flocation); + SpoutFeatures.updateTerritoryDisplayLoc(flocation); myFaction.msg("%s unclaimed some land.", fme.describeTo(myFaction, true)); } diff --git a/src/com/massivecraft/factions/cmd/CmdUnclaimall.java b/src/com/massivecraft/factions/cmd/CmdUnclaimall.java index ddce85dc..de711578 100644 --- a/src/com/massivecraft/factions/cmd/CmdUnclaimall.java +++ b/src/com/massivecraft/factions/cmd/CmdUnclaimall.java @@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Board; import com.massivecraft.factions.Conf; import com.massivecraft.factions.integration.Econ; +import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.struct.Permission; public class CmdUnclaimall extends FCommand @@ -39,6 +40,7 @@ public class CmdUnclaimall extends FCommand Board.unclaimAll(myFaction.getId()); myFaction.msg("%s unclaimed ALL of your faction's land.", fme.describeTo(myFaction, true)); + SpoutFeatures.updateTerritoryDisplayLoc(null); } } diff --git a/src/com/massivecraft/factions/cmd/FRelationCommand.java b/src/com/massivecraft/factions/cmd/FRelationCommand.java index e2636faa..b18b6b14 100644 --- a/src/com/massivecraft/factions/cmd/FRelationCommand.java +++ b/src/com/massivecraft/factions/cmd/FRelationCommand.java @@ -76,6 +76,6 @@ public abstract class FRelationCommand extends FCommand } SpoutFeatures.updateAppearances(myFaction, them); - + SpoutFeatures.updateTerritoryDisplayLoc(null); } } diff --git a/src/com/massivecraft/factions/integration/SpoutFeatures.java b/src/com/massivecraft/factions/integration/SpoutFeatures.java index 8272bd70..448e2b39 100644 --- a/src/com/massivecraft/factions/integration/SpoutFeatures.java +++ b/src/com/massivecraft/factions/integration/SpoutFeatures.java @@ -6,6 +6,7 @@ import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.FLocation; import com.massivecraft.factions.P; import org.bukkit.ChatColor; @@ -63,13 +64,60 @@ public class SpoutFeatures } + // update displayed current territory for all players inside a specified chunk; if specified chunk is null, then simply update everyone online + public static void updateTerritoryDisplayLoc(FLocation fLoc) + { + if (!enabled()) + return; + + Set players = FPlayers.i.getOnline(); + + for (FPlayer player : players) + { + if (fLoc == null) + mainListener.updateTerritoryDisplay(player, false); + else if (player.getLastStoodAt().equals(fLoc)) + mainListener.updateTerritoryDisplay(player, true); + } + } + // update displayed current territory for specified player; returns false if unsuccessful public static boolean updateTerritoryDisplay(FPlayer player) { if (!enabled()) return false; - return mainListener.updateTerritoryDisplay(player); + return mainListener.updateTerritoryDisplay(player, true); + } + + // update owner list for all players inside a specified chunk; if specified chunk is null, then simply update everyone online + public static void updateOwnerListLoc(FLocation fLoc) + { + if (!enabled()) + return; + + Set players = FPlayers.i.getOnline(); + + for (FPlayer player : players) + { + if (fLoc == null || player.getLastStoodAt().equals(fLoc)) + mainListener.updateOwnerList(player); + } +/* // immediate update after a change doesn't seem to work; oh well, delay it slightly + P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, new Runnable() + { + @Override + public void run() + { + Set players = FPlayers.i.getOnline(); + + for (FPlayer player : players) + { + if (fLoc == null || player.getLastStoodAt() == fLoc) + mainListener.updateOwnerList(player); + } + } + }, 5);*/ } // update owner list for specified player @@ -94,19 +142,15 @@ public class SpoutFeatures public static void updateAppearances() { if (!enabled()) - { return; - } Set players = FPlayers.i.getOnline(); - Faction factionA; for (FPlayer playerA : players) { - factionA = playerA.getFaction(); for (FPlayer playerB : players) { - updateSingle(playerB.getPlayer(), playerA.getPlayer(), factionA.getRelationTo(playerB), factionA, playerA.getTitle(), playerA.getRole()); + updateSingle(playerB, playerA); } } } @@ -115,33 +159,39 @@ public class SpoutFeatures public static void updateAppearances(Player player) { if (!enabled() || player == null) - { return; - } Set players = FPlayers.i.getOnline(); FPlayer playerA = FPlayers.i.get(player); - Faction factionA = playerA.getFaction(); for (FPlayer playerB : players) { - Player player2 = playerB.getPlayer(); - Relation rel = factionA.getRelationTo(playerB); - updateSingle(player2, player, rel, factionA, playerA.getTitle(), playerA.getRole()); - updateSingle(player, player2, rel, playerB.getFaction(), playerB.getTitle(), playerB.getRole()); + updateSingle(playerB, playerA); + updateSingle(playerA, playerB); } } + // as above method, but with a delay added; useful for after-login update which doesn't always propagate if done immediately + public static void updateAppearancesShortly(final Player player) + { + P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, new Runnable() + { + @Override + public void run() + { + updateAppearances(player); + } + }, 100); + } + // update all appearances related to a single faction public static void updateAppearances(Faction faction) { if (!enabled() || faction == null) - { return; - } Set players = FPlayers.i.getOnline(); - Faction factionA, factionB; + Faction factionA; for (FPlayer playerA : players) { @@ -149,12 +199,10 @@ public class SpoutFeatures for (FPlayer playerB : players) { - factionB = playerB.getFaction(); - if (factionA != faction && factionB != faction) - { + if (factionA != faction && playerB.getFaction() != faction) continue; - } - updateSingle(playerB.getPlayer(), playerA.getPlayer(), factionA.getRelationTo(factionB), factionA, playerA.getTitle(), playerA.getRole()); + + updateSingle(playerB, playerA); } } } @@ -163,31 +211,33 @@ public class SpoutFeatures public static void updateAppearances(Faction factionA, Faction factionB) { if (!enabled() || factionA == null || factionB == null) - { return; - } for (FPlayer playerA : factionA.getFPlayersWhereOnline(true)) { for (FPlayer playerB : factionB.getFPlayersWhereOnline(true)) { - Player player1 = playerA.getPlayer(); - Player player2 = playerB.getPlayer(); - Relation rel = factionA.getRelationTo(factionB); - updateSingle(player2, player1, rel, factionA, playerA.getTitle(), playerA.getRole()); - updateSingle(player1, player2, rel, factionB, playerB.getTitle(), playerB.getRole()); + updateSingle(playerB, playerA); + updateSingle(playerA, playerB); } } } // update a single appearance; internal use only by above public methods - private static void updateSingle(Player viewer, Player viewed, Relation relation, Faction viewedFaction, String viewedTitle, Role viewedRole) + private static void updateSingle(FPlayer viewer, FPlayer viewed) { if (viewer == null || viewed == null) return; - SpoutPlayer sPlayer = SpoutManager.getPlayer(viewer); + Faction viewedFaction = viewed.getFaction(); + if (viewedFaction == null) + return; + + SpoutPlayer sPlayer = SpoutManager.getPlayer(viewer.getPlayer()); + Player pViewed = viewed.getPlayer(); + String viewedTitle = viewed.getTitle(); + Role viewedRole = viewed.getRole(); if ((Conf.spoutFactionTagsOverNames || Conf.spoutFactionTitlesOverNames) && viewer != viewed) { @@ -195,19 +245,17 @@ public class SpoutFeatures { String addTag = ""; if (Conf.spoutFactionTagsOverNames) - { - addTag += viewedFaction.getTag(relation.getColor().toString() + "[") + "]"; - } + addTag += viewedFaction.getTag(viewed.getColorTo(viewer).toString() + "[") + "]"; + String rolePrefix = viewedRole.getPrefix(); if (Conf.spoutFactionTitlesOverNames && (!viewedTitle.isEmpty() || !rolePrefix.isEmpty())) - { addTag += (addTag.isEmpty() ? "" : " ") + viewedRole.getPrefix() + viewedTitle; - } - spoutApp.setPlayerTitle(sPlayer, viewed, addTag + "\n" + viewed.getDisplayName()); + + spoutApp.setPlayerTitle(sPlayer, pViewed, addTag + "\n" + pViewed.getDisplayName()); } else { - spoutApp.setPlayerTitle(sPlayer, viewed, viewed.getDisplayName()); + spoutApp.setPlayerTitle(sPlayer, pViewed, pViewed.getDisplayName()); } } @@ -226,54 +274,41 @@ public class SpoutFeatures ) ) { + Relation relation = viewer.getRelationTo(viewed); String cape = ""; if (!viewedFaction.isNormal()) { // yeah, no cape if no faction } else if (viewedFaction.isPeaceful()) - { cape = Conf.capePeaceful; - } else if (relation.isNeutral()) - { cape = Conf.capeNeutral; - } else if (relation.isMember()) - { cape = Conf.capeMember; - } else if (relation.isEnemy()) - { cape = Conf.capeEnemy; - } else if (relation.isAlly()) - { cape = Conf.capeAlly; - } if (cape.isEmpty()) - { - spoutApp.resetPlayerCloak(sPlayer, viewed); - } + spoutApp.resetPlayerCloak(sPlayer, pViewed); else - { - spoutApp.setPlayerCloak(sPlayer, viewed, cape); - } + spoutApp.setPlayerCloak(sPlayer, pViewed, cape); } else if (Conf.spoutFactionAdminCapes || Conf.spoutFactionModeratorCapes) { - spoutApp.resetPlayerCloak(sPlayer, viewed); + spoutApp.resetPlayerCloak(sPlayer, pViewed); } } + // method to convert a Bukkit ChatColor to a Spout Color protected static Color getSpoutColor(ChatColor inColor, int alpha) { if (inColor == null) - { return SpoutFixedColor(191, 191, 191, alpha); - } + switch (inColor.getCode()) { case 0x1: return SpoutFixedColor(0, 0, 191, alpha); diff --git a/src/com/massivecraft/factions/integration/SpoutMainListener.java b/src/com/massivecraft/factions/integration/SpoutMainListener.java index a796a335..48f4a698 100644 --- a/src/com/massivecraft/factions/integration/SpoutMainListener.java +++ b/src/com/massivecraft/factions/integration/SpoutMainListener.java @@ -29,7 +29,7 @@ public class SpoutMainListener extends SpoutListener final FPlayer me = FPlayers.i.get(event.getPlayer()); SpoutFeatures.updateAppearances(me.getPlayer()); - updateTerritoryDisplay(me); + updateTerritoryDisplay(me, true); } //-----------------------------------------------------------------------------------------// @@ -43,7 +43,7 @@ public class SpoutMainListener extends SpoutListener // private final static int SCREEN_HEIGHT = 240; - public boolean updateTerritoryDisplay(FPlayer player) + public boolean updateTerritoryDisplay(FPlayer player, boolean notify) { Player p = player.getPlayer(); if (p == null) @@ -53,7 +53,7 @@ public class SpoutMainListener extends SpoutListener if (!sPlayer.isSpoutCraftEnabled() || (Conf.spoutTerritoryDisplaySize <= 0 && ! Conf.spoutTerritoryNoticeShow)) return false; - doLabels(player, sPlayer); + doLabels(player, sPlayer, notify); return true; } @@ -80,11 +80,11 @@ public class SpoutMainListener extends SpoutListener } - private void doLabels(FPlayer player, SpoutPlayer sPlayer) + private void doLabels(FPlayer player, SpoutPlayer sPlayer, boolean notify) { FLocation here = new FLocation(player); Faction factionHere = Board.getFactionAt(here); - String tag = factionHere.getTag(player); + String tag = factionHere.getColorTo(player).toString() + factionHere.getTag(); // ---------------------- // Main territory display @@ -122,7 +122,7 @@ public class SpoutMainListener extends SpoutListener // ----------------------- // Fading territory notice // ----------------------- - if (Conf.spoutTerritoryNoticeShow && Conf.spoutTerritoryNoticeSize > 0) + if (notify && Conf.spoutTerritoryNoticeShow && Conf.spoutTerritoryNoticeSize > 0) { NoticeLabel label; if (territoryChangeLabels.containsKey(player.getName())) diff --git a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java index cfa8f36f..fe52d493 100644 --- a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -154,6 +154,8 @@ public class FactionsPlayerListener extends PlayerListener // Run the member auto kick routine. Twice to get to the admins... FPlayers.i.autoLeaveOnInactivityRoutine(); FPlayers.i.autoLeaveOnInactivityRoutine(); + + SpoutFeatures.updateAppearancesShortly(event.getPlayer()); } @Override