From 2c7883ebc39193964d92a51e92dffbc5db72ab3c Mon Sep 17 00:00:00 2001 From: Nonoriri Date: Sat, 23 Nov 2013 14:35:47 -0500 Subject: [PATCH] Re-added deleted anvil code. --- .../src/me/kaZep/Base/PlayerListener.java | 1410 +++++++++-------- 1 file changed, 782 insertions(+), 628 deletions(-) diff --git a/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java b/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java index 271faa0..7a9d82a 100644 --- a/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java +++ b/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java @@ -209,7 +209,7 @@ implements Listener } enum Cube { SMALL, LARGE, ENDER } - + public boolean naturalBlock(Material mat) { List natural_mats = new ArrayList(); natural_mats.add(Material.DIRT); @@ -232,7 +232,7 @@ implements Listener return false; } } - + public void updateTopSPLEEFSigns() { String name[] = {"","",""}; int rating[] = {-9999,-9999,-9999}, wins[] = {0,0,0}, losses[] = {0,0,0}; @@ -1283,15 +1283,15 @@ implements Listener } - @EventHandler - public void onPlayerWakeup(PlayerBedLeaveEvent e) { - Player p = e.getPlayer(); - //p.sendMessage("Wakeup at "+Bukkit.getWorld("world").getTime()); - if (Bukkit.getWorld("world").getTime()==0) { - this.plugin.last_world_time=0; + @EventHandler + public void onPlayerWakeup(PlayerBedLeaveEvent e) { + Player p = e.getPlayer(); + //p.sendMessage("Wakeup at "+Bukkit.getWorld("world").getTime()); + if (Bukkit.getWorld("world").getTime()==0) { + this.plugin.last_world_time=0; + } + return; } - return; - } @EventHandler public void onPlayerSneak(PlayerToggleSneakEvent e) { @@ -2090,13 +2090,13 @@ implements Listener l.setHealth(l.getMaxHealth()); } } - if (Math.random()<=0.003 && l.getLocation().getY()>=60) { - Skeleton s = (Skeleton)l; - s.setSkeletonType(SkeletonType.WITHER); - s.setMaxHealth(150); - s.setHealth(s.getMaxHealth()); - s.getEquipment().setItemInHand(new ItemStack(Material.IRON_SWORD)); - } + if (Math.random()<=0.003 && l.getLocation().getY()>=60) { + Skeleton s = (Skeleton)l; + s.setSkeletonType(SkeletonType.WITHER); + s.setMaxHealth(150); + s.setHealth(s.getMaxHealth()); + s.getEquipment().setItemInHand(new ItemStack(Material.IRON_SWORD)); + } }break; case SLIME: { }break; @@ -3197,7 +3197,7 @@ implements Listener private void breakOreBlock(Player p, Block b, boolean silk_touch) { breakOreBlock(p, b, false, 1); } - + private void breakOreBlock(Player p, Block b, boolean silk_touch, double xp_mult) { if (this.plugin.PlayerinJob(p, "Miner")) { //Bukkit.getLogger().info("This player is a miner."); @@ -3207,49 +3207,49 @@ implements Listener if (b.getType()==Material.STONE) { this.plugin.gainMoneyExp(p,"Miner",0.0025,1); } else - if (b.getType()==Material.NETHERRACK) { - this.plugin.gainMoneyExp(p,"Miner",0.005,1); - } else - if (b.getType()==Material.COAL_ORE && !silk_touch) { - this.plugin.gainMoneyExp(p,"Miner",0.0125,3); - //Bukkit.getLogger().info("Coal Ore."); - } else - if (b.getType()==Material.GLOWSTONE && !silk_touch) { - this.plugin.gainMoneyExp(p,"Miner",0.015,3); - } else - if (b.getType()==Material.SANDSTONE) { - this.plugin.gainMoneyExp(p,"Miner",0.015,4); - } else - if (b.getType()==Material.NETHER_BRICK) { - this.plugin.gainMoneyExp(p,"Miner",0.02,3); - } else - if (b.getType()==Material.QUARTZ_ORE && !silk_touch) { - this.plugin.gainMoneyExp(p,"Miner",0.025,4); - } else - if (b.getType()==Material.LAPIS_ORE && !silk_touch) { - this.plugin.gainMoneyExp(p,"Miner",0.03,5); - } else - if (b.getType()==Material.MOSSY_COBBLESTONE) { - this.plugin.gainMoneyExp(p,"Miner",0.0375,8); - } else - if (b.getType()==Material.IRON_ORE && !silk_touch) { - this.plugin.gainMoneyExp(p,"Miner",0.0375,6); - } else - if ((b.getType()==Material.REDSTONE_ORE || b.getType()==Material.GLOWING_REDSTONE_ORE) && !silk_touch) { - this.plugin.gainMoneyExp(p,"Miner",0.05,9); - } else - if (b.getType()==Material.OBSIDIAN) { - this.plugin.gainMoneyExp(p,"Miner",0.0625,10); - } else - if (b.getType()==Material.GOLD_ORE && !silk_touch) { - this.plugin.gainMoneyExp(p,"Miner",0.0975,12); - } else - if (b.getType()==Material.DIAMOND_ORE && !silk_touch) { - this.plugin.gainMoneyExp(p,"Miner",0.3125,60); - } else - if (b.getType()==Material.EMERALD_ORE && !silk_touch) { - this.plugin.gainMoneyExp(p,"Miner",0.7625,160); - } + if (b.getType()==Material.NETHERRACK) { + this.plugin.gainMoneyExp(p,"Miner",0.005,1); + } else + if (b.getType()==Material.COAL_ORE && !silk_touch) { + this.plugin.gainMoneyExp(p,"Miner",0.0125,3); + //Bukkit.getLogger().info("Coal Ore."); + } else + if (b.getType()==Material.GLOWSTONE && !silk_touch) { + this.plugin.gainMoneyExp(p,"Miner",0.015,3); + } else + if (b.getType()==Material.SANDSTONE) { + this.plugin.gainMoneyExp(p,"Miner",0.015,4); + } else + if (b.getType()==Material.NETHER_BRICK) { + this.plugin.gainMoneyExp(p,"Miner",0.02,3); + } else + if (b.getType()==Material.QUARTZ_ORE && !silk_touch) { + this.plugin.gainMoneyExp(p,"Miner",0.025,4); + } else + if (b.getType()==Material.LAPIS_ORE && !silk_touch) { + this.plugin.gainMoneyExp(p,"Miner",0.03,5); + } else + if (b.getType()==Material.MOSSY_COBBLESTONE) { + this.plugin.gainMoneyExp(p,"Miner",0.0375,8); + } else + if (b.getType()==Material.IRON_ORE && !silk_touch) { + this.plugin.gainMoneyExp(p,"Miner",0.0375,6); + } else + if ((b.getType()==Material.REDSTONE_ORE || b.getType()==Material.GLOWING_REDSTONE_ORE) && !silk_touch) { + this.plugin.gainMoneyExp(p,"Miner",0.05,9); + } else + if (b.getType()==Material.OBSIDIAN) { + this.plugin.gainMoneyExp(p,"Miner",0.0625,10); + } else + if (b.getType()==Material.GOLD_ORE && !silk_touch) { + this.plugin.gainMoneyExp(p,"Miner",0.0975,12); + } else + if (b.getType()==Material.DIAMOND_ORE && !silk_touch) { + this.plugin.gainMoneyExp(p,"Miner",0.3125,60); + } else + if (b.getType()==Material.EMERALD_ORE && !silk_touch) { + this.plugin.gainMoneyExp(p,"Miner",0.7625,160); + } } } Material[] fortune_materials = {Material.EMERALD_ORE,Material.COAL_ORE,Material.DIAMOND_ORE,Material.REDSTONE_ORE,Material.GLOWING_REDSTONE_ORE,Material.LAPIS_ORE,Material.QUARTZ_ORE}; //An array of all blocks that multiply via fortune. @@ -3258,16 +3258,16 @@ implements Listener int fortune_material_slot=0; int mult = 1; short WOOD_PICKAXE = 0, STONE_PICKAXE = 1, GOLD_PICKAXE = 2, IRON_PICKAXE = 3, DIAMOND_PICKAXE = 4; //Constants that define the pickaxe strength. - + short[] material_pickaxe_requirements = {IRON_PICKAXE,WOOD_PICKAXE,IRON_PICKAXE,IRON_PICKAXE,IRON_PICKAXE,STONE_PICKAXE,WOOD_PICKAXE}; - + short my_pickaxe_strength=-1; //-1 is some other random item / your hand. switch (p.getItemInHand().getType()) { - case WOOD_PICKAXE:{my_pickaxe_strength = WOOD_PICKAXE;}break; - case STONE_PICKAXE:{my_pickaxe_strength = STONE_PICKAXE;}break; - case GOLD_PICKAXE:{my_pickaxe_strength = GOLD_PICKAXE;}break; - case IRON_PICKAXE:{my_pickaxe_strength = IRON_PICKAXE;}break; - case DIAMOND_PICKAXE:{my_pickaxe_strength = DIAMOND_PICKAXE;}break; + case WOOD_PICKAXE:{my_pickaxe_strength = WOOD_PICKAXE;}break; + case STONE_PICKAXE:{my_pickaxe_strength = STONE_PICKAXE;}break; + case GOLD_PICKAXE:{my_pickaxe_strength = GOLD_PICKAXE;}break; + case IRON_PICKAXE:{my_pickaxe_strength = IRON_PICKAXE;}break; + case DIAMOND_PICKAXE:{my_pickaxe_strength = DIAMOND_PICKAXE;}break; } for (int i=0;i effects = p.getActivePotionEffects().iterator(); - //Figure out potion effects when player joins. - while (effects.hasNext()) { - PotionEffect nexteffect = effects.next(); - if (nexteffect.getType().getName().compareTo(PotionEffectType.HEALTH_BOOST.getName())==0) { - double myhealth = p.getHealth(); - p.removePotionEffect(PotionEffectType.HEALTH_BOOST); - p.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST,1200,nexteffect.getAmplifier()+1)); - p.setHealth(myhealth); - } - effects.remove(); + //Figure out potion effects when player joins. + while (effects.hasNext()) { + PotionEffect nexteffect = effects.next(); + if (nexteffect.getType().getName().compareTo(PotionEffectType.HEALTH_BOOST.getName())==0) { + double myhealth = p.getHealth(); + p.removePotionEffect(PotionEffectType.HEALTH_BOOST); + p.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST,1200,nexteffect.getAmplifier()+1)); + p.setHealth(myhealth); } - } catch (ConcurrentModificationException ex_e) { - Bukkit.getLogger().warning("Potion Effect Collection not accessible while initializing player speed."); - } + effects.remove(); + } + } catch (ConcurrentModificationException ex_e) { + Bukkit.getLogger().warning("Potion Effect Collection not accessible while initializing player speed."); + } p.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST,1200,0)); destroyNearbyTree(e.getBlock().getWorld() ,e.getBlock().getLocation(), e.getBlock().getLocation(), (byte)(e.getBlock().getData()%4), p.getItemInHand().getEnchantmentLevel(Enchantment.SILK_TOUCH)>0); } } - + if (this.plugin.hasJobBuff("Miner", p, Job.JOB5)) { if (e.getBlock().getType().name().toLowerCase().contains("ore")) { @@ -3623,7 +3623,7 @@ implements Listener } } //*******************************//Job Buffs end here! - + int myData=this.plugin.getPlayerDataSlot(p); if (p!=null) { if (e.getBlock().getType()==Material.COMMAND) { @@ -5545,7 +5545,7 @@ implements Listener public ItemStack getGoodie() { return getGoodie(0); } - + public ItemStack getGoodie(int rar /*1=Mythical 0=Normal*/) { ItemStack item = null; if (Math.random()<0.33) { @@ -7217,7 +7217,7 @@ implements Listener @EventHandler public void onEnemyHit(EntityDamageByEntityEvent e) { - + //**********************************//Player buffs begin if (e.getDamager() instanceof Player) { Player p = (Player)e.getDamager(); @@ -7226,7 +7226,7 @@ implements Listener } } //**********************************//Player buffs end - + if (e.getEntity() instanceof LivingEntity) { final LivingEntity l = (LivingEntity)e.getEntity(); if (l instanceof Player) { @@ -7254,37 +7254,37 @@ implements Listener l.removePotionEffect(PotionEffectType.NIGHT_VISION); l.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,999999,2)); LivingEntity zombie = (LivingEntity)Bukkit.getWorld("world").spawnEntity(e.getEntity().getLocation(),EntityType.ZOMBIE); - LivingEntity enderdragon = (LivingEntity)Bukkit.getWorld("world").spawnEntity(e.getEntity().getLocation(),EntityType.ENDER_DRAGON); - //Bukkit.getWorld("world").spawn(e.getEntity().getLocation(), enderdragon.getClass()); - zombie.setCustomName(ChatColor.DARK_PURPLE+"Charge Zombie III"); - zombie.getEquipment().setBoots(new ItemStack(Material.IRON_BOOTS)); - zombie.getEquipment().setChestplate(new ItemStack(Material.IRON_CHESTPLATE)); - zombie.getEquipment().setLeggings(new ItemStack(Material.IRON_LEGGINGS)); - zombie.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION,999999,3)); - ItemStack sword = new ItemStack(Material.IRON_SWORD); - sword.addEnchantment(Enchantment.DAMAGE_ALL, 3); - zombie.getEquipment().setItemInHand(sword); - ItemStack skull = new ItemStack(397); - skull.setDurability((short)3); - SkullMeta meta = (SkullMeta)skull.getItemMeta(); - meta.setOwner("MHF_Enderman"); - skull.setItemMeta(meta); - zombie.getEquipment().setHelmet(skull); - - enderdragon.setCustomName(ChatColor.DARK_PURPLE+"Charge Zombie III"); - enderdragon.setMaxHealth(200); - enderdragon.setHealth(200); - enderdragon.remove(); - //enderdragon.teleport(new Location(p.getWorld(),p.getLocation().getBlockX()+i,-250,p.getLocation().getBlockZ()+j)); - //p.sendMessage(ChatColor.DARK_PURPLE+"You feel a dark presence nearby."); - //Bukkit.getPlayer("sigonasr2").sendMessage("Trigger this."); - zombie.setRemoveWhenFarAway(false); - zombie.setMaxHealth(300); - zombie.setHealth(300); - zombie.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION,999999,0)); - zombie.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE,999999,0)); - zombie.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING,999999,0)); - zombie.setTicksLived(1); + LivingEntity enderdragon = (LivingEntity)Bukkit.getWorld("world").spawnEntity(e.getEntity().getLocation(),EntityType.ENDER_DRAGON); + //Bukkit.getWorld("world").spawn(e.getEntity().getLocation(), enderdragon.getClass()); + zombie.setCustomName(ChatColor.DARK_PURPLE+"Charge Zombie III"); + zombie.getEquipment().setBoots(new ItemStack(Material.IRON_BOOTS)); + zombie.getEquipment().setChestplate(new ItemStack(Material.IRON_CHESTPLATE)); + zombie.getEquipment().setLeggings(new ItemStack(Material.IRON_LEGGINGS)); + zombie.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION,999999,3)); + ItemStack sword = new ItemStack(Material.IRON_SWORD); + sword.addEnchantment(Enchantment.DAMAGE_ALL, 3); + zombie.getEquipment().setItemInHand(sword); + ItemStack skull = new ItemStack(397); + skull.setDurability((short)3); + SkullMeta meta = (SkullMeta)skull.getItemMeta(); + meta.setOwner("MHF_Enderman"); + skull.setItemMeta(meta); + zombie.getEquipment().setHelmet(skull); + + enderdragon.setCustomName(ChatColor.DARK_PURPLE+"Charge Zombie III"); + enderdragon.setMaxHealth(200); + enderdragon.setHealth(200); + enderdragon.remove(); + //enderdragon.teleport(new Location(p.getWorld(),p.getLocation().getBlockX()+i,-250,p.getLocation().getBlockZ()+j)); + //p.sendMessage(ChatColor.DARK_PURPLE+"You feel a dark presence nearby."); + //Bukkit.getPlayer("sigonasr2").sendMessage("Trigger this."); + zombie.setRemoveWhenFarAway(false); + zombie.setMaxHealth(300); + zombie.setHealth(300); + zombie.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION,999999,0)); + zombie.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE,999999,0)); + zombie.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING,999999,0)); + zombie.setTicksLived(1); } /*if (nexteffect.getType().getName().compareTo(PotionEffectType.JUMP.getName())==0) { p.removePotionEffect(PotionEffectType.JUMP); @@ -7296,15 +7296,15 @@ implements Listener Bukkit.getLogger().warning("Potion Effect Collection not accessible while trying to hurt entity."); } } - if (e.getEntity().getType()==EntityType.ZOMBIE) { - Zombie z = (Zombie)e.getEntity(); - if ((z.getCustomName()==null || ( - z.getCustomName()!=null && !z.getCustomName().contains(ChatColor.DARK_PURPLE+"") && ((!z.getCustomName().contains(ChatColor.DARK_PURPLE+"") && z.getCustomName().contains("II")) || - z.getCustomName().contains("Ninja")))) && z.getHealth()>65) { - //If it's a normal zombie with too much HP, something's wrong. Lower it. - z.setHealth(z.getHealth()/2); - } - } + if (e.getEntity().getType()==EntityType.ZOMBIE) { + Zombie z = (Zombie)e.getEntity(); + if ((z.getCustomName()==null || ( + z.getCustomName()!=null && !z.getCustomName().contains(ChatColor.DARK_PURPLE+"") && ((!z.getCustomName().contains(ChatColor.DARK_PURPLE+"") && z.getCustomName().contains("II")) || + z.getCustomName().contains("Ninja")))) && z.getHealth()>65) { + //If it's a normal zombie with too much HP, something's wrong. Lower it. + z.setHealth(z.getHealth()/2); + } + } if (e.getDamager() instanceof Projectile) { Projectile pp = (Projectile)(e.getDamager()); if (pp.getShooter() instanceof Player && l instanceof Wither) { @@ -9897,48 +9897,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 map = event.getInventory().getContents()[2].getEnchantments(); - for (Map.Entry 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. @@ -10099,7 +10057,7 @@ implements Listener ItemStack extra_item = insertIntoItemCube(p, event.getCurrentItem(), event.getCursor()); if (!extra_item.equals(event.getCursor())) { //If the items don't match, it means something happened to the items, so some got inserted into the Item Cube. - //If they are the same, instead we will simply swap them. Normal functionality. + //If they are the same, instead we will simply swap them. Normal functionality. event.setCursor(extra_item); p.updateInventory(); event.setCancelled(true); @@ -10188,34 +10146,34 @@ 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. if (event.isShiftClick()) { - // Call the scheduled task to validate and update the inventory + // Call the scheduled task to validate and update the inventory Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new updateInventoryTask(event.getWhoClicked().getName())); } - } else { - // Clicked the anvil. If GUI items are clicked or an invalid operation happens, cancel the operation. + } else { + // Clicked the anvil. If GUI items are clicked or an invalid operation happens, cancel the operation. if (event.getSlot() == INPUT || event.getSlot() == MATERIALS || event.getSlot() == MAGIC || event.getSlot() == OUTPUT) { - /* + /* * OUTPUT Block */ 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 } @@ -10223,18 +10181,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 @@ -10242,7 +10200,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() @@ -10250,19 +10208,51 @@ 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 map = event.getInventory().getItem(INPUT).getEnchantments(); + for (Map.Entry entry : map.entrySet()) { + event.getInventory().getItem(INPUT).removeEnchantment(entry.getKey()); + } + if (event.getInventory().getItem(INPUT).hasItemMeta() && event.getInventory().getItem(INPUT).getItemMeta().hasLore()) { + List newlore = new ArrayList(); + for (int i=0;i map = event.getInventory().getItem(INPUT).getEnchantments(); + for (Map.Entry entry : map.entrySet()) { + event.getInventory().getItem(INPUT).removeEnchantment(entry.getKey()); + } + if (event.getInventory().getItem(INPUT).hasItemMeta() && event.getInventory().getItem(INPUT).getItemMeta().hasLore()) { + List newlore = new ArrayList(); + for (int i=0;i map = event.getInventory().getItem(INPUT).getEnchantments(); + for (Map.Entry entry : map.entrySet()) { + event.getInventory().getItem(INPUT).removeEnchantment(entry.getKey()); + } + if (event.getInventory().getItem(INPUT).hasItemMeta() && event.getInventory().getItem(INPUT).getItemMeta().hasLore()) { + List newlore = new ArrayList(); + for (int i=0;i temp_meta_lore = new ArrayList(); - temp_meta_lore.add(ChatColor.ITALIC + "Experience Cost of Enchanting."); + temp_meta_lore.add(ChatColor.ITALIC + "Experience Cost of Enchanting."); temp_meta.setLore(temp_meta_lore); orbs.setItemMeta(temp_meta); anvilInv.setItem(LEVELS, orbs); @@ -13386,13 +13447,21 @@ class updateInventoryTask implements Runnable { 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. + // 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; + boolean isHalloweenItem = false; + + List lore = anvilInv.getItem(INPUT).getItemMeta().getLore(); + for (int i=0;i 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); @@ -13514,32 +13599,32 @@ 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 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); ItemMeta temp_meta = orbs.getItemMeta(); temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost"); List temp_meta_lore = new ArrayList(); - temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels."); - temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels."); + temp_meta_lore.add(ChatColor.ITALIC + "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); @@ -13561,7 +13646,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())); } @@ -13570,356 +13655,426 @@ 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. - // Get the list of enchantments from both items. - Map itemEnchantments = anvilInv.getItem(INPUT).getEnchantments(); - Map bookEnchantments = new java.util.HashMap(); - - // 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 itemBonuses = new java.util.HashMap(); - Map bookBonuses = new java.util.HashMap(); - - 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).getType() == Material.ENCHANTED_BOOK) { + // Both Magic slots are populated, enchanted book is detected. + // Get the list of enchantments from both items. + Map itemEnchantments = anvilInv.getItem(INPUT).getEnchantments(); + Map bookEnchantments = new java.util.HashMap(); + + // 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 itemBonuses = new java.util.HashMap(); + Map bookBonuses = new java.util.HashMap(); + + 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) { + 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("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))); + // 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 probableEnchantments = new java.util.HashMap(); + // Generate appropriate possible enchantments + Map probableEnchantments = new java.util.HashMap(); - for (Enchantment e : bookEnchantments.keySet()) { - Bukkit.getLogger().info("Iterating enchantment: " + e); + 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); + 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) && 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 probableBonuses = new java.util.HashMap(); + // Generate appropriate possible bonuses + Map probableBonuses = new java.util.HashMap(); - for (String e : bookBonuses.keySet()) { - Bukkit.getLogger().info("Iterating bonus: " + e); + 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 (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)); + } } - } - 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()); + 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; + int i = 0; - Enchantment appliedEnchant = null; - int magnitude = 0; - for (Enchantment e : probableEnchantments.keySet()) { + Enchantment appliedEnchant = null; + int magnitude = 0; + for (Enchantment e : probableEnchantments.keySet()) { - if (i == random) { - // Rolled this one - appliedEnchant = e; - magnitude = probableEnchantments.get(e); + if (i == random) { + // Rolled this one + appliedEnchant = e; + magnitude = probableEnchantments.get(e); + } + i++; } - i++; - } - int cost = 0; + int cost = 0; - if (itemEnchantments.get(appliedEnchant) == null) { - // This enchantment doesn't exist. Calculate full cost. + 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 + 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); + ItemStack orbs = new ItemStack(Material.SLIME_BALL); - ItemMeta temp_meta = orbs.getItemMeta(); - temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost"); - List temp_meta_lore = new ArrayList(); - temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels."); - temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels."); + ItemMeta temp_meta = orbs.getItemMeta(); + temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost"); + List temp_meta_lore = new ArrayList(); + 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."); - } + 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); + 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); + 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. + } 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 + 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); + ItemStack orbs = new ItemStack(Material.SLIME_BALL); - ItemMeta temp_meta = orbs.getItemMeta(); - temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost"); - List temp_meta_lore = new ArrayList(); - temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels."); - temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels."); + ItemMeta temp_meta = orbs.getItemMeta(); + temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost"); + List temp_meta_lore = new ArrayList(); + 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."); - } + 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); + temp_meta.setLore(temp_meta_lore); + orbs.setItemMeta(temp_meta); - orbs.setAmount(cost); - anvilInv.setItem(LEVELS, orbs); + 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()); - 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()); - } + } + + boolean isTinkerer = true; // Change this to a playerInJob() call later. - 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()); + 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()); - int i = 0; + int i = 0; - String appliedEnchant = null; - double magnitude = 0; - for (String e : probableBonuses.keySet()) { + String appliedEnchant = null; + int magnitude = 0; + for (String e : probableBonuses.keySet()) { - if (i == random) { - // Rolled this one - appliedEnchant = e; - magnitude = probableBonuses.get(e); + if (i == random) { + // Rolled this one + appliedEnchant = e; + magnitude = probableBonuses.get(e); + } + i++; } - i++; - } - int cost = 0; + int cost = 0; - if (itemBonuses.get(appliedEnchant) == null) { - // This bonus doesn't exist. Calculate full cost. + 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); + ItemStack orbs = new ItemStack(Material.SLIME_BALL); - ItemMeta temp_meta = orbs.getItemMeta(); - temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost"); - List temp_meta_lore = new ArrayList(); - temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels."); - temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels."); + ItemMeta temp_meta = orbs.getItemMeta(); + temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost"); + List temp_meta_lore = new ArrayList(); + 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."); - } + 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); + temp_meta.setLore(temp_meta_lore); + orbs.setItemMeta(temp_meta); - orbs.setAmount(cost); - anvilInv.setItem(LEVELS, orbs); - - // Change entry matching modified lore - List bonusesLore = anvilInv.getItem(OUTPUT).getItemMeta().getLore(); + orbs.setAmount(cost); + anvilInv.setItem(LEVELS, orbs); - 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"); - } + // Change entry matching modified lore + ItemMeta bonusesMeta = anvilInv.getItem(OUTPUT).getItemMeta(); + List bonusesLore = bonusesMeta.getLore(); + if (bonusesLore == null) + { + bonusesLore = new ArrayList(); } - } - - 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); + // Bukkit.getLogger().info("Bonus enchantment string: " + appliedEnchant); + if (appliedEnchant.equalsIgnoreCase("Critical Chance")) { + bonusesLore.add(ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Critical 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"); + } - ItemMeta temp_meta = orbs.getItemMeta(); - temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost"); - List temp_meta_lore = new ArrayList(); - temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels."); - temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels."); + bonusesMeta.setLore(bonusesLore); + anvilInv.getItem(OUTPUT).setItemMeta(bonusesMeta); - 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."); - } + // This enchantment exists. Calculate incremental cost. - temp_meta.setLore(temp_meta_lore); - orbs.setItemMeta(temp_meta); + 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); - orbs.setAmount(cost); - anvilInv.setItem(LEVELS, orbs); + ItemStack orbs = new ItemStack(Material.SLIME_BALL); - // Change entry matching modified lore - List bonusesLore = anvilInv.getItem(OUTPUT).getItemMeta().getLore(); + ItemMeta temp_meta = orbs.getItemMeta(); + temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost"); + List temp_meta_lore = new ArrayList(); + temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels."); + temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels."); - 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"); + 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 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"); + } } } + + bonusesMeta.setLore(bonusesLore); + anvilInv.getItem(OUTPUT).setItemMeta(bonusesMeta); } - - anvilInv.getItem(OUTPUT).getItemMeta().setLore(bonusesLore); - } + } + + } + // TRY EVERYTHING + player.getInventory().setContents(player.getInventory().getContents()); + anvilInv.setContents(anvilInv.getContents()); + player.updateInventory(); + } else if (anvilInv.getItem(MAGIC).getType() == Material.BOOK && anvilInv.getItem(INPUT).getType() != Material.ENCHANTED_BOOK) { + // Magic slot is a book. Unenchanting logic goes here. + anvilInv.setItem(OUTPUT, new ItemStack(Material.ENCHANTED_BOOK)); + anvilInv.getItem(OUTPUT).setType(Material.ENCHANTED_BOOK); + + ItemMeta bookMeta = anvilInv.getItem(INPUT).getItemMeta(); + bookMeta.setDisplayName(null); + anvilInv.getItem(OUTPUT).setItemMeta(bookMeta); + + // If books stacked past 1, return all but 1 book to player inventory. + + if (anvilInv.getItem(MAGIC).getAmount() > 1) { + sendToInventory(MAGIC, anvilInv.getItem(MAGIC).getAmount() - 1, player); + } + + int cost = 12; + + Map 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 temp_meta_lore = new ArrayList(); + temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels."); + temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels."); + + if (cost > player.getLevel()) { + orbs.setType(Material.MAGMA_CREAM); + temp_meta_lore.add(""); + temp_meta_lore.add(ChatColor.RED + "You can't afford this!"); + } else { + temp_meta_lore.add(""); + temp_meta_lore.add(ChatColor.GREEN + "Completing the operation will"); + temp_meta_lore.add(ChatColor.GREEN + "bring you to " + (player.getLevel() - cost) + " levels."); } + temp_meta.setLore(temp_meta_lore); + orbs.setItemMeta(temp_meta); + + orbs.setAmount(cost); + anvilInv.setItem(LEVELS, orbs); + + // TRY EVERYTHING + player.getInventory().setContents(player.getInventory().getContents()); + anvilInv.setContents(anvilInv.getContents()); + player.updateInventory(); + } - // TRY EVERYTHING - player.getInventory().setContents(player.getInventory().getContents()); - anvilInv.setContents(anvilInv.getContents()); - player.updateInventory(); } } public void sendToInventory(int slot, int itemCount, Player player) { - 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(); @@ -13933,20 +14088,20 @@ class updateInventoryTask implements Runnable { ItemStack leftovers = playerInventory.addItem(temp).get(0); if (leftovers != null) { - player.getWorld().dropItemNaturally(player.getLocation(), leftovers); + player.getWorld().dropItemNaturally(player.getLocation(), leftovers); } - 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."); - anvilInventory.setItem(slot, new ItemStack(Material.AIR)); + // 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); + // 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)); @@ -13958,7 +14113,7 @@ class updateInventoryTask implements Runnable { 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)); + // Bukkit.getLogger().info("Enchant number is "+Double.valueOf(newstring)); return Double.valueOf(newstring); } else { return 0; @@ -13976,12 +14131,11 @@ class updateInventoryTask implements Runnable { } - public boolean containsEnchantment(String s, String enchant) { - if (s.contains(enchant)) { - return true; - } - return false; - } - -} + public boolean containsEnchantment(String s, String enchant) { + if (s.contains(enchant)) { + return true; + } + return false; + } +} \ No newline at end of file