Messing arund a bit with defaults
This commit is contained in:
		@@ -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; 
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -80,7 +80,7 @@ public enum FPerm
 | 
			
		||||
	
 | 
			
		||||
	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();
 | 
			
		||||
		ret = new LinkedHashSet<Rel>(ret);
 | 
			
		||||
		return ret;
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -20,8 +21,9 @@ 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();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -34,7 +34,7 @@ public class CmdFactionsCreate extends FCommand
 | 
			
		||||
		String newTag = this.arg(0);
 | 
			
		||||
		
 | 
			
		||||
		// Verify
 | 
			
		||||
		if (fme.hasFaction())
 | 
			
		||||
		if (fme.getFaction().isNormal())
 | 
			
		||||
		{
 | 
			
		||||
			msg("<b>You must leave your current faction first.");
 | 
			
		||||
			return;
 | 
			
		||||
 
 | 
			
		||||
@@ -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("<b>%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("<b>%s must leave %s current faction first.", uplayer.describeTo(fme, true), (samePlayer ? "your" : "their"));
 | 
			
		||||
			return;
 | 
			
		||||
 
 | 
			
		||||
@@ -269,24 +269,25 @@ public class Faction extends Entity<Faction> 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<Faction> 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()
 | 
			
		||||
 
 | 
			
		||||
@@ -27,31 +27,29 @@ public class UConf extends Entity<UConf>
 | 
			
		||||
	// 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 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<FFlag, Boolean> defaultFactionFlags = FFlag.getDefaultDefaults();
 | 
			
		||||
	public Map<FPerm, Set<Rel>> defaultFactionPerms = FPerm.getDefaultDefaults();
 | 
			
		||||
	
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// DENY COMMANDS
 | 
			
		||||
 
 | 
			
		||||
@@ -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<UPlayer> 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<UPlayer> 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<UPlayer> 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<UPlayer> 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<UPlayer> implements EconomyParticipato
 | 
			
		||||
		if (factionId.equals(oldFactionId)) return;
 | 
			
		||||
		
 | 
			
		||||
		// Apply change
 | 
			
		||||
		if (factionId.equals(Const.FACTIONID_NONE))
 | 
			
		||||
		{
 | 
			
		||||
			this.factionId = null;
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
		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<UPlayer> 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
 | 
			
		||||
		{
 | 
			
		||||
		if (role == null || MUtil.equals(role, this.getDefaultRole())) role = null;
 | 
			
		||||
		this.role = role;
 | 
			
		||||
		}
 | 
			
		||||
		this.changed();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
@@ -295,23 +291,22 @@ public class UPlayer extends SenderEntity<UPlayer> 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
 | 
			
		||||
		{
 | 
			
		||||
		if (power == null || MUtil.equals(power, this.getDefaultPower())) power = null;
 | 
			
		||||
		this.power = power;
 | 
			
		||||
		}
 | 
			
		||||
		this.changed();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
@@ -333,11 +328,9 @@ public class UPlayer extends SenderEntity<UPlayer> 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:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user