From 5b5b73cde0806b844c6183a696403af15ce87a6a Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Fri, 22 Mar 2013 00:38:15 +0100 Subject: [PATCH] Improving Chimaera Wing - part 2 * Added a warmup before using a Chimaera Wing * Closes #740 --- .../java/com/gmail/nossr50/config/Config.java | 1 + .../nossr50/datatypes/player/McMMOPlayer.java | 16 ++++- .../runnables/items/ChimaeraWingWarmup.java | 49 +++++++++++++++ .../com/gmail/nossr50/util/ChimaeraWing.java | 61 +++++++++++++------ src/main/resources/config.yml | 1 + 5 files changed, 107 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/runnables/items/ChimaeraWingWarmup.java diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index 0b22550d8..f87b1a3cd 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -107,6 +107,7 @@ public class Config extends AutoUpdateConfigLoader { public boolean getChimaeraEnabled() { return config.getBoolean("Items.Chimaera_Wing.Enabled", true); } public boolean getChimaeraPreventUseUnderground() { return config.getBoolean("Items.Chimaera_Wing.Prevent_Use_Underground", true); } public int getChimaeraCooldown() { return config.getInt("Items.Chimaera_Wing.Cooldown", 240); } + public int getChimaeraWarmup() { return config.getInt("Items.Chimaera_Wing.Warmup", 5); } /* Particles */ public boolean getAbilityActivationEffectEnabled() { return config.getBoolean("Particles.Ability_Activation", true); } diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index 2385ccd12..afc477572 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -5,6 +5,7 @@ import java.util.Map; import java.util.Set; import org.bukkit.GameMode; +import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -78,8 +79,10 @@ public class McMMOPlayer { private Map toolMode = new HashMap(); private Map toolATS = new HashMap(); - private int recentlyHurt; private int chimaeraWing; + private Location chimaeraWingCommence; + + private int recentlyHurt; private int respawnATS; public McMMOPlayer(Player player) { @@ -315,6 +318,17 @@ public class McMMOPlayer { chimaeraWing = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR); } + public Location getChimaeraCommenceLocation() { + return chimaeraWingCommence; + } + + public void setChimaeraCommenceLocation(Location location) { + chimaeraWingCommence = location; + } + + public void actualizeChimaeraCommenceLocation(Player player) { + setChimaeraCommenceLocation(player.getLocation()); + } /* * Exploit Prevention diff --git a/src/main/java/com/gmail/nossr50/runnables/items/ChimaeraWingWarmup.java b/src/main/java/com/gmail/nossr50/runnables/items/ChimaeraWingWarmup.java new file mode 100644 index 000000000..8c99900eb --- /dev/null +++ b/src/main/java/com/gmail/nossr50/runnables/items/ChimaeraWingWarmup.java @@ -0,0 +1,49 @@ +package com.gmail.nossr50.runnables.items; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import com.gmail.nossr50.datatypes.player.McMMOPlayer; +import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.util.ChimaeraWing; +import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.util.skills.SkillUtils; + +public class ChimaeraWingWarmup extends BukkitRunnable { + private McMMOPlayer mcMMOPlayer; + + public ChimaeraWingWarmup(McMMOPlayer mcMMOPlayer) { + this.mcMMOPlayer = mcMMOPlayer; + } + + @Override + public void run() { + checkChimaeraWingTeleport(); + } + + private void checkChimaeraWingTeleport() { + Player player = mcMMOPlayer.getPlayer(); + Location previousLocation = mcMMOPlayer.getChimaeraCommenceLocation(); + Location newLocation = mcMMOPlayer.getPlayer().getLocation(); + long recentlyHurt = mcMMOPlayer.getRecentlyHurt(); + + if (newLocation.distanceSquared(previousLocation) > 1.0) { + player.sendMessage(ChatColor.RED + "Teleportation canceled!"); //TODO Locale! + + mcMMOPlayer.setChimaeraCommenceLocation(null); + return; + } + + if (!SkillUtils.cooldownOver(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, 60, player)) { + player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, 60, player))); + + mcMMOPlayer.setChimaeraCommenceLocation(null); + return; + } + ChimaeraWing.chimaeraExecuteTeleport(); + + mcMMOPlayer.setChimaeraCommenceLocation(null); + } +} diff --git a/src/main/java/com/gmail/nossr50/util/ChimaeraWing.java b/src/main/java/com/gmail/nossr50/util/ChimaeraWing.java index 5a8dd1c4f..010b022a7 100644 --- a/src/main/java/com/gmail/nossr50/util/ChimaeraWing.java +++ b/src/main/java/com/gmail/nossr50/util/ChimaeraWing.java @@ -13,14 +13,20 @@ import org.bukkit.inventory.ShapelessRecipe; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.util.Vector; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.metrics.MetricsManager; +import com.gmail.nossr50.runnables.items.ChimaeraWingWarmup; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.SkillUtils; public final class ChimaeraWing { + private static McMMOPlayer mcMMOPlayer; + private static Location location; + private ChimaeraWing() {} /** @@ -35,12 +41,18 @@ public final class ChimaeraWing { return; } - Location location = player.getLocation(); + mcMMOPlayer = UserManager.getPlayer(player); + + location = player.getLocation(); int amount = inHand.getAmount(); - long recentlyHurt = UserManager.getPlayer(player).getRecentlyHurt(); - long lastChimaeraWing = (UserManager.getPlayer(player).getLastChimaeraTeleport()); + long recentlyHurt = mcMMOPlayer.getRecentlyHurt(); + long lastChimaeraWing = mcMMOPlayer.getLastChimaeraTeleport(); if (Permissions.chimaeraWing(player) && ItemUtils.isChimaeraWing(inHand)) { + if (mcMMOPlayer.getChimaeraCommenceLocation() != null) { + return; + } + if (!SkillUtils.cooldownOver(lastChimaeraWing * Misc.TIME_CONVERSION_FACTOR, Config.getInstance().getChimaeraCooldown(), player)) { player.sendMessage(ChatColor.RED + "You need to wait before you can use this again! " + ChatColor.YELLOW + "(" + SkillUtils.calculateTimeLeft(lastChimaeraWing * Misc.TIME_CONVERSION_FACTOR, Config.getInstance().getChimaeraCooldown(), player) + ")"); //TODO Locale! return; @@ -56,37 +68,46 @@ public final class ChimaeraWing { return; } - player.setItemInHand(new ItemStack(getChimaeraWing(amount - Config.getInstance().getChimaeraUseCost()))); - if (Config.getInstance().getChimaeraPreventUseUnderground()) { if (location.getY() < player.getWorld().getHighestBlockYAt(location)) { + player.setItemInHand(new ItemStack(getChimaeraWing(amount - Config.getInstance().getChimaeraUseCost()))); player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Fail")); player.setVelocity(new Vector(0, 0.5D, 0)); CombatUtils.dealDamage(player, Misc.getRandom().nextInt(player.getHealth() - 10)); - UserManager.getPlayer(player).actualizeLastChimaeraTeleport(); + mcMMOPlayer.actualizeLastChimaeraTeleport(); return; } } + mcMMOPlayer.actualizeChimaeraCommenceLocation(player); - if (player.getBedSpawnLocation() != null) { - player.teleport(player.getBedSpawnLocation()); + long warmup = Config.getInstance().getChimaeraWarmup(); + player.sendMessage(ChatColor.GRAY + "Commencing teleport in " + ChatColor.GOLD + "(" + warmup + ")" + ChatColor.GRAY + " seconds, please stand still..."); //TODO Locale! + new ChimaeraWingWarmup(mcMMOPlayer).runTaskLater(mcMMO.p, 20 * warmup); + } + } + + public static void chimaeraExecuteTeleport() { + Player player = mcMMOPlayer.getPlayer(); + + if (player.getBedSpawnLocation() != null) { + player.teleport(player.getBedSpawnLocation()); + } + else { + Location spawnLocation = player.getWorld().getSpawnLocation(); + if (spawnLocation.getBlock().getType() == Material.AIR) { + player.teleport(spawnLocation); } else { - Location spawnLocation = player.getWorld().getSpawnLocation(); - if (spawnLocation.getBlock().getType() == Material.AIR) { - player.teleport(spawnLocation); - } - else { - player.teleport(player.getWorld().getHighestBlockAt(spawnLocation).getLocation()); - } + player.teleport(player.getWorld().getHighestBlockAt(spawnLocation).getLocation()); } - - UserManager.getPlayer(player).actualizeLastChimaeraTeleport(); - MetricsManager.chimeraWingUsed(); - player.playSound(location, Sound.BAT_TAKEOFF, Misc.BAT_VOLUME, Misc.BAT_PITCH); - player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Pass")); } + + player.setItemInHand(new ItemStack(getChimaeraWing(player.getItemInHand().getAmount() - Config.getInstance().getChimaeraUseCost()))); + UserManager.getPlayer(player).actualizeLastChimaeraTeleport(); + MetricsManager.chimeraWingUsed(); + player.playSound(location, Sound.BAT_TAKEOFF, Misc.BAT_VOLUME, Misc.BAT_PITCH); + player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Pass")); } public static ItemStack getChimaeraWing(int amount) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f0361cafc..89b95e8e4 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -73,6 +73,7 @@ Items: Chimaera_Wing: Enabled: true Cooldown: 240 + Warmup: 5 Prevent_Use_Underground: true Use_Cost: 1 Recipe_Cost: 5