From 6f897e15ff562e94519aa1898ed20022d57d7205 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Thu, 11 Apr 2013 12:22:35 +0200 Subject: [PATCH] Starting to preparation of Faction entity. --- src/com/massivecraft/factions/Faction.java | 115 ++++++++++++++++++--- 1 file changed, 102 insertions(+), 13 deletions(-) diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index fba8e8df..6e91f9dd 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -14,25 +14,69 @@ import com.massivecraft.factions.util.*; import com.massivecraft.factions.zcore.persist.Entity; import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.util.Txt; +import com.massivecraft.mcore.xlib.gson.annotations.SerializedName; public class Faction extends Entity implements EconomyParticipator { - // FIELD: relationWish - private Map relationWish; - - // FIELD: fplayers + // -------------------------------------------- // + // META + // -------------------------------------------- // + + /*public static Faction get(Object oid) + { + return FactionColl.get().get(oid); + }*/ + + // -------------------------------------------- // + // OVERRIDE: ENTITY + // -------------------------------------------- // + + /*@Override + public Faction load(Faction that) + { + //this.item = that.item; + // TODO + + return this; + }*/ + + // -------------------------------------------- // + // FIELDS: RAW + // -------------------------------------------- // + // speedy lookup of players in faction private transient Set fplayers = new HashSet(); - - // FIELD: invites - // Where string is a lowercase player name - private Set invites; - public void invite(FPlayer fplayer) { this.invites.add(fplayer.getId().toLowerCase()); } - public void deinvite(FPlayer fplayer) { this.invites.remove(fplayer.getId().toLowerCase()); } - public boolean isInvited(FPlayer fplayer) { return this.invites.contains(fplayer.getId().toLowerCase()); } + // TODO + + private Map relationWish; + // TODO + + @SerializedName("invites") + private Set invitedPlayerIds = null; + 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) + { + TreeSet target = new TreeSet(String.CASE_INSENSITIVE_ORDER); + + if (invitedPlayerIds != null) + { + for (String invitedPlayerId : invitedPlayerIds) + { + target.add(invitedPlayerId.toLowerCase()); + } + } + + this.invitedPlayerIds = target; + // TODO: Add when we use a true mcore entity. + // this.changed(); + } - // FIELD: open private boolean open; public boolean isOpen() { return this.open; } public void setOpen(boolean open) { this.open = open; } @@ -193,7 +237,6 @@ public class Faction extends Entity implements EconomyParticipator public Faction() { this.relationWish = new HashMap(); - this.invites = new HashSet(); this.open = ConfServer.newFactionsDefaultOpen; this.tag = "???"; this.description = "Default faction description :("; @@ -202,6 +245,52 @@ public class Faction extends Entity implements EconomyParticipator this.permOverrides = new LinkedHashMap>(); } + // -------------------------------------------- // + // FIELDS: EXTRA + // -------------------------------------------- // + + // TODO: Make use of a player name extractor? + + public boolean addInvitedPlayerId(String playerId) + { + TreeSet invitedPlayerIds = this.getInvitedPlayerIds(); + if (invitedPlayerIds.add(playerId.toLowerCase())) + { + this.setInvitedPlayerIds(invitedPlayerIds); + return true; + } + return false; + } + + public boolean removeInvitedPlayerId(String playerId) + { + TreeSet invitedPlayerIds = this.getInvitedPlayerIds(); + if (invitedPlayerIds.remove(playerId.toLowerCase())) + { + this.setInvitedPlayerIds(invitedPlayerIds); + return true; + } + return false; + } + + public boolean isInvited(FPlayer fplayer) + { + return this.getInvitedPlayerIds().contains(fplayer.getId()); + } + + // -------------------------------------------- // + // ACTIONS + // -------------------------------------------- // + + public void invite(FPlayer fplayer) + { + this.addInvitedPlayerId(fplayer.getId()); + } + + public void deinvite(FPlayer fplayer) + { + this.removeInvitedPlayerId(fplayer.getId()); + } // ------------------------------- // Understand the types