Updated Spout features to improve consistency (of code, and of displayed information)

This commit is contained in:
Brettflan 2011-10-23 09:03:28 -05:00
parent a9b1aad956
commit 3e8faad156
8 changed files with 113 additions and 63 deletions

View File

@ -771,6 +771,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
} }
Board.setFactionAt(forFaction, flocation); Board.setFactionAt(forFaction, flocation);
SpoutFeatures.updateTerritoryDisplayLoc(flocation);
return true; return true;
} }

View File

@ -5,6 +5,7 @@ import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation; import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
@ -90,6 +91,7 @@ public class CmdOwner extends FCommand
if (args.isEmpty() && myFaction.doesLocationHaveOwnersSet(flocation)) if (args.isEmpty() && myFaction.doesLocationHaveOwnersSet(flocation))
{ {
myFaction.clearClaimOwnership(flocation); myFaction.clearClaimOwnership(flocation);
SpoutFeatures.updateOwnerListLoc(flocation);
fme.msg("<i>You have cleared ownership for this claimed area."); fme.msg("<i>You have cleared ownership for this claimed area.");
return; return;
} }
@ -97,6 +99,7 @@ public class CmdOwner extends FCommand
if (myFaction.isPlayerInOwnerList(playerName, flocation)) if (myFaction.isPlayerInOwnerList(playerName, flocation))
{ {
myFaction.removePlayerAsOwner(playerName, flocation); myFaction.removePlayerAsOwner(playerName, flocation);
SpoutFeatures.updateOwnerListLoc(flocation);
fme.msg("<i>You have removed ownership of this claimed land from %s<i>.", playerName); fme.msg("<i>You have removed ownership of this claimed land from %s<i>.", playerName);
return; 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; if ( ! payForCommand(Conf.econCostOwner, "to set ownership of claimed land", "for setting ownership of claimed land")) return;
myFaction.setPlayerAsOwner(playerName, flocation); myFaction.setPlayerAsOwner(playerName, flocation);
SpoutFeatures.updateOwnerListLoc(flocation);
fme.msg("<i>You have added %s<i> to the owner list for this claimed land.", playerName); fme.msg("<i>You have added %s<i> to the owner list for this claimed land.", playerName);
} }
} }

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board; import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.FLocation; import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
@ -38,6 +39,7 @@ public class CmdUnclaim extends FCommand
if (Permission.MANAGE_SAFE_ZONE.has(sender)) if (Permission.MANAGE_SAFE_ZONE.has(sender))
{ {
Board.removeAt(flocation); Board.removeAt(flocation);
SpoutFeatures.updateTerritoryDisplayLoc(flocation);
msg("<i>Safe zone was unclaimed."); msg("<i>Safe zone was unclaimed.");
} }
else else
@ -51,6 +53,7 @@ public class CmdUnclaim extends FCommand
if (Permission.MANAGE_WAR_ZONE.has(sender)) if (Permission.MANAGE_WAR_ZONE.has(sender))
{ {
Board.removeAt(flocation); Board.removeAt(flocation);
SpoutFeatures.updateTerritoryDisplayLoc(flocation);
msg("<i>War zone was unclaimed."); msg("<i>War zone was unclaimed.");
} }
else else
@ -63,6 +66,7 @@ public class CmdUnclaim extends FCommand
if (fme.isAdminBypassing()) if (fme.isAdminBypassing())
{ {
Board.removeAt(flocation); Board.removeAt(flocation);
SpoutFeatures.updateTerritoryDisplayLoc(flocation);
otherFaction.msg("%s<i> unclaimed some of your land.", fme.describeTo(otherFaction, true)); otherFaction.msg("%s<i> unclaimed some of your land.", fme.describeTo(otherFaction, true));
msg("<i>You unclaimed this land."); msg("<i>You unclaimed this land.");
@ -148,6 +152,7 @@ public class CmdUnclaim extends FCommand
} }
Board.removeAt(flocation); Board.removeAt(flocation);
SpoutFeatures.updateTerritoryDisplayLoc(flocation);
myFaction.msg("%s<i> unclaimed some land.", fme.describeTo(myFaction, true)); myFaction.msg("%s<i> unclaimed some land.", fme.describeTo(myFaction, true));
} }

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board; import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
public class CmdUnclaimall extends FCommand public class CmdUnclaimall extends FCommand
@ -39,6 +40,7 @@ public class CmdUnclaimall extends FCommand
Board.unclaimAll(myFaction.getId()); Board.unclaimAll(myFaction.getId());
myFaction.msg("%s<i> unclaimed ALL of your faction's land.", fme.describeTo(myFaction, true)); myFaction.msg("%s<i> unclaimed ALL of your faction's land.", fme.describeTo(myFaction, true));
SpoutFeatures.updateTerritoryDisplayLoc(null);
} }
} }

View File

@ -76,6 +76,6 @@ public abstract class FRelationCommand extends FCommand
} }
SpoutFeatures.updateAppearances(myFaction, them); SpoutFeatures.updateAppearances(myFaction, them);
SpoutFeatures.updateTerritoryDisplayLoc(null);
} }
} }

View File

@ -6,6 +6,7 @@ import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.P; import com.massivecraft.factions.P;
import org.bukkit.ChatColor; 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<FPlayer> 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 // update displayed current territory for specified player; returns false if unsuccessful
public static boolean updateTerritoryDisplay(FPlayer player) public static boolean updateTerritoryDisplay(FPlayer player)
{ {
if (!enabled()) if (!enabled())
return false; 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<FPlayer> 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<FPlayer> players = FPlayers.i.getOnline();
for (FPlayer player : players)
{
if (fLoc == null || player.getLastStoodAt() == fLoc)
mainListener.updateOwnerList(player);
}
}
}, 5);*/
} }
// update owner list for specified player // update owner list for specified player
@ -94,19 +142,15 @@ public class SpoutFeatures
public static void updateAppearances() public static void updateAppearances()
{ {
if (!enabled()) if (!enabled())
{
return; return;
}
Set<FPlayer> players = FPlayers.i.getOnline(); Set<FPlayer> players = FPlayers.i.getOnline();
Faction factionA;
for (FPlayer playerA : players) for (FPlayer playerA : players)
{ {
factionA = playerA.getFaction();
for (FPlayer playerB : players) 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) public static void updateAppearances(Player player)
{ {
if (!enabled() || player == null) if (!enabled() || player == null)
{
return; return;
}
Set<FPlayer> players = FPlayers.i.getOnline(); Set<FPlayer> players = FPlayers.i.getOnline();
FPlayer playerA = FPlayers.i.get(player); FPlayer playerA = FPlayers.i.get(player);
Faction factionA = playerA.getFaction();
for (FPlayer playerB : players) for (FPlayer playerB : players)
{ {
Player player2 = playerB.getPlayer(); updateSingle(playerB, playerA);
Relation rel = factionA.getRelationTo(playerB); updateSingle(playerA, playerB);
updateSingle(player2, player, rel, factionA, playerA.getTitle(), playerA.getRole());
updateSingle(player, player2, rel, playerB.getFaction(), playerB.getTitle(), playerB.getRole());
} }
} }
// 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 // update all appearances related to a single faction
public static void updateAppearances(Faction faction) public static void updateAppearances(Faction faction)
{ {
if (!enabled() || faction == null) if (!enabled() || faction == null)
{
return; return;
}
Set<FPlayer> players = FPlayers.i.getOnline(); Set<FPlayer> players = FPlayers.i.getOnline();
Faction factionA, factionB; Faction factionA;
for (FPlayer playerA : players) for (FPlayer playerA : players)
{ {
@ -149,12 +199,10 @@ public class SpoutFeatures
for (FPlayer playerB : players) for (FPlayer playerB : players)
{ {
factionB = playerB.getFaction(); if (factionA != faction && playerB.getFaction() != faction)
if (factionA != faction && factionB != faction)
{
continue; 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) public static void updateAppearances(Faction factionA, Faction factionB)
{ {
if (!enabled() || factionA == null || factionB == null) if (!enabled() || factionA == null || factionB == null)
{
return; return;
}
for (FPlayer playerA : factionA.getFPlayersWhereOnline(true)) for (FPlayer playerA : factionA.getFPlayersWhereOnline(true))
{ {
for (FPlayer playerB : factionB.getFPlayersWhereOnline(true)) for (FPlayer playerB : factionB.getFPlayersWhereOnline(true))
{ {
Player player1 = playerA.getPlayer(); updateSingle(playerB, playerA);
Player player2 = playerB.getPlayer(); updateSingle(playerA, playerB);
Relation rel = factionA.getRelationTo(factionB);
updateSingle(player2, player1, rel, factionA, playerA.getTitle(), playerA.getRole());
updateSingle(player1, player2, rel, factionB, playerB.getTitle(), playerB.getRole());
} }
} }
} }
// update a single appearance; internal use only by above public methods // 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) if (viewer == null || viewed == null)
return; 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) if ((Conf.spoutFactionTagsOverNames || Conf.spoutFactionTitlesOverNames) && viewer != viewed)
{ {
@ -195,19 +245,17 @@ public class SpoutFeatures
{ {
String addTag = ""; String addTag = "";
if (Conf.spoutFactionTagsOverNames) if (Conf.spoutFactionTagsOverNames)
{ addTag += viewedFaction.getTag(viewed.getColorTo(viewer).toString() + "[") + "]";
addTag += viewedFaction.getTag(relation.getColor().toString() + "[") + "]";
}
String rolePrefix = viewedRole.getPrefix(); String rolePrefix = viewedRole.getPrefix();
if (Conf.spoutFactionTitlesOverNames && (!viewedTitle.isEmpty() || !rolePrefix.isEmpty())) if (Conf.spoutFactionTitlesOverNames && (!viewedTitle.isEmpty() || !rolePrefix.isEmpty()))
{
addTag += (addTag.isEmpty() ? "" : " ") + viewedRole.getPrefix() + viewedTitle; addTag += (addTag.isEmpty() ? "" : " ") + viewedRole.getPrefix() + viewedTitle;
}
spoutApp.setPlayerTitle(sPlayer, viewed, addTag + "\n" + viewed.getDisplayName()); spoutApp.setPlayerTitle(sPlayer, pViewed, addTag + "\n" + pViewed.getDisplayName());
} }
else 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 = ""; String cape = "";
if (!viewedFaction.isNormal()) if (!viewedFaction.isNormal())
{ {
// yeah, no cape if no faction // yeah, no cape if no faction
} }
else if (viewedFaction.isPeaceful()) else if (viewedFaction.isPeaceful())
{
cape = Conf.capePeaceful; cape = Conf.capePeaceful;
}
else if (relation.isNeutral()) else if (relation.isNeutral())
{
cape = Conf.capeNeutral; cape = Conf.capeNeutral;
}
else if (relation.isMember()) else if (relation.isMember())
{
cape = Conf.capeMember; cape = Conf.capeMember;
}
else if (relation.isEnemy()) else if (relation.isEnemy())
{
cape = Conf.capeEnemy; cape = Conf.capeEnemy;
}
else if (relation.isAlly()) else if (relation.isAlly())
{
cape = Conf.capeAlly; cape = Conf.capeAlly;
}
if (cape.isEmpty()) if (cape.isEmpty())
{ spoutApp.resetPlayerCloak(sPlayer, pViewed);
spoutApp.resetPlayerCloak(sPlayer, viewed);
}
else else
{ spoutApp.setPlayerCloak(sPlayer, pViewed, cape);
spoutApp.setPlayerCloak(sPlayer, viewed, cape);
}
} }
else if (Conf.spoutFactionAdminCapes || Conf.spoutFactionModeratorCapes) else if (Conf.spoutFactionAdminCapes || Conf.spoutFactionModeratorCapes)
{ {
spoutApp.resetPlayerCloak(sPlayer, viewed); spoutApp.resetPlayerCloak(sPlayer, pViewed);
} }
} }
// method to convert a Bukkit ChatColor to a Spout Color // method to convert a Bukkit ChatColor to a Spout Color
protected static Color getSpoutColor(ChatColor inColor, int alpha) protected static Color getSpoutColor(ChatColor inColor, int alpha)
{ {
if (inColor == null) if (inColor == null)
{
return SpoutFixedColor(191, 191, 191, alpha); return SpoutFixedColor(191, 191, 191, alpha);
}
switch (inColor.getCode()) switch (inColor.getCode())
{ {
case 0x1: return SpoutFixedColor(0, 0, 191, alpha); case 0x1: return SpoutFixedColor(0, 0, 191, alpha);

View File

@ -29,7 +29,7 @@ public class SpoutMainListener extends SpoutListener
final FPlayer me = FPlayers.i.get(event.getPlayer()); final FPlayer me = FPlayers.i.get(event.getPlayer());
SpoutFeatures.updateAppearances(me.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; // private final static int SCREEN_HEIGHT = 240;
public boolean updateTerritoryDisplay(FPlayer player) public boolean updateTerritoryDisplay(FPlayer player, boolean notify)
{ {
Player p = player.getPlayer(); Player p = player.getPlayer();
if (p == null) if (p == null)
@ -53,7 +53,7 @@ public class SpoutMainListener extends SpoutListener
if (!sPlayer.isSpoutCraftEnabled() || (Conf.spoutTerritoryDisplaySize <= 0 && ! Conf.spoutTerritoryNoticeShow)) if (!sPlayer.isSpoutCraftEnabled() || (Conf.spoutTerritoryDisplaySize <= 0 && ! Conf.spoutTerritoryNoticeShow))
return false; return false;
doLabels(player, sPlayer); doLabels(player, sPlayer, notify);
return true; 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); FLocation here = new FLocation(player);
Faction factionHere = Board.getFactionAt(here); Faction factionHere = Board.getFactionAt(here);
String tag = factionHere.getTag(player); String tag = factionHere.getColorTo(player).toString() + factionHere.getTag();
// ---------------------- // ----------------------
// Main territory display // Main territory display
@ -122,7 +122,7 @@ public class SpoutMainListener extends SpoutListener
// ----------------------- // -----------------------
// Fading territory notice // Fading territory notice
// ----------------------- // -----------------------
if (Conf.spoutTerritoryNoticeShow && Conf.spoutTerritoryNoticeSize > 0) if (notify && Conf.spoutTerritoryNoticeShow && Conf.spoutTerritoryNoticeSize > 0)
{ {
NoticeLabel label; NoticeLabel label;
if (territoryChangeLabels.containsKey(player.getName())) if (territoryChangeLabels.containsKey(player.getName()))

View File

@ -154,6 +154,8 @@ public class FactionsPlayerListener extends PlayerListener
// Run the member auto kick routine. Twice to get to the admins... // Run the member auto kick routine. Twice to get to the admins...
FPlayers.i.autoLeaveOnInactivityRoutine(); FPlayers.i.autoLeaveOnInactivityRoutine();
FPlayers.i.autoLeaveOnInactivityRoutine(); FPlayers.i.autoLeaveOnInactivityRoutine();
SpoutFeatures.updateAppearancesShortly(event.getPlayer());
} }
@Override @Override