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: <?phpnamespace 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()); }}
dispatchCommand is probably your friend here What are you trying to do with the command? This might be a case of http://xyproblem.info
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");
PHP: <?phpnamespace 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:
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