Solved Checking for not equal to one of two commands

Discussion in 'Plugin Development' started by Tdarnell, Jun 23, 2013.

Thread Status:
Not open for further replies.
  1. Fairly basic problem, not sure how to go about solving it though.

    Code:java
    1. if ((!cmd.equalsIgnoreCase("bleep")) || (!cmd.equalsIgnoreCase("bloop"))){
    2. event.setCancelled(true);
    3. }


    I have tried several methods, such as having an 'else if' for the second command, but the problem is I can't check for it being one or the other very easily, maby an array?
    is there something simple I am missing?

    I basically want to block everything but these two commands, before other plugins process them (using the PlayerCommandPreprocessEvent)

    as always, any help is appreciated :)
     
  2. Offline

    Rocoty

    I think you'd like to change || to &&
     
  3. Wow, that was a simple mistake, thanks ;D
    I just couldn't get my head round it very easily, wasn't sure if I should use 'and' or 'or' in this case.
    Thanks
     
  4. Offline

    tuskiomi

    yes, that if statement would always trigger because if it is beep its not boop and vice verca
     
  5. I thought thats how the && statement would end up working, I was wrong :p

    Ok, this is still broken. fires every time I enter a command still, the && statement did not fix it, I am once again, completely baffled.

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

    tuskiomi

    !((cmd.equalsIgnoreCase("bleep"))||(cmd.equalsIgnoreCase("bloop"))
     
  7. I'll try it :)
    Looks right though
     
  8. Offline

    tuskiomi

    Code:
    !((cmd.equalsIgnoreCase("bleep")) || (cmd.equalsIgnoreCase("bloop")))
    try this
    edit: i ninja'd myself
     
  9. Still broken :'(
    It still sends me the debug message I put in there saying It was not one of those commands.
     
  10. Offline

    tuskiomi

    cmd is a string, right? not a command.
     
  11. Code:java
    1. @EventHandler
    2. public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event){
    3. Player player = event.getPlayer();
    4. String cmd = event.getMessage();


    *Slightly ashamed bump*

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

    tuskiomi

    try replacing "bleep" with /bleep
     
  13. nope :'(
     
  14. Offline

    tuskiomi

  15. Code:java
    1. if (!(cmd.equalsIgnoreCase("/rules")) && (!cmd.equalsIgnoreCase("/acceptrules"))){

    Fixed using ! ourside an && bracket with the /. Thanks for all the help :)
     
Thread Status:
Not open for further replies.

Share This Page