Solved How to check hologram?

Discussion in 'Spigot Plugin Development' started by Joshuak52, Mar 15, 2020.

  1. Hi, trying to check if a hologram contains a certain line to do the event. not working

    Code (Text):
        @EventHandler
        public void onMove(PlayerMoveEvent event) {
            Player player = (Player) event.getPlayer();
            if(showingCrystals.contains(player.getName())) {
                player.sendMessage("yes1");
                if(event.getFrom().getX() != event.getTo().getX() || event.getFrom().getZ() != event.getTo().getZ()) {
                    for (Hologram hologram : HologramsAPI.getHolograms(plugin)) {
                        String HologramName = ChatColor.DARK_RED + "[!] " + ChatColor.GRAY + player.getName() + ChatColor.DARK_RED + " has " + getConfig().getInt("Crystals." + player.getUniqueId()) + " pvp crystals";
                        if(hologram.getLine(3).toString().equals(HologramName)) {
                            player.sendMessage("yes");
                            int y = (int) (player.getLocation().getBlockY() + 4);
                            World w = player.getWorld();
                            Location loc = new Location(w, player.getLocation().getX(), y, player.getLocation().getZ());
                            hologram.teleport(loc);
                        } else {
                            player.sendMessage("no");
                        }
                    }
                }
            } else {
                return;
            }
        }
    The thing is, I am not getting the no debug message either?
     
  2. FrostedSnowman

    Resource Staff

    If you're not getting the "yes1" message, then your collection does not contain the player name. You need to debug the code around it, not only debug the code that is expected.
     
  3. I am getting yes1. Any advice?

    UPDATE:

    hologram.getLine(3) needed to be hologram.getLine(2)

    but now I am getting the "no" message even though the line should be correct?

    This is what command I type for the hologram to show up
    Code (Text):
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player player = (Player) sender;
            if(cmd.getName().equalsIgnoreCase("PvPC")) {
                if(args.length == 0) {
                    if(showingCrystals.contains(player.getName())) {
                        sender.sendMessage(ChatColor.RED + "[!]" + ChatColor.GRAY + " Error: You are already showing your pvp crystals off!");
                        return true;
                    }
                    int y = (int) (player.getLocation().getBlockY() + 4);
                    World w = player.getWorld();
                    Location loc = new Location(w, player.getLocation().getX(), y, player.getLocation().getZ());
                    Hologram hologram = HologramsAPI.createHologram(plugin, loc);
                   
                    ItemStack head = new ItemStack(Material.PLAYER_HEAD);
                    SkullMeta skull = (SkullMeta) head.getItemMeta();
                    skull.setOwner(player.getName());
                    head.setItemMeta(skull);
                   
                    hologram.appendItemLine(head);
                    hologram.appendItemLine(new ItemStack(Material.END_CRYSTAL));
                    hologram.appendTextLine(ChatColor.DARK_RED + "[!] " + ChatColor.GRAY + player.getName() + ChatColor.DARK_RED + " has " + getConfig().getInt("Crystals." + player.getUniqueId()) + " pvp crystals");
                   
                    showingCrystals.add(player.getName());
                    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                        public void run() {
                            showingCrystals.remove(player.getName());
                            hologram.delete();
                        }
                    }, 4 * 20L);
                }
     
    #3 Joshuak52, Mar 15, 2020
    Last edited: Mar 15, 2020
  4. UPDATE: SOLVED

    if(hologram.getLine(2).toString().contains(HologramName)) {