I'm trying to change/set the player's chat message to something else. I tried this plugin too. Can anyone help? PHP: public function onChat(PlayerChatEvent $event) { $message = str_ireplace("hello", "bye", $event->getMessage()); $event->setMessage($message);}
This problem might by caused by another plugin setting the message after your plugin PHP: /** @param PlayerChatEvent $event* @priority HIGHEST*/ This code above your PlayerChatEvent function (the one that runs when PlayerChatEvent is called) will make the event run AFTER the event was called on other plugins, also, the priority goes from LOWEST to HIGHEST Try that and tell if it worked
Hi =), Error in Line 2 (str_ireplace) PHP: public function onChat(PlayerChatEvent $event){ $message = str_replace("hello", "bye", $event->getMessage()); $event->setMessage($message);} Solved?
But you shouldn't be changing anything once the priority reaches MONITOR. So HIGHEST is the last priority that is relevant here, as the OP is changing something. @KYUMA str_ireplace() is a PHP function, it's the case-insensitive version of str_replace(). @WinterBuild7074 Any error messages? If you echo something when the event is called, do you see it on console?
I recommend you guys learn more about Priorities.. and how they work! Here's something that'll get your mind straight!
The priority is totally irrelevant with whether the event is cancelled, since you are not tracking @ignoreCancelled.