Implement the f setpower command
This commit is contained in:
parent
486f8ac957
commit
d6d5cb325d
@ -61,6 +61,7 @@ permissions:
|
||||
factions.seechunk: {description: see the chunk you stand in, default: false}
|
||||
factions.seechunkold: {description: see the chunk you stand in, default: false}
|
||||
factions.sethome: {description: set the faction home, default: false}
|
||||
factions.setpower: {description: set power, default: false}
|
||||
factions.name: {description: set faction name, default: false}
|
||||
factions.title: {description: set player title, default: false}
|
||||
factions.title.color: {description: set player title with color, default: false}
|
||||
@ -132,6 +133,7 @@ permissions:
|
||||
factions.seechunk: true
|
||||
factions.seechunkold: true
|
||||
factions.sethome: true
|
||||
factions.setpower: true
|
||||
factions.name: true
|
||||
factions.title: true
|
||||
factions.title.color: true
|
||||
@ -165,6 +167,7 @@ permissions:
|
||||
factions.leader.any: true
|
||||
factions.officer.any: true
|
||||
factions.access.any: true
|
||||
factions.setpower: true
|
||||
factions.kit.rank1:
|
||||
default: false
|
||||
children:
|
||||
|
@ -61,6 +61,7 @@ public enum Perm
|
||||
SEECHUNK("seechunk"),
|
||||
SEECHUNKOLD("seechunkold"),
|
||||
SETHOME("sethome"),
|
||||
SETPOWER("setpower"),
|
||||
NAME("name"),
|
||||
TITLE("title"),
|
||||
TITLE_COLOR("title.color"),
|
||||
|
@ -53,6 +53,7 @@ public class CmdFactions extends FactionsCommand
|
||||
public CmdFactionsAdmin cmdFactionsAdmin = new CmdFactionsAdmin();
|
||||
public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband();
|
||||
public CmdFactionsPowerBoost cmdFactionsPowerBoost = new CmdFactionsPowerBoost();
|
||||
public CmdFactionsSetpower cmdFactionsSetpower = new CmdFactionsSetpower();
|
||||
public VersionCommand cmdFactionsVersion = new VersionCommand(Factions.get(), Perm.VERSION.node, "v", "version");
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -102,6 +103,7 @@ public class CmdFactions extends FactionsCommand
|
||||
this.addSubCommand(this.cmdFactionsAdmin);
|
||||
this.addSubCommand(this.cmdFactionsDisband);
|
||||
this.addSubCommand(this.cmdFactionsPowerBoost);
|
||||
this.addSubCommand(this.cmdFactionsSetpower);
|
||||
this.addSubCommand(this.cmdFactionsVersion);
|
||||
|
||||
// Deprecated Commands
|
||||
|
72
src/com/massivecraft/factions/cmd/CmdFactionsSetpower.java
Normal file
72
src/com/massivecraft/factions/cmd/CmdFactionsSetpower.java
Normal file
@ -0,0 +1,72 @@
|
||||
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;
|
||||
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
|
||||
this.addRequiredArg("player");
|
||||
this.addRequiredArg("power");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqHasPerm.get(Perm.SETPOWER.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
MPlayer mplayer = this.arg(0, ARMPlayer.getAny());
|
||||
if (mplayer == null) return;
|
||||
Double power = this.arg(1, ARDouble.get());
|
||||
if (power == null) return;
|
||||
|
||||
// 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)
|
||||
{
|
||||
msender.msg("%s's <i>power is already <h>%.2f<i>.", mplayer.getDisplayName(msender), newPower);
|
||||
return;
|
||||
}
|
||||
|
||||
// Event
|
||||
EventFactionsPowerChange event = new EventFactionsPowerChange(sender, mplayer, PowerChangeReason.COMMAND, newPower);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
// Inform
|
||||
msender.msg("<i>You changed %s's <i>power from <h>%.2f <i>to <h>%.2f<i>.", mplayer.getDisplayName(msender), oldPower, newPower);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -49,6 +49,7 @@ public class EventFactionsPowerChange extends EventFactionsAbstractSender
|
||||
{
|
||||
TIME,
|
||||
DEATH,
|
||||
COMMAND,
|
||||
UNDEFINED,
|
||||
;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user