The Special Factions are now unique per universe.

This commit is contained in:
Olof Larsson 2013-04-24 13:50:02 +02:00
parent e0c6e71b91
commit 0eb121c444
7 changed files with 146 additions and 143 deletions

View File

@ -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;

View File

@ -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<TerritoryAccess>
// 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());
}

View File

@ -90,7 +90,7 @@ public class Board extends Entity<Board> 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<Board> 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);
}

View File

@ -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<Faction> implements EconomyParticipator
public boolean isNone()
{
return this.getId().equals(Const.FACTIONID_NONE);
return this.getId().equals(UConf.get(this).factionIdNone);
}
public boolean isNormal()

View File

@ -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<Faction>
{
super.init();
this.createDefaultFactions();
this.createSpecialFactions();
}
/*
@ -64,6 +63,23 @@ public class FactionColl extends Coll<Faction>
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<Faction>
}
// -------------------------------------------- //
// 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<Faction>
{
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);
}
}

View File

@ -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<UConf>
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<FFlag, Boolean> defaultFactionFlags = FFlag.getDefaultDefaults();
public Map<FPerm, Set<Rel>> defaultFactionPerms = FPerm.getDefaultDefaults();
// -------------------------------------------- //
// CORE
// -------------------------------------------- //
@ -48,20 +68,7 @@ public class UConf extends Entity<UConf>
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<FFlag, Boolean> defaultFactionFlags = FFlag.getDefaultDefaults();
public Map<FPerm, Set<Rel>> defaultFactionPerms = FPerm.getDefaultDefaults();
// -------------------------------------------- //
// POWER

View File

@ -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<UPlayer> 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