Solved Hover over advancement with Chat Component API

Discussion in 'Spigot Plugin Development' started by UnspecifiedUser, Jul 8, 2021.

  1. The Component stuff has very few documentation (or often just few basics), and even after reading the javadoc I can't figure out how to make a Hover event showing an advancement bubble.

    I think the beginning would be something like this :

    Code (Text):

    TextComponent advancement = new TextComponent("advancement");
    advancement.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, [maybe a certain kind of BaseComponent]);
     
    Thanks for the help !
     
  2. Ok I found the solution^^ I wasn't able to make my own advancement bubble but I tried with :"\n"... and it worked (I don't know why I didn't try this)

    So with this code, if you hover over "advancement", a custom advancement bubble appears :

    Code (Text):

    TextComponent advancement = new TextComponent("advancement");
    advancement.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
        new ComponentBuilder(ChatColor.YELLOW + "Goal Reached!\n"
        + ChatColor.AQUA + "" + ChatColor.UNDERLINE + "You made this work").create()));

    TextComponent text = new TextComponent("You can hover over this ");
    text.addExtra(advancement);

    Bukkit.getServer().spigot().broadcast(text);
     
     
  3. Adventure is a great library for this! Check it out.
     
    • Like Like x 1