diff --git a/BankEconomyMod/src/me/kaZep/Base/PlayerBuffData.java b/BankEconomyMod/src/me/kaZep/Base/PlayerBuffData.java index 1b89a26..bb9f73b 100644 --- a/BankEconomyMod/src/me/kaZep/Base/PlayerBuffData.java +++ b/BankEconomyMod/src/me/kaZep/Base/PlayerBuffData.java @@ -24,7 +24,6 @@ public class PlayerBuffData { List armorbufflist; double base_hplv; List hpbufflist; - short helmet_durability,chestplate_durability,leggings_durability,boots_durability; int potion_spdlv; long potion_time; long hpbuff_time; @@ -37,9 +36,8 @@ public class PlayerBuffData { public String toString() { //A method that outputs this class as a string. return "PlayerBuffData@{p = "+((p!=null)?p.toString():"null")+", base_spdlv = "+base_spdlv+", base_armorlv = "+base_armorlv+", armorbufflist = "+ - ((armorbufflist!=null)?armorbufflist.toString():"null")+", base_hplv = "+base_hplv+", hpbufflist = "+((hpbufflist!=null)?hpbufflist.toString():"null")+", helmet_durability = "+ - helmet_durability+", chestplate_durability = "+chestplate_durability+", leggings_durability = "+leggings_durability+"," + - " boots_durability = "+boots_durability+", potion_spdlv = "+potion_spdlv+", potion_time = "+potion_time+", hpbuff_time = "+ + ((armorbufflist!=null)?armorbufflist.toString():"null")+", base_hplv = "+base_hplv+", hpbufflist = "+((hpbufflist!=null)?hpbufflist.toString():"null")+ + ", potion_spdlv = "+potion_spdlv+", potion_time = "+potion_time+", hpbuff_time = "+ hpbuff_time+", extra_hp = "+extra_hp+", money_gained = "+money_gained+", last_money_report_time = "+last_money_report_time+"," + "plugin = "+((plugin!=null)?plugin.toString():"null")+"}"; } @@ -109,26 +107,6 @@ public class PlayerBuffData { this.hpbufflist=new ArrayList(); this.last_money_report_time=Main.SERVER_TICK_TIME; this.money_gained=0; - if (p.getInventory().getHelmet()!=null) { - this.helmet_durability=p.getInventory().getHelmet().getDurability(); - } else { - this.helmet_durability=-1; - } - if (p.getInventory().getChestplate()!=null) { - this.chestplate_durability=p.getInventory().getChestplate().getDurability(); - } else { - this.chestplate_durability=-1; - } - if (p.getInventory().getLeggings()!=null) { - this.leggings_durability=p.getInventory().getLeggings().getDurability(); - } else { - this.leggings_durability=-1; - } - if (p.getInventory().getBoots()!=null) { - this.boots_durability=p.getInventory().getBoots().getDurability(); - } else { - this.boots_durability=-1; - } this.plugin=thisplugin; try { Iterator effects = p.getActivePotionEffects().iterator(); @@ -209,30 +187,19 @@ public class PlayerBuffData { p.removePotionEffect(PotionEffectType.FAST_DIGGING); p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING,399,this.plugin.getStatBonus(1, this.plugin.getAccountsConfig().getInt(p.getName().toLowerCase()+".stats.stat2")/5)/20-1)); } - if (base_hplv!=p.getMaxHealth()) { - double temphp=0; - if (base_hplvp.getMaxHealth()) { p.setHealth(p.getMaxHealth()); - //p.sendMessage("Health: "+p.getHealth()+"/"+p.getMaxHealth()+" Set new health: "+p.getMaxHealth()+"+"+extra_hp); } - /*if (base_hplv!=p.getMaxHealth()) { + + Bukkit.getLogger().info("Base hp level: "+base_hplv+" Max Health: "+p.getMaxHealth()); + if (base_hplv!=p.getMaxHealth()) { + double temphp=0; + temphp = p.getHealth(); p.setMaxHealth(base_hplv-extra_hp); - }*/ - /* - if (p.getHealth()>base_hplv) { - p.setHealth(base_hplv); - //p.sendMessage("Health too high. Lowering to "+p.getMaxHealth()); - }*/ + p.setHealth(temphp); + } + //Send new speed totals so the player's speed can be manually adjusted. if (potion_spdlv>0 && potion_time0) { - //Bukkit.getPlayer("AaMay").sendMessage("Explorer giving speed buff: "+(base_spdlv-1+potion_spdlv)); p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 2147479999, base_spdlv-1+potion_spdlv, true)); } if (last_money_report_time+7200080*levelsmult) { //Try to spawn a counter slime. @@ -6832,7 +6833,9 @@ implements Listener @EventHandler public void onItemChange(PlayerItemHeldEvent e) { Player p = e.getPlayer(); - + if (p.getInventory().getContents()[e.getNewSlot()]!=null) { + Bukkit.getLogger().info("Durability of this item is "+p.getInventory().getContents()[e.getNewSlot()].getDurability()); + } //**************************//Job Buffs begin here. if (p.getInventory().getContents()[e.getNewSlot()]!=null) { if (p.getInventory().getContents()[e.getNewSlot()].getType().name().toLowerCase().contains("pickaxe") && this.plugin.hasJobBuff("Miner", p, Job.JOB10)) { @@ -8905,6 +8908,9 @@ implements Listener @EventHandler public void onEnemyHit(EntityDamageByEntityEvent e) { + + boolean blocked_attack=false; //Whether or not this attack was blocked. A flag used to detect durability reduction. + boolean blocked_hunter_buff=false; //Whether or not the block occurred due to the hunter buff. //**********************************//Player buffs begin if (e.getDamager() instanceof Player) { @@ -9496,330 +9502,13 @@ implements Listener break; } } - Listblocks = new ArrayList(); //Corresponds to helmet, chestplate, leggings, and boots. //Found the slot. Check armor values. double block_chance=0,speed_boost_chance=0; if (this.plugin.hasJobBuff("Hunter", p, Job.JOB30A)) { block_chance+=(double)10*this.plugin.getPlayerData(p).blockstack; - } - if (p.getEquipment().getBoots()!=null) { - ItemStack item = p.getEquipment().getBoots(); - if (this.plugin.isBroken(item)) { - //Add it either to our inventory, or drop on the ground. - if (this.plugin.inventoryFull(p)) { - //Drop it on the ground. - p.sendMessage(ChatColor.LIGHT_PURPLE+"Dropped "+item.getItemMeta().getDisplayName()+ChatColor.LIGHT_PURPLE+" on the ground since there is no room in your inventory."); - p.getWorld().dropItemNaturally(p.getLocation(), item); - } else { - p.getInventory().addItem(item); - } - - //Remove it from the slot. - p.getEquipment().setBoots(new ItemStack(Material.AIR)); - } else - if (item.getItemMeta()!=null && item.getItemMeta().getLore()!=null && item.getItemMeta().getLore().size()!=0) { - for (int i=0;i100) { - extradurability=this.plugin.getEnchantmentNumb(item.getItemMeta().getLore().get(i)); - } - } - } - - //Bukkit.getLogger().info("Made it through 2.1.6."); - } - int heal = item.getDurability()-this.plugin.SPEED_CONTROL.get(slot).boots_durability+1; - //p.sendMessage("Heal is "+heal+" ("+item.getDurability()+"-"+this.plugin.SPEED_CONTROL.get(slot).boots_durability+")"); - if (Math.random()<=0.75 && heal>0) { - heal--; - item.setDurability((short)(item.getDurability()-1)); - //p.sendMessage("Healed! "+item.getDurability()); - } - if (heal!=0) { - while (extradurability>0) { - extradurability-=200; - if (Math.random()<=0.5 && heal>0) { - heal--; - item.setDurability((short)(item.getDurability()-1)); - //p.sendMessage("Healed! "+item.getDurability()); - } - } - } - //Bukkit.getLogger().info("Armor durability now "+item.getDurability()); - //Bukkit.getLogger().info("Made it through 2.1.7."); - this.plugin.SPEED_CONTROL.get(slot).boots_durability=item.getDurability(); - //p.sendMessage("New Durability: "+item.getDurability()); - //Bukkit.getLogger().info("Made it through 2.1.8."); - } - } - } else { - this.plugin.SPEED_CONTROL.get(slot).boots_durability=-1; - //Bukkit.getLogger().info("Made it through 2.1.9."); - } - //Bukkit.getLogger().info("Made it through 2.1."); - if (p.getEquipment().getChestplate()!=null) { - ItemStack item = p.getEquipment().getChestplate(); - if (this.plugin.isBroken(item)) { - //Add it either to our inventory, or drop on the ground. - if (this.plugin.inventoryFull(p)) { - //Drop it on the ground. - p.sendMessage(ChatColor.LIGHT_PURPLE+"Dropped "+item.getItemMeta().getDisplayName()+ChatColor.LIGHT_PURPLE+" on the ground since there is no room in your inventory."); - p.getWorld().dropItemNaturally(p.getLocation(), item); - } else { - p.getInventory().addItem(item); - } - - //Remove it from the slot. - p.getEquipment().setChestplate(new ItemStack(Material.AIR)); - } else - if (item.getItemMeta()!=null && item.getItemMeta().getLore()!=null && item.getItemMeta().getLore().size()!=0) { - for (int i=0;i100) { - extradurability=this.plugin.getEnchantmentNumb(item.getItemMeta().getLore().get(i)); - } - } - } - } - boolean allow=false; - int heal = item.getDurability()-this.plugin.SPEED_CONTROL.get(slot).chestplate_durability+1; - if (Math.random()<=0.75 && heal>0) { - heal--; - item.setDurability((short)(item.getDurability()-1)); - } - if (heal!=0) { - while (extradurability>0) { - extradurability-=200; - if (Math.random()<=0.5 && heal>0) { - heal--; - item.setDurability((short)(item.getDurability()-1)); - } - } - } - this.plugin.SPEED_CONTROL.get(slot).chestplate_durability=item.getDurability(); - } - } - } else { - this.plugin.SPEED_CONTROL.get(slot).chestplate_durability=-1; - } - //Bukkit.getLogger().info("Made it through 2.2."); - if (p.getEquipment().getLeggings()!=null) { - ItemStack item = p.getEquipment().getLeggings(); - if (this.plugin.isBroken(item)) { - //Add it either to our inventory, or drop on the ground. - if (this.plugin.inventoryFull(p)) { - //Drop it on the ground. - p.sendMessage(ChatColor.LIGHT_PURPLE+"Dropped "+item.getItemMeta().getDisplayName()+ChatColor.LIGHT_PURPLE+" on the ground since there is no room in your inventory."); - p.getWorld().dropItemNaturally(p.getLocation(), item); - } else { - p.getInventory().addItem(item); - } - - //Remove it from the slot. - p.getEquipment().setLeggings(new ItemStack(Material.AIR)); - } else - if (item.getItemMeta()!=null && item.getItemMeta().getLore()!=null && item.getItemMeta().getLore().size()!=0) { - for (int i=0;i100) { - extradurability=this.plugin.getEnchantmentNumb(item.getItemMeta().getLore().get(i)); - } - } - } - } - int heal = item.getDurability()-this.plugin.SPEED_CONTROL.get(slot).leggings_durability+1; - if (Math.random()<=0.75 && heal>0) { - heal--; - item.setDurability((short)(item.getDurability()-1)); - } - if (heal!=0) { - while (extradurability>0) { - extradurability-=200; - if (Math.random()<=0.5 && heal>0) { - heal--; - item.setDurability((short)(item.getDurability()-1)); - } - } - } - this.plugin.SPEED_CONTROL.get(slot).leggings_durability=item.getDurability(); - } - } - } else { - this.plugin.SPEED_CONTROL.get(slot).leggings_durability=-1; - } - //Bukkit.getLogger().info("Made it through 2.3"); - if (p.getEquipment().getHelmet()!=null) { - ItemStack item = p.getEquipment().getHelmet(); - if (this.plugin.isBroken(item)) { - //Add it either to our inventory, or drop on the ground. - if (this.plugin.inventoryFull(p)) { - //Drop it on the ground. - p.sendMessage(ChatColor.LIGHT_PURPLE+"Dropped "+item.getItemMeta().getDisplayName()+ChatColor.LIGHT_PURPLE+" on the ground since there is no room in your inventory."); - p.getWorld().dropItemNaturally(p.getLocation(), item); - } else { - p.getInventory().addItem(item); - } - - //Remove it from the slot. - p.getEquipment().setHelmet(new ItemStack(Material.AIR)); - } else - if (item.getItemMeta()!=null && item.getItemMeta().getLore()!=null && item.getItemMeta().getLore().size()!=0) { - for (int i=0;i100) { - extradurability=this.plugin.getEnchantmentNumb(item.getItemMeta().getLore().get(i)); - } - } - } - } - int heal = item.getDurability()-this.plugin.SPEED_CONTROL.get(slot).helmet_durability+1; - if (Math.random()<=0.75 && heal>0) { - heal--; - item.setDurability((short)(item.getDurability()-1)); - } - if (heal!=0) { - while (extradurability>0) { - extradurability-=200; - if (Math.random()<=0.5 && heal>0) { - heal--; - item.setDurability((short)(item.getDurability()-1)); - } - } - } - this.plugin.SPEED_CONTROL.get(slot).helmet_durability=item.getDurability(); - } + if (Math.random()*100<=block_chance) { + blocked_hunter_buff=true; } - } else { - this.plugin.SPEED_CONTROL.get(slot).helmet_durability=-1; } //Bukkit.getLogger().info("Made it through 3."); //This is the player getting hit. @@ -9864,6 +9553,8 @@ implements Listener if (Math.random()<=block_chance/100.0d) { e.setDamage(0); //Choose a random set to mark off. + blocked_attack=true; + /* if (blocks.size()>0) { int armor = blocks.get((int)(Math.random()*blocks.size())); switch (armor) { @@ -9880,7 +9571,7 @@ implements Listener p.getInventory().getBoots().setDurability((short)(p.getInventory().getBoots().getDurability()+1)); }break; } - } + }*/ e.setCancelled(true); } //Bukkit.getLogger().info("Made it through 4."); @@ -10649,6 +10340,140 @@ implements Listener } } } + if (e.getEntity().getType()==EntityType.PLAYER) { + final Player p = (Player)e.getEntity(); + final boolean blocked = blocked_attack; + final boolean blocked_hunter = blocked_hunter_buff; + final Main plug = this.plugin; + p.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + //This player lost durability, we will attempt to give it back based on certain conditions. + //CASE 1: The player actually loses more durability if it's weak armor. + //CASE 2: The player gains back -1 durability if they have +X% Durability. The chance of it occuring is Math.random()*X<=100 + //CASE 3: The amount lost by the blocking stat has the possibility to be gained back. + int helm_dura=-1,chest_dura=-1,legs_dura=-1,boots_dura=-1; + boolean weak_helm=false,weak_chest=false,weak_legs=false,weak_boots=false; + if (p.getEquipment().getHelmet()!=null) {helm_dura=p.getEquipment().getHelmet().getDurability();} + if (p.getEquipment().getChestplate()!=null) {chest_dura=p.getEquipment().getChestplate().getDurability();} + if (p.getEquipment().getLeggings()!=null) {legs_dura=p.getEquipment().getLeggings().getDurability();} + if (p.getEquipment().getBoots()!=null) {boots_dura=p.getEquipment().getBoots().getDurability();} + Bukkit.getLogger().info("Durability of items are: "+helm_dura+","+chest_dura+","+legs_dura+","+boots_dura); + int gained_back=0; + if (!blocked_hunter && blocked) { + if (p.getEquipment().getHelmet()!=null && p.getEquipment().getHelmet().hasItemMeta() && + p.getEquipment().getHelmet().getItemMeta().hasLore()) { + List lore = p.getEquipment().getHelmet().getItemMeta().getLore(); + for (int i=0;i lore = p.getEquipment().getChestplate().getItemMeta().getLore(); + for (int i=0;i lore = p.getEquipment().getLeggings().getItemMeta().getLore(); + for (int i=0;i lore = p.getEquipment().getBoots().getItemMeta().getLore(); + for (int i=0;i lore = p.getEquipment().getHelmet().getItemMeta().getLore(); + for (int i=0;i100) { + helm_dura-=1; + } + } + } + } + if (p.getEquipment().getChestplate()!=null && p.getEquipment().getChestplate().hasItemMeta() && + p.getEquipment().getChestplate().getItemMeta().hasLore()) { + List lore = p.getEquipment().getChestplate().getItemMeta().getLore(); + for (int i=0;i100) { + chest_dura-=1; + } + } + } + } + if (p.getEquipment().getLeggings()!=null && p.getEquipment().getLeggings().hasItemMeta() && + p.getEquipment().getLeggings().getItemMeta().hasLore()) { + List lore = p.getEquipment().getLeggings().getItemMeta().getLore(); + for (int i=0;i100) { + legs_dura-=1; + } + } + } + } + if (p.getEquipment().getBoots()!=null && p.getEquipment().getBoots().hasItemMeta() && + p.getEquipment().getBoots().getItemMeta().hasLore()) { + List lore = p.getEquipment().getBoots().getItemMeta().getLore(); + for (int i=0;i100) { + boots_dura-=1; + } + } + } + } + if (p.getEquipment().getBoots()!=null) {ItemStack i = p.getEquipment().getBoots(); i.setDurability((short)boots_dura); p.getEquipment().setBoots(i);} + if (p.getEquipment().getLeggings()!=null) {ItemStack i = p.getEquipment().getLeggings(); i.setDurability((short)legs_dura); p.getEquipment().setLeggings(i);} + if (p.getEquipment().getChestplate()!=null) {ItemStack i = p.getEquipment().getChestplate(); i.setDurability((short)chest_dura); p.getEquipment().setChestplate(i);} + if (p.getEquipment().getHelmet()!=null) {ItemStack i = p.getEquipment().getHelmet(); i.setDurability((short)helm_dura); p.getEquipment().setHelmet(i);} + Bukkit.getLogger().info("Durability of items now are: "+helm_dura+","+chest_dura+","+legs_dura+","+boots_dura); + } + },1); + } } @EventHandler @@ -17028,107 +16853,9 @@ implements Listener }break; } if (name.equalsIgnoreCase("Dye")) { - switch (data) { - case 0:{ - color = "Black"; - }break; - case 1:{ - color = "Red"; - }break; - case 2:{ - color = "Green"; - }break; - case 3:{ - color = "Brown"; - }break; - case 4:{ - color = "Blue"; - }break; - case 5:{ - color = "Purple"; - }break; - case 6:{ - color = "Cyan"; - }break; - case 7:{ - color = "Light Gray"; - }break; - case 8:{ - color = "Gray"; - }break; - case 9:{ - color = "Pink"; - }break; - case 10:{ - color = "Lime"; - }break; - case 11:{ - color = "Yellow"; - }break; - case 12:{ - color = "Light Blue"; - }break; - case 13:{ - color = "Magenta"; - }break; - case 14:{ - color = "Orange"; - }break; - case 15:{ - color = "White"; - }break; - } + color = DyeColor.getByDyeData((byte)data).name(); } else { - switch (data) { - case 0:{ - color = "White"; - }break; - case 1:{ - color = "Orange"; - }break; - case 2:{ - color = "Magenta"; - }break; - case 3:{ - color = "Light Blue"; - }break; - case 4:{ - color = "Yellow"; - }break; - case 5:{ - color = "Lime"; - }break; - case 6:{ - color = "Pink"; - }break; - case 7:{ - color = "Gray"; - }break; - case 8:{ - color = "Light Gray"; - }break; - case 9:{ - color = "Cyan"; - }break; - case 10:{ - color = "Purple"; - }break; - case 11:{ - color = "Blue"; - }break; - case 12:{ - color = "Brown"; - }break; - case 13:{ - color = "Green"; - }break; - case 14:{ - color = "Red"; - }break; - case 15:{ - color = "Black"; - }break; - } + color = DyeColor.getByWoolData((byte)data).name(); } return String.valueOf(color+" "+name); } diff --git a/BankEconomyMod/src/me/kaZep/Commands/commandBankEconomy.java b/BankEconomyMod/src/me/kaZep/Commands/commandBankEconomy.java index 3c5c13d..de1aa5b 100644 --- a/BankEconomyMod/src/me/kaZep/Commands/commandBankEconomy.java +++ b/BankEconomyMod/src/me/kaZep/Commands/commandBankEconomy.java @@ -10,11 +10,11 @@ import java.util.List; import java.util.Map; import me.kaZep.Base.Main; +import me.kaZep.Commands.JobsDataInfo.Job; import net.jmhertlein.mctowns.MCTowns; import net.jmhertlein.mctowns.MCTownsPlugin; import net.jmhertlein.mctowns.database.TownManager; import net.jmhertlein.mctowns.structure.Town; -import me.kaZep.Commands.JobsDataInfo.Job; import net.milkbowl.vault.economy.Economy; import org.bukkit.Bukkit;