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

@@ -110,11 +110,11 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
// 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.
private double power;
private Double power = null;
// This is the timestamp for the last calculation of the power.
// The value is used for the lazy calculation described above.
private long lastPowerUpdateTime;
private long lastPowerUpdateTime = System.currentTimeMillis();
// -------------------------------------------- //
// FIELDS: RAW TRANSIENT
@@ -153,15 +153,11 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
public FPlayer()
{
this.resetFactionData(false);
this.setFactionId(ConfServer.newPlayerStartingFactionID);
this.power = ConfServer.powerStarting;
this.lastPowerUpdateTime = System.currentTimeMillis();
//this.power = ConfServer.powerStarting;
}
public final void resetFactionData(boolean doSpoutUpdate)
public void resetFactionData(boolean doSpoutUpdate)
{
// TODO: Should we not rather use ConfServer.newPlayerStartingFactionID here?
// The default neutral faction
this.setFactionId(null);
this.setRole(null);
@@ -189,7 +185,7 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
// This method never returns null
public String getFactionId()
{
if (this.factionId == null) return Const.FACTIONID_NONE;
if (this.factionId == null) return UConf.get(this).playerDefaultFactionId;
return this.factionId;
}
@@ -197,7 +193,7 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
public Faction getFaction()
{
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;
}
@@ -259,13 +255,13 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
public Rel getRole()
{
if (this.role == null) return Rel.MEMBER;
if (this.role == null) return UConf.get(this).playerDefaultRole;
return this.role;
}
public void setRole(Rel role)
{
if (role == null || role == Rel.MEMBER)
if (role == null || role == UConf.get(this).playerDefaultRole)
{
this.role = null;
}
@@ -662,7 +658,7 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
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.");
return;

View File

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

View File

@@ -124,18 +124,18 @@ public class FactionColl extends Coll<Faction>
// FACTION TAG
// -------------------------------------------- //
public static ArrayList<String> validateTag(String str)
public ArrayList<String> validateTag(String str)
{
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())

View File

@@ -1,5 +1,12 @@
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;
public class UConf extends Entity<UConf>
@@ -8,15 +15,29 @@ public class UConf extends Entity<UConf>
// 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;
}