Anvil changes added to master.

master_event
Nonoriri 11 years ago
parent 287328e29a
commit 84c305dd9c
  1. 715
      BankEconomyMod/src/me/kaZep/Base/PlayerListener.java

@ -12990,6 +12990,7 @@ implements Listener
class updateInventoryTask implements Runnable { class updateInventoryTask implements Runnable {
String playerName; String playerName;
double repairMultiplier, experienceMultiplier;
public updateInventoryTask(String pl){ public updateInventoryTask(String pl){
playerName = pl; playerName = pl;
@ -12997,7 +12998,7 @@ class updateInventoryTask implements Runnable {
@Override @Override
public void run() { public void run() {
Bukkit.getLogger().info("Runnable task run() called; player name: " + playerName); // Bukkit.getLogger().info("Runnable task run() called; player name: " + playerName);
Player player = Bukkit.getPlayer(playerName); Player player = Bukkit.getPlayer(playerName);
Inventory anvilInv = player.getOpenInventory().getTopInventory(); Inventory anvilInv = player.getOpenInventory().getTopInventory();
@ -13008,6 +13009,10 @@ class updateInventoryTask implements Runnable {
final int OUTPUT = 16; final int OUTPUT = 16;
final int LEVELS = 22; final int LEVELS = 22;
// Apply cost reductions for specialists
repairMultiplier = 0.2; // Set to 0.25 if Blacksmith/Weaponsmith
experienceMultiplier = 1; // Halve for enchanters (maybe? balance issue), reduce substantially for tinkerers
// Redundant validation code for verification // Redundant validation code for verification
@ -13016,13 +13021,13 @@ class updateInventoryTask implements Runnable {
anvilInv.getItem(INPUT).getType().toString().toUpperCase().contains("LEGGINGS") || anvilInv.getItem(INPUT).getType().toString().toUpperCase().contains("BOOTS") || anvilInv.getItem(INPUT).getType().toString().toUpperCase().contains("LEGGINGS") || anvilInv.getItem(INPUT).getType().toString().toUpperCase().contains("BOOTS") ||
anvilInv.getItem(INPUT).getType().toString().toUpperCase().contains("PICKAXE") || anvilInv.getItem(INPUT).getType().toString().toUpperCase().contains("SPADE") || anvilInv.getItem(INPUT).getType().toString().toUpperCase().contains("PICKAXE") || anvilInv.getItem(INPUT).getType().toString().toUpperCase().contains("SPADE") ||
anvilInv.getItem(INPUT).getType().toString().toUpperCase().contains("HOE") || anvilInv.getItem(INPUT).getType().toString().toUpperCase().contains("AXE") || anvilInv.getItem(INPUT).getType().toString().toUpperCase().contains("HOE") || anvilInv.getItem(INPUT).getType().toString().toUpperCase().contains("AXE") ||
anvilInv.getItem(INPUT).getType().toString().toUpperCase().contains("SWORD") || anvilInv.getItem(INPUT).getType().toString().toUpperCase().contains("FISHING") || anvilInv.getItem(INPUT).getType().toString().toUpperCase().contains("SWORD") || anvilInv.getItem(INPUT).getType().toString().toUpperCase().contentEquals("FISHING") ||
anvilInv.getItem(INPUT).getType().toString().toUpperCase().contentEquals("BOW"))) { anvilInv.getItem(INPUT).getType().toString().toUpperCase().contentEquals("BOW") || anvilInv.getItem(INPUT).getType().toString().toUpperCase().contentEquals("ENCHANTED_BOOK"))) {
sendToInventory(INPUT, anvilInv.getItem(INPUT).getAmount(), player); sendToInventory(INPUT, anvilInv.getItem(INPUT).getAmount(), player);
Bukkit.getLogger().info("Invalid input!"); // Bukkit.getLogger().info("Invalid input!");
} else { } else {
Bukkit.getLogger().info("Valid input, " + anvilInv.getItem(INPUT).toString().toUpperCase() + " with durability " + anvilInv.getItem(INPUT).getDurability()); // Bukkit.getLogger().info("Valid input, " + anvilInv.getItem(INPUT).toString().toUpperCase() + " with durability " + anvilInv.getItem(INPUT).getDurability());
} }
} }
@ -13032,24 +13037,27 @@ class updateInventoryTask implements Runnable {
anvilInv.getItem(MATERIALS).getType() == Material.DIAMOND_BLOCK || anvilInv.getItem(MATERIALS).getType() == Material.DIAMOND || anvilInv.getItem(MATERIALS).getType() == Material.DIAMOND_BLOCK || anvilInv.getItem(MATERIALS).getType() == Material.DIAMOND ||
anvilInv.getItem(MATERIALS).getType() == Material.WOOD || anvilInv.getItem(MATERIALS).getType() == Material.COBBLESTONE || anvilInv.getItem(MATERIALS).getType() == Material.WOOD || anvilInv.getItem(MATERIALS).getType() == Material.COBBLESTONE ||
anvilInv.getItem(MATERIALS).getType() == Material.LOG || anvilInv.getItem(MATERIALS).getType() == Material.STONE || anvilInv.getItem(MATERIALS).getType() == Material.LOG || anvilInv.getItem(MATERIALS).getType() == Material.STONE ||
anvilInv.getItem(MATERIALS).getType() == Material.STRING)) { anvilInv.getItem(MATERIALS).getType() == Material.STRING || anvilInv.getItem(MATERIALS).getType() == Material.EMERALD ||
anvilInv.getItem(MATERIALS).getType() == Material.EMERALD_BLOCK || anvilInv.getItem(MATERIALS).getType() == Material.ENCHANTED_BOOK)) {
sendToInventory(MATERIALS, anvilInv.getItem(MATERIALS).getAmount(), player); sendToInventory(MATERIALS, anvilInv.getItem(MATERIALS).getAmount(), player);
Bukkit.getLogger().info("Invalid materials!"); // Bukkit.getLogger().info("Invalid materials!");
} else { } else if ((anvilInv.getItem(MATERIALS).getType() == Material.ENCHANTED_BOOK || anvilInv.getItem(MATERIALS).getType() == Material.BOOK) && anvilInv.getItem(MAGIC) == null) {
Bukkit.getLogger().info("Valid materials, " + anvilInv.getItem(MATERIALS).toString().toUpperCase() + " with durability " + anvilInv.getItem(MATERIALS).getDurability()); anvilInv.setItem(MAGIC, anvilInv.getItem(MATERIALS).clone());
anvilInv.setItem(MATERIALS, new ItemStack(Material.AIR));
// Bukkit.getLogger().info("Valid materials, " + anvilInv.getItem(MATERIALS).toString().toUpperCase() + " with durability " + anvilInv.getItem(MATERIALS).getDurability());
} }
} }
if (anvilInv.getItem(MAGIC) != null) { if (anvilInv.getItem(MAGIC) != null) {
if (!(anvilInv.getItem(MAGIC).getType() == Material.ENCHANTED_BOOK)) { if (!(anvilInv.getItem(MAGIC).getType() == Material.ENCHANTED_BOOK || anvilInv.getItem(MAGIC).getType() == Material.BOOK)) {
sendToInventory(MAGIC, anvilInv.getItem(MAGIC).getAmount(), player); sendToInventory(MAGIC, anvilInv.getItem(MAGIC).getAmount(), player);
Bukkit.getLogger().info("Invalid magic!"); // Bukkit.getLogger().info("Invalid magic!");
} else { } else {
Bukkit.getLogger().info("Valid magic, " + anvilInv.getItem(MAGIC).toString().toUpperCase()); // Bukkit.getLogger().info("Valid magic, " + anvilInv.getItem(MAGIC).toString().toUpperCase());
} }
} }
@ -13063,7 +13071,7 @@ class updateInventoryTask implements Runnable {
ItemMeta temp_meta = orbs.getItemMeta(); ItemMeta temp_meta = orbs.getItemMeta();
temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost"); temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost");
List<String> temp_meta_lore = new ArrayList<String>(); List<String> temp_meta_lore = new ArrayList<String>();
temp_meta_lore.add(ChatColor.ITALIC + "Experience Cost of Enchanting."); temp_meta_lore.add(ChatColor.ITALIC + "Experience Cost of Enchanting.");
temp_meta.setLore(temp_meta_lore); temp_meta.setLore(temp_meta_lore);
orbs.setItemMeta(temp_meta); orbs.setItemMeta(temp_meta);
anvilInv.setItem(LEVELS, orbs); anvilInv.setItem(LEVELS, orbs);
@ -13077,6 +13085,14 @@ class updateInventoryTask implements Runnable {
// Verify the right material is combined with the source item. // Verify the right material is combined with the source item.
boolean validCombo = false; boolean validCombo = false;
double multiplier = 0; double multiplier = 0;
boolean isHalloweenItem = false;
List<String> lore = anvilInv.getItem(INPUT).getItemMeta().getLore();
for (int i=0;i<lore.size();i++) {
if (lore.get(i).contains(ChatColor.YELLOW+"[Halloween]")) {
isHalloweenItem = true;
}
}
if (anvilInv.getItem(MATERIALS).getType() == Material.WOOD && (anvilInv.getItem(INPUT).getType() == Material.WOOD_AXE || if (anvilInv.getItem(MATERIALS).getType() == Material.WOOD && (anvilInv.getItem(INPUT).getType() == Material.WOOD_AXE ||
anvilInv.getItem(INPUT).getType() == Material.WOOD_SWORD || anvilInv.getItem(INPUT).getType() == Material.WOOD_HOE || anvilInv.getItem(INPUT).getType() == Material.WOOD_SWORD || anvilInv.getItem(INPUT).getType() == Material.WOOD_HOE ||
@ -13163,11 +13179,12 @@ class updateInventoryTask implements Runnable {
multiplier = 0.3; multiplier = 0.3;
} }
if (anvilInv.getItem(MATERIALS).getType() == Material.DIAMOND && (anvilInv.getItem(INPUT).getType() == Material.DIAMOND_BOOTS || if ((anvilInv.getItem(MATERIALS).getType() == Material.DIAMOND && (anvilInv.getItem(INPUT).getType() == Material.DIAMOND_BOOTS ||
anvilInv.getItem(INPUT).getType() == Material.DIAMOND_CHESTPLATE || anvilInv.getItem(INPUT).getType() == Material.DIAMOND_HELMET || anvilInv.getItem(INPUT).getType() == Material.DIAMOND_CHESTPLATE || anvilInv.getItem(INPUT).getType() == Material.DIAMOND_HELMET ||
anvilInv.getItem(INPUT).getType() == Material.DIAMOND_LEGGINGS || anvilInv.getItem(INPUT).getType() == Material.DIAMOND_AXE || anvilInv.getItem(INPUT).getType() == Material.DIAMOND_LEGGINGS || anvilInv.getItem(INPUT).getType() == Material.DIAMOND_AXE ||
anvilInv.getItem(INPUT).getType() == Material.DIAMOND_SWORD || anvilInv.getItem(INPUT).getType() == Material.DIAMOND_HOE || anvilInv.getItem(INPUT).getType() == Material.DIAMOND_SWORD || anvilInv.getItem(INPUT).getType() == Material.DIAMOND_HOE ||
anvilInv.getItem(INPUT).getType() == Material.DIAMOND_PICKAXE || anvilInv.getItem(INPUT).getType() == Material.DIAMOND_SPADE)) { anvilInv.getItem(INPUT).getType() == Material.DIAMOND_PICKAXE || anvilInv.getItem(INPUT).getType() == Material.DIAMOND_SPADE) &&
!isHalloweenItem)) {
validCombo = true; validCombo = true;
multiplier = 1.2; multiplier = 1.2;
@ -13181,16 +13198,31 @@ class updateInventoryTask implements Runnable {
validCombo = true; validCombo = true;
multiplier = 0.12; multiplier = 0.12;
if (isHalloweenItem) {
multiplier = 1.2;
}
}
if (anvilInv.getItem(MATERIALS).getType() == Material.EMERALD) {
validCombo = true;
multiplier = 0.5;
}
if (anvilInv.getItem(MATERIALS).getType() == Material.EMERALD_BLOCK) {
validCombo = true;
multiplier = 0.05;
} }
if (validCombo) { if (validCombo) {
// If materials stacked past number needed to full repair, reduce stack size and drop the rest // If materials stacked past number needed to full repair, reduce stack size and drop the rest
// in the player's inventory, or if that fails, drop it on the ground. // in the player's inventory, or if that fails, drop it on the ground.
// Limit to 5 just in case math doesn't work. // Limit to 5 just in case math doesn't work.
int maxItemsNeeded = Math.min(5, 1 + (5 * anvilInv.getItem(INPUT).getDurability() / anvilInv.getItem(INPUT).getType().getMaxDurability())); int maxPossible = (int)Math.round(1 / repairMultiplier);
int maxItemsNeeded = Math.min(maxPossible, 1 + (maxPossible * anvilInv.getItem(INPUT).getDurability() / anvilInv.getItem(INPUT).getType().getMaxDurability()));
if (anvilInv.getItem(MATERIALS).getAmount() > maxItemsNeeded) { if (anvilInv.getItem(MATERIALS).getAmount() > 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); sendToInventory(MATERIALS, anvilInv.getItem(MATERIALS).getAmount() - maxItemsNeeded, player);
@ -13201,32 +13233,32 @@ class updateInventoryTask implements Runnable {
int bonus_cost = 0; int bonus_cost = 0;
ItemStack item = anvilInv.getContents()[INPUT]; ItemStack item = anvilInv.getContents()[INPUT];
Bukkit.getLogger().warning("Repair cost calculation valid"); // Bukkit.getLogger().warning("Repair cost calculation valid");
Map<Enchantment, Integer> enchantments = item.getEnchantments(); Map<Enchantment, Integer> enchantments = item.getEnchantments();
Bukkit.getLogger().warning(enchantments.keySet().toString()); // Bukkit.getLogger().warning(enchantments.keySet().toString());
for (Enchantment e : enchantments.keySet()) { 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)); bonus_cost += (2 + enchantments.get(e));
} }
cost += bonus_cost; cost += bonus_cost;
Bukkit.getLogger().info("Raw cost: " + cost); // Bukkit.getLogger().info("Raw cost: " + cost);
cost = (short) Math.floor(cost * multiplier); cost = (short) Math.floor(cost * multiplier);
cost = Math.min(cost, 60); // Cap cost at 60 in case some egregiously enchanted item exists 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 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); ItemStack orbs = new ItemStack(Material.SLIME_BALL);
ItemMeta temp_meta = orbs.getItemMeta(); ItemMeta temp_meta = orbs.getItemMeta();
temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost"); temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost");
List<String> temp_meta_lore = new ArrayList<String>(); List<String> temp_meta_lore = new ArrayList<String>();
temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels."); temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels.");
temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels."); temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels.");
if (cost > player.getLevel()) { if (cost > player.getLevel()) {
orbs.setType(Material.MAGMA_CREAM); orbs.setType(Material.MAGMA_CREAM);
@ -13248,7 +13280,7 @@ class updateInventoryTask implements Runnable {
// anvilInv.getContents()[OUTPUT].setData(item.getData()); // anvilInv.getContents()[OUTPUT].setData(item.getData());
anvilInv.setItem(OUTPUT, item.clone()); 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()));
} }
@ -13257,356 +13289,426 @@ class updateInventoryTask implements Runnable {
anvilInv.setContents(anvilInv.getContents()); anvilInv.setContents(anvilInv.getContents());
player.updateInventory(); player.updateInventory();
} else if (anvilInv.getItem(INPUT) != null && anvilInv.getItem(MAGIC) != null) { } else if (anvilInv.getItem(INPUT) != null && anvilInv.getItem(MAGIC) != null) {
// Both Magic slots are populated. if (anvilInv.getItem(MAGIC).getType() == Material.ENCHANTED_BOOK) {
// Get the list of enchantments from both items. // Both Magic slots are populated, enchanted book is detected.
Map<Enchantment, Integer> itemEnchantments = anvilInv.getItem(INPUT).getEnchantments(); // Get the list of enchantments from both items.
Map<Enchantment, Integer> bookEnchantments = new java.util.HashMap<Enchantment, Integer>(); Map<Enchantment, Integer> itemEnchantments = anvilInv.getItem(INPUT).getEnchantments();
Map<Enchantment, Integer> bookEnchantments = new java.util.HashMap<Enchantment, Integer>();
// Get enchanted book "enchantment" and enchantments.
bookEnchantments.putAll(anvilInv.getItem(MAGIC).getEnchantments()); // Get enchanted book "enchantment" and enchantments.
bookEnchantments.putAll(((EnchantmentStorageMeta)(anvilInv.getItem(MAGIC).getItemMeta())).getStoredEnchants()); bookEnchantments.putAll(anvilInv.getItem(MAGIC).getEnchantments());
bookEnchantments.putAll(((EnchantmentStorageMeta)(anvilInv.getItem(MAGIC).getItemMeta())).getStoredEnchants());
// Get the list of bonuses from both items.
Map<String, Double> itemBonuses = new java.util.HashMap<String, Double>(); // Get the list of bonuses from both items.
Map<String, Double> bookBonuses = new java.util.HashMap<String, Double>(); Map<String, Double> itemBonuses = new java.util.HashMap<String, Double>();
Map<String, Double> bookBonuses = new java.util.HashMap<String, Double>();
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));
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)));
itemBonuses.put(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)), getEnchantmentNumb(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)));
} else {
if (anvilInv.getItem(INPUT).getItemMeta().hasLore()) { // Bukkit.getLogger().info("Stacking bonus: " + itemBonuses.get(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))) + " + " + getEnchantmentNumb(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)));
for (int i = 0; i < anvilInv.getItem(INPUT).getItemMeta().getLore().size(); 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)));
// Put enchantments together for the input. Also stacks identical enchantments. }
Bukkit.getLogger().info("Iterating bonus: " + anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)); }
}
}
if (getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)) != null) { if (anvilInv.getItem(MAGIC).getItemMeta().hasLore()) {
if (itemBonuses.get(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))) == null) { 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));
if (bookBonuses.get(getEnchantmentName(anvilInv.getItem(MAGIC).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(MAGIC).getItemMeta().getLore().get(i)));
itemBonuses.put(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)), getEnchantmentNumb(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))); bookBonuses.put(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)), getEnchantmentNumb(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)));
} else { } 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: " + bookBonuses.get(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))) + " + " + getEnchantmentNumb(anvilInv.getItem(MAGIC).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))); 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)));
} }
} }
} }
}
if (anvilInv.getItem(MAGIC).getItemMeta().hasLore()) { // Generate appropriate possible enchantments
for (int i = 0; i < anvilInv.getItem(MAGIC).getItemMeta().getLore().size(); i++) { Map<Enchantment, Integer> probableEnchantments = new java.util.HashMap<Enchantment, Integer>();
// Put enchantments together for the MAGIC. Also stacks identical enchantments.
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))); for (Enchantment e : bookEnchantments.keySet()) {
bookBonuses.put(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)), getEnchantmentNumb(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))); // Bukkit.getLogger().info("Iterating enchantment: " + e);
} else {
Bukkit.getLogger().info("Stacking bonus: " + bookBonuses.get(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))) + " + " + getEnchantmentNumb(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))); if (itemEnchantments.get(e) == null || bookEnchantments.get(e) > itemEnchantments.get(e)) {
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))); // 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) && bookEnchantments.get(e) <= 10) {
// Book enchantment is same in magnitude. Upgrade by one level.
probableEnchantments.put(e, bookEnchantments.get(e) + 1);
} }
} }
}
// Generate appropriate possible enchantments // Generate appropriate possible bonuses
Map<Enchantment, Integer> probableEnchantments = new java.util.HashMap<Enchantment, Integer>(); Map<String, Integer> probableBonuses = new java.util.HashMap<String, Integer>();
for (Enchantment e : bookEnchantments.keySet()) { for (String e : bookBonuses.keySet()) {
Bukkit.getLogger().info("Iterating enchantment: " + e); // Bukkit.getLogger().info("Iterating bonus: " + e);
if (itemEnchantments.get(e) == null || bookEnchantments.get(e) > itemEnchantments.get(e)) { if (itemBonuses.get(e) == null) {
// Book enchantment is larger in magnitude. Assign it as a possible outcome. // Book enchantment is new. Assign it as a possible outcome.
probableEnchantments.put(e, bookEnchantments.get(e)); probableBonuses.put(e, (int)Math.round(bookBonuses.get(e) * 0.2));
} else if (bookEnchantments.get(e) == itemEnchantments.get(e)) { // The int cast appears to be needed to make it display integers and not stuff like "+5.0 Health"
// Book enchantment is same in magnitude. Upgrade by one level. // Don't remove unless workaround can be found.
probableEnchantments.put(e, bookEnchantments.get(e) + 1); } else if (bookBonuses.get(e) >= itemBonuses.get(e) * 0.2) {
// Book enchantment is large enough in magnitude to stack. Assign it as a possible outcome.
probableBonuses.put(e, (int)Math.round(itemBonuses.get(e) + bookBonuses.get(e) * 0.2));
}
} }
}
// Generate appropriate possible bonuses if (probableEnchantments.size() == 0 && probableBonuses.size() == 0) {
Map<String, Double> probableBonuses = new java.util.HashMap<String, Double>(); // No possible valid enchantments. Output nothing
} else {
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());
for (String e : bookBonuses.keySet()) { int i = 0;
Bukkit.getLogger().info("Iterating bonus: " + e);
if (itemBonuses.get(e) == null || bookBonuses.get(e) > itemBonuses.get(e)) { Enchantment appliedEnchant = null;
// Book enchantment is larger in magnitude. Assign it as a possible outcome. int magnitude = 0;
probableBonuses.put(e, bookBonuses.get(e)); for (Enchantment e : probableEnchantments.keySet()) {
} else if (bookBonuses.get(e) == itemBonuses.get(e)) {
// Book enchantment is same in magnitude. Upgrade by half.
probableBonuses.put(e, Math.floor(bookBonuses.get(e) * 1.5));
}
}
if (probableEnchantments.size() == 0 && probableBonuses.size() == 0) { if (i == random) {
// No possible valid enchantments. Output nothing // Rolled this one
} else { appliedEnchant = e;
if (probableEnchantments.size() != 0) { magnitude = probableEnchantments.get(e);
// Randomly select an enchantment to add. }
int random = (int)(Math.random() * probableEnchantments.size()); i++;
Bukkit.getLogger().info("Randomized to # " + (random + 1) + " out of " + probableEnchantments.size()); }
int i = 0; int cost = 0;
Enchantment appliedEnchant = null; if (itemEnchantments.get(appliedEnchant) == null) {
int magnitude = 0; // This enchantment doesn't exist. Calculate full cost.
for (Enchantment e : probableEnchantments.keySet()) {
if (i == random) { cost = Math.min(60, magnitude * magnitude);
// Rolled this one cost = Math.max(cost, 1); // Make sure it's at least one level
appliedEnchant = e;
magnitude = probableEnchantments.get(e);
}
i++;
}
int cost = 0; ItemStack orbs = new ItemStack(Material.SLIME_BALL);
if (itemEnchantments.get(appliedEnchant) == null) { ItemMeta temp_meta = orbs.getItemMeta();
// This enchantment doesn't exist. Calculate full cost. temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost");
List<String> temp_meta_lore = new ArrayList<String>();
temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels.");
temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels.");
cost = Math.min(60, magnitude * magnitude); if (cost > player.getLevel()) {
cost = Math.max(cost, 1); // Make sure it's at least one level orbs.setType(Material.MAGMA_CREAM);
temp_meta_lore.add("");
temp_meta_lore.add(ChatColor.RED + "You can't afford this!");
} else {
temp_meta_lore.add("");
temp_meta_lore.add(ChatColor.GREEN + "Completing the operation will");
temp_meta_lore.add(ChatColor.GREEN + "bring you to " + (player.getLevel() - cost) + " levels.");
}
ItemStack orbs = new ItemStack(Material.SLIME_BALL); temp_meta.setLore(temp_meta_lore);
orbs.setItemMeta(temp_meta);
ItemMeta temp_meta = orbs.getItemMeta(); orbs.setAmount(cost);
temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost"); anvilInv.setItem(LEVELS, orbs);
List<String> temp_meta_lore = new ArrayList<String>(); anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone());
temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels."); anvilInv.getItem(OUTPUT).addUnsafeEnchantment(appliedEnchant, magnitude);
temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels.");
if (cost > player.getLevel()) {
orbs.setType(Material.MAGMA_CREAM);
temp_meta_lore.add("");
temp_meta_lore.add(ChatColor.RED + "You can't afford this!");
} else { } else {
temp_meta_lore.add(""); // This enchantment exists. Calculate incremental cost.
temp_meta_lore.add(ChatColor.GREEN + "Completing the operation will");
temp_meta_lore.add(ChatColor.GREEN + "bring you to " + (player.getLevel() - cost) + " levels.");
}
temp_meta.setLore(temp_meta_lore); cost = Math.min(60, magnitude * magnitude - itemEnchantments.get(appliedEnchant) * itemEnchantments.get(appliedEnchant));
orbs.setItemMeta(temp_meta); cost = Math.max(cost, 1); // Make sure it's at least one level
orbs.setAmount(cost); ItemStack orbs = new ItemStack(Material.SLIME_BALL);
anvilInv.setItem(LEVELS, orbs);
anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone());
anvilInv.getItem(OUTPUT).addUnsafeEnchantment(appliedEnchant, magnitude);
} else { ItemMeta temp_meta = orbs.getItemMeta();
// This enchantment exists. Calculate incremental cost. temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost");
List<String> temp_meta_lore = new ArrayList<String>();
temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels.");
temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels.");
cost = Math.min(60, magnitude * magnitude - itemEnchantments.get(appliedEnchant) * itemEnchantments.get(appliedEnchant)); if (cost > player.getLevel()) {
cost = Math.max(cost, 1); // Make sure it's at least one level orbs.setType(Material.MAGMA_CREAM);
temp_meta_lore.add("");
temp_meta_lore.add(ChatColor.RED + "You can't afford this!");
} else {
temp_meta_lore.add("");
temp_meta_lore.add(ChatColor.GREEN + "Completing the operation will");
temp_meta_lore.add(ChatColor.GREEN + "bring you to " + (player.getLevel() - cost) + " levels.");
}
ItemStack orbs = new ItemStack(Material.SLIME_BALL); temp_meta.setLore(temp_meta_lore);
orbs.setItemMeta(temp_meta);
ItemMeta temp_meta = orbs.getItemMeta(); orbs.setAmount(cost);
temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost"); anvilInv.setItem(LEVELS, orbs);
List<String> temp_meta_lore = new ArrayList<String>();
temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels.");
temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels.");
if (cost > player.getLevel()) { anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone());
orbs.setType(Material.MAGMA_CREAM); anvilInv.getItem(OUTPUT).removeEnchantment(appliedEnchant);
temp_meta_lore.add(""); anvilInv.getItem(OUTPUT).addUnsafeEnchantment(appliedEnchant, magnitude);
temp_meta_lore.add(ChatColor.RED + "You can't afford this!");
} else {
temp_meta_lore.add("");
temp_meta_lore.add(ChatColor.GREEN + "Completing the operation will");
temp_meta_lore.add(ChatColor.GREEN + "bring you to " + (player.getLevel() - cost) + " levels.");
} }
} else {
temp_meta.setLore(temp_meta_lore); // Can't add enchant, but can add bonus. Prepare output for bonus.
orbs.setItemMeta(temp_meta);
orbs.setAmount(cost);
anvilInv.setItem(LEVELS, orbs);
anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone()); anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone());
anvilInv.getItem(OUTPUT).removeEnchantment(appliedEnchant);
anvilInv.getItem(OUTPUT).addUnsafeEnchantment(appliedEnchant, magnitude);
} }
} else {
// Can't add enchant, but can add bonus. Prepare output for bonus.
anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone());
}
if (probableBonuses.size() != 0) { boolean isTinkerer = true; // Change this to a playerInJob() call later.
// Randomly select a bonus to add.
int random = (int)(Math.random() * probableBonuses.size()); if (probableBonuses.size() != 0 && isTinkerer) {
Bukkit.getLogger().info("Randomized to # " + (random + 1) + " out of " + probableBonuses.size()); // Randomly select a bonus to add.
int random = (int)(Math.random() * probableBonuses.size());
Bukkit.getLogger().info("Randomized to # " + (random + 1) + " out of " + probableBonuses.size());
int i = 0; int i = 0;
String appliedEnchant = null; String appliedEnchant = null;
double magnitude = 0; int magnitude = 0;
for (String e : probableBonuses.keySet()) { for (String e : probableBonuses.keySet()) {
if (i == random) { if (i == random) {
// Rolled this one // Rolled this one
appliedEnchant = e; appliedEnchant = e;
magnitude = probableBonuses.get(e); magnitude = probableBonuses.get(e);
}
i++;
} }
i++;
}
int cost = 0; int cost = 0;
if (itemBonuses.get(appliedEnchant) == null) { if (itemBonuses.get(appliedEnchant) == null) {
// This bonus doesn't exist. Calculate full cost. // This bonus doesn't exist. Calculate full cost.
Bukkit.getLogger().info("Bonus doesn't exist.");
Bukkit.getLogger().info("Bonus is: " + appliedEnchant + " at magnitude " + magnitude);
cost = 30; cost += 12;
cost = Math.min(60, cost);
cost = Math.max(1, cost);
ItemStack orbs = new ItemStack(Material.SLIME_BALL); ItemStack orbs = new ItemStack(Material.SLIME_BALL);
ItemMeta temp_meta = orbs.getItemMeta(); ItemMeta temp_meta = orbs.getItemMeta();
temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost"); temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost");
List<String> temp_meta_lore = new ArrayList<String>(); List<String> temp_meta_lore = new ArrayList<String>();
temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels."); temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels.");
temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels."); temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels.");
if (cost > player.getLevel()) { if (cost > player.getLevel()) {
orbs.setType(Material.MAGMA_CREAM); orbs.setType(Material.MAGMA_CREAM);
temp_meta_lore.add(""); temp_meta_lore.add("");
temp_meta_lore.add(ChatColor.RED + "You can't afford this!"); temp_meta_lore.add(ChatColor.RED + "You can't afford this!");
} else { } else {
temp_meta_lore.add(""); temp_meta_lore.add("");
temp_meta_lore.add(ChatColor.GREEN + "Completing the operation will"); temp_meta_lore.add(ChatColor.GREEN + "Completing the operation will");
temp_meta_lore.add(ChatColor.GREEN + "bring you to " + (player.getLevel() - cost) + " levels."); temp_meta_lore.add(ChatColor.GREEN + "bring you to " + (player.getLevel() - cost) + " levels.");
} }
temp_meta.setLore(temp_meta_lore);
orbs.setItemMeta(temp_meta);
orbs.setAmount(cost); temp_meta.setLore(temp_meta_lore);
anvilInv.setItem(LEVELS, orbs); orbs.setItemMeta(temp_meta);
// Change entry matching modified lore orbs.setAmount(cost);
List<String> bonusesLore = anvilInv.getItem(OUTPUT).getItemMeta().getLore(); anvilInv.setItem(LEVELS, orbs);
for (int i1 = 0; i1 < bonusesLore.size(); i1++) { // Change entry matching modified lore
String e = bonusesLore.get(i1); ItemMeta bonusesMeta = anvilInv.getItem(OUTPUT).getItemMeta();
List<String> bonusesLore = bonusesMeta.getLore();
if (bonusesLore == null)
{
bonusesLore = new ArrayList<String>();
}
if (containsEnchantment(e, appliedEnchant)) { // Bukkit.getLogger().info("Bonus enchantment string: " + appliedEnchant);
if (appliedEnchant.equalsIgnoreCase("Critical Chance")) { if (appliedEnchant.equalsIgnoreCase("Critical Chance")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Critical Chance"); bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Critical Chance");
} }
if (appliedEnchant.equalsIgnoreCase("Armor Penetration")) { if (appliedEnchant.equalsIgnoreCase("Armor Penetration")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Armor Penetration"); bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Armor Penetration");
} }
if (appliedEnchant.equalsIgnoreCase("Life Steal")) { if (appliedEnchant.equalsIgnoreCase("Life Steal")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Life Steal"); bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Life Steal");
} }
if (appliedEnchant.equalsIgnoreCase("Attack Speed")) { if (appliedEnchant.equalsIgnoreCase("Attack Speed")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Attack Speed"); bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Attack Speed");
} }
if (appliedEnchant.equalsIgnoreCase("Damage")) { if (appliedEnchant.equalsIgnoreCase("Damage")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Damage"); bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Damage");
} }
if (appliedEnchant.equalsIgnoreCase("Health")) { if (appliedEnchant.equalsIgnoreCase("Health")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Health"); bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Health");
} }
if (appliedEnchant.equalsIgnoreCase("Damage Reduction")) { if (appliedEnchant.equalsIgnoreCase("Damage Reduction")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Damage Reduction"); bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Damage Reduction");
} }
if (appliedEnchant.equalsIgnoreCase("Durability")) { if (appliedEnchant.equalsIgnoreCase("Durability")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Durability"); bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Durability");
} }
if (appliedEnchant.equalsIgnoreCase("Block Chance")) { if (appliedEnchant.equalsIgnoreCase("Block Chance")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Block Chance"); bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Block Chance");
} }
if (appliedEnchant.equalsIgnoreCase("Speed Boost Chance")) { if (appliedEnchant.equalsIgnoreCase("Speed Boost Chance")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Speed Boost Chance"); bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Speed Boost Chance");
}
} }
}
anvilInv.getItem(OUTPUT).getItemMeta().setLore(bonusesLore); bonusesMeta.setLore(bonusesLore);
anvilInv.getItem(OUTPUT).setItemMeta(bonusesMeta);
} else { } else {
// This enchantment exists. Calculate incremental cost. // This enchantment exists. Calculate incremental cost.
cost = (int)(30 * itemBonuses.get(appliedEnchant) / probableBonuses.get(appliedEnchant)); // Make sure it's at least one level cost += (int)(12 * itemBonuses.get(appliedEnchant) / probableBonuses.get(appliedEnchant)); // Make sure it's at least one level
cost = Math.min(60, cost);
cost = Math.max(1, cost);
ItemStack orbs = new ItemStack(Material.SLIME_BALL); ItemStack orbs = new ItemStack(Material.SLIME_BALL);
ItemMeta temp_meta = orbs.getItemMeta(); ItemMeta temp_meta = orbs.getItemMeta();
temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost"); temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost");
List<String> temp_meta_lore = new ArrayList<String>(); List<String> temp_meta_lore = new ArrayList<String>();
temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels."); temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels.");
temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels."); temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels.");
if (cost > player.getLevel()) { if (cost > player.getLevel()) {
orbs.setType(Material.MAGMA_CREAM); orbs.setType(Material.MAGMA_CREAM);
temp_meta_lore.add(""); temp_meta_lore.add("");
temp_meta_lore.add(ChatColor.RED + "You can't afford this!"); temp_meta_lore.add(ChatColor.RED + "You can't afford this!");
} else { } else {
temp_meta_lore.add(""); temp_meta_lore.add("");
temp_meta_lore.add(ChatColor.GREEN + "Completing the operation will"); temp_meta_lore.add(ChatColor.GREEN + "Completing the operation will");
temp_meta_lore.add(ChatColor.GREEN + "bring you to " + (player.getLevel() - cost) + " levels."); temp_meta_lore.add(ChatColor.GREEN + "bring you to " + (player.getLevel() - cost) + " levels.");
} }
temp_meta.setLore(temp_meta_lore); temp_meta.setLore(temp_meta_lore);
orbs.setItemMeta(temp_meta); orbs.setItemMeta(temp_meta);
orbs.setAmount(cost); orbs.setAmount(cost);
anvilInv.setItem(LEVELS, orbs); anvilInv.setItem(LEVELS, orbs);
// Change entry matching modified lore // Change entry matching modified lore
List<String> bonusesLore = anvilInv.getItem(OUTPUT).getItemMeta().getLore(); ItemMeta bonusesMeta = anvilInv.getItem(OUTPUT).getItemMeta();
List<String> bonusesLore = bonusesMeta.getLore();
for (int i1 = 0; i1 < bonusesLore.size(); i1++) { for (int i1 = 0; i1 < bonusesLore.size(); i1++) {
String e = bonusesLore.get(i1); String e = bonusesLore.get(i1);
if (containsEnchantment(e, appliedEnchant)) { if (containsEnchantment(e, appliedEnchant)) {
if (appliedEnchant.equalsIgnoreCase("Critical Chance")) { // Bukkit.getLogger().info("Success! Found enchantment: " + e);
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Critical Chance"); // Bukkit.getLogger().info("Bonus enchantment: " + appliedEnchant);
}
if (appliedEnchant.equalsIgnoreCase("Armor Penetration")) { if (appliedEnchant.equalsIgnoreCase("Critical Chance")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Armor Penetration"); bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Critical Chance");
} }
if (appliedEnchant.equalsIgnoreCase("Life Steal")) { if (appliedEnchant.equalsIgnoreCase("Armor Penetration")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Life Steal"); bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Armor Penetration");
} }
if (appliedEnchant.equalsIgnoreCase("Attack Speed")) { if (appliedEnchant.equalsIgnoreCase("Life Steal")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Attack Speed"); bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Life Steal");
} }
if (appliedEnchant.equalsIgnoreCase("Damage")) { if (appliedEnchant.equalsIgnoreCase("Attack Speed")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Damage"); bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Attack Speed");
} }
if (appliedEnchant.equalsIgnoreCase("Health")) { if (appliedEnchant.equalsIgnoreCase("Damage")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Health"); bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Damage");
} }
if (appliedEnchant.equalsIgnoreCase("Damage Reduction")) { if (appliedEnchant.equalsIgnoreCase("Health")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Damage Reduction"); bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Health");
} }
if (appliedEnchant.equalsIgnoreCase("Durability")) { if (appliedEnchant.equalsIgnoreCase("Damage Reduction")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Durability"); bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Damage Reduction");
} }
if (appliedEnchant.equalsIgnoreCase("Block Chance")) { if (appliedEnchant.equalsIgnoreCase("Durability")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Block Chance"); bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Durability");
} }
if (appliedEnchant.equalsIgnoreCase("Speed Boost Chance")) { if (appliedEnchant.equalsIgnoreCase("Block Chance")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Speed Boost Chance"); bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Block Chance");
}
if (appliedEnchant.equalsIgnoreCase("Speed Boost Chance")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Speed Boost Chance");
}
} }
} }
}
anvilInv.getItem(OUTPUT).getItemMeta().setLore(bonusesLore); bonusesMeta.setLore(bonusesLore);
anvilInv.getItem(OUTPUT).setItemMeta(bonusesMeta);
}
} }
}
// TRY EVERYTHING
player.getInventory().setContents(player.getInventory().getContents());
anvilInv.setContents(anvilInv.getContents());
player.updateInventory();
} 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, new ItemStack(Material.ENCHANTED_BOOK));
anvilInv.getItem(OUTPUT).setType(Material.ENCHANTED_BOOK);
ItemMeta bookMeta = anvilInv.getItem(INPUT).getItemMeta();
bookMeta.setDisplayName(null);
anvilInv.getItem(OUTPUT).setItemMeta(bookMeta);
// If books stacked past 1, return all but 1 book to player inventory.
if (anvilInv.getItem(MAGIC).getAmount() > 1) {
sendToInventory(MAGIC, anvilInv.getItem(MAGIC).getAmount() - 1, player);
} }
int cost = 12;
Map<Enchantment, Integer> enchantments = anvilInv.getItem(INPUT).getEnchantments();
for (Enchantment e : enchantments.keySet()) {
cost += (1 + enchantments.get(e));
}
ItemStack orbs = new ItemStack(Material.SLIME_BALL);
ItemMeta temp_meta = orbs.getItemMeta();
temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost");
List<String> temp_meta_lore = new ArrayList<String>();
temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels.");
temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels.");
if (cost > player.getLevel()) {
orbs.setType(Material.MAGMA_CREAM);
temp_meta_lore.add("");
temp_meta_lore.add(ChatColor.RED + "You can't afford this!");
} else {
temp_meta_lore.add("");
temp_meta_lore.add(ChatColor.GREEN + "Completing the operation will");
temp_meta_lore.add(ChatColor.GREEN + "bring you to " + (player.getLevel() - cost) + " levels.");
}
temp_meta.setLore(temp_meta_lore);
orbs.setItemMeta(temp_meta);
orbs.setAmount(cost);
anvilInv.setItem(LEVELS, orbs);
// TRY EVERYTHING
player.getInventory().setContents(player.getInventory().getContents());
anvilInv.setContents(anvilInv.getContents());
player.updateInventory();
} }
// TRY EVERYTHING
player.getInventory().setContents(player.getInventory().getContents());
anvilInv.setContents(anvilInv.getContents());
player.updateInventory();
} }
} }
public void sendToInventory(int slot, int itemCount, Player player) { public void sendToInventory(int slot, int itemCount, Player player) {
Bukkit.getLogger().info("Slot: " + slot); // Bukkit.getLogger().info("Slot: " + slot);
Bukkit.getLogger().info("Item Count: " + itemCount); // Bukkit.getLogger().info("Item Count: " + itemCount);
Bukkit.getLogger().info("Player: " + player.getDisplayName()); // Bukkit.getLogger().info("Player: " + player.getDisplayName());
// Get inventories // Get inventories
Inventory anvilInventory = player.getOpenInventory().getTopInventory(); Inventory anvilInventory = player.getOpenInventory().getTopInventory();
@ -13624,16 +13726,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) { if (anvilInventory.getItem(slot).getAmount() - itemCount == 0) {
// Should reduce stack count to zero, meaning item needs to be removed. // 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)); anvilInventory.setItem(slot, new ItemStack(Material.AIR));
} else { } else {
// Should set stack size. // 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); 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)); // player.getWorld().dropItemNaturally(player.getLocation(), new ItemStack(anvilInv.getItem(MATERIALS).getType(), anvilInv.getItem(MATERIALS).getAmount() - maxItemsNeeded));
@ -13645,7 +13747,7 @@ class updateInventoryTask implements Runnable {
String[] enchant = s.split(" "); String[] enchant = s.split(" ");
if (enchant[0].contains(ChatColor.YELLOW+"")) { if (enchant[0].contains(ChatColor.YELLOW+"")) {
String newstring = ((enchant[0].replace(ChatColor.YELLOW.getChar(), ' ')).replace('%', ' ')).replace(Character.toString((char)0x00A7), Character.toString((char)0x0020)); 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); return Double.valueOf(newstring);
} else { } else {
return 0; return 0;
@ -13663,12 +13765,11 @@ class updateInventoryTask implements Runnable {
} }
public boolean containsEnchantment(String s, String enchant) { public boolean containsEnchantment(String s, String enchant) {
if (s.contains(enchant)) { if (s.contains(enchant)) {
return true; return true;
} }
return false; return false;
} }
} }

Loading…
Cancel
Save