Help With TextComponent API (Making Hover Over Text in Chat)

Discussion in 'Spigot Plugin Development' started by Keubix, Jun 7, 2017.

  1. Hi! I'm currently writing a plugin for my server, which adds hashtags to the chat. I have a method that extracts those hashtags from the chat and gives them color. What I want to do is make it so you can hover over each hashtag, and it will tell you how many times it's been used, who's created, etc.. I'm just not sure how I can put a TextComponent into a message. Any ideas?

    Thanks!


    My code for extracting hashtags if this helps.
    Code (Text):
    public void onHashtag(AsyncPlayerChatEvent event)
          {
            String msg = event.getMessage();
            while (msg.contains("#")) {
              msg = msg.substring(msg.indexOf("#"));
              String hashtag; if (msg.indexOf(" ") == -1) { hashtag = msg.substring(1);
              }
              else
                hashtag = msg.substring(msg.indexOf("#") + 1, msg.indexOf(" "));
              if (hashtag.length() <= 1)
              {
                return;
              }
             
              String chat = event.getMessage().replace("#", ChatColor.BLUE + "#" + ChatColor.RESET);
              event.setMessage(chat.replace(hashtag, ChatColor.AQUA + hashtag + ChatColor.RESET));
             
              if (msg.indexOf(" ") != -1) { msg = msg.substring(msg.indexOf(" "));
              } else {
                msg = "";
              }
            }
          }
     
  2. What is this
    Code (Text):
    while (msg.contains("#"))
    why theres while? The message cannot be changed so that while is useless.
     
  3. https://www.spigotmc.org/wiki/the-chat-component-api/
     
    • Like Like x 1
  4. Bump. Still need help.
     
  5. Any help please?