From a01882aea569dbacd1b4bf2fe1d3876306ae189c Mon Sep 17 00:00:00 2001 From: GJ Date: Wed, 23 Jan 2013 23:09:54 -0500 Subject: [PATCH] Because we need to care about the result, not the source. Also adds a couple of null checks, just to be safe. --- .../nossr50/listeners/InventoryListener.java | 10 +++++--- .../com/gmail/nossr50/util/ItemChecks.java | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java b/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java index 75333e970..c48cc7a2c 100644 --- a/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java @@ -12,6 +12,7 @@ import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.FurnaceInventory; +import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.skills.smelting.SmeltingManager; @@ -58,8 +59,9 @@ public class InventoryListener implements Listener{ public void onFurnaceBurnEvent(FurnaceBurnEvent event) { Block furnaceBlock = event.getBlock(); FurnaceInventory inventory = ((Furnace)furnaceBlock.getState()).getInventory(); + ItemStack smelting = inventory.getSmelting(); - if (plugin.furnaceIsTracked(furnaceBlock) && ItemChecks.isSmeltable(inventory.getSmelting())) { + if (plugin.furnaceIsTracked(furnaceBlock) && smelting != null && ItemChecks.isSmeltable(smelting)) { SmeltingManager smeltingManager = new SmeltingManager(plugin.getFurnacePlayer(furnaceBlock)); smeltingManager.fuelEfficiency(event); } @@ -69,8 +71,9 @@ public class InventoryListener implements Listener{ public void onFurnaceSmeltEvent(FurnaceSmeltEvent event) { Block furnaceBlock = event.getBlock(); FurnaceInventory inventory = ((Furnace)furnaceBlock.getState()).getInventory(); + ItemStack smelting = inventory.getSmelting(); - if (plugin.furnaceIsTracked(furnaceBlock) && ItemChecks.isSmeltable(inventory.getSmelting())) { + if (plugin.furnaceIsTracked(furnaceBlock) && smelting != null && ItemChecks.isSmeltable(smelting)) { SmeltingManager smeltingManager = new SmeltingManager(plugin.getFurnacePlayer(furnaceBlock)); smeltingManager.smeltProcessing(event); } @@ -80,8 +83,9 @@ public class InventoryListener implements Listener{ public void onFurnaceExtractEvent(FurnaceExtractEvent event) { Block furnaceBlock = event.getBlock(); FurnaceInventory inventory = ((Furnace)furnaceBlock.getState()).getInventory(); + ItemStack result = inventory.getResult(); - if (plugin.furnaceIsTracked(furnaceBlock) && inventory.getSmelting() != null && ItemChecks.isSmeltable(inventory.getSmelting())) { + if (plugin.furnaceIsTracked(furnaceBlock) && result != null && ItemChecks.isSmelted(result)) { SmeltingManager smeltingManager = new SmeltingManager(plugin.getFurnacePlayer(furnaceBlock)); smeltingManager.vanillaXPBoost(event); } diff --git a/src/main/java/com/gmail/nossr50/util/ItemChecks.java b/src/main/java/com/gmail/nossr50/util/ItemChecks.java index 63948eab0..010741c95 100644 --- a/src/main/java/com/gmail/nossr50/util/ItemChecks.java +++ b/src/main/java/com/gmail/nossr50/util/ItemChecks.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.util; +import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -490,4 +491,26 @@ public class ItemChecks { return false; } } + + public static boolean isSmelted(ItemStack itemStack) { + switch (itemStack.getType()) { + case COAL: + case DIAMOND: + case REDSTONE: + case GOLD_INGOT: + case IRON_INGOT: + case EMERALD: + return true; + + case INK_SACK: + if (itemStack.getData().getData() == DyeColor.BLUE.getDyeData()) { + return true; + } + + return false; + + default: + return false; + } + } }