Clear Block drops without cancelling event

Discussion in 'Plugin Development' started by Ar7ific1al, Jan 31, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Ar7ific1al

    After about an hour of experimentation and searching with Google, I've to resort to asking this question myself here on the Bukkit forum.

    My question deals with my thread title, obviously. I've searched around heavily, and everything I find points to cancelling the BlockBreakEvent event, setting the block to air, then using dropItemNaturally().

    Is there not a method for removing the drops from breaking a block without just cancelling the event and setting the block to air? I don't want to set the block to air, and cancel the event, for various reasons I'm sure you can guess, such as logging and interfering with other plugins. I need some method of clearing the drops so I can drop what I want, and still actually break the block. As it stands, it's ridiculous that we don't have a built-in method for modifying the contents of a block's drops upon breaking.
     
  2. Offline

    CubixCoders

    BlockBreakEvent event.getBlock().getDrops().clear();
     
  3. Offline

    Ar7ific1al

    Did you read my post? I don't think you did... Please read it again...

    If you did read my post, please understand that this method does not work! All it does is it clears the drop list; it does not actually clear the drops.
     
  4. Offline

    StickyMan

    just set a game rule like that:
     
  5. Offline

    Ar7ific1al

    *Facepalm* -_- The objective is to change what drops when a block is broken without cancelling the BlockBreakEvent. What I'm after is a means of clearing the usual drops from a block when it is harvested, and replacing it with something else.

    event.getBlock().getDrops().clear() does not clear the drops. It clears the drop list. This method is effectively useless for my purpose.
    Using /gamerule doTileDrops false disables all drops for the entire server. This is not what I'm trying to do... I know this function exists already, and if it were what I was trying to accomplish, I would not be here asking...

    Is it too much to ask that you read my post beforehand? :/
     
    skiithaw likes this.
  6. Offline

    Zarius

    No, there's currently no method (that I know of) apart from cancelling the event, replacing with air & dropItemNaturally. As the developer of OtherDrops I'd love to have another way too - I've dug into the Bukkit code a little in the past and whilst it could be done (similar to mob drops) it's not as easy as it looks.
     
  7. Offline

    Zarius

    FYI: please vote on the Bukkit issue tracker here if you're interested in a fix (ie. to be able to modify a blockbreakevent's drops without cancelling).
     
  8. Well this isn't exactly great, but you could use this:
    e.setCancelled(true);
    e.getBlock().setType(Material.AIR);
    e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(),new ItemStack(Material.ITEMNAME));
     
  9. Offline

    macguy8

    rb2750
    That completely breaks most logging plugins
     
  10. Yeah well, its better than nothing.
     
  11. Offline

    macguy8

    rb2750
    You could always make a BlockBreakEvent, call it, and then if its not cancelled run that code, so logging plugins can then pick it up
     
  12. macguy8
    That would be a problem for plugins that don't care about canceled events, they will listen to it twice.

    Ar7ific1al
    But yeah, as an alternative provide an option in your plugin's config to enable/disable sending an uncanceled event for logging plugins if admins use them and don't have any plugins that break from triggering the same block breaking twice.

    EDIT:
    Hmm, alternatively, you could also make a 1-tick delayed task and check in the blockspace (that's from X to X+1 and same for Y and Z) for dropped item entities that match possible drops from the block and remove them, then drop your own.
     
  13. Offline

    macguy8

    Digi
    True, but it's better than not having the logs at all in most cases, and most modern logging plugins will account for cancelled events
     
Thread Status:
Not open for further replies.

Share This Page