Implement interface Powerboosted.
This commit is contained in:
@@ -1,23 +1,13 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.cmd.type.TypeMPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.Parameter;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeDouble;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeString;
|
||||
|
||||
public class CmdFactionsPowerBoost extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private Parameter<MPlayer> parameterMplayer = new Parameter<MPlayer>(TypeMPlayer.get(), "name");
|
||||
private Parameter<Faction> parameterFaction = new Parameter<Faction>(TypeFaction.get(), "name");
|
||||
public CmdFactionsPowerBoostPlayer cmdFactionsPowerBoostPlayer = new CmdFactionsPowerBoostPlayer();
|
||||
public CmdFactionsPowerBoostFaction cmdFactionsPowerBoostFaction = new CmdFactionsPowerBoostFaction();
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
@@ -25,55 +15,9 @@ public class CmdFactionsPowerBoost extends FactionsCommand
|
||||
|
||||
public CmdFactionsPowerBoost()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeString.get(), "p|f|player|faction");
|
||||
this.addParameter(parameterMplayer);
|
||||
this.addParameter(TypeDouble.get(), "#");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
String type = this.<String>readArg().toLowerCase();
|
||||
boolean doPlayer = true;
|
||||
if (type.equals("f") || type.equals("faction"))
|
||||
{
|
||||
doPlayer = false;
|
||||
}
|
||||
else if (!type.equals("p") && !type.equals("player"))
|
||||
{
|
||||
msg("<b>You must specify \"p\" or \"player\" to target a player or \"f\" or \"faction\" to target a faction.");
|
||||
msg("<b>ex. /f powerboost p SomePlayer 0.5 -or- /f powerboost f SomeFaction -5");
|
||||
return;
|
||||
}
|
||||
|
||||
double targetPower = this.readArgAt(2);
|
||||
|
||||
String target;
|
||||
|
||||
if (doPlayer)
|
||||
{
|
||||
this.getParameters().set(1, parameterMplayer);
|
||||
MPlayer targetPlayer = this.readArgAt(1);
|
||||
|
||||
targetPlayer.setPowerBoost(targetPower);
|
||||
target = "Player \""+targetPlayer.getName()+"\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getParameters().set(1, parameterFaction);
|
||||
Faction targetFaction = this.readArgAt(1);
|
||||
|
||||
targetFaction.setPowerBoost(targetPower);
|
||||
target = "Faction \""+targetFaction.getName()+"\"";
|
||||
}
|
||||
|
||||
msg("<i>"+target+" now has a power bonus/penalty of "+targetPower+" to min and max power levels.");
|
||||
Factions.get().log(msender.getName()+" has set the power bonus/penalty for "+target+" to "+targetPower+".");
|
||||
// Child
|
||||
this.addChild(this.cmdFactionsPowerBoostPlayer);
|
||||
this.addChild(this.cmdFactionsPowerBoostFaction);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,76 @@
|
||||
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
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
protected CmdFactionsPowerBoostAbstract(Type<? extends FactionsParticipator> parameterType, String parameterName)
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(parameterType, parameterName);
|
||||
this.addParameter(TypeNullable.get(TypeDouble.get()), "amount", "show");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Parameters
|
||||
FactionsParticipator factionsParticipator = this.readArg();
|
||||
Double powerBoost = this.readArg(factionsParticipator.getPowerBoost());
|
||||
|
||||
// Try set the powerBoost
|
||||
boolean updated = this.trySet(factionsParticipator, powerBoost);
|
||||
|
||||
// Inform
|
||||
this.informPowerBoost(factionsParticipator, powerBoost, 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)
|
||||
{
|
||||
// Prepare
|
||||
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";
|
||||
|
||||
// Create message
|
||||
String messagePlayer = Txt.parse("<i>%s<i> %s%s a power %s<i> of <h>%.2f<i> to min and max power levels.", participatorDescribe, when, verb, powerDescription, powerBoost);
|
||||
String messageLog = Txt.parse("%s %s set the power %s<i> for %s<i> to <h>%.2f<i>.", msender.getName(), verb, powerDescription, factionsParticipator.getName(), powerBoost);
|
||||
|
||||
// Inform
|
||||
msender.message(messagePlayer);
|
||||
if (updated) Factions.get().log(messageLog);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
|
||||
public class CmdFactionsPowerBoostFaction extends CmdFactionsPowerBoostAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsPowerBoostFaction()
|
||||
{
|
||||
super(TypeFaction.get(), "faction");
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.cmd.type.TypeMPlayer;
|
||||
|
||||
public class CmdFactionsPowerBoostPlayer extends CmdFactionsPowerBoostAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsPowerBoostPlayer()
|
||||
{
|
||||
super(TypeMPlayer.get(), "player");
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user