Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Check player message

Comments in 'Plugin Development' started by Artide, Sep 10, 2015.

  1. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    Ok :)
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It's called code style, not syntax.
    Actually, both way work on both script plugins and phar plugins. However, it is pointless to use namespace{} instead of namespace; in phar plugins, because you only have one namespace in each file in (proper) phar plugins (that follow correct code styles).
    strtolower converts the message to lowercase. In that case, the output can only be "hi" not "Hi". Remember that strtolower only turns one string to lower case, and it doesn't act as something like String.equalsIgnoreCase(String) in Java.
    Code?
    Also, use stripos to detect case-insensitively.
    HotFireyDeath likes this.
  3. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Yes, I did something like:
    if(stripos($e->getMessage(),'noob') !== false){

    $e->setMessage("****");
    $player->sendMessage("No swearing!");

    }
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Check does string is in string
    PHP:
    $string 'Hello World, my name is Nick Jonah'
    if (strpos(strtolower($string), strtolower('Hello World')) != false){
    // $string contains "Hello World"
    }
    And its not 'stripos' but 'strpos'
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It is stripos. Please read the PHP docs before you post. Doing stripos($a, $b) is faster than strpos(strtolower($a), strtolower($b)).
    HotFireyDeath likes this.
  6. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Use a code block, kid! :p
  7. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    No.
  8. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Why? Because you don't know how? :p
  9. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    No. What is it?
  10. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    What is what?
  11. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    The thing you said: 'code block'.
  12. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    PHP:
    //This comment is inside a code block.
    Last edited: Sep 11, 2015
  13. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Oh. I thought they were called comments. :p
    HotFireyDeath likes this.
  14. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    I was talking about the block the comment was inside of. :p
    HotFireyDeath likes this.
  15. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    ?
  16. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    you forgot

    PHP:
       $ev->setCancelled(true);
    so it get cancelled and not preformed.
  17. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    I know that but don't put true because it will disable the whole chat.
    Taha_The_Hacker likes this.
  18. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Learn using [plain][/plain], kid.
    Anyway, @Artide, it should be [php][/php].
    Event->setCancelled() does the exact same thing as Event->setCancelled(true) and has little/no difference in terms of performance.
    Artide likes this.
  19. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Well, then how to enable again if I use $e->setCancelled()?
    Taha_The_Hacker likes this.
  20. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    $ev->setCancelled(false);
    PEMapModder and Taha_The_Hacker like this.

Share This Page

Advertisement