New hex colors for MOTD?

Discussion in 'Spigot Discussion' started by andrew121410, Jun 26, 2020.

  1. I was wondering if you could use the new hex colors for the MOTD because I heard you could use them for scoreboards?
     
  2. Well, apparently you can, but it's not the same format as in-game.
    upload_2020-6-26_8-37-2.png
    upload_2020-6-26_8-37-22.png
    I tried setting the motd to the lastest coloured chat message with the rainbow colour plugin I made for fun earlier lol
     
  3. But wait - you can!
    [​IMG]

    This can be accomplished by registering a PacketAdapter with ProtocolLib:
    Code (Java):
    new PacketAdapter(plugin, PacketType.Status.Server.SERVER_INFO)
    {
        @Override
        public void onPacketSending(PacketEvent event)
        {
            BaseComponent[] components =
                new ComponentBuilder()
                    .append("You ").bold(true).color(ChatColor.of("#cf1f8e"))
                    .append("can").underlined(true).color(ChatColor.of("#09e0d0"))
                    .append(" actually!").underlined(false).color(ChatColor.of("#8dc743"))
                    .append("\n").reset()
                    .append("wow ").color(ChatColor.of("#e64500"))
                    .append("yay").color(ChatColor.of("#faf99a"))
                    .create();
           
            WrappedChatComponent wrappedComponent =
                WrappedChatComponent.fromJson(ComponentSerializer.toString(components));
           
            WrappedServerPing ping = event.getPacket().getServerPings().read(0);
            ping.setMotD(wrappedComponent);
        }
    }
    The distinction between using the above and simply listening for the standard ServerListPingEvent is that the event version only accepts a legacy-style string, whereas the packet version is capable of setting the MOTD to a chat component.
     
    • Like Like x 3
    • Informative Informative x 3
  4. See that is truly epic, thanks for sharing.
     
  5. Choco

    Moderator

    I would consider this a bug. Report it on the JIRA. Though worth noting that these only display to 1.16 clients. :)
     
  6. This has been fixed in 7560f5f5a69 so you can use the hex colors with ServerListPingEvent. @Creeprr

    So that's good.
     
    • Informative Informative x 1
  7. Epic, thanks.
     
  8. Could someone show me how you achieve it?
    I am using the correct event but my colors still default to the classic ones.
    Code (Java):
    private final String MOTD = ChatColor.of("#A686DB") + "y" + ChatColor.of("#D994CF") + "o";
     
  9. This is how I did it and it works. Annotation 2020-06-30 171240.png Annotation 2020-06-30 171225.png
     
    • Useful Useful x 1