Event handler help

Discussion in 'Spigot Plugin Development' started by Crafter145, Apr 18, 2017.

  1. Could someone send me a code of if a player right clicks while shifting on a block it will run a command i already made?
     
  2. Code (Text):
    If a player right clicks while shifting on a block it will run a command i already made
     
    • Funny Funny x 1
  3. Okay i do deserve that but please im having trouble making the action right clicking while shifting
     
  4. I'm not going to spoonfeed code, but you should look into registering events, specifically the PlayerInteractEvent.
     
  5. No I'm just joking :D I will dont give you code, but logic how to make it ;) Sorry but no spoonfeeds.

    PlayerInterractEvent
    If player is Shifting, if event#getAction == Action#Right_Click_Block ---> player#performCommand(cmd)
     
  6. I can only find right clicking and other actions but not shift right clicking
     
  7. Oh. Here you go: Player#isSneaking
     

  8. Yes but how do i make it only when they shift right click
     
  9. If action is right click && player.isSneaking()


    Sent from my iPhone using Tapatalk
     
    • Agree Agree x 1
  10. Thanks that makes sense xD
     
  11. @EventHandler
    public void rightclickstick(PlayerInteractEvent event) {

    Player player = event.getPlayer();

    if(event.getAction() == Action.RIGHT_CLICK_BLOCK && player.isSneaking()){

    if(player.getItemInHand().getType() == Material.STICK) {


    Would this work right?
     
  12. Yes but if they have no item in hand then it will throw a Null Pointer Exception (NPE) because itemInHand is null.

    You should check if iteminhand is null then if so do your check for the stick


    Sent from my iPhone using Tapatalk
     
  13. Okay thanks so much