PlayerCommandPreprocessEvent Problem

Discussion in 'Plugin Development' started by MrSpyMan, Dec 19, 2014.

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

    MrSpyMan

    I'm not sure why this part of my code won't work. I am trying to make players only able to use /msg, /w, /t and /tell. I was debugging it and I couldn't figure out why it wouldn't work..


    Code:
    @EventHandler
    public void onPreCommand(PlayerCommandPreprocessEvent event){
          
    if (!event.getMessage().toLowerCase().startsWith("/msg")
                    || !event.getMessage().toLowerCase().startsWith("/w")
                    || !event.getMessage().toLowerCase().startsWith("/t")
                    || !event.getMessage().toLowerCase().startsWith("/tell")) {
                event.setCancelled(true);
                }
            }
     
  2. Offline

    Tecno_Wizard

    @MrSpyMan, Your issue is fairly stupid. You're trying to accept all but these values, correct?
    All of the ors must be ands, || must be &&
     
  3. Offline

    MrSpyMan

    @Tecno_Wizard I'm pretty sure it should be || because that means or... This is ment to check if the message is /msg or /w or /t or /tell. But I'm not sure why it's not working..
     
  4. Offline

    mythbusterma

    @MrSpyMan

    He's right, it's DeMorgan's law.

    [​IMG]
     
    API_Tutorials and MrSpyMan like this.
  5. Offline

    Tecno_Wizard

    @MrSpyMan, it's a lot more confusing than it seems.

    So I am going to use the fake method foo() which returns a Boolean as an example.
    Foo returns true if a innocuous condition is true.

    So our if statement is if (foo() || foo1() || foo2())
    If ONE of these is true in this case, ALL of them are true because an or statement will always return true if even one is true. So while foo() might be true, foo1() will be false, because it is not that command, making the final Boolean false. If you use and, all of them must be true for the final response to be true. If even one is false, the entire statement will be false.
    Comprendre?

    @mythbusterma, that's a law?
     
  6. Offline

    mythbusterma

    @Tecno_Wizard

    His misguided thinking was something along the lines of "not (message is /msg or message is /w)," which he then incorrectly simplified to "not message is /msg or not message is /w" when, logically it is "not message is /msg and not message is /w." Look at the Wikipedia article: http://en.wikipedia.org/wiki/De_Morgan's_laws
     
  7. Offline

    MrSpyMan

    @mythbusterma Thank you for the help! Besides De Morgan's Law is there anything other laws like that?
     
  8. Offline

    mythbusterma

    Konato_K and MrSpyMan like this.
  9. Offline

    drpk

    @MrSpyMan wont your code make every other command not work?

    Edit: Whoops, missed the word only.
     
    Last edited: Dec 21, 2014
  10. Offline

    SuperOriginal

    @drpk Did you even read the first post...
     
    drpk likes this.
  11. Offline

    stoneminer02

    Maybe try to set the priority to high?
     
  12. @stoneminer02 No that's not the problem. Read the other replies.
     
  13. Offline

    stoneminer02

    I am not familiar with laws or anything from US/UK as of being from Norway.
    Sorry.
     
  14. Konato_K likes this.
  15. Offline

    stoneminer02

    I see alot of the talking about laws :p
     
  16. Offline

    Konato_K

    Hahahahahaha you made my day!
     
    stoneminer02 likes this.
  17. Offline

    mythbusterma

    @stoneminer02

    We were talking about laws of logic and rules of inference......none of those have to do with the rule of law, at all. Really, read the posts.
     
  18. Offline

    _Filip

    stoneminer02 and leon3001 like this.
  19. Offline

    stoneminer02

    Love you too <3 :3
     
Thread Status:
Not open for further replies.

Share This Page