Check if the furnace is actually a furnace - fixes ClassCastExceptions

caused by "virtual furnace" plugins.
This commit is contained in:
GJ 2013-01-29 08:08:40 -05:00
parent 5bf1e49e43
commit 659e982c47

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.listeners;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Furnace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -69,7 +70,10 @@ public class InventoryListener implements Listener{
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onFurnaceBurnEvent(FurnaceBurnEvent event) {
Block furnaceBlock = event.getBlock();
FurnaceInventory inventory = ((Furnace)furnaceBlock.getState()).getInventory();
BlockState blockState = furnaceBlock.getState();
if (blockState instanceof Furnace) {
FurnaceInventory inventory = ((Furnace) blockState).getInventory();
ItemStack smelting = inventory.getSmelting();
if (plugin.furnaceIsTracked(furnaceBlock) && smelting != null && ItemChecks.isSmeltable(smelting)) {
@ -81,11 +85,15 @@ public class InventoryListener implements Listener{
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onFurnaceSmeltEvent(FurnaceSmeltEvent event) {
Block furnaceBlock = event.getBlock();
FurnaceInventory inventory = ((Furnace)furnaceBlock.getState()).getInventory();
BlockState blockState = furnaceBlock.getState();
if (blockState instanceof Furnace) {
FurnaceInventory inventory = ((Furnace) blockState).getInventory();
ItemStack smelting = inventory.getSmelting();
if (plugin.furnaceIsTracked(furnaceBlock) && smelting != null && ItemChecks.isSmeltable(smelting)) {
@ -97,11 +105,15 @@ public class InventoryListener implements Listener{
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onFurnaceExtractEvent(FurnaceExtractEvent event) {
Block furnaceBlock = event.getBlock();
FurnaceInventory inventory = ((Furnace)furnaceBlock.getState()).getInventory();
BlockState blockState = furnaceBlock.getState();
if (blockState instanceof Furnace) {
FurnaceInventory inventory = ((Furnace) blockState).getInventory();
ItemStack result = inventory.getResult();
if (plugin.furnaceIsTracked(furnaceBlock) && result != null && ItemChecks.isSmelted(result)) {
@ -110,3 +122,4 @@ public class InventoryListener implements Listener{
}
}
}
}