ArmorStand Hologram Disappearing - setRemoveWhenFarAway(false) Not working?

Discussion in 'Spigot Plugin Development' started by unenergizer, May 1, 2017.

  1. Hi,

    I have some code that will spawn a "Hologram" or invisible ArmorStand. The code works great, and the entities spawn. However, if you teleport away, the hologram disappears. I installed a plugin that would keep the chunk the hologram was in loaded to see if that was the problem, but this did not work either.

    I am hoping someone can point me to a solution to the problem. The armorstand spawning code is this...

    Code (Text):
         * This will spawn an armor stand with a hologram type setup.
         * @param name     The name to display over the hologram.
         * @param location The location to spawn the hologram.
         * @return Returns the generated entity.
        private ArmorStand spawnArmorStand(String name, Location location) {
            String worldName = location.getWorld().getName();
            ArmorStand stand = (ArmorStand) Bukkit.getWorld(worldName).spawnEntity(location, EntityType.ARMOR_STAND);

            //Setup armor stand.

            //Set the armor stands name.

            return stand;
    Thank you for the help!

    Edit: using Spigot-API 1.11.2-R0.1-SNAPSHOT
    #1 unenergizer, May 1, 2017
    Last edited: May 1, 2017
  2. Try setting the PersistanceRequired nbt tag to 1.
  3. I have googled many different searches to figure out how to add NBT tags to an entity. Most results are from 2015ish and not reliant. I know how to add NBT tags to items, using itemFlags, but I don't see such a method for entities.

    Searches used:
    • spigot set nbt tag
    • spigot PersistanceRequired
    • spigot PersistenceRequired (spelling change)
    • spigot armor stand disappeared
    • spigot armor stand despawning

    Could you perhaps give a clue on how to implement this? I have googled other hologram plugins and reviewed some of their code, but it seem some of these plugins are having the same issue.

    Thank you for your help!

    EDIT: The only other way I know to work around this is to heavily change my code. I can save the armorStand locations to a file, on ChunkLoad check if a hologram is inside that chunk, if it is, then I can spawn the hologram. When ChunkUnload happens, I can despawn/remove reference in my code. Then we just wait until the chunk is loaded again and respawn. While also adding in some check to see if the location is a match, check to see if entity with X name exists and if it does, don't recreate it. However while this is not difficult to implement, I would much prefer to not do this. It would be ideal if the hologram just stayed in when spawned.
    #3 unenergizer, May 2, 2017
    Last edited: May 2, 2017
  4. What? How do you think hologram is affected by PersistenceRequired....

    1. Have you tested with no other plugin on your testing server?
    2. Try something like world.getEntities() and see if those armor stand are there but not shown.
    3. /gamemode 3 and see whether some invisible armor stand are messed up (gamemode 3 will show invisible armorstand even it is a marker).
  5. 1. Yes. The only hologram code is what I have written.
    2. No problem, code for this already exists to check entities in my plugin. Image will be pasted below.
    3. I have gone into gamemode 3 to see if they disappear, and they do. I am coming here as a last resort, not the first one.


    In the image above, I login to the server before the armor stands are generated. Then when they were, I took the first screen shot. Afterwards I logged out and then logged back in. You can see the time difference on the "Server Up Time" line.

    This is the code that loop's through all entities and determines if they are armor stands.

    Code (Text):
    //Get the number of living entities.
                        for (Entity entity : ((Player) commandSender).getWorld().getEntities()) {
                            if (entity instanceof LivingEntity) {
                                if (!(entity instanceof Player)) {
                                    if (entity instanceof ArmorStand) {
                                } else {
    // snip
    Note: The //snip is some other code that is not related to this question, so it was removed.
  6. i would make a config where it stores the displayname and location and world for each armor stand and make a playerTeleport/playerWalkEvent depending on whether the player teleports or walks and check if there location is in there veiw distance radius and spawn it in, and when its not despawn it. And have a check to make sure if more than one player do the same thing so more than 1 dont spawn
    #6 xPlumpOrange, May 2, 2017
    Last edited: May 2, 2017
  7. Yes this is a possibility. It is a similar fix as one I mentioned in post #3 after the "EDIT:" text. While this may work, I would prefer the ArmorStand to be persistent. I am trying to avoid doing the location checks as this is increased CPU work versus the ArmorStand just being there.

    If anyone has any other ideas, I am all ears! :)

    Thanks for the help!
    • Like Like x 1
  8. #8 unenergizer, May 4, 2017
    Last edited: May 4, 2017
  9. I know this is a necro, but, I'm having the same problem now with the same version and all and want to know how you fixed it. I probably won't be the last person to encounter this either.