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

Player.openWorkbench calls open and close inventory events before opening properly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: Minor Minor
    • None
    • None
    • API version 1.18.2-R0.1-SNAPSHOT
    • Yes

      When opening a custom workbench using player.openWorkbench(location, true), InventoryOpenEvent and InventoryCloseEvent are both called before again calling InventoryOpenEvent. For example, the sequence of events include:

      openWorkbench -> InventoryOpenEvent -> InventoryCloseEvent -> InventoryOpenEvent

       

      After the final InventoryOpenEvent is called, the workbench can be used normally, and hitting escape to close the inventory will call InventoryCloseEvent as it should. All other inventories that can normally be opened in the vanilla game seem to call these events properly.

       

      The following code includes the event handlers that demonstrate this bug:

      @EventHandler
      public void onInventoryClose(InventoryCloseEvent e) {
          InventoryType type = e.getInventory().getType();
          System.out.println(String.format("Close Inventory: %s", type));
      }
      
      @EventHandler
      public void onInventoryOpen(InventoryOpenEvent e) {
          InventoryType type = e.getInventory().getType();
          System.out.println(String.format("Open Inventory: %s", type));
      }
      
      @EventHandler
      public void onInteract(PlayerInteractEvent e) {
          if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
              Player p = e.getPlayer();
              Block block = e.getClickedBlock();
              if (block.getType() == Material.PETRIFIED_OAK_SLAB) {
                  e.setCancelled(true);
                  p.openWorkbench(block.getLocation(), true);
              }
          }
      }

      Material.PETRIFIED_OAK_SLAB was entire arbitrary and could have been any block material.

      The only other code that is within this plugin is the enable function with the instantiation of the listener.

      The only other plugin involved is PlugManX, which is used to live reload the test plugin.

       

      The attached image shows the outputs in the console after one right click, which should only call InventoryOpenEvent once, but instead calls InventoryOpenEvent, then InventoryCloseEvent, then InventoryOpenEvent again.

            Unassigned Unassigned
            BlockMan731 Theodore
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: