TextComponent To String?

Discussion in 'Spigot Plugin Development' started by TimLampen, May 18, 2015.

  1. Hey,
    Im trying to make text appear when a player hovers over the text, and I found the BungeeCord TextComponent class in the spigot-api class so I was able to make this:
    Code (Text):
                TextComponent prestige = new TextComponent(pre.getNumber(pre.getPrestige(player)));
                prestige.setColor(ChatColor.GRAY);
                prestige.setBold(true);
                TextComponent name = new TextComponent(player.getDisplayName());
                TextComponent arrow = new TextComponent(" ยป ");
                arrow.setColor(ChatColor.GRAY);
                arrow.setBold(false);
                TextComponent msg = new TextComponent(event.getMessage());
                msg.setColor(ChatColor.AQUA);
                msg.setBold(false);
               
                prestige.addExtra(name);
                prestige.addExtra(arrow);
                prestige.addExtra(msg);
                prestige.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("adfasfdas").create()));
               
                for(Player plyer : Bukkit.getOnlinePlayers()){
                    plyer.sendMessage(prestige.toLegacyText());
                }
    (This is listening in AsyncPlayerChatEvent and don't worry about the getPrestige and such methods)

    This does work except the hover does not appear. Is this because I can't send a TextComponent to a player? If so how can I get around it?

    Thanks,
    Tim
     
  2. Player.spigot().sendMessage(...)