From 818c051ae1b3d363a2cf9c9779b58e7a3b322cd6 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 17 Apr 2013 12:08:30 +0200 Subject: [PATCH] Write some comments and reorder fields --- src/com/massivecraft/factions/Faction.java | 338 +++++++++++---------- 1 file changed, 175 insertions(+), 163 deletions(-) diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index 9c4a7361..81843f03 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -39,12 +39,12 @@ public class Faction extends Entity implements EconomyParticipator { this.tag = that.tag; this.setDescription(that.description); + this.home = that.home; + this.setPowerBoost(that.powerBoost); + this.cape = that.cape; this.open = that.open; this.setInvitedPlayerIds(that.invitedPlayerIds); this.setRelationWishes(that.relationWish); - this.home = that.home; - this.cape = that.cape; - this.setPowerBoost(that.powerBoost); this.setFlags(that.flagOverrides); this.permOverrides = that.permOverrides; @@ -63,24 +63,36 @@ public class Faction extends Entity implements EconomyParticipator // Thus we make use of a name. Since the id is used in all foreign key situations changing the name is fine. private String tag = null; + // Factions can optionally set a description for themselves. + // This description can for example be seen in territorial alerts. private String description = null; + // Factions can optionally set a home location. + // If they do their members can teleport there using /f home + private PS home = null; + + // Factions usually do not have a powerboost. It defaults to 0. + // The powerBoost is a custom increase/decrease to default and maximum power. + private Double powerBoost = null; + + // The cape field is used by the Spout integration features. + // It's the URL to the faction cape. + private String cape = null; + + // Can anyone join the Faction? + // If the faction is open they can. + // If the faction is closed an invite is required. private Boolean open = null; + // This is the ids of the invited players. + // They are actually "senderIds" since you can invite "@console" to your faction. @SerializedName("invites") private Set invitedPlayerIds = null; + // The keys in this map are factionIds. private Map relationWish = null; - private PS home = null; - - // The cape field is a URL used by the Spout integration features. - private String cape = null; - - // The powerBoost is a custom increase/decrease to default and max power for this faction. - private Double powerBoost = null; - - // The flag overrides are the modifications to the default values + // The flag overrides are the modifications to the default values. private Map flagOverrides; // FIELDS: Permission <-> Groups management @@ -141,7 +153,6 @@ public class Faction extends Entity implements EconomyParticipator this.setPermittedRelations(perm, temp); } - // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // @@ -260,6 +271,81 @@ public class Faction extends Entity implements EconomyParticipator this.changed(); } + // -------------------------------------------- // + // FIELD: home + // -------------------------------------------- // + + // TODO: Checkery is a bit weird? + + public PS getHome() + { + this.verifyHomeIsValid(); + return this.home; + } + + public void verifyHomeIsValid() + { + if (this.isValidHome(this.home)) return; + this.home = null; + msg("Your faction home has been un-set since it is no longer in your territory."); + } + + public boolean isValidHome(PS ps) + { + if (ps == null) return true; + if (!ConfServer.homesMustBeInClaimedTerritory) return true; + if (BoardColl.get().getFactionAt(ps) == this) return true; + return false; + } + + public boolean hasHome() + { + return this.getHome() != null; + } + + public void setHome(PS home) + { + this.home = home; + } + + // -------------------------------------------- // + // FIELD: powerBoost + // -------------------------------------------- // + + // RAW + + public double getPowerBoost() + { + Double ret = this.powerBoost; + if (ret == null) ret = 0D; + return ret; + } + + public void setPowerBoost(Double powerBoost) + { + if (powerBoost == null || powerBoost == 0) + { + powerBoost = null; + } + this.powerBoost = powerBoost; + this.changed(); + } + + // -------------------------------------------- // + // FIELD: cape + // -------------------------------------------- // + + public String getCape() + { + return cape; + } + + public void setCape(String cape) + { + this.cape = cape; + SpoutFeatures.updateCape(this, null); + } + // -------------------------------------------- // // FIELD: open // -------------------------------------------- // @@ -277,6 +363,82 @@ public class Faction extends Entity implements EconomyParticipator this.changed(); } + // -------------------------------------------- // + // FIELD: invitedPlayerIds + // -------------------------------------------- // + + // RAW + + public TreeSet getInvitedPlayerIds() + { + TreeSet ret = new TreeSet(String.CASE_INSENSITIVE_ORDER); + if (this.invitedPlayerIds != null) ret.addAll(this.invitedPlayerIds); + return ret; + } + + public void setInvitedPlayerIds(Collection invitedPlayerIds) + { + if (invitedPlayerIds == null || invitedPlayerIds.isEmpty()) + { + this.invitedPlayerIds = null; + } + else + { + TreeSet target = new TreeSet(String.CASE_INSENSITIVE_ORDER); + for (String invitedPlayerId : invitedPlayerIds) + { + target.add(invitedPlayerId.toLowerCase()); + } + this.invitedPlayerIds = target; + } + this.changed(); + } + + // FINER + + public boolean isInvited(String playerId) + { + return this.getInvitedPlayerIds().contains(playerId); + } + + public boolean isInvited(FPlayer fplayer) + { + return this.isInvited(fplayer.getId()); + } + + public boolean invite(String playerId) + { + TreeSet invitedPlayerIds = this.getInvitedPlayerIds(); + if (invitedPlayerIds.add(playerId.toLowerCase())) + { + this.setInvitedPlayerIds(invitedPlayerIds); + return true; + } + return false; + } + + public void invite(FPlayer fplayer) + { + this.invite(fplayer.getId()); + } + + public boolean deinvite(String playerId) + { + TreeSet invitedPlayerIds = this.getInvitedPlayerIds(); + if (invitedPlayerIds.remove(playerId.toLowerCase())) + { + this.setInvitedPlayerIds(invitedPlayerIds); + return true; + } + return false; + } + + public void deinvite(FPlayer fplayer) + { + this.deinvite(fplayer.getId()); + } + + // -------------------------------------------- // // FIELD: relationWish // -------------------------------------------- // @@ -360,156 +522,6 @@ public class Faction extends Entity implements EconomyParticipator return ret; } - // -------------------------------------------- // - // FIELD: invitedPlayerIds - // -------------------------------------------- // - - // RAW - - public TreeSet getInvitedPlayerIds() - { - TreeSet ret = new TreeSet(String.CASE_INSENSITIVE_ORDER); - if (this.invitedPlayerIds != null) ret.addAll(this.invitedPlayerIds); - return ret; - } - - public void setInvitedPlayerIds(Collection invitedPlayerIds) - { - if (invitedPlayerIds == null || invitedPlayerIds.isEmpty()) - { - this.invitedPlayerIds = null; - } - else - { - TreeSet target = new TreeSet(String.CASE_INSENSITIVE_ORDER); - for (String invitedPlayerId : invitedPlayerIds) - { - target.add(invitedPlayerId.toLowerCase()); - } - this.invitedPlayerIds = target; - } - this.changed(); - } - - // FINER - - public boolean isInvited(String playerId) - { - return this.getInvitedPlayerIds().contains(playerId); - } - - public boolean isInvited(FPlayer fplayer) - { - return this.isInvited(fplayer.getId()); - } - - public boolean invite(String playerId) - { - TreeSet invitedPlayerIds = this.getInvitedPlayerIds(); - if (invitedPlayerIds.add(playerId.toLowerCase())) - { - this.setInvitedPlayerIds(invitedPlayerIds); - return true; - } - return false; - } - - public void invite(FPlayer fplayer) - { - this.invite(fplayer.getId()); - } - - public boolean deinvite(String playerId) - { - TreeSet invitedPlayerIds = this.getInvitedPlayerIds(); - if (invitedPlayerIds.remove(playerId.toLowerCase())) - { - this.setInvitedPlayerIds(invitedPlayerIds); - return true; - } - return false; - } - - public void deinvite(FPlayer fplayer) - { - this.deinvite(fplayer.getId()); - } - - // -------------------------------------------- // - // FIELD: home - // -------------------------------------------- // - - // TODO: Checkery is a bit weird? - - public PS getHome() - { - this.verifyHomeIsValid(); - return this.home; - } - - public void verifyHomeIsValid() - { - if (this.isValidHome(this.home)) return; - this.home = null; - msg("Your faction home has been un-set since it is no longer in your territory."); - } - - public boolean isValidHome(PS ps) - { - if (ps == null) return true; - if (!ConfServer.homesMustBeInClaimedTerritory) return true; - if (BoardColl.get().getFactionAt(ps) == this) return true; - return false; - } - - public boolean hasHome() - { - return this.getHome() != null; - } - - public void setHome(PS home) - { - this.home = home; - } - - // -------------------------------------------- // - // FIELD: cape - // -------------------------------------------- // - - public String getCape() - { - return cape; - } - - public void setCape(String cape) - { - this.cape = cape; - SpoutFeatures.updateCape(this, null); - } - - // -------------------------------------------- // - // FIELD: powerBoost - // -------------------------------------------- // - - // RAW - - public double getPowerBoost() - { - Double ret = this.powerBoost; - if (ret == null) ret = 0D; - return ret; - } - - public void setPowerBoost(Double powerBoost) - { - if (powerBoost == null || powerBoost == 0) - { - powerBoost = null; - } - this.powerBoost = powerBoost; - this.changed(); - } - // -------------------------------------------- // // FIELD: flagOverrides // -------------------------------------------- //