Right Click event not working but Left Click is

Discussion in 'Plugin Development' started by josh12341, Nov 13, 2013.

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

    josh12341

    Hey guys,
    I need some help again :p.
    I'm trying to create a plugin but A left click event will work but not a right. I don't understand why, could you try to give me examples and tell me how to fix this problem.
    BTW: This is not my whole code but I know it's working because the Left Click works!
    CODE:
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler(priority = EventPriority.LOW)
    3. public void onPlayerInteract(PlayerInteractEvent event) {
    4. Player player = event.getPlayer();
    5. ItemStack held = player.getItemInHand();
    6. Block target = player.getTargetBlock(null, 100);
    7. if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK)
    8. if(held.getType() == Material.STICK){
    9. ItemMeta meta = held.getItemMeta();
    10. if(meta != null){
    11. if(meta.getDisplayName().equalsIgnoreCase("Exploder")){
    12. player.getWorld().strikeLightning(target.getLocation());
    13. }else{
    14. if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)
    15. if(held.getType() == Material.STICK){
    16. if(meta != null){
    17. if(meta.getDisplayName().equalsIgnoreCase("Exploder")){
    18. player.getWorld().createExplosion(target.getLocation(), 5);
    19. }else{
    20. return;
    21. }
    22. }
    23. }
    24. }
    25. }
    26. }
    27. }
    28. }
     
  2. Offline

    Sweatyyyy

    josh12341
    Try removing both of the else statements as they are not needed
     
  3. Offline

    josh12341

    It still doesn't work :( please help!
     
  4. Offline

    drtshock

  5. Offline

    josh12341

    If I'm, wrong please give me an example.
    I don't think it matter, but any way here is the new code, Testing now:
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler(priority = EventPriority.LOW)
    3. public void onPlayerInteract(PlayerInteractEvent event) {
    4. Player player = event.getPlayer();
    5. ItemStack held = player.getItemInHand();
    6. Block target = player.getTargetBlock(null, 100);
    7. if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK)
    8. if(held.getType() == Material.STICK){
    9. ItemMeta meta = held.getItemMeta();
    10. if(meta != null){
    11. if(meta.getDisplayName().equalsIgnoreCase("Exploder")){
    12. player.getWorld().strikeLightning(target.getLocation());
    13. if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)
    14. if(held.getType() == Material.STICK){
    15. if(meta != null){
    16. if(meta.getDisplayName().equalsIgnoreCase("Exploder")){
    17. player.getWorld().createExplosion(target.getLocation(), 5);
    18. }
    19. }
    20. }
    21. }
    22. }
    23. }
    24. }
    25. }


    Nope, still doesn't work.
    I'm telling you, the lining doesn't matter.
    My left click event is working but just not the right.
    If lining does matter can you please fix it and give me an example.
    Thanks

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  6. Offline

    cummo15

    josh12341 Your "lining" was off.
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4. ItemStack held = player.getItemInHand();
    5. Block target = player.getTargetBlock(null, 100);
    6. ItemMeta meta = held.getItemMeta();
    7. if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
    8. if (held.getType() == Material.STICK) {
    9. if (meta != null) {
    10. if (meta.getDisplayName().equalsIgnoreCase("Exploder")) {
    11. player.getWorld().strikeLightning(target.getLocation());
    12. }
    13. }
    14. }
    15. }
    16. if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    17. if (held.getType() == Material.STICK) {
    18. if (meta != null) {
    19. if (meta.getDisplayName().equalsIgnoreCase("Exploder")) {
    20. player.getWorld().createExplosion(target.getLocation(), 5);
    21. }
    22. }
    23. }
    24. }
    25. }
     
  7. Offline

    hellboyPS

    Note: PlayerInteractEvent does not get called if the player is rightclicking a block while holding a item/block in his hand (like, for example, right clicking a sign while having cobblestone in your hand).
    It wasn't like this before (I think the change came somewhere around 1.3).
     
  8. Offline

    josh12341

    OMG thanks, it Works now!
    :)
     
Thread Status:
Not open for further replies.

Share This Page