Solved Need help with HolographicDisplays's API

Discussion in 'Spigot Plugin Development' started by Kompye, Dec 3, 2019.

  1. Hello, I have this code
    Code (Java):
    Hologram statsHologram = HologramsAPI.createHologram(plugin, player.getLocation());
                TextLine line1 = statsHologram.appendTextLine("uuu");
    and no error appears when using the command, but there is no hologram
     
  2. That seems to be correct, have you actually tried teleporting yourself to the hologram's location and perhaps debugg anything at all?

    Also, have you made sure you are using the latest version of holographic displays?
     
  3. I'm not using the latest version, I am using 1.12 but /hd create works. The hologram creates at my location why would I want to teleport to it and what could I debug in 2 lines of code xd
     
  4. Thread solved, I didn't pay attention to the paranthesis...
     
  5. To what?
     
  6. I had the command check outside the permission check, anyways I have another question. How do I move the hologram if it already exists?
     
  7. Using Hologram#teleport
     
    • Like Like x 1
  8. Um yeah but how do I know if it exists or not?
     
  9. Hologram#isDeleted() to check if it has been deleted? What exactly are you asking?
     
    • Like Like x 1
  10. No, anyways I have a more important issue. It deletes when reloading the server. How can I save it in a file?
     
  11. No doesn't quite answer my question.

    Save the location of the hologram, along with the text and load them up again onEnable.
     
    • Like Like x 1
  12. Ok so I mean if at the beginning the command creates the hologram and then I want to move it how can I do it? I know I can use #teleport but if it already exists I don't want to make another one
     
  13. You save it somewhere, perhaps in a hashmap, as a value, and have a String to be it's ID. So you can refer back to it somehow and move it.

    So when you are to create a hologram, you will need to pass a certain ID (anything). After it is created, it'll be added in a Map<String, Hologram>. If you want to manipulate the hologram (move it, etc), you'd basically type out it's ID in the command and through that you would get access to it and move it accordingly. If the ID doesn't exist, it means that the hologram it is being referred to, doesn't exist.
     
    • Like Like x 1
  14. I have only one hologram is there any easier way?
     
  15. You save that hologram into a "global" variable, add getters to it. When you are to create it or teleport it, check if the variable is null. If it is, it means it doesn't exist. If it is not null, it means it has been created and exists.
     
    • Like Like x 1
  16. Sorry but I don't understand. In what class do I put the variable and how do I declare it?
     
  17. You put it wherever you fill it should be, and you declare it as what it is, a hologram.
    Code (Java):
    private Hologram hologram = null;

    public getHologram() {
    return this.hologram;
    }
     
    • Like Like x 1
  18. Uhh I think this is a mess but this is what I understood lol
    Code (Java):
    package net.etheral.commands;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    import com.gmail.filoghost.holographicdisplays.api.Hologram;
    import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;

    import net.etheral.EtheralParkour;
    import net.md_5.bungee.api.ChatColor;

    public class EpsetCommand implements CommandExecutor{

        EtheralParkour plugin;
        Hologram hologram = null;
       
        public Hologram getHologram() {
            return this.hologram;
        }
       
        public EpsetCommand(EtheralParkour instanceOfMain) {
            this.plugin = instanceOfMain;
        }
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = (Player) sender;
            if(player.hasPermission("EtheralParkour.admin")) {
            if(args[0].equalsIgnoreCase("start")) {
                plugin.getConfig().set("start", player.getLocation().getBlock().getLocation());
                plugin.saveConfig();
                player.sendMessage("Start set!");
            }
            else if(args[0].equalsIgnoreCase("finish")) {
                plugin.getConfig().set("finish", player.getLocation().getBlock().getLocation());
                plugin.saveConfig();
                player.sendMessage("Finish set!");
            }
            else if(args[0].equalsIgnoreCase("stats")) {
                if(getHologram() == null) {
                    Hologram hologram = HologramsAPI.createHologram(plugin, player.getLocation());
                } else {
                    getHologram().teleport(player.getLocation());
                }
            }
            }
            else {
                player.sendMessage(ChatColor.RED + "Nu ai permisiunea sa folosesti aceasta comanda!");
            }
            return true;
        }
       
    }

     
     
  19. That is essentially what you should be doing. However, you needn't use #getHologram() in the same class as your variable, directly use the variable. #getHologram would be used if you were to access the variable from a different class.
     
    • Winner Winner x 1
  20. It worked! Thank you!