Solved Hologram rename not visible for all players

Discussion in 'Spigot Plugin Development' started by unenergizer, Jun 9, 2017.

  1. Hello all,

    I have some code that updates a holograms (armor stand) name. However, this rename is not visible to all players online. It is quite odd... Is there anything that would make this happen?

    Info:
    Only two holograms exist. Created all at one time. They are not hidden/show individually per player.

    Here is a video.


    If you know why this might happen, please let me know! Thanks!

    Hologram Code:
    Code (Text):
    package com.forgestorm.mgf.util.display;

    import lombok.Getter;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.entity.ArmorStand;
    import org.bukkit.entity.EntityType;

    import java.util.ArrayList;
    import java.util.List;

    @Getter
    public class Hologram {

        private final ArrayList<ArmorStand> armorStands;

        public Hologram() {
            armorStands = new ArrayList<>();
        }

        /**
         * Creates a hologram with the given text at a given location.
         * @param name The text to display in the hologram.
         * @param location The location to spawn the hologram.
         */
        public void createHologram(String name, Location location) {
            //Create armor stand and save it.
            armorStands.add(spawnArmorStand(name, location));
        }

        /**
         * Creates a hologram with the given text at a given location.
         * @param name The text to display in the hologram.
         * @param location The location to spawn the hologram.
         */
        public void createHologram(List<String> name, Location location) {

            double spotsMovedDown = 0;

            //Create armor stand and save it.
            for (String hologramName : name) {
                Location adjustedLocation = new Location(location.getWorld(), location.getX(), location.getY() - spotsMovedDown, location.getZ());
                armorStands.add(spawnArmorStand(hologramName, adjustedLocation));

                spotsMovedDown += .3;
            }
        }

        /**
         * 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.
            stand.setSmall(true);
            stand.setBasePlate(false);
            stand.setCanPickupItems(false);
            stand.setCollidable(false);
            stand.setGravity(false);
            stand.setInvulnerable(true);
            stand.setVisible(false);

            //Set the armor stands name.
            stand.setCustomName(color(name));
            stand.setCustomNameVisible(true);

            return stand;
        }

        /**
         * This will completely remove and despawn a hologram.
         */
        public void removeHolograms() {
            //Loop through and delete hologram entities.
            for (ArmorStand armorStand : armorStands) {
                armorStand.remove();
            }

            //Clear array holograms.
            armorStands.clear();
        }

        private String color(String msg) {
            return ChatColor.translateAlternateColorCodes('&', msg);
        }

    }
     
    New hologram and hologram rename code..
    Code (Text):
    private final Map<Team, Hologram> teamHolograms = new HashMap<>();

        /**
         * Update holograms after a queue update or a team join.
         */
        private void updateHolograms() {
            for (Map.Entry<Team, Hologram> entry : teamHolograms.entrySet()) {
                Team team = entry.getKey();
                Hologram hologram = entry.getValue();
                int queuedCount = team.getQueuedPlayers().size();
                int currentTeamSize = team.getTeamPlayers().size();
                int maxTeamSize;

                if (team.getTeamSizes() == -1) {
                    maxTeamSize = gameManager.getMaxPlayersOnline();
                } else {
                    maxTeamSize = team.getTeamSizes();
                }

                ArmorStand players = hologram.getArmorStands().get(0);
                ArmorStand queue = hologram.getArmorStands().get(1);
                players.setCustomName(ChatColor.BOLD + "Players: " + Integer.toString(currentTeamSize) + " / " + maxTeamSize);
                queue.setCustomName(ChatColor.BOLD + "Queued Players: " + queuedCount);
            }

        }

        /**
         * Holograms are spawned above entity heads
         *
         * @param team     The team we are setting up a hologram for.
         * @param location The location to spawn the holograms.
         */
        private void spawnHolograms(Team team, Location location) {
            List<String> hologramText = new ArrayList<>();
            int queuedCount = team.getQueuedPlayers().size();
            int currentTeamSize = team.getTeamPlayers().size();
            int maxTeamSize;

            if (team.getTeamSizes() == -1) {
                maxTeamSize = gameManager.getMaxPlayersOnline();
            } else {
                maxTeamSize = team.getTeamSizes();
            }

            hologramText.add(ChatColor.BOLD + "Players: " + Integer.toString(currentTeamSize) + " / " + maxTeamSize);
            hologramText.add(ChatColor.BOLD + "Queued Players: " + queuedCount);

            Hologram hologram = new Hologram();
            hologram.createHologram(hologramText, location.add(0, 2, 0));

            teamHolograms.put(team, hologram);
        }
    NOTE:
    • spawnHolograms() is called only once per team setup. This happens one time when a minigame lobby is being setup. This call is NOT dependent on player join/quits.
    • Were not doing any custom per player packets.
     
    #1 unenergizer, Jun 9, 2017
    Last edited: Jun 9, 2017
  2. is that just a regular entity (not custom) that you spawned?

    could u show your code
     
  3. Post update with code.
     
    • Friendly Friendly x 1