From 8e0a1f4f70ad6b808ec768547b56b0e95ca15141 Mon Sep 17 00:00:00 2001 From: GJ Date: Fri, 3 May 2013 16:14:03 -0400 Subject: [PATCH] Summon the kraken at will! --- .../gmail/nossr50/commands/KrakenCommand.java | 65 +++++++++++++++++++ .../skills/fishing/FishingManager.java | 26 +++++--- .../com/gmail/nossr50/util/Permissions.java | 3 + .../commands/CommandRegistrationManager.java | 11 ++++ src/main/resources/plugin.yml | 9 +++ 5 files changed, 104 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/commands/KrakenCommand.java diff --git a/src/main/java/com/gmail/nossr50/commands/KrakenCommand.java b/src/main/java/com/gmail/nossr50/commands/KrakenCommand.java new file mode 100644 index 000000000..99028c66c --- /dev/null +++ b/src/main/java/com/gmail/nossr50/commands/KrakenCommand.java @@ -0,0 +1,65 @@ +package com.gmail.nossr50.commands; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.util.StringUtil; + +import com.gmail.nossr50.datatypes.player.McMMOPlayer; +import com.gmail.nossr50.util.Permissions; +import com.gmail.nossr50.util.commands.CommandUtils; +import com.gmail.nossr50.util.player.UserManager; +import com.google.common.collect.ImmutableList; + +public class KrakenCommand implements TabExecutor { + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + switch (args.length) { + case 0: + if (CommandUtils.noConsoleUsage(sender)) { + return true; + } + + if (!Permissions.kraken(sender)) { + sender.sendMessage(command.getPermissionMessage()); + return true; + } + + UserManager.getPlayer(sender.getName()).getFishingManager().unleashTheKraken(); + return true; + + case 1: + if (!Permissions.krakenOthers(sender)) { + sender.sendMessage(command.getPermissionMessage()); + return true; + } + + McMMOPlayer mcMMOPlayer = UserManager.getPlayer(args[0]); + + if (!CommandUtils.checkPlayerExistence(sender, args[0], mcMMOPlayer)) { + return true; + } + + mcMMOPlayer.getFishingManager().unleashTheKraken(); + return true; + + default: + return false; + } + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + switch (args.length) { + case 1: + Set playerNames = UserManager.getPlayers().keySet(); + return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList(playerNames.size())); + default: + return ImmutableList.of(); + } + } +} diff --git a/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java b/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java index 56eea4836..b3ba78908 100644 --- a/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java @@ -50,7 +50,7 @@ import com.gmail.nossr50.util.skills.SkillUtils; public class FishingManager extends SkillManager { private final long FISHING_COOLDOWN_SECONDS = 1000L; - private int fishingTries = 1; + private int fishingTries = 0; private long fishingTimestamp = 0L; public FishingManager(McMMOPlayer mcMMOPlayer) { @@ -65,12 +65,12 @@ public class FishingManager extends SkillManager { return Permissions.masterAngler(getPlayer()); } -// public boolean unleashTheKraken() { -// -// } + public boolean unleashTheKraken() { + return unleashTheKraken(true); + } - private boolean unleashTheKraken() { - if (fishingTries < AdvancedConfig.getInstance().getKrakenTriesBeforeRelease() || fishingTries <= Misc.getRandom().nextInt(200)) { + private boolean unleashTheKraken(boolean forceSpawn) { + if (!forceSpawn && (fishingTries < AdvancedConfig.getInstance().getKrakenTriesBeforeRelease() || fishingTries <= Misc.getRandom().nextInt(200))) { return false; } @@ -118,7 +118,10 @@ public class FishingManager extends SkillManager { int attackInterval = AdvancedConfig.getInstance().getKrakenAttackInterval() * 20; new KrakenAttackTask(kraken, player, player.getLocation()).runTaskTimer(mcMMO.p, attackInterval, attackInterval); - fishingTries = 1; + if (!forceSpawn) { + fishingTries = 0; + } + return true; } @@ -128,7 +131,10 @@ public class FishingManager extends SkillManager { int attackInterval = AdvancedConfig.getInstance().getKrakenAttackInterval() * 20; new KrakenAttackTask(kraken, player).runTaskTimer(mcMMO.p, attackInterval, attackInterval); - fishingTries = 1; + if (!forceSpawn) { + fishingTries = 0; + } + return true; } @@ -140,9 +146,9 @@ public class FishingManager extends SkillManager { long currentTime = System.currentTimeMillis(); boolean hasFished = currentTime < fishingTimestamp + FISHING_COOLDOWN_SECONDS; - fishingTries = hasFished ? fishingTries + 1 : fishingTries - 1; + fishingTries = hasFished ? fishingTries + 1 : Math.max(fishingTries - 1, 0); fishingTimestamp = currentTime; - return unleashTheKraken(); + return unleashTheKraken(false); } public boolean canIceFish(Block block) { diff --git a/src/main/java/com/gmail/nossr50/util/Permissions.java b/src/main/java/com/gmail/nossr50/util/Permissions.java index e81014661..d717ed5bd 100644 --- a/src/main/java/com/gmail/nossr50/util/Permissions.java +++ b/src/main/java/com/gmail/nossr50/util/Permissions.java @@ -49,6 +49,9 @@ public final class Permissions { public static boolean inspectFar(Permissible permissible) { return (permissible.hasPermission("mcmmo.commands.inspect.far")); } public static boolean inspectOffline(Permissible permissible) { return (permissible.hasPermission("mcmmo.commands.inspect.offline")); } + public static boolean kraken(Permissible permissible) { return permissible.hasPermission("mcmmo.commands.kraken"); } + public static boolean krakenOthers(Permissible permissible) { return permissible.hasPermission("mcmmo.commands.kraken.others"); } + public static boolean mcability(Permissible permissible) { return (permissible.hasPermission("mcmmo.commands.mcability")); } public static boolean mcabilityOthers(Permissible permissible) { return (permissible.hasPermission("mcmmo.commands.mcability.others")); } diff --git a/src/main/java/com/gmail/nossr50/util/commands/CommandRegistrationManager.java b/src/main/java/com/gmail/nossr50/util/commands/CommandRegistrationManager.java index 611163aed..cf4b18638 100644 --- a/src/main/java/com/gmail/nossr50/util/commands/CommandRegistrationManager.java +++ b/src/main/java/com/gmail/nossr50/util/commands/CommandRegistrationManager.java @@ -6,6 +6,7 @@ import java.util.List; import org.bukkit.command.PluginCommand; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.commands.KrakenCommand; import com.gmail.nossr50.commands.McabilityCommand; import com.gmail.nossr50.commands.McgodCommand; import com.gmail.nossr50.commands.McmmoCommand; @@ -391,8 +392,18 @@ public final class CommandRegistrationManager { command.setExecutor(new McscoreboardCommand()); } + private static void registerKrakenCommand() { + PluginCommand command = mcMMO.p.getCommand("kraken"); + command.setDescription("Unleash the kraken!"); //TODO: Localize + command.setPermission("mcmmo.commands.kraken;mcmmo.commands.kraken.others"); + command.setPermissionMessage(permissionsMessage); + command.setUsage(LocaleLoader.getString("Commands.Usage.1", "kraken", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]")); + command.setExecutor(new KrakenCommand()); + } + public static void registerCommands() { // Generic Commands + registerKrakenCommand(); registerMcabilityCommand(); registerMcgodCommand(); registerMcmmoCommand(); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 254139711..a217fa757 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -109,6 +109,9 @@ commands: description: Change the style of the mob healthbar mcscoreboard: description: Change the current mcMMO scoreboard being displayed + kraken: + aliases: [mckraken] + description: Unleash the kraken! permissions: mcmmo.*: default: false @@ -695,6 +698,8 @@ permissions: mcmmo.commands.hardcore.all: true mcmmo.commands.inspect.far: true mcmmo.commands.inspect.offline: true + mcmmo.commands.kraken: true + mcmmo.commands.kraken.others: true mcmmo.commands.mcability.others: true mcmmo.commands.mcgod: true mcmmo.commands.mcgod.others: true @@ -770,6 +775,10 @@ permissions: description: Allows access to the inspect command for far players mcmmo.commands.inspect.offline: description: Allows access to the inspect command for offline players + mcmmo.commands.kraken: + description: Allows access to the kraken command + mcmmo.commands.kraken.others: + description: Allows access to the kraken command for other players mcmmo.commands.mcability: description: Allows access to the mcability command mcmmo.commands.mcability.others: