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

72 lines
2.0 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.arg.ARMPlayer;
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-01-23 08:16:31 +01:00
import com.massivecraft.massivecore.cmd.arg.ARDouble;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
public class CmdFactionsSetpower extends FactionsCommand
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsSetpower()
{
// Aliases
this.addAliases("sp", "setpower");
// Args
2015-07-24 13:42:06 +02:00
this.addArg(ARMPlayer.get(), "player");
2015-05-06 17:04:35 +02:00
this.addArg(ARDouble.get(), "power");
2015-01-23 08:16:31 +01:00
// Requirements
this.addRequirements(ReqHasPerm.get(Perm.SETPOWER.node));
}
// -------------------------------------------- //
// 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);
}
}