Implement the f setpower command

This commit is contained in:
Benjamin Heusser 2015-01-23 08:16:31 +01:00 committed by Olof Larsson
parent 486f8ac957
commit d6d5cb325d
5 changed files with 188 additions and 109 deletions

View File

@ -61,6 +61,7 @@ permissions:
factions.seechunk: {description: see the chunk you stand in, default: false} factions.seechunk: {description: see the chunk you stand in, default: false}
factions.seechunkold: {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.sethome: {description: set the faction home, default: false}
factions.setpower: {description: set power, default: false}
factions.name: {description: set faction name, default: false} factions.name: {description: set faction name, default: false}
factions.title: {description: set player title, default: false} factions.title: {description: set player title, default: false}
factions.title.color: {description: set player title with color, default: false} factions.title.color: {description: set player title with color, default: false}
@ -132,6 +133,7 @@ permissions:
factions.seechunk: true factions.seechunk: true
factions.seechunkold: true factions.seechunkold: true
factions.sethome: true factions.sethome: true
factions.setpower: true
factions.name: true factions.name: true
factions.title: true factions.title: true
factions.title.color: true factions.title.color: true
@ -165,6 +167,7 @@ permissions:
factions.leader.any: true factions.leader.any: true
factions.officer.any: true factions.officer.any: true
factions.access.any: true factions.access.any: true
factions.setpower: true
factions.kit.rank1: factions.kit.rank1:
default: false default: false
children: children:

View File

@ -61,6 +61,7 @@ public enum Perm
SEECHUNK("seechunk"), SEECHUNK("seechunk"),
SEECHUNKOLD("seechunkold"), SEECHUNKOLD("seechunkold"),
SETHOME("sethome"), SETHOME("sethome"),
SETPOWER("setpower"),
NAME("name"), NAME("name"),
TITLE("title"), TITLE("title"),
TITLE_COLOR("title.color"), TITLE_COLOR("title.color"),

View File

@ -53,6 +53,7 @@ public class CmdFactions extends FactionsCommand
public CmdFactionsAdmin cmdFactionsAdmin = new CmdFactionsAdmin(); public CmdFactionsAdmin cmdFactionsAdmin = new CmdFactionsAdmin();
public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband(); public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband();
public CmdFactionsPowerBoost cmdFactionsPowerBoost = new CmdFactionsPowerBoost(); public CmdFactionsPowerBoost cmdFactionsPowerBoost = new CmdFactionsPowerBoost();
public CmdFactionsSetpower cmdFactionsSetpower = new CmdFactionsSetpower();
public VersionCommand cmdFactionsVersion = new VersionCommand(Factions.get(), Perm.VERSION.node, "v", "version"); 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.cmdFactionsAdmin);
this.addSubCommand(this.cmdFactionsDisband); this.addSubCommand(this.cmdFactionsDisband);
this.addSubCommand(this.cmdFactionsPowerBoost); this.addSubCommand(this.cmdFactionsPowerBoost);
this.addSubCommand(this.cmdFactionsSetpower);
this.addSubCommand(this.cmdFactionsVersion); this.addSubCommand(this.cmdFactionsVersion);
// Deprecated Commands // Deprecated Commands

View 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);
}
}

View File

@ -49,6 +49,7 @@ public class EventFactionsPowerChange extends EventFactionsAbstractSender
{ {
TIME, TIME,
DEATH, DEATH,
COMMAND,
UNDEFINED, UNDEFINED,
; ;
} }