mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-23 17:09:19 +00:00
feat(core): 添加表情符号补全功能
This commit is contained in:
@@ -5,6 +5,7 @@ import com.google.gson.JsonPrimitive;
|
||||
import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent;
|
||||
import io.papermc.paper.event.player.AsyncChatDecorateEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.util.ComponentUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.LegacyInventoryUtils;
|
||||
@@ -31,6 +32,7 @@ import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.inventory.PrepareAnvilEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerEditBookEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.bukkit.inventory.view.AnvilView;
|
||||
@@ -58,6 +60,23 @@ public class BukkitFontManager extends AbstractFontManager implements Listener {
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delayedLoad() {
|
||||
Map<UUID, String> oldCachedEmojiSuggestions = this.oldCachedEmojiSuggestions();
|
||||
super.delayedLoad();
|
||||
this.oldCachedEmojiSuggestions.putAll(this.cachedEmojiSuggestions());
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
FastNMS.INSTANCE.method$ChatSuggestions$remove(oldCachedEmojiSuggestions.keySet(), player);
|
||||
FastNMS.INSTANCE.method$ChatSuggestions$add(this.cachedEmojiSuggestions(), player);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
FastNMS.INSTANCE.method$ChatSuggestions$add(this.cachedEmojiSuggestions(), player);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public void onChat(AsyncChatDecorateEvent event) {
|
||||
|
||||
@@ -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")) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ geantyref_version=1.3.16
|
||||
zstd_version=1.5.7-2
|
||||
commons_io_version=2.18.0
|
||||
sparrow_nbt_version=0.6.2
|
||||
sparrow_util_version=0.37
|
||||
sparrow_util_version=0.38
|
||||
fastutil_version=8.5.15
|
||||
netty_version=4.1.119.Final
|
||||
joml_version=1.10.8
|
||||
@@ -51,7 +51,7 @@ byte_buddy_version=1.17.5
|
||||
ahocorasick_version=0.6.3
|
||||
snake_yaml_version=2.4
|
||||
anti_grief_version=0.13
|
||||
nms_helper_version=0.53
|
||||
nms_helper_version=0.54
|
||||
# Ignite Dependencies
|
||||
mixinextras_version=0.4.1
|
||||
mixin_version=0.15.2+mixin.0.8.7
|
||||
|
||||
Reference in New Issue
Block a user