Daniel Juric
Daniel Juric

Reputation: 148

Spigot | ClassCastException cannot Cast as chest

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);

Upvotes: 2

Views: 1034

Answers (1)

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

Upvotes: 3

Related Questions