From 0eb121c444e33a837f41bb35383b97fd89e46b94 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 24 Apr 2013 13:50:02 +0200 Subject: [PATCH] The Special Factions are now unique per universe. --- src/com/massivecraft/factions/Const.java | 5 - .../adapter/TerritoryAccessAdapter.java | 5 - .../massivecraft/factions/entity/Board.java | 4 +- .../massivecraft/factions/entity/Faction.java | 3 +- .../factions/entity/FactionColl.java | 234 +++++++++--------- .../massivecraft/factions/entity/UConf.java | 35 +-- .../massivecraft/factions/entity/UPlayer.java | 3 +- 7 files changed, 146 insertions(+), 143 deletions(-) diff --git a/src/com/massivecraft/factions/Const.java b/src/com/massivecraft/factions/Const.java index 8bdcf842..09f9a9c8 100644 --- a/src/com/massivecraft/factions/Const.java +++ b/src/com/massivecraft/factions/Const.java @@ -22,11 +22,6 @@ public class Const // Aspect Ids public static final String ASPECT_ID = "factions"; - // Defautlt faction ids - public static final String FACTIONID_NONE = "0"; - public static final String FACTIONID_SAFEZONE = "-1"; - public static final String FACTIONID_WARZONE = "-2"; - // ASCII Map public static final int MAP_HEIGHT = 8; public static final int MAP_WIDTH = 39; diff --git a/src/com/massivecraft/factions/adapter/TerritoryAccessAdapter.java b/src/com/massivecraft/factions/adapter/TerritoryAccessAdapter.java index d16dc667..19389c0e 100644 --- a/src/com/massivecraft/factions/adapter/TerritoryAccessAdapter.java +++ b/src/com/massivecraft/factions/adapter/TerritoryAccessAdapter.java @@ -14,7 +14,6 @@ import com.massivecraft.mcore.xlib.gson.JsonPrimitive; import com.massivecraft.mcore.xlib.gson.JsonSerializationContext; import com.massivecraft.mcore.xlib.gson.JsonSerializer; -import com.massivecraft.factions.Const; import com.massivecraft.factions.Factions; import com.massivecraft.factions.TerritoryAccess; @@ -97,10 +96,6 @@ public class TerritoryAccessAdapter implements JsonDeserializer // if default values, store as simple string if (src.isDefault()) { - // if Wilderness (faction "0") and default access values, no need to store it - if (src.getHostFactionId().equals(Const.FACTIONID_NONE)) - return null; - return new JsonPrimitive(src.getHostFactionId()); } diff --git a/src/com/massivecraft/factions/entity/Board.java b/src/com/massivecraft/factions/entity/Board.java index 91bc1001..1f4ac266 100644 --- a/src/com/massivecraft/factions/entity/Board.java +++ b/src/com/massivecraft/factions/entity/Board.java @@ -90,7 +90,7 @@ public class Board extends Entity implements BoardInterface if (ps == null) return null; ps = ps.getChunkCoords(true); TerritoryAccess ret = this.map.get(ps); - if (ret == null) ret = new TerritoryAccess(Const.FACTIONID_NONE); + if (ret == null) ret = new TerritoryAccess(UConf.get(this).factionIdNone); return ret; } @@ -108,7 +108,7 @@ public class Board extends Entity implements BoardInterface { ps = ps.getChunkCoords(true); - if (territoryAccess == null || (territoryAccess.getHostFactionId().equals(Const.FACTIONID_NONE) && territoryAccess.isDefault())) + if (territoryAccess == null || (territoryAccess.getHostFactionId().equals(UConf.get(this).factionIdNone) && territoryAccess.isDefault())) { this.map.remove(ps); } diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 567f38df..fccb3db8 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -8,7 +8,6 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import com.massivecraft.factions.Const; import com.massivecraft.factions.EconomyParticipator; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FPerm; @@ -116,7 +115,7 @@ public class Faction extends Entity implements EconomyParticipator public boolean isNone() { - return this.getId().equals(Const.FACTIONID_NONE); + return this.getId().equals(UConf.get(this).factionIdNone); } public boolean isNormal() diff --git a/src/com/massivecraft/factions/entity/FactionColl.java b/src/com/massivecraft/factions/entity/FactionColl.java index 4ef8510b..aca1c320 100644 --- a/src/com/massivecraft/factions/entity/FactionColl.java +++ b/src/com/massivecraft/factions/entity/FactionColl.java @@ -10,7 +10,6 @@ import com.massivecraft.mcore.store.MStore; import com.massivecraft.mcore.util.Txt; import com.massivecraft.factions.ConfServer; -import com.massivecraft.factions.Const; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; @@ -38,7 +37,7 @@ public class FactionColl extends Coll { super.init(); - this.createDefaultFactions(); + this.createSpecialFactions(); } /* @@ -64,6 +63,23 @@ public class FactionColl extends Coll return ret; }*/ + // TODO: I hope this one is not crucial anymore. + // If it turns out to be I will just have to recreate the feature in the proper place. + /* + @Override + public Faction get(String id) + { + if ( ! this.exists(id)) + { + Factions.get().log(Level.WARNING, "Non existing factionId "+id+" requested! Issuing cleaning!"); + BoardColl.get().clean(); + FPlayerColl.get().clean(); + } + + return super.get(id); + } + */ + @Override public Faction detachId(Object oid) { @@ -95,29 +111,116 @@ public class FactionColl extends Coll } // -------------------------------------------- // - // GET + // SPECIAL FACTIONS // -------------------------------------------- // - // TODO: I hope this one is not crucial anymore. - // If it turns out to be I will just have to recreate the feature in the proper place. - /* - @Override - public Faction get(String id) + public void createSpecialFactions() { - if ( ! this.exists(id)) - { - Factions.get().log(Level.WARNING, "Non existing factionId "+id+" requested! Issuing cleaning!"); - BoardColl.get().clean(); - FPlayerColl.get().clean(); - } - - return super.get(id); + this.getNone(); + this.getSafezone(); + this.getWarzone(); } - */ public Faction getNone() { - return this.get(Const.FACTIONID_NONE); + String id = UConf.get(this).factionIdNone; + Faction faction = this.get(id); + if (faction != null) return faction; + + faction = this.createNewInstance(); + + faction.setTag(ChatColor.DARK_GREEN+"Wilderness"); + faction.setDescription(null); + faction.setOpen(false); + + faction.setFlag(FFlag.PERMANENT, true); + faction.setFlag(FFlag.PEACEFUL, false); + faction.setFlag(FFlag.INFPOWER, true); + faction.setFlag(FFlag.POWERLOSS, true); + faction.setFlag(FFlag.PVP, true); + faction.setFlag(FFlag.FRIENDLYFIRE, false); + faction.setFlag(FFlag.MONSTERS, true); + faction.setFlag(FFlag.EXPLOSIONS, true); + faction.setFlag(FFlag.FIRESPREAD, true); + faction.setFlag(FFlag.ENDERGRIEF, true); + + faction.setPermittedRelations(FPerm.BUILD, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.DOOR, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.CONTAINER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.BUTTON, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.LEVER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + + this.attach(faction, id); + + return faction; + } + + public Faction getSafezone() + { + String id = UConf.get(this).factionIdSafezone; + Faction faction = this.get(id); + if (faction != null) return faction; + + faction = this.createNewInstance(); + + faction.setTag("SafeZone"); + faction.setDescription("Free from PVP and monsters"); + faction.setOpen(false); + + faction.setFlag(FFlag.PERMANENT, true); + faction.setFlag(FFlag.PEACEFUL, true); + faction.setFlag(FFlag.INFPOWER, true); + faction.setFlag(FFlag.POWERLOSS, false); + faction.setFlag(FFlag.PVP, false); + faction.setFlag(FFlag.FRIENDLYFIRE, false); + faction.setFlag(FFlag.MONSTERS, false); + faction.setFlag(FFlag.EXPLOSIONS, false); + faction.setFlag(FFlag.FIRESPREAD, false); + faction.setFlag(FFlag.ENDERGRIEF, false); + + faction.setPermittedRelations(FPerm.DOOR, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.CONTAINER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.BUTTON, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.LEVER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.TERRITORY, Rel.LEADER, Rel.OFFICER, Rel.MEMBER); + + this.attach(faction, id); + + return faction; + } + + public Faction getWarzone() + { + String id = UConf.get(this).factionIdWarzone; + Faction faction = this.get(id); + if (faction != null) return faction; + + faction = this.createNewInstance(); + + faction.setTag("WarZone"); + faction.setDescription("Not the safest place to be"); + faction.setOpen(false); + + faction.setFlag(FFlag.PERMANENT, true); + faction.setFlag(FFlag.PEACEFUL, true); + faction.setFlag(FFlag.INFPOWER, true); + faction.setFlag(FFlag.POWERLOSS, true); + faction.setFlag(FFlag.PVP, true); + faction.setFlag(FFlag.FRIENDLYFIRE, true); + faction.setFlag(FFlag.MONSTERS, true); + faction.setFlag(FFlag.EXPLOSIONS, true); + faction.setFlag(FFlag.FIRESPREAD, true); + faction.setFlag(FFlag.ENDERGRIEF, true); + + faction.setPermittedRelations(FPerm.DOOR, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.CONTAINER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.BUTTON, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.LEVER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(FPerm.TERRITORY, Rel.LEADER, Rel.OFFICER, Rel.MEMBER); + + this.attach(faction, id); + + return faction; } // -------------------------------------------- // @@ -209,100 +312,5 @@ public class FactionColl extends Coll { return this.getByTag(str) != null; } - - // -------------------------------------------- // - // CREATE DEFAULT FACTIONS - // -------------------------------------------- // - - public void createDefaultFactions() - { - this.createNoneFaction(); - this.createSafeZoneFaction(); - this.createWarZoneFaction(); - } - - public void createNoneFaction() - { - if (this.containsId(Const.FACTIONID_NONE)) return; - - Faction faction = this.create(Const.FACTIONID_NONE); - - faction.setTag(ChatColor.DARK_GREEN+"Wilderness"); - faction.setDescription(""); - faction.setOpen(false); - - faction.setFlag(FFlag.PERMANENT, true); - faction.setFlag(FFlag.PEACEFUL, false); - faction.setFlag(FFlag.INFPOWER, true); - faction.setFlag(FFlag.POWERLOSS, true); - faction.setFlag(FFlag.PVP, true); - faction.setFlag(FFlag.FRIENDLYFIRE, false); - faction.setFlag(FFlag.MONSTERS, true); - faction.setFlag(FFlag.EXPLOSIONS, true); - faction.setFlag(FFlag.FIRESPREAD, true); - faction.setFlag(FFlag.ENDERGRIEF, true); - - faction.setPermittedRelations(FPerm.BUILD, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.DOOR, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.CONTAINER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.BUTTON, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.LEVER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - } - - public void createSafeZoneFaction() - { - if (this.containsId(Const.FACTIONID_SAFEZONE)) return; - - Faction faction = this.create(Const.FACTIONID_SAFEZONE); - - faction.setTag("SafeZone"); - faction.setDescription("Free from PVP and monsters"); - faction.setOpen(false); - - faction.setFlag(FFlag.PERMANENT, true); - faction.setFlag(FFlag.PEACEFUL, true); - faction.setFlag(FFlag.INFPOWER, true); - faction.setFlag(FFlag.POWERLOSS, false); - faction.setFlag(FFlag.PVP, false); - faction.setFlag(FFlag.FRIENDLYFIRE, false); - faction.setFlag(FFlag.MONSTERS, false); - faction.setFlag(FFlag.EXPLOSIONS, false); - faction.setFlag(FFlag.FIRESPREAD, false); - faction.setFlag(FFlag.ENDERGRIEF, false); - - faction.setPermittedRelations(FPerm.DOOR, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.CONTAINER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.BUTTON, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.LEVER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.TERRITORY, Rel.LEADER, Rel.OFFICER, Rel.MEMBER); - } - - public void createWarZoneFaction() - { - if (this.containsId(Const.FACTIONID_WARZONE)) return; - - Faction faction = this.create(Const.FACTIONID_WARZONE); - - faction.setTag("WarZone"); - faction.setDescription("Not the safest place to be"); - faction.setOpen(false); - - faction.setFlag(FFlag.PERMANENT, true); - faction.setFlag(FFlag.PEACEFUL, true); - faction.setFlag(FFlag.INFPOWER, true); - faction.setFlag(FFlag.POWERLOSS, true); - faction.setFlag(FFlag.PVP, true); - faction.setFlag(FFlag.FRIENDLYFIRE, true); - faction.setFlag(FFlag.MONSTERS, true); - faction.setFlag(FFlag.EXPLOSIONS, true); - faction.setFlag(FFlag.FIRESPREAD, true); - faction.setFlag(FFlag.ENDERGRIEF, true); - - faction.setPermittedRelations(FPerm.DOOR, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.CONTAINER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.BUTTON, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.LEVER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.TERRITORY, Rel.LEADER, Rel.OFFICER, Rel.MEMBER); - } } diff --git a/src/com/massivecraft/factions/entity/UConf.java b/src/com/massivecraft/factions/entity/UConf.java index 855bceea..adbf673e 100644 --- a/src/com/massivecraft/factions/entity/UConf.java +++ b/src/com/massivecraft/factions/entity/UConf.java @@ -4,8 +4,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; -import com.massivecraft.factions.Const; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Rel; @@ -24,6 +24,26 @@ public class UConf extends Entity return UConfColls.get().get2(oid); } + // -------------------------------------------- // + // SPECIAL FACTION IDS + // -------------------------------------------- // + + public String factionIdNone = UUID.randomUUID().toString(); + public String factionIdSafezone = UUID.randomUUID().toString(); + public String factionIdWarzone = UUID.randomUUID().toString(); + + // -------------------------------------------- // + // DEFAULTS + // -------------------------------------------- // + + public String defaultPlayerFactionId = this.factionIdNone; + public double defaultPlayerPower = 0.0; + public Rel defaultPlayerRole = Rel.RECRUIT; + + public boolean defaultFactionOpen = false; + public Map defaultFactionFlags = FFlag.getDefaultDefaults(); + public Map> defaultFactionPerms = FPerm.getDefaultDefaults(); + // -------------------------------------------- // // CORE // -------------------------------------------- // @@ -48,20 +68,7 @@ public class UConf extends Entity public double territoryShieldFactor = 0.3; - // -------------------------------------------- // - // DEFAULTS - // -------------------------------------------- // - // TODO: should I add a nofaction id here? - // And perhaps for safezone and warzone as well. - - public String defaultPlayerFactionId = Const.FACTIONID_NONE; - public double defaultPlayerPower = 0.0; - public Rel defaultPlayerRole = Rel.RECRUIT; - - public boolean defaultFactionOpen = false; - public Map defaultFactionFlags = FFlag.getDefaultDefaults(); - public Map> defaultFactionPerms = FPerm.getDefaultDefaults(); // -------------------------------------------- // // POWER diff --git a/src/com/massivecraft/factions/entity/UPlayer.java b/src/com/massivecraft/factions/entity/UPlayer.java index a005baad..ad58da03 100644 --- a/src/com/massivecraft/factions/entity/UPlayer.java +++ b/src/com/massivecraft/factions/entity/UPlayer.java @@ -6,7 +6,6 @@ import java.util.Set; import org.bukkit.ChatColor; import org.bukkit.entity.Player; -import com.massivecraft.factions.Const; import com.massivecraft.factions.EconomyParticipator; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.Factions; @@ -189,7 +188,7 @@ public class UPlayer extends SenderEntity implements EconomyParticipato public boolean hasFaction() { - return !this.getFactionId().equals(Const.FACTIONID_NONE); + return !this.getFactionId().equals(UConf.get(this).factionIdNone); } // This setter is so long because it search for default/null case and takes care of updating the faction member index