4
4
import net .earthcomputer .clientcommands .command .VarCommand ;
5
5
import net .minecraft .client .gui .components .EditBox ;
6
6
import net .minecraft .client .gui .screens .ChatScreen ;
7
+ import org .jetbrains .annotations .Nullable ;
7
8
import org .spongepowered .asm .mixin .Mixin ;
8
9
import org .spongepowered .asm .mixin .Shadow ;
10
+ import org .spongepowered .asm .mixin .Unique ;
9
11
import org .spongepowered .asm .mixin .injection .At ;
10
12
import org .spongepowered .asm .mixin .injection .Inject ;
11
13
import org .spongepowered .asm .mixin .injection .ModifyVariable ;
12
14
import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
13
15
14
16
@ Mixin (ChatScreen .class )
15
17
public class MixinChatScreen {
16
-
17
18
@ Shadow protected EditBox input ;
18
19
20
+ @ Unique
21
+ @ Nullable
22
+ private Integer oldMaxLength = null ;
23
+
19
24
// replace the text before the Fabric Command API executes it,
20
25
// but ensure the message is added to the history in its raw form.
21
26
@ ModifyVariable (method = "handleChatInput" , at = @ At (value = "INVOKE" , target = "Ljava/lang/String;startsWith(Ljava/lang/String;)Z" , remap = false ), argsOnly = true )
@@ -30,10 +35,16 @@ private String onHandleChatInput(String message) {
30
35
@ Inject (method = "onEdited" , at = @ At ("HEAD" ))
31
36
private void onEdited (String value , CallbackInfo ci ) {
32
37
if (value .startsWith ("/" ) && ClientCommands .isClientcommandsCommand (value .substring (1 ).split (" " )[0 ])) {
38
+ if (oldMaxLength == null ) {
39
+ oldMaxLength = input .maxLength ;
40
+ }
33
41
input .setMaxLength (32767 );
34
42
} else {
35
43
// TODO: what if other mods try to do the same thing?
36
- input .setMaxLength (256 );
44
+ if (oldMaxLength != null ) {
45
+ input .setMaxLength (oldMaxLength );
46
+ oldMaxLength = null ;
47
+ }
37
48
}
38
49
}
39
50
}
0 commit comments