1
1
/*
2
- * Copyright (C) 2021 DarkKronicle
2
+ * Copyright (C) 2021-2022 DarkKronicle
3
3
*
4
4
* This Source Code Form is subject to the terms of the Mozilla Public
5
5
* License, v. 2.0. If a copy of the MPL was not distributed with this
10
10
import io .github .darkkronicle .advancedchatcore .interfaces .IMessageFilter ;
11
11
import io .github .darkkronicle .advancedchatcore .interfaces .IMessageProcessor ;
12
12
import io .github .darkkronicle .advancedchatcore .util .FindType ;
13
- import io .github .darkkronicle .advancedchatcore .util .FluidText ;
14
13
import io .github .darkkronicle .advancedchatcore .util .SearchResult ;
15
14
import io .github .darkkronicle .advancedchatcore .util .SearchUtils ;
15
+ import io .github .darkkronicle .advancedchatcore .util .StringInsert ;
16
16
import io .github .darkkronicle .advancedchatcore .util .StringMatch ;
17
17
import io .github .darkkronicle .advancedchatcore .util .StyleFormatter ;
18
+ import io .github .darkkronicle .advancedchatcore .util .TextUtil ;
18
19
import java .util .ArrayList ;
19
20
import java .util .HashMap ;
20
21
import java .util .Map ;
21
22
import java .util .Optional ;
22
23
import net .fabricmc .api .EnvType ;
23
24
import net .fabricmc .api .Environment ;
24
25
import net .minecraft .text .ClickEvent ;
26
+ import net .minecraft .text .LiteralTextContent ;
27
+ import net .minecraft .text .MutableText ;
25
28
import net .minecraft .text .Text ;
26
29
import org .apache .logging .log4j .LogManager ;
27
30
@@ -60,7 +63,7 @@ private MessageDispatcher() {
60
63
if (search .size () == 0 ) {
61
64
return Optional .empty ();
62
65
}
63
- Map <StringMatch , FluidText . StringInsert > insert = new HashMap <>();
66
+ Map <StringMatch , StringInsert > insert = new HashMap <>();
64
67
for (StringMatch match : search .getMatches ()) {
65
68
insert .put (
66
69
match ,
@@ -71,16 +74,12 @@ private MessageDispatcher() {
71
74
url = "https://" + url ;
72
75
}
73
76
if (current .getStyle ().getClickEvent () == null ) {
74
- return new FluidText (
75
- current .withStyle (current .getStyle ().withClickEvent (
76
- new ClickEvent (ClickEvent .Action .OPEN_URL , url )
77
- )).withMessage (match1 .match )
78
- );
77
+ return MutableText .of (new LiteralTextContent (match1 .match )).fillStyle (current .getStyle ().withClickEvent (new ClickEvent (ClickEvent .Action .OPEN_URL , url )));
79
78
}
80
- return new FluidText (current );
79
+ return MutableText . of (current . getContent ()). fillStyle ( current . getStyle () );
81
80
});
82
81
}
83
- text .replaceStrings (insert );
82
+ TextUtil .replaceStrings (text , insert );
84
83
return Optional .of (text );
85
84
},
86
85
-1 );
@@ -108,27 +107,26 @@ private MessageDispatcher() {
108
107
* @param text Text that is received
109
108
*/
110
109
public void handleText (Text text ) {
111
- FluidText fluidText = new FluidText (text );
112
- boolean previouslyBlank = fluidText .getString ().length () == 0 ;
113
- fluidText = preFilter (fluidText );
114
- if (fluidText .getString ().length () == 0 && !previouslyBlank ) {
110
+ boolean previouslyBlank = text .getString ().length () == 0 ;
111
+ text = preFilter (text );
112
+ if (text .getString ().length () == 0 && !previouslyBlank ) {
115
113
// No more
116
114
return ;
117
115
}
118
- process (fluidText );
116
+ process (text );
119
117
}
120
118
121
- private FluidText preFilter (FluidText text ) {
119
+ private Text preFilter (Text text ) {
122
120
for (IMessageFilter f : preFilters ) {
123
- Optional <FluidText > t = f .filter (text );
121
+ Optional <Text > t = f .filter (text );
124
122
if (t .isPresent ()) {
125
123
text = t .get ();
126
124
}
127
125
}
128
126
return text ;
129
127
}
130
128
131
- private void process (FluidText text ) {
129
+ private void process (Text text ) {
132
130
for (IMessageFilter f : processors ) {
133
131
f .filter (text );
134
132
}
0 commit comments