how do i spawn floatingTexts in one world only? or maybe 2? PHP: public function onPlayerJoin(PlayerJoinEvent $event){ $player = $event->getPlayer(); $level = $player->getLevel(); $vector = new Vector3(60, 60, 60); $level->addParticle(new FloatingTextParticle($vector, "Test")); }
i tried PHP: $level = $this->getServer()->getLevelByName("mines"); $player = $event->getPlayer(); $vector = new Vector3(60, 60, 60); $level->addParticle(new FloatingTextParticle($vector, "Test")); but for some reason the texts spawns in all worlds ;/
this is a known problem. you can work around it by despawning the FTPs to players that are not in the world. A very crappy and bad example is my FTP plugin which does this, but i wrote that 2yrs ago and was just learning php back then. But if it helps, here it is:
This might help you! PHP: const REMOVE_TEXT_PACKET = 0;const ADD_TEXT_PACKET = 1;private $floatingTextLevelId = -1;/** @var Position $pos */$particle = new FloatingTextParticle($pos, "Test");$this->floatingTextLevelId = $pos->getLevel()->getId();$packets = $particle->encode();/** * @param EntityLevelChangeEvent $e * @priority HIGH * @ignoreCancelled true */public function onLevelChange(EntityLevelChangeEvent $e){ $entity = $e->getEntity(); if($entity instanceof Player){ if($e->getOrigin()->getId() === $this->floatingTextLevelId){ $entity->dataPacket($packets[self::REMOVE_TEXT_PACKET]); }elseif($e->getTarget()->getId() === $this->floatingTextLevelId){ $entity->dataPacket($packets[self::ADD_TEXT_PACKET]); } }} Explanation: The floating text is constructed using Position instead of Vector3 and the Position's levelId is cached to a class property $floatingTextLevelId. FloatingTextParticle::encode() returns 2 packets enclosed in an array. The first being RemoveEntityPacket and the second one - AddEntityPacket. On EntityLevelChangeEvent, we first check whether the entity is a player to avoid unnecessary checks and errors while calling dataPacket() function. If the origin level is same as the floating text's level, then that means the player is leaving the floating text's level. If the target level is the same as the floating text's level, then that means the player is teleporting to the floating text's level.