Try moving some core configuration over to UConf.

This commit is contained in:
Olof Larsson 2013-04-22 16:58:22 +02:00
parent 6d2db1930c
commit 9a324d572e
12 changed files with 65 additions and 73 deletions

View File

@ -22,35 +22,6 @@ public class ConfServer extends SimpleConfig
public static List<String> baseCommandAliases = MUtil.list("f"); public static List<String> baseCommandAliases = MUtil.list("f");
public static String dburi = "default"; public static String dburi = "default";
// -------------------------------------------- //
// DOUBTFULLY CONFIGURABLE DEFAULTS (TODO)
// -------------------------------------------- //
public static Map<FFlag, Boolean> factionFlagDefaults = FFlag.getDefaultDefaults();
public static Map<FPerm, Set<Rel>> factionPermDefaults = FPerm.getDefaultDefaults();
// TODO: Shouldn't this be a constant rather?
public static Rel factionRankDefault = Rel.RECRUIT;
// -------------------------------------------- //
// CORE
// -------------------------------------------- //
public static int factionTagLengthMin = 3;
public static int factionTagLengthMax = 10;
public static boolean factionTagForceUpperCase = false;
public static boolean newFactionsDefaultOpen = false;
// when faction membership hits this limit, players will no longer be able to join using /f join; default is 0, no limit
public static int factionMemberLimit = 0;
// what faction ID to start new players in when they first join the server; default is 0, "no faction"
public static String newPlayerStartingFactionID = Const.FACTIONID_NONE;
// Disallow joining/leaving/kicking while power is negative
public static boolean canLeaveWithNegativePower = true;
// -------------------------------------------- // // -------------------------------------------- //
// AUTO LEAVE // AUTO LEAVE
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -3,6 +3,8 @@ package com.massivecraft.factions;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import com.massivecraft.factions.entity.UConf;
/** /**
* Flags that describe the nature of a faction and it's territory. * Flags that describe the nature of a faction and it's territory.
@ -64,9 +66,9 @@ public enum FFlag
// DEFAULTS // DEFAULTS
// -------------------------------------------- // // -------------------------------------------- //
public boolean getDefault() public boolean getDefault(Object o)
{ {
Boolean ret = ConfServer.factionFlagDefaults.get(this); Boolean ret = UConf.get(o).factionFlagDefaults.get(this);
if (ret == null) return this.getDefaultDefault(); if (ret == null) return this.getDefaultDefault();
return ret; return ret;
} }

View File

@ -13,6 +13,7 @@ import org.bukkit.command.CommandSender;
import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.BoardColls;
import com.massivecraft.factions.entity.FPlayer; import com.massivecraft.factions.entity.FPlayer;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.UConf;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
/** /**
@ -77,9 +78,9 @@ public enum FPerm
// DEFAULTS // DEFAULTS
// -------------------------------------------- // // -------------------------------------------- //
public Set<Rel> getDefault() public Set<Rel> getDefault(Object o)
{ {
Set<Rel> ret = ConfServer.factionPermDefaults.get(this); Set<Rel> ret = UConf.get(o).factionPermDefaults.get(this);
if (ret == null) return this.getDefaultDefault(); if (ret == null) return this.getDefaultDefault();
ret = new LinkedHashSet<Rel>(ret); ret = new LinkedHashSet<Rel>(ret);
return ret; return ret;

View File

@ -48,7 +48,7 @@ public class CmdFactionsCreate extends FCommand
return; return;
} }
ArrayList<String> tagValidationErrors = FactionColl.validateTag(newTag); ArrayList<String> tagValidationErrors = coll.validateTag(newTag);
if (tagValidationErrors.size() > 0) if (tagValidationErrors.size() > 0)
{ {
sendMessage(tagValidationErrors); sendMessage(tagValidationErrors);

View File

@ -1,6 +1,5 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFPlayer; import com.massivecraft.factions.cmd.arg.ARFPlayer;
@ -8,6 +7,7 @@ import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.entity.FPlayer; import com.massivecraft.factions.entity.FPlayer;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.UConf;
import com.massivecraft.factions.event.FactionsEventMembershipChange; import com.massivecraft.factions.event.FactionsEventMembershipChange;
import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason; import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
@ -49,9 +49,9 @@ public class CmdFactionsJoin extends FCommand
return; return;
} }
if (ConfServer.factionMemberLimit > 0 && faction.getFPlayers().size() >= ConfServer.factionMemberLimit) if (UConf.get(faction).factionMemberLimit > 0 && faction.getFPlayers().size() >= UConf.get(faction).factionMemberLimit)
{ {
msg(" <b>!<white> The faction %s is at the limit of %d members, so %s cannot currently join.", faction.getTag(fme), ConfServer.factionMemberLimit, fplayer.describeTo(fme, false)); msg(" <b>!<white> The faction %s is at the limit of %d members, so %s cannot currently join.", faction.getTag(fme), UConf.get(faction).factionMemberLimit, fplayer.describeTo(fme, false));
return; return;
} }
@ -61,7 +61,7 @@ public class CmdFactionsJoin extends FCommand
return; return;
} }
if (!ConfServer.canLeaveWithNegativePower && fplayer.getPower() < 0) if (!UConf.get(faction).canLeaveWithNegativePower && fplayer.getPower() < 0)
{ {
msg("<b>%s cannot join a faction with a negative power level.", fplayer.describeTo(fme, true)); msg("<b>%s cannot join a faction with a negative power level.", fplayer.describeTo(fme, true));
return; return;
@ -93,7 +93,6 @@ public class CmdFactionsJoin extends FCommand
// Apply // Apply
fplayer.resetFactionData(); fplayer.resetFactionData();
fplayer.setFaction(faction); fplayer.setFaction(faction);
fme.setRole(ConfServer.factionRankDefault); // They have just joined a faction, start them out on the lowest rank (default config).
faction.setInvited(fplayer, false); faction.setInvited(fplayer, false);

View File

@ -1,6 +1,5 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
@ -10,6 +9,7 @@ import com.massivecraft.factions.entity.FPlayer;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.FactionColls; import com.massivecraft.factions.entity.FactionColls;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.UConf;
import com.massivecraft.factions.event.FactionsEventMembershipChange; import com.massivecraft.factions.event.FactionsEventMembershipChange;
import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason; import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
@ -47,7 +47,7 @@ public class CmdFactionsKick extends FCommand
return; return;
} }
if ( ! ConfServer.canLeaveWithNegativePower && fplayer.getPower() < 0) if ( ! UConf.get(fplayer).canLeaveWithNegativePower && fplayer.getPower() < 0)
{ {
msg("<b>You cannot kick that member until their power is positive."); msg("<b>You cannot kick that member until their power is positive.");
return; return;

View File

@ -67,7 +67,7 @@ public class CmdFactionsPerm extends FCommand
faction.setRelationPermitted(perm, rel, val); faction.setRelationPermitted(perm, rel, val);
// The following is to make sure the leader always has the right to change perms if that is our goal. // The following is to make sure the leader always has the right to change perms if that is our goal.
if (perm == FPerm.PERMS && FPerm.PERMS.getDefault().contains(Rel.LEADER)) if (perm == FPerm.PERMS && FPerm.PERMS.getDefault(faction).contains(Rel.LEADER))
{ {
faction.setRelationPermitted(FPerm.PERMS, Rel.LEADER, true); faction.setRelationPermitted(FPerm.PERMS, Rel.LEADER, true);
} }

View File

@ -34,14 +34,16 @@ public class CmdFactionsTag extends FCommand
String newTag = this.arg(0); String newTag = this.arg(0);
// TODO does not first test cover selfcase? // TODO does not first test cover selfcase?
if (FactionColls.get().get(myFaction).isTagTaken(newTag) && ! MiscUtil.getComparisonString(newTag).equals(myFaction.getComparisonTag()))
FactionColl factionColl = FactionColls.get().get(myFaction);
if (factionColl.isTagTaken(newTag) && ! MiscUtil.getComparisonString(newTag).equals(myFaction.getComparisonTag()))
{ {
msg("<b>That tag is already taken"); msg("<b>That tag is already taken");
return; return;
} }
ArrayList<String> errors = new ArrayList<String>(); ArrayList<String> errors = new ArrayList<String>();
errors.addAll(FactionColl.validateTag(newTag)); errors.addAll(factionColl.validateTag(newTag));
if (errors.size() > 0) if (errors.size() > 0)
{ {
sendMessage(errors); sendMessage(errors);

View File

@ -110,11 +110,11 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
// This field contains the last calculated value of the players power. // This field contains the last calculated value of the players power.
// The power calculation is lazy which means that the power is calculated first when you try to view the value. // The power calculation is lazy which means that the power is calculated first when you try to view the value.
private double power; private Double power = null;
// This is the timestamp for the last calculation of the power. // This is the timestamp for the last calculation of the power.
// The value is used for the lazy calculation described above. // The value is used for the lazy calculation described above.
private long lastPowerUpdateTime; private long lastPowerUpdateTime = System.currentTimeMillis();
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS: RAW TRANSIENT // FIELDS: RAW TRANSIENT
@ -153,15 +153,11 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
public FPlayer() public FPlayer()
{ {
this.resetFactionData(false); this.resetFactionData(false);
this.setFactionId(ConfServer.newPlayerStartingFactionID); //this.power = ConfServer.powerStarting;
this.power = ConfServer.powerStarting;
this.lastPowerUpdateTime = System.currentTimeMillis();
} }
public final void resetFactionData(boolean doSpoutUpdate) public void resetFactionData(boolean doSpoutUpdate)
{ {
// TODO: Should we not rather use ConfServer.newPlayerStartingFactionID here?
// The default neutral faction // The default neutral faction
this.setFactionId(null); this.setFactionId(null);
this.setRole(null); this.setRole(null);
@ -189,7 +185,7 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
// This method never returns null // This method never returns null
public String getFactionId() public String getFactionId()
{ {
if (this.factionId == null) return Const.FACTIONID_NONE; if (this.factionId == null) return UConf.get(this).playerDefaultFactionId;
return this.factionId; return this.factionId;
} }
@ -197,7 +193,7 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
public Faction getFaction() public Faction getFaction()
{ {
Faction ret = FactionColls.get().get(this).get(this.getFactionId()); Faction ret = FactionColls.get().get(this).get(this.getFactionId());
if (ret == null) ret = FactionColls.get().get(this).get(Const.FACTIONID_NONE); if (ret == null) ret = FactionColls.get().get(this).get(UConf.get(this).playerDefaultFactionId);
return ret; return ret;
} }
@ -259,13 +255,13 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
public Rel getRole() public Rel getRole()
{ {
if (this.role == null) return Rel.MEMBER; if (this.role == null) return UConf.get(this).playerDefaultRole;
return this.role; return this.role;
} }
public void setRole(Rel role) public void setRole(Rel role)
{ {
if (role == null || role == Rel.MEMBER) if (role == null || role == UConf.get(this).playerDefaultRole)
{ {
this.role = null; this.role = null;
} }
@ -662,7 +658,7 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
return; return;
} }
if (!ConfServer.canLeaveWithNegativePower && this.getPower() < 0) if (!UConf.get(myFaction).canLeaveWithNegativePower && this.getPower() < 0)
{ {
msg("<b>You cannot leave until your power is positive."); msg("<b>You cannot leave until your power is positive.");
return; return;

View File

@ -150,7 +150,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
public String getTag() public String getTag()
{ {
String ret = this.tag; String ret = this.tag;
if (ConfServer.factionTagForceUpperCase) if (UConf.get(this).factionTagForceUpperCase)
{ {
ret = ret.toUpperCase(); ret = ret.toUpperCase();
} }
@ -159,7 +159,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
public void setTag(String str) public void setTag(String str)
{ {
if (ConfServer.factionTagForceUpperCase) if (UConf.get(this).factionTagForceUpperCase)
{ {
str = str.toUpperCase(); str = str.toUpperCase();
} }
@ -302,7 +302,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
public boolean isOpen() public boolean isOpen()
{ {
Boolean ret = this.open; Boolean ret = this.open;
if (ret == null) ret = ConfServer.newFactionsDefaultOpen; if (ret == null) ret = UConf.get(this).newFactionsDefaultOpen;
return ret; return ret;
} }
@ -472,7 +472,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
for (FFlag fflag : FFlag.values()) for (FFlag fflag : FFlag.values())
{ {
ret.put(fflag, fflag.getDefault()); ret.put(fflag, fflag.getDefault(this));
} }
if (this.flagOverrides != null) if (this.flagOverrides != null)
@ -499,7 +499,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
while (iter.hasNext()) while (iter.hasNext())
{ {
Entry<FFlag, Boolean> entry = iter.next(); Entry<FFlag, Boolean> entry = iter.next();
if (entry.getKey().getDefault() == entry.getValue()) if (entry.getKey().getDefault(this) == entry.getValue())
{ {
iter.remove(); iter.remove();
} }
@ -541,7 +541,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
for (FPerm fperm : FPerm.values()) for (FPerm fperm : FPerm.values())
{ {
ret.put(fperm, fperm.getDefault()); ret.put(fperm, fperm.getDefault(this));
} }
if (this.permOverrides != null) if (this.permOverrides != null)
@ -571,7 +571,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
while (iter.hasNext()) while (iter.hasNext())
{ {
Entry<FPerm, Set<Rel>> entry = iter.next(); Entry<FPerm, Set<Rel>> entry = iter.next();
if (entry.getKey().getDefault().equals(entry.getValue())) if (entry.getKey().getDefault(this).equals(entry.getValue()))
{ {
iter.remove(); iter.remove();
} }

View File

@ -124,18 +124,18 @@ public class FactionColl extends Coll<Faction>
// FACTION TAG // FACTION TAG
// -------------------------------------------- // // -------------------------------------------- //
public static ArrayList<String> validateTag(String str) public ArrayList<String> validateTag(String str)
{ {
ArrayList<String> errors = new ArrayList<String>(); ArrayList<String> errors = new ArrayList<String>();
if(MiscUtil.getComparisonString(str).length() < ConfServer.factionTagLengthMin) if (MiscUtil.getComparisonString(str).length() < UConf.get(this).factionTagLengthMin)
{ {
errors.add(Txt.parse("<i>The faction tag can't be shorter than <h>%s<i> chars.", ConfServer.factionTagLengthMin)); errors.add(Txt.parse("<i>The faction tag can't be shorter than <h>%s<i> chars.", UConf.get(this).factionTagLengthMin));
} }
if(str.length() > ConfServer.factionTagLengthMax) if (str.length() > UConf.get(this).factionTagLengthMax)
{ {
errors.add(Txt.parse("<i>The faction tag can't be longer than <h>%s<i> chars.", ConfServer.factionTagLengthMax)); errors.add(Txt.parse("<i>The faction tag can't be longer than <h>%s<i> chars.", UConf.get(this).factionTagLengthMax));
} }
for (char c : str.toCharArray()) for (char c : str.toCharArray())

View File

@ -1,5 +1,12 @@
package com.massivecraft.factions.entity; package com.massivecraft.factions.entity;
import java.util.Map;
import java.util.Set;
import com.massivecraft.factions.Const;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Rel;
import com.massivecraft.mcore.store.Entity; import com.massivecraft.mcore.store.Entity;
public class UConf extends Entity<UConf> public class UConf extends Entity<UConf>
@ -8,15 +15,29 @@ public class UConf extends Entity<UConf>
// META // META
// -------------------------------------------- // // -------------------------------------------- //
public static UConf get(Object worldNameExtractable) public static UConf get(Object oid)
{ {
return UConfColls.get().get2(worldNameExtractable); return UConfColls.get().get2(oid);
} }
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // CORE
// -------------------------------------------- // // -------------------------------------------- //
public Map<FFlag, Boolean> factionFlagDefaults = FFlag.getDefaultDefaults();
public Map<FPerm, Set<Rel>> factionPermDefaults = FPerm.getDefaultDefaults();
public String playerDefaultFactionId = Const.FACTIONID_NONE;
public Rel playerDefaultRole = Rel.RECRUIT;
public boolean canLeaveWithNegativePower = true;
public int factionTagLengthMin = 3;
public int factionTagLengthMax = 10;
public boolean factionTagForceUpperCase = false;
public boolean newFactionsDefaultOpen = false;
public int factionMemberLimit = 0;
} }