From e6d45a6aa2e26a944563a395bfb14ec8676c6419 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 21 Oct 2011 20:08:54 +0200 Subject: [PATCH] Spout overlay support is missing for the new relation coloring. Otherwise done. --- src/com/massivecraft/factions/Board.java | 10 ++-- src/com/massivecraft/factions/FPlayer.java | 13 ++--- src/com/massivecraft/factions/Faction.java | 52 +++++++++---------- .../factions/cmd/CmdPeaceful.java | 2 +- src/com/massivecraft/factions/cmd/CmdTag.java | 2 +- .../factions/iface/RelationParticipator.java | 2 +- .../integration/SpoutMainListener.java | 1 - .../massivecraft/factions/struct/Role.java | 24 ++++++--- .../factions/util/RelationUtil.java | 9 +++- 9 files changed, 63 insertions(+), 52 deletions(-) diff --git a/src/com/massivecraft/factions/Board.java b/src/com/massivecraft/factions/Board.java index 4b9f1b7d..a2326ab1 100644 --- a/src/com/massivecraft/factions/Board.java +++ b/src/com/massivecraft/factions/Board.java @@ -212,7 +212,7 @@ public class Board if (factionHere.isNone()) { row += ChatColor.GRAY+"-"; } else if (factionHere.isSafeZone()) { - row += ChatColor.GOLD+"+"; + row += Conf.colorPeaceful+"+"; } else if (factionHere.isWarZone()) { row += ChatColor.DARK_RED+"+"; } else if ( @@ -225,7 +225,7 @@ public class Board if (!fList.containsKey(factionHere.getTag())) fList.put(factionHere.getTag(), Conf.mapKeyChrs[chrIdx++]); char tag = fList.get(factionHere.getTag()); - row += factionHere.getRelationTo(faction).getColor() + "" + tag; + row += factionHere.getColorTo(faction) + "" + tag; } else { row += ChatColor.GRAY+"-"; } @@ -243,9 +243,11 @@ public class Board ret.set(3, asciiCompass.get(2)+ret.get(3).substring(3*3)); // Add the faction key - if (Conf.showMapFactionKey) { + if (Conf.showMapFactionKey) + { String fRow = ""; - for(String key : fList.keySet()) { + for(String key : fList.keySet()) + { fRow += String.format("%s%s: %s ", ChatColor.GRAY, fList.get(key), key); } ret.add(fRow); diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 4b4ef21e..373f39a3 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -312,11 +312,11 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator public String getNameAndTitle(Faction faction) { - return this.getRelationColor(faction)+this.getNameAndTitle(); + return this.getColorTo(faction)+this.getNameAndTitle(); } public String getNameAndTitle(FPlayer fplayer) { - return this.getRelationColor(fplayer)+this.getNameAndTitle(); + return this.getColorTo(fplayer)+this.getNameAndTitle(); } /*public String getNameAndTag(Faction faction) @@ -372,11 +372,12 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator public String getChatTag(FPlayer fplayer) { - if ( ! this.hasFaction()) { + if ( ! this.hasFaction()) + { return ""; } - return this.getRelationTo(fplayer).getColor()+getChatTag(); + return this.getColorTo(fplayer)+getChatTag(); } // ------------------------------- @@ -413,9 +414,9 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator } @Override - public ChatColor getRelationColor(RelationParticipator rp) + public ChatColor getColorTo(RelationParticipator rp) { - return RelationUtil.getRelationColor(this, rp); + return RelationUtil.getColorOfThatToMe(this, rp); } //----------------------------------------------// diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index 5852b48b..ab1835be 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -68,14 +68,14 @@ public class Faction extends Entity implements EconomyParticipator { return getTag(); } - return this.getTag(otherFaction.getRelationColor(this).toString()); + return this.getTag(otherFaction.getColorTo(this).toString()); } public String getTag(FPlayer otherFplayer) { if (otherFplayer == null) { return getTag(); } - return this.getTag(otherFplayer.getRelationColor(this).toString()); + return this.getTag(this.getColorTo(otherFplayer).toString()); } public void setTag(String str) { @@ -216,9 +216,9 @@ public class Faction extends Entity implements EconomyParticipator } @Override - public ChatColor getRelationColor(RelationParticipator rp) + public ChatColor getColorTo(RelationParticipator rp) { - return RelationUtil.getRelationColor(this, rp); + return RelationUtil.getColorOfThatToMe(this, rp); } public Relation getRelationWish(Faction otherFaction) @@ -248,31 +248,38 @@ public class Faction extends Entity implements EconomyParticipator public double getPower() { double ret = 0; - for (FPlayer fplayer : this.getFPlayers()) { + for (FPlayer fplayer : this.getFPlayers()) + { ret += fplayer.getPower(); } - if (Conf.powerFactionMax > 0 && ret > Conf.powerFactionMax) { + if (Conf.powerFactionMax > 0 && ret > Conf.powerFactionMax) + { ret = Conf.powerFactionMax; } return ret; } - public double getPowerMax() { + public double getPowerMax() + { double ret = 0; - for (FPlayer fplayer : this.getFPlayers()) { + for (FPlayer fplayer : this.getFPlayers()) + { ret += fplayer.getPowerMax(); } - if (Conf.powerFactionMax > 0 && ret > Conf.powerFactionMax) { + if (Conf.powerFactionMax > 0 && ret > Conf.powerFactionMax) + { ret = Conf.powerFactionMax; } return ret; } - public int getPowerRounded() { + public int getPowerRounded() + { return (int) Math.round(this.getPower()); } - public int getPowerMaxRounded() { + public int getPowerMaxRounded() + { return (int) Math.round(this.getPowerMax()); } @@ -280,11 +287,13 @@ public class Faction extends Entity implements EconomyParticipator return Board.getFactionCoordCount(this); } - public int getLandRoundedInWorld(String worldName) { + public int getLandRoundedInWorld(String worldName) + { return Board.getFactionCoordCountInWorld(this, worldName); } - public boolean hasLandInflation() { + public boolean hasLandInflation() + { return this.getLandRounded() > this.getPowerRounded(); } @@ -430,20 +439,6 @@ public class Faction extends Entity implements EconomyParticipator } } - //----------------------------------------------// - // Mudd TODO - //----------------------------------------------// - - public ChatColor getRelationColor(Faction otherFaction) - { - return this.getRelationTo(otherFaction).getColor(); - } - - public ChatColor getRelationColor(FPlayer fplayer) - { - return this.getRelationTo(fplayer).getColor(); - } - //----------------------------------------------// // Ownership of specific claims //----------------------------------------------// @@ -539,7 +534,8 @@ public class Faction extends Entity implements EconomyParticipator public void removePlayerAsOwner(String playerName, FLocation loc) { Set ownerData = claimOwnership.get(loc); - if (ownerData == null) { + if (ownerData == null) + { return; } ownerData.remove(playerName.toLowerCase()); diff --git a/src/com/massivecraft/factions/cmd/CmdPeaceful.java b/src/com/massivecraft/factions/cmd/CmdPeaceful.java index 103cfda8..0750996f 100644 --- a/src/com/massivecraft/factions/cmd/CmdPeaceful.java +++ b/src/com/massivecraft/factions/cmd/CmdPeaceful.java @@ -53,7 +53,7 @@ public class CmdPeaceful extends FCommand } else { - fplayer.msg((fme == null ? "A server admin" : fme.describeTo(fplayer, true))+" has "+change+" the faction \"" + faction.getTag(fplayer) + "\"."); + fplayer.msg((fme == null ? "A server admin" : fme.describeTo(fplayer, true))+" has "+change+" the faction \"" + faction.getTag(fplayer) + "\"."); } } diff --git a/src/com/massivecraft/factions/cmd/CmdTag.java b/src/com/massivecraft/factions/cmd/CmdTag.java index ab199bcc..47c37e43 100644 --- a/src/com/massivecraft/factions/cmd/CmdTag.java +++ b/src/com/massivecraft/factions/cmd/CmdTag.java @@ -62,7 +62,7 @@ public class CmdTag extends FCommand { continue; } - faction.msg("The faction %s changed their name to %s.", fme.getRelationColor(faction)+oldtag, myFaction.getTag(faction)); + faction.msg("The faction %s changed their name to %s.", fme.getColorTo(faction)+oldtag, myFaction.getTag(faction)); } if (Conf.spoutFactionTagsOverNames) diff --git a/src/com/massivecraft/factions/iface/RelationParticipator.java b/src/com/massivecraft/factions/iface/RelationParticipator.java index acbf7a40..b46b6f3b 100644 --- a/src/com/massivecraft/factions/iface/RelationParticipator.java +++ b/src/com/massivecraft/factions/iface/RelationParticipator.java @@ -12,5 +12,5 @@ public interface RelationParticipator public Relation getRelationTo(RelationParticipator that); public Relation getRelationTo(RelationParticipator that, boolean ignorePeaceful); - public ChatColor getRelationColor(RelationParticipator to); + public ChatColor getColorTo(RelationParticipator to); } diff --git a/src/com/massivecraft/factions/integration/SpoutMainListener.java b/src/com/massivecraft/factions/integration/SpoutMainListener.java index 526dd869..a796a335 100644 --- a/src/com/massivecraft/factions/integration/SpoutMainListener.java +++ b/src/com/massivecraft/factions/integration/SpoutMainListener.java @@ -32,7 +32,6 @@ public class SpoutMainListener extends SpoutListener updateTerritoryDisplay(me); } - //-----------------------------------------------------------------------------------------// // Everything below this is handled in here to prevent errors on servers not running Spout //-----------------------------------------------------------------------------------------// diff --git a/src/com/massivecraft/factions/struct/Role.java b/src/com/massivecraft/factions/struct/Role.java index ecbd4ebf..08af23c9 100644 --- a/src/com/massivecraft/factions/struct/Role.java +++ b/src/com/massivecraft/factions/struct/Role.java @@ -2,7 +2,8 @@ package com.massivecraft.factions.struct; import com.massivecraft.factions.Conf; -public enum Role { +public enum Role +{ ADMIN(2, "admin"), MODERATOR(1, "moderator"), NORMAL(0, "normal member"); @@ -10,30 +11,37 @@ public enum Role { public final int value; public final String nicename; - private Role(final int value, final String nicename) { + private Role(final int value, final String nicename) + { this.value = value; this.nicename = nicename; } - public boolean isAtLeast(Role role) { + public boolean isAtLeast(Role role) + { return this.value >= role.value; } - public boolean isAtMost(Role role) { + public boolean isAtMost(Role role) + { return this.value <= role.value; } @Override - public String toString() { + public String toString() + { return this.nicename; } - public String getPrefix() { - if (this == Role.ADMIN) { + public String getPrefix() + { + if (this == Role.ADMIN) + { return Conf.prefixAdmin; } - if (this == Role.MODERATOR) { + if (this == Role.MODERATOR) + { return Conf.prefixMod; } diff --git a/src/com/massivecraft/factions/util/RelationUtil.java b/src/com/massivecraft/factions/util/RelationUtil.java index 3168ec59..0762033a 100644 --- a/src/com/massivecraft/factions/util/RelationUtil.java +++ b/src/com/massivecraft/factions/util/RelationUtil.java @@ -2,6 +2,7 @@ package com.massivecraft.factions.util; import org.bukkit.ChatColor; +import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.iface.RelationParticipator; @@ -53,7 +54,7 @@ public class RelationUtil ret = TextUtil.upperCaseFirst(ret); } - return "" + getRelationColor(me, that) + ret; + return "" + getColorOfThatToMe(that, me) + ret; } public static String describeThatToMe(RelationParticipator that, RelationParticipator me) @@ -113,8 +114,12 @@ public class RelationUtil return null; } - public static ChatColor getRelationColor(RelationParticipator me, RelationParticipator that) + public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me) { + if (getFaction(that) != null && getFaction(that).isPeaceful() && getFaction(that) != getFaction(me)) + { + return Conf.colorPeaceful; + } return getRelationTo(that, me).getColor(); } }