ClassCastException cannot Cast as chest

问题描述 投票:0回答:1

why is is saying cannot cast the block as a chest? i created it before...

Could not pass event PlayerDeathEvent to FactionsCSN v1.0-SNAPSHOT
java.lang.ClassCastException: org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock cannot be cast to org.bukkit.block.Chest
        at creepans.factions.dims.GhostDimListener.onPlayerDeath(GhostDimListener.java:43)

Here you see, first Set Type to Chest and then the block at the same position have to be a chest

world.getBlockAt(loc).setType(Material.CHEST);
Chest crate = (Chest) world.getBlockAt(loc);
java exception casting minecraft bukkit
1个回答
1
投票

You need to cast the block state to Chest, not the block itself. Try Chest crate = (Chest) world.getBlockAt(loc).getState(); instead.

热门问题
推荐问题
最新问题