Fix sortEnchantments() so it works in all situations. Fixed issue with

Enchanter A buff creating inventory desyncs.
dev
sigonasr2 11 years ago
parent e6e0fd9df2
commit 9781185282
  1. 22
      BankEconomyMod/src/me/kaZep/Base/Main.java
  2. 28
      BankEconomyMod/src/me/kaZep/Base/PlayerListener.java

@ -5504,9 +5504,11 @@ public void payDay(int time)
List<String> newLoreData = new ArrayList<String>();
//First find all 'extra' special enchantments.
for (int i=0;i<LoreData.size();i++) {
if (LoreData.get(i).contains(ChatColor.GRAY+"Sturdy ")) {
newLoreData.add(LoreData.get(i));
LoreData.remove(i);
for (int j=0;j<getBonusRomanNumeralEnchantments().size();j++) {
if (LoreData.get(i).contains(ChatColor.GRAY+getBonusRomanNumeralEnchantments().get(j).name+" ")) {
newLoreData.add(LoreData.get(i));
LoreData.remove(i);
}
}
}
//Now find all bonus enchantments.
@ -6124,6 +6126,20 @@ public void payDay(int time)
}
return finallist;
}
/**
* A helper function for Bonus Enchantments.
* @return Returns all enchantments in a list that are formatted like real Minecraft enchantments.
*/
public static List<BonusEnchantment> getBonusRomanNumeralEnchantments() {
List<BonusEnchantment> finallist = new ArrayList<BonusEnchantment>();
for (int i=0;i<bonus_enchantment_list.size();i++) {
if (bonus_enchantment_list.get(i).enchant_format) {
finallist.add(bonus_enchantment_list.get(i));
}
}
return finallist;
}
}
class BonusEnchantment {

@ -480,7 +480,7 @@ implements Listener
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_BLOCK_CHANCE, 5*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_SPEED_BOOST_CHANCE, 20*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_STURDY, lvs/10+1);inv.addItem(base);
if (lvs==30) {base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_REPAIR, lvs/10+1);inv.addItem(base);}
if (lvs==30) {base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_REPAIR, 1);inv.addItem(base);}
} else
if (input.getType().name().toLowerCase().contains("chestplate") || input.getType().name().toLowerCase().contains("leggings")) {
ItemStack base = input.clone();base.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, base.getEnchantmentLevel(Enchantment.PROTECTION_ENVIRONMENTAL)+lvs/10+1);inv.addItem(base);
@ -495,7 +495,7 @@ implements Listener
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_BLOCK_CHANCE, 5*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_SPEED_BOOST_CHANCE, 20*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_STURDY, lvs/10+1);inv.addItem(base);
if (lvs==30) {base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_REPAIR, lvs/10+1);inv.addItem(base);}
if (lvs==30) {base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_REPAIR, 1);inv.addItem(base);}
} else
if (input.getType().name().toLowerCase().contains("boots")) {
ItemStack base = input.clone();base.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, base.getEnchantmentLevel(Enchantment.PROTECTION_ENVIRONMENTAL)+lvs/10+1);inv.addItem(base);
@ -511,7 +511,7 @@ implements Listener
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_BLOCK_CHANCE, 5*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_SPEED_BOOST_CHANCE, 20*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_STURDY, lvs/10+1);inv.addItem(base);
if (lvs==30) {base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_REPAIR, lvs/10+1);inv.addItem(base);}
if (lvs==30) {base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_REPAIR, 1);inv.addItem(base);}
} else
if (input.getType().name().toLowerCase().contains("sword")) {
ItemStack base = input.clone();base.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, base.getEnchantmentLevel(Enchantment.DAMAGE_ALL)+lvs/10+1);inv.addItem(base);
@ -526,7 +526,7 @@ implements Listener
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_LIFE_STEAL, 2*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_ATTACK_SPEED, 10*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_DAMAGE, 2*(lvs/10+1));inv.addItem(base);
if (lvs==30) {base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_EXECUTE, lvs/10+1);inv.addItem(base);}
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_EXECUTE, lvs/10+1);inv.addItem(base);
} else
if (input.getType().name().toLowerCase().contains("axe") && !input.getType().name().toLowerCase().contains("pickaxe")) {
ItemStack base = input.clone();base.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, base.getEnchantmentLevel(Enchantment.DAMAGE_ALL)+lvs/10+1);inv.addItem(base);
@ -540,7 +540,7 @@ implements Listener
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_LIFE_STEAL, 2*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_ATTACK_SPEED, 10*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_DAMAGE, 2*(lvs/10+1));inv.addItem(base);
if (lvs==30) {base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_EXECUTE, lvs/10+1);inv.addItem(base);}
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_EXECUTE, lvs/10+1);inv.addItem(base);
} else
if (input.getType().name().toLowerCase().contains("spade") || input.getType().name().toLowerCase().contains("pickaxe")) {
ItemStack base = input.clone();base.addUnsafeEnchantment(Enchantment.DIG_SPEED, base.getEnchantmentLevel(Enchantment.DIG_SPEED)+lvs/10+1);inv.addItem(base);
@ -552,7 +552,7 @@ implements Listener
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_LIFE_STEAL, 2*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_ATTACK_SPEED, 10*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_DAMAGE, 2*(lvs/10+1));inv.addItem(base);
if (lvs==30) {base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_EXECUTE, lvs/10+1);inv.addItem(base);}
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_EXECUTE, lvs/10+1);inv.addItem(base);
} else
if (input.getType().name().toLowerCase().contains("bow")) {
ItemStack base = input.clone();base.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, base.getEnchantmentLevel(Enchantment.ARROW_DAMAGE)+lvs/10+1);inv.addItem(base);
@ -565,7 +565,7 @@ implements Listener
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_LIFE_STEAL, 2*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_ATTACK_SPEED, 10*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_DAMAGE, 2*(lvs/10+1));inv.addItem(base);
if (lvs==30) {base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_EXECUTE, lvs/10+1);inv.addItem(base);}
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_EXECUTE, lvs/10+1);inv.addItem(base);
} else
if (input.getType().name().toLowerCase().contains("hoe")) {
ItemStack base = input.clone();base.addUnsafeEnchantment(Enchantment.DURABILITY, base.getEnchantmentLevel(Enchantment.DURABILITY)+lvs/10+1);inv.addItem(base);
@ -574,7 +574,7 @@ implements Listener
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_LIFE_STEAL, 2*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_ATTACK_SPEED, 10*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_DAMAGE, 2*(lvs/10+1));inv.addItem(base);
if (lvs==30) {base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_EXECUTE, lvs/10+1);inv.addItem(base);}
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_EXECUTE, lvs/10+1);inv.addItem(base);
} else
if (input.getType().name().toLowerCase().contains("shears")) {
ItemStack base = input.clone();base.addUnsafeEnchantment(Enchantment.DIG_SPEED, base.getEnchantmentLevel(Enchantment.DIG_SPEED)+lvs/10+1);inv.addItem(base);
@ -585,7 +585,7 @@ implements Listener
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_LIFE_STEAL, 2*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_ATTACK_SPEED, 10*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_DAMAGE, 2*(lvs/10+1));inv.addItem(base);
if (lvs==30) {base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_EXECUTE, lvs/10+1);inv.addItem(base);}
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_EXECUTE, lvs/10+1);inv.addItem(base);
} else
if (input.getType().name().toLowerCase().contains("flint")) {
ItemStack base = input.clone();base.addUnsafeEnchantment(Enchantment.DURABILITY, base.getEnchantmentLevel(Enchantment.DURABILITY)+lvs/10+1);inv.addItem(base);
@ -594,7 +594,7 @@ implements Listener
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_LIFE_STEAL, 2*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_ATTACK_SPEED, 10*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_DAMAGE, 2*(lvs/10+1));inv.addItem(base);
if (lvs==30) {base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_EXECUTE, lvs/10+1);inv.addItem(base);}
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_EXECUTE, lvs/10+1);inv.addItem(base);
} else
if (input.getType().name().toLowerCase().contains("carrot")) {
ItemStack base = input.clone();base.addUnsafeEnchantment(Enchantment.DURABILITY, base.getEnchantmentLevel(Enchantment.DURABILITY)+lvs/10+1);inv.addItem(base);
@ -603,7 +603,7 @@ implements Listener
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_LIFE_STEAL, 2*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_ATTACK_SPEED, 10*(lvs/10+1));inv.addItem(base);
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_DAMAGE, 2*(lvs/10+1));inv.addItem(base);
if (lvs==30) {base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_EXECUTE, lvs/10+1);inv.addItem(base);}
base = input.clone();this.plugin.addBonusEnchantment(base, Main.ENCHANT_EXECUTE, lvs/10+1);inv.addItem(base);
} else {
return null;
}
@ -13098,10 +13098,6 @@ implements Listener
}
} else
if (event.getInventory().getTitle().equalsIgnoreCase("Choose an additional bonus:")) {
if (event.getClick()!=ClickType.LEFT) {
event.setCancelled(true);
p.updateInventory();
}
if (event.getClick()==ClickType.LEFT) {
//Select this one. Drop it on the ground.
//Bukkit.getLogger().info("Raw slot is "+event.getRawSlot());
@ -13117,6 +13113,8 @@ implements Listener
p.getInventory().removeItem(p.getInventory().getContents()[i]);
}
}
event.setCancelled(true);
p.updateInventory();
p.closeInventory();
}
} else {

Loading…
Cancel
Save