Create new empty TextComponent rowMessage = new TextComponent(""), after that, add extra to rowMessage with colours (rowMessage.addExtra(....). Send message to player and message not coloured full.

          [SPIGOT-3132] TextComponent, colors not working correctly

          pokechu22 added a comment -

          What part of the message do you want to add a hover message to? You can't directly add a hover message to a normal string, currently. But the sample you gave doesn't have a clean way of adding a hover message either.

          Once my PR is finished, the game will automatically add the standard hover message (as found on vanilla servers) with the player's UUID and the ability to PM them by clicking their name (if you use %1$s in the format string). Other hover messages won't be automatically usable, but the same framework can be added to the general component library.

          Also, one alternative is to use TextMessage.fromLegacyText if you need to parse non-JSON data from configs.

          pokechu22 added a comment - What part of the message do you want to add a hover message to? You can't directly add a hover message to a normal string, currently. But the sample you gave doesn't have a clean way of adding a hover message either. Once my PR is finished, the game will automatically add the standard hover message (as found on vanilla servers) with the player's UUID and the ability to PM them by clicking their name (if you use %1$s in the format string). Other hover messages won't be automatically usable, but the same framework can be added to the general component library. Also, one alternative is to use TextMessage.fromLegacyText if you need to parse non-JSON data from configs.

          MrFiliper added a comment -

          Ok, but how can I add hover message to string? I must create and parse JSON message from config? Its that right way?

          MrFiliper added a comment - Ok, but how can I add hover message to string? I must create and parse JSON message from config? Its that right way?

          pokechu22 added a comment -

          Yes, that'd do it.  If you're going to use ChatColor, use the text-based messages as they internally translate it to components. Don't mix components and ChatColor, or bad stuff will happen. You'd want something like this:

          String profilMessage, middleMessage;
          
          profilMessage = ChatColor.translateAlternateColorCodes('&', SkyBlock.getPlugin().getConfig().getString(path + ".profil")
          .replace("%playerName%", e.getPlayer().getName())
          .replace("%playerGroup%", playerGroup)
          .replace("%messageTime%", dateFormat.format(date)));
          
          middleMessage = ChatColor.translateAlternateColorCodes('&', SkyBlock.getPlugin().getConfig().getString(path + ".message") + e.getMessage());
          
          String rowMessage = profilMessage + middleMessage;
          
          for(Player player : Bukkit.getOnlinePlayers()) {
          player.sendMessage(rowMessage);
          }
          

          If you want components and custom formatting (or even, decently componented text in general), so that you can use hover events or whatever, it's currently fairly awkward. I'm working on a PR that improves component support in craftbukkit (and thus spigot) so that player names actually keep their hover events (among other things). Once that PR has been merged, you'd implement as something like this (assuming this is an AsyncPlayerChatEvent) - in fact, this is probably how you should currently be implementing it, as it'll still handle everything you want for you... Don't reimplement the format API if possible.

          String profile = ChatColor.translateAlternateColorCodes('&', SkyBlock.getPlugin().getConfig().getString(path + ".profil")
                  .replace("%playerName%", "%1$s")  // Don't manually fill in the name
                  .replace("%playerGroup%", playerGroup)
                  .replace("%messageTime%", dateFormat.format(date)));
          String message = ChatColor.translateAlternateColorCodes('&', SkyBlock.getPlugin().getConfig().getString(path + ".message") + "%2$s";
          
          e.setFormat(profile + message); // That's it; the actual sending will be handled automatically.
          

          pokechu22 added a comment - Yes, that'd do it.  If you're going to use ChatColor , use the text-based messages as they internally translate it to components. Don't mix components and ChatColor , or bad stuff will happen. You'd want something like this: String profilMessage, middleMessage; profilMessage = ChatColor.translateAlternateColorCodes( '&' , SkyBlock.getPlugin().getConfig().getString(path + ".profil" ) .replace( "%playerName%" , e.getPlayer().getName()) .replace( "%playerGroup%" , playerGroup) .replace( "%messageTime%" , dateFormat.format(date))); middleMessage = ChatColor.translateAlternateColorCodes( '&' , SkyBlock.getPlugin().getConfig().getString(path + ".message" ) + e.getMessage()); String rowMessage = profilMessage + middleMessage; for (Player player : Bukkit.getOnlinePlayers()) { player.sendMessage(rowMessage); } If you want components and custom formatting (or even, decently componented text in general), so that you can use hover events or whatever, it's currently fairly awkward. I'm working on a PR that improves component support in craftbukkit (and thus spigot) so that player names actually keep their hover events (among other things). Once that PR has been merged, you'd implement as something like this (assuming this is an AsyncPlayerChatEvent ) - in fact, this is probably how you should currently be implementing it, as it'll still handle everything you want for you... Don't reimplement the format API if possible. String profile = ChatColor.translateAlternateColorCodes( '&' , SkyBlock.getPlugin().getConfig().getString(path + ".profil" ) .replace( "%playerName%" , "%1$s" ) // Don't manually fill in the name .replace( "%playerGroup%" , playerGroup) .replace( "%messageTime%" , dateFormat.format(date))); String message = ChatColor.translateAlternateColorCodes( '&' , SkyBlock.getPlugin().getConfig().getString(path + ".message" ) + "%2$s" ; e.setFormat(profile + message); // That's it; the actual sending will be handled automatically.

          MrFiliper added a comment -

          Ok, code here, I use ChatColor, thats the problem?

          TextComponent rowMessage = new TextComponent("");
          TextComponent profilMessage, middleMessage;
          
          profilMessage = new TextComponent(ChatColor.translateAlternateColorCodes('&', SkyBlock.getPlugin().getConfig().getString(path + ".profil")
          .replace("%playerName%", e.getPlayer().getName())
          .replace("%playerGroup%", playerGroup)
          .replace("%messageTime%", dateFormat.format(date))));
          
          middleMessage = new TextComponent(ChatColor.translateAlternateColorCodes('&', SkyBlock.getPlugin().getConfig().getString(path + ".message") + e.getMessage()));
          
          rowMessage.addExtra(profilMessage);
          rowMessage.addExtra(middleMessage);
          
          for(Player player : Bukkit.getOnlinePlayers()) {
          player.spigot().sendMessage(rowMessage);
          }
          

          MrFiliper added a comment - Ok, code here, I use ChatColor, thats the problem? TextComponent rowMessage = new TextComponent(""); TextComponent profilMessage, middleMessage; profilMessage = new TextComponent(ChatColor.translateAlternateColorCodes( '&' , SkyBlock.getPlugin().getConfig().getString(path + ".profil" ) .replace( "%playerName%" , e.getPlayer().getName()) .replace( "%playerGroup%" , playerGroup) .replace( "%messageTime%" , dateFormat.format(date)))); middleMessage = new TextComponent(ChatColor.translateAlternateColorCodes( '&' , SkyBlock.getPlugin().getConfig().getString(path + ".message" ) + e.getMessage())); rowMessage.addExtra(profilMessage); rowMessage.addExtra(middleMessage); for (Player player : Bukkit.getOnlinePlayers()) { player.spigot().sendMessage(rowMessage); }

          pokechu22 added a comment -

          To clarify:

          This works correctly:

          /tellraw @p {"text":"<name> ","extra":[{"color":"red","text":"LLLLLLLLLL break for demo LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL"}]}

          This breaks, because it directly inserts a §-based format code and that is not allowed:

          /tellraw @p {"text":"<name> ","extra":[{"text":"\u00a7cLLLLLLLLLL break for demo LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL"}]}

          Do not put § into component text. Just don't. Use the appropriate color and style setting methods instead.

           

          If you're formatting components the correct way and it still doesn't work, please add a test case to this ticket.

          pokechu22 added a comment - To clarify: This works correctly: /tellraw @p {"text":"<name> ","extra":[{"color":"red","text":"LLLLLLLLLL break for demo LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL"}]} This breaks, because it directly inserts a §-based format code and that is not allowed: /tellraw @p {"text":"<name> ","extra":[{"text":"\u00a7cLLLLLLLLLL break for demo LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL"}]} Do not put § into component text. Just don't. Use the appropriate color and style setting methods instead.   If you're formatting components the correct way and it still doesn't work, please add a test case to this ticket.

          pokechu22 added a comment -

          This is a client issue when using raw §-based formatting (including directly embedding ChatColor constants).  However, when using components, it shouldn't be an issue; can you provide the full code please?  If it is a vanilla bug, I can create the appropriate ticket there.

          pokechu22 added a comment - This is a client issue when using raw §-based formatting (including directly embedding ChatColor constants).  However, when using components, it shouldn't be an issue; can you provide the full code please?  If it is a vanilla bug, I can create the appropriate ticket there.

          md_5 added a comment -

          No complete code, likely an issue with your code or the client

          md_5 added a comment - No complete code, likely an issue with your code or the client

            Assignee:
            Unassigned
            Reporter:
            MrFiliper
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: