Detecting when a player clicks with a certain item

Discussion in 'Plugin Development' started by mike546378, Jul 25, 2013.

Thread Status:
Not open for further replies.
  1. So im making a plugin for my modded server that will stop people from using certain items. So far I have Craft, ItemPickup and blockPlace listeners then those events get canceled if the player has a specific permission with the item id and data value in it. However when I came round to disabling right/left click with certain items I couldn't find an event for it. I did find something about ClickType in the apidocs but am not too sure how to use it. Would I set it up as a listener and if so how would I start it? ie. one of my listeners is
    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. //On Block Place
    3. public void onBlockPlace(BlockPlaceEvent ev){
    But I just cant figure out how to do that with ClickType. Any help is appreciated
     
  2. Offline

    chasechocolate

    PlayerInteractEvent.
     
  3. Offline

    ShadowLAX

    Those API Docs are for version 1.5.2 What exactly did you want the players to not be able to do? Clarify please.

    EDIT: Solved above.
     
  4. Offline

    seemethere

    mike546378

    Code:java
    1. @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. if (event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
    4. //Do stuff
    5. } else if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    6. //Do stuff
    7. } else if (event.getAction().equals(Action.LEFT_CLICK_AIR)) {
    8. //Do Stuff
    9. } else if (event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
    10. //Do Stuff
    11. }
    12. }
     
  5. seemethere Ahh, thanks. Didn't realize it was the PlayerInteractEvent I had to use :)
     
Thread Status:
Not open for further replies.

Share This Page