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

BlockDispenseEvent triggers after dispenser inventory changed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • None
    • This server is running CraftBukkit version git-Spigot-f68f5a8-e70d864 (MC: 1.13) (Implementing API version 1.13-R0.1-SNAPSHOT)
    • Yes

      When BlockDispenseEvent triggers, it appears that the dispenser inventory has already changed, even though BlockDispenseEvent is a cancellable event.

      For example:

      protected void onBlockDispense(BlockDispenseEvent event) {
      BlockData blockData = event.getBlock().getBlockData();
      ItemStack item = event.getItem();
        if (item != null && blockData instanceof Dispenser) {
          Location location = event.getBlock().getLocation();
          InventoryHolder inventoryHolder = (InventoryHolder) location.getBlock().getState();
          for (ItemStack item : inventoryHolder.getInventory().getContents()) {
            System.out.println(item.getType().name());
          }
        }
      }
      

      With that code, the dispensed item won't be displayed in the output. There is one exception though, being that if a water bucket or lava bucket is being dispensed, it still shows as being in the dispenser. I assume this is because the item is being changed from, for example, a water bucket to a regular bucket. However, it still shows the original item (e.g. a water bucket).

      Expected behaviour is that all items should still show up as being in the dispenser for the event, not just water and lava buckets.

            Unassigned Unassigned
            Intelli Intelli
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: