Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String fromComponent(IChatBaseComponent component) {
- return fromComponent(component, EnumChatFormat.BLACK);
- }
- public static String toJSON(IChatBaseComponent component) {
- return IChatBaseComponent.ChatSerializer.a(component);
- }
- public static String fromComponent(IChatBaseComponent component, EnumChatFormat defaultColor) {
- if (component == null) return "";
- StringBuilder out = new StringBuilder();
- for (IChatBaseComponent c : (Iterable<IChatBaseComponent>) component) {
- ChatModifier modi = c.getChatModifier();
- out.append(modi.getColor() == null ? defaultColor : modi.getColor());
- if (modi.isBold()) {
- out.append(EnumChatFormat.BOLD);
- }
- if (modi.isItalic()) {
- out.append(EnumChatFormat.ITALIC);
- }
- if (modi.isUnderlined()) {
- out.append(EnumChatFormat.UNDERLINE);
- }
- if (modi.isStrikethrough()) {
- out.append(EnumChatFormat.STRIKETHROUGH);
- }
- if (modi.isRandom()) {
- out.append(EnumChatFormat.OBFUSCATED);
- }
- out.append(c.getText());
- }
- return out.toString().replaceFirst("^(" + defaultColor + ")*", "");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement