Browse Source

Improving Chimaera Wing - part 2

 * Added a warmup before using a Chimaera Wing
 * Closes #740
TfT_02 12 years ago
parent
commit
5b5b73cde0

+ 1 - 0
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 getChimaeraEnabled() { return config.getBoolean("Items.Chimaera_Wing.Enabled", true); }
     public boolean getChimaeraPreventUseUnderground() { return config.getBoolean("Items.Chimaera_Wing.Prevent_Use_Underground", 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 getChimaeraCooldown() { return config.getInt("Items.Chimaera_Wing.Cooldown", 240); }
+    public int getChimaeraWarmup() { return config.getInt("Items.Chimaera_Wing.Warmup", 5); }
 
 
     /* Particles */
     /* Particles */
     public boolean getAbilityActivationEffectEnabled() { return config.getBoolean("Particles.Ability_Activation", true); }
     public boolean getAbilityActivationEffectEnabled() { return config.getBoolean("Particles.Ability_Activation", true); }

+ 15 - 1
src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java

@@ -5,6 +5,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.Set;
 
 
 import org.bukkit.GameMode;
 import org.bukkit.GameMode;
+import org.bukkit.Location;
 import org.bukkit.entity.Player;
 import org.bukkit.entity.Player;
 import org.bukkit.inventory.ItemStack;
 import org.bukkit.inventory.ItemStack;
 
 
@@ -78,8 +79,10 @@ public class McMMOPlayer {
     private Map<ToolType, Boolean> toolMode = new HashMap<ToolType, Boolean>();
     private Map<ToolType, Boolean> toolMode = new HashMap<ToolType, Boolean>();
     private Map<ToolType, Integer> toolATS  = new HashMap<ToolType, Integer>();
     private Map<ToolType, Integer> toolATS  = new HashMap<ToolType, Integer>();
 
 
-    private int recentlyHurt;
     private int chimaeraWing;
     private int chimaeraWing;
+    private Location chimaeraWingCommence;
+
+    private int recentlyHurt;
     private int respawnATS;
     private int respawnATS;
 
 
     public McMMOPlayer(Player player) {
     public McMMOPlayer(Player player) {
@@ -315,6 +318,17 @@ public class McMMOPlayer {
         chimaeraWing = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
         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
      * Exploit Prevention

+ 49 - 0
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);
+    }
+}

+ 41 - 20
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.inventory.meta.ItemMeta;
 import org.bukkit.util.Vector;
 import org.bukkit.util.Vector;
 
 
+import com.gmail.nossr50.mcMMO;
 import com.gmail.nossr50.config.Config;
 import com.gmail.nossr50.config.Config;
+import com.gmail.nossr50.datatypes.player.McMMOPlayer;
 import com.gmail.nossr50.locale.LocaleLoader;
 import com.gmail.nossr50.locale.LocaleLoader;
 import com.gmail.nossr50.metrics.MetricsManager;
 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.player.UserManager;
 import com.gmail.nossr50.util.skills.CombatUtils;
 import com.gmail.nossr50.util.skills.CombatUtils;
 import com.gmail.nossr50.util.skills.SkillUtils;
 import com.gmail.nossr50.util.skills.SkillUtils;
 
 
 public final class ChimaeraWing {
 public final class ChimaeraWing {
+    private static McMMOPlayer mcMMOPlayer;
+    private static Location location;
+
     private ChimaeraWing() {}
     private ChimaeraWing() {}
 
 
     /**
     /**
@@ -35,12 +41,18 @@ public final class ChimaeraWing {
             return;
             return;
         }
         }
 
 
-        Location location = player.getLocation();
+        mcMMOPlayer = UserManager.getPlayer(player);
+
+        location = player.getLocation();
         int amount = inHand.getAmount();
         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 (Permissions.chimaeraWing(player) && ItemUtils.isChimaeraWing(inHand)) {
+            if (mcMMOPlayer.getChimaeraCommenceLocation() != null) {
+                return;
+            }
+
             if (!SkillUtils.cooldownOver(lastChimaeraWing * Misc.TIME_CONVERSION_FACTOR, Config.getInstance().getChimaeraCooldown(), player)) {
             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!
                 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;
                 return;
@@ -56,37 +68,46 @@ public final class ChimaeraWing {
                 return;
                 return;
             }
             }
 
 
-            player.setItemInHand(new ItemStack(getChimaeraWing(amount - Config.getInstance().getChimaeraUseCost())));
-
             if (Config.getInstance().getChimaeraPreventUseUnderground()) {
             if (Config.getInstance().getChimaeraPreventUseUnderground()) {
 
 
                 if (location.getY() < player.getWorld().getHighestBlockYAt(location)) {
                 if (location.getY() < player.getWorld().getHighestBlockYAt(location)) {
+                    player.setItemInHand(new ItemStack(getChimaeraWing(amount - Config.getInstance().getChimaeraUseCost())));
                     player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Fail"));
                     player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Fail"));
                     player.setVelocity(new Vector(0, 0.5D, 0));
                     player.setVelocity(new Vector(0, 0.5D, 0));
                     CombatUtils.dealDamage(player, Misc.getRandom().nextInt(player.getHealth() - 10));
                     CombatUtils.dealDamage(player, Misc.getRandom().nextInt(player.getHealth() - 10));
-                    UserManager.getPlayer(player).actualizeLastChimaeraTeleport();
+                    mcMMOPlayer.actualizeLastChimaeraTeleport();
                     return;
                     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 {
             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) {
     public static ItemStack getChimaeraWing(int amount) {

+ 1 - 0
src/main/resources/config.yml

@@ -73,6 +73,7 @@ Items:
     Chimaera_Wing:
     Chimaera_Wing:
         Enabled: true
         Enabled: true
         Cooldown: 240
         Cooldown: 240
+        Warmup: 5
         Prevent_Use_Underground: true
         Prevent_Use_Underground: true
         Use_Cost: 1
         Use_Cost: 1
         Recipe_Cost: 5
         Recipe_Cost: 5