package com.massivecraft.factions.cmd; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.type.TypeMPlayer; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.event.EventFactionsPowerChange; import com.massivecraft.factions.event.EventFactionsPowerChange.PowerChangeReason; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; import com.massivecraft.massivecore.command.type.primitive.TypeDouble; public class CmdFactionsSetpower extends FactionsCommand { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // public CmdFactionsSetpower() { // Aliases this.addAliases("sp", "setpower"); // Parameters this.addParameter(TypeMPlayer.get(), "player"); this.addParameter(TypeDouble.get(), "power"); // Requirements this.addRequirements(RequirementHasPerm.get(Perm.SETPOWER)); } // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // @Override public void perform() throws MassiveException { // Args MPlayer mplayer = this.readArg(); double power = this.readArg(); // 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) { msg("%s's power is already %.2f.", mplayer.getDisplayName(msender), newPower); return; } // Event EventFactionsPowerChange event = new EventFactionsPowerChange(sender, mplayer, PowerChangeReason.COMMAND, newPower); event.run(); if (event.isCancelled()) return; // Inform msg("You changed %s's power from %.2f to %.2f.", mplayer.getDisplayName(msender), oldPower, newPower); if (msender != mplayer) { mplayer.msg("%s changed your power from %.2f to %.2f.", msender.getDisplayName(mplayer), oldPower, newPower); } // Apply mplayer.setPower(newPower); } }