Factions3/src/com/massivecraft/factions/cmd/CmdFactionsPowerBoost.java
2015-05-06 21:44:59 +02:00

87 lines
2.5 KiB
Java

package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARMPlayer;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.cmd.ArgSetting;
import com.massivecraft.massivecore.cmd.arg.ARDouble;
import com.massivecraft.massivecore.cmd.arg.ARString;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
public class CmdFactionsPowerBoost extends FactionsCommand
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private ArgSetting setting = ArgSetting.of(ARMPlayer.getAny(), false, "name", null);
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsPowerBoost()
{
// Aliases
this.addAliases("powerboost");
// Args
this.addArg(ARString.get(), "p|f|player|faction");
this.addArg(setting);
this.addArg(ARDouble.get(), "#");
// Requirements
this.addRequirements(ReqHasPerm.get(Perm.POWERBOOST.node));
}
// -------------------------------------------- //
// 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)
{
setting.setReader(ARMPlayer.getAny());
MPlayer targetPlayer = this.readArgAt(1);
targetPlayer.setPowerBoost(targetPower);
target = "Player \""+targetPlayer.getName()+"\"";
}
else
{
setting.setReader(ARFaction.get());
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+".");
}
}