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

Player.chat

Comments in 'Plugin Development' started by Legomite, Apr 20, 2014.

  1. Legomite
    Offline

    Legomite Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    470
    Plugins:
    2
    Minecraft User:
    Legomite
    How do you detect a certain symbol on the player.chat?
  2. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    388
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    I'm not 100% sure but I think its:
    PHP:
    $message strtolower($data['message']);
    $Symbol "(Symbol)";
    if(
    preg_match($Symbol$message)){
        
    //Code for if message contains the symbol
    }
    For example if you were looking for the symbol @ then the symbol variable ($Symbol) would look like this:
    PHP:
    $Symbol "@";
  3. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    That might work but regex are slow, try:
    PHP:
    if(stripos($data["message"],$symbol) !== false){
    //Do this
    }
    You can set $symbol to any string.
    Comedyman937 likes this.
  4. Legomite
    Offline

    Legomite Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    470
    Plugins:
    2
    Minecraft User:
    Legomite
    How do you make the plugin detect what's after the symbol like I want to detect the word By with the text @by
  5. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    If you only need that first occurrence you can create a substring of the original starting at the stripos and then create a substring of that going from 0 to the strpos of " ". If you need to detect all occurrences of this you could do a fancy loop or use a regex (I have one like this in my Mentions plugin).
  6. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    435
    Plugins:
    4
    Minecraft User:
    Lambo
    I think you want to replace a symbol in chat?
    PHP:
    $msg str_replace("@by","replace_word",$data["message"]);
  7. Legomite
    Offline

    Legomite Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    470
    Plugins:
    2
    Minecraft User:
    Legomite
    In English please. :)
  8. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    In the following message what information would you want to extract:
    Code:
    Hello @b foo @c
  9. Legomite
    Offline

    Legomite Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    470
    Plugins:
    2
    Minecraft User:
    Legomite
    b from @b
  10. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    If you just need the first one that you can use:
    PHP:
    if(strpos($data['message'],"@") !== false){
    $foo substr($data['message'],strpos($data['message'],"@"));
    $foo substr($foo,0,strpos($foo," "));
    }
  11. Legomite
    Offline

    Legomite Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    470
    Plugins:
    2
    Minecraft User:
    Legomite
    If I would like to detect the word after the @ like this.

    @Thisismyword not me!

    I would want to detect Thisismyword, but not the not me!
  12. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Yes this would detect the word foo in the following messages and only foo:
    @foo hey
    [email protected]
    @foo @not
  13. Legomite
    Offline

    Legomite Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    470
    Plugins:
    2
    Minecraft User:
    Legomite
    So in the code, the value $foo would get the thisismyword?
  14. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    That's what's supposed to happen :)

Share This Page

Advertisement