9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2026-01-04 15:41:38 +00:00

feat(core): 添加表情符号补全功能

This commit is contained in:
jhqwqmc
2025-04-10 19:13:00 +08:00
parent 41b7ed4a61
commit a904b63c40
4 changed files with 45 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.core.font;
import com.google.common.collect.ImmutableMap;
import net.kyori.adventure.text.Component;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.pack.LoadingSequence;
@@ -35,6 +36,9 @@ public abstract class AbstractFontManager implements FontManager {
protected Trie emojiKeywordTrie;
private Map<String, Component> tagMapper;
protected Map<String, Emoji> emojiMapper;
// tab补全
protected final Map<UUID, String> cachedEmojiSuggestions = new HashMap<>();
protected final Map<UUID, String> oldCachedEmojiSuggestions = new HashMap<>();
public AbstractFontManager(CraftEngine plugin) {
this.plugin = plugin;
@@ -55,6 +59,17 @@ public abstract class AbstractFontManager implements FontManager {
this.images.clear();
this.illegalChars.clear();
this.emojis.clear();
this.cachedEmojiSuggestions.clear();
}
@Override
public Map<UUID, String> cachedEmojiSuggestions() {
return ImmutableMap.copyOf(this.cachedEmojiSuggestions);
}
@Override
public Map<UUID, String> oldCachedEmojiSuggestions() {
return ImmutableMap.copyOf(this.oldCachedEmojiSuggestions);
}
@Override
@@ -146,6 +161,7 @@ public abstract class AbstractFontManager implements FontManager {
@Override
public void delayedLoad() {
this.oldCachedEmojiSuggestions.clear();
Optional.ofNullable(this.fonts.get(DEFAULT_FONT)).ifPresent(font -> this.illegalChars.addAll(font.codepointsInUse()));
this.buildImageTagTrie();
this.buildEmojiKeywordsTrie();
@@ -263,6 +279,9 @@ public abstract class AbstractFontManager implements FontManager {
return;
}
List<String> keywords = MiscUtils.getAsStringList(keywordsRaw);
UUID uuid = UUID.randomUUID();
String keyword = keywords.get(0);
cachedEmojiSuggestions.put(uuid, keyword);
String content = section.getOrDefault("content", "<arg:emoji>").toString();
String image = null;
if (section.containsKey("image")) {

View File

@@ -11,6 +11,7 @@ import net.momirealms.craftengine.core.util.Key;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
public interface FontManager extends Manageable {
Key DEFAULT_FONT = Key.of("minecraft:default");
@@ -73,4 +74,8 @@ public interface FontManager extends Manageable {
}
Map<String, Component> matchTags(String json);
Map<UUID, String> cachedEmojiSuggestions();
Map<UUID, String> oldCachedEmojiSuggestions();
}