From 2ac96f4278e9c9990bf452fc75110d5b69ce3e1f Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Sat, 22 Oct 2011 18:12:15 +0200 Subject: [PATCH] Added a permanent power command --- plugin.yml | 3 ++ src/com/massivecraft/factions/Faction.java | 16 ++++++ .../massivecraft/factions/cmd/CmdHelp.java | 1 + .../factions/cmd/CmdPermanentPower.java | 50 +++++++++++++++++++ .../massivecraft/factions/cmd/FCmdRoot.java | 2 + .../factions/struct/Permission.java | 1 + 6 files changed, 73 insertions(+) create mode 100644 src/com/massivecraft/factions/cmd/CmdPermanentPower.java diff --git a/plugin.yml b/plugin.yml index 57943a4d..e04fc585 100644 --- a/plugin.yml +++ b/plugin.yml @@ -26,6 +26,7 @@ permissions: factions.kit.halfmod: true factions.disband.any: true factions.setpermanent: true + factions.setpermanentpower: true factions.setpeaceful: true factions.sethome.any: true factions.money.*: true @@ -175,6 +176,8 @@ permissions: description: designate a faction as peaceful factions.setpermanent: description: designate a faction as permanent + factions.setpermanentpower: + description: set permanent power for a faction factions.power: description: show player power info factions.power.any: diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index 8b872aeb..32546978 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -129,6 +129,12 @@ public class Faction extends Entity implements EconomyParticipator return Econ.getMethod().getAccount(aid); } + // FIELD: permanentPower + private Integer permanentPower; + public Integer getPermanentPower() { return this.permanentPower; } + public void setPermanentPower(Integer permanentPower) { this.permanentPower = permanentPower; } + public boolean hasPermanentPower() { return this.permanentPower != null; } + // -------------------------------------------- // // Construct // -------------------------------------------- // @@ -247,6 +253,11 @@ public class Faction extends Entity implements EconomyParticipator //----------------------------------------------// public double getPower() { + if (this.hasPermanentPower()) + { + return this.getPermanentPower(); + } + double ret = 0; for (FPlayer fplayer : this.getFPlayers()) { @@ -261,6 +272,11 @@ public class Faction extends Entity implements EconomyParticipator public double getPowerMax() { + if (this.hasPermanentPower()) + { + return this.getPermanentPower(); + } + double ret = 0; for (FPlayer fplayer : this.getFPlayers()) { diff --git a/src/com/massivecraft/factions/cmd/CmdHelp.java b/src/com/massivecraft/factions/cmd/CmdHelp.java index b00e2e6d..f4387631 100644 --- a/src/com/massivecraft/factions/cmd/CmdHelp.java +++ b/src/com/massivecraft/factions/cmd/CmdHelp.java @@ -169,6 +169,7 @@ public class CmdHelp extends FCommand pageLines.add(p.txt.parse("More commands for server admins:")); pageLines.add( p.cmdBase.cmdPeaceful.getUseageTemplate(true) ); pageLines.add( p.cmdBase.cmdPermanent.getUseageTemplate(true) ); + pageLines.add( p.cmdBase.cmdPermanentPower.getUseageTemplate(true) ); pageLines.add(p.txt.parse("Peaceful factions are protected from PvP and land capture.")); pageLines.add( p.cmdBase.cmdLock.getUseageTemplate(true) ); pageLines.add( p.cmdBase.cmdReload.getUseageTemplate(true) ); diff --git a/src/com/massivecraft/factions/cmd/CmdPermanentPower.java b/src/com/massivecraft/factions/cmd/CmdPermanentPower.java new file mode 100644 index 00000000..ff275c26 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdPermanentPower.java @@ -0,0 +1,50 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.struct.Permission; + +public class CmdPermanentPower extends FCommand +{ + public CmdPermanentPower() + { + super(); + this.aliases.add("permanentpower"); + + this.requiredArgs.add("faction"); + this.optionalArgs.put("power", "reset"); + + this.permission = Permission.SET_PERMANENTPOWER.node; + this.disableOnLock = true; + + senderMustBePlayer = false; + senderMustBeMember = false; + senderMustBeModerator = false; + senderMustBeAdmin = false; + } + + @Override + public void perform() + { + Faction targetFaction = this.argAsFaction(0); + if (targetFaction == null) return; + + Integer targetPower = this.argAsInt(1); + + targetFaction.setPermanentPower(targetPower); + + String change = "removed permanentpower status from"; + if(targetFaction.hasPermanentPower()) + { + change = "added permanentpower status to"; + } + + msg("You %s %s.", change, targetFaction.describeTo(fme)); + + // Inform all players + for (FPlayer fplayer : targetFaction.getFPlayersWhereOnline(true)) + { + fplayer.msg((fme == null ? "A server admin" : fme.describeTo(fplayer, true))+" "+change+" your faction."); + } + } +} diff --git a/src/com/massivecraft/factions/cmd/FCmdRoot.java b/src/com/massivecraft/factions/cmd/FCmdRoot.java index 734d724c..0b3cbad0 100644 --- a/src/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/com/massivecraft/factions/cmd/FCmdRoot.java @@ -33,6 +33,7 @@ public class FCmdRoot extends FCommand public CmdOwnerList cmdOwnerList = new CmdOwnerList(); public CmdPeaceful cmdPeaceful = new CmdPeaceful(); public CmdPermanent cmdPermanent = new CmdPermanent(); + public CmdPermanentPower cmdPermanentPower = new CmdPermanentPower(); public CmdPower cmdPower = new CmdPower(); public CmdRelationAlly cmdRelationAlly = new CmdRelationAlly(); public CmdRelationEnemy cmdRelationEnemy = new CmdRelationEnemy(); @@ -98,6 +99,7 @@ public class FCmdRoot extends FCommand this.addSubCommand(this.cmdOwnerList); this.addSubCommand(this.cmdPeaceful); this.addSubCommand(this.cmdPermanent); + this.addSubCommand(this.cmdPermanentPower); this.addSubCommand(this.cmdPower); this.addSubCommand(this.cmdRelationAlly); this.addSubCommand(this.cmdRelationEnemy); diff --git a/src/com/massivecraft/factions/struct/Permission.java b/src/com/massivecraft/factions/struct/Permission.java index 32c324bf..49a430e4 100644 --- a/src/com/massivecraft/factions/struct/Permission.java +++ b/src/com/massivecraft/factions/struct/Permission.java @@ -45,6 +45,7 @@ public enum Permission OWNERLIST("ownerlist"), SET_PEACEFUL("setpeaceful"), SET_PERMANENT("setpermanent"), + SET_PERMANENTPOWER("setpermanentpower"), POWER("power"), POWER_ANY("power.any"), RELATION("relation"),