Library Holographic Displays v2: an easy way to manage holograms (+ power ups)

Discussion in 'Resources' started by filoghost, May 19, 2014.

Thread Status:
Not open for further replies.
  1. Offline


    Holographic Displays includes a simple API for developers. Here's a tutorial on how to use it.

    Why should you use it
    • Stable, efficient and easy to use.
    • You don't have to use any NMS code.
    • Automatic chunk loading / unloading management (doesn't keep chunks loaded).
    • Always updated to support multiple Bukkit/Spigot/MCPC+/Cauldron versions.
    Let's start with the tutorial! This is what we're going to create:

    Creating an hologram is really simple and just requires a basic Bukkit knowledge. Code example:
    1. // Suppose that "player" is a Player object obtained before.
    2. Hologram hologram = HologramsAPI.createHologram(this, player.getEyeLocation());
    3. hologram.appendTextLine("This is a hologram.", ChatColor.AQUA + "Hello world!");

    The hologram is not automatically saved to disk. If you don't remove it, it will stay until server stop.

    How to use it in your plugin
    First of all, add 'softdepend' to your plugin.yml:
    softdepend: [HolographicDisplays]
    Then check if Holographic Displays is correctly installed and loaded in your onEnable():
    1. if (!Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays")) {
    2. getLogger().severe("*** HolographicDisplays is not installed or not enabled. ***");
    3. getLogger().severe("*** This plugin will be disabled. ***");
    4. this.setEnabled(false);
    5. return;
    6. }

    If Holographic Displays is not strictly needed, you can use a boolean in your plugin's instance to check if you should use holograms, and continue with the execution instead of disabling your plugin.

    Now you can just use static methods from the class HologramsAPI, as shown in the example above.

    Other tutorials (on GitHub)

    How to create icons

    How to create power ups

    Read more
    Full API tutorial: [link]
    Hologram class (javadocs): [link]
    HologramsAPI class (javadocs): [link]

    Feedback is appreciated, whether positive or negative. If I forgot something or you just need help, please let me know. Thanks for reading!
    Last edited: Dec 21, 2014
  2. Offline


    How is this better or more useful than HoloApi?
    DSH105 likes this.
  3. Offline


    More efficient (custom entities are faster than packets), easier to use API (in my opinion), more stable (all the mayor bugs were fixed 1-2 months ago), MCPC+ full support (1.6 and 1.7), used by more servers.

    Downsides: individual holograms require ProtocolLib, doesn't still support GIFs, and something else that I may not remember.
    Bammerbom and Phasesaber like this.
  4. Offline


    Does it have clickable holograms? Per player holograms?
  5. Offline


    Onlineids Touch holograms are not ready yet, but they are ~90% complete. You can have a hologram shown to one player only, but custom individual variables are not included. You must use ProtocolLib, as I did with {player} and {displayname}.
  6. Offline


    There is one simple answer to that; personal choice ;)

    HoloAPI (as the name suggests) is specifically designed to be an API. In that respect, it is more extensive and opens up plenty more opportunities for developers than you may have realised :).
  7. Can you provide evidence for your claims? Custom entities use packets + use server memory. That means they're both heavy on the client and the server. Packets however are only heavy on the client which results (or should result) in less server lag. Claiming that your entities are better than packets is the same as claiming that being hit by a (driving) car is better than being hit by a pedestrian.
  8. Offline


    By their very nature, holograms are resource-intensive. They were not intended to be used in such a way by Mojang, and many would consider it a "hack" whether you use entities or packets. Once everyone has them on their servers, I think this fad will be replaced by the newest coolest thing, but until then we are stuck with the lag.
  9. ccrama That is exactly my point. They are very resource-intensive and that is exactly why HoloAPI uses packets, which means the server has no idea the holograms are there (which results in barely/no server lag). Yes the creation of our holograms may take a bit (0.5 ticks?) longer but because the server has no idea the holograms are there, it won't care about them. With custom entities this is entirely different, the server knows there is "something" there, and runs checks and onTick() methods on it.
  10. Offline


    I've made some test, with 20 holograms in a single chunk (1 line each one). HoloAPI spent 5 millis on PlayerTeleportEvent, while HolographicDisplays lets the server handle everything. Why should the server lag, if the entities do not even tick? I think it's much more resource intensive doing calculation with players, acting like if holograms are really there. Why not let the server handle them? It runs the "onTick" method, but it's empty. An example could be:

    You have a villager, that doesn't move and when you interact it opens a custom GUI.
    You would just spawn an entity and customize it, instead of sending packets.

    CaptainBern If you want, I can make a benchmark, and see if I'm correct.

    DSH105 Yes, your API is more advanced, but usually people do not need to make complex things with holograms. For example, a minigame that handles the scores through holograms doesn't need a lot of methods, just a setLine().
  11. filoghost The methods we use to calculate where to place our holograms are also calculated by you, well by the server to be specific so that isn't a valid argument either.
    Again, please provide sources for your claims.
  12. Offline


    20 holograms for each plugin, with one line, in the same location.

    Show Spoiler


    - Start the server with the holograms already loaded.
    - /timings reset.
    - Made the chunk load 3 times.
    - Teleported to myself 3 times.
    - 1st timings test.
    - After ~10 minutes standing still and writing this post, 2nd timings test.


    First test:
    Average tick for EntityHologramWitherSkull: 0.0008 ms
    Average tick for EntityHologramHorse: 0.0003 ms

    Second test:
    Average tick for EntityHologramWitherSkull: 0.0004 ms
    Average tick for EntityHologramHorse: 0.0002 ms

    As said the tick method is (nearly) empty, and doesn't have any impact on the server.

    8.6823 ms for PlayerTeleportEvent with HoloAPI, while HolographicDisplays doesn't even have registered the event. Holographic Displays is also faster in ChunkLoadEvent and in ChunkUnloadEvent. Sending packets with Bukkit object can't be faster or more than built-in nms methods. It also refreshes the hologram on teleport even if the player is near, that is useless.

    That's why I didn't switched to packets.
  13. filoghost Mind sending me the benchmark code? Also why "Sending packets with Bukkit object can't be faster or more than built-in nms methods" ? The only thing that could slow down the packet sending is when we get the send method, which is used by the nms-code.
  14. Offline


    There's no code to benchmark, just the latest versions of the two plugins, moving in the world making the chunks load / unload, and /tp filoghost filoghost.

    Correction, Bukkit objects slightly reduce performance (I can only think about casting to CraftPlayer, and the code to find near players). Reflection affects performance. I cannot prove it, I just think that using direct nms methods is faster, or at least equal.
  15. I never claimed reflection is faster :p . Your comment was a bit unclear, like you meant "using bukkit to send packets is slower" - which is always false because there is no packet-api in bukkit. Ofcourse reflection is slower, the way it works etc, no need to proof that :p
  16. Offline


    CaptainBern Yes, thanks for the correction. Do you trust me now? :)
    CaptainBern likes this.
  17. filoghost It's not about trust, it's just that I do not need to appriciate you making claims about my plugin without proper evidence :) (I just discovered a bug because of the "packet sending" you said ;) )
  18. Offline


    Ok, no problem :D
  19. Offline


  20. Offline


    With the new naming of any mob that is going to be in 1.8, you can name wither skulls with 0 motion, making them invisible! So, people will continue to make them.
  21. Offline


    filoghost hey this is rly cool but I have one question , if I have multiple of these would it lag the server? So for example 20 of them near in one area
  22. Offline


    If they're in a loaded chunk, a ton of them will start to lag because filog uses actual entities (not packets).
    unforgiven5232 and DSH105 like this.
  23. Offline


    Ultimate_n00b what you're saying is false, read the benchmarks. The entities do not tick, and server automatically sends the needed packets. It's actually less efficient with packets than with entities.

    Phasesaber yes I will change to the new system :)

    unforgiven5232 20 holograms are not a problem for the server. The problem is that too many of them can cause fps drops.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 8, 2016
  24. Offline


    Hm? I did a lot of tests involving the time for the minecraft ticking method to run. Adding a lot of these (example: 200-1000 spread across the world) will cause a delay in the ticking thread.
    DSH105 likes this.
  25. Offline


    Ultimate_n00b there's nothing to measure... the methods are nearly empty.
  26. Offline


        [11:07:39] [Server thread/ERROR]: Could not pass event ChunkLoadEvent to HolographicDisplays v1.8.2
        at org$1.execute(
    at org.bukkit.plugin.RegisteredListener.callEvent(
    at org.bukkit.plugin.TimedRegisteredListener.callEvent(
    at org.bukkit.plugin.SimplePluginManager.fireEvent(
    at org.bukkit.plugin.SimplePluginManager.callEvent(
    at org.bukkit.craftbukkit.v1_7_R3.chunkio.ChunkIOProvider.callStage2(
    at org.bukkit.craftbukkit.v1_7_R3.chunkio.ChunkIOProvider.callStage2(
    at org.bukkit.craftbukkit.v1_7_R3.util.AsynchronousExecutor$Task.finish(
    at org.bukkit.craftbukkit.v1_7_R3.util.AsynchronousExecutor$Task.get(
    at org.bukkit.craftbukkit.v1_7_R3.util.AsynchronousExecutor.skipQueue(
    at org.bukkit.craftbukkit.v1_7_R3.util.AsynchronousExecutor.getSkipQueue(
    at org.bukkit.craftbukkit.v1_7_R3.chunkio.ChunkIOExecutor.syncChunkLoad(
    at net.minecraft.server.v1_7_R3.ChunkProviderServer.getChunkAt(
    at net.minecraft.server.v1_7_R3.ChunkProviderServer.getChunkAt(
    at net.minecraft.server.v1_7_R3.PlayerList.a(
    at net.minecraft.server.v1_7_R3.PlayerList.c(
    at net.minecraft.server.v1_7_R3.PlayerList.a(
    at net.minecraft.server.v1_7_R3.LoginListener.c(
    at net.minecraft.server.v1_7_R3.LoginListener.a(
    at net.minecraft.server.v1_7_R3.NetworkManager.a(
    at net.minecraft.server.v1_7_R3.ServerConnection.c(
    at net.minecraft.server.v1_7_R3.MinecraftServer.v(
    at net.minecraft.server.v1_7_R3.DedicatedServer.v(
    at net.minecraft.server.v1_7_R3.MinecraftServer.u(
    Caused byjava.lang.NullPointerException
        at com
    .gmail.filoghost.holograms.object.HologramLine.spawn( ~[?:?]
    at ~[?:?]
    at ~[?:?]
    at ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0]
    at$1.execute( ~]
    25 more
    Why was this error thrown when I joined?
    public class DisplayChicken {
    private ClassDisplay display;
    private JavaPlugin plugin;
        public DisplayChicken(ClassDisplay display, JavaPlugin plugin){
            this.display = display;
            this.plugin = plugin;
        public ClassDisplay getDisplay(){
            return display;
        public void spawn(){
            Location l = getDisplay().getLocation();
            Chicken chicken = l.getWorld().spawn(l, Chicken.class);
            EntitySpeedModifier.setSpeed(chicken, Double.MAX_VALUE);
            HolographicDisplaysAPI.createHologram(plugin, l.add(0, 2, 0), MessageManager.translateColors("&e&l" + display.getClassBase().getDisplayName()));
  27. Offline


  28. Offline


    The amount of time it takes to tick entities? That's measurable. Or even better, time taken to tick hologram parts. Also measurable.
  29. Offline


    Ultimate_n00b this is the method for horses, and I don't think it's accurately measurable because it's very fast:
    1. if (ticksLived % 20 == 0) {
    2. // The horse dies without a vehicle.
    3. if (this.vehicle == null) {
    4. die();
    5. }
    6. }
    8. if (!lockTick) {
    9. super.h();
    10. }

    The timings say 0.0003-0.0002 millis for each of them.
  30. Offline


    I'm not talking about the single methods, I'm talking about as a whole. Take for example, it calculates if a player is near enough to view it. How long does that method takes? I've been doing all the calculating via packets on an async thread, which is much faster.
    DSH105 likes this.
Thread Status:
Not open for further replies.

Share This Page