TextComponent do not formatting on new line

Discussion in 'BungeeCord Plugin Development' started by JoeyPlayzTV, Oct 12, 2019.

  1. I have the following code,

    Code (Java):
    TextComponent main = new TextComponent("§7[§c#" + entry.getId() + "§7] §c" + entry.getReason() + " §7> ");
                            TextComponent info = new TextComponent("§c[Info] ");
                            info.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§7Ersteller: §c" + entry.getInvoker() + "\n§7Erstellt: §c" + entry.getCreatedDate() + "\n§7Dauer: §c" + entry.getDurationTime()).create()));
                            TextComponent remove = new TextComponent("§c[Entfernen]");
                            remove.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/removepunishlog MUTE " + entry.getId()));
                            remove.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§7Klicke, um Eintrag #" + entry.getId() + " zu verwerfen.").create()));
                            main.addExtra(info);
                            main.addExtra(remove);
                            sender.sendMessage(main);




    But it shows me the 2. Line without color: http://prntscr.com/pid28d a part of Info is white


    Can someone help me to format the complete text using textcomponents.
     
  2. Yea, i will try the translateAlternate method. With and the chatcolor.color enum. The chatcolor enum is very nasty to use and makes the text extremly long.
     
  3. TextComponent.fromLegacyText Then you can use § and if you parse that to '&' with the ChatColor enum you're pretty much done.
     
  4. Yea but the clickevents dont working with this method.
     
  5. new TextComponent(TextComponent.fromLegacyText("bla bla bla")).setClickEvent(...)
     
  6. Code (Java):
    TextComponent main = new TextComponent();
    for (BaseComponent c : TextComponent.fromLegacyText("§7[§c#" + entry.getId() + "§7] §c" + entry.getReason() + " §7> ")) {
        main.addExtra(c);
    }
    TextComponent info = new TextComponent("[Info] ");
    info.setColor(ChatColor.RED);
    info.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§7Ersteller: §c" + entry.getInvoker() + "\n§7Erstellt: §c" + entry.getCreatedDate() + "\n§7Dauer: §c" + entry.getDurationTime())));
    TextComponent remove = new TextComponent("[Entfernen]");
    remove.setColor(ChatColor.RED);
    remove.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/removepunishlog MUTE " + entry.getId()));
    remove.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§7Klicke, um Eintrag #" + entry.getId() + " zu verwerfen.")));
    main.addExtra(info);
    main.addExtra(remove);
    sender.sendMessage(main);
     
    #7 IlyaHiguti, Oct 13, 2019
    Last edited: Oct 14, 2019
    • Like Like x 1
  7. Thank you very much for all your suggestions. Tomorrow i will test it and give you feedback. Thanks