1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Help EventListener Class

Discussion in 'Development' started by GrieferHax, May 14, 2021.

  1. GrieferHax

    GrieferHax Silverfish

    Messages:
    19
    The Error:
    Main.php:
    PHP:
    <?php

    declare(strict_types=1);

    namespace 
    ghax\lobby;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;

    class 
    Main extends PluginBase implements Listener{
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
        }
    }
    EventListener.php:
    PHP:
    <?

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerJoinEvent;

    class 
    EventListener implements Listener {
        private 
    $plugin;

        public function 
    __construct(Main $plugin) {
            
    $this->plugin $plugin;
        }

        public function 
    onJoin(PlayerJoinEvent $event) {
            
    $player $event->getPlayer();
            
    $name $player->getName();
            
    $event->setJoinMessage($name." §8[§a+§8]");
        }
    }
     
  2. GrieferHax

    GrieferHax Silverfish

    Messages:
    19
    I add the namespace and use the Main.php too and use listener in the main
     
  3. DavyCraft648

    DavyCraft648 Spider Jockey

    Messages:
    40
    GitHub:
    DavyCraft648
    -lobby
    ---src
    ------ghax
    ---------lobby
    ------------Main.php
    ------------EventListener.php
    ---plugin.yml

    PHP:
    <?php

    declare(strict_types=1);

    namespace 
    ghax\lobby;

    use 
    pocketmine\plugin\PluginBase;

    class 
    Main extends PluginBase {
        public function 
    onEnable() {
            
    $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
        }
    }
    PHP:
    <?php

    namespace ghax\lobby;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerJoinEvent;

    class 
    EventListener implements Listener {
        private 
    $plugin;

        public function 
    __construct(Main $plugin) {
            
    $this->plugin $plugin;
        }

        public function 
    onJoin(PlayerJoinEvent $event): void {
            
    $player $event->getPlayer();
            
    $name $player->getName();
            
    $event->setJoinMessage($name." §8[§a+§8]");
        }
    }
     
    GrieferHax likes this.
  4. GrieferHax

    GrieferHax Silverfish

    Messages:
    19
    Because i dont unser stand but my code was 1 to 1 tue same i have Experiment 2 houers After I poste die ich lok die code i say to me its the same or not ? And i lok 3 Times was exactlie the same code but dont work and than i copy and pasted and than it work but why I dont unser stand this
     
  5. GrieferHax

    GrieferHax Silverfish

    Messages:
    19
    I trie in the function
    PHP:
    $player->sendMessage("myMessage");
    Dont work i got every when i join internal server error but what i do wrong i
    PHP:
    use pocketmine/Player
    in the Main and the eventlistener
     
  6. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Dont just say u have an error. Send us the error
     
  7. GrieferHax

    GrieferHax Silverfish

    Messages:
    19
    In the Logg is not a error but when i join the server instand kick and than come internal server error
     
  8. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Yes it does say an error. Look closely
     
  9. ComorDev

    ComorDev Spider

    Messages:
    11
    GitHub:
    comordev
    If I understand correctly, then your namespace is not specified correctly in the EventListener class.
     
    Last edited: May 27, 2021
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.