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

Cancelled EntityPickupItemEvent and PlayerPickupItemEvent alter on-ground stacks

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • None
    • All

    • git-Spigot-a596182-edd8fdf (MC: 1.14.4) (Implementing API version 1.14.4-R0.1-SNAPSHOT)
    • Yes

      If either EntityPickupItemEvent or PlayerPickupItemEvent is cancelled but the player would otherwise be able to pick up the item, the quantity of the item on the ground is incorrectly altered to be the amount that would have been picked up.

      For example, if the player has capacity to hold two stone blocks, walking over a stack of stone blocks would reduce their number to two.

      The bug seems obvious in the code:

      From EntityItem.java in pickup(EntityHuman):

      if (this.pickupDelay <= 0 && canHold > 0) {

      // RIGHT HERE
      itemstack.setCount(canHold);

      PlayerPickupItemEvent playerEvent = new PlayerPickupItemEvent((Player)entityhuman.getBukkitEntity(), (Item)getBukkitEntity(), remaining);
      playerEvent.setCancelled(!entityhuman.canPickUpLoot);
      this.world.getServer().getPluginManager().callEvent(playerEvent);
      if (playerEvent.isCancelled())

      { return; }

      EntityPickupItemEvent entityEvent = new EntityPickupItemEvent((Player)entityhuman.getBukkitEntity(), (Item)getBukkitEntity(), remaining);
      entityEvent.setCancelled(!entityhuman.canPickUpLoot);
      this.world.getServer().getPluginManager().callEvent(entityEvent);
      if (entityEvent.isCancelled()) { return; }

      itemstack.setCount(canHold + remaining);

            Unassigned Unassigned
            geekhideout Fred
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: