From 52dc2d0e7a7f119040648bb01dcaa076b381c7f4 Mon Sep 17 00:00:00 2001 From: Nonoriri Date: Sun, 24 Nov 2013 16:14:42 -0500 Subject: [PATCH] Fixed a merging error that somehow slipped through. Disenchanting will now properly keep items a percentage of the time. --- .../src/me/kaZep/Base/PlayerListener.java | 150 +++++++++++++++--- 1 file changed, 126 insertions(+), 24 deletions(-) diff --git a/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java b/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java index eff3278..10041e0 100644 --- a/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java +++ b/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java @@ -9881,16 +9881,16 @@ implements Listener final int LEVELS = 22; boolean anvilClicked = false; - Bukkit.getLogger().info("Anvil interface CLICK at slot #" + event.getRawSlot()); + // Bukkit.getLogger().info("Anvil interface CLICK at slot #" + event.getRawSlot()); if (event.getRawSlot() == -999) { anvilClicked = false; - Bukkit.getLogger().info("Window exterior clicked."); + // Bukkit.getLogger().info("Window exterior clicked."); } else if (event.getRawSlot() < 27) { anvilClicked = true; - Bukkit.getLogger().info("Anvil clicked."); + // Bukkit.getLogger().info("Anvil clicked."); } else { - Bukkit.getLogger().info("Inventory clicked."); + // Bukkit.getLogger().info("Inventory clicked."); } if (!anvilClicked) { // Clicked the inventory. Leave the operation alone UNLESS it's a shift-click operation. @@ -9908,7 +9908,7 @@ implements Listener */ if (event.getSlot() == OUTPUT && event.getCursor() != null && event.getCursor().getType() != Material.AIR && !matches(event.getCursor(), event.getCurrentItem())){ - Bukkit.getLogger().info("Anvil OUTPUT click."); + // Bukkit.getLogger().info("Anvil OUTPUT click."); event.setCancelled(true); // Cancel the event if trying to put items into the output slot } @@ -9916,18 +9916,18 @@ implements Listener if (event.getInventory().getContents()[OUTPUT] != null && event.getSlot() == OUTPUT) { - Bukkit.getLogger().info("Anvil OUTPUT click with output populated."); + // Bukkit.getLogger().info("Anvil OUTPUT click with output populated."); if (event.getInventory().getContents()[LEVELS].getAmount() > Bukkit.getPlayer(event.getWhoClicked().getName()).getLevel()) { // Player doesn't have enough XP, abort - Bukkit.getLogger().info("Player has insufficient XP."); + // Bukkit.getLogger().info("Player has insufficient XP."); p.sendMessage(ChatColor.RED+"You don't have enough experience to do that!"); event.setCancelled(true); } else { - Bukkit.getLogger().info("Player has sufficient XP."); + // Bukkit.getLogger().info("Player has sufficient XP."); if (event.getCursor() != null && event.getCursor().getType() != Material.AIR) { - Bukkit.getLogger().info("Anvil OUTPUT click with non-null mouse. Mouse has: " + event.getCursor()); + // Bukkit.getLogger().info("Anvil OUTPUT click with non-null mouse. Mouse has: " + event.getCursor()); event.setCancelled(true); // Cancel event if cursor is not empty @@ -9935,7 +9935,7 @@ implements Listener // Attempts to store the item in the player's inventory. // If it succeeds, remove the item from the anvil // interface. - Bukkit.getLogger().info("Shift-click"); + // Bukkit.getLogger().info("Shift-click"); if (event .getWhoClicked() .getInventory() @@ -9943,16 +9943,48 @@ implements Listener event.getInventory().getContents()[OUTPUT]) .isEmpty()) { - Bukkit.getLogger().info("Can place into inventory."); - - event.getInventory().setItem(INPUT, new ItemStack(Material.AIR)); + // Bukkit.getLogger().info("Can place into inventory."); + + if (event.getCurrentItem().getType() == Material.ENCHANTED_BOOK && event.getInventory().getItem(MAGIC).getType() == Material.BOOK) { + // Halve its durability + event.getInventory().getItem(INPUT).setDurability((short)(event.getInventory().getItem(INPUT).getDurability() + (event.getInventory().getItem(INPUT).getType().getMaxDurability() - event.getInventory().getItem(INPUT).getDurability()) / 2)); + + // DISENCHANT BEGIN + Map map = event.getInventory().getItem(INPUT).getEnchantments(); + for (Map.Entry entry : map.entrySet()) { + event.getInventory().getItem(INPUT).removeEnchantment(entry.getKey()); + } + if (event.getInventory().getItem(INPUT).hasItemMeta() && event.getInventory().getItem(INPUT).getItemMeta().hasLore()) { + List newlore = new ArrayList(); + for (int i=0;i map = event.getInventory().getItem(INPUT).getEnchantments(); + for (Map.Entry entry : map.entrySet()) { + event.getInventory().getItem(INPUT).removeEnchantment(entry.getKey()); + } + if (event.getInventory().getItem(INPUT).hasItemMeta() && event.getInventory().getItem(INPUT).getItemMeta().hasLore()) { + List newlore = new ArrayList(); + for (int i=0;i map = event.getInventory().getItem(INPUT).getEnchantments(); + for (Map.Entry entry : map.entrySet()) { + event.getInventory().getItem(INPUT).removeEnchantment(entry.getKey()); + } + if (event.getInventory().getItem(INPUT).hasItemMeta() && event.getInventory().getItem(INPUT).getItemMeta().hasLore()) { + List newlore = new ArrayList(); + for (int i=0;i