I'm trying to learn plugin development and started with a very simple thing. I want something to run when a player is sending a message. But it does not work. What's wrong? Probably something very simple and stupid? The PlayerChatEvent() don't seem to be called because the string "Someone wrote a message." does not show up in the server-log when i write a message. Here is the code: PHP: <?phpnamespace Bendrin\Test;use pocketmine\plugin\PluginBase;use pocketmine\event\player\PlayerChatEvent;class Test extends PluginBase{ public function onEnable(){ $this->getLogger()->info("onEnable() has been called!"); } public function PlayerChatEvent(){ $this->getLogger()->info("Someone wrote a message."); } public function onDisable(){ $this->getLogger()->info("onDisable() has been called!"); }}
The plugin is loaded as it should. Tried it, but it didn't fix it. Can it be something with PHP: class Test extends PluginBase ? It only extends PluginBase and not PlayerChatEvent. How do i put it in there?
onchat or onchatevent is callable so it doesn't matter what it is called so i think the problem is from the plugin.yml , can you show it to us
Nope, that didn't fix it. I don't think it's a problem in the plugin.yml. The plugin loads just fine and the other 2 functions onEnable() and onDisable() works. Btw, here is the plugin.yml: Code: name: Test version: 1.0.0 api: 1.0.0 author: Bendrin main: Bendrin\Test\Test
maybe it's pocketmine problem , when you tested did you tested by chatting in the console or the normal player chat ?
What I'm referencing is private, but I learned from SimpleAuth: https://github.com/PocketMine/SimpleAuth/blob/master/src/SimpleAuth/SimpleAuth.php#L289-L290
oh yeah you have to put $this->getServer()->getPluginManager()->registerEvents($this, $this); under onenable ( how did i forgot about it )
Yaay! It's working! But I get an error in the console every time a message is sent in game. The plugin works, but the spam in the console is not very nice. This is how my code looks right now: PHP: <?phpnamespace Bendrin\Test;use pocketmine\plugin\PluginBase;use pocketmine\event\player\PlayerChatEvent;use pocketmine\event\Listener;class Test extends PluginBase{ public function onEnable(){ $this->getLogger()->info("onEnable() has been called!"); $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onChatEvent(PlayerChatEvent $event){ $this->getLogger()->info("Someone wrote a message."); } public function onDisable(){ $this->getLogger()->info("onDisable() has been called!"); }}
It's not a Pocketmine problem.. Replace: PHP: class Test extends PluginBase{ With: PHP: class Test extends PluginBase implements listener{