diff options
| author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-06-04 12:40:50 +0200 |
|---|---|---|
| committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-06-04 12:40:50 +0200 |
| commit | 27ca631ac727377f0514954dd179ef145a8feba4 (patch) | |
| tree | ab5ba44d4cd5f47d995df6f81a67846e200c2753 /src/main/java/at/hannibal2/skyhanni/mixins | |
| parent | 1a6dc6ad26494c6769159a9b404ccfb837065bcf (diff) | |
| download | skyhanni-27ca631ac727377f0514954dd179ef145a8feba4.tar.gz skyhanni-27ca631ac727377f0514954dd179ef145a8feba4.tar.bz2 skyhanni-27ca631ac727377f0514954dd179ef145a8feba4.zip | |
Added Command Autocomplete
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/mixins')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinGuiChat.java | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinGuiChat.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinGuiChat.java new file mode 100644 index 000000000..87f01f792 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinGuiChat.java @@ -0,0 +1,65 @@ +package at.hannibal2.skyhanni.mixins.transformers; + +import at.hannibal2.skyhanni.features.misc.tabcomplete.TabComplete; +import com.google.common.collect.Lists; +import net.minecraft.client.gui.GuiChat; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.util.EnumChatFormatting; +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; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.List; + +@Mixin(GuiChat.class) +public class MixinGuiChat { + + @Shadow + protected GuiTextField inputField; + + @Shadow + private boolean waitingOnAutocomplete; + + @Shadow + private boolean playerNamesFound; + + @Shadow + private List<String> foundPlayerNames = Lists.newArrayList(); + + @Shadow + public void autocompletePlayerNames() { + + } + + @Inject(method = "onAutocompleteResponse", at = @At(value = "HEAD"), cancellable = true) + private void renderItemOverlayPost(String[] originalArray, CallbackInfo ci) { + + if (this.waitingOnAutocomplete) { + String[] result = TabComplete.handleTabComplete(this.inputField.getText(), originalArray); + if (result == null) return; + ci.cancel(); + + this.playerNamesFound = false; + this.foundPlayerNames.clear(); + for (String s : result) { + if (s.length() > 0) { + this.foundPlayerNames.add(s); + } + } + + String s1 = this.inputField.getText().substring(this.inputField.func_146197_a(-1, this.inputField.getCursorPosition(), false)); + String s2 = StringUtils.getCommonPrefix(result); + s2 = EnumChatFormatting.getTextWithoutFormattingCodes(s2); + if (s2.length() > 0 && !s1.equalsIgnoreCase(s2)) { + this.inputField.deleteFromCursor(this.inputField.func_146197_a(-1, this.inputField.getCursorPosition(), false) - this.inputField.getCursorPosition()); + this.inputField.writeText(s2); + } else if (this.foundPlayerNames.size() > 0) { + this.playerNamesFound = true; + this.autocompletePlayerNames(); + } + } + } +} |
