Solved Event (!=) operator not working

Discussion in 'Plugin Development' started by lewysryan, Jan 17, 2014.

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

    lewysryan

    Any idea?

    Code:java
    1. @EventHandler
    2. public void shopopen(PlayerInteractEvent e){
    3. Player player = e.getPlayer();
    4.  
    5. if((e.getAction() != Action.RIGHT_CLICK_AIR) || (e.getAction() != Action.RIGHT_CLICK_BLOCK )){
    6. return;
    7. }
    8. if(player.getItemInHand().getType() != Material.BONE) {
    9. return;
    10. }
    11. player.sendMessage("YO THIS **** WORK");
    12.  
    13. }
     
  2. Offline

    Garris0n

    Is it registered?
     
  3. Offline

    lewysryan

    Garris0n yeah, It is

    EDIT: it is firing. Just not doing what I want.

    Code:java
    1. @EventHandler
    2. public void shopopen(PlayerInteractEvent e){
    3. Player player = e.getPlayer();
    4. player.sendMessage("CLICK ME BABE <3"); //This is working
    5.  
    6. if(((e.getAction() != Action.RIGHT_CLICK_AIR) || (e.getAction() != Action.RIGHT_CLICK_BLOCK ))){
    7. return;
    8. }
    9. if(player.getItemInHand().getType() != Material.BONE) {
    10. return;
    11. }
    12. player.sendMessage("YO THIS **** WORK"); //this is not.
    13.  
    14. }
    15. }
     
  4. Offline

    Garris0n

    The action can only be one thing, so that if statement is always true. Also, you should read up on Java naming conventions.
     
    lewysryan likes this.
  5. Offline

    Blah1

    Will first, use !.equals instead of !=
    And always check to make sure and item != null && !item is air
     
    lewysryan likes this.
  6. Offline

    lewysryan

    Garris0n Blah1

    Lol had a dumb moment. I got it working now. Thank you both. and will do blah1 thanks.

    Code:java
    1. if(e.getAction() != Action.RIGHT_CLICK_AIR) {
    2. if(e.getAction() != Action.RIGHT_CLICK_BLOCK){
    3. return;
    4. }
    5. }
     
  7. Offline

    Not2EXceL

    lewysryan you should have and && instead of an || operator then.
     
    lewysryan and Garris0n like this.
Thread Status:
Not open for further replies.

Share This Page