From 2b94b14c4950bfcd440ea3157820a1d67e379f44 Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Sat, 9 Aug 2014 02:30:04 +0200 Subject: [PATCH] Added a way to disable Notch apples. Closes #3. --- .../me/azenet/UHPlugin/UHPluginListener.java | 25 +++++++++++++++++++ src/main/resources/config.yml | 2 ++ 2 files changed, 27 insertions(+) diff --git a/src/main/java/me/azenet/UHPlugin/UHPluginListener.java b/src/main/java/me/azenet/UHPlugin/UHPluginListener.java index 87c9204..500acad 100644 --- a/src/main/java/me/azenet/UHPlugin/UHPluginListener.java +++ b/src/main/java/me/azenet/UHPlugin/UHPluginListener.java @@ -49,6 +49,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Recipe; import org.bukkit.inventory.ShapedRecipe; +import org.bukkit.inventory.ShapelessRecipe; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.potion.PotionEffect; @@ -330,6 +331,30 @@ public void onPreCraftEvent(PrepareItemCraftEvent ev) { return; } + // Enchanted golden apple - the same technique does not work, this is a workaround + if(p.getConfig().getBoolean("gameplay-changes.goldenApple.disableNotchApples")) { + if(ev.getInventory().getResult().getType() == Material.GOLDEN_APPLE) { + if(recipe instanceof ShapelessRecipe) { + for(ItemStack item : ((ShapelessRecipe) recipe).getIngredientList()) { + if(item.getType() == Material.GOLD_BLOCK) { + // There is a gold block in a recipe for a golden apple - NOPE + ev.getInventory().setResult(new ItemStack(Material.AIR)); + return; + } + } + } + else { // shaped recipe + for(ItemStack item : ((ShapedRecipe) recipe).getIngredientMap().values()) { + if(item.getType() == Material.GOLD_BLOCK) { + // There is a gold block in a recipe for a golden apple - NOPE NOPE NOPE + ev.getInventory().setResult(new ItemStack(Material.AIR)); + return; + } + } + } + } + } + /** Adds a lore to the golden apples crafted from a head **/ diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index aa72cbc..8163962 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -81,6 +81,8 @@ gameplay-changes: notch: 180 fromNormalHead: 4 fromNotchHead: 180 + + disableNotchApples: false disableEnderpearlsDamages: true