Помогите с FloatingText

Проблема в том что мне нужен спавн текста только в одном мире, и чтобы в другом мире он не появлялся, но FloatingText не привязывается к мирам, и я пытался удалять и создавать текста при телепортациях по мирам, даже использовал ГПТ, но не получилось ничего. Текст то появляется при переходе в мир “spawn” но когда телепортируюсь обратно в мир “world” то текст никуда не исчезает.

Код
<?php

namespace ItemText;

use pocketmine\plugin\PluginBase;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\event\entity\EntityTeleportEvent;
use pocketmine\Player;
use pocketmine\utils\Config;
use pocketmine\math\Vector3;
use pocketmine\level\particle\FloatingTextParticle;
use pocketmine\network\mcpe\protocol\AddItemActorPacket;
use pocketmine\network\mcpe\protocol\RemoveActorPacket;
use pocketmine\entity\Entity;
use pocketmine\item\Item;
use pocketmine\scheduler\Task;

class Main extends PluginBase implements Listener {

    public Config $config;

    public array $itemEntities = [];

    public function onEnable(): void {
        if (!$this->getServer()->isLevelLoaded("spawn")) {
            $this->getServer()->loadLevel("spawn");
        }

        @mkdir($this->getDataFolder());

        $this->config = new Config(
            $this->getDataFolder() . "config.yml",
            Config::YAML,
            [
                "Texts" => [
                    [
                        "Coordinates" => "0 65 0",
                        "Text" => "Привет\n{player}",
                        "ItemId" => 266
                    ]
                ]
            ]
        );

        $this->getServer()->getPluginManager()->registerEvents($this, $this);
    }

    /* ================= ПОКАЗ ================= */

    public function show(Player $player): void {
        $spawn = $this->getServer()->getLevelByName("spawn");
        if ($spawn === null || $player->getLevel() !== $spawn) {
            return;
        }

   
        $this->hideFromSpawn($player);

        foreach ($this->config->get("Texts") as $data) {
            if (!isset($data["Coordinates"], $data["Text"])) {
                continue;
            }

            $coords = explode(" ", $data["Coordinates"]);
            if (count($coords) !== 3) {
                continue;
            }

            $x = (float) $coords[0];
            $y = (float) $coords[1];
            $z = (float) $coords[2];

            $yBase = $y + 1.25;

            $lines = preg_split(
                "/\\n/",
                str_replace('\n', "\n", (string) $data["Text"])
            );

            $lineCount = count($lines);
            $lineHeight = 0.27;

            foreach ($lines as $index => $line) {
                $line = str_replace("{player}", $player->getName(), $line);

                $yPos = $yBase + ($lineCount - $index - 1) * $lineHeight;

                $particle = new FloatingTextParticle(
                    new Vector3($x, $yPos, $z),
                    "",
                    $line
                );

            
                $spawn->addParticle($particle, [$player]);
            }

     
            $runtimeId = Entity::$entityCount++;

            $this->itemEntities[$player->getId()][] = [
                "id" => $runtimeId
            ];

            $itemId = (int) ($data["ItemId"] ?? 266);

            $pk = new AddItemActorPacket();
            $pk->entityRuntimeId = $runtimeId;
            $pk->entityUniqueId  = $runtimeId;
            $pk->item            = Item::get($itemId, 0, 1);
            $pk->position        = new Vector3($x, $y - 1, $z);
            $pk->motion          = new Vector3(0, 0, 0);

            $player->dataPacket($pk);
        }
    }

    public function hideFromSpawn(Player $player): void {
        $spawn = $this->getServer()->getLevelByName("spawn");
        if ($spawn === null) {
            return;
        }

        foreach ($this->config->get("Texts") as $data) {
            if (!isset($data["Coordinates"], $data["Text"])) {
                continue;
            }

            $coords = explode(" ", $data["Coordinates"]);
            if (count($coords) !== 3) {
                continue;
            }

            $x = (float) $coords[0];
            $y = (float) $coords[1];
            $z = (float) $coords[2];

            $yBase = $y + 1.25;

            $lines = preg_split(
                "/\\n/",
                str_replace('\n', "\n", (string) $data["Text"])
            );

            $count = count($lines);
            $height = 0.27;

            for ($i = 0; $i < $count; $i++) {
                $yPos = $yBase + ($count - $i - 1) * $height;

                $spawn->addParticle(
                    new FloatingTextParticle(
                        new Vector3($x, $yPos, $z),
                        "",
                        ""
                    ),
                    [$player]
                );
            }
        }

        foreach ($this->itemEntities[$player->getId()] ?? [] as $data) {
            $pk = new RemoveActorPacket();
            $pk->entityUniqueId = $data["id"];
            $player->dataPacket($pk);
        }

        unset($this->itemEntities[$player->getId()]);
    }


    public function onJoin(PlayerJoinEvent $event): void {
        $player = $event->getPlayer();

        $this->getScheduler()->scheduleDelayedTask(
            new class($this, $player) extends Task {
                public Main $plugin;
                public Player $player;

                public function __construct(Main $plugin, Player $player) {
                    $this->plugin = $plugin;
                    $this->player = $player;
                }

                public function onRun(int $currentTick): void {
                    if ($this->player->isOnline()) {
                        $this->plugin->show($this->player);
                    }
                }
            },
            40
        );
    }

    public function onQuit(PlayerQuitEvent $event): void {
        $this->hideFromSpawn($event->getPlayer());
    }

    public function onTeleport(EntityTeleportEvent $event): void {
        $player = $event->getEntity();
        if (!$player instanceof Player) {
            return;
        }

        $spawn = $this->getServer()->getLevelByName("spawn");
        if ($spawn === null) {
            return;
        }

  
        if ($event->getFrom()->getLevel() === $spawn) {
         
            $this->getScheduler()->scheduleDelayedTask(
                new class($this, $player) extends Task {
                    private Main $plugin;
                    private Player $player;

                    public function __construct(Main $plugin, Player $player) {
                        $this->plugin = $plugin;
                        $this->player = $player;
                    }

                    public function onRun(int $tick): void {
                        if ($this->player->isOnline()) {
                            $this->plugin->hideFromSpawn($this->player);
                        }
                    }
                },
                1
            );
        }


        $this->getScheduler()->scheduleDelayedTask(
            new class($this, $player) extends Task {
                private Main $plugin;
                private Player $player;

                public function __construct(Main $plugin, Player $player) {
                    $this->plugin = $plugin;
                    $this->player = $player;
                }

                public function onRun(int $tick): void {
                    if (!$this->player->isOnline()) {
                        return;
                    }

                    $spawn = $this->plugin->getServer()->getLevelByName("spawn");
                    if ($spawn !== null && $this->player->getLevel() === $spawn) {
                        $this->plugin->show($this->player);
                    }
                }
            },
            1
        );
    }
}

Какой ужас

знаю xD

Уже ненадо, решил,

кому интересно - через setInvisible()

Какой ужас что кто-то реально вспомнил про эту новеллу

Нет, просто аватарка понравилась)

Зачем через setInvisible. Вот в ядро закинь этот через setEntityID и getEntityId’

use pocketmine\\entity\\Entity;
use pocketmine\\item\\Item;
use pocketmine\\math\\Vector3;
use pocketmine\\network\\mcpe\\protocol\\AddPlayerPacket;
use pocketmine\\network\\mcpe\\protocol\\RemoveEntityPacket;
use pocketmine\\utils\\UUID;
use pocketmine\\level\\particle\\Particle;

class FloatingTextParticle extends Particle {
//TODO: HACK!


protected $text;
protected $title;
protected $entityId;
protected $invisible = false;

/**
 * @param Vector3 $pos
 * @param string  $text
 * @param string  $title
 */
public function __construct(Vector3 $pos, $text, $title = ""){
	parent::__construct($pos->x, $pos->y, $pos->z);
	$this->text = $text;
	$this->title = $title;
}

public function setEntityId($id) {
    $this->entityId = $id;
}

public function getEntityId() {
    return $this->entityId;
}

/**
 * @return int
 */
public function getText(){
	return $this->text;
}

/**
 * @return string
 */
public function getTitle(){
	return $this->title;
}

/**
 * @param $text
 */
public function setText($text){
	$this->text = $text;
}

/**
 * @param $title
 */
public function setTitle($title){
	$this->title = $title;
}

/**
 * @return bool
 */
public function isInvisible(){
	return $this->invisible;
}

/**
 * @param bool $value
 */
public function setInvisible($value = true){
	$this->invisible = (bool) $value;
}

/**
 * @return array
 */
public function encode(){
	$p = [];

	if($this->entityId === null){
		$this->entityId = Entity::$entityCount++;
	}else{
		$pk0 = new RemoveEntityPacket();
		$pk0->eid = $this->entityId;

		$p[] = $pk0;
	}

	if(!$this->invisible){
		$pk = new AddPlayerPacket();
		$pk->uuid = UUID::fromRandom();
		$pk->username = $this->title;
		$pk->eid = $this->entityId;
		$pk->x = $this->x;
		$pk->y = $this->y - 0.50;
		$pk->z = $this->z;
		$pk->item = Item::get(Item::AIR);
		$flags = (
			(1 << Entity::DATA_FLAG_CAN_SHOW_NAMETAG) |
			(1 << Entity::DATA_FLAG_ALWAYS_SHOW_NAMETAG) |
			(1 << Entity::DATA_FLAG_IMMOBILE)
		);
		$pk->metadata = [
			Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG, $flags],
			Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, $this->title . ($this->text !== "" ? "\n" . $this->text : "")],
			Entity::DATA_SCALE => [Entity::DATA_TYPE_FLOAT, 0],
		];

		$p[] = $pk;
	}

	return $p;
}
}

Понял

Это из litecore todo я не убрал. Я просто модифицировал его чтобы легко было пользоваться.

Чуть позже протестируюу, а так галочку дам сразу

Модифицировал что?