Solved Error when trying to spawn custom armorstand

Discussion in 'Spigot Plugin Development' started by Xurvold, Jul 2, 2021.

  1. Hello I am running into an issue when trying to spawn a custom armorstand.

    The MyArmorStand class is just a class extending EntityArmorstand

    This is the error
    [14:33:48 WARN]: java.lang.Throwable: [ERROR] Illegal PlayerChunkMap::addEntity for world world: MyArmorStand_1_16_R3['Vehicle'/176, uuid='3ee51d03-a406-4616-ab99-8b8d9dded052', l='ServerLevel[world]', x=123.00, y=74.00, z=254.00, cx=7, cz=15, tl=0, v=true, d=false] ALREADY CONTAINED (This would have crashed your server)
    [14:33:48 WARN]: at net.minecraft.server.v1_16_R3.PlayerChunkMap.addEntity(
    [14:33:48 WARN]: at net.minecraft.server.v1_16_R3.ChunkProviderServer.addEntity(
    [14:33:48 WARN]: at net.minecraft.server.v1_16_R3.WorldServer.registerEntity(
    [14:33:48 WARN]: at net.minecraft.server.v1_16_R3.WorldServer.addEntity0(
    [14:33:48 WARN]: at net.minecraft.server.v1_16_R3.WorldServer.addEntity(
    [14:33:48 WARN]: at me.aaron.testvehicles.R3_1_16.implementations.MyArmorStand_1_16_R3.<init>(
    [14:33:48 WARN]: at me.aaron.testvehicles.R3_1_16.implementations.ArmorStandManager_1_16_R3.lambda$null$1(
    [14:33:48 WARN]: at
    [14:33:48 WARN]: at org.bukkit.craftbukkit.v1_16_R3.scheduler.CraftScheduler.mainThreadHeartbeat(
    [14:33:48 WARN]: at net.minecraft.server.v1_16_R3.MinecraftServer.w(
    [14:33:48 WARN]: at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$a$0(
    [14:33:48 WARN]: at java.base/

    line 49 is this: world.addEntity(this);
    I noticed it has to do with apparently the UUID already being used, any idea how come? I am not giving it a uuid anywhere. Paper is generating the uuid itself.
    #1 Xurvold, Jul 2, 2021
    Last edited: Jul 2, 2021
  2. Please post the full code of the method. It is difficult to check the error with that code alone.
  3. World#addEntity is an nms method, not a custom one.
  4. I said. Please provide the full code. world.addEntity(); You just can't know. Do you think we are smart?
  5. Nothing much here, it's just a class extending EntityArmorstand
  6. This entity is already in the world and you’re trying to add it again. If you’re using paper you should go seek help there cause I’m pretty sure this works with spigot.
  7. I already know it has to do with the entity somehow already existing (bottom of original post), I am just trying to figure out why. Because if I don't add it to the world the entity doesn't show up. Now I need to kill all entities before I can spawn a new entity of MyArmorStand.

    And when running Spigot it produces a similar exception so it has nothing to do with Paper.

    java.lang.IllegalStateException: Entity is already tracked!
    at net.minecraft.server.v1_16_R3.PlayerChunkMap.addEntity( ~[server.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.ChunkProviderServer.addEntity( ~[server.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.WorldServer.registerEntity( ~[server.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.WorldServer.addEntity0( ~[server.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.WorldServer.addEntity( ~[server.jar:2991-Spigot-018b9a0-f3f3094]
    at me.aaron.testvehicles.R3_1_16.implementations.MyArmorStand_1_16_R3.<init>( ~[?:?]
    at me.aaron.testvehicles.R3_1_16.implementations.ArmorStandManager.lambda$null$1( ~[?:?]
    at ~[server.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.craftbukkit.v1_16_R3.scheduler.CraftScheduler.mainThreadHeartbeat( ~[server.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.MinecraftServer.b( ~[server.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.DedicatedServer.b( ~[server.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.MinecraftServer.a( ~[server.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.MinecraftServer.w( ~[server.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$0( ~[server.jar:2991-Spigot-018b9a0-f3f3094]
    at [?:1.8.0_292]
  8. This stacktrace is still related to your main issue: the entity already exist with this uuid
  9. Yeah I already knew that. The question was if anyone knew why.
  10. Have you tried moving the World#addEntity outside of the entity constructor? I've had some problems with that in the past, you could give it a try
  11. Nope didn't change anything, still getting the same error
  12. Okay, so I tried to reproduce your issue on 1.16.5 with the following code:
    Code (Java):
    import net.minecraft.server.v1_16_R3.EntityArmorStand;
    import net.minecraft.server.v1_16_R3.World;
    import org.bukkit.Location;

    public class MyArmorStand extends EntityArmorStand {
        public MyArmorStand(World world, Location location) {
            super(world, location.getX(), location.getY(), location.getZ());

    Code (Java):
    import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;

    public class PlayerJoinListener implements Listener {

        private final TestPlugin plugin;

        public PlayerJoinListener(TestPlugin plugin) {
            this.plugin = plugin;

        public void onPlayerJoin(PlayerJoinEvent event) {
            new MyArmorStand(((CraftWorld) event.getPlayer().getWorld()).getHandle(), event.getPlayer().getLocation());

    The armor stand spawned without any issues, is it possible that you call the addEntity method twice, as this would explain the double add with the same uuid?
  13. After you restart the server does it still spawn the entity without any errors? Because I can spawn it once, but after a restart the error will appear each time I try to spawn the entity. And I am 1000% sure I am not calling addEntity twice.
  14. Yup, works like a charm, two joins without a restart and two joins with a restart in between - Could you share your complete source? If its confidential, you can send it via DM if you are more comfortable with that.
  15. Barely anything, which is why I am so confused about the error
  16. Based on the stacktrace:

    This is not everything at all
  17. MyArmorStand contained a lot of commented out code which I didn't include in the pastebin, and removed the ArmorStandManager class after the latest exception to see if it would change anything.
  18. What if you only use the code i sent you? Does it work then?
    If so, the error is in your code - Otherwise try to update the spigot version, maybe some kind of broken build?
  19. Managed to fix it.