Simple give command

Discussion in 'Plugin Development' started by Darkpicasa, Sep 7, 2014.

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

    Darkpicasa

    Hi everyone!
    I was wondering, is there a way to give a player an item, if you have the player object?
    I tried using the /give command, but it spams the console with messages, because of Essentials.
    Please help :)
     
  2. I dont quite understand what you are trying to accomplish. Are you looking for an existing command? Or trying a program a different one?
     
  3. Offline

    Darkpicasa

    I'm coding a plugin that when you break a block, it gives you a block. But the thing is, if I use the Bukkit.DispatchCommand with ConsoleSender for the command /give, then it spams the console with info about giving a player a block. I was wondering if there was a separate code possible, like player.giveBlock(Item) or something like that.
     
  4. So you want it to give the player the item without making an itemdrop?
     
  5. Offline

    Darkpicasa

    xXblazingvortexXx yeah, sorta. But I got everything working already, other than that giving the player an item with the ConsoleSender /give command spams the console with "Gave player 1 stone" and stuff like that.
     
  6. Offline

    SmooshCakez

    Use Player#getInventory() and then do Inventory#addItem() to give them items. As for the block not dropping, do e.setCancelled(); and get the block with e.getBlock(), then set its type to Material.AIR.
     
  7. ^^ what he said, also dont forget event.getBlock().getDrops().clear(); to remove the drops it creates
     
  8. Offline

    Darkpicasa

    Thanks!
     
  9. Offline

    SmooshCakez

    It won't create drops if you cancel the event. Another note, Darkpicasa, you should take durability from the tool the player is holding when they break the block, because cancelling the event cancels items taking durability too.
     
  10. SmooshCakez If you cancel the event then the block will still be there after breaking it and you can break it again and get infinite of what ever you want. However there is an expection if your making a mini game plugin and you just want it for selecting classes and when you break it it gives you that class or whatever. But for what I think your doing, you only want to clear the item drops so the block dissapears after you break it.
     
Thread Status:
Not open for further replies.

Share This Page