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.
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:
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.
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.
The token behind case should be a value. Putting characters directly behind it would be parsed as a constant name.
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.
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
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. Spoiler: Log
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.