diff --git a/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java b/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java index a96e268..958dbf9 100644 --- a/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java +++ b/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java @@ -20,6 +20,8 @@ import net.milkbowl.vault.economy.EconomyResponse; + + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Chunk; @@ -9676,16 +9678,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. @@ -9703,7 +9705,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 } @@ -9711,18 +9713,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 @@ -9730,7 +9732,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() @@ -9738,12 +9740,32 @@ implements Listener event.getInventory().getContents()[OUTPUT]) .isEmpty()) { - Bukkit.getLogger().info("Can place into inventory."); + // 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 lore = anvilInv.getItem(INPUT).getItemMeta().getLore(); + for (int i=0;i maxItemsNeeded) { - // Bukkit.getLogger().info("Materials exceed " + maxItemsNeeded + " stack. Dropping " + (anvilInv.getItem(MATERIALS).getAmount() - maxItemsNeeded) + " of " + anvilInv.getItem(MATERIALS).getType()); + // // Bukkit.getLogger().info("Materials exceed " + maxItemsNeeded + " stack. Dropping " + (anvilInv.getItem(MATERIALS).getAmount() - maxItemsNeeded) + " of " + anvilInv.getItem(MATERIALS).getType()); sendToInventory(MATERIALS, anvilInv.getItem(MATERIALS).getAmount() - maxItemsNeeded, player); @@ -13047,24 +13131,24 @@ class updateInventoryTask implements Runnable { int bonus_cost = 0; ItemStack item = anvilInv.getContents()[INPUT]; - Bukkit.getLogger().warning("Repair cost calculation valid"); + // Bukkit.getLogger().warning("Repair cost calculation valid"); Map enchantments = item.getEnchantments(); - Bukkit.getLogger().warning(enchantments.keySet().toString()); + // Bukkit.getLogger().warning(enchantments.keySet().toString()); for (Enchantment e : enchantments.keySet()) { - Bukkit.getLogger().warning("BC: " + bonus_cost + " | INCR: " + 2 + enchantments.get(e)); + // Bukkit.getLogger().warning("BC: " + bonus_cost + " | INCR: " + 2 + enchantments.get(e)); bonus_cost += (2 + enchantments.get(e)); } cost += bonus_cost; - Bukkit.getLogger().info("Raw cost: " + cost); + // Bukkit.getLogger().info("Raw cost: " + cost); cost = (short) Math.floor(cost * multiplier); cost = Math.min(cost, 60); // Cap cost at 60 in case some egregiously enchanted item exists cost = Math.max(cost, 1); // Make sure it's at least one level - Bukkit.getLogger().info("Cost: " + cost); + // Bukkit.getLogger().info("Cost: " + cost); ItemStack orbs = new ItemStack(Material.SLIME_BALL); @@ -13094,7 +13178,7 @@ class updateInventoryTask implements Runnable { // anvilInv.getContents()[OUTPUT].setData(item.getData()); anvilInv.setItem(OUTPUT, item.clone()); - anvilInv.getContents()[OUTPUT].setDurability((short) (item.getDurability() - item.getType().getMaxDurability() * 0.2 * anvilInv.getContents()[MATERIALS].getAmount())); + anvilInv.getContents()[OUTPUT].setDurability((short) (item.getDurability() - item.getType().getMaxDurability() * repairMultiplier * anvilInv.getContents()[MATERIALS].getAmount())); } @@ -13120,16 +13204,16 @@ class updateInventoryTask implements Runnable { if (anvilInv.getItem(INPUT).getItemMeta().hasLore()) { for (int i = 0; i < anvilInv.getItem(INPUT).getItemMeta().getLore().size(); i++) { // Put enchantments together for the input. Also stacks identical enchantments. - Bukkit.getLogger().info("Iterating bonus: " + anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)); + // Bukkit.getLogger().info("Iterating bonus: " + anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)); if (getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)) != null) { if (itemBonuses.get(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))) == null) { - Bukkit.getLogger().info("New bonus: " + getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))); + // Bukkit.getLogger().info("New bonus: " + getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))); itemBonuses.put(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)), getEnchantmentNumb(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))); } else { - Bukkit.getLogger().info("Stacking bonus: " + itemBonuses.get(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))) + " + " + getEnchantmentNumb(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))); + // Bukkit.getLogger().info("Stacking bonus: " + itemBonuses.get(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))) + " + " + getEnchantmentNumb(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))); itemBonuses.put(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)), itemBonuses.get(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))) + getEnchantmentNumb(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))); } } @@ -13139,14 +13223,14 @@ class updateInventoryTask implements Runnable { if (anvilInv.getItem(MAGIC).getItemMeta().hasLore()) { for (int i = 0; i < anvilInv.getItem(MAGIC).getItemMeta().getLore().size(); i++) { // Put enchantments together for the MAGIC. Also stacks identical enchantments. - Bukkit.getLogger().info("Iterating bonus: " + anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)); + // Bukkit.getLogger().info("Iterating bonus: " + anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)); if (bookBonuses.get(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))) == null) { - Bukkit.getLogger().info("New bonus: " + getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))); + // Bukkit.getLogger().info("New bonus: " + getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))); bookBonuses.put(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)), getEnchantmentNumb(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))); } else { - Bukkit.getLogger().info("Stacking bonus: " + bookBonuses.get(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))) + " + " + getEnchantmentNumb(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))); + // Bukkit.getLogger().info("Stacking bonus: " + bookBonuses.get(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))) + " + " + getEnchantmentNumb(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))); bookBonuses.put(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)), bookBonuses.get(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))) + getEnchantmentNumb(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))); } } @@ -13156,12 +13240,12 @@ class updateInventoryTask implements Runnable { Map probableEnchantments = new java.util.HashMap(); for (Enchantment e : bookEnchantments.keySet()) { - Bukkit.getLogger().info("Iterating enchantment: " + e); + // Bukkit.getLogger().info("Iterating enchantment: " + e); if (itemEnchantments.get(e) == null || bookEnchantments.get(e) > itemEnchantments.get(e)) { // Book enchantment is larger in magnitude. Assign it as a possible outcome. probableEnchantments.put(e, bookEnchantments.get(e)); - } else if (bookEnchantments.get(e) == itemEnchantments.get(e)) { + } else if (bookEnchantments.get(e) == itemEnchantments.get(e) && bookEnchantments.get(e) <= 10) { // Book enchantment is same in magnitude. Upgrade by one level. probableEnchantments.put(e, bookEnchantments.get(e) + 1); } @@ -13171,7 +13255,7 @@ class updateInventoryTask implements Runnable { Map probableBonuses = new java.util.HashMap(); for (String e : bookBonuses.keySet()) { - Bukkit.getLogger().info("Iterating bonus: " + e); + // Bukkit.getLogger().info("Iterating bonus: " + e); if (itemBonuses.get(e) == null) { // Book enchantment is new. Assign it as a possible outcome. @@ -13190,7 +13274,7 @@ class updateInventoryTask implements Runnable { if (probableEnchantments.size() != 0) { // Randomly select an enchantment to add. int random = (int)(Math.random() * probableEnchantments.size()); - Bukkit.getLogger().info("Randomized to # " + (random + 1) + " out of " + probableEnchantments.size()); + // Bukkit.getLogger().info("Randomized to # " + (random + 1) + " out of " + probableEnchantments.size()); int i = 0; @@ -13338,8 +13422,12 @@ class updateInventoryTask implements Runnable { // Change entry matching modified lore ItemMeta bonusesMeta = anvilInv.getItem(OUTPUT).getItemMeta(); List bonusesLore = bonusesMeta.getLore(); + if (bonusesLore == null) + { + bonusesLore = new ArrayList(); + } - Bukkit.getLogger().info("Bonus enchantment string: " + appliedEnchant); + // Bukkit.getLogger().info("Bonus enchantment string: " + appliedEnchant); if (appliedEnchant.equalsIgnoreCase("Critical Chance")) { bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Critical Chance"); } @@ -13413,8 +13501,8 @@ class updateInventoryTask implements Runnable { String e = bonusesLore.get(i1); if (containsEnchantment(e, appliedEnchant)) { - Bukkit.getLogger().info("Success! Found enchantment: " + e); - Bukkit.getLogger().info("Bonus enchantment: " + appliedEnchant); + // Bukkit.getLogger().info("Success! Found enchantment: " + e); + // Bukkit.getLogger().info("Bonus enchantment: " + appliedEnchant); if (appliedEnchant.equalsIgnoreCase("Critical Chance")) { bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Critical Chance"); @@ -13459,7 +13547,7 @@ class updateInventoryTask implements Runnable { player.getInventory().setContents(player.getInventory().getContents()); anvilInv.setContents(anvilInv.getContents()); player.updateInventory(); - } else if (anvilInv.getItem(MAGIC).getType() == Material.BOOK) { + } else if (anvilInv.getItem(MAGIC).getType() == Material.BOOK && anvilInv.getItem(INPUT).getType() != Material.ENCHANTED_BOOK) { // Magic slot is a book. Unenchanting logic goes here. anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone()); anvilInv.getItem(OUTPUT).setType(Material.ENCHANTED_BOOK); @@ -13471,7 +13559,13 @@ class updateInventoryTask implements Runnable { sendToInventory(MAGIC, anvilInv.getItem(MAGIC).getAmount() - 1, player); } - int cost = 1; + int cost = 12; + + Map enchantments = anvilInv.getItem(INPUT).getEnchantments(); + + for (Enchantment e : enchantments.keySet()) { + cost += (1 + enchantments.get(e)); + } ItemStack orbs = new ItemStack(Material.SLIME_BALL); @@ -13507,9 +13601,9 @@ class updateInventoryTask implements Runnable { } public void sendToInventory(int slot, int itemCount, Player player) { - Bukkit.getLogger().info("Slot: " + slot); - Bukkit.getLogger().info("Item Count: " + itemCount); - Bukkit.getLogger().info("Player: " + player.getDisplayName()); + // Bukkit.getLogger().info("Slot: " + slot); + // Bukkit.getLogger().info("Item Count: " + itemCount); + // Bukkit.getLogger().info("Player: " + player.getDisplayName()); // Get inventories Inventory anvilInventory = player.getOpenInventory().getTopInventory(); @@ -13527,16 +13621,16 @@ class updateInventoryTask implements Runnable { } - Bukkit.getLogger().info("Slot stack size is " + anvilInventory.getItem(slot).getAmount()); + // Bukkit.getLogger().info("Slot stack size is " + anvilInventory.getItem(slot).getAmount()); if (anvilInventory.getItem(slot).getAmount() - itemCount == 0) { // Should reduce stack count to zero, meaning item needs to be removed. - Bukkit.getLogger().info("Item stack size reduced to 0, " + anvilInventory.getItem(slot).getType().toString() + " removed."); + // Bukkit.getLogger().info("Item stack size reduced to 0, " + anvilInventory.getItem(slot).getType().toString() + " removed."); anvilInventory.setItem(slot, new ItemStack(Material.AIR)); } else { // Should set stack size. - Bukkit.getLogger().info("Reduced stack size from " + anvilInventory.getItem(slot).getAmount() + " by " + itemCount); + // Bukkit.getLogger().info("Reduced stack size from " + anvilInventory.getItem(slot).getAmount() + " by " + itemCount); anvilInventory.getItem(slot).setAmount(anvilInventory.getItem(slot).getAmount() - itemCount); } // player.getWorld().dropItemNaturally(player.getLocation(), new ItemStack(anvilInv.getItem(MATERIALS).getType(), anvilInv.getItem(MATERIALS).getAmount() - maxItemsNeeded)); @@ -13548,7 +13642,7 @@ class updateInventoryTask implements Runnable { String[] enchant = s.split(" "); if (enchant[0].contains(ChatColor.YELLOW+"")) { String newstring = ((enchant[0].replace(ChatColor.YELLOW.getChar(), ' ')).replace('%', ' ')).replace(Character.toString((char)0x00A7), Character.toString((char)0x0020)); - //Bukkit.getLogger().info("Enchant number is "+Double.valueOf(newstring)); + // Bukkit.getLogger().info("Enchant number is "+Double.valueOf(newstring)); return Double.valueOf(newstring); } else { return 0;