Merge branch 'newdev' into dev

dev
sigonasr2 11 years ago
commit 271c40553b
  1. 418
      BankEconomyMod/src/me/kaZep/Base/PlayerListener.java

@ -9542,48 +9542,6 @@ implements Listener
if (p.hasPermission("group.administrators")) {
p.getScoreboard().getTeam(p.getName()).setPrefix(ChatColor.DARK_PURPLE+"");
}
if (event.getInventory().getType()==InventoryType.MERCHANT) {
double villager_mult = 2.00d; //The rate at which merchant amounts will be increased (For quantity items).
if (event.getInventory().getContents()[2]!=null) {
//Bukkit.getLogger().info("Result trade item is "+event.getInventory().getContents()[2]);
if (event.getInventory().getContents()[2].getMaxStackSize()>1) {
//This is a stackable item.
//event.getInventory().getContents()[2].setAmount((int)(event.getInventory().getContents()[2].getAmount()*villager_mult));
} else {
int amount=28;
if (event.getInventory().getContents()[0]!=null) {
amount+=event.getInventory().getContents()[0].getAmount()*8;
}
if (event.getInventory().getContents()[1]!=null) {
amount+=event.getInventory().getContents()[1].getAmount()*20;
}
boolean slot1_equip=false;
boolean slot2_equip=false;
ItemMeta meta = event.getInventory().getContents()[2].getItemMeta();
if (event.getInventory().getContents()[0].getMaxStackSize()<=1) {
slot1_equip=true;
}
if (event.getInventory().getContents()[1].getMaxStackSize()<=1) {
slot2_equip=true;
}
if (event.getInventory().getContents()[0].hasItemMeta() && event.getInventory().getContents()[0].getItemMeta().hasLore()) {
meta.setLore(event.getInventory().getContents()[0].getItemMeta().getLore());
} else {
if (event.getInventory().getContents()[1].hasItemMeta() && event.getInventory().getContents()[1].getItemMeta().hasLore()) {
meta.setLore(event.getInventory().getContents()[1].getItemMeta().getLore());
}
}
meta.setDisplayName(ChatColor.GRAY+"Trader's "+convertToItemName(event.getInventory().getContents()[2].getType().name()));
event.getInventory().getContents()[2].setItemMeta(meta);
Random r = new Random(amount);
Map<Enchantment,Integer> map = event.getInventory().getContents()[2].getEnchantments();
for (Map.Entry<Enchantment,Integer> entry : map.entrySet()) {
//Bukkit.getLogger().info("Raising "+entry.getKey().toString()+"'s value from "+entry.getValue());
event.getInventory().getContents()[2].addUnsafeEnchantment(entry.getKey(), entry.getValue()+(r.nextInt(11)));
}
}
}
}
if (event.getCursor()!=null || event.getCurrentItem()!=null) {
if (event.getCursor().getType()==Material.SULPHUR) {
//This is a broken Halloween item...Maybe. Let's find out.
@ -9833,16 +9791,16 @@ implements Listener
final int LEVELS = 22;
boolean anvilClicked = false;
Bukkit.getLogger().info("Anvil interface CLICK at slot #" + event.getRawSlot());
// Bukkit.getLogger().info("Anvil interface CLICK at slot #" + event.getRawSlot());
if (event.getRawSlot() == -999) {
anvilClicked = false;
Bukkit.getLogger().info("Window exterior clicked.");
// Bukkit.getLogger().info("Window exterior clicked.");
} else if (event.getRawSlot() < 27) {
anvilClicked = true;
Bukkit.getLogger().info("Anvil clicked.");
// Bukkit.getLogger().info("Anvil clicked.");
} else {
Bukkit.getLogger().info("Inventory clicked.");
// Bukkit.getLogger().info("Inventory clicked.");
}
if (!anvilClicked) {
// Clicked the inventory. Leave the operation alone UNLESS it's a shift-click operation.
@ -9860,7 +9818,7 @@ implements Listener
*/
if (event.getSlot() == OUTPUT && event.getCursor() != null && event.getCursor().getType() != Material.AIR && !matches(event.getCursor(), event.getCurrentItem())){
Bukkit.getLogger().info("Anvil OUTPUT click.");
// Bukkit.getLogger().info("Anvil OUTPUT click.");
event.setCancelled(true); // Cancel the event if trying to put items into the output slot
}
@ -9868,18 +9826,18 @@ implements Listener
if (event.getInventory().getContents()[OUTPUT] != null
&& event.getSlot() == OUTPUT) {
Bukkit.getLogger().info("Anvil OUTPUT click with output populated.");
// Bukkit.getLogger().info("Anvil OUTPUT click with output populated.");
if (event.getInventory().getContents()[LEVELS].getAmount() > Bukkit.getPlayer(event.getWhoClicked().getName()).getLevel()) {
// Player doesn't have enough XP, abort
Bukkit.getLogger().info("Player has insufficient XP.");
// Bukkit.getLogger().info("Player has insufficient XP.");
p.sendMessage(ChatColor.RED+"You don't have enough experience to do that!");
event.setCancelled(true);
} else {
Bukkit.getLogger().info("Player has sufficient XP.");
// Bukkit.getLogger().info("Player has sufficient XP.");
if (event.getCursor() != null && event.getCursor().getType() != Material.AIR) {
Bukkit.getLogger().info("Anvil OUTPUT click with non-null mouse. Mouse has: " + event.getCursor());
// Bukkit.getLogger().info("Anvil OUTPUT click with non-null mouse. Mouse has: " + event.getCursor());
event.setCancelled(true); // Cancel event if cursor is not empty
@ -9887,7 +9845,7 @@ implements Listener
// Attempts to store the item in the player's inventory.
// If it succeeds, remove the item from the anvil
// interface.
Bukkit.getLogger().info("Shift-click");
// Bukkit.getLogger().info("Shift-click");
if (event
.getWhoClicked()
.getInventory()
@ -9895,16 +9853,48 @@ implements Listener
event.getInventory().getContents()[OUTPUT])
.isEmpty()) {
Bukkit.getLogger().info("Can place into inventory.");
// Bukkit.getLogger().info("Can place into inventory.");
if (event.getCurrentItem().getType() == Material.ENCHANTED_BOOK && event.getInventory().getItem(MAGIC).getType() == Material.BOOK) {
// Halve its durability
event.getInventory().getItem(INPUT).setDurability((short)(event.getInventory().getItem(INPUT).getDurability() + (event.getInventory().getItem(INPUT).getType().getMaxDurability() - event.getInventory().getItem(INPUT).getDurability()) / 2));
// DISENCHANT BEGIN
Map<Enchantment,Integer> map = event.getInventory().getItem(INPUT).getEnchantments();
for (Map.Entry<Enchantment,Integer> entry : map.entrySet()) {
event.getInventory().getItem(INPUT).removeEnchantment(entry.getKey());
}
if (event.getInventory().getItem(INPUT).hasItemMeta() && event.getInventory().getItem(INPUT).getItemMeta().hasLore()) {
List<String> newlore = new ArrayList<String>();
for (int i=0;i<event.getInventory().getItem(INPUT).getItemMeta().getLore().size();i++) {
//Remove all lore when unenchanting.
//Do not remove -400% durability.
if (this.plugin.is_PermanentProperty(event.getInventory().getItem(INPUT).getItemMeta().getLore().get(i))) {
newlore.add(event.getInventory().getItem(INPUT).getItemMeta().getLore().get(i));
}
}
ItemMeta meta = event.getInventory().getItem(INPUT).getItemMeta();
meta.setLore(newlore);
event.getInventory().getItem(INPUT).setItemMeta(meta);
}
// DISENCHANT END
// 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(MAGIC, new ItemStack(Material.AIR));
// Set XP
Bukkit.getPlayer(event.getWhoClicked().getName()).setLevel(Bukkit.getPlayer(event.getWhoClicked().getName()).getLevel() - event.getInventory().getContents()[LEVELS].getAmount());
Bukkit.getLogger().info("Item is: " + event.getInventory().getItem(OUTPUT));
// Bukkit.getLogger().info("Item is: " + event.getInventory().getItem(OUTPUT));
// Play anvil sound
if (event.getInventory().getItem(OUTPUT).getType().toString().toUpperCase().contains("IRON") ||
@ -9930,7 +9920,7 @@ implements Listener
}
} else {
Bukkit.getLogger().info("Anvil OUTPUT click with null mouse.");
// Bukkit.getLogger().info("Anvil OUTPUT click with null mouse.");
if (event.isShiftClick()) {
@ -9939,7 +9929,7 @@ implements Listener
// Attempts to store the item in the player's inventory.
// If it succeeds, remove the item from the anvil
// interface.
Bukkit.getLogger().info("Shift-click");
// Bukkit.getLogger().info("Shift-click");
if (event
.getWhoClicked()
.getInventory()
@ -9947,9 +9937,41 @@ implements Listener
event.getInventory().getContents()[OUTPUT])
.isEmpty()) {
Bukkit.getLogger().info("Can place into inventory.");
// Bukkit.getLogger().info("Can place into inventory.");
if (event.getCurrentItem().getType() == Material.ENCHANTED_BOOK && event.getInventory().getItem(MAGIC).getType() == Material.BOOK) {
// Halve its durability and remove enchantments
event.getInventory().getItem(INPUT).setDurability((short)(event.getInventory().getItem(INPUT).getDurability() + (event.getInventory().getItem(INPUT).getType().getMaxDurability() - event.getInventory().getItem(INPUT).getDurability()) / 2));
// DISENCHANT BEGIN
Map<Enchantment,Integer> map = event.getInventory().getItem(INPUT).getEnchantments();
for (Map.Entry<Enchantment,Integer> entry : map.entrySet()) {
event.getInventory().getItem(INPUT).removeEnchantment(entry.getKey());
}
if (event.getInventory().getItem(INPUT).hasItemMeta() && event.getInventory().getItem(INPUT).getItemMeta().hasLore()) {
List<String> newlore = new ArrayList<String>();
for (int i=0;i<event.getInventory().getItem(INPUT).getItemMeta().getLore().size();i++) {
//Remove all lore when unenchanting.
//Do not remove -400% durability.
if (this.plugin.is_PermanentProperty(event.getInventory().getItem(INPUT).getItemMeta().getLore().get(i))) {
newlore.add(event.getInventory().getItem(INPUT).getItemMeta().getLore().get(i));
}
}
ItemMeta meta = event.getInventory().getItem(INPUT).getItemMeta();
meta.setLore(newlore);
event.getInventory().getItem(INPUT).setItemMeta(meta);
}
// DISENCHANT END
// 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(MAGIC, new ItemStack(Material.AIR));
@ -9977,10 +9999,41 @@ implements Listener
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new updateInventoryTask(event.getWhoClicked().getName()));
}
} else {
Bukkit.getLogger().info("Normal click");
// Bukkit.getLogger().info("Normal click");
// Cursor is empty, item picked up. Subtract XP levels and remove ingredients.
if (event.getCurrentItem().getType() == Material.ENCHANTED_BOOK && event.getInventory().getItem(MAGIC).getType() == Material.BOOK) {
// Halve its durability
event.getInventory().getItem(INPUT).setDurability((short)(event.getInventory().getItem(INPUT).getDurability() + (event.getInventory().getItem(INPUT).getType().getMaxDurability() - event.getInventory().getItem(INPUT).getDurability()) / 2));
// DISENCHANT BEGIN
Map<Enchantment,Integer> map = event.getInventory().getItem(INPUT).getEnchantments();
for (Map.Entry<Enchantment,Integer> entry : map.entrySet()) {
event.getInventory().getItem(INPUT).removeEnchantment(entry.getKey());
}
if (event.getInventory().getItem(INPUT).hasItemMeta() && event.getInventory().getItem(INPUT).getItemMeta().hasLore()) {
List<String> newlore = new ArrayList<String>();
for (int i=0;i<event.getInventory().getItem(INPUT).getItemMeta().getLore().size();i++) {
//Remove all lore when unenchanting.
//Do not remove -400% durability.
if (this.plugin.is_PermanentProperty(event.getInventory().getItem(INPUT).getItemMeta().getLore().get(i))) {
newlore.add(event.getInventory().getItem(INPUT).getItemMeta().getLore().get(i));
}
}
ItemMeta meta = event.getInventory().getItem(INPUT).getItemMeta();
meta.setLore(newlore);
event.getInventory().getItem(INPUT).setItemMeta(meta);
}
// DISENCHANT END
// 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(MAGIC, new ItemStack(Material.AIR));
// event.getInventory().setItem(OUTPUT, new ItemStack(Material.AIR));
@ -10028,7 +10081,7 @@ implements Listener
* All tools and armor types, as well as fishing rods and bows.
*/
Bukkit.getLogger().info("Anvil INPUT click with this item on mouse: " + event.getCursor().getType().toString());
// Bukkit.getLogger().info("Anvil INPUT click with this item on mouse: " + event.getCursor().getType().toString());
/*
if (event.getCursor().getType().toString().toUpperCase().contains("HELMET") || event.getCursor().getType().toString().toUpperCase().contains("CHESTPLATE") ||
@ -10053,7 +10106,7 @@ implements Listener
* Leather, string, wood, cobble, iron, gold, and diamond allowed.
*/
Bukkit.getLogger().info("Anvil MATERIALS click with this item on mouse: " + event.getCursor().getType().toString());
// Bukkit.getLogger().info("Anvil MATERIALS click with this item on mouse: " + event.getCursor().getType().toString());
/*
if (event.getCursor().getType() == Material.LEATHER || event.getCursor().getType() == Material.IRON_INGOT ||
@ -10073,7 +10126,7 @@ implements Listener
* Not implemented yet, so nothing is allowed at the moment.
*/
Bukkit.getLogger().info("Anvil MAGIC click with this item on mouse: " + event.getCursor().getType().toString());
// Bukkit.getLogger().info("Anvil MAGIC click with this item on mouse: " + event.getCursor().getType().toString());
/*
if (event.getCursor().getType() == Material.FLINT || event.getCursor().getType() == Material.QUARTZ ||
@ -13322,6 +13375,7 @@ implements Listener
class updateInventoryTask implements Runnable {
String playerName;
double repairMultiplier, experienceMultiplier;
public updateInventoryTask(String pl){
playerName = pl;
@ -13329,7 +13383,7 @@ class updateInventoryTask implements Runnable {
@Override
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);
Inventory anvilInv = player.getOpenInventory().getTopInventory();
@ -13340,6 +13394,10 @@ class updateInventoryTask implements Runnable {
final int OUTPUT = 16;
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
@ -13348,13 +13406,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("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"))) {
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("ENCHANTED_BOOK"))) {
sendToInventory(INPUT, anvilInv.getItem(INPUT).getAmount(), player);
Bukkit.getLogger().info("Invalid input!");
// Bukkit.getLogger().info("Invalid input!");
} 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());
}
}
@ -13364,24 +13422,27 @@ class updateInventoryTask implements Runnable {
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)) {
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);
Bukkit.getLogger().info("Invalid materials!");
} else {
Bukkit.getLogger().info("Valid materials, " + anvilInv.getItem(MATERIALS).toString().toUpperCase() + " with durability " + anvilInv.getItem(MATERIALS).getDurability());
// Bukkit.getLogger().info("Invalid materials!");
} else if ((anvilInv.getItem(MATERIALS).getType() == Material.ENCHANTED_BOOK || anvilInv.getItem(MATERIALS).getType() == Material.BOOK) && anvilInv.getItem(MAGIC) == null) {
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).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);
Bukkit.getLogger().info("Invalid magic!");
// Bukkit.getLogger().info("Invalid magic!");
} else {
Bukkit.getLogger().info("Valid magic, " + anvilInv.getItem(MAGIC).toString().toUpperCase());
// Bukkit.getLogger().info("Valid magic, " + anvilInv.getItem(MAGIC).toString().toUpperCase());
}
}
@ -13409,6 +13470,14 @@ class updateInventoryTask implements Runnable {
// Verify the right material is combined with the source item.
boolean validCombo = false;
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 ||
anvilInv.getItem(INPUT).getType() == Material.WOOD_SWORD || anvilInv.getItem(INPUT).getType() == Material.WOOD_HOE ||
@ -13495,11 +13564,12 @@ class updateInventoryTask implements Runnable {
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_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_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;
multiplier = 1.2;
@ -13513,16 +13583,31 @@ class updateInventoryTask implements Runnable {
validCombo = true;
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 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.
// 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) {
// 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);
@ -13533,24 +13618,24 @@ class updateInventoryTask implements Runnable {
int bonus_cost = 0;
ItemStack item = anvilInv.getContents()[INPUT];
Bukkit.getLogger().warning("Repair cost calculation valid");
// Bukkit.getLogger().warning("Repair cost calculation valid");
Map<Enchantment, Integer> enchantments = item.getEnchantments();
Bukkit.getLogger().warning(enchantments.keySet().toString());
// Bukkit.getLogger().warning(enchantments.keySet().toString());
for (Enchantment e : enchantments.keySet()) {
Bukkit.getLogger().warning("BC: " + bonus_cost + " | INCR: " + 2 + enchantments.get(e));
// Bukkit.getLogger().warning("BC: " + bonus_cost + " | INCR: " + 2 + enchantments.get(e));
bonus_cost += (2 + enchantments.get(e));
}
cost += bonus_cost;
Bukkit.getLogger().info("Raw cost: " + cost);
// Bukkit.getLogger().info("Raw cost: " + cost);
cost = (short) Math.floor(cost * multiplier);
cost = Math.min(cost, 60); // Cap cost at 60 in case some egregiously enchanted item exists
cost = Math.max(cost, 1); // Make sure it's at least one level
Bukkit.getLogger().info("Cost: " + cost);
// Bukkit.getLogger().info("Cost: " + cost);
ItemStack orbs = new ItemStack(Material.SLIME_BALL);
@ -13580,7 +13665,7 @@ class updateInventoryTask implements Runnable {
// anvilInv.getContents()[OUTPUT].setData(item.getData());
anvilInv.setItem(OUTPUT, item.clone());
anvilInv.getContents()[OUTPUT].setDurability((short) (item.getDurability() - item.getType().getMaxDurability() * 0.2 * anvilInv.getContents()[MATERIALS].getAmount()));
anvilInv.getContents()[OUTPUT].setDurability((short) (item.getDurability() - item.getType().getMaxDurability() * repairMultiplier * anvilInv.getContents()[MATERIALS].getAmount()));
}
@ -13589,7 +13674,8 @@ class updateInventoryTask implements Runnable {
anvilInv.setContents(anvilInv.getContents());
player.updateInventory();
} else if (anvilInv.getItem(INPUT) != null && anvilInv.getItem(MAGIC) != null) {
// Both Magic slots are populated.
if (anvilInv.getItem(MAGIC).getType() == Material.ENCHANTED_BOOK) {
// Both Magic slots are populated, enchanted book is detected.
// 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>();
@ -13605,16 +13691,16 @@ class updateInventoryTask implements Runnable {
if (anvilInv.getItem(INPUT).getItemMeta().hasLore()) {
for (int i = 0; i < anvilInv.getItem(INPUT).getItemMeta().getLore().size(); i++) {
// Put enchantments together for the input. Also stacks identical enchantments.
Bukkit.getLogger().info("Iterating bonus: " + anvilInv.getItem(INPUT).getItemMeta().getLore().get(i));
// Bukkit.getLogger().info("Iterating bonus: " + anvilInv.getItem(INPUT).getItemMeta().getLore().get(i));
if (getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)) != null) {
if (itemBonuses.get(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))) == null) {
Bukkit.getLogger().info("New bonus: " + getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)));
// Bukkit.getLogger().info("New bonus: " + getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)));
itemBonuses.put(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)), getEnchantmentNumb(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)));
} else {
Bukkit.getLogger().info("Stacking bonus: " + itemBonuses.get(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))) + " + " + getEnchantmentNumb(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)));
// Bukkit.getLogger().info("Stacking bonus: " + itemBonuses.get(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))) + " + " + getEnchantmentNumb(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)));
itemBonuses.put(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)), itemBonuses.get(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))) + getEnchantmentNumb(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)));
}
}
@ -13624,14 +13710,14 @@ class updateInventoryTask implements Runnable {
if (anvilInv.getItem(MAGIC).getItemMeta().hasLore()) {
for (int i = 0; i < anvilInv.getItem(MAGIC).getItemMeta().getLore().size(); i++) {
// Put enchantments together for the MAGIC. Also stacks identical enchantments.
Bukkit.getLogger().info("Iterating bonus: " + anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i));
// Bukkit.getLogger().info("Iterating bonus: " + anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i));
if (bookBonuses.get(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))) == null) {
Bukkit.getLogger().info("New bonus: " + getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)));
// Bukkit.getLogger().info("New bonus: " + getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)));
bookBonuses.put(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)), getEnchantmentNumb(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)));
} else {
Bukkit.getLogger().info("Stacking bonus: " + bookBonuses.get(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))) + " + " + getEnchantmentNumb(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)));
// Bukkit.getLogger().info("Stacking bonus: " + bookBonuses.get(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))) + " + " + getEnchantmentNumb(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)));
bookBonuses.put(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)), bookBonuses.get(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))) + getEnchantmentNumb(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)));
}
}
@ -13641,29 +13727,31 @@ class updateInventoryTask implements Runnable {
Map<Enchantment, Integer> probableEnchantments = new java.util.HashMap<Enchantment, Integer>();
for (Enchantment e : bookEnchantments.keySet()) {
Bukkit.getLogger().info("Iterating enchantment: " + e);
// Bukkit.getLogger().info("Iterating enchantment: " + e);
if (itemEnchantments.get(e) == null || bookEnchantments.get(e) > itemEnchantments.get(e)) {
// Book enchantment is larger in magnitude. Assign it as a possible outcome.
probableEnchantments.put(e, bookEnchantments.get(e));
} else if (bookEnchantments.get(e) == itemEnchantments.get(e)) {
} else if (bookEnchantments.get(e) == itemEnchantments.get(e) && bookEnchantments.get(e) <= 10) {
// Book enchantment is same in magnitude. Upgrade by one level.
probableEnchantments.put(e, bookEnchantments.get(e) + 1);
}
}
// Generate appropriate possible bonuses
Map<String, Double> probableBonuses = new java.util.HashMap<String, Double>();
Map<String, Integer> probableBonuses = new java.util.HashMap<String, Integer>();
for (String e : bookBonuses.keySet()) {
Bukkit.getLogger().info("Iterating bonus: " + e);
// 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 (itemBonuses.get(e) == null) {
// Book enchantment is new. Assign it as a possible outcome.
probableBonuses.put(e, (int)Math.round(bookBonuses.get(e) * 0.2));
// The int cast appears to be needed to make it display integers and not stuff like "+5.0 Health"
// Don't remove unless workaround can be found.
} 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));
}
}
@ -13673,7 +13761,7 @@ class updateInventoryTask implements Runnable {
if (probableEnchantments.size() != 0) {
// Randomly select an enchantment to add.
int random = (int)(Math.random() * probableEnchantments.size());
Bukkit.getLogger().info("Randomized to # " + (random + 1) + " out of " + probableEnchantments.size());
// Bukkit.getLogger().info("Randomized to # " + (random + 1) + " out of " + probableEnchantments.size());
int i = 0;
@ -13762,7 +13850,9 @@ class updateInventoryTask implements Runnable {
anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone());
}
if (probableBonuses.size() != 0) {
boolean isTinkerer = true; // Change this to a playerInJob() call later.
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());
@ -13770,7 +13860,7 @@ class updateInventoryTask implements Runnable {
int i = 0;
String appliedEnchant = null;
double magnitude = 0;
int magnitude = 0;
for (String e : probableBonuses.keySet()) {
if (i == random) {
@ -13785,8 +13875,12 @@ class updateInventoryTask implements Runnable {
if (itemBonuses.get(appliedEnchant) == null) {
// 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);
@ -13813,51 +13907,54 @@ class updateInventoryTask implements Runnable {
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);
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")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Critical Chance");
bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Critical Chance");
}
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")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Life Steal");
bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Life Steal");
}
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")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Damage");
bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Damage");
}
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")) {
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Damage Reduction");
bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Damage Reduction");
}
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")) {
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")) {
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 {
// 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);
@ -13884,12 +13981,16 @@ class updateInventoryTask implements Runnable {
anvilInv.setItem(LEVELS, orbs);
// 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++) {
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");
}
@ -13923,7 +14024,8 @@ class updateInventoryTask implements Runnable {
}
}
anvilInv.getItem(OUTPUT).getItemMeta().setLore(bonusesLore);
bonusesMeta.setLore(bonusesLore);
anvilInv.getItem(OUTPUT).setItemMeta(bonusesMeta);
}
}
@ -13932,13 +14034,66 @@ class updateInventoryTask implements Runnable {
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();
}
}
}
public void sendToInventory(int slot, int itemCount, Player player) {
Bukkit.getLogger().info("Slot: " + slot);
Bukkit.getLogger().info("Item Count: " + itemCount);
Bukkit.getLogger().info("Player: " + player.getDisplayName());
// Bukkit.getLogger().info("Slot: " + slot);
// Bukkit.getLogger().info("Item Count: " + itemCount);
// Bukkit.getLogger().info("Player: " + player.getDisplayName());
// Get inventories
Inventory anvilInventory = player.getOpenInventory().getTopInventory();
@ -13956,16 +14111,16 @@ class updateInventoryTask implements Runnable {
}
Bukkit.getLogger().info("Slot stack size is " + anvilInventory.getItem(slot).getAmount());
// Bukkit.getLogger().info("Slot stack size is " + anvilInventory.getItem(slot).getAmount());
if (anvilInventory.getItem(slot).getAmount() - itemCount == 0) {
// Should reduce stack count to zero, meaning item needs to be removed.
Bukkit.getLogger().info("Item stack size reduced to 0, " + anvilInventory.getItem(slot).getType().toString() + " removed.");
// Bukkit.getLogger().info("Item stack size reduced to 0, " + anvilInventory.getItem(slot).getType().toString() + " removed.");
anvilInventory.setItem(slot, new ItemStack(Material.AIR));
} else {
// Should set stack size.
Bukkit.getLogger().info("Reduced stack size from " + anvilInventory.getItem(slot).getAmount() + " by " + itemCount);
// Bukkit.getLogger().info("Reduced stack size from " + anvilInventory.getItem(slot).getAmount() + " by " + itemCount);
anvilInventory.getItem(slot).setAmount(anvilInventory.getItem(slot).getAmount() - itemCount);
}
// player.getWorld().dropItemNaturally(player.getLocation(), new ItemStack(anvilInv.getItem(MATERIALS).getType(), anvilInv.getItem(MATERIALS).getAmount() - maxItemsNeeded));
@ -14003,4 +14158,3 @@ class updateInventoryTask implements Runnable {
}
}

Loading…
Cancel
Save