Make f powerboost commands more granular close #16
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
package com.massivecraft.factions;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.massivecore.Identified;
 | 
			
		||||
import com.massivecraft.massivecore.MassiveException;
 | 
			
		||||
import com.massivecraft.massivecore.util.PermissionUtil;
 | 
			
		||||
import org.bukkit.permissions.Permissible;
 | 
			
		||||
 | 
			
		||||
@@ -65,5 +66,10 @@ public enum Perm implements Identified
 | 
			
		||||
	{
 | 
			
		||||
		return PermissionUtil.hasPermission(permissible, this);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void hasOrThrow(Permissible permissible) throws MassiveException
 | 
			
		||||
	{
 | 
			
		||||
		PermissionUtil.hasPermissionOrThrow(permissible, this);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -58,7 +58,7 @@ public class CmdFactions extends FactionsCommand
 | 
			
		||||
	public CmdFactionsUnstuck cmdFactionsUnstuck = new CmdFactionsUnstuck();
 | 
			
		||||
	public CmdFactionsOverride cmdFactionsOverride = new CmdFactionsOverride();
 | 
			
		||||
	public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband();
 | 
			
		||||
	public CmdFactionsPowerBoost cmdFactionsPowerBoost = new CmdFactionsPowerBoost();
 | 
			
		||||
	public CmdFactionsPowerboost cmdFactionsPowerBoost = new CmdFactionsPowerboost();
 | 
			
		||||
	public CmdFactionsSetpower cmdFactionsSetpower = new CmdFactionsSetpower();
 | 
			
		||||
	public CmdFactionsMoneyconvert cmdFactionsMoneyconvert = new CmdFactionsMoneyconvert();
 | 
			
		||||
	public CmdFactionsConfig cmdFactionsConfig = new CmdFactionsConfig();
 | 
			
		||||
 
 | 
			
		||||
@@ -1,19 +1,19 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsPowerBoost extends FactionsCommand
 | 
			
		||||
public class CmdFactionsPowerboost extends FactionsCommand
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// FIELDS
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	
 | 
			
		||||
	public CmdFactionsPowerBoostPlayer cmdFactionsPowerBoostPlayer = new CmdFactionsPowerBoostPlayer();
 | 
			
		||||
	public CmdFactionsPowerBoostFaction cmdFactionsPowerBoostFaction = new CmdFactionsPowerBoostFaction();
 | 
			
		||||
	public CmdFactionsPowerboostPlayer cmdFactionsPowerBoostPlayer = new CmdFactionsPowerboostPlayer();
 | 
			
		||||
	public CmdFactionsPowerboostFaction cmdFactionsPowerBoostFaction = new CmdFactionsPowerboostFaction();
 | 
			
		||||
	
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// CONSTRUCT
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	
 | 
			
		||||
	public CmdFactionsPowerBoost()
 | 
			
		||||
	public CmdFactionsPowerboost()
 | 
			
		||||
	{
 | 
			
		||||
		// Child
 | 
			
		||||
		this.addChild(this.cmdFactionsPowerBoostPlayer);
 | 
			
		||||
@@ -2,26 +2,33 @@ package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.factions.Factions;
 | 
			
		||||
import com.massivecraft.factions.FactionsParticipator;
 | 
			
		||||
import com.massivecraft.factions.Perm;
 | 
			
		||||
import com.massivecraft.massivecore.MassiveException;
 | 
			
		||||
import com.massivecraft.massivecore.command.type.Type;
 | 
			
		||||
import com.massivecraft.massivecore.command.type.TypeNullable;
 | 
			
		||||
import com.massivecraft.massivecore.command.type.primitive.TypeDouble;
 | 
			
		||||
import com.massivecraft.massivecore.util.Txt;
 | 
			
		||||
 | 
			
		||||
public abstract class CmdFactionsPowerBoostAbstract extends FactionsCommand
 | 
			
		||||
public abstract class CmdFactionsPowerboostAbstract extends FactionsCommand
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// CONSTRUCT
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	
 | 
			
		||||
	protected CmdFactionsPowerBoostAbstract(Type<? extends FactionsParticipator> parameterType, String parameterName)
 | 
			
		||||
	protected CmdFactionsPowerboostAbstract(Type<? extends FactionsParticipator> parameterType, String parameterName)
 | 
			
		||||
	{
 | 
			
		||||
		// Parameters
 | 
			
		||||
		this.addParameter(parameterType, parameterName);
 | 
			
		||||
		this.addParameter(TypeNullable.get(TypeDouble.get()), "amount", "show");
 | 
			
		||||
		if (!this.getClass().getSimpleName().contains("Show"))
 | 
			
		||||
		{
 | 
			
		||||
			this.addParameter(TypeDouble.get(), "amount");
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// ABSTRACT
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	public abstract double calcNewPowerboost(double current, double d);
 | 
			
		||||
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// OVERRIDE
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
@@ -31,35 +38,32 @@ public abstract class CmdFactionsPowerBoostAbstract extends FactionsCommand
 | 
			
		||||
	{
 | 
			
		||||
		// Parameters
 | 
			
		||||
		FactionsParticipator factionsParticipator = this.readArg();
 | 
			
		||||
		Double powerBoost = this.readArg(factionsParticipator.getPowerBoost());
 | 
			
		||||
		
 | 
			
		||||
 | 
			
		||||
		boolean updated = false;
 | 
			
		||||
		// Try set the powerBoost
 | 
			
		||||
		boolean updated = this.trySet(factionsParticipator, powerBoost);
 | 
			
		||||
		if (this.argIsSet(1))
 | 
			
		||||
		{
 | 
			
		||||
			// Yes updated
 | 
			
		||||
			updated = true;
 | 
			
		||||
 | 
			
		||||
			// Calc powerboost
 | 
			
		||||
			double current = factionsParticipator.getPowerBoost();
 | 
			
		||||
			double number = this.readArg();
 | 
			
		||||
			double powerBoost = this.calcNewPowerboost(current, number);
 | 
			
		||||
 | 
			
		||||
			// Set
 | 
			
		||||
			factionsParticipator.setPowerBoost(powerBoost);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// Inform
 | 
			
		||||
		this.informPowerBoost(factionsParticipator, powerBoost, updated);
 | 
			
		||||
		this.informPowerBoost(factionsParticipator, updated);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private boolean trySet(FactionsParticipator factionsParticipator, Double powerBoost) throws MassiveException
 | 
			
		||||
	{
 | 
			
		||||
		// Trying to set?
 | 
			
		||||
		if (!this.argIsSet(1)) return false;
 | 
			
		||||
		
 | 
			
		||||
		// Check set permissions
 | 
			
		||||
		if (!Perm.POWERBOOST_SET.has(sender, true)) throw new MassiveException();
 | 
			
		||||
		
 | 
			
		||||
		// Set
 | 
			
		||||
		factionsParticipator.setPowerBoost(powerBoost);
 | 
			
		||||
		
 | 
			
		||||
		// Return
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private void informPowerBoost(FactionsParticipator factionsParticipator, Double powerBoost, boolean updated)
 | 
			
		||||
 | 
			
		||||
	private void informPowerBoost(FactionsParticipator factionsParticipator, boolean updated)
 | 
			
		||||
	{
 | 
			
		||||
		// Prepare
 | 
			
		||||
		Double powerBoost = factionsParticipator.getPowerBoost();
 | 
			
		||||
		String participatorDescribe = factionsParticipator.describeTo(msender, true);
 | 
			
		||||
		powerBoost = powerBoost == null ? factionsParticipator.getPowerBoost() : powerBoost;
 | 
			
		||||
		String powerDescription = Txt.parse(Double.compare(powerBoost, 0D) >= 0 ? "<g>bonus" : "<b>penalty");
 | 
			
		||||
		String when = updated ? "now " : "";
 | 
			
		||||
		String verb = factionsParticipator.equals(msender) ? "have" : "has";
 | 
			
		||||
@@ -0,0 +1,15 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsPowerboostFaction extends FactionsCommand
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// FIELDS
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	public CmdFactionsPowerboostFactionShow cmdFactionsPowerBoostFactionShow = new CmdFactionsPowerboostFactionShow();
 | 
			
		||||
	public CmdFactionsPowerboostFactionSet cmdFactionsPowerBoostFactionSet = new CmdFactionsPowerboostFactionSet();
 | 
			
		||||
	public CmdFactionsPowerboostFactionAdd cmdFactionsPowerBoostFactionAdd = new CmdFactionsPowerboostFactionAdd();
 | 
			
		||||
	public CmdFactionsPowerboostFactionTake cmdFactionsPowerBoostFactionTake = new CmdFactionsPowerboostFactionTake();
 | 
			
		||||
	public CmdFactionsPowerboostFactionMultiply cmdFactionsPowerBoostFactionMultiply = new CmdFactionsPowerboostFactionMultiply();
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
@@ -2,15 +2,15 @@ package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.factions.cmd.type.TypeFaction;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsPowerBoostFaction extends CmdFactionsPowerBoostAbstract
 | 
			
		||||
public abstract class CmdFactionsPowerboostFactionAbstract extends CmdFactionsPowerboostAbstract
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// CONSTRUCT
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	
 | 
			
		||||
	public CmdFactionsPowerBoostFaction()
 | 
			
		||||
 | 
			
		||||
	public CmdFactionsPowerboostFactionAbstract()
 | 
			
		||||
	{
 | 
			
		||||
		super(TypeFaction.get(), "faction");
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,15 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsPowerboostFactionAdd extends CmdFactionsPowerboostFactionAbstract
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// OVERRIDE
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public double calcNewPowerboost(double current, double d)
 | 
			
		||||
	{
 | 
			
		||||
		return current + d;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,15 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsPowerboostFactionMultiply extends CmdFactionsPowerboostFactionAbstract
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// OVERRIDE
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public double calcNewPowerboost(double current, double d)
 | 
			
		||||
	{
 | 
			
		||||
		return current * d;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,15 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsPowerboostFactionSet extends CmdFactionsPowerboostFactionAbstract
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// OVERRIDE
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public double calcNewPowerboost(double current, double d)
 | 
			
		||||
	{
 | 
			
		||||
		return d;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,15 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsPowerboostFactionShow extends CmdFactionsPowerboostFactionAbstract
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// OVERRIDE
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public double calcNewPowerboost(double current, double d)
 | 
			
		||||
	{
 | 
			
		||||
		throw new UnsupportedOperationException();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,15 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsPowerboostFactionTake extends CmdFactionsPowerboostFactionAbstract
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// OVERRIDE
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public double calcNewPowerboost(double current, double d)
 | 
			
		||||
	{
 | 
			
		||||
		return current - d;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,15 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsPowerboostPlayer extends FactionsCommand
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// FIELDS
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	public CmdFactionsPowerboostPlayerShow cmdFactionsPowerBoostPlayerShow = new CmdFactionsPowerboostPlayerShow();
 | 
			
		||||
	public CmdFactionsPowerboostPlayerSet cmdFactionsPowerBoostPlayerSet = new CmdFactionsPowerboostPlayerSet();
 | 
			
		||||
	public CmdFactionsPowerboostPlayerAdd cmdFactionsPowerBoostPlayerAdd = new CmdFactionsPowerboostPlayerAdd();
 | 
			
		||||
	public CmdFactionsPowerboostPlayerTake cmdFactionsPowerBoostPlayerTake = new CmdFactionsPowerboostPlayerTake();
 | 
			
		||||
	public CmdFactionsPowerboostPlayerMultiply cmdFactionsPowerBoostPlayerMultiply = new CmdFactionsPowerboostPlayerMultiply();
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
@@ -2,15 +2,15 @@ package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.factions.cmd.type.TypeMPlayer;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsPowerBoostPlayer extends CmdFactionsPowerBoostAbstract
 | 
			
		||||
public abstract class CmdFactionsPowerboostPlayerAbstract extends CmdFactionsPowerboostAbstract
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// CONSTRUCT
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	
 | 
			
		||||
	public CmdFactionsPowerBoostPlayer()
 | 
			
		||||
 | 
			
		||||
	public CmdFactionsPowerboostPlayerAbstract()
 | 
			
		||||
	{
 | 
			
		||||
		super(TypeMPlayer.get(), "player");
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,15 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsPowerboostPlayerAdd extends CmdFactionsPowerboostPlayerAbstract
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// OVERRIDE
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public double calcNewPowerboost(double current, double d)
 | 
			
		||||
	{
 | 
			
		||||
		return current + d;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,15 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsPowerboostPlayerMultiply extends CmdFactionsPowerboostPlayerAbstract
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// OVERRIDE
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public double calcNewPowerboost(double current, double d)
 | 
			
		||||
	{
 | 
			
		||||
		return current * d;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,15 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsPowerboostPlayerSet extends CmdFactionsPowerboostPlayerAbstract
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// OVERRIDE
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public double calcNewPowerboost(double current, double d)
 | 
			
		||||
	{
 | 
			
		||||
		return d;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,15 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsPowerboostPlayerShow extends CmdFactionsPowerboostPlayerAbstract
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// OVERRIDE
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public double calcNewPowerboost(double current, double d)
 | 
			
		||||
	{
 | 
			
		||||
		throw new UnsupportedOperationException();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,15 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsPowerboostPlayerTake extends CmdFactionsPowerboostPlayerAbstract
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// OVERRIDE
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public double calcNewPowerboost(double current, double d)
 | 
			
		||||
	{
 | 
			
		||||
		return current - d;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user