[SPIGOT-1039] ClassCastException in DoubleChest.getLocation when called on a chest block connected to two other chest blocks Created: 11/Jul/15  Updated: 25/Jun/16  Resolved: 25/Jun/16

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Philip Cass Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None


 Description   

Triple chests are not a feature of minecraft but can be created by irresponsible use of mcedit or similar. If you try to call DoubleChest.getLocation on the middle chest block of a triple (whether in a straight line or corner-shaped), I get the following error:

[14:27:24 ERROR]: Could not pass event InventoryOpenEvent to LogBlock v1.94-dev-SNAPSHOT (build #258)
org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:36) ~[craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callInventoryOpenEvent(CraftEventFactory.java:698) [craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at net.minecraft.server.v1_8_R3.EntityPlayer.openContainer(EntityPlayer.java:648) [craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at net.minecraft.server.v1_8_R3.BlockChest.interact(SourceFile:339) [craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at net.minecraft.server.v1_8_R3.PlayerInteractManager.interact(PlayerInteractManager.java:495) [craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:705) [craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:52) [craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_45]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SystemUtils.java:19) [craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:676) [craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:632) [craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:540) [craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
Caused by: java.lang.ClassCastException: org.bukkit.block.DoubleChest cannot be cast to org.bukkit.block.Chest
        at org.bukkit.block.DoubleChest.getX(DoubleChest.java:40) ~[craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at org.bukkit.block.DoubleChest.getLocation(DoubleChest.java:32) ~[craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        at de.diddiz.util.BukkitUtils.getInventoryHolderType(BukkitUtils.java:207) ~[?:?]
        at de.diddiz.LogBlock.listeners.ChestAccessLogging.onInventoryOpen(ChestAccessLogging.java:61) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:300) ~[craftbukkit-1.8.7.jar:git-Bukkit-a03743b]
        ... 20 more

The corresponding plugin code is here

I understand that well-behaved code should not be creating these triple chests and am not asking for support for them; I am only concerned with innocent plugins that come along afterwards and try to call getLocation (and presumably others) on the chest

See also https://github.com/LogBlock/LogBlock/issues/558 for a further example



 Comments   
Comment by md_5 [ 25/Jun/16 ]

Resolved to match Minecraft thanks to new inventory location API \o/

Comment by md_5 [ 12/Jul/15 ]

throw new IllegalArgumentException("triple chest") and then make your own code fallback to just accessing as a single chest inventory........ It's very hard to make a "correct" fix, although I guess reimplementing Minecraft's own chest logic and disregarding "bastard" chests would work.

Comment by Philip Cass [ 11/Jul/15 ]

for what it's worth, I just recursively iterated through the left and right children of all the chests in a 12x12 grid, and the left and right sides were all eventually chests, not doubles

since a DoubleChest is purely a runtime construct (it's not saved in the map format) I wonder if the solution relies in the code that determines whether a chest is part of a double. If it's potentially paired to more than one chest, maybe it should just present itself as a single

Comment by Thinkofname [ 11/Jul/15 ]

I'm not sure how getLocation/X/Y/Z/ should handle this case. If we add a case for DoubleChest (Using getX on DoubleChest instead of Chest) we run the risk of a loop. Returning zero or the position of just one chest isn't right either. How would you expect it to work in this case?

Generated at Sat Dec 13 13:38:42 UTC 2025 using Jira 10.3.13#10030013-sha1:56dd970ae30ebfeda3a697d25be1f6388b68a422.