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

@ -1,109 +1,110 @@
package com.massivecraft.factions; package com.massivecraft.factions;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
import com.massivecraft.massivecore.util.PermUtil; import com.massivecraft.massivecore.util.PermUtil;
public enum Perm public enum Perm
{ {
// -------------------------------------------- // // -------------------------------------------- //
// ENUM // ENUM
// -------------------------------------------- // // -------------------------------------------- //
ACCESS("access"), ACCESS("access"),
ACCESS_VIEW("access.view"), ACCESS_VIEW("access.view"),
ACCESS_PLAYER("access.player"), ACCESS_PLAYER("access.player"),
ACCESS_FACTION("access.faction"), ACCESS_FACTION("access.faction"),
ADMIN("admin"), ADMIN("admin"),
CLAIM("claim"), CLAIM("claim"),
CLAIM_ONE("claim.one"), CLAIM_ONE("claim.one"),
CLAIM_AUTO("claim.auto"), CLAIM_AUTO("claim.auto"),
CLAIM_FILL("claim.fill"), CLAIM_FILL("claim.fill"),
CLAIM_SQUARE("claim.square"), CLAIM_SQUARE("claim.square"),
CLAIM_CIRCLE("claim.circle"), CLAIM_CIRCLE("claim.circle"),
CLAIM_ALL("claim.all"), CLAIM_ALL("claim.all"),
CREATE("create"), CREATE("create"),
DESCRIPTION("description"), DESCRIPTION("description"),
DISBAND("disband"), DISBAND("disband"),
EXPANSIONS("expansions"), EXPANSIONS("expansions"),
FACTION("faction"), FACTION("faction"),
FLAG("flag"), FLAG("flag"),
HOME("home"), HOME("home"),
INVITE("invite"), INVITE("invite"),
INVITE_LIST("invite.list"), INVITE_LIST("invite.list"),
INVITE_LIST_OTHER("invite.list.other"), INVITE_LIST_OTHER("invite.list.other"),
INVITE_ADD("invite.add"), INVITE_ADD("invite.add"),
INVITE_REMOVE("invite.remove"), INVITE_REMOVE("invite.remove"),
JOIN("join"), JOIN("join"),
JOIN_ANY("join.any"), JOIN_ANY("join.any"),
JOIN_OTHERS("join.others"), JOIN_OTHERS("join.others"),
KICK("kick"), KICK("kick"),
LEAVE("leave"), LEAVE("leave"),
LIST("list"), LIST("list"),
MAP("map"), MAP("map"),
MONEY("money"), MONEY("money"),
MONEY_BALANCE("money.balance"), MONEY_BALANCE("money.balance"),
MONEY_BALANCE_ANY("money.balance.any"), MONEY_BALANCE_ANY("money.balance.any"),
MONEY_DEPOSIT("money.deposit"), MONEY_DEPOSIT("money.deposit"),
MONEY_F2F("money.f2f"), MONEY_F2F("money.f2f"),
MONEY_F2P("money.f2p"), MONEY_F2P("money.f2p"),
MONEY_P2F("money.p2f"), MONEY_P2F("money.p2f"),
MONEY_WITHDRAW("money.withdraw"), MONEY_WITHDRAW("money.withdraw"),
MOTD("motd"), MOTD("motd"),
OPEN("open"), OPEN("open"),
PERM("perm"), PERM("perm"),
PLAYER("player"), PLAYER("player"),
POWERBOOST("powerboost"), POWERBOOST("powerboost"),
RANK("rank"), RANK("rank"),
RANK_SHOW("rank.show"), RANK_SHOW("rank.show"),
RANK_ACTION("rank.action"), RANK_ACTION("rank.action"),
RELATION("relation"), RELATION("relation"),
SEECHUNK("seechunk"), SEECHUNK("seechunk"),
SEECHUNKOLD("seechunkold"), SEECHUNKOLD("seechunkold"),
SETHOME("sethome"), SETHOME("sethome"),
NAME("name"), SETPOWER("setpower"),
TITLE("title"), NAME("name"),
TITLE_COLOR("title.color"), TITLE("title"),
UNCLAIM("unclaim"), TITLE_COLOR("title.color"),
UNCLAIM_ONE("unclaim.one"), UNCLAIM("unclaim"),
UNCLAIM_AUTO("unclaim.auto"), UNCLAIM_ONE("unclaim.one"),
UNCLAIM_FILL("unclaim.fill"), UNCLAIM_AUTO("unclaim.auto"),
UNCLAIM_SQUARE("unclaim.square"), UNCLAIM_FILL("unclaim.fill"),
UNCLAIM_CIRCLE("unclaim.circle"), UNCLAIM_SQUARE("unclaim.square"),
UNCLAIM_ALL("unclaim.all"), UNCLAIM_CIRCLE("unclaim.circle"),
UNSETHOME("unsethome"), UNCLAIM_ALL("unclaim.all"),
VERSION("version"), UNSETHOME("unsethome"),
VERSION("version"),
// END OF LIST
; // END OF LIST
;
// -------------------------------------------- //
// FIELDS // -------------------------------------------- //
// -------------------------------------------- // // FIELDS
// -------------------------------------------- //
public final String node;
public final String node;
// -------------------------------------------- //
// CONSTRUCT // -------------------------------------------- //
// -------------------------------------------- // // CONSTRUCT
// -------------------------------------------- //
Perm(final String node)
{ Perm(final String node)
this.node = "factions."+node; {
} this.node = "factions."+node;
}
// -------------------------------------------- //
// HAS // -------------------------------------------- //
// -------------------------------------------- // // HAS
// -------------------------------------------- //
public boolean has(Permissible permissible, boolean informSenderIfNot)
{ public boolean has(Permissible permissible, boolean informSenderIfNot)
return PermUtil.has(permissible, this.node, informSenderIfNot); {
} return PermUtil.has(permissible, this.node, informSenderIfNot);
}
public boolean has(Permissible permissible)
{ public boolean has(Permissible permissible)
return has(permissible, false); {
} return has(permissible, false);
}
}
}

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,
; ;
} }