Make f powerboost commands more granular close #16

This commit is contained in:
Magnus Ulf 2019-02-17 14:30:25 +01:00
parent 32f52c1158
commit b67e02f8e9
19 changed files with 263 additions and 46 deletions

View File

@ -71,9 +71,18 @@ permissions:
factions.perm.viewall: {description: view all perms held by, default: false}
factions.player: {description: show player information}
factions.powerboost: {description: manage powerboost, default: false}
factions.powerboost.faction: {description: show faction powerboost, default: false}
factions.powerboost.player: {description: show player powerboost, default: false}
factions.powerboost.set: {description: set powerboost, default: false}
factions.powerboost.faction: {description: manage faction powerboost, default: false}
factions.powerboost.faction.add: {description: add to faction powerboost, default: false}
factions.powerboost.faction.multiply: {description: multiply faction powerboost, default: false}
factions.powerboost.faction.set: {description: set faction powerboost, default: false}
factions.powerboost.faction.show: {description: show faction powerboost, default: false}
factions.powerboost.faction.take: {description: take faction powerboost, default: false}
factions.powerboost.player: {description: manage player powerboost, default: false}
factions.powerboost.player.add: {description: add to player powerboost, default: false}
factions.powerboost.player.multiply: {description: multiply player powerboost, default: false}
factions.powerboost.player.set: {description: set player powerboost, default: false}
factions.powerboost.player.show: {description: show player powerboost, default: false}
factions.powerboost.player.take: {description: take player powerboost, default: false}
factions.rank: {description: manage/show ranks, default: false}
factions.rank.show: {description: show rank, default: false}
factions.rank.set: {description: set rank, default: false}
@ -185,8 +194,17 @@ permissions:
factions.player: true
factions.powerboost: true
factions.powerboost.faction: true
factions.powerboost.faction.add: true
factions.powerboost.faction.multiply: true
factions.powerboost.faction.set: true
factions.powerboost.faction.show: true
factions.powerboost.faction.take: true
factions.powerboost.player: true
factions.powerboost.set: true
factions.powerboost.player.add: true
factions.powerboost.player.multiply: true
factions.powerboost.player.set: true
factions.powerboost.player.show: true
factions.powerboost.player.take: true
factions.rank: true
factions.rank.show: true
factions.rank.set: true
@ -247,7 +265,14 @@ permissions:
default: false
children:
factions.kit.rank1: true
factions.powerboost.set: true
factions.powerboost.faction.add: true
factions.powerboost.faction.multiply: true
factions.powerboost.faction.set: true
factions.powerboost.faction.take: true
factions.powerboost.player.add: true
factions.powerboost.player.multiply: true
factions.powerboost.player.set: true
factions.powerboost.player.take: true
factions.join.others: true
factions.leader.any: true
factions.officer.any: true
@ -324,7 +349,9 @@ permissions:
factions.promote: true
factions.powerboost: true
factions.powerboost.faction: true
factions.powerboost.faction.show: true
factions.powerboost.player: true
factions.powerboost.player.show: true
factions.rank: true
factions.rank.show: true
factions.rank.set: true

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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);

View File

@ -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";

View File

@ -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();
}

View File

@ -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");
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -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");
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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();
}
}

View File

@ -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;
}
}