diff --git a/src/com/massivecraft/factions/ConfServer.java b/src/com/massivecraft/factions/ConfServer.java index 1512ffb0..1ac9b42f 100644 --- a/src/com/massivecraft/factions/ConfServer.java +++ b/src/com/massivecraft/factions/ConfServer.java @@ -22,35 +22,6 @@ public class ConfServer extends SimpleConfig public static List baseCommandAliases = MUtil.list("f"); public static String dburi = "default"; - // -------------------------------------------- // - // DOUBTFULLY CONFIGURABLE DEFAULTS (TODO) - // -------------------------------------------- // - - public static Map factionFlagDefaults = FFlag.getDefaultDefaults(); - public static Map> 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 // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/FFlag.java b/src/com/massivecraft/factions/FFlag.java index 0d1c0241..3c50ed87 100644 --- a/src/com/massivecraft/factions/FFlag.java +++ b/src/com/massivecraft/factions/FFlag.java @@ -3,6 +3,8 @@ package com.massivecraft.factions; import java.util.LinkedHashMap; import java.util.Map; +import com.massivecraft.factions.entity.UConf; + /** * Flags that describe the nature of a faction and it's territory. @@ -64,9 +66,9 @@ public enum FFlag // 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(); return ret; } diff --git a/src/com/massivecraft/factions/FPerm.java b/src/com/massivecraft/factions/FPerm.java index 3a49de83..54d5f954 100644 --- a/src/com/massivecraft/factions/FPerm.java +++ b/src/com/massivecraft/factions/FPerm.java @@ -13,6 +13,7 @@ import org.bukkit.command.CommandSender; import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.FPlayer; import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.UConf; import com.massivecraft.mcore.ps.PS; /** @@ -77,9 +78,9 @@ public enum FPerm // DEFAULTS // -------------------------------------------- // - public Set getDefault() + public Set getDefault(Object o) { - Set ret = ConfServer.factionPermDefaults.get(this); + Set ret = UConf.get(o).factionPermDefaults.get(this); if (ret == null) return this.getDefaultDefault(); ret = new LinkedHashSet(ret); return ret; diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java index c0e0c419..2fdb2f28 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java @@ -48,7 +48,7 @@ public class CmdFactionsCreate extends FCommand return; } - ArrayList tagValidationErrors = FactionColl.validateTag(newTag); + ArrayList tagValidationErrors = coll.validateTag(newTag); if (tagValidationErrors.size() > 0) { sendMessage(tagValidationErrors); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java index 25dc5ea1..e01f0908 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java @@ -1,6 +1,5 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; 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.Faction; import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.UConf; import com.massivecraft.factions.event.FactionsEventMembershipChange; import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason; import com.massivecraft.mcore.cmd.req.ReqHasPerm; @@ -49,9 +49,9 @@ public class CmdFactionsJoin extends FCommand return; } - if (ConfServer.factionMemberLimit > 0 && faction.getFPlayers().size() >= ConfServer.factionMemberLimit) + if (UConf.get(faction).factionMemberLimit > 0 && faction.getFPlayers().size() >= UConf.get(faction).factionMemberLimit) { - msg(" ! 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(" ! 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; } @@ -61,7 +61,7 @@ public class CmdFactionsJoin extends FCommand return; } - if (!ConfServer.canLeaveWithNegativePower && fplayer.getPower() < 0) + if (!UConf.get(faction).canLeaveWithNegativePower && fplayer.getPower() < 0) { msg("%s cannot join a faction with a negative power level.", fplayer.describeTo(fme, true)); return; @@ -93,7 +93,6 @@ public class CmdFactionsJoin extends FCommand // Apply fplayer.resetFactionData(); 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); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsKick.java b/src/com/massivecraft/factions/cmd/CmdFactionsKick.java index 61c577dc..77a96130 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsKick.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsKick.java @@ -1,6 +1,5 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; 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.FactionColls; import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.UConf; import com.massivecraft.factions.event.FactionsEventMembershipChange; import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason; import com.massivecraft.mcore.cmd.req.ReqHasPerm; @@ -47,7 +47,7 @@ public class CmdFactionsKick extends FCommand return; } - if ( ! ConfServer.canLeaveWithNegativePower && fplayer.getPower() < 0) + if ( ! UConf.get(fplayer).canLeaveWithNegativePower && fplayer.getPower() < 0) { msg("You cannot kick that member until their power is positive."); return; diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java b/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java index 4cdab8f4..2fca529f 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java @@ -67,7 +67,7 @@ public class CmdFactionsPerm extends FCommand 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. - 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); } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTag.java b/src/com/massivecraft/factions/cmd/CmdFactionsTag.java index 38de86a1..8be0604f 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTag.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsTag.java @@ -34,14 +34,16 @@ public class CmdFactionsTag extends FCommand String newTag = this.arg(0); // 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("That tag is already taken"); return; } ArrayList errors = new ArrayList(); - errors.addAll(FactionColl.validateTag(newTag)); + errors.addAll(factionColl.validateTag(newTag)); if (errors.size() > 0) { sendMessage(errors); diff --git a/src/com/massivecraft/factions/entity/FPlayer.java b/src/com/massivecraft/factions/entity/FPlayer.java index edbb4b1e..9f3fcf00 100644 --- a/src/com/massivecraft/factions/entity/FPlayer.java +++ b/src/com/massivecraft/factions/entity/FPlayer.java @@ -110,11 +110,11 @@ public class FPlayer extends SenderEntity 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 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 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 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 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 implements EconomyParticipato return; } - if (!ConfServer.canLeaveWithNegativePower && this.getPower() < 0) + if (!UConf.get(myFaction).canLeaveWithNegativePower && this.getPower() < 0) { msg("You cannot leave until your power is positive."); return; diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 41b089ad..99f25574 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -150,7 +150,7 @@ public class Faction extends Entity 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 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 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 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 implements EconomyParticipator while (iter.hasNext()) { Entry 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 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 implements EconomyParticipator while (iter.hasNext()) { Entry> entry = iter.next(); - if (entry.getKey().getDefault().equals(entry.getValue())) + if (entry.getKey().getDefault(this).equals(entry.getValue())) { iter.remove(); } diff --git a/src/com/massivecraft/factions/entity/FactionColl.java b/src/com/massivecraft/factions/entity/FactionColl.java index 5ddb84c3..7c164ec3 100644 --- a/src/com/massivecraft/factions/entity/FactionColl.java +++ b/src/com/massivecraft/factions/entity/FactionColl.java @@ -124,18 +124,18 @@ public class FactionColl extends Coll // FACTION TAG // -------------------------------------------- // - public static ArrayList validateTag(String str) + public ArrayList validateTag(String str) { ArrayList errors = new ArrayList(); - if(MiscUtil.getComparisonString(str).length() < ConfServer.factionTagLengthMin) + if (MiscUtil.getComparisonString(str).length() < UConf.get(this).factionTagLengthMin) { - errors.add(Txt.parse("The faction tag can't be shorter than %s chars.", ConfServer.factionTagLengthMin)); + errors.add(Txt.parse("The faction tag can't be shorter than %s chars.", UConf.get(this).factionTagLengthMin)); } - if(str.length() > ConfServer.factionTagLengthMax) + if (str.length() > UConf.get(this).factionTagLengthMax) { - errors.add(Txt.parse("The faction tag can't be longer than %s chars.", ConfServer.factionTagLengthMax)); + errors.add(Txt.parse("The faction tag can't be longer than %s chars.", UConf.get(this).factionTagLengthMax)); } for (char c : str.toCharArray()) diff --git a/src/com/massivecraft/factions/entity/UConf.java b/src/com/massivecraft/factions/entity/UConf.java index 224fbac3..47c19e99 100644 --- a/src/com/massivecraft/factions/entity/UConf.java +++ b/src/com/massivecraft/factions/entity/UConf.java @@ -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 @@ -8,15 +15,29 @@ public class UConf extends Entity // 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 factionFlagDefaults = FFlag.getDefaultDefaults(); + public Map> factionPermDefaults = FPerm.getDefaultDefaults(); + public String playerDefaultFactionId = Const.FACTIONID_NONE; + public Rel playerDefaultRole = Rel.RECRUIT; -} \ No newline at end of file + public boolean canLeaveWithNegativePower = true; + + public int factionTagLengthMin = 3; + public int factionTagLengthMax = 10; + public boolean factionTagForceUpperCase = false; + + public boolean newFactionsDefaultOpen = false; + + public int factionMemberLimit = 0; + +}