Summon the kraken at will!

This commit is contained in:
GJ 2013-05-03 16:14:03 -04:00
parent b07cf6bdde
commit 8e0a1f4f70
5 changed files with 104 additions and 10 deletions

View File

@ -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<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
switch (args.length) {
case 1:
Set<String> playerNames = UserManager.getPlayers().keySet();
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<String>(playerNames.size()));
default:
return ImmutableList.of();
}
}
}

View File

@ -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) {

View File

@ -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")); }

View File

@ -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();

View File

@ -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: