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

How to get the content of chat messages.

Comments in 'Plugin Development' started by 1vannn, Jul 25, 2014.

  1. 1vannn
    Offline

    1vannn New Member

    Joined:
    Jul 25, 2014
    Posts:
    7
    Minecraft User:
    1vannn
    I am creating a mod for myself (and others if they are interested) where you type in simple things in chat, maybe 'daytime', or 'midnight', and it'll turn it to that period of day. My question at the moment is how do I get the content of a chat message for me to find parts of the string for matches (daytime, etc). This is also my first plugin, so I am not 100% sure what I am doing either although I do know PHP. :)

  2. Topic
    Offline

    Topic New Member Plugin Developer

    Joined:
    Aug 29, 2013
    Posts:
    47
    Plugins:
    3
    Minecraft User:
    topic
    It's already in PocketMine-MP, command: /time set
  3. 1vannn
    Offline

    1vannn New Member

    Joined:
    Jul 25, 2014
    Posts:
    7
    Minecraft User:
    1vannn
    The reason I want to implement this for myself is not only for time, I'm well aware of /time set, but I was going to make it simpler with a simple chat message, "diamond", "night", etc. This is what I've come up so far. Only problem is that it crashes.

    Serverlog:
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    1. onDisable() isn't necessary.
    2. Why use RegExp for something such simple?
    3. I don't like seeing fully qualified namespaces inside code, and I think most if the forum likes reading code in the [PHP][/PHP] bbcode tag instead, but they are still, ok.
    4. It is in Zekkou cake API, so there is no $this->api defined, so it crashes.
  5. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    i think onLoad isn't necessary as well
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes, but he didn't put it there
  7. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    i meant the first code
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    BTW it's called a plugin not a mod.
    swagboy47 likes this.
  9. 1vannn
    Offline

    1vannn New Member

    Joined:
    Jul 25, 2014
    Posts:
    7
    Minecraft User:
    1vannn
    Sorry, PEMapModder. It's 2am, I need sleep haha. ;) I rewrote it a little bit, it doesn't crash now because I didn't tell it to run console commands. :\ I think switch() is much simpler.

  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The token behind case should be a value. Putting characters directly behind it would be parsed as a constant name.
  11. 1vannn
    Offline

    1vannn New Member

    Joined:
    Jul 25, 2014
    Posts:
    7
    Minecraft User:
    1vannn
    Alright, let me rephrase my question, my goal for this project is like the iOS assistant, Siri, except as a way of learning how to use Events, etc. in PHP. I have a few younger nephews (5,6,10) who play on my server and do not know how to run commands. What I want to make is a plugin that reads all messages from chat and checks for specific words in it, so for instance Mason types, "Ivan, can you make it day?". The bolded text would be a keyword I specified and gave a output, which is a command. Day would refer to /time set 900, night 19000, etc. The problem I am having is running the console command, it crashes my server. If someone would guide me in the right direction I would really appreciate your help. :)
  12. iFootball
    Offline

    iFootball Active Member

    Joined:
    Jun 9, 2014
    Posts:
    84
    Minecraft User:
    iFootball
    Someone already made this, but for the case it would be
    PHP:
    case "time":
    case 
    "Ivan, can you make it day":
    case 
    "I want day":
    //and so on for each way of saying it
    //then the commands
     
    break;
    And please use ["PHP"] ["/PHP"] (No quotes)for your code it makes it easier to understand
    LDX likes this.
  13. 1vannn
    Offline

    1vannn New Member

    Joined:
    Jul 25, 2014
    Posts:
    7
    Minecraft User:
    1vannn
    ah, iFootball, thanks for the help on the PHP tag, never used that before haha. How do I run the command, because I do
    PHP:
            if (preg_match('/day/',$message)) { // I'll use Case, easier but for now.
                
    $this->api->console->run("time set 900");
            }
    and it crashes the server.
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I told you already. You defined no such thing as $this->api.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What if they say, "hi ***, every day I play on this server!"
  16. Dutok
    Offline

    Dutok Notable Member Plugin Developer

    Joined:
    Jun 20, 2014
    Posts:
    371
    Plugins:
    3
    Minecraft User:
    Dutok
    He will probably warn them of this feature. :)
  17. iFootball
    Offline

    iFootball Active Member

    Joined:
    Jun 9, 2014
    Posts:
    84
    Minecraft User:
    iFootball
    That's old API,
    New API:
    PHP:
    $this->getServer()->dispatchCommand("time set 900");
  18. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You need the ConsoleCommandSender parameter.
    I think it is faster to use stripos(). Also, if you use RegExp, add the "i" delimiter for case insensitive check.
  19. 1vannn
    Offline

    1vannn New Member

    Joined:
    Jul 25, 2014
    Posts:
    7
    Minecraft User:
    1vannn
    Thank you all for your help. Sorry I haven't made a plugin yet, so I am not very experienced haha.
  20. 1vannn
    Offline

    1vannn New Member

    Joined:
    Jul 25, 2014
    Posts:
    7
    Minecraft User:
    1vannn
    That would why I test the plugin and find that same problem and use switch() instead. Thanks! :)

Share This Page

Advertisement