OnPlayerBreak event give player the item

Discussion in 'Plugin Development' started by Cherwin1, Nov 5, 2014.

Thread Status:
Not open for further replies.
  1. Hello,

    I am making a new plugin.

    Idea: When mining it will add the block into your inventory and no drops on the ground.
    So i coded this so far:
    Code:java
    1. @EventHandler(priority = EventPriority.HIGH)
    2. public void onBlockBreak(BlockBreakEvent e) {
    3. Player p = e.getPlayer();
    4.  
    5. p.getInventory().addItem(new ItemStack(e.getBlock().getType()., e.getBlock().getDrops().size()));
    6. e.setCancelled(true);
    7. e.getBlock().setType(Material.AIR);
    8.  
    9.  
    10. }


    But i dont know how to make it so if you mine a Diamond ore it will give you a diamond?
    So it will give the player the right drop and not the block type?!

    Right now if you mine grass it will give you grass and if you mine an Ore it will give you that ore..

    Thanks,
    Cherwin1
     
  2. Offline

    Darkpicasa

    Do e.getBlock().getDrops(), not e.getBlock().getType().
     
  3. Offline

    Barinade

    Are you doing this so players can't steal other players' blocks?
    Just make it so the item isn't able to be picked up unless the block breaker is picking it up
     
  4. Does this give the player the right drop?

    Making that is a bit too difficult i think ;$
    Im not that good yet.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  5. Offline

    Barinade

    Not particularly. If you don't experiment with what you don't know you will never learn :p
     
  6. Sounds like a really good idea though ;$
    Only the player who broke the block can pick the item(s) up :)

    I am going to experiment with that idea tomorrow
     
Thread Status:
Not open for further replies.

Share This Page