diff --git a/src/main/java/com/stupidrepo/giveme/client/CustomGiveCommand.java b/src/main/java/com/stupidrepo/giveme/client/CustomGiveCommand.java index 911a275..d454428 100644 --- a/src/main/java/com/stupidrepo/giveme/client/CustomGiveCommand.java +++ b/src/main/java/com/stupidrepo/giveme/client/CustomGiveCommand.java @@ -5,7 +5,6 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.arguments.item.ItemInput; import net.minecraft.network.chat.Component; @@ -30,7 +29,7 @@ public static void register(CommandDispatcher dispatc dispatcher.register(literal("giveme") .then(argument("item", itemStack(context)).executes(ctx -> give(ctx.getSource(), getCItemStackArgument(ctx, "item"), 1)) .then(argument("count", integer(1)).executes(ctx -> give(ctx.getSource(), getCItemStackArgument(ctx, "item"), getInteger(ctx, "count")))))); - LOGGER.info("Registered /giveme command"); + LOGGER.info("Registered the giveme command"); } private static int give(FabricClientCommandSource source, ItemInput itemInput, int count) throws CommandSyntaxException { diff --git a/src/main/java/com/stupidrepo/giveme/client/mixins/ChatScreenMixin.java b/src/main/java/com/stupidrepo/giveme/client/mixins/ChatScreenMixin.java index feadd77..b5fe75c 100644 --- a/src/main/java/com/stupidrepo/giveme/client/mixins/ChatScreenMixin.java +++ b/src/main/java/com/stupidrepo/giveme/client/mixins/ChatScreenMixin.java @@ -1,11 +1,10 @@ package com.stupidrepo.giveme.client.mixins; +import com.stupidrepo.giveme.client.GiveMeClient; import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.screens.ChatScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; -import net.minecraft.util.StringUtil; -import org.apache.commons.lang3.StringUtils; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -13,6 +12,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.util.Objects; + @Mixin(ChatScreen.class) public class ChatScreenMixin extends Screen { protected ChatScreenMixin(Component component) { @@ -29,21 +30,15 @@ protected ChatScreenMixin(Component component) { @Inject(method = "onEdited", at = @At("TAIL")) protected void onEdited(String string, CallbackInfo ci) { - if(string.startsWith("/giveme")) { - this.input.setMaxLength(Integer.MAX_VALUE); - } else { - this.input.setMaxLength(256); - } + var m = Objects.equals(string.split(" ")[0].trim(), "/giveme") ? Integer.MAX_VALUE : GiveMeClient.MAX_MESSAGE_LENGTH; + this.input.setMaxLength(m); } -// @Inject(method = "normalizeChatMessage", at = @At("HEAD"), cancellable = true) -// protected void normalizeChatMessage(String string, CallbackInfoReturnable cir) { -// if(string.length() > 256) { -// if(string.startsWith("/giveme")) { -// cir.setReturnValue(string); -// } else { -// cir.setReturnValue(StringUtil.trimChatMessage(StringUtils.normalizeSpace(string.trim()))); -// } -// } -// } + @Inject(method = "normalizeChatMessage", at = @At("HEAD"), cancellable = true) + protected void normalizeChatMessage(String string, CallbackInfoReturnable cir) { + if(Objects.equals(string.split(" ")[0].trim(), "/giveme")) { + cir.cancel(); + cir.setReturnValue(string); + } + } }