Im planning to make a JoinTitle plugin for my server But Since Im a beginner,I dont know what to do next Can someone pls help me what to do next PHP: <?phpnamespace creepermonster\jointitlepe;use pocketmine\plugin\PluginBase;class Main extends PluginBase{ public function onLoad(){ $this->getLogger()->info("JoinTitlePE Loading"); } public function onEnable(){ $this->getLogger()->info("JoinTitlePE Enabled"); } public function onDisable(){ $this->getLogger()->info("JoinTitlePE Disabled"); }
Hello, CreeperMonster. As you want send a message when a player join, you must use a Event. To use events, you'll need a event listener. This time we are going to use your main class as Listener, simply implement Listener class in your Main class. PHP: class Main extends PluginBase implements Listener {// code} You must register events to tell PocketMine where are you going to handle the events. You can do this onEnable function. PHP: class Main extends PluginBase implements Listener{ public function onLoad(){ $this->getLogger()->info("JoinTitlePE Loading"); } public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getLogger()->info("JoinTitlePE Enabled"); } public function onDisable(){ $this->getLogger()->info("JoinTitlePE Disabled"); } Now you can handle events on your Main class. As you want add a title when a player join, you can use PlayerJoinEvent. PHP: public function onJoin(PlayerJoinEvent $event) { $event->getPlayer()->addTitle("This is a title", "This is a subtitle");}
However, just doing this will not show the title as the player joins. You must schedule a delayed task and then proceed to sending the title.
no task needed https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/Player.php#L3142 $event->getPlayer()->addTitle("title, "subtitle", /*fadeIn*/, /*DURATION*/, /*fadeOut*/);
True, the duration can be set fro how long the title should stay on the user's screen, however, that doesn't actually add the title AFTER the player joins. It only appears when the player is able to see it, but the title is sent before the player joins which can cause other issues aswell(citation needed)
i made a task for it and set the time to 0, basically the same thing as noting and it still worked , delayed task ofc
@CreeperMonster Here use this. PHP: public function onJoinTitle(PlayerJoinEvent $ev){ $ev = $ev->getPlayer(); $ev->addTitle("Text here", "sub-title here", "fade-in", "duration", "fade-out");}