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. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    oh yeah :confused: , forgot the PlayerChatEvent $event (dumy)
  4. 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?
  5. 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
  6. 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
  7. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    this is wired
  8. 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 ?
  9. 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.
  10. Dutok
    Offline

    Dutok Notable Member Plugin Developer

    Joined:
    Jun 20, 2014
    Posts:
    371
    Plugins:
    3
    Minecraft User:
    Dutok
    It's not. I can use this function fine.
  11. 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.
  12. Dutok
    Offline

    Dutok Notable Member Plugin Developer

    Joined:
    Jun 20, 2014
    Posts:
    371
    Plugins:
    3
    Minecraft User:
    Dutok
  13. Bendrin
    Offline

    Bendrin New Member

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

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    Last edited: Jul 14, 2014
  15. 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!");
        }
    }
  16. swagboy47
    Offline

    swagboy47 Active Member

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

    Bendrin New Member

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

    Thank you everyone that helped me! :)
    Dutok likes this.
  18. 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.
  19. Dutok
    Offline

    Dutok Notable Member Plugin Developer

    Joined:
    Jun 20, 2014
    Posts:
    371
    Plugins:
    3
    Minecraft User:
    Dutok
    It's not a Pocketmine problem.. :rolleyes:

    Replace:
    PHP:
    class Test extends PluginBase{
    With:
    PHP:
    class Test extends PluginBase implements listener{
    Bendrin and Darunia18 like this.
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You have to implement the Listener interface. All event listeners need to when they are registered.
    Dutok and Bendrin like this.

Share This Page

Advertisement