From 066c9d9fecbcdefd97250db1d4824cac893417f0 Mon Sep 17 00:00:00 2001 From: GJ Date: Thu, 31 May 2012 14:08:17 -0400 Subject: [PATCH] Archery to SkillCommand --- .../commands/skills/ArcheryCommand.java | 124 +++++++----------- 1 file changed, 48 insertions(+), 76 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/skills/ArcheryCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/ArcheryCommand.java index 01e936a62..265e5bd6c 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/ArcheryCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/ArcheryCommand.java @@ -1,22 +1,10 @@ package com.gmail.nossr50.commands.skills; -import java.text.DecimalFormat; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import com.gmail.nossr50.commands.CommandHelper; -import com.gmail.nossr50.datatypes.PlayerProfile; +import com.gmail.nossr50.commands.SkillCommand; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.locale.LocaleLoader; -import com.gmail.nossr50.util.Page; -import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.Users; -public class ArcheryCommand implements CommandExecutor { - private float skillValue; +public class ArcheryCommand extends SkillCommand { private String skillShotBonus; private String dazeChance; private String retrieveChance; @@ -25,67 +13,12 @@ public class ArcheryCommand implements CommandExecutor { private boolean canDaze; private boolean canRetrieve; - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (CommandHelper.noConsoleUsage(sender)) { - return true; - } - - if (CommandHelper.noCommandPermissions(sender, "mcmmo.skills.archery")) { - return true; - } - - Player player = (Player) sender; - PlayerProfile PP = Users.getProfile(player); - - skillValue = (float) PP.getSkillLevel(SkillType.ARCHERY); - dataCalculations(skillValue); - permissionsCheck(player); - - player.sendMessage(LocaleLoader.getString("Skills.Header", new Object[] { LocaleLoader.getString("Archery.SkillName") })); - player.sendMessage(LocaleLoader.getString("Commands.XPGain", new Object[] { LocaleLoader.getString("Commands.XPGain.Archery") })); - player.sendMessage(LocaleLoader.getString("Effects.Level", new Object[] { PP.getSkillLevel(SkillType.ARCHERY), PP.getSkillXpLevel(SkillType.ARCHERY), PP.getXpToLevel(SkillType.ARCHERY) })); - - if (canSkillShot || canDaze || canRetrieve) { - player.sendMessage(LocaleLoader.getString("Skills.Header", new Object[] { LocaleLoader.getString("Effects.Effects") })); - } - - if (canSkillShot) { - player.sendMessage(LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Archery.Effect.0"), LocaleLoader.getString("Archery.Effect.1") })); - } - - if (canDaze) { - player.sendMessage(LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Archery.Effect.2"), LocaleLoader.getString("Archery.Effect.3") })); - } - - if (canRetrieve) { - player.sendMessage(LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Archery.Effect.4"), LocaleLoader.getString("Archery.Effect.5") })); - } - - if (canSkillShot || canDaze || canRetrieve) { - player.sendMessage(LocaleLoader.getString("Skills.Header", new Object[] { LocaleLoader.getString("Commands.Stats.Self") })); - } - - if (canSkillShot) { - player.sendMessage(LocaleLoader.getString("Archery.Combat.SkillshotBonus", new Object[] { skillShotBonus })); - } - - if (canDaze) { - player.sendMessage(LocaleLoader.getString("Archery.Combat.DazeChance", new Object[] { dazeChance })); - } - - if (canRetrieve) { - player.sendMessage(LocaleLoader.getString("Archery.Combat.RetrieveChance", new Object[] { retrieveChance })); - } - - Page.grabGuidePageForSkill(SkillType.ARCHERY, player, args); - - return true; + public ArcheryCommand() { + super(SkillType.ARCHERY); } - private void dataCalculations(float skillValue) { - DecimalFormat percent = new DecimalFormat("##0.00%"); - + @Override + protected void dataCalculations() { if (skillValue >= 1000) { skillShotBonus = "200.00%"; dazeChance = "50.00%"; @@ -98,11 +31,50 @@ public class ArcheryCommand implements CommandExecutor { } } - private void permissionsCheck(Player player) { - Permissions permInstance = Permissions.getInstance(); - + @Override + protected void permissionsCheck() { canSkillShot = permInstance.archeryBonus(player); canDaze = permInstance.daze(player); canRetrieve = permInstance.trackArrows(player); } + + @Override + protected boolean effectsHeaderPermissions() { + return canSkillShot || canDaze || canRetrieve; + } + + @Override + protected void effectsDisplay() { + if (canSkillShot) { + player.sendMessage(LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Archery.Effect.0"), LocaleLoader.getString("Archery.Effect.1") })); + } + + if (canDaze) { + player.sendMessage(LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Archery.Effect.2"), LocaleLoader.getString("Archery.Effect.3") })); + } + + if (canRetrieve) { + player.sendMessage(LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Archery.Effect.4"), LocaleLoader.getString("Archery.Effect.5") })); + } + } + + @Override + protected boolean statsHeaderPermissions() { + return canSkillShot || canDaze || canRetrieve; + } + + @Override + protected void statsDisplay() { + if (canSkillShot) { + player.sendMessage(LocaleLoader.getString("Archery.Combat.SkillshotBonus", new Object[] { skillShotBonus })); + } + + if (canDaze) { + player.sendMessage(LocaleLoader.getString("Archery.Combat.DazeChance", new Object[] { dazeChance })); + } + + if (canRetrieve) { + player.sendMessage(LocaleLoader.getString("Archery.Combat.RetrieveChance", new Object[] { retrieveChance })); + } + } }