From 054f986acb40fb0b69268fe271fcf9dd4d595063 Mon Sep 17 00:00:00 2001 From: Andy Date: Fri, 29 Mar 2024 11:30:05 -0400 Subject: [PATCH 1/2] Fix crash when typing "/ " in chat --- .../net/earthcomputer/clientcommands/mixin/MixinChatScreen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/mixin/MixinChatScreen.java b/src/main/java/net/earthcomputer/clientcommands/mixin/MixinChatScreen.java index f391aaf7b..04ac2859c 100644 --- a/src/main/java/net/earthcomputer/clientcommands/mixin/MixinChatScreen.java +++ b/src/main/java/net/earthcomputer/clientcommands/mixin/MixinChatScreen.java @@ -34,7 +34,7 @@ private String onHandleChatInput(String message) { @Inject(method = "onEdited", at = @At("HEAD")) private void onEdited(String value, CallbackInfo ci) { - if (value.startsWith("/") && ClientCommands.isClientcommandsCommand(value.substring(1).split(" ")[0])) { + if (value.startsWith("/") && !value.startsWith("/ ") && ClientCommands.isClientcommandsCommand(value.substring(1).split(" ")[0])) { if (oldMaxLength == null) { oldMaxLength = input.maxLength; } From 6c651c1f9841ed92d7af0d3f730eeb85111c4fd0 Mon Sep 17 00:00:00 2001 From: Andy Date: Fri, 29 Mar 2024 12:59:20 -0400 Subject: [PATCH 2/2] Check argument array length instead of checking for "/ " --- .../clientcommands/mixin/MixinChatScreen.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/mixin/MixinChatScreen.java b/src/main/java/net/earthcomputer/clientcommands/mixin/MixinChatScreen.java index 04ac2859c..5a0fc9349 100644 --- a/src/main/java/net/earthcomputer/clientcommands/mixin/MixinChatScreen.java +++ b/src/main/java/net/earthcomputer/clientcommands/mixin/MixinChatScreen.java @@ -34,12 +34,18 @@ private String onHandleChatInput(String message) { @Inject(method = "onEdited", at = @At("HEAD")) private void onEdited(String value, CallbackInfo ci) { - if (value.startsWith("/") && !value.startsWith("/ ") && ClientCommands.isClientcommandsCommand(value.substring(1).split(" ")[0])) { - if (oldMaxLength == null) { - oldMaxLength = input.maxLength; + boolean isClientcommandsCommand = false; + if (value.startsWith("/")) { + String[] commandArgs = value.substring(1).split(" "); + if (commandArgs.length > 0 && ClientCommands.isClientcommandsCommand(commandArgs[0])) { + isClientcommandsCommand = true; + if (oldMaxLength == null) { + oldMaxLength = input.maxLength; + } + input.setMaxLength(32767); } - input.setMaxLength(32767); - } else { + } + if (!isClientcommandsCommand) { // TODO: what if other mods try to do the same thing? if (oldMaxLength != null) { input.setMaxLength(oldMaxLength);