How to check what item a player used to break a block

Discussion in 'Spigot Plugin Help' started by kinggoesgaming, May 27, 2015.

  1. Hi

    I am currently working on a plugin that modifies how a player plays survival, however i need a slightly amount of help: how to see what item (shovel, pickaxe etc) or no item for that matter, the player used to break a block.

    Any help appreciated :D
  2. Possibly make an event of a BreakEntity ? I don't really know as I am new to this too and it would seem you can use the getEntity() method after something like this? Possibly make every event like this log into some flat file like Coreprotect or mysql like logblock.
  3. Use a Block break event, then get the player that broke the block and then get the item in the players hand, you can then use this to get the material type etc. Hope that helps?
  4. This is exactly want to know: how to get the item that player is holding and then i can run custom events based on that. I am a bit new to bukkit and stuff so a bit of a struggle for me...
  5. player.getItemInHand() gives you the itemstack of the item the player is holding
  6. If you wish to do custom stuff with certain tools, you can actually name the tool (and give via an essentials kit or even make a new itemstack for it). Upon block break, check for item in hand, check if displayname = "some string", then do stuff.
  7. Thanks a lot guys for the quick replies :D i will get to get that working and if i get anymore problems i will ask :D
  8. Do not forget to check they are actually holding an item, otherwise it will print a stack-trace.
    • Like Like x 1