Make Enchantment merges

master_event
sigonasr2 11 years ago
parent 2b6a439970
commit 77cdd6328d
  1. 495
      BankEconomyMod/src/me/kaZep/Base/PlayerListener.java

@ -12861,41 +12861,71 @@ class updateInventoryTask implements Runnable {
final int LEVELS = 22;
// Redundant validation code for verification
if (anvilInv.getItem(INPUT) != null) {
if (!(anvilInv.getItem(INPUT).getType().toString().toUpperCase().contains("HELMET") || anvilInv.getItem(INPUT).getType().toString().toUpperCase().contains("CHESTPLATE") ||
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("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().contentEquals("BOW"))) {
if (anvilInv.getItem(INPUT) == null || anvilInv.getItem(MATERIALS) == null) {
// No valid combo, set XP orb to stack size 1 and remove output.
anvilInv.getItem(LEVELS).setAmount(1);
anvilInv.setItem(OUTPUT, new ItemStack(Material.AIR));
}
else
{
// Redundant validation code for verification
if (!((anvilInv.getItem(INPUT).toString().toUpperCase().contains("HELMET") || anvilInv.getItem(INPUT).toString().toUpperCase().contains("CHESTPLATE") ||
anvilInv.getItem(INPUT).toString().toUpperCase().contains("LEGGINGS") || anvilInv.getItem(INPUT).toString().toUpperCase().contains("BOOTS") ||
anvilInv.getItem(INPUT).toString().toUpperCase().contains("PICKAXE") || anvilInv.getItem(INPUT).toString().toUpperCase().contains("SPADE") ||
anvilInv.getItem(INPUT).toString().toUpperCase().contains("HOE") || anvilInv.getItem(INPUT).toString().toUpperCase().contains("AXE") ||
anvilInv.getItem(INPUT).toString().toUpperCase().contains("SWORD") || anvilInv.getItem(INPUT).toString().toUpperCase().contains("FISHING") ||
anvilInv.getItem(INPUT).toString().toUpperCase().contentEquals("BOW")) && anvilInv.getItem(INPUT).getDurability() != 0)) {
sendToInventory(anvilInv.getItem(INPUT), anvilInv.getItem(INPUT).getAmount(), player, player.getInventory());
sendToInventory(INPUT, anvilInv.getItem(INPUT).getAmount(), player);
Bukkit.getLogger().info("Invalid input!");
} else {
Bukkit.getLogger().info("Valid input, " + anvilInv.getItem(INPUT).toString().toUpperCase() + " with durability " + anvilInv.getItem(INPUT).getDurability());
}
}
if (anvilInv.getItem(MATERIALS) != null) {
if (!(anvilInv.getItem(MATERIALS).getType() == Material.LEATHER || anvilInv.getItem(MATERIALS).getType() == Material.IRON_INGOT ||
anvilInv.getItem(MATERIALS).getType() == Material.GOLD_INGOT || anvilInv.getItem(MATERIALS).getType() == Material.IRON_BLOCK ||
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.LOG || anvilInv.getItem(MATERIALS).getType() == Material.STONE ||
anvilInv.getItem(MATERIALS).getType() == Material.STRING)) {
sendToInventory(anvilInv.getItem(MATERIALS), anvilInv.getItem(MATERIALS).getAmount(), player, player.getInventory());
sendToInventory(MATERIALS, anvilInv.getItem(MATERIALS).getAmount(), player);
Bukkit.getLogger().info("Invalid materials!");
} else {
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).getType() == Material.ENCHANTED_BOOK)) {
sendToInventory(MAGIC, anvilInv.getItem(MAGIC).getAmount(), player);
Bukkit.getLogger().info("Invalid magic!");
} else {
Bukkit.getLogger().info("Valid magic, " + anvilInv.getItem(MAGIC).toString().toUpperCase());
}
}
if ((anvilInv.getItem(INPUT) == null) || // No input, or material/magic both empty, or all three filled, or input and materials filled but item full
(anvilInv.getItem(MAGIC) == null && anvilInv.getItem(MATERIALS) == null) ||
(anvilInv.getItem(MAGIC) != null && anvilInv.getItem(MATERIALS) != null && anvilInv.getItem(INPUT) != null) ||
(anvilInv.getItem(INPUT) != null && anvilInv.getItem(MATERIALS) != null && anvilInv.getItem(INPUT).getDurability() == 0)) {
// No valid combo, set XP orb to stack size 1 and remove output.
anvilInv.setItem(OUTPUT, new ItemStack(Material.AIR));
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 + "Experience Cost of Enchanting.");
temp_meta.setLore(temp_meta_lore);
orbs.setItemMeta(temp_meta);
anvilInv.setItem(LEVELS, orbs);
// TRY EVERYTHING
player.getInventory().setContents(player.getInventory().getContents());
anvilInv.setContents(anvilInv.getContents());
player.updateInventory();
} else if (anvilInv.getItem(INPUT) != null && anvilInv.getItem(MATERIALS) != null && anvilInv.getItem(INPUT).getDurability() != 0) {
// Both repair slots are populated, and the item is damaged.
// Verify the right material is combined with the source item.
boolean validCombo = false;
double multiplier = 0;
@ -12908,6 +12938,14 @@ class updateInventoryTask implements Runnable {
multiplier = 0.1;
}
if (anvilInv.getItem(MATERIALS).getType() == Material.LOG && (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_PICKAXE || anvilInv.getItem(INPUT).getType() == Material.WOOD_SPADE)) {
validCombo = true;
multiplier = 0;
}
if (anvilInv.getItem(MATERIALS).getType() == Material.STRING && (anvilInv.getItem(INPUT).getType() == Material.FISHING_ROD ||
anvilInv.getItem(INPUT).getType() == Material.BOW)) {
@ -12923,6 +12961,14 @@ class updateInventoryTask implements Runnable {
multiplier = 0.2;
}
if (anvilInv.getItem(MATERIALS).getType() == Material.STONE && (anvilInv.getItem(INPUT).getType() == Material.STONE_AXE ||
anvilInv.getItem(INPUT).getType() == Material.STONE_SWORD || anvilInv.getItem(INPUT).getType() == Material.STONE_HOE ||
anvilInv.getItem(INPUT).getType() == Material.STONE_PICKAXE || anvilInv.getItem(INPUT).getType() == Material.STONE_SPADE)) {
validCombo = true;
multiplier = 0;
}
if (anvilInv.getItem(MATERIALS).getType() == Material.LEATHER && (anvilInv.getItem(INPUT).getType() == Material.LEATHER_BOOTS ||
anvilInv.getItem(INPUT).getType() == Material.LEATHER_CHESTPLATE || anvilInv.getItem(INPUT).getType() == Material.LEATHER_HELMET ||
anvilInv.getItem(INPUT).getType() == Material.LEATHER_LEGGINGS)) {
@ -12998,10 +13044,10 @@ class updateInventoryTask implements Runnable {
if (anvilInv.getItem(MATERIALS).getAmount() > maxItemsNeeded) {
// Bukkit.getLogger().info("Materials exceed " + maxItemsNeeded + " stack. Dropping " + (anvilInv.getItem(MATERIALS).getAmount() - maxItemsNeeded) + " of " + anvilInv.getItem(MATERIALS).getType());
sendToInventory(anvilInv.getItem(MATERIALS), anvilInv.getItem(MATERIALS).getAmount() - maxItemsNeeded, player, player.getInventory());
sendToInventory(MATERIALS, anvilInv.getItem(MATERIALS).getAmount() - maxItemsNeeded, player);
// anvilInv.getItem(MATERIALS).setAmount(maxItemsNeeded);
}
}
int cost = anvilInv.getContents()[MATERIALS].getAmount() * 2;
int bonus_cost = 0;
@ -13062,30 +13108,419 @@ class updateInventoryTask implements Runnable {
player.getInventory().setContents(player.getInventory().getContents());
anvilInv.setContents(anvilInv.getContents());
player.updateInventory();
} else if (anvilInv.getItem(INPUT) != null && anvilInv.getItem(MAGIC) != null) {
// Both Magic slots are populated.
// Get the list of enchantments from both items.
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());
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>();
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 {
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 {
Bukkit.getLogger().info("Stacking bonus: " + bookBonuses.get(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))) + " + " + getEnchantmentNumb(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)));
bookBonuses.put(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)), bookBonuses.get(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))) + getEnchantmentNumb(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)));
}
}
}
// Generate appropriate possible enchantments
Map<Enchantment, Integer> probableEnchantments = new java.util.HashMap<Enchantment, Integer>();
for (Enchantment e : bookEnchantments.keySet()) {
Bukkit.getLogger().info("Iterating enchantment: " + e);
if (itemEnchantments.get(e) == null || bookEnchantments.get(e) > itemEnchantments.get(e)) {
// Book enchantment is larger in magnitude. Assign it as a possible outcome.
probableEnchantments.put(e, bookEnchantments.get(e));
} else if (bookEnchantments.get(e) == itemEnchantments.get(e)) {
// Book enchantment is same in magnitude. Upgrade by one level.
probableEnchantments.put(e, bookEnchantments.get(e) + 1);
}
}
// 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 (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 {
// Can't add enchant, but can add bonus. Prepare output for bonus.
anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone());
}
if (probableBonuses.size() != 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;
String appliedEnchant = null;
double magnitude = 0;
for (String e : probableBonuses.keySet()) {
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");
}
}
}
anvilInv.getItem(OUTPUT).getItemMeta().setLore(bonusesLore);
} else {
// This enchantment exists. Calculate incremental cost.
cost = (int)(30 * itemBonuses.get(appliedEnchant) / probableBonuses.get(appliedEnchant)); // 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);
// 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");
}
}
}
anvilInv.getItem(OUTPUT).getItemMeta().setLore(bonusesLore);
}
}
}
// TRY EVERYTHING
player.getInventory().setContents(player.getInventory().getContents());
anvilInv.setContents(anvilInv.getContents());
player.updateInventory();
}
}
public void sendToInventory(ItemStack item, int number, Player player, Inventory target) {
public void sendToInventory(int slot, int itemCount, Player player) {
Bukkit.getLogger().info("Slot: " + slot);
Bukkit.getLogger().info("Item Count: " + itemCount);
Bukkit.getLogger().info("Player: " + player.getDisplayName());
// Get inventories
Inventory anvilInventory = player.getOpenInventory().getTopInventory();
Inventory playerInventory = player.getOpenInventory().getBottomInventory();
ItemStack temp = item.clone();
// Get a temporary item stack to transfer
ItemStack temp = anvilInventory.getItem(slot).clone();
temp.setAmount(itemCount);
temp.setAmount(number);
ItemStack leftovers = target.addItem(temp).get(0);
// Attempt to add to the player inventory. Store leftovers in itemstack to be dropped.
ItemStack leftovers = playerInventory.addItem(temp).get(0);
if (leftovers != null) {
player.getWorld().dropItemNaturally(player.getLocation(), leftovers);
}
item.setAmount(item.getAmount() - number);
if (item.getAmount() - number == 0) {
item.setType(Material.AIR);
Bukkit.getLogger().info("Slot stack size is " + anvilInventory.getItem(slot).getAmount());
Bukkit.getLogger().info("Item stack size reduced to 0, " + item.getType().toString() + " removed.");
if (anvilInventory.getItem(slot).getAmount() - itemCount == 0) {
// Should reduce stack count to zero, meaning item needs to be removed.
Bukkit.getLogger().info("Item stack size reduced to 0, " + anvilInventory.getItem(slot).getType().toString() + " removed.");
anvilInventory.setItem(slot, new ItemStack(Material.AIR));
} else {
// Should set stack size.
Bukkit.getLogger().info("Reduced stack size from " + anvilInventory.getItem(slot).getAmount() + " by " + itemCount);
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));
}
public double getEnchantmentNumb(String s) {
//Parse the string for spaces.
String[] enchant = s.split(" ");
if (enchant[0].contains(ChatColor.YELLOW+"")) {
String newstring = ((enchant[0].replace(ChatColor.YELLOW.getChar(), ' ')).replace('%', ' ')).replace(Character.toString((char)0x00A7), Character.toString((char)0x0020));
//Bukkit.getLogger().info("Enchant number is "+Double.valueOf(newstring));
return Double.valueOf(newstring);
} else {
return 0;
}
}
public String getEnchantmentName(String s) {
//Parse the string for spaces.
String[] enchant = s.split(ChatColor.BLUE+"");
if (enchant.length > 1) {
return enchant[1];
} else {
return null;
}
}
public boolean containsEnchantment(String s, String enchant) {
if (s.contains(enchant)) {
return true;
}
return false;
}
}

Loading…
Cancel
Save