mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-04-04 18:56:23 +02:00
Check if the furnace is actually a furnace - fixes ClassCastExceptions
caused by "virtual furnace" plugins.
This commit is contained in:
parent
5bf1e49e43
commit
659e982c47
@ -1,6 +1,7 @@
|
|||||||
package com.gmail.nossr50.listeners;
|
package com.gmail.nossr50.listeners;
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.Furnace;
|
import org.bukkit.block.Furnace;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -69,7 +70,10 @@ public class InventoryListener implements Listener{
|
|||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onFurnaceBurnEvent(FurnaceBurnEvent event) {
|
public void onFurnaceBurnEvent(FurnaceBurnEvent event) {
|
||||||
Block furnaceBlock = event.getBlock();
|
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();
|
ItemStack smelting = inventory.getSmelting();
|
||||||
|
|
||||||
if (plugin.furnaceIsTracked(furnaceBlock) && smelting != null && ItemChecks.isSmeltable(smelting)) {
|
if (plugin.furnaceIsTracked(furnaceBlock) && smelting != null && ItemChecks.isSmeltable(smelting)) {
|
||||||
@ -81,11 +85,15 @@ public class InventoryListener implements Listener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onFurnaceSmeltEvent(FurnaceSmeltEvent event) {
|
public void onFurnaceSmeltEvent(FurnaceSmeltEvent event) {
|
||||||
Block furnaceBlock = event.getBlock();
|
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();
|
ItemStack smelting = inventory.getSmelting();
|
||||||
|
|
||||||
if (plugin.furnaceIsTracked(furnaceBlock) && smelting != null && ItemChecks.isSmeltable(smelting)) {
|
if (plugin.furnaceIsTracked(furnaceBlock) && smelting != null && ItemChecks.isSmeltable(smelting)) {
|
||||||
@ -97,11 +105,15 @@ public class InventoryListener implements Listener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onFurnaceExtractEvent(FurnaceExtractEvent event) {
|
public void onFurnaceExtractEvent(FurnaceExtractEvent event) {
|
||||||
Block furnaceBlock = event.getBlock();
|
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();
|
ItemStack result = inventory.getResult();
|
||||||
|
|
||||||
if (plugin.furnaceIsTracked(furnaceBlock) && result != null && ItemChecks.isSmelted(result)) {
|
if (plugin.furnaceIsTracked(furnaceBlock) && result != null && ItemChecks.isSmelted(result)) {
|
||||||
@ -110,3 +122,4 @@ public class InventoryListener implements Listener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user