aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/woverflow/chattils/mixin/ClientCommandHandlerMixin.java
blob: 0692342abbebf5974e9612595dbd96084607bb45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package cc.woverflow.chattils.mixin;

import cc.woverflow.chattils.chat.ChatShortcuts;
import cc.woverflow.chattils.config.ChattilsConfig;
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.Iterator;
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 (ChattilsConfig.INSTANCE.getChatShortcuts()) {
            for (Pair<String, String> pair : ChatShortcuts.INSTANCE.getShortcuts()) {
                if (pair.getFirst().startsWith(leftOfCursor)) {
                    autocompleteList.add(pair.getFirst());
                }
            }
        }
        return autocompleteList;
    }
}