-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* try adding autoprefix * remove nix files * add working auto prefix command * remove more nix files * add comments on why shift by -2 * use `@ModifyReceiver` for mixin instead * fix review * i forgot the alphabet * fix bug and add custom parameter * dont include nix stuff in gitignore * Use a config for setting autoprefix instead * dont specify getter/setter
- Loading branch information
Showing
2 changed files
with
19 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 16 additions & 4 deletions
20
src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ChatScreenMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
package net.earthcomputer.clientcommands.mixin.commands.generic; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyReceiver; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import com.llamalad7.mixinextras.sugar.ref.LocalRef; | ||
import net.earthcomputer.clientcommands.ClientCommands; | ||
import net.earthcomputer.clientcommands.Configs; | ||
import net.earthcomputer.clientcommands.command.VarCommand; | ||
import net.minecraft.client.gui.screens.ChatScreen; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.ModifyVariable; | ||
|
||
@Mixin(ChatScreen.class) | ||
public class ChatScreenMixin { | ||
// replace the text before the Fabric Command API executes it, | ||
// but ensure the message is added to the history in its raw form. | ||
@ModifyVariable(method = "handleChatInput", at = @At(value = "INVOKE", target = "Ljava/lang/String;startsWith(Ljava/lang/String;)Z", remap = false), argsOnly = true) | ||
private String onHandleChatInput(String message) { | ||
String command = VarCommand.replaceVariables(message); | ||
@ModifyReceiver(method = "handleChatInput", at = @At(value = "INVOKE", target = "Ljava/lang/String;startsWith(Ljava/lang/String;)Z", remap = false)) | ||
private String onHandleChatInput(String instance, String slash, @Local(argsOnly = true) LocalRef<String> message) { | ||
String prefix = Configs.autoPrefix; | ||
if (prefix.isEmpty() || instance.startsWith("/")) { | ||
prefix = ""; | ||
} else { | ||
prefix = prefix + " "; | ||
} | ||
|
||
String command = VarCommand.replaceVariables(prefix + instance); | ||
if (command.startsWith("/")) { | ||
ClientCommands.sendCommandExecutionToServer(command.substring(1)); | ||
} | ||
|
||
message.set(command); | ||
return command; | ||
} | ||
} |