Sfoglia il codice sorgente

Improving Chimaera Wing - part 1

 * Added cooldown between using Chimaera Wings
 * Added shapeless recipe to craft a Chimaera Wing (by default 5
feathers)
TfT_02 12 anni fa
parent
commit
a07f14e326

+ 2 - 0
Changelog.txt

@@ -10,6 +10,7 @@ Key:
 Version 1.4.03-dev
  + Added option to advanced.yml to determine the # of enchant levels used when buffing Super Breaker & Giga Drill Breaker
  + Improved stats display for child skills
+ + Added cooldown between using Chimaera Wings
  = Fixed bug with Smelting not properly tracking furnaces
  = Fixed bug with Blast Mining not dropping blocks correctly
  = Fixed bug with custom blocks not working
@@ -25,6 +26,7 @@ Version 1.4.03-dev
  = Fixed bug where the 'mcmmo.commands.ptp.world.all' was registered twice
  = Fixed bug where Beast Lore wouldn't work on friendly pets
  ! Moved the Salvage unlock level from config.yml to advanced.yml
+ ! Changed how Chimaera Wings are acquired, you need to craft them now. (By default, use 5 feathers in a shapeless recipe)
  - Removed option to disable Salvage via the config file. This should be handled via permissions instead.
  - Removed the option to use Woodcutting without an axe from the config file.
 

+ 4 - 1
src/main/java/com/gmail/nossr50/config/Config.java

@@ -101,9 +101,12 @@ public class Config extends AutoUpdateConfigLoader {
     public boolean getEntityModsEnabled() { return config.getBoolean("Mods.Entity_Mods_Enabled", false); }
 
     /* Items */
-    public int getChimaeraCost() { return config.getInt("Items.Chimaera_Wing.Feather_Cost", 10); }
+    public int getChimaeraUseCost() { return config.getInt("Items.Chimaera_Wing.Use_Cost", 1); }
+    public int getChimaeraRecipeCost() { return config.getInt("Items.Chimaera_Wing.Recipe_Cost", 5); }
     public int getChimaeraItemId() { return config.getInt("Items.Chimaera_Wing.Item_ID", 288); }
     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); }
 
     /* Particles */
     public boolean getAbilityActivationEffectEnabled() { return config.getBoolean("Particles.Ability_Activation", true); }

+ 18 - 0
src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java

@@ -79,6 +79,7 @@ public class McMMOPlayer {
     private Map<ToolType, Integer> toolATS  = new HashMap<ToolType, Integer>();
 
     private int recentlyHurt;
+    private int chimaeraWing;
     private int respawnATS;
 
     public McMMOPlayer(Player player) {
@@ -298,6 +299,23 @@ public class McMMOPlayer {
         recentlyHurt = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
     }
 
+    /*
+     * Chimaera Wing
+     */
+
+    public int getLastChimaeraTeleport() {
+        return chimaeraWing;
+    }
+
+    public void setLastChimaeraTeleport(int value) {
+        chimaeraWing = value;
+    }
+
+    public void actualizeLastChimaeraTeleport() {
+        chimaeraWing = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
+    }
+
+
     /*
      * Exploit Prevention
      */

+ 8 - 0
src/main/java/com/gmail/nossr50/mcMMO.java

@@ -48,6 +48,7 @@ import com.gmail.nossr50.skills.repair.Repairable;
 import com.gmail.nossr50.skills.repair.RepairableManager;
 import com.gmail.nossr50.skills.repair.RepairableManagerFactory;
 import com.gmail.nossr50.skills.repair.config.RepairConfigManager;
+import com.gmail.nossr50.util.ChimaeraWing;
 import com.gmail.nossr50.util.LogFilter;
 import com.gmail.nossr50.util.Permissions;
 import com.gmail.nossr50.util.UpdateChecker;
@@ -114,6 +115,7 @@ public class mcMMO extends JavaPlugin {
             }
 
             registerEvents();
+            registerCustomRecipes();
 
             // Setup the leader boards
             if (Config.getInstance().getUseMySQL()) {
@@ -433,6 +435,12 @@ public class mcMMO extends JavaPlugin {
         CommandRegistrationManager.registerMchudCommand();
     }
 
+    private void registerCustomRecipes() {
+        if (Config.getInstance().getChimaeraEnabled()) {
+            getServer().addRecipe(ChimaeraWing.getChimaeraWingRecipe());
+        }
+    }
+
     private void scheduleTasks() {
         BukkitScheduler scheduler = getServer().getScheduler();
 

+ 52 - 13
src/main/java/com/gmail/nossr50/util/ChimaeraWing.java

@@ -1,9 +1,15 @@
 package com.gmail.nossr50.util;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import org.bukkit.ChatColor;
 import org.bukkit.Material;
 import org.bukkit.block.Block;
 import org.bukkit.entity.Player;
 import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.ShapelessRecipe;
+import org.bukkit.inventory.meta.ItemMeta;
 
 import com.gmail.nossr50.config.Config;
 import com.gmail.nossr50.locale.LocaleLoader;
@@ -22,23 +28,31 @@ public final class ChimaeraWing {
     public static void activationCheck(Player player) {
         ItemStack inHand = player.getItemInHand();
 
-        if (!Config.getInstance().getChimaeraEnabled() || inHand.getTypeId() != Config.getInstance().getChimaeraItemId()) {
+        if (!Config.getInstance().getChimaeraEnabled() || !ItemUtils.isChimaeraWing(inHand)) {
             return;
         }
 
         Block block = player.getLocation().getBlock();
         int amount = inHand.getAmount();
-        long recentlyHurt = UserManager.getPlayer(player).getRecentlyHurt() * Misc.TIME_CONVERSION_FACTOR;
+        long recentlyHurt = UserManager.getPlayer(player).getRecentlyHurt();
+        long lastChimaeraWing = (UserManager.getPlayer(player).getLastChimaeraTeleport());
+
+        if (Permissions.chimaeraWing(player) && ItemUtils.isChimaeraWing(inHand)) {
+            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;
+            }
 
-        if (Permissions.chimaeraWing(player) && inHand.getTypeId() == Config.getInstance().getChimaeraItemId()) {
-            if (SkillUtils.cooldownOver(recentlyHurt, 60, player) && amount >= Config.getInstance().getChimaeraCost()) {
-                player.setItemInHand(new ItemStack(Config.getInstance().getChimaeraItemId(), amount - Config.getInstance().getChimaeraCost()));
+            if (SkillUtils.cooldownOver(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, 60, player) && amount >= Config.getInstance().getChimaeraUseCost()) {
+                player.setItemInHand(new ItemStack(getChimaeraWing(amount - Config.getInstance().getChimaeraUseCost())));
 
-                for (int y = 1; block.getY() + y < player.getWorld().getMaxHeight(); y++) {
-                    if (!(block.getRelative(0, y, 0).getType() == Material.AIR)) {
-                        player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Fail"));
-                        player.teleport(block.getRelative(0, y - 1, 0).getLocation());
-                        return;
+                if (Config.getInstance().getChimaeraPreventUseUnderground()) {
+                    for (int y = 1; block.getY() + y < player.getWorld().getMaxHeight(); y++) {
+                        if (!(block.getRelative(0, y, 0).getType() == Material.AIR)) {
+                            player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Fail"));
+                            player.teleport(block.getRelative(0, y - 1, 0).getLocation());
+                            return;
+                        }
                     }
                 }
 
@@ -49,15 +63,40 @@ public final class ChimaeraWing {
                     player.teleport(player.getWorld().getSpawnLocation());
                 }
 
+                UserManager.getPlayer(player).actualizeLastChimaeraTeleport();
                 MetricsManager.chimeraWingUsed();
                 player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Pass"));
             }
-            else if (!SkillUtils.cooldownOver(recentlyHurt, 60, player) && amount >= Config.getInstance().getChimaeraCost()) {
+            else if (!SkillUtils.cooldownOver(recentlyHurt, 60 * Misc.TIME_CONVERSION_FACTOR, player) && amount >= Config.getInstance().getChimaeraUseCost()) {
                 player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", SkillUtils.calculateTimeLeft(recentlyHurt, 60, player)));
             }
-            else if (amount <= Config.getInstance().getChimaeraCost()) {
-                player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(Config.getInstance().getChimaeraItemId())));
+            else if (amount <= Config.getInstance().getChimaeraUseCost()) {
+                player.sendMessage(LocaleLoader.getString("Skills.NeedMore", "Chimaera Wings")); //TODO Locale!
             }
         }
     }
+
+    public static ItemStack getChimaeraWing(int amount) {
+        ItemStack itemStack = new ItemStack(Material.FEATHER, amount);
+        ItemMeta itemMeta = itemStack.getItemMeta();
+        itemMeta.setDisplayName(ChatColor.GOLD + "Chimaera Wing"); //TODO Locale!
+        List<String> itemLore = new ArrayList<String>();
+        itemLore.add("mcMMO Item");
+        itemLore.add(ChatColor.GRAY + "Teleports you to your bed."); //TODO Locale!
+        itemMeta.setLore(itemLore);
+        itemStack.setItemMeta(itemMeta);
+        return itemStack;
+    }
+
+    public static ShapelessRecipe getChimaeraWingRecipe() {
+        Material ingredient = Material.getMaterial(Config.getInstance().getChimaeraItemId());
+        int amount = Config.getInstance().getChimaeraRecipeCost();
+        if (amount > 9) {
+            amount = 9;
+        }
+
+        ShapelessRecipe ChimaeraWing = new ShapelessRecipe(getChimaeraWing(1));
+        ChimaeraWing.addIngredient(amount, ingredient);
+        return ChimaeraWing;
+    }
 }

+ 28 - 0
src/main/java/com/gmail/nossr50/util/ItemUtils.java

@@ -1,8 +1,12 @@
 package com.gmail.nossr50.util;
 
+import java.util.List;
+
+import org.bukkit.ChatColor;
 import org.bukkit.DyeColor;
 import org.bukkit.Material;
 import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
 
 import com.gmail.nossr50.mcMMO;
 import com.gmail.nossr50.api.SpoutToolsAPI;
@@ -644,4 +648,28 @@ public class ItemUtils {
                 return false;
         }
     }
+
+    public static boolean isMcMMOItem(ItemStack is) {
+        ItemMeta itemMeta = is.getItemMeta();
+        if (itemMeta.hasLore()) {
+            List<String> itemLore = itemMeta.getLore();
+            if (itemLore.contains("mcMMO Item")) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public static boolean isChimaeraWing(ItemStack is) {
+        if (!isMcMMOItem(is)) {
+            return false;
+        }
+
+        ItemMeta itemMeta = is.getItemMeta();
+        if (itemMeta.hasDisplayName() && itemMeta.getDisplayName().equals(ChatColor.GOLD + "Chimaera Wing")) { //TODO Get localized name
+            return true;
+        }
+
+        return false;
+    }
 }

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

@@ -72,7 +72,9 @@ Mods:
 Items:
     Chimaera_Wing:
         Enabled: true
-        Feather_Cost: 10
+        Prevent_Use_Underground: true
+        Use_Cost: 1
+        Recipe_Cost: 5
         Item_ID: 288
 
 #