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

Tutorial New API: Handling events

Comments in 'Resources' started by GlaciercreepsMC, Aug 3, 2014.

  1. GlaciercreepsMC
    Offline

    GlaciercreepsMC Active Member Plugin Developer

    Joined:
    Jan 21, 2014
    Posts:
    91
    Plugins:
    1
    Minecraft User:
    GlaciercreepsMC
    No, foreach loops are kinda meant for arrays, theres something wrong with your code or something else you missed. Try reading my post again carefully and remake the project, use the links as well. Do you use an IDE? IDE's can help you find your error.
  2. sebagius7110
    Offline

    sebagius7110 Active Member

    Joined:
    Jul 1, 2014
    Posts:
    66
    Minecraft User:
    sebagius7110
    Yes I use an IDE and there are no errors there.
  3. Kagehis4
    Offline

    Kagehis4 New Member

    Joined:
    Aug 20, 2014
    Posts:
    44
    Minecraft User:
    Kagehis4
    use preg_match

    Code:
    $msg = $event->getMessage();
    $bannedwords = array(...);
    if(preg_match('/'.implode('|', $bannedwords).'/', $msg, $matches)){
    $event->setCanceled();
    }
    
    LDX and PEMapModder like this.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Double l for cancelled.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    in_array() is faster :)
  6. Kagehis4
    Offline

    Kagehis4 New Member

    Joined:
    Aug 20, 2014
    Posts:
    44
    Minecraft User:
    Kagehis4
    yeah but you must explode the $msg too.. what if they write "f*ckyou" no spaces.. you cant use in_array to get that..
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Then strpos.
  8. Kagehis4
    Offline

    Kagehis4 New Member

    Joined:
    Aug 20, 2014
    Posts:
    44
    Minecraft User:
    Kagehis4
    yeah but strpos cannot use array as search value but instead converting it as ordinal value character.. if not supplied by string
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    foreach the array of bad words and use stripos (edit: not strpos()). It is still faster than RegExp I think.
    LDX likes this.
  10. xXSuperFrostyXx
    Offline

    xXSuperFrostyXx New Member

    Joined:
    Apr 16, 2015
    Posts:
    7
    Minecraft User:
    xXSuperFrostyXx
    Thanks for your help. I really need this information. Thanks ;)
  11. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    PEMapModder likes this.

Share This Page

Advertisement