Holographic Displays per player holograms

Status
This thread has been locked.

mxnny

Premium
Feedback score
4
Posts
205
Reactions
69
Resources
0
Alright running into problems with HolographicDisplays when I tried making per player holograms, not sure why this wouldn't be working.

Currently using the latest version of HolographicDisplays on the server (2.4.4) and the server spigot is 1.8 based (Custom SportPaper fork).
There are no errors in console.

I originally tried to do it this way, which didn't work.
Code:
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        Location location = ...
        JavaPlugin plugin = ...

        Hologram hologram = HologramsAPI.createHologram(plugin, location);
        hologram.getVisibilityManager().setVisibleByDefault(false);

        hologram.appendTextLine(ChatColor.GREEN + "Your Stats: " + event.getPlayer().getName());

        hologram.getVisibilityManager().showTo(event.getPlayer());
    }

Then tried to do it this way by storing it in a HashMap and looping through the Holograms to hide them for all online players and showing the player's hologram to them and the hide it to other players online, but this didn't work either.
Code:
    private final Map<UUID, Hologram> holograms = new HashMap<>();

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        Location location = ...
        JavaPlugin plugin = ...

        Hologram hologram = HologramsAPI.createHologram(plugin, location);

        hologram.appendTextLine(ChatColor.GREEN + "Your Stats: " + event.getPlayer().getName());

        Bukkit.getOnlinePlayers().forEach(player -> hologram.getVisibilityManager().hideTo(player));
        holograms.values().forEach(loopHologram -> loopHologram.getVisibilityManager().hideTo(event.getPlayer()));
        hologram.getVisibilityManager().showTo(event.getPlayer());
        holograms.put(event.getPlayer().getUniqueId(), hologram);
    }

If anyone could help would highly appreciate it :) Thanks
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Gatopansi

Premium
Feedback score
2
Posts
0
Reactions
28
Resources
0
I did this to fix this issue:
Code:
holo.getVisibilityManager().setVisibleByDefault(false);
holo.getVisibilityManager().resetVisibilityAll();
holo.getVisibilityManager().showTo(getPlayer());

Put that code before appending the text line. Not sure if the resetting is required, but it was there in the version that worked so didn't remove it.
 

mxnny

Premium
Feedback score
4
Posts
205
Reactions
69
Resources
0
I did this to fix this issue:
Code:
holo.getVisibilityManager().setVisibleByDefault(false);
holo.getVisibilityManager().resetVisibilityAll();
holo.getVisibilityManager().showTo(getPlayer());

Put that code before appending the text line. Not sure if the resetting is required, but it was there in the version that worked so didn't remove it.
Code:
           Hologram hologram = HologramsAPI.createHologram(managerHandler.getPlugin(), location);

            hologram.getVisibilityManager().setVisibleByDefault(false);
            hologram.getVisibilityManager().resetVisibilityAll();
            hologram.getVisibilityManager().showTo(event.getPlayer());

            hologram.appendTextLine(CC.LINE + "-----------------------------------");
            hologram.appendTextLine(CC.translate("&bYour Stats: &e" + event.getPlayer().getName()));
            hologram.appendTextLine(CC.LINE + "-----------------------------------");

            holograms.put(event.getPlayer().getUniqueId(), hologram);

This is what I have in right now, still not working though.
 

mxnny

Premium
Feedback score
4
Posts
205
Reactions
69
Resources
0
Do you have ProtocolLib? It's required for that function.
No I haven't put in ProtocolLib. I'll test with it in right now.[DOUBLEPOST=1599473393][/DOUBLEPOST]Put in ProtocolLib but it is still the same, all the holograms are stacking on top of each other.
 
Last edited:

domninos

Feedback score
1
Posts
74
Reactions
4
Resources
1
No I haven't put in ProtocolLib. I'll test with it in right now.[DOUBLEPOST=1599473393][/DOUBLEPOST]Put in ProtocolLib but it is still the same, all the holograms are stacking on top of each other.
It should work because ProtocolLib is what you need if you want to make a per-player holorams. Not sure if you're already removing them on quit but you should delete the hologram / remove uuid of player from map since you're creating a new one every time they join.

I am not sure what you're trying to do but if you just want to show numbers, you can use PlaceholderAPI's way. Register the placeholder to PlaceHolderAPI. (I used MVdWPlaceholderAPI for this!)
Code:
        PlaceholderAPI.registerPlaceholder(plugin, "stats_kills", (event) -> {
            if (event.isOnline()) {
                // return the kills from online player
            } else {
                // return the kills from an offline player
            }

            return "0";
        });

Then register it to HolographicDisplays. (You need those { } if I remember correctly.)
Code:
        RelativePlaceholder.register(new RelativePlaceholder("{stats_kills}") {
            @Override
            public String getReplacement(Player player) {
                return player != null ? // player is online : "0";
            }
        });

Then proceed to create your holograms using the registered placeholder.

NOTE: I believe they only update if you:
  1. Die and/or respawn.
  2. Join the server.
Also, MVdWPlaceholderAPI uses { } as its 'format', I'm not sure if it's the same for when you're using PlaceholderAPI. But if it doesn't work, use the usual % format.

This is tested on 1.8, with MVdWPlaceholderAPI. Not sure if it works on the newer versions.
 
Last edited:

mxnny

Premium
Feedback score
4
Posts
205
Reactions
69
Resources
0
It should work because ProtocolLib is what you need if you want to make a per-player holorams. Not sure if you're already removing them on quit but you should delete the hologram / remove uuid of player from map since you're creating a new one every time they join.

I am not sure what you're trying to do but if you just want to show numbers, you can use PlaceholderAPI's way. Register the placeholder to PlaceHolderAPI. (I used MVdWPlaceholderAPI for this!)
Code:
        PlaceholderAPI.registerPlaceholder(plugin, "stats_kills", (event) -> {
            if (event.isOnline()) {
                // return the kills from online player
            } else {
                // return the kills from an offline player
            }

            return "0";
        });

Then register it to HolographicDisplays. (You need those { } if I remember correctly.)
Code:
        RelativePlaceholder.register(new RelativePlaceholder("{stats_kills}") {
            @Override
            public String getReplacement(Player player) {
                return player != null ? // player is online : "0";
            }
        });

Then proceed to create your holograms using the registered placeholder.

NOTE: I believe they only update if you:
  1. Die and/or respawn.
  2. Join the server.
Also, MVdWPlaceholderAPI uses { } as its 'format', I'm not sure if it's the same for when you're using PlaceholderAPI. But if it doesn't work, use the usual % format.

This is tested on 1.8, with MVdWPlaceholderAPI. Not sure if it works on the newer versions.
Yeah I am removing them from the HashMap and I am deleting the hologram on quit. For the holograms I am having more than just a bunch of numbers thats why I tried using HolographicDisplays to do it, however, didn't work. I tried using "HolosAPI" but that plugin is too old and is only compatible with 1.7.
 

mxnny

Premium
Feedback score
4
Posts
205
Reactions
69
Resources
0
If anyone still needs this I am now using helper by Luck. Only downside is that it depends on ProtocolLib but other than that it should be fine. Works really well and all the hiding works perfectly.

https://github.com/lucko/helper
 
Status
This thread has been locked.
Top