Enchanted books can now be combined. Enchanted book bonuses are now
possible to transfer (it only adds 20% of the value on the book). Emeralds added as a universal repair ingredient at a 0.5 multiplier (tentative). Emerald blocks behave similarly at a 0.05 multiplier. Unenchanting items via the anvil is now possible by putting a normal book in the magic slot. This will destroy the item at least 50% of the time. It tentatively costs one level.
This commit is contained in:
parent
c5a992c418
commit
b207796945
@ -9773,7 +9773,19 @@ implements Listener
|
|||||||
|
|
||||||
Bukkit.getLogger().info("Can place into inventory.");
|
Bukkit.getLogger().info("Can place into inventory.");
|
||||||
|
|
||||||
event.getInventory().setItem(INPUT, new ItemStack(Material.AIR));
|
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));
|
||||||
|
|
||||||
|
// Destroy the item if random() exceeds %remaining durability
|
||||||
|
if (Math.random() < (double)(event.getInventory().getItem(INPUT).getType().getMaxDurability() - event.getInventory().getItem(INPUT).getDurability()) / (double)event.getInventory().getItem(INPUT).getType().getMaxDurability()) {
|
||||||
|
event.getInventory().setItem(INPUT, new ItemStack(Material.AIR));
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
event.getInventory().setItem(INPUT, new ItemStack(Material.AIR));
|
||||||
|
}
|
||||||
|
|
||||||
event.getInventory().setItem(MATERIALS, new ItemStack(Material.AIR));
|
event.getInventory().setItem(MATERIALS, new ItemStack(Material.AIR));
|
||||||
event.getInventory().setItem(MAGIC, new ItemStack(Material.AIR));
|
event.getInventory().setItem(MAGIC, new ItemStack(Material.AIR));
|
||||||
|
|
||||||
@ -9825,7 +9837,18 @@ implements Listener
|
|||||||
|
|
||||||
Bukkit.getLogger().info("Can place into inventory.");
|
Bukkit.getLogger().info("Can place into inventory.");
|
||||||
|
|
||||||
event.getInventory().setItem(INPUT, new ItemStack(Material.AIR));
|
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));
|
||||||
|
|
||||||
|
// Destroy the item if random() exceeds %remaining durability
|
||||||
|
if (Math.random() < (double)(event.getInventory().getItem(INPUT).getType().getMaxDurability() - event.getInventory().getItem(INPUT).getDurability()) / (double)event.getInventory().getItem(INPUT).getType().getMaxDurability()) {
|
||||||
|
event.getInventory().setItem(INPUT, new ItemStack(Material.AIR));
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
event.getInventory().setItem(INPUT, new ItemStack(Material.AIR));
|
||||||
|
}
|
||||||
event.getInventory().setItem(MATERIALS, new ItemStack(Material.AIR));
|
event.getInventory().setItem(MATERIALS, new ItemStack(Material.AIR));
|
||||||
event.getInventory().setItem(MAGIC, new ItemStack(Material.AIR));
|
event.getInventory().setItem(MAGIC, new ItemStack(Material.AIR));
|
||||||
|
|
||||||
@ -9856,7 +9879,18 @@ implements Listener
|
|||||||
Bukkit.getLogger().info("Normal click");
|
Bukkit.getLogger().info("Normal click");
|
||||||
|
|
||||||
// Cursor is empty, item picked up. Subtract XP levels and remove ingredients.
|
// Cursor is empty, item picked up. Subtract XP levels and remove ingredients.
|
||||||
event.getInventory().setItem(INPUT, new ItemStack(Material.AIR));
|
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));
|
||||||
|
|
||||||
|
// Destroy the item if random() exceeds %remaining durability
|
||||||
|
if (Math.random() < (double)(event.getInventory().getItem(INPUT).getType().getMaxDurability() - event.getInventory().getItem(INPUT).getDurability()) / (double)event.getInventory().getItem(INPUT).getType().getMaxDurability()) {
|
||||||
|
event.getInventory().setItem(INPUT, new ItemStack(Material.AIR));
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
event.getInventory().setItem(INPUT, new ItemStack(Material.AIR));
|
||||||
|
}
|
||||||
event.getInventory().setItem(MATERIALS, new ItemStack(Material.AIR));
|
event.getInventory().setItem(MATERIALS, new ItemStack(Material.AIR));
|
||||||
event.getInventory().setItem(MAGIC, new ItemStack(Material.AIR));
|
event.getInventory().setItem(MAGIC, new ItemStack(Material.AIR));
|
||||||
// event.getInventory().setItem(OUTPUT, new ItemStack(Material.AIR));
|
// event.getInventory().setItem(OUTPUT, new ItemStack(Material.AIR));
|
||||||
@ -12850,8 +12884,8 @@ 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!");
|
||||||
@ -12866,7 +12900,8 @@ 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)) {
|
||||||
|
|
||||||
sendToInventory(MATERIALS, anvilInv.getItem(MATERIALS).getAmount(), player);
|
sendToInventory(MATERIALS, anvilInv.getItem(MATERIALS).getAmount(), player);
|
||||||
|
|
||||||
@ -12877,7 +12912,7 @@ class updateInventoryTask implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
@ -13017,6 +13052,16 @@ class updateInventoryTask implements Runnable {
|
|||||||
multiplier = 0.12;
|
multiplier = 0.12;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.
|
||||||
@ -13091,349 +13136,406 @@ 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.
|
// Get enchanted book "enchantment" and enchantments.
|
||||||
bookEnchantments.putAll(anvilInv.getItem(MAGIC).getEnchantments());
|
bookEnchantments.putAll(anvilInv.getItem(MAGIC).getEnchantments());
|
||||||
bookEnchantments.putAll(((EnchantmentStorageMeta)(anvilInv.getItem(MAGIC).getItemMeta())).getStoredEnchants());
|
bookEnchantments.putAll(((EnchantmentStorageMeta)(anvilInv.getItem(MAGIC).getItemMeta())).getStoredEnchants());
|
||||||
|
|
||||||
// Get the list of bonuses from both items.
|
// Get the list of bonuses from both items.
|
||||||
Map<String, Double> itemBonuses = 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>();
|
Map<String, Double> bookBonuses = new java.util.HashMap<String, Double>();
|
||||||
|
|
||||||
if (anvilInv.getItem(INPUT).getItemMeta().hasLore()) {
|
if (anvilInv.getItem(INPUT).getItemMeta().hasLore()) {
|
||||||
for (int i = 0; i < anvilInv.getItem(INPUT).getItemMeta().getLore().size(); i++) {
|
for (int i = 0; i < anvilInv.getItem(INPUT).getItemMeta().getLore().size(); i++) {
|
||||||
// Put enchantments together for the input. Also stacks identical enchantments.
|
// 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 (getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)) != null) {
|
||||||
if (itemBonuses.get(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)));
|
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)));
|
||||||
|
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)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
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)));
|
||||||
|
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)) {
|
||||||
|
// 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
|
|
||||||
Map<String, Double> probableBonuses = new java.util.HashMap<String, Double>();
|
|
||||||
|
|
||||||
for (String e : bookBonuses.keySet()) {
|
|
||||||
Bukkit.getLogger().info("Iterating bonus: " + e);
|
|
||||||
|
|
||||||
if (itemBonuses.get(e) == null || bookBonuses.get(e) > itemBonuses.get(e)) {
|
|
||||||
// Book enchantment is larger in magnitude. Assign it as a possible outcome.
|
|
||||||
probableBonuses.put(e, bookBonuses.get(e));
|
|
||||||
} 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) {
|
|
||||||
// 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());
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
Enchantment appliedEnchant = null;
|
|
||||||
int magnitude = 0;
|
|
||||||
for (Enchantment e : probableEnchantments.keySet()) {
|
|
||||||
|
|
||||||
if (i == random) {
|
|
||||||
// Rolled this one
|
|
||||||
appliedEnchant = e;
|
|
||||||
magnitude = probableEnchantments.get(e);
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int cost = 0;
|
if (probableEnchantments.size() == 0 && probableBonuses.size() == 0) {
|
||||||
|
// No possible valid enchantments. Output nothing
|
||||||
if (itemEnchantments.get(appliedEnchant) == null) {
|
|
||||||
// This enchantment doesn't exist. Calculate full cost.
|
|
||||||
|
|
||||||
cost = Math.min(60, magnitude * magnitude);
|
|
||||||
cost = Math.max(cost, 1); // Make sure it's at least one level
|
|
||||||
|
|
||||||
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);
|
|
||||||
anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone());
|
|
||||||
anvilInv.getItem(OUTPUT).addUnsafeEnchantment(appliedEnchant, magnitude);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// This enchantment exists. Calculate incremental cost.
|
|
||||||
|
|
||||||
cost = Math.min(60, magnitude * magnitude - itemEnchantments.get(appliedEnchant) * itemEnchantments.get(appliedEnchant));
|
|
||||||
cost = Math.max(cost, 1); // Make sure it's at least one level
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone());
|
|
||||||
anvilInv.getItem(OUTPUT).removeEnchantment(appliedEnchant);
|
|
||||||
anvilInv.getItem(OUTPUT).addUnsafeEnchantment(appliedEnchant, magnitude);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Can't add enchant, but can add bonus. Prepare output for bonus.
|
if (probableEnchantments.size() != 0) {
|
||||||
anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone());
|
// Randomly select an enchantment to add.
|
||||||
}
|
int random = (int)(Math.random() * probableEnchantments.size());
|
||||||
|
Bukkit.getLogger().info("Randomized to # " + (random + 1) + " out of " + probableEnchantments.size());
|
||||||
|
|
||||||
if (probableBonuses.size() != 0) {
|
int i = 0;
|
||||||
// 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;
|
Enchantment appliedEnchant = null;
|
||||||
|
int magnitude = 0;
|
||||||
|
for (Enchantment e : probableEnchantments.keySet()) {
|
||||||
|
|
||||||
String appliedEnchant = null;
|
if (i == random) {
|
||||||
double magnitude = 0;
|
// Rolled this one
|
||||||
for (String e : probableBonuses.keySet()) {
|
appliedEnchant = e;
|
||||||
|
magnitude = probableEnchantments.get(e);
|
||||||
if (i == random) {
|
|
||||||
// Rolled this one
|
|
||||||
appliedEnchant = e;
|
|
||||||
magnitude = probableBonuses.get(e);
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
int cost = 0;
|
|
||||||
|
|
||||||
if (itemBonuses.get(appliedEnchant) == null) {
|
|
||||||
// This bonus doesn't exist. Calculate full cost.
|
|
||||||
|
|
||||||
cost = 30;
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
// Change entry matching modified lore
|
|
||||||
List<String> bonusesLore = anvilInv.getItem(OUTPUT).getItemMeta().getLore();
|
|
||||||
|
|
||||||
for (int i1 = 0; i1 < bonusesLore.size(); i1++) {
|
|
||||||
String e = bonusesLore.get(i1);
|
|
||||||
|
|
||||||
if (containsEnchantment(e, appliedEnchant)) {
|
|
||||||
if (appliedEnchant.equalsIgnoreCase("Critical Chance")) {
|
|
||||||
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Critical Chance");
|
|
||||||
}
|
|
||||||
if (appliedEnchant.equalsIgnoreCase("Armor Penetration")) {
|
|
||||||
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Armor Penetration");
|
|
||||||
}
|
|
||||||
if (appliedEnchant.equalsIgnoreCase("Life Steal")) {
|
|
||||||
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Life Steal");
|
|
||||||
}
|
|
||||||
if (appliedEnchant.equalsIgnoreCase("Attack Speed")) {
|
|
||||||
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Attack Speed");
|
|
||||||
}
|
|
||||||
if (appliedEnchant.equalsIgnoreCase("Damage")) {
|
|
||||||
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Damage");
|
|
||||||
}
|
|
||||||
if (appliedEnchant.equalsIgnoreCase("Health")) {
|
|
||||||
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Health");
|
|
||||||
}
|
|
||||||
if (appliedEnchant.equalsIgnoreCase("Damage Reduction")) {
|
|
||||||
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Damage Reduction");
|
|
||||||
}
|
|
||||||
if (appliedEnchant.equalsIgnoreCase("Durability")) {
|
|
||||||
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Durability");
|
|
||||||
}
|
|
||||||
if (appliedEnchant.equalsIgnoreCase("Block 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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
anvilInv.getItem(OUTPUT).getItemMeta().setLore(bonusesLore);
|
int cost = 0;
|
||||||
|
|
||||||
|
if (itemEnchantments.get(appliedEnchant) == null) {
|
||||||
|
// This enchantment doesn't exist. Calculate full cost.
|
||||||
|
|
||||||
|
cost = Math.min(60, magnitude * magnitude);
|
||||||
|
cost = Math.max(cost, 1); // Make sure it's at least one level
|
||||||
|
|
||||||
|
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);
|
||||||
|
anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone());
|
||||||
|
anvilInv.getItem(OUTPUT).addUnsafeEnchantment(appliedEnchant, magnitude);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// This enchantment exists. Calculate incremental cost.
|
||||||
|
|
||||||
|
cost = Math.min(60, magnitude * magnitude - itemEnchantments.get(appliedEnchant) * itemEnchantments.get(appliedEnchant));
|
||||||
|
cost = Math.max(cost, 1); // Make sure it's at least one level
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone());
|
||||||
|
anvilInv.getItem(OUTPUT).removeEnchantment(appliedEnchant);
|
||||||
|
anvilInv.getItem(OUTPUT).addUnsafeEnchantment(appliedEnchant, magnitude);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// This enchantment exists. Calculate incremental cost.
|
// Can't add enchant, but can add bonus. Prepare output for bonus.
|
||||||
|
anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone());
|
||||||
|
}
|
||||||
|
|
||||||
cost = (int)(30 * itemBonuses.get(appliedEnchant) / probableBonuses.get(appliedEnchant)); // Make sure it's at least one level
|
boolean isTinkerer = true; // Change this to a playerInJob() call later.
|
||||||
|
|
||||||
ItemStack orbs = new ItemStack(Material.SLIME_BALL);
|
if (probableBonuses.size() != 0 && isTinkerer) {
|
||||||
|
// Randomly select a bonus to add.
|
||||||
|
int random = (int)(Math.random() * probableBonuses.size());
|
||||||
|
Bukkit.getLogger().info("Randomized to # " + (random + 1) + " out of " + probableBonuses.size());
|
||||||
|
|
||||||
ItemMeta temp_meta = orbs.getItemMeta();
|
int i = 0;
|
||||||
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()) {
|
String appliedEnchant = null;
|
||||||
orbs.setType(Material.MAGMA_CREAM);
|
int magnitude = 0;
|
||||||
temp_meta_lore.add("");
|
for (String e : probableBonuses.keySet()) {
|
||||||
temp_meta_lore.add(ChatColor.RED + "You can't afford this!");
|
|
||||||
} else {
|
if (i == random) {
|
||||||
temp_meta_lore.add("");
|
// Rolled this one
|
||||||
temp_meta_lore.add(ChatColor.GREEN + "Completing the operation will");
|
appliedEnchant = e;
|
||||||
temp_meta_lore.add(ChatColor.GREEN + "bring you to " + (player.getLevel() - cost) + " levels.");
|
magnitude = probableBonuses.get(e);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
temp_meta.setLore(temp_meta_lore);
|
int cost = 0;
|
||||||
orbs.setItemMeta(temp_meta);
|
|
||||||
|
|
||||||
orbs.setAmount(cost);
|
if (itemBonuses.get(appliedEnchant) == null) {
|
||||||
anvilInv.setItem(LEVELS, orbs);
|
// This bonus doesn't exist. Calculate full cost.
|
||||||
|
Bukkit.getLogger().info("Bonus doesn't exist.");
|
||||||
|
Bukkit.getLogger().info("Bonus is: " + appliedEnchant + " at magnitude " + magnitude);
|
||||||
|
|
||||||
// Change entry matching modified lore
|
cost += 12;
|
||||||
List<String> bonusesLore = anvilInv.getItem(OUTPUT).getItemMeta().getLore();
|
cost = Math.min(60, cost);
|
||||||
|
cost = Math.max(1, cost);
|
||||||
|
|
||||||
for (int i1 = 0; i1 < bonusesLore.size(); i1++) {
|
ItemStack orbs = new ItemStack(Material.SLIME_BALL);
|
||||||
String e = bonusesLore.get(i1);
|
|
||||||
|
|
||||||
if (containsEnchantment(e, appliedEnchant)) {
|
ItemMeta temp_meta = orbs.getItemMeta();
|
||||||
if (appliedEnchant.equalsIgnoreCase("Critical Chance")) {
|
temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost");
|
||||||
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Critical Chance");
|
List<String> temp_meta_lore = new ArrayList<String>();
|
||||||
}
|
temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels.");
|
||||||
if (appliedEnchant.equalsIgnoreCase("Armor Penetration")) {
|
temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels.");
|
||||||
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Armor Penetration");
|
|
||||||
}
|
if (cost > player.getLevel()) {
|
||||||
if (appliedEnchant.equalsIgnoreCase("Life Steal")) {
|
orbs.setType(Material.MAGMA_CREAM);
|
||||||
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Life Steal");
|
temp_meta_lore.add("");
|
||||||
}
|
temp_meta_lore.add(ChatColor.RED + "You can't afford this!");
|
||||||
if (appliedEnchant.equalsIgnoreCase("Attack Speed")) {
|
} else {
|
||||||
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Attack Speed");
|
temp_meta_lore.add("");
|
||||||
}
|
temp_meta_lore.add(ChatColor.GREEN + "Completing the operation will");
|
||||||
if (appliedEnchant.equalsIgnoreCase("Damage")) {
|
temp_meta_lore.add(ChatColor.GREEN + "bring you to " + (player.getLevel() - cost) + " levels.");
|
||||||
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Damage");
|
}
|
||||||
}
|
|
||||||
if (appliedEnchant.equalsIgnoreCase("Health")) {
|
temp_meta.setLore(temp_meta_lore);
|
||||||
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Health");
|
orbs.setItemMeta(temp_meta);
|
||||||
}
|
|
||||||
if (appliedEnchant.equalsIgnoreCase("Damage Reduction")) {
|
orbs.setAmount(cost);
|
||||||
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Damage Reduction");
|
anvilInv.setItem(LEVELS, orbs);
|
||||||
}
|
|
||||||
if (appliedEnchant.equalsIgnoreCase("Durability")) {
|
// Change entry matching modified lore
|
||||||
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Durability");
|
ItemMeta bonusesMeta = anvilInv.getItem(OUTPUT).getItemMeta();
|
||||||
}
|
List<String> bonusesLore = bonusesMeta.getLore();
|
||||||
if (appliedEnchant.equalsIgnoreCase("Block Chance")) {
|
|
||||||
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Block Chance");
|
Bukkit.getLogger().info("Bonus enchantment string: " + appliedEnchant);
|
||||||
}
|
if (appliedEnchant.equalsIgnoreCase("Critical Chance")) {
|
||||||
if (appliedEnchant.equalsIgnoreCase("Speed Boost Chance")) {
|
bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Critical Chance");
|
||||||
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Speed Boost Chance");
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Armor Penetration")) {
|
||||||
|
bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Armor Penetration");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Life Steal")) {
|
||||||
|
bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Life Steal");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Attack Speed")) {
|
||||||
|
bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Attack Speed");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Damage")) {
|
||||||
|
bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Damage");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Health")) {
|
||||||
|
bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Health");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Damage Reduction")) {
|
||||||
|
bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Damage Reduction");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Durability")) {
|
||||||
|
bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Durability");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Block Chance")) {
|
||||||
|
bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Block Chance");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Speed Boost Chance")) {
|
||||||
|
bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Speed Boost Chance");
|
||||||
|
}
|
||||||
|
|
||||||
|
bonusesMeta.setLore(bonusesLore);
|
||||||
|
anvilInv.getItem(OUTPUT).setItemMeta(bonusesMeta);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// This enchantment exists. Calculate incremental cost.
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Change entry matching modified lore
|
||||||
|
ItemMeta bonusesMeta = anvilInv.getItem(OUTPUT).getItemMeta();
|
||||||
|
List<String> bonusesLore = bonusesMeta.getLore();
|
||||||
|
|
||||||
|
for (int i1 = 0; i1 < bonusesLore.size(); i1++) {
|
||||||
|
String e = bonusesLore.get(i1);
|
||||||
|
|
||||||
|
if (containsEnchantment(e, 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");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Armor Penetration")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Armor Penetration");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Life Steal")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Life Steal");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Attack Speed")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Attack Speed");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Damage")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Damage");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Health")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Health");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Damage Reduction")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Damage Reduction");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Durability")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Durability");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Block 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) {
|
||||||
|
// Magic slot is a book. Unenchanting logic goes here.
|
||||||
|
anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone());
|
||||||
|
anvilInv.getItem(OUTPUT).setType(Material.ENCHANTED_BOOK);
|
||||||
|
anvilInv.getItem(OUTPUT).setDurability((short)0);
|
||||||
|
|
||||||
|
// 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 = 1;
|
||||||
|
|
||||||
|
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user