BlockBreakEvent

Discussion in 'Plugin Development' started by ProStriker123, Sep 5, 2014.

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

    ProStriker123

    How to do when you breaking a block its will add instand to the inventory
    @EventHandler
    public void onBreak(BlockBreakEvent e) {
    Player p = e.getPlayer();
    p.openInventory(p.getInventory());
    }
    this its not working for me
     
  2. Offline

    ERROR372

    Uh... your code doesn't add anything to the inventory. Why are you bothering to open the inventory? Just do something along the lines of:

    Code:java
    1. ItemStack dropped = new ItemStack(e.getBlock().getType(), 1);
    2. e.getPlayer().getInventory.addItem(dropped);
    3. e.getBlock().getDrops().clear();


    That should add the item to the dropped block straight to the inventory, and prevent the block from dropping any items.


    or, if you want to cut one more line out:

    Code:java
    1. e.getPlayer().getInventory().addItem(new ItemStack(e.getBlock().getType(), 1));
    2. e.getBlock().getDrops().clear();
     
    MrEditor97 likes this.
  3. Offline

    MoeMix

    ProStriker123, what are you trying to do? the p#openInventory() method will not call an inventory if it's null! You have to create an inventory first and then you can open it. Google it... not that hard.
     
Thread Status:
Not open for further replies.

Share This Page