From f8023070564d9e1edb0738880dad3da61bfe529c Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 23 Apr 2013 14:00:18 +0200 Subject: [PATCH] Messing arund a bit with defaults --- src/com/massivecraft/factions/FFlag.java | 2 +- src/com/massivecraft/factions/FPerm.java | 2 +- .../factions/chat/tag/ChatTagTag.java | 8 ++- .../factions/cmd/CmdFactionsCreate.java | 2 +- .../factions/cmd/CmdFactionsJoin.java | 5 +- .../massivecraft/factions/entity/Faction.java | 15 ++-- .../massivecraft/factions/entity/UConf.java | 26 ++++--- .../massivecraft/factions/entity/UPlayer.java | 69 +++++++++---------- 8 files changed, 62 insertions(+), 67 deletions(-) diff --git a/src/com/massivecraft/factions/FFlag.java b/src/com/massivecraft/factions/FFlag.java index 3c50ed87..79754535 100644 --- a/src/com/massivecraft/factions/FFlag.java +++ b/src/com/massivecraft/factions/FFlag.java @@ -68,7 +68,7 @@ public enum FFlag public boolean getDefault(Object o) { - Boolean ret = UConf.get(o).factionFlagDefaults.get(this); + Boolean ret = UConf.get(o).defaultFactionFlags.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 f2ffecbf..b57a14c0 100644 --- a/src/com/massivecraft/factions/FPerm.java +++ b/src/com/massivecraft/factions/FPerm.java @@ -80,7 +80,7 @@ public enum FPerm public Set getDefault(Object o) { - Set ret = UConf.get(o).factionPermDefaults.get(this); + Set ret = UConf.get(o).defaultFactionPerms.get(this); if (ret == null) return this.getDefaultDefault(); ret = new LinkedHashSet(ret); return ret; diff --git a/src/com/massivecraft/factions/chat/tag/ChatTagTag.java b/src/com/massivecraft/factions/chat/tag/ChatTagTag.java index 233acc54..f473cc44 100644 --- a/src/com/massivecraft/factions/chat/tag/ChatTagTag.java +++ b/src/com/massivecraft/factions/chat/tag/ChatTagTag.java @@ -1,6 +1,7 @@ package com.massivecraft.factions.chat.tag; import com.massivecraft.factions.chat.ChatTagAbstract; +import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.UPlayer; public class ChatTagTag extends ChatTagAbstract @@ -19,9 +20,10 @@ public class ChatTagTag extends ChatTagAbstract @Override public String getReplacement(UPlayer fsender, UPlayer frecipient) - { - if (!fsender.hasFaction()) return ""; - return fsender.getFaction().getTag(); + { + Faction faction = fsender.getFaction(); + if (faction.isNone()) return ""; + return faction.getTag(); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java index bc5b09ad..19f5fc4e 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java @@ -34,7 +34,7 @@ public class CmdFactionsCreate extends FCommand String newTag = this.arg(0); // Verify - if (fme.hasFaction()) + if (fme.getFaction().isNormal()) { msg("You must leave your current faction first."); return; diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java index fa1513ab..f76888f6 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java @@ -33,6 +33,7 @@ public class CmdFactionsJoin extends FCommand UPlayer uplayer = this.arg(1, ARUPlayer.getStartAny(sender), fme); if (uplayer == null) return; + Faction uplayerFaction = uplayer.getFaction(); boolean samePlayer = uplayer == fme; @@ -43,7 +44,7 @@ public class CmdFactionsJoin extends FCommand return; } - if (faction == uplayer.getFaction()) + if (faction == uplayerFaction) { msg("%s %s already a member of %s", uplayer.describeTo(fme, true), (samePlayer ? "are" : "is"), faction.getTag(fme)); return; @@ -55,7 +56,7 @@ public class CmdFactionsJoin extends FCommand return; } - if (uplayer.hasFaction()) + if (uplayerFaction.isNormal()) { msg("%s must leave %s current faction first.", uplayer.describeTo(fme, true), (samePlayer ? "your" : "their")); return; diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 92ad1e21..93c495f9 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -269,24 +269,25 @@ public class Faction extends Entity implements EconomyParticipator this.changed(); } - public boolean hasPowerBoost() - { - return this.getPowerBoost() != 0D; - } - // -------------------------------------------- // // FIELD: open // -------------------------------------------- // + public boolean isDefaultOpen() + { + return UConf.get(this).defaultFactionOpen; + } + public boolean isOpen() { Boolean ret = this.open; - if (ret == null) ret = UConf.get(this).newFactionsDefaultOpen; + if (ret == null) ret = this.isDefaultOpen(); return ret; } public void setOpen(Boolean open) { + if (open == null || MUtil.equals(open, this.isDefaultOpen())) open = null; this.open = open; this.changed(); } @@ -664,7 +665,7 @@ public class Faction extends Entity implements EconomyParticipator public double getPowerMax() { if (this.getFlag(FFlag.INFPOWER)) return 999999; - return UConf.get(this).powerFactionMax + this.getPowerBoost(); + return UConf.get(this).factionPowerMax + this.getPowerBoost(); } public int getPowerRounded() diff --git a/src/com/massivecraft/factions/entity/UConf.java b/src/com/massivecraft/factions/entity/UConf.java index eb668ff9..7f36f606 100644 --- a/src/com/massivecraft/factions/entity/UConf.java +++ b/src/com/massivecraft/factions/entity/UConf.java @@ -27,31 +27,29 @@ public class UConf extends Entity // CORE // -------------------------------------------- // - public Map factionFlagDefaults = FFlag.getDefaultDefaults(); - public Map> factionPermDefaults = FPerm.getDefaultDefaults(); - - public String playerDefaultFactionId = Const.FACTIONID_NONE; - public Rel playerDefaultRole = Rel.RECRUIT; - public boolean canLeaveWithNegativePower = true; + public int factionMemberLimit = 0; + public double factionPowerMax = 1000.0; + public int factionTagLengthMin = 3; public int factionTagLengthMax = 10; public boolean factionTagForceUpperCase = false; - public boolean newFactionsDefaultOpen = false; - - public int factionMemberLimit = 0; - // -------------------------------------------- // - // POWER + // DEFAULTS // -------------------------------------------- // - // TODO: Group default values together? + // TODO: should I add a nofaction id here? + // And perhaps for safezone and warzone as well. - public double powerPlayerDefault = 0.0; + public String defaultPlayerFactionId = Const.FACTIONID_NONE; + public double defaultPlayerPower = 0.0; + public Rel defaultPlayerRole = Rel.RECRUIT; - public double powerFactionMax = 1000.0; + public boolean defaultFactionOpen = false; + public Map defaultFactionFlags = FFlag.getDefaultDefaults(); + public Map> defaultFactionPerms = FPerm.getDefaultDefaults(); // -------------------------------------------- // // DENY COMMANDS diff --git a/src/com/massivecraft/factions/entity/UPlayer.java b/src/com/massivecraft/factions/entity/UPlayer.java index 3a8735c4..283e1620 100644 --- a/src/com/massivecraft/factions/entity/UPlayer.java +++ b/src/com/massivecraft/factions/entity/UPlayer.java @@ -26,6 +26,7 @@ import com.massivecraft.mcore.mixin.Mixin; import com.massivecraft.mcore.money.Money; import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.store.SenderEntity; +import com.massivecraft.mcore.util.MUtil; import com.massivecraft.mcore.util.Txt; @@ -58,13 +59,10 @@ public class UPlayer extends SenderEntity implements EconomyParticipato @Override public boolean isDefault() { - // TODO: What if I incorporated the "default" word into the system? - // Rename?: hasFaction --> isFactionDefault - if (this.hasFaction()) return false; // Role means nothing without a faction. // Title means nothing without a faction. - if (this.getPowerRounded() != (int) Math.round(UConf.get(this).powerPlayerDefault)) return false; + if (this.getPowerRounded() != (int) Math.round(UConf.get(this).defaultPlayerPower)) return false; return true; } @@ -174,10 +172,15 @@ public class UPlayer extends SenderEntity implements EconomyParticipato // FIELD: factionId // -------------------------------------------- // + public String getDefaultFactionId() + { + return UConf.get(this).defaultPlayerFactionId; + } + // This method never returns null public String getFactionId() { - if (this.factionId == null) return UConf.get(this).playerDefaultFactionId; + if (this.factionId == null) return this.getDefaultFactionId(); return this.factionId; } @@ -185,7 +188,7 @@ public class UPlayer 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(UConf.get(this).playerDefaultFactionId); + if (ret == null) ret = FactionColls.get().get(this).get(UConf.get(this).defaultPlayerFactionId); return ret; } @@ -198,7 +201,7 @@ public class UPlayer extends SenderEntity implements EconomyParticipato public void setFactionId(String factionId) { // Avoid null input - if (factionId == null) factionId = Const.FACTIONID_NONE; + if (factionId == null) factionId = this.getDefaultFactionId(); // Get the old value String oldFactionId = this.getFactionId(); @@ -207,14 +210,8 @@ public class UPlayer extends SenderEntity implements EconomyParticipato if (factionId.equals(oldFactionId)) return; // Apply change - if (factionId.equals(Const.FACTIONID_NONE)) - { - this.factionId = null; - } - else - { - this.factionId = factionId; - } + if (factionId.equals(this.getDefaultFactionId())) factionId = null; + this.factionId = factionId; // Next we must be attached and inited if (!this.attached()) return; @@ -241,22 +238,21 @@ public class UPlayer extends SenderEntity implements EconomyParticipato // FIELD: role // -------------------------------------------- // + public Rel getDefaultRole() + { + return UConf.get(this).defaultPlayerRole; + } + public Rel getRole() { - if (this.role == null) return UConf.get(this).playerDefaultRole; + if (this.role == null) return this.getDefaultRole(); return this.role; } public void setRole(Rel role) { - if (role == null || role == UConf.get(this).playerDefaultRole) - { - this.role = null; - } - else - { - this.role = role; - } + if (role == null || MUtil.equals(role, this.getDefaultRole())) role = null; + this.role = role; this.changed(); } @@ -295,23 +291,22 @@ public class UPlayer extends SenderEntity implements EconomyParticipato // RAW + public double getDefaultPower() + { + return UConf.get(this).defaultPlayerPower; + } + public double getPower() { Double ret = this.power; - if (ret == null) ret = UConf.get(this).powerPlayerDefault; + if (ret == null) ret = this.getDefaultPower(); return ret; } public void setPower(Double power) { - if (power == null || power == UConf.get(this).powerPlayerDefault) - { - this.power = null; - } - else - { - this.power = power; - } + if (power == null || MUtil.equals(power, this.getDefaultPower())) power = null; + this.power = power; this.changed(); } @@ -333,11 +328,9 @@ public class UPlayer extends SenderEntity implements EconomyParticipato public String getTag() { - if ( ! this.hasFaction()) - { - return ""; - } - return this.getFaction().getTag(); + Faction faction = this.getFaction(); + if (faction.isNone()) return ""; + return faction.getTag(); } // Base concatenations: