How to automatically send mined blocks to inventory?

Discussion in 'Spigot Plugin Development' started by DarkSoldier, Jun 20, 2015.

  1. I would like to implement this feature into my plugin, but am completely clueless as to how I can go along doing so. I decompiled some plugins that already did this, but was unable to understand how they were achieving the desired result.

    Could someone please take me through, in step-by-step process, and explain to me how to code something like this?
     
  2. maldahleh

    Wiki Team

    The easiest way is to probably listen to BlockBreakEvent, cancel the event, add the mined block type to the player inventory using e.getBlock() to determine what kind of block it was, and then set the mined block to air.

    There are probably other ways and maybe better ways of doing this, but this was the first that came to mind.
     
    • Agree Agree x 1
  3. block break event and get the block + cleardrops then change all items to be dropped