1.15.2 Holographic Displays API getHolograms(plugin)

Discussion in 'Spigot Plugin Development' started by BKnight_, Mar 6, 2020.

  1. HolographicDisplays' API is a pain to work with. My current issue is that the method getHolograms(plugin) is returning only a handful of things and none of them are from the HolographicDisplays plugin itself.

    My initial call was the following because of this post and the javadocs:
    Code (Text):
    Collection<Hologram> holograms = HologramsAPI.getHolograms(Bukit.getServer().getPluginManager().getPlugin("HolographicDisplays));
    But that yielded nothing. An empty list.

    After trying a few other plugins, in the end I got frustrated and gave up and just iterated through every single plugin on the server (all 71) in order to get every single possible hologram. It looks like this:

    Code (Text):
            Plugin[] plugins = Bukkit.getServer().getPluginManager().getPlugins();
            List<Hologram> holograms = new ArrayList<>(Collections.emptyList());
            for (Plugin plugin : plugins){
                if (plugin != null){
    But that returns a collection only 10 entries long. We have 24 entries just from HolographicDisplays alone (created manually in-game), so that's excluding those created by plugins. When I then iterate through that collection to find the hologram I want, I can't find it.

    How in God's name am I suppose to retrieve all holograms? At this point, I think it'd be more optimised and quicker to just open the database.yml inside of HolographicDisplays config folder than find them using the API.

    If you're reading this HD Author; please, please just have a method that returns all holograms in a list rather than requiring a specific plugin. Keep that method, but add one that just gets them all. And let us refer to them by their ID too! It's annoying have to match specific lines just to identify the hologram I need.
  2. It looks like the person who responded to the linked thread hadn't necessarily tested the code he wrote, and his response appears to be something put together after looking at the documentation quickly but not fully understanding the API itself. The HologramsAPI#getHolograms method should get holograms from the plugin that registered them, which wouldn't be the HolographicDisplays plugin, but instead the plugin you wrote. Some quick test code I wrote in the onEnable method:
    Code (Java):
    Location location = new Location(Bukkit.getWorld("world"), -145, 72, 751);
    Hologram hologram = HologramsAPI.createHologram(this, location);
    hologram.appendTextLine("Test hologram");

    for (Hologram holo : HologramsAPI.getHolograms(this)) {
    You can see that the plugin I used in getHolograms was the same one I used when creating the hologram I'm trying to get, and this did work for me.

    Of course, if you wanted to access this from some class other than the main class, you could do something like this in the main class
    Code (Java):
    private static YourPlugin plugin;

    public static YourPlugin getInstance() {
        return plugin;
    and replace 'this' with 'YourPlugin#getInstance()'. It's not exactly the best practice to do it this way, but for Spigot plugins it's good enough.
    #2 _Silver, Mar 7, 2020
    Last edited: Mar 7, 2020
  3. HD has a pretty easy to work with API as APIs come. It isn’t the best, but I can think of several extremely poorly written APIs that are much worse than HD.

    Yes, because HD doesn’t register its own holograms created through the hd command. HD is open source, HD has its own NamedHologramManager to store its holograms so it will never register them to the API where plugins can access them without going through NamedHologramManager.

    Do your results make more sense knowing that you cannot get the holograms created by the HD commands in game?

    See above

    The point of the API is to allow plugins to create and manage their own holograms, not those of other plugins. The weakness of HD’s API is that it allows you to access any plugin’s holograms (except for HD’s). I highly doubt this was the intention of the author.
  4. You're both right. I managed to fix it by directly using HolographicDisplays' in-built, public methods that retrieve the hologram from the config rather than the API.

    I think there needs to be greater information about the API that clearly shows it's not meant for interacting with HolographicDisplays on the server but rather implementing your own holograms in your plugin.

    Also, yeah, other API's are certainly worse. I've honestly yet to find a nice to use API for any plugin in Minecraft but some are definitely better than others. Thank you both by the way, appreciate it.
  5. drives_a_ford


    I realize this has mostly been figured out by now but I thought I'd add my experience to the mix.

    I've also had the pleasure to work with the HD API and I ran into the very same issue.
    I, too ended up using some of their internal classes. I ended up using
    Code (Java):

    NamedHologram holo;
            try {
                holo = CommandValidator.getNamedHologram(args[0]);
            } catch (CommandException e) {
                // send errorr message
                return true;
    Another thing I had issues with was the fact that there is no way of knowing when these holograms become available. They don't become available at server startup. If I recall, they're loaded a tick later. Would be wonderful to have an event for that.

    With that said, given the current API doesn't seem to be meant for such things (i.e use/modifications of their own holograms) I refrained from a feature request.
  6. Hey I recently started using the holographic display api for a project am working on and I just watch your post, how did you use their internal classes on your plugin/project.
  7. drives_a_ford


    Just as you would their API. Use their plugin as a dependency.
    • Informative Informative x 1
    • Optimistic Optimistic x 1