From 080ea3363bab3df8687e688e1d27e2b7fd19dc0a Mon Sep 17 00:00:00 2001 From: Brettflan Date: Mon, 25 Jul 2011 13:16:14 -0500 Subject: [PATCH] New command /f power [player name] to check either your own power (if no name is specified) or another player's power (if a player name is specified). The ability for a player to view their own power is based on the standard factions.participate permission, but to check the power of other players, the new permission node factions.viewAnyPower needs to be granted. If you aren't using a Permissions plugin (instead defaulting to the built-in Bukkit permission system), the factions.viewAnyPower permission is granted by default. Otherwise, you'll need to configure your Permissions plugin to grant the new permission as needed. --- src/com/massivecraft/factions/Factions.java | 5 ++ .../factions/commands/FCommandHelp.java | 4 +- .../factions/commands/FCommandPower.java | 52 +++++++++++++++++++ src/plugin.yml | 7 +++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 src/com/massivecraft/factions/commands/FCommandPower.java diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 60b9021f..a646ebe9 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -94,6 +94,7 @@ public class Factions extends JavaPlugin { commands.add(new FCommandMap()); commands.add(new FCommandMod()); commands.add(new FCommandOpen()); + commands.add(new FCommandPower()); commands.add(new FCommandRelationAlly()); commands.add(new FCommandRelationEnemy()); commands.add(new FCommandRelationNeutral()); @@ -353,6 +354,10 @@ public class Factions extends JavaPlugin { return hasPerm(sender, "factions.worldOptions"); } + public static boolean hasPermViewAnyPower(CommandSender sender) { + return hasPerm(sender, "factions.viewAnyPower"); + } + public static boolean isCommandDisabled(CommandSender sender, String command) { return (hasPerm(sender, "factions.commandDisable."+command) && !hasPerm(sender, "factions.commandDisable.none")); } diff --git a/src/com/massivecraft/factions/commands/FCommandHelp.java b/src/com/massivecraft/factions/commands/FCommandHelp.java index 6894cb7b..e804e232 100644 --- a/src/com/massivecraft/factions/commands/FCommandHelp.java +++ b/src/com/massivecraft/factions/commands/FCommandHelp.java @@ -58,7 +58,7 @@ public class FCommandHelp extends FBaseCommand { pageLines.add( new FCommandHelp().getUseageTemplate() ); pageLines.add( new FCommandList().getUseageTemplate() ); pageLines.add( new FCommandShow().getUseageTemplate() ); - pageLines.add( new FCommandMap().getUseageTemplate() ); + pageLines.add( new FCommandPower().getUseageTemplate() ); pageLines.add( new FCommandJoin().getUseageTemplate() ); pageLines.add( new FCommandLeave().getUseageTemplate() ); pageLines.add( new FCommandChat().getUseageTemplate() ); @@ -91,13 +91,13 @@ public class FCommandHelp extends FBaseCommand { helpPages.add(pageLines); pageLines = new ArrayList(); + pageLines.add( new FCommandMap().getUseageTemplate() ); pageLines.add( new FCommandRelationAlly().getUseageTemplate() ); pageLines.add( new FCommandRelationNeutral().getUseageTemplate() ); pageLines.add( new FCommandRelationEnemy().getUseageTemplate() ); pageLines.add(""); pageLines.add("Set the relation you WISH to have with another faction."); pageLines.add("Your default relation with other factions will be neutral."); - pageLines.add(""); pageLines.add("If BOTH factions choose \"ally\" you will be allies."); pageLines.add("If ONE faction chooses \"enemy\" you will be enemies."); helpPages.add(pageLines); diff --git a/src/com/massivecraft/factions/commands/FCommandPower.java b/src/com/massivecraft/factions/commands/FCommandPower.java new file mode 100644 index 00000000..e675f4b8 --- /dev/null +++ b/src/com/massivecraft/factions/commands/FCommandPower.java @@ -0,0 +1,52 @@ +package com.massivecraft.factions.commands; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.massivecraft.factions.Conf; +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.FPlayer; + + +public class FCommandPower extends FBaseCommand { + + public FCommandPower() { + aliases.add("power"); + aliases.add("pow"); + + senderMustBePlayer = false; + + optionalParameters.add("player name"); + + helpDescription = "show player power info"; + } + + @Override + public boolean hasPermission(CommandSender sender) { + return true; + } + + @Override + public void perform() { + FPlayer target; + if (parameters.size() > 0) { + if (!Factions.hasPermViewAnyPower(player)) { + me.sendMessage("You do not have the appropriate permission to view another player's power level."); + return; + } + target = findFPlayer(parameters.get(0), false); + } else if (!(sender instanceof Player)) { + sendMessage("From the command line, you must specify a player (f power )."); + return; + } else { + target = me; + } + + if (target == null) { + return; + } + + sendMessage(target.getNameAndRelevant(me)+Conf.colorChrome+" - Power / Maxpower: "+Conf.colorSystem+target.getPowerRounded()+" / "+target.getPowerMaxRounded()); + } + +} diff --git a/src/plugin.yml b/src/plugin.yml index 4adb2a09..1de47be5 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -18,6 +18,7 @@ permissions: children: factions.participate: true factions.create: true + factions.viewAnyPower: true factions.manageSafeZone: true factions.manageWarZone: true factions.adminBypass: true @@ -34,6 +35,9 @@ permissions: factions.create: description: Allows the player to create a new faction default: true + factions.viewAnyPower: + description: Allows the player to view the power level of anyone else + default: true factions.manageSafeZone: description: Allows the player to claim land as a safe zone, and to build/destroy within safe zones default: op @@ -130,6 +134,9 @@ permissions: factions.commandDisable.open: description: open command disabled default: false + factions.commandDisable.power: + description: power command disabled + default: false factions.commandDisable.ally: description: ally command disabled default: false