So in a LobbyCore plugin I'm making, I made it so when the plugin enables, it creates a NBT like so: PHP: $querypvp = PMQuery::query("ip", 30000); $kitpvp = (int) $querypvp['Players']; $nbt = Entity::createBaseNBT(new Vector3(0.5, 86, 18.5)); $npc1 = new Villager($level, $nbt); $npc1->setNameTag(TextFormat::BOLD . TextFormat::GOLD . "KitPvP\n" . TextFormat::GREEN . "Online: " . $kitpvp); $npc1->setNameTagVisible(true); $npc1->lookAt(new Vector3(0, 86, 0)); $npc1->spawnToAll(); The problem with this is that it will always spawn the Entity whenever it's enabled, making multiple entities. I tried the following (I started to use everything since I started getting annoyed lol): PHP: foreach($level->getEntities() as $entity){ $entity->flagForDespawn(); $entity->setHealth(0); $entity->kill(); $entity->despawnFromAll(); $entity->close(); } Can anyone help me? Thanks in advance!
Ok, so basiclly, the first time the plugin is enabled, it creates the Entity and puts it in the position. That's why when it enables again, I want it to remove all the entities that are currently in place, and then make the same entity again, that way, there is only one entity.
Im guessing the entity was saved in the chunks, to prevent that simply PHP: $entity->setCanSaveWithChunk(false); Note that if the chunk is not a spawn chunk and was unloaded, the entity will disappear Another way will be to save the entity somewhere in the plugin and remove the entity onDisable