1.8.8 Stopping a BlockBreakEvent from dropping items

Discussion in 'Spigot Plugin Development' started by OnheKnock, Mar 25, 2020 at 6:49 PM.

  1. Hey,
    i want to stop a bed from dropping an Item. I already tried to cancel the event and set the block to air, but if you just break the top half of the bed it drops the bed again.

  2. Im pretty sure you have a method e.setDropItems(false)
  3. In my research i often found that solution, but idk wich version you are using, but in mine it doesn't exist..
    I'm using this Event: org.bukkit.event.block.BlockBreakEvent
  4. If I am not mistaken, BlockBreakEvent#setDropItems() was introduced after 1.8.8.

    You could try using the ItemSpawnEvent,I haven't checked but I think that still exists in 1.8.8.

    EDIT: Yes, It still exists.
  5. This was indeed not part of the API in 1.8.8. But then again, using a nearly 5 years old version of Spigot, comes with disadvantages.

    An alternative solution, as also noted in the Spigot 1.8.8 BlockBreakEvent documentation could be to set the block to Material.AIR.

    Or as mentioned by @Struck713 to listen to the ItemSpawnEvent - this just leaves you with little clue where the Item came from, except for checking it manually, but even that gives you only a hint since the block it came from is already broken.
    • Agree Agree x 1
  6. I tried this, but does not work. Maybe i'm just bad, I'm awake since more than 24 hours...

    Of cause, but PvP in 1.9+ is just bad, so a PvP-Plugin for 1.9+ makes just barely sense.

    As i mentioned, i already tried this, but if i break the upper half of the bed, it drops the Item again.
  7. Then set both bed blocks to Material.AIR? ^^

    Code (Java):
    Bed bed = (Bed) block.getState();
    // bed.getPart() == Part.FOOT / Part.HEAD to figure out which part of the bed it is
    // bed.getFacing() to get the BlockFace the bed block is facing
  8. Thank you very much!