From 5fe020b68af4031283f3fcca00c085d53e7495d7 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sat, 30 Nov 2013 23:12:39 -0700 Subject: [PATCH] Cook job complete. --- BankEconomyMod/src/me/kaZep/Base/Main.java | 6 +- .../src/me/kaZep/Base/PlayerData.java | 1 + .../src/me/kaZep/Base/PlayerListener.java | 388 +++++++++++++++--- 3 files changed, 340 insertions(+), 55 deletions(-) diff --git a/BankEconomyMod/src/me/kaZep/Base/Main.java b/BankEconomyMod/src/me/kaZep/Base/Main.java index a60464d..b305653 100644 --- a/BankEconomyMod/src/me/kaZep/Base/Main.java +++ b/BankEconomyMod/src/me/kaZep/Base/Main.java @@ -1096,11 +1096,11 @@ public class Main extends JavaPlugin Cook_job.addData("GRILLED PORK", 0.12, 48, 1); Cook_job.addData("COOKED BEEF", 0.20, 80, 1); Cook_job.setBuffData("Double the amount of cooking time with one fuel item in the furnace.", - "Results of crafting food is double the normal amount.", - "Results of cooking food is double the normal amount.", + "Food that is cooked/crafted gives double the amount of hunger restoration and heals 1 Heart of Health (2HP) when eaten.", + "Food that is cooked/crafted gain magical buffs that apply when someone eats them. These last for 60 seconds.", "Increases buff strength of all food items by 1.", "Increases bonus effect duration of all food items by x4.", - "Cooking and crafting food gives 4x the normal amount. Cooking and crafting food gives exp orbs and has a chance of giving Golden Apples and Golden Carrots sometimes. (15% per crafted/cooked item.)"); + "Food that is cooked/crafted gain a 'Saturation' magical buff that lasts for 2 minutes and heals 3 hearts (6HP) for the player that eats it. All food magical buffs' durations will be increased an additional 3 minutes long and the strength of those buffs increase by 1. Food results that are cooked/crafted will be doubled."); Brewer_job.setJobName("Brewer"); Brewer_job.setJobDescription("A brewer's job is to create potions for others and themselves in order to change the outcome of situations."); diff --git a/BankEconomyMod/src/me/kaZep/Base/PlayerData.java b/BankEconomyMod/src/me/kaZep/Base/PlayerData.java index 86d8531..f25c3b3 100644 --- a/BankEconomyMod/src/me/kaZep/Base/PlayerData.java +++ b/BankEconomyMod/src/me/kaZep/Base/PlayerData.java @@ -13,6 +13,7 @@ public class PlayerData { long lastsneaktime=0; int minestreak=0; boolean haslanded=true; + long lasteattime=Main.SERVER_TICK_TIME; int blockstack=0; //The amount of times you've gotten hit (The amount of "blocking" stacks you now have) int fishingstreak=0; int fishingrodfails=0; //The amount of times in a row you've failed to catch fish. diff --git a/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java b/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java index 0c02fe4..475f29e 100644 --- a/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java +++ b/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java @@ -929,10 +929,33 @@ implements Listener ItemMeta meta = e.getResult().getItemMeta(); meta.setLore(lore); ItemStack newstack = e.getResult(); + newstack.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 1); newstack.setItemMeta(meta); e.setResult(newstack); } } + if (hasJobBuff("Cook", owner, Job.JOB40)) { + if (hasJobBuff("Cook", owner, Job.JOB30A)) { + e.setResult(modifyFoodItem(e.getResult(),1,0,true)); + } else + if (hasJobBuff("Cook", owner, Job.JOB30B)) { + e.setResult(modifyFoodItem(e.getResult(),0,3,true)); + } + ItemStack oldamt = e.getResult(); + oldamt.setAmount(oldamt.getAmount()+1); + e.setResult(oldamt); + } + else + if (hasJobBuff("Cook", owner, Job.JOB30A) || hasJobBuff("Cook", owner, Job.JOB30B)) { + if (hasJobBuff("Cook", owner, Job.JOB30A)) { + e.setResult(modifyFoodItem(e.getResult(),1)); + } else { + e.setResult(modifyFoodItem(e.getResult(),0,3)); + } + } else + if (hasJobBuff("Cook", owner, Job.JOB20)) { + e.setResult(modifyFoodItem(e.getResult())); + } //*************************//Not Job Buffies below. if (this.plugin.PlayerinJob(owner, "Digger")) { @@ -4360,7 +4383,7 @@ implements Listener } @EventHandler - public void onPotionConsume(PlayerItemConsumeEvent e) { + public void onItemConsume(PlayerItemConsumeEvent e) { final Player p = e.getPlayer(); Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable() { @Override @@ -4368,6 +4391,107 @@ implements Listener p.getScoreboard().getTeam(p.getName().toLowerCase()).setSuffix(healthbar(p.getHealth(),p.getMaxHealth(),p.getFoodLevel())); } },5); + if (isFood(e.getItem()) && e.getItem().hasItemMeta() && e.getItem().getItemMeta().hasLore()) { + //We need to parse the lore for any additional effects to give. + List itemlore = e.getItem().getItemMeta().getLore(); + if (itemlore.contains("This food item was fabulously")) { + int hungerincrease=0; + float saturationincrease=0; + switch (e.getItem().getType()) { + case POTATO:{hungerincrease=1;}break; + case COOKIE: + case MELON: + case POISONOUS_POTATO: + case RAW_CHICKEN: + case SPIDER_EYE: + case RAW_FISH:{hungerincrease=2;}break; + case PORK: + case RAW_BEEF:{hungerincrease=3;}break; + case ROTTEN_FLESH: + case CARROT_ITEM: + case GOLDEN_APPLE: + case APPLE:{hungerincrease=4;}break; + case BREAD: + case COOKED_FISH:{hungerincrease=5;}break; + case MUSHROOM_SOUP: + case BAKED_POTATO: + case COOKED_CHICKEN: + case GOLDEN_CARROT:{hungerincrease=6;}break; + case PUMPKIN_PIE: + case COOKED_BEEF: + case GRILLED_PORK:{hungerincrease=8;}break; + } + switch (e.getItem().getType()) { + case COOKIE: + case RAW_FISH:{saturationincrease=0.4f;}break; + case POTATO:{saturationincrease=0.6f;}break; + case ROTTEN_FLESH:{saturationincrease=0.8f;}break; + case MELON: + case RAW_CHICKEN: + case POISONOUS_POTATO:{saturationincrease=1.2f;}break; + case PORK: + case RAW_BEEF:{saturationincrease=1.8f;}break; + case APPLE:{saturationincrease=2.4f;}break; + case SPIDER_EYE:{saturationincrease=3.2f;}break; + case CARROT:{saturationincrease=4.8f;}break; + case PUMPKIN_PIE: + case BREAD:{saturationincrease=6f;}break; + case BAKED_POTATO: + case COOKED_CHICKEN: + case MUSHROOM_SOUP:{saturationincrease=7.2f;}break; + case GOLDEN_APPLE:{saturationincrease=9.6f;}break; + case COOKED_BEEF: + case GRILLED_PORK:{saturationincrease=12.8f;}break; + case GOLDEN_CARROT:{saturationincrease=14.4f;}break; + } + p.setFoodLevel(p.getFoodLevel()+hungerincrease); + p.setSaturation(p.getSaturation()+saturationincrease); + if (p.getSaturation()>30f) { + p.setSaturation(30f); + } + if (p.getHealth()+2 lore = null,altlore = null; + if (i.hasItemMeta() && i.getItemMeta().hasLore()) { + lore = i.getItemMeta().getLore(); + altlore = i.getItemMeta().getLore(); + } else { + lore = new ArrayList(); + lore = new ArrayList(); + } + lore.add(""); + lore.add(ChatColor.AQUA+"Additional Effects:"); + if (ult) { + lore.add(" "+ChatColor.BLUE+"Heals 6 HP "+Character.toString((char)0x2665)+Character.toString((char)0x2665)+Character.toString((char)0x2665)); + lore.add(" "+ChatColor.GRAY+"Saturation (2:00)"); + if (duration_level==4) {duration_level=16;} else {duration_level=4;} + power_level++; + altlore.add(""); + altlore.add(ChatColor.AQUA+"Additional Effects:"); + altlore.add(" "+ChatColor.BLUE+"Heals 6 HP "+Character.toString((char)0x2665)+Character.toString((char)0x2665)+Character.toString((char)0x2665)); + altlore.add(" "+ChatColor.GRAY+"Saturation (2:00)"); + } + String duration = ""; + boolean no_effect=false; + switch (duration_level) { + case 1:{ + duration = "1:00"; + }break; + case 4:{ + duration = "4:00"; + }break; + case 16:{ + duration = "16:00"; + }break; + } + switch (i.getType()) { + case GOLDEN_CARROT:{lore.add(" "+ChatColor.GRAY+"Night Vision ("+duration+")");}break; + case GOLDEN_APPLE:{lore.add(" "+ChatColor.GRAY+"Regeneration "+this.plugin.toRomanNumeral(power_level)+" ("+duration+")");}break; + case COOKED_BEEF: + case GRILLED_PORK:{lore.add(" "+ChatColor.GRAY+"Strength "+this.plugin.toRomanNumeral(power_level)+" ("+duration+")");}break; + case COOKED_FISH:{lore.add(" "+ChatColor.GRAY+"Water Breathing ("+duration+")");}break; + case BREAD:{lore.add(" "+ChatColor.GRAY+"Fire Resistance ("+duration+")");}break; + case MUSHROOM_SOUP:{lore.add(" "+ChatColor.GRAY+"Haste "+this.plugin.toRomanNumeral(power_level)+" ("+duration+")");}break; + case COOKED_CHICKEN:{lore.add(" "+ChatColor.GRAY+"Jump Boost "+this.plugin.toRomanNumeral(power_level)+" ("+duration+")");}break; + case BAKED_POTATO:{lore.add(" "+ChatColor.GRAY+"Speed "+this.plugin.toRomanNumeral(power_level)+" ("+duration+")");}break; + default: {no_effect=true;} + } + if (no_effect) { + ItemMeta meta = i.getItemMeta(); + meta.setLore(altlore); + i.setItemMeta(meta); + return i; + } else { + ItemMeta meta = i.getItemMeta(); + meta.setLore(lore); + i.setItemMeta(meta); + return i; + } + } @EventHandler public void onItemPrepareCraft(PrepareItemCraftEvent e) { CraftingInventory result = e.getInventory(); //****************************// Job Boofs poof here. - - if (result.getResult().getType()==Material.WOOD){ - boolean allow_wood=false; - Player p = null; - for (int i=0;i lore = new ArrayList(); + if (resulting.getItemMeta().hasLore()) { + lore = resulting.getItemMeta().getLore(); + } else { + lore.add("This food item was fabulously"); + lore.add("created by cook "+ChatColor.YELLOW+p.getName()+","); + lore.add("restoring more hunger and"); + lore.add("saturation than normal, and"); + lore.add("healing 1 Heart of health."); + } + ItemMeta meta = resulting.getItemMeta(); + meta.setLore(lore); + resulting.setItemMeta(meta); + result.setResult(resulting); + } + if (hasJobBuff("Cook", p, Job.JOB40)) { + if (hasJobBuff("Cook", p, Job.JOB30A)) { + result.setResult(modifyFoodItem(result.getResult(),1,0,true)); + } else + if (hasJobBuff("Cook", p, Job.JOB30B)) { + result.setResult(modifyFoodItem(result.getResult(),0,3,true)); + } + ItemStack final_result = result.getResult(); + final_result.setAmount(final_result.getAmount()*2); + result.setResult(final_result); + } else + if (hasJobBuff("Cook", p, Job.JOB30A) || hasJobBuff("Cook", p, Job.JOB30B)) { + if (hasJobBuff("Cook", p, Job.JOB30A)) { + result.setResult(modifyFoodItem(result.getResult(),1)); + } else { + result.setResult(modifyFoodItem(result.getResult(),0,3)); + } + } else + if (hasJobBuff("Cook", p, Job.JOB20)) { + result.setResult(modifyFoodItem(result.getResult())); + } + } + //****************************//Job Non-Boofs go below. @@ -5517,9 +5775,11 @@ implements Listener } } + /* + ItemStack resulting = new ItemStack(result.getResult().getType(),result.getResult().getAmount()); if (hasJobBuff("Cook", p, Job.JOB10)) { if (e.getClick()!=ClickType.SHIFT_RIGHT && e.getClick()!=ClickType.SHIFT_LEFT) { - ItemStack resulting = result.getResult(); + resulting.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 1); List lore = new ArrayList(); if (resulting.getItemMeta().hasLore()) { lore = resulting.getItemMeta().getLore(); @@ -5536,6 +5796,9 @@ implements Listener result.setResult(resulting); } } + if (hasJobBuff("Cook", p, Job.JOB20)) { + result.setResult(modifyFoodItem(result.getResult())); + }*/ ItemStack item = result.getResult(); int amount=1; @@ -5581,6 +5844,13 @@ implements Listener crafteditem=true; } } + if (this.plugin.hasJobBuff("Cook", p, Job.JOB40)) { + if (e.getClick()!=ClickType.SHIFT_LEFT && e.getClick()!=ClickType.SHIFT_RIGHT) { + ItemStack replenishitem = item.clone(); + replenishitem.setAmount(1); + p.getInventory().addItem(replenishitem); + } + } /* if (this.plugin.getJobLv("Cook", p)>=10 && crafteditem==true) { //This is an ugly fix for the problem...But it works somehow. @@ -11549,7 +11819,7 @@ implements Listener player.getInventory().setItem(i, resulting); } } - if (PlayerinJob((Player)player,"Blacksmith")) { + if (PlayerinJob((Player)player,"Blacksmith") || hasJobBuff("Blacksmith", (Player)player, Job.JOB40)) { ItemStack resulting = clone; if (hasJobBuff("Blacksmith", player.getName(), Job.JOB30A) && validItem_Blacksmith(post)) { ItemMeta meta = resulting.getItemMeta(); @@ -11561,11 +11831,11 @@ implements Listener meta.setLore(lore); resulting.setItemMeta(meta); } - if (getJobLv("Blacksmith", player.getName())>=10 && validItem_Blacksmith(post)) { + if (hasJobBuff("Blacksmith", player.getName(), Job.JOB10) && validItem_Blacksmith(post)) { //Bukkit.getPlayer("sigonasr2").sendMessage("Valid item. Going to attempt to enchant."); resulting = EnchantItem(clone,10,(Player)player); } else - if (getJobLv("Blacksmith", player.getName())>=5 && validItem_Blacksmith(post)) { + if (hasJobBuff("Blacksmith", player.getName(), Job.JOB5) && validItem_Blacksmith(post)) { //Bukkit.getPlayer("sigonasr2").sendMessage("Valid item. Going to attempt to enchant."); resulting = EnchantItem(clone,5,(Player)player); } @@ -11579,23 +11849,6 @@ implements Listener } player.getInventory().setItem(i, resulting); } - if (hasJobBuff("Cook", (Player)player, Job.JOB10)) { - ItemStack resulting = clone; - List lore = new ArrayList(); - if (resulting.getItemMeta().hasLore()) { - lore = resulting.getItemMeta().getLore(); - } else { - lore.add("This food item was fabulously"); - lore.add("created by cook "+ChatColor.YELLOW+player.getName()+","); - lore.add("restoring more hunger and"); - lore.add("saturation than normal, and"); - lore.add("healing 1 Heart of health."); - } - ItemMeta meta = resulting.getItemMeta(); - meta.setLore(lore); - resulting.setItemMeta(meta); - player.getInventory().setItem(i, resulting); - } } //Bukkit.getPlayer("sigonasr2").sendMessage("Item amounts differ. New count: "+newItemsCount); } @@ -13852,7 +14105,33 @@ implements Listener } public boolean isFood(ItemStack i) { - + if (i.getType()==Material.RAW_FISH || + i.getType()==Material.ROTTEN_FLESH || + i.getType()==Material.COOKIE || + i.getType()==Material.CAKE || + i.getType()==Material.POTATO || + i.getType()==Material.MELON || + i.getType()==Material.POISONOUS_POTATO || + i.getType()==Material.RAW_CHICKEN || + i.getType()==Material.RAW_BEEF || + i.getType()==Material.PORK || + i.getType()==Material.APPLE || + i.getType()==Material.PUMPKIN_PIE || + i.getType()==Material.CARROT_ITEM || + i.getType()==Material.COOKED_FISH || + i.getType()==Material.BREAD || + i.getType()==Material.MUSHROOM_SOUP || + i.getType()==Material.COOKED_CHICKEN || + i.getType()==Material.BAKED_POTATO || + i.getType()==Material.SPIDER_EYE || + i.getType()==Material.COOKED_BEEF || + i.getType()==Material.GRILLED_PORK || + i.getType()==Material.GOLDEN_APPLE || + i.getType()==Material.GOLDEN_CARROT) { + return true; + } else { + return false; + } } @EventHandler @@ -14263,9 +14542,14 @@ implements Listener } if ((e.getAction()==Action.RIGHT_CLICK_AIR || (e.getAction()==Action.RIGHT_CLICK_BLOCK && p.isSneaking())) && p.getItemInHand().hasItemMeta() && p.getItemInHand().getItemMeta().hasLore()) { - /*if (isFood(p.getItemInHand().getType())) { - - }*/ + if (isFood(p.getItemInHand()) && p.getItemInHand().hasItemMeta() && p.getItemInHand().getItemMeta().hasLore()) { + //This is a special food. Even if we are full, take action. + if (p.getFoodLevel()>=20 && Main.SERVER_TICK_TIME-this.plugin.getPlayerData(p).lasteattime>100) { + p.setFoodLevel(19); + p.playSound(p.getLocation(), Sound.EAT, 1.0f, 1.0f); + this.plugin.getPlayerData(p).lasteattime=Main.SERVER_TICK_TIME; + } + } } //******************************//End Job related buffs.