Solved Right Click Air not working?

Discussion in 'Plugin Development' started by gamerzap, Sep 30, 2012.

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

    gamerzap

    I have it set so that when certain players right click air or a block with a blaze rod, it shoots an arrow, but it's only working when they right click a block. Heres the code:
    Code:
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent evt){   
            if(player.getItemInHand().getType()==Material.BLAZE_ROD && kit.get(player)==Kit.COMMANDO && (evt.getAction().equals(Action.RIGHT_CLICK_AIR) || evt.getAction().equals(Action.RIGHT_CLICK_BLOCK))){
                if(player.getInventory().contains(Material.ARROW)){
                    Arrow arrow = player.launchProjectile(Arrow.class);
                    arrow.setVelocity(arrow.getVelocity().multiply(5));
                    ItemStack iss = new ItemStack(Material.ARROW);
                    player.getInventory().removeItem(iss);
                }
            }
        }
    Bump
    (I really need to know this as soon as is possible)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  2. try replacing this:

    Code:
    if(player.getItemInHand().getType()==Material.BLAZE_ROD && kit.get(player)==Kit.COMMANDO && (evt.getAction().equals(Action.RIGHT_CLICK_AIR) || evt.getAction().equals(Action.RIGHT_CLICK_BLOCK))){
    with:

    Code:
    if(player.getItemInHand().getType()==Material.BLAZE_ROD && kit.get(player)==Kit.COMMANDO){
    if(evt.getAction().equals(Action.RIGHT_CLICK_AIR) || evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
    // code
    }
    }
     
  3. Offline

    gamerzap

    Didn't work. Still doesn't do anything when I right click air.

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  4. But now it also doesn't do anything when you right click a block, because the precondition is false.
     
  5. For whatever reason, the bukkit team decided that playerInteract for right clicks on air should be automatically cancelled. At least I'm pretty sure it's intentional, tho I can't make any sense of it.

    Anyways, unless they fix/change it if you're ignoring cancelled events, it won't fire in this case.
     
    _LB likes this.
  6. Offline

    gamerzap

    Really? I've seen people do it before? Is there some other way to do it?
     
  7. Offline

    gamerzap

    Bump ( I REALLY REALLY need this)
     
  8. Doesn't it work if you try to use BlockBreakEvent and if the item is air? :D or Block Damage event.
     
  9. Your conditions are turning up false, dude.. gamerzap

    kit.get(player)==Kit.COMMANDO
     
  10. Offline

    gamerzap

    Tirelessly No, It works if I right click a block
     
  11. you're doing it wrong...
    its not evt.getAction.equals...equals is for strings *slaps it with staple on your forehead*
    use if(evt.getAction() == Action.RIGHT_CLICK_AIR or block or your dog whatever .. peace this is solved < <
     
  12. event.getAction() == Action.RIGHT_CLICK_AIR
    What Vandrake said
     
  13. Offline

    gamerzap

    Umm, .equals is for ALL OBJECTS.
     
    1mpre55, Derthmonuter and kroltan like this.
  14. Offline

    Courier

    With primitives and enums, you use ==.

    == compares the object references (the pointers).
    equals() compares whatever the object defines in its equals() method.

    Enum values are static, so Action.RIGHT_CLICK_AIR == Action.RIGHT_CLICK_AIR. They are the same object.
     
    kroltan likes this.
  15. This may be true, but I don't think it's the problem. The equals() method works perfectly fine on enums.
     
    1mpre55 likes this.
  16. Offline

    Courier

    Yeah. With Enums you can use either. Conventions usually say to use ==.

    Also it's a teeny tiny bit faster, because there is one less virtual function call.
     
  17. Offline

    gamerzap

    I know, I usually use ==, but that's not the issue here.
     
  18. Ok, I'm going to say it one more time then I'm going to give up on you.

    if(player.getItemInHand().getType()==Material.BLAZE_ROD && kit.get(player)==Kit.COMMANDO && (evt.getAction().equals(Action.RIGHT_CLICK_AIR) || evt.getAction().equals(Action.RIGHT_CLICK_BLOCK))){

    So what you're saying here is, if the player is holding a blaze rod, right clicking air, and they're kit.COMMANDO, then do this. If they're not all of those things, but they are right clicking a block (not at all checking what they're holding or if they're kit.COMMANDO), then continue. So basically the reason that right click block works is because it continues as long as it's a block right click, regardless of kit.COMMANDO or what they person is holding.

    You can fix that by putting parenthesis around the two actions.
     
  19. Offline

    gamerzap

    Look closer. I did put parentheses around the two actions. I'm not stupid. Don't you see the parentheses before the first action and the second one after the second action?

    Anyway, that's not the problem. It doesn't work if I right click a block with anything besides a blaze rod, and it also doesn't work if their kit isn't commando. The problem is for some reason it isn't doing anything when they right click air.

    Doesn't anybody know how to do this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
    1mpre55 likes this.
  20. this is not hard :confused: why are you having trouble?
    Just check the action of the event
    if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)
    then
    if(e.getPlayer().getInventory().getItemInHand().getType() == Material.BLAZE_ROD)
    then spawn an arrow with velocity :confused:
     
  21. Offline

    gamerzap

    Why does no one listen to me? I did that! Look at my code! But it only works when the right click a block!
     
  22. Offline

    williamtdr

    Works fine on my server, griefme.tk. I comiled what vandrake said to do 2 mins ago, works perfectly. I don't know what you're doing wrong, but you're being kind of impatient. [skeleton]
     
  23. Offline

    gamerzap

    williamtdr Yeah, I'm sorry, it's just these people keep saying the same thing over and over again and if it didn't work the first time, they shouldn't expect it to work the 15th time. I used what Vandrake said, but it still isn't working for me.

    I'm starting to think it has something to do with my computer, because I did get one other weird glitch recently where potion effects would vanish at 26 seconds and my chunk generation on my computer doesn't seem to work correctly, so I think I'll get my freind to run some tests on his computer.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  24. You are definitly having some conflicting plugin :confused: just delete all plugins and test it. If it still happens, then use my code. Completely re-write the code. That's how I do it when I'm stuck o.o delete the WHOLE code in ALL classes o.o but lets not be crazy like me ok?:D Just delete that code xD And rewrite it according to my directions. :3[iron]
     
  25. Offline

    gamerzap

    That was my only plugin (I usually only use plugins I make) and there was nothing conflicting. My comp was the problem.

    Vandrake Oh, and already used your advice, so thanks.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  26. gamerzap So what was the problem? Because I have this issue VERY consistently. The code is all correct, but right clicks on air simply are not fired. Debug code on the very first line of the event handler doesn't output.
     
  27. Offline

    gamerzap

    It seemed to be my computer. It worked on other computers I tested it on.

    I think Mine just didn't consider it improtant enough XD

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  28. Malikk player interact events are only handled if right clicked with items. air and blocks are not accepted. this is my own experiments. nothing official so xD
     
  29. I'm listening for spawn eggs, in my case. So, I'm not sure as to why it isn't firing.
     
  30. Offline

    gamerzap

    Yeah, and I was listening for blaze rods.
     
Thread Status:
Not open for further replies.

Share This Page