Remove block drops from area?

Discussion in 'Plugin Development' started by danielh112, Apr 23, 2014.

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

    danielh112

    Hi I have been trying to remove all block drops in a certain area (after game finishes); what I have currently got is this but I cannot get it to work. I am guessing it is something to do with b.getDrops().clear(); but I am not sure what exactly (do I need to check for entities in the area instead?)

    Code:java
    1. for(int x = arena.arenaLoc1().getBlockX(); x <= arena.arenaLoc2().getBlockX(); x++) {
    2. for(int y = arena.arenaLoc1().getBlockY(); y <= arena.arenaLoc2().getBlockY(); y++) {
    3. for(int z = arena.arenaLoc1().getBlockZ(); z <= arena.arenaLoc2().getBlockZ(); z++) {
    4. Block b = Bukkit.getWorld("competition").getBlockAt(x, y, z);
    5. b.getDrops().clear();


    Any help would be greatly appreciated!
     
  2. Offline

    stink123456

    what you can do is onBlockBreakEvent you could check if the block is in that area and if so set the block to air and cancel the event.
     
  3. Offline

    danielh112

    I did consider this but Ideally they still need to be able to pick up the blocks. Thats why I was wondering if there is anyway to remove all of the dropped blocks. But thank you
     
  4. Offline

    stink123456

    if(boolean){?
     
  5. Offline

    BlazingBroGamer

    Or maybe...
    Code:
     player.getWorld().getEntities(); 
     
  6. Offline

    danielh112


    Yeh the problem is I have multiple arenas in one world so that will remove all of these entities as well
     
  7. Offline

    BlazingBroGamer

    danielh112
    Mabe you can make use of the WorldEdit API to get a selection or something... I am not too good with the WorldEdit API
     
  8. Offline

    Deleted user

    Cancel BlockBreakEvent event, then set block as air.
     
  9. Offline

    danielh112


    Thank you but if I do this how would I give the player the actual materials they would get I have tried getting the material and giving them that. But this does not work with stuff like Redstone ore (as it does not give them redstone).
     
  10. Offline

    Code0

    So you don't want the block to drop the item, but the player to receive it?
     
  11. Offline

    danielh112

    yes this seems the only way to do what I want
     
  12. Offline

    danielh112

    *bump* (sorry)
     
  13. Offline

    Deleted user

    Exceptions? Post your code.
     
  14. Offline

    danielh112


    No there is no errors the problem I have got is I cannot give the player what they should actually get

    The code I am using
    Code:java
    1. e.getBlock().setType(Material.AIR);
    2. e.setCancelled(true);
    3. e.getPlayer().getInventory().addItem(new ItemStack(e.getBlock().getType()));

    As for example if they mine a block of coal they do not get coal ore, they get the actual ore (not what they are meant to get).
     
  15. Offline

    Deleted user

    You must specify the items amount.
     
  16. Offline

    BillyGalbreath

Thread Status:
Not open for further replies.

Share This Page