6
6
package meteordevelopment .meteorclient .utils .player ;
7
7
8
8
import baritone .api .BaritoneAPI ;
9
+ import com .mojang .brigadier .StringReader ;
9
10
import meteordevelopment .meteorclient .MeteorClient ;
10
11
import meteordevelopment .meteorclient .mixininterface .IChatHud ;
11
12
import meteordevelopment .meteorclient .systems .config .Config ;
@@ -30,7 +31,7 @@ public class ChatUtils {
30
31
31
32
@ PostInit
32
33
public static void init () {
33
- PREFIX = Text .literal ( "" )
34
+ PREFIX = Text .empty ( )
34
35
.setStyle (Style .EMPTY .withFormatting (Formatting .GRAY ))
35
36
.append ("[" )
36
37
.append (Text .literal ("Meteor" ).setStyle (Style .EMPTY .withColor (TextColor .fromRgb (MeteorClient .ADDON .color .getPacked ()))))
@@ -121,19 +122,19 @@ public static void sendMsg(int id, Formatting color, String message, Object... a
121
122
}
122
123
123
124
public static void sendMsg (int id , @ Nullable String prefixTitle , @ Nullable Formatting prefixColor , Formatting messageColor , String messageContent , Object ... args ) {
124
- sendMsg (id , prefixTitle , prefixColor , formatMsg (messageContent , messageColor , args ), messageColor );
125
+ MutableText message = formatMsg (String .format (messageContent , args ), messageColor );
126
+ sendMsg (id , prefixTitle , prefixColor , message );
125
127
}
126
128
127
129
public static void sendMsg (int id , @ Nullable String prefixTitle , @ Nullable Formatting prefixColor , String messageContent , Formatting messageColor ) {
128
- MutableText message = Text .literal (messageContent );
129
- message .setStyle (message .getStyle ().withFormatting (messageColor ));
130
+ MutableText message = formatMsg (messageContent , messageColor );
130
131
sendMsg (id , prefixTitle , prefixColor , message );
131
132
}
132
133
133
134
public static void sendMsg (int id , @ Nullable String prefixTitle , @ Nullable Formatting prefixColor , Text msg ) {
134
135
if (mc .world == null ) return ;
135
136
136
- MutableText message = Text .literal ( "" );
137
+ MutableText message = Text .empty ( );
137
138
message .append (getPrefix ());
138
139
if (prefixTitle != null ) message .append (getCustomPrefix (prefixTitle , prefixColor ));
139
140
message .append (msg );
@@ -144,7 +145,7 @@ public static void sendMsg(int id, @Nullable String prefixTitle, @Nullable Forma
144
145
}
145
146
146
147
private static MutableText getCustomPrefix (String prefixTitle , Formatting prefixColor ) {
147
- MutableText prefix = Text .literal ( "" );
148
+ MutableText prefix = Text .empty ( );
148
149
prefix .setStyle (prefix .getStyle ().withFormatting (Formatting .GRAY ));
149
150
150
151
prefix .append ("[" );
@@ -196,19 +197,50 @@ private static Text getPrefix() {
196
197
return PREFIX ;
197
198
}
198
199
199
- private static String formatMsg (String format , Formatting defaultColor , Object ... args ) {
200
- String msg = String .format (format , args );
201
- msg = msg .replace ("(default)" , defaultColor .toString ());
202
- msg = msg .replace ("(highlight)" , Formatting .WHITE .toString ());
203
- msg = msg .replace ("(underline)" , Formatting .UNDERLINE .toString ());
200
+ private static MutableText formatMsg (String message , Formatting defaultColor ) {
201
+ StringReader reader = new StringReader (message );
202
+ MutableText text = Text .empty ();
203
+ Style style = Style .EMPTY .withFormatting (defaultColor );
204
+ StringBuilder result = new StringBuilder ();
205
+ boolean formatting = false ;
206
+ while (reader .canRead ()) {
207
+ char c = reader .read ();
208
+ if (c == '(' ) {
209
+ text .append (Text .literal (result .toString ()).setStyle (style ));
210
+ result .setLength (0 );
211
+ result .append (c );
212
+ formatting = true ;
213
+ } else {
214
+ result .append (c );
215
+
216
+ if (formatting && c == ')' ) {
217
+ switch (result .toString ()) {
218
+ case "(default)" -> {
219
+ style = style .withFormatting (defaultColor );
220
+ result .setLength (0 );
221
+ }
222
+ case "(highlight)" -> {
223
+ style = style .withFormatting (Formatting .WHITE );
224
+ result .setLength (0 );
225
+ }
226
+ case "(underline)" -> {
227
+ style = style .withFormatting (Formatting .UNDERLINE );
228
+ result .setLength (0 );
229
+ }
230
+ }
231
+ formatting = false ;
232
+ }
233
+ }
234
+ }
235
+
236
+ if (!result .isEmpty ()) text .append (Text .literal (result .toString ()).setStyle (style ));
204
237
205
- return msg ;
238
+ return text ;
206
239
}
207
240
208
241
public static MutableText formatCoords (Vec3d pos ) {
209
242
String coordsString = String .format ("(highlight)(underline)%.0f, %.0f, %.0f(default)" , pos .x , pos .y , pos .z );
210
- coordsString = formatMsg (coordsString , Formatting .GRAY );
211
- MutableText coordsText = Text .literal (coordsString );
243
+ MutableText coordsText = formatMsg (coordsString , Formatting .GRAY );
212
244
coordsText .setStyle (coordsText .getStyle ()
213
245
.withFormatting (Formatting .BOLD )
214
246
.withClickEvent (new ClickEvent (
0 commit comments