Factions3/src/com/massivecraft/factions/cmd/CmdFactionsSetpower.java

72 lines
2.1 KiB
Java
Raw Normal View History

2015-01-23 08:16:31 +01:00
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.type.TypeMPlayer;
2015-01-23 08:16:31 +01:00
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.event.EventFactionsPowerChange;
import com.massivecraft.factions.event.EventFactionsPowerChange.PowerChangeReason;
2015-02-12 12:00:55 +01:00
import com.massivecraft.massivecore.MassiveException;
2015-11-06 02:10:29 +01:00
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.command.type.primitive.TypeDouble;
2015-01-23 08:16:31 +01:00
public class CmdFactionsSetpower extends FactionsCommand
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsSetpower()
{
// Aliases
this.addAliases("sp", "setpower");
// Parameters
this.addParameter(TypeMPlayer.get(), "player");
this.addParameter(TypeDouble.get(), "power");
2015-01-23 08:16:31 +01:00
// Requirements
this.addRequirements(RequirementHasPerm.get(Perm.SETPOWER));
2015-01-23 08:16:31 +01:00
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
2015-02-12 12:00:55 +01:00
public void perform() throws MassiveException
2015-01-23 08:16:31 +01:00
{
// Args
2015-05-06 17:04:35 +02:00
MPlayer mplayer = this.readArg();
double power = this.readArg();
2015-01-23 08:16:31 +01:00
// Power
double oldPower = mplayer.getPower();
double newPower = mplayer.getLimitedPower(power);
// Detect "no change"
double difference = Math.abs(newPower - oldPower);
double maxDifference = 0.1d;
if (difference < maxDifference)
{
2015-05-06 17:04:35 +02:00
msg("%s's <i>power is already <h>%.2f<i>.", mplayer.getDisplayName(msender), newPower);
2015-01-23 08:16:31 +01:00
return;
}
// Event
EventFactionsPowerChange event = new EventFactionsPowerChange(sender, mplayer, PowerChangeReason.COMMAND, newPower);
event.run();
if (event.isCancelled()) return;
// Inform
2015-05-06 17:04:35 +02:00
msg("<i>You changed %s's <i>power from <h>%.2f <i>to <h>%.2f<i>.", mplayer.getDisplayName(msender), oldPower, newPower);
2015-01-23 08:16:31 +01:00
if (msender != mplayer)
{
mplayer.msg("%s <i>changed your power from <h>%.2f <i>to <h>%.2f<i>.", msender.getDisplayName(mplayer), oldPower, newPower);
}
// Apply
mplayer.setPower(newPower);
}
}