From 9a6c15edd1c479862e8d4572e06af3ec3f1b7343 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Sat, 28 Jan 2012 11:56:51 -0600 Subject: [PATCH] New command /f powerboost <#>, which will apply a permanent power bonus/penalty to a specified player or faction. When applied to a player, it will affect their max power and min power. When applied to a faction, it will be applied to current and max power levels. Whether it is a bonus or a penalty depends on whether the number you specify is positive or negative. New permission factions.powerboost which is required to use the above command. This permission is added to the factions.kit.mod permission kit. example usage: /f powerboost p Player1 1.5 (give player "Player1" a bonus of 1.5 power) /f powerboost faction SomeFaction -6 (give faction "SomeFaction" a penalty of -6 power) --- plugin.yml | 3 + src/com/massivecraft/factions/FPlayer.java | 19 ++--- src/com/massivecraft/factions/Faction.java | 11 ++- .../massivecraft/factions/cmd/CmdHelp.java | 2 +- .../massivecraft/factions/cmd/CmdPower.java | 4 +- .../factions/cmd/CmdPowerBoost.java | 72 +++++++++++++++++++ .../massivecraft/factions/cmd/CmdShow.java | 5 +- .../massivecraft/factions/cmd/FCmdRoot.java | 2 + .../factions/struct/Permission.java | 1 + 9 files changed, 106 insertions(+), 13 deletions(-) create mode 100644 src/com/massivecraft/factions/cmd/CmdPowerBoost.java diff --git a/plugin.yml b/plugin.yml index 4ff23f60..3ec8db7e 100644 --- a/plugin.yml +++ b/plugin.yml @@ -25,6 +25,7 @@ permissions: children: factions.kit.halfmod: true factions.flag.set: true + factions.powerboost: true factions.join.any: true factions.leader.any: true factions.officer.any: true @@ -156,6 +157,8 @@ permissions: description: show player power info factions.power.any: description: view an other players power level + factions.powerboost: + description: apply permanent power bonus/penalty to specified player or faction factions.relation: description: set relation wish to another faction factions.reload: diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 746ebd56..c2faa99a 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -66,7 +66,13 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator // FIELD: power private double power; - + + // FIELD: powerBoost + // special increase/decrease to min and max power for this player + private double powerBoost; + public double getPowerBoost() { return this.powerBoost; } + public void setPowerBoost(double powerBoost) { this.powerBoost = powerBoost; } + // FIELD: lastPowerUpdateTime private long lastPowerUpdateTime; @@ -124,6 +130,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator this.mapAutoUpdating = false; this.autoClaimFor = null; this.loginPvpDisabled = (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0) ? true : false; + this.powerBoost = 0.0; if ( ! Conf.newPlayerStartingFactionID.equals("0") && Factions.i.exists(Conf.newPlayerStartingFactionID)) { @@ -337,23 +344,19 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator { this.power += delta; if (this.power > this.getPowerMax()) - { this.power = this.getPowerMax(); - } else if (this.power < this.getPowerMin()) - { + else if (this.power < this.getPowerMin()) this.power = this.getPowerMin(); - } - //Log.debug("Power of "+this.getName()+" is now: "+this.power); } public double getPowerMax() { - return Conf.powerPlayerMax; + return Conf.powerPlayerMax + this.powerBoost; } public double getPowerMin() { - return Conf.powerPlayerMin; + return Conf.powerPlayerMin + this.powerBoost; } public int getPowerRounded() diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index de01f34c..b0649aed 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -94,6 +94,12 @@ public class Faction extends Entity implements EconomyParticipator return aid; } + // FIELD: powerBoost + // special increase/decrease to default and max power for this faction + private double powerBoost; + public double getPowerBoost() { return this.powerBoost; } + public void setPowerBoost(double powerBoost) { this.powerBoost = powerBoost; } + // FIELDS: Flag management // TODO: This will save... defaults if they where changed to... private Map flagOverrides; // Contains the modifications to the default values @@ -168,6 +174,7 @@ public class Faction extends Entity implements EconomyParticipator this.tag = "???"; this.description = "Default faction description :("; this.money = 0.0; + this.powerBoost = 0.0; this.flagOverrides = new LinkedHashMap(); this.permOverrides = new LinkedHashMap>(); } @@ -280,7 +287,7 @@ public class Faction extends Entity implements EconomyParticipator { ret = Conf.powerFactionMax; } - return ret; + return ret + this.powerBoost; } public double getPowerMax() @@ -299,7 +306,7 @@ public class Faction extends Entity implements EconomyParticipator { ret = Conf.powerFactionMax; } - return ret; + return ret + this.powerBoost; } public int getPowerRounded() diff --git a/src/com/massivecraft/factions/cmd/CmdHelp.java b/src/com/massivecraft/factions/cmd/CmdHelp.java index 476ab4f3..ecc96f0e 100644 --- a/src/com/massivecraft/factions/cmd/CmdHelp.java +++ b/src/com/massivecraft/factions/cmd/CmdHelp.java @@ -166,7 +166,7 @@ public class CmdHelp extends FCommand pageLines = new ArrayList(); pageLines.add(p.txt.parse("More commands for server admins:")); pageLines.add( p.cmdBase.cmdChatSpy.getUseageTemplate(true) ); - pageLines.add(p.txt.parse("Peaceful factions are protected from PvP and land capture.")); + pageLines.add( p.cmdBase.cmdPowerBoost.getUseageTemplate(true) ); pageLines.add( p.cmdBase.cmdLock.getUseageTemplate(true) ); pageLines.add( p.cmdBase.cmdReload.getUseageTemplate(true) ); pageLines.add( p.cmdBase.cmdSaveAll.getUseageTemplate(true) ); diff --git a/src/com/massivecraft/factions/cmd/CmdPower.java b/src/com/massivecraft/factions/cmd/CmdPower.java index 1826faa3..12115816 100644 --- a/src/com/massivecraft/factions/cmd/CmdPower.java +++ b/src/com/massivecraft/factions/cmd/CmdPower.java @@ -36,7 +36,9 @@ public class CmdPower extends FCommand // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay if ( ! payForCommand(Conf.econCostPower, "to show player power info", "for showing player power info")) return; - msg("%s - Power / Maxpower: %d / %d", target.describeTo(fme, true), target.getPowerRounded(), target.getPowerMaxRounded()); + double powerBoost = target.getPowerBoost(); + String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? " (bonus: " : " (penalty: ") + powerBoost + ")"; + msg("%s - Power / Maxpower: %d / %d %s", target.describeTo(fme, true), target.getPowerRounded(), target.getPowerMaxRounded(), boost); } } diff --git a/src/com/massivecraft/factions/cmd/CmdPowerBoost.java b/src/com/massivecraft/factions/cmd/CmdPowerBoost.java new file mode 100644 index 00000000..9a849662 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdPowerBoost.java @@ -0,0 +1,72 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.P; +import com.massivecraft.factions.struct.Permission; + +public class CmdPowerBoost extends FCommand +{ + public CmdPowerBoost() + { + super(); + this.aliases.add("powerboost"); + + this.requiredArgs.add("p|f|player|faction"); + this.requiredArgs.add("name"); + this.requiredArgs.add("#"); + + this.permission = Permission.POWERBOOST.node; + this.disableOnLock = true; + + senderMustBePlayer = false; + senderMustBeMember = false; + senderMustBeOfficer = false; + senderMustBeLeader = false; + } + + @Override + public void perform() + { + String type = this.argAsString(0).toLowerCase(); + boolean doPlayer = true; + if (type.equals("f") || type.equals("faction")) + { + doPlayer = false; + } + else if (!type.equals("p") && !type.equals("player")) + { + msg("You must specify \"p\" or \"player\" to target a player or \"f\" or \"faction\" to target a faction."); + msg("ex. /f powerboost p SomePlayer 0.5 -or- /f powerboost f SomeFaction -5"); + return; + } + + Double targetPower = this.argAsDouble(2); + if (targetPower == null) + { + msg("You must specify a valid numeric value for the power bonus/penalty amount."); + return; + } + + String target; + + if (doPlayer) + { + FPlayer targetPlayer = this.argAsBestFPlayerMatch(1); + if (targetPlayer == null) return; + targetPlayer.setPowerBoost(targetPower); + target = "Player \""+targetPlayer.getName()+"\""; + } + else + { + Faction targetFaction = this.argAsFaction(1); + if (targetFaction == null) return; + targetFaction.setPowerBoost(targetPower); + target = "Faction \""+targetFaction.getTag()+"\""; + } + + msg(""+target+" now has a power bonus/penalty of "+targetPower+" to min and max power levels."); + if (!senderIsConsole) + P.p.log(fme.getName()+" has set the power bonus/penalty for "+target+" to "+targetPower+"."); + } +} diff --git a/src/com/massivecraft/factions/cmd/CmdShow.java b/src/com/massivecraft/factions/cmd/CmdShow.java index 3c7c60e7..86ffd912 100644 --- a/src/com/massivecraft/factions/cmd/CmdShow.java +++ b/src/com/massivecraft/factions/cmd/CmdShow.java @@ -66,7 +66,10 @@ public class CmdShow extends FCommand } msg("Joining: "+(faction.getOpen() ? "no invitation is needed" : "invitation is required")); - msg("Land / Power / Maxpower: %d/%d/%d", faction.getLandRounded(), faction.getPowerRounded(), faction.getPowerMaxRounded()); + + double powerBoost = faction.getPowerBoost(); + String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? " (bonus: " : " (penalty: ") + powerBoost + ")"; + msg("Land / Power / Maxpower: %d/%d/%d %s", faction.getLandRounded(), faction.getPowerRounded(), faction.getPowerMaxRounded(), boost); // show the land value if (Econ.shouldBeUsed()) diff --git a/src/com/massivecraft/factions/cmd/FCmdRoot.java b/src/com/massivecraft/factions/cmd/FCmdRoot.java index 0b71dbb6..9bf36b9c 100644 --- a/src/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/com/massivecraft/factions/cmd/FCmdRoot.java @@ -32,6 +32,7 @@ public class FCmdRoot extends FCommand public CmdOpen cmdOpen = new CmdOpen(); public CmdPerm cmdPerm = new CmdPerm(); public CmdPower cmdPower = new CmdPower(); + public CmdPowerBoost cmdPowerBoost = new CmdPowerBoost(); public CmdRelationAlly cmdRelationAlly = new CmdRelationAlly(); public CmdRelationEnemy cmdRelationEnemy = new CmdRelationEnemy(); public CmdRelationNeutral cmdRelationNeutral = new CmdRelationNeutral(); @@ -95,6 +96,7 @@ public class FCmdRoot extends FCommand this.addSubCommand(this.cmdOpen); this.addSubCommand(this.cmdPerm); this.addSubCommand(this.cmdPower); + this.addSubCommand(this.cmdPowerBoost); this.addSubCommand(this.cmdRelationAlly); this.addSubCommand(this.cmdRelationEnemy); this.addSubCommand(this.cmdRelationNeutral); diff --git a/src/com/massivecraft/factions/struct/Permission.java b/src/com/massivecraft/factions/struct/Permission.java index 0c4b289a..f04a7944 100644 --- a/src/com/massivecraft/factions/struct/Permission.java +++ b/src/com/massivecraft/factions/struct/Permission.java @@ -42,6 +42,7 @@ public enum Permission PERM("perm"), POWER("power"), POWER_ANY("power.any"), + POWERBOOST("powerboost"), RELATION("relation"), RELOAD("reload"), SAVE("save"),