diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2021-12-23 16:50:27 +0700 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2021-12-23 16:50:27 +0700 |
commit | 1cd878614130057e61e085e7ef791629b1ca9cbe (patch) | |
tree | 24bdb1065523c3feda507452a658569ad7c38b52 /src/main/java | |
parent | de0341400abcfca65afe5d65053ab520aa20844c (diff) | |
download | Chatting-1cd878614130057e61e085e7ef791629b1ca9cbe.tar.gz Chatting-1cd878614130057e61e085e7ef791629b1ca9cbe.tar.bz2 Chatting-1cd878614130057e61e085e7ef791629b1ca9cbe.zip |
chat shortcuts gui + tab autocomplete for shortcuts
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/raeids/stratus/mixin/ClientCommandHandlerMixin.java | 33 | ||||
-rw-r--r-- | src/main/java/com/raeids/stratus/mixin/GuiChatMixin.java | 12 |
2 files changed, 40 insertions, 5 deletions
diff --git a/src/main/java/com/raeids/stratus/mixin/ClientCommandHandlerMixin.java b/src/main/java/com/raeids/stratus/mixin/ClientCommandHandlerMixin.java new file mode 100644 index 0000000..3082b88 --- /dev/null +++ b/src/main/java/com/raeids/stratus/mixin/ClientCommandHandlerMixin.java @@ -0,0 +1,33 @@ +package com.raeids.stratus.mixin; + +import com.raeids.stratus.config.StratusConfig; +import com.raeids.stratus.hook.ChatShortcuts; +import kotlin.Pair; +import net.minecraft.client.Minecraft; +import net.minecraft.command.CommandHandler; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.BlockPos; +import net.minecraftforge.client.ClientCommandHandler; +import net.minecraftforge.fml.client.FMLClientHandler; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.List; + +@Mixin(value = ClientCommandHandler.class, remap = false) +public class ClientCommandHandlerMixin extends CommandHandler { + @Redirect(method = "autoComplete", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/ClientCommandHandler;getTabCompletionOptions(Lnet/minecraft/command/ICommandSender;Ljava/lang/String;Lnet/minecraft/util/BlockPos;)Ljava/util/List;")) + private List<String> addChatShortcuts(ClientCommandHandler instance, ICommandSender iCommandSender, String leftOfCursor, BlockPos blockPos) { + Minecraft mc = FMLClientHandler.instance().getClient(); + List<String> autocompleteList = instance.getTabCompletionOptions(mc.thePlayer, leftOfCursor, mc.thePlayer.getPosition()); + if (StratusConfig.INSTANCE.getChatShortcuts()) { + for (Pair<String, String> pair : ChatShortcuts.INSTANCE.getShortcuts()) { + if (pair.getFirst().startsWith(leftOfCursor)) { + autocompleteList.add(pair.getFirst()); + } + } + } + return autocompleteList; + } +} diff --git a/src/main/java/com/raeids/stratus/mixin/GuiChatMixin.java b/src/main/java/com/raeids/stratus/mixin/GuiChatMixin.java index 350f000..397cb06 100644 --- a/src/main/java/com/raeids/stratus/mixin/GuiChatMixin.java +++ b/src/main/java/com/raeids/stratus/mixin/GuiChatMixin.java @@ -7,6 +7,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiChat; import net.minecraft.client.gui.GuiScreen; import net.minecraft.util.MathHelper; +import org.apache.commons.lang3.StringUtils; import org.lwjgl.input.Mouse; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -80,13 +81,14 @@ public abstract class GuiChatMixin extends GuiScreen { } } } - @ModifyArg(method = "keyTyped", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;sendChatMessage(Ljava/lang/String;)V"), index = 0) - private String modifySentMessage(String original){ - if(original.equalsIgnoreCase ("/pw")){ - return "/p warp"; + @ModifyArg(method = "keyTyped", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;sendChatMessage(Ljava/lang/String;)V"), index = 0) + private String modifySentMessage(String original) { + if (StratusConfig.INSTANCE.getChatShortcuts()) { + if (original.startsWith("/")) { + return "/" + ChatShortcuts.INSTANCE.handleSentCommand(StringUtils.substringAfter(original, "/")); + } } return original; - } } |