Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-4197

Trapped double chests don't return DoubleChestInventory

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • This server is running CraftBukkit version git-Spigot-69774b3-8592585 (MC: 1.13) (Implementing API version 1.13-R0.1-SNAPSHOT)
    • Yes

      Expectation

      The inventory of a trapped double chest should be of type DoubleChestInventory (CraftInventoryDoubleChest) as in older versions (1.12 and earlier), so that its holder is of type DoubleChest.

       

      Reality

      The inventory of a trapped double chest is of type Inventory (CraftInventory) and its holder is of type Chest.

       

      Example

      import org.bukkit.Material;
      import org.bukkit.block.Block;
      import org.bukkit.block.Chest;
      import org.bukkit.event.EventHandler;
      import org.bukkit.event.Listener;
      import org.bukkit.event.player.PlayerInteractEvent;
      import org.bukkit.inventory.DoubleChestInventory;
      import org.bukkit.inventory.Inventory;
      import org.bukkit.plugin.java.JavaPlugin;
      
      public class ExamplePlugin extends JavaPlugin implements Listener {
          @Override
          public void onEnable() {
              getServer().getPluginManager().registerEvents(this, this);
          }
      
          @EventHandler
          public void onPlayerInteract(PlayerInteractEvent e) {
              Block b = e.getClickedBlock();
              if (b.getType() == Material.CHEST || b.getType() == Material.TRAPPED_CHEST) {
                  Chest chest = (Chest) b.getState();
                  Inventory inv = chest.getInventory();
                  if (inv instanceof DoubleChestInventory) {
                      e.getPlayer().sendMessage("This is a double chest");
                  } else {
                      e.getPlayer().sendMessage("This is not a double chest: " + inv.getClass().getName());
                  }
              }
          }
      }

       

            Unassigned Unassigned
            EpicEric EpicEric
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: