From 1ed5e3b38a18eaf6c52a4ae67cbb15a841ed39bc Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Fri, 11 Apr 2025 20:21:08 +0800 Subject: [PATCH] =?UTF-8?q?perf(bukkit):=20=E4=BC=98=E5=8C=96=E8=A1=A8?= =?UTF-8?q?=E6=83=85=E5=BB=BA=E8=AE=AE=E7=9A=84=E6=B7=BB=E5=8A=A0=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bukkit/font/BukkitFontManager.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/font/BukkitFontManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/font/BukkitFontManager.java index 6b3a6a440..a06665ba7 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/font/BukkitFontManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/font/BukkitFontManager.java @@ -67,14 +67,29 @@ public class BukkitFontManager extends AbstractFontManager implements Listener { 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); + this.addEmojiSuggestions(player); }); } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - FastNMS.INSTANCE.method$ChatSuggestions$add(this.cachedEmojiSuggestions(), player); + this.addEmojiSuggestions(player); + } + + private void addEmojiSuggestions(Player player) { + Map hasPermissions = new HashMap<>(); + Map cachedEmojiSuggestions = this.cachedEmojiSuggestions(); + for (UUID uuid : cachedEmojiSuggestions.keySet()) { + String keyword = cachedEmojiSuggestions.get(uuid); + Emoji emoji = super.emojiMapper.get(keyword); + if (emoji == null) continue; + if (emoji.permission() != null && !player.hasPermission(Objects.requireNonNull(emoji.permission()))) { + continue; + } + hasPermissions.put(uuid, keyword); + } + FastNMS.INSTANCE.method$ChatSuggestions$add(hasPermissions, player); } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)