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