Messing arund a bit with defaults

This commit is contained in:
Olof Larsson 2013-04-23 14:00:18 +02:00
parent f8c3c6a911
commit f802307056
8 changed files with 62 additions and 67 deletions

View File

@ -68,7 +68,7 @@ public enum FFlag
public boolean getDefault(Object o) 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(); if (ret == null) return this.getDefaultDefault();
return ret; return ret;
} }

View File

@ -80,7 +80,7 @@ public enum FPerm
public Set<Rel> getDefault(Object o) public Set<Rel> getDefault(Object o)
{ {
Set<Rel> ret = UConf.get(o).factionPermDefaults.get(this); Set<Rel> ret = UConf.get(o).defaultFactionPerms.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

@ -1,6 +1,7 @@
package com.massivecraft.factions.chat.tag; package com.massivecraft.factions.chat.tag;
import com.massivecraft.factions.chat.ChatTagAbstract; import com.massivecraft.factions.chat.ChatTagAbstract;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.UPlayer; import com.massivecraft.factions.entity.UPlayer;
public class ChatTagTag extends ChatTagAbstract public class ChatTagTag extends ChatTagAbstract
@ -19,9 +20,10 @@ public class ChatTagTag extends ChatTagAbstract
@Override @Override
public String getReplacement(UPlayer fsender, UPlayer frecipient) public String getReplacement(UPlayer fsender, UPlayer frecipient)
{ {
if (!fsender.hasFaction()) return ""; Faction faction = fsender.getFaction();
return fsender.getFaction().getTag(); if (faction.isNone()) return "";
return faction.getTag();
} }
} }

View File

@ -34,7 +34,7 @@ public class CmdFactionsCreate extends FCommand
String newTag = this.arg(0); String newTag = this.arg(0);
// Verify // Verify
if (fme.hasFaction()) if (fme.getFaction().isNormal())
{ {
msg("<b>You must leave your current faction first."); msg("<b>You must leave your current faction first.");
return; return;

View File

@ -33,6 +33,7 @@ public class CmdFactionsJoin extends FCommand
UPlayer uplayer = this.arg(1, ARUPlayer.getStartAny(sender), fme); UPlayer uplayer = this.arg(1, ARUPlayer.getStartAny(sender), fme);
if (uplayer == null) return; if (uplayer == null) return;
Faction uplayerFaction = uplayer.getFaction();
boolean samePlayer = uplayer == fme; boolean samePlayer = uplayer == fme;
@ -43,7 +44,7 @@ public class CmdFactionsJoin extends FCommand
return; return;
} }
if (faction == uplayer.getFaction()) if (faction == uplayerFaction)
{ {
msg("<b>%s %s already a member of %s", uplayer.describeTo(fme, true), (samePlayer ? "are" : "is"), faction.getTag(fme)); msg("<b>%s %s already a member of %s", uplayer.describeTo(fme, true), (samePlayer ? "are" : "is"), faction.getTag(fme));
return; return;
@ -55,7 +56,7 @@ public class CmdFactionsJoin extends FCommand
return; return;
} }
if (uplayer.hasFaction()) if (uplayerFaction.isNormal())
{ {
msg("<b>%s must leave %s current faction first.", uplayer.describeTo(fme, true), (samePlayer ? "your" : "their")); msg("<b>%s must leave %s current faction first.", uplayer.describeTo(fme, true), (samePlayer ? "your" : "their"));
return; return;

View File

@ -269,24 +269,25 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
this.changed(); this.changed();
} }
public boolean hasPowerBoost()
{
return this.getPowerBoost() != 0D;
}
// -------------------------------------------- // // -------------------------------------------- //
// FIELD: open // FIELD: open
// -------------------------------------------- // // -------------------------------------------- //
public boolean isDefaultOpen()
{
return UConf.get(this).defaultFactionOpen;
}
public boolean isOpen() public boolean isOpen()
{ {
Boolean ret = this.open; Boolean ret = this.open;
if (ret == null) ret = UConf.get(this).newFactionsDefaultOpen; if (ret == null) ret = this.isDefaultOpen();
return ret; return ret;
} }
public void setOpen(Boolean open) public void setOpen(Boolean open)
{ {
if (open == null || MUtil.equals(open, this.isDefaultOpen())) open = null;
this.open = open; this.open = open;
this.changed(); this.changed();
} }
@ -664,7 +665,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
public double getPowerMax() public double getPowerMax()
{ {
if (this.getFlag(FFlag.INFPOWER)) return 999999; if (this.getFlag(FFlag.INFPOWER)) return 999999;
return UConf.get(this).powerFactionMax + this.getPowerBoost(); return UConf.get(this).factionPowerMax + this.getPowerBoost();
} }
public int getPowerRounded() public int getPowerRounded()

View File

@ -27,31 +27,29 @@ public class UConf extends Entity<UConf>
// CORE // 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 boolean canLeaveWithNegativePower = true;
public int factionMemberLimit = 0;
public double factionPowerMax = 1000.0;
public int factionTagLengthMin = 3; public int factionTagLengthMin = 3;
public int factionTagLengthMax = 10; public int factionTagLengthMax = 10;
public boolean factionTagForceUpperCase = false; 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<FFlag, Boolean> defaultFactionFlags = FFlag.getDefaultDefaults();
public Map<FPerm, Set<Rel>> defaultFactionPerms = FPerm.getDefaultDefaults();
// -------------------------------------------- // // -------------------------------------------- //
// DENY COMMANDS // DENY COMMANDS

View File

@ -26,6 +26,7 @@ import com.massivecraft.mcore.mixin.Mixin;
import com.massivecraft.mcore.money.Money; import com.massivecraft.mcore.money.Money;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.store.SenderEntity; import com.massivecraft.mcore.store.SenderEntity;
import com.massivecraft.mcore.util.MUtil;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.Txt;
@ -58,13 +59,10 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
@Override @Override
public boolean isDefault() public boolean isDefault()
{ {
// TODO: What if I incorporated the "default" word into the system?
// Rename?: hasFaction --> isFactionDefault
if (this.hasFaction()) return false; if (this.hasFaction()) return false;
// Role means nothing without a faction. // Role means nothing without a faction.
// Title 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; return true;
} }
@ -174,10 +172,15 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
// FIELD: factionId // FIELD: factionId
// -------------------------------------------- // // -------------------------------------------- //
public String getDefaultFactionId()
{
return UConf.get(this).defaultPlayerFactionId;
}
// This method never returns null // This method never returns null
public String getFactionId() public String getFactionId()
{ {
if (this.factionId == null) return UConf.get(this).playerDefaultFactionId; if (this.factionId == null) return this.getDefaultFactionId();
return this.factionId; return this.factionId;
} }
@ -185,7 +188,7 @@ public class UPlayer extends SenderEntity<UPlayer> 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(UConf.get(this).playerDefaultFactionId); if (ret == null) ret = FactionColls.get().get(this).get(UConf.get(this).defaultPlayerFactionId);
return ret; return ret;
} }
@ -198,7 +201,7 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
public void setFactionId(String factionId) public void setFactionId(String factionId)
{ {
// Avoid null input // Avoid null input
if (factionId == null) factionId = Const.FACTIONID_NONE; if (factionId == null) factionId = this.getDefaultFactionId();
// Get the old value // Get the old value
String oldFactionId = this.getFactionId(); String oldFactionId = this.getFactionId();
@ -207,14 +210,8 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
if (factionId.equals(oldFactionId)) return; if (factionId.equals(oldFactionId)) return;
// Apply change // Apply change
if (factionId.equals(Const.FACTIONID_NONE)) if (factionId.equals(this.getDefaultFactionId())) factionId = null;
{ this.factionId = factionId;
this.factionId = null;
}
else
{
this.factionId = factionId;
}
// Next we must be attached and inited // Next we must be attached and inited
if (!this.attached()) return; if (!this.attached()) return;
@ -241,22 +238,21 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
// FIELD: role // FIELD: role
// -------------------------------------------- // // -------------------------------------------- //
public Rel getDefaultRole()
{
return UConf.get(this).defaultPlayerRole;
}
public Rel getRole() public Rel getRole()
{ {
if (this.role == null) return UConf.get(this).playerDefaultRole; if (this.role == null) return this.getDefaultRole();
return this.role; return this.role;
} }
public void setRole(Rel role) public void setRole(Rel role)
{ {
if (role == null || role == UConf.get(this).playerDefaultRole) if (role == null || MUtil.equals(role, this.getDefaultRole())) role = null;
{ this.role = role;
this.role = null;
}
else
{
this.role = role;
}
this.changed(); this.changed();
} }
@ -295,23 +291,22 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
// RAW // RAW
public double getDefaultPower()
{
return UConf.get(this).defaultPlayerPower;
}
public double getPower() public double getPower()
{ {
Double ret = this.power; Double ret = this.power;
if (ret == null) ret = UConf.get(this).powerPlayerDefault; if (ret == null) ret = this.getDefaultPower();
return ret; return ret;
} }
public void setPower(Double power) public void setPower(Double power)
{ {
if (power == null || power == UConf.get(this).powerPlayerDefault) if (power == null || MUtil.equals(power, this.getDefaultPower())) power = null;
{ this.power = power;
this.power = null;
}
else
{
this.power = power;
}
this.changed(); this.changed();
} }
@ -333,11 +328,9 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
public String getTag() public String getTag()
{ {
if ( ! this.hasFaction()) Faction faction = this.getFaction();
{ if (faction.isNone()) return "";
return ""; return faction.getTag();
}
return this.getFaction().getTag();
} }
// Base concatenations: // Base concatenations: