Update holograms

Discussion in 'Spigot Plugin Development' started by iNoXs, Jun 11, 2018.

  1. Hello !

    im trying to update per player hologram like every second

    Code (Text):
        public void spawnHolo(Location location, Player p) {
            if (plugin.getUtils().getPlayerConfig(p.getName()) == null) {
                return;
            }
            if(api != null){
                api.destroy(p);
            }

            if (!plugin.getUtils().playerHaveKit(plugin.getUtils().getDay(), plugin.getUtils().getPlayerConfig(p.getName()).getPlayerConfig())) {
                api = HoloAPI.newInstance(location, Arrays.asList("text", "text"));
                api.display(p);
            } else {
                api = HoloAPI.newInstance(location, Arrays.asList("text", "text", plugin.getUtils().getTime()));
                api.display(p);
            }
        }

        public void refresh(Location location) {
            for (Player p : Bukkit.getServer().getOnlinePlayers()) {
                Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                    @Override
                    public void run() {
                        spawnHolo(location,p);
                    }
                }, 20L, 20L);
            }
        }
    Im using this API https://www.spigotmc.org/threads/class-holograms-in-1-8.40625/

    if i try this :
    Code (Text):
    Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                    @Override
                    public void run() {
                        refresh(loc)
                    }
                }, 20L, 20L);
           
    it keep creating more and more holograms when there is more than 1 player in the server

    thanks for help

    sorry for my bad english
     
  2. up up up i realy need help pls
     
  3. From what I can tell, your "refresh" method is simply calling "spawnHolo" over and over. Nowhere do you remove the existing one. This may be your issue.
     
    • Agree Agree x 1
  4. i remove the hologram via api.destroy(p);
     
  5. well, if that's the case, the only thing possible is either the api.destroy() method is not functioning and should be brought to the API's author's attention, or the api is becoming null between when you call these methods.
     
  6. the method is working, my probleme is when there is more than 2 player in the server the hologram keep spawning however when there is only one player in the server the code work perfectly fine :)
     

Share This Page