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

Need help with a very simple thing

Comments in 'Plugin Development' started by Bendrin, Jul 14, 2014.

  1. Bendrin
    Offline

    Bendrin New Member

    Joined:
    Sep 29, 2013
    Posts:
    12
    Minecraft User:
    Bendrin
    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:
    <?php

    namespace 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!");
        }
    }
  2. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    do /pugins and make sure it is in the list if it is not then the problem is from the plugin.yml
  3. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    Try using:
    PHP:
    public function onChatEvent(PlayerChatEvent $event){
    $this->getLogger()->info("Someone wrote a message.");
    }
  4. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    oh yeah :confused: , forgot the PlayerChatEvent $event (dumy)
  5. Bendrin
    Offline

    Bendrin New Member

    Joined:
    Sep 29, 2013
    Posts:
    12
    Minecraft User:
    Bendrin
    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?
  6. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    I made a mistake, try with this code (replace this to the previous one):
    PHP:
    public function onChat(PlayerChatEvent $event){
    $this->getLogger()->info("Someone wrote a message.");
    }
  7. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    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
  8. Bendrin
    Offline

    Bendrin New Member

    Joined:
    Sep 29, 2013
    Posts:
    12
    Minecraft User:
    Bendrin
    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
  9. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    this is wired
  10. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    maybe it's pocketmine problem , when you tested did you tested by chatting in the console or the normal player chat ?
  11. Bendrin
    Offline

    Bendrin New Member

    Joined:
    Sep 29, 2013
    Posts:
    12
    Minecraft User:
    Bendrin
    Indeed it's weird. :p

    I chatted from a normal player in game.
  12. Dutok
    Offline

    Dutok Notable Member Plugin Developer

    Joined:
    Jun 20, 2014
    Posts:
    372
    Plugins:
    3
    Minecraft User:
    Dutok
    It's not. I can use this function fine.
  13. Bendrin
    Offline

    Bendrin New Member

    Joined:
    Sep 29, 2013
    Posts:
    12
    Minecraft User:
    Bendrin
    Can you give me a working code example? It's very weird that it's not working for me.
  14. Dutok
    Offline

    Dutok Notable Member Plugin Developer

    Joined:
    Jun 20, 2014
    Posts:
    372
    Plugins:
    3
    Minecraft User:
    Dutok
  15. Bendrin
    Offline

    Bendrin New Member

    Joined:
    Sep 29, 2013
    Posts:
    12
    Minecraft User:
    Bendrin
  16. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    Last edited: Jul 14, 2014
  17. Bendrin
    Offline

    Bendrin New Member

    Joined:
    Sep 29, 2013
    Posts:
    12
    Minecraft User:
    Bendrin
    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.
    [​IMG]

    This is how my code looks right now:

    PHP:
    <?php

    namespace 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!");
        }
    }
  18. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    it's pocketmine problem
  19. Bendrin
    Offline

    Bendrin New Member

    Joined:
    Sep 29, 2013
    Posts:
    12
    Minecraft User:
    Bendrin
    Okay! :)

    Thank you everyone that helped me! :)
    Dutok likes this.
  20. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    no problem and if you need any help just ask me ;)
    Bendrin likes this.

Share This Page

Advertisement