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

Join Server Commands

Discussion in 'Development' started by @McJblus, Apr 5, 2019.

  1. @McJblus

    @McJblus Spider

    Messages:
    6
    Hello, in a code like this one below I would like to execute a command at each join of the server mcpe, how could I integrate in a code like its?

    PHP:
    <?php

    namespace jblusdev\kenchycore;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerLoginEvent;
    use 
    pocketmine\plugin\PluginBase as Plugin;

    use 
    CustomAlerts\Commands\Commands;
    use 
    CustomAlerts\Events\CustomAlertsMotdUpdateEvent;

    class 
    Loader extends Plugin implements Listener{
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getServer()->getLogger()->info("KenchyCore Enabled!");
        }

        public function 
    onPlayerLogin(PlayerLoginEvent $event){
            
    $event->getPlayer()->teleport($this->getServer()->getDefaultLevel()->getSafeSpawn());
        }

    }
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
  3. Zach1603

    Zach1603 Spider Jockey

    Messages:
    27
    GitHub:
    zedstar16
    It depends who you want to execute the command, if its the player joining it would be
    PHP:
    $this->getServer()->dispatchCommand($event->getPlayer(), "command");
    If you want the executor to be console it would be
    PHP:
    $this->getServer()->dispatchCommand(new \pocketmine\command\ConsoleCommandSender"cmd");
     
  4. @McJblus

    @McJblus Spider

    Messages:
    6
    PHP:
    <?php

    namespace jblusdev\kenchycore;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerLoginEvent;
    use 
    pocketmine\plugin\PluginBase as Plugin;

    use 
    CustomAlerts\Commands\Commands;
    use 
    CustomAlerts\Events\CustomAlertsMotdUpdateEvent;

    class 
    Loader extends Plugin implements Listener{
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getServer()->getLogger()->info("KenchyCore Enabled!");
        }

        public function 
    onPlayerLogin(PlayerLoginEvent $event){
            
    $event->getPlayer()->teleport($this->getServer()->getDefaultLevel()->getSafeSpawn());
            
    $this->getServer()->dispatchCommand($event->getPlayer(), "rules");
        }

    }
    So once the line of code you told me to put my code will look like this:
     
  5. Zach1603

    Zach1603 Spider Jockey

    Messages:
    27
    GitHub:
    zedstar16
    Yes, also I would recommend using PlayerJoinEvent as it gets called when the player gets onto the server instead of PlayerLoginEvent which is called before the player is on the server
     
  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.