Testing code:
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPlayerInteractEvent(PlayerInteractEvent event) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (event.getHand() != EquipmentSlot.HAND) return; if (event.getItem() == null || event.getItem().getType() != Material.STICK) return; Block block = event.getClickedBlock(); if (block == null || block.getType() != Material.CHEST) return; Player player = event.getPlayer(); player.sendMessage("right clicked chest with stick"); event.setCancelled(true); Bukkit.getScheduler().runTaskLater(Test.INSTANCE, () -> { if (!player.isValid()) return; if (block.getType() != Material.CHEST) return; player.sendMessage("Opening chest .."); Chest chest = (Chest) block.getState(); Inventory inventory = chest.getInventory(); player.sendMessage(" " + inventory.getClass().getName()); player.sendMessage(" " + inventory.getHolder().getClass().getName()); player.openInventory(inventory); }, 20L); }
Right clicking a double chest with a stick only opens one half of the double chest and yields the following output in chat:
Opening chest .. org.bukkit.caftbukkit.v1_17_R1.inventory.CraftInventory org.bukkit.caftbukkit.v1_17_R1.block.CraftChest