-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
110 additions
and
6 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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package vg.skye; | ||
|
||
import com.mojang.brigadier.context.StringRange; | ||
import com.mojang.brigadier.suggestion.Suggestion; | ||
import com.mojang.brigadier.suggestion.Suggestions; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class EmojiSuggestion extends Suggestion { | ||
private final String value; | ||
private EmojiSuggestion(StringRange range, String text) { | ||
super(range, ":" + text + ": " + text); | ||
this.value = text; | ||
} | ||
|
||
@Override | ||
public String apply(String input) { | ||
String valueToReplace = ":" + value + ":"; | ||
StringRange range = getRange(); | ||
if (range.getStart() == 0 && range.getEnd() == input.length()) { | ||
return valueToReplace; | ||
} | ||
final StringBuilder result = new StringBuilder(); | ||
if (range.getStart() > 0) { | ||
result.append(input, 0, range.getStart()); | ||
} | ||
result.append(valueToReplace); | ||
if (range.getEnd() < input.length()) { | ||
result.append(input.substring(range.getEnd())); | ||
} | ||
return result.toString(); | ||
} | ||
|
||
public static Suggestions suggest(String text, int start) { | ||
List<Suggestion> result = new ArrayList<>(); | ||
String remaining = text.substring(start + 1); | ||
for (String key: EmojilessClient.emojis.keySet()) { | ||
if (key.startsWith(remaining)) { | ||
result.add(new EmojiSuggestion(StringRange.between(start, text.length()), key)); | ||
} | ||
} | ||
return Suggestions.create(text, result); | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
common/src/main/java/vg/skye/mixin/CommandSuggestionsMixin.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package vg.skye.mixin; | ||
|
||
import com.mojang.brigadier.suggestion.Suggestions; | ||
import com.samsthenerd.inline.api.client.InlineClientAPI; | ||
import net.minecraft.client.gui.components.CommandSuggestions; | ||
import net.minecraft.client.gui.components.EditBox; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.spongepowered.asm.mixin.Final; | ||
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 vg.skye.EmojiMatcher; | ||
import vg.skye.EmojiSuggestion; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
@Mixin(CommandSuggestions.class) | ||
public abstract class CommandSuggestionsMixin { | ||
@Shadow @Final | ||
EditBox input; | ||
|
||
@Shadow private CompletableFuture<Suggestions> pendingSuggestions; | ||
|
||
@Shadow public abstract void showSuggestions(boolean bl); | ||
|
||
@Inject(method = "updateCommandInfo", at = @At(value = "INVOKE", target = "Lnet/minecraft/commands/SharedSuggestionProvider;suggest(Ljava/lang/Iterable;Lcom/mojang/brigadier/suggestion/SuggestionsBuilder;)Ljava/util/concurrent/CompletableFuture;", shift = At.Shift.AFTER)) | ||
private void inject(CallbackInfo ci) { | ||
if (!InlineClientAPI.INSTANCE.getConfig().isMatcherEnabled(new ResourceLocation("emojiless", "emoji"))) | ||
return; | ||
String text = this.input.getValue(); | ||
int cursor = this.input.getCursorPosition(); | ||
String textUptoCursor = text.substring(0, cursor); | ||
var negMatcher = EmojiMatcher.PARTIAL_NEG.matcher(textUptoCursor); | ||
var matcher = EmojiMatcher.PARTIAL.matcher(textUptoCursor); | ||
if (matcher.find() && !negMatcher.find()) { | ||
this.pendingSuggestions = CompletableFuture.completedFuture(EmojiSuggestion.suggest(textUptoCursor, matcher.start())); | ||
this.showSuggestions(false); | ||
} | ||
} | ||
} |
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,4 +1,6 @@ | ||
{ | ||
"matcher.emojiless.emoji.title.styled": "Emojis", | ||
"matcher.emojiless.emoji.description": "Displays shortcodes as emojis" | ||
"matcher.emojiless.emoji.title.styled": "Emojis (shortcode syntax)", | ||
"matcher.emojiless.emoji.description": "Displays shortcodes as emojis", | ||
"matcher.emojiless.emoji_standard.title.styled": "Emojis (Inline syntax)", | ||
"matcher.emojiless.emoji_standard.description": "Displays emojis using Inline syntax" | ||
} |
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
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