MCPcopy Create free account
hub / github.com/5zig/The-5zig-Mod / ChatComponentBuilder

Class ChatComponentBuilder

Minecraft-Utils/1.10/src/ChatComponentBuilder.java:13–129  ·  view source on GitHub ↗

Created by 5zig. All rights reserved © 2015 Utility class for ChatComponent serialization.

Source from the content-addressed store, hash-verified

11 * Utility class for ChatComponent serialization.
12 */
13public class ChatComponentBuilder {
14
15 private static final Map<ChatColor, a> TRANSLATE = new HashMap<ChatColor, a>();
16 private static final Pattern url = Pattern.compile("^(?:(https?)://)?([-\\w_\\.]{2,}\\.[a-z]{2,4})(/\\S*)?$");
17
18 static {
19 for (int i = 0; i < a.values().length; i++) {
20 TRANSLATE.put(ChatColor.values()[i], a.values()[i]);
21 }
22 }
23
24 // CHATCOMPONENT = eu
25 // ChatComponentStyle = es
26 // ChatStyle = ez
27 // TEXTCOMPONENT = fe
28 // ClickEvent = et
29 // HoverEvent = ey
30
31 public static ey fromLegacyText(String message) {
32 fe base = new fe("");
33 StringBuilder builder = new StringBuilder();
34 fe currentComponent = new fe("");
35 fd currentStyle = new fd();
36 currentComponent.a(currentStyle);
37 Matcher matcher = url.matcher(message);
38
39 for (int i = 0; i < message.length(); i++) {
40 char c = message.charAt(i);
41
42 if (c == ChatColor.COLOR_CHAR) {
43 i++;
44 c = message.charAt(i);
45 if (c >= 'A' && c <= 'Z') {
46 c += 32;
47 }
48
49 ChatColor format = ChatColor.getByChar(c);
50 if (format == null) {
51 continue;
52 }
53
54 if (builder.length() > 0) {
55 fe old = currentComponent;
56 currentComponent = old.h();
57 currentStyle = currentComponent.b();
58 old.a(builder.toString());
59 builder = new StringBuilder();
60 base.a(old);
61 }
62
63 switch (format) {
64 case BOLD:
65 currentStyle.a(true);
66 break;
67 case ITALIC:
68 currentStyle.b(true);
69 break;
70 case STRIKETHROUGH:

Callers

nothing calls this directly

Calls 1

putMethod · 0.80

Tested by

no test coverage detected