Search code examples
bukkit

-Holographic Displays API- How to remove holograms near a player


I am making a plugin. That when a command is typed. It removes the nearest Holograms to the sender/player. Now, the things I have tried are to remove the Invisible armor stands in a radius of 10 blocks. I also tried to see if there is a method to get the nearest holograms, but I had no luck. If there is any way to point to what I need to do, that would be helpful. I am not asking for code, just for what I need to look under, say a specific class etc.

Thanks, seb.

Trying to remove armor stands:

for(Entity en : player.getNearbyEntities(10, 10, 10)) {
            if(en instanceof ArmorStand) {
                en.remove();
            }
}

My Question: Where should I look to find a way to remove nearby Holograms to the player? If you can provide code, not needed though.


Solution

  • //Loop through all existing holograms registered to your plugin
    for (Hologram hologram : HologramsAPI.getHolograms(plugin)) {
        Location playerLoc   = player.getLocation();
        Location hologramLoc = hologram.getLocation();
    
        //Check if the distance between the locations are less than 10
        //and deletes the hologram if true
        if (playerLoc.distance(hologramLoc) < 10) {
            hologram.delete();
        }
    }
    

    This Holographic Displays API has a hologram delete method.

    https://github.com/filoghost/HolographicDisplays/wiki