From 2601d04a285478e8e8245308e586faf638bc162a Mon Sep 17 00:00:00 2001 From: Patbox <39821509+Patbox@users.noreply.github.com> Date: Tue, 30 Nov 2021 22:08:08 +0100 Subject: [PATCH] Fix emoticons not working --- gradle.properties | 8 ++++---- .../java/eu/pb4/styledchat/StyledChatUtils.java | 13 ++++++++++++- src/main/java/eu/pb4/styledchat/config/Config.java | 3 ++- .../eu/pb4/styledchat/config/data/ConfigData.java | 11 ++++++++++- .../mixin/ServerPlayNetworkManagerMixin.java | 11 +++++------ 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/gradle.properties b/gradle.properties index c396ea4..290df9e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=1.18-rc1 - yarn_mappings=1.18-rc1+build.1 - loader_version=0.12.5 + minecraft_version=1.18 + yarn_mappings=1.18+build.1 + loader_version=0.12.6 #Fabric api fabric_version=0.43.1+1.18 # Mod Properties - mod_version = 1.2.1+1.18 + mod_version = 1.2.2+1.18 maven_group = eu.pb4 archives_base_name = styled-chat diff --git a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java index 0a1ea99..20dfad3 100644 --- a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java +++ b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java @@ -67,6 +67,11 @@ public static Map getHandlers(ServerPla } } + if (config.defaultFormattingCodes.getBoolean(SPOILER_TAG) + || Permissions.check(source, FORMAT_PERMISSION_BASE + SPOILER_TAG, 2)) { + handlers.put(SPOILER_TAG, SPOILER_TAG_HANDLER); + } + if (handlers.containsKey("light_purple")) { handlers.put("pink", handlers.get("light_purple")); } @@ -170,7 +175,13 @@ public Text get(Object key) { } text = this.texts.get(key); - return text != null ? this.cache.put((String) key, this.getParsed(text)) : null; + + if (text != null) { + var out = this.getParsed(text); + this.cache.put((String) key, out); + return out; + } + return null; } @NotNull diff --git a/src/main/java/eu/pb4/styledchat/config/Config.java b/src/main/java/eu/pb4/styledchat/config/Config.java index 0815a06..0d47b1d 100644 --- a/src/main/java/eu/pb4/styledchat/config/Config.java +++ b/src/main/java/eu/pb4/styledchat/config/Config.java @@ -55,9 +55,10 @@ public Config(ConfigData data) { for (var entry : data.permissionEmoticons) { var emotes = PermissionEmotes.of(entry.permission, entry.opLevel); - for (var emote : entry.emotes.entrySet()) { + for (var emote : entry.emoticons.entrySet()) { emotes.emotes().put(emote.getKey(), TextParser.parse(emote.getValue())); } + this.permissionEmotes.add(emotes); } diff --git a/src/main/java/eu/pb4/styledchat/config/data/ConfigData.java b/src/main/java/eu/pb4/styledchat/config/data/ConfigData.java index dc1140e..7e0146a 100644 --- a/src/main/java/eu/pb4/styledchat/config/data/ConfigData.java +++ b/src/main/java/eu/pb4/styledchat/config/data/ConfigData.java @@ -89,6 +89,13 @@ public static ConfigData transform(ConfigData configData) { } + for (var entry : configData.permissionEmoticons) { + if (entry.emotes != null) { + entry.emoticons = entry.emotes; + entry.emotes = null; + } + } + return configData; } @@ -108,6 +115,8 @@ public static PermissionPriorityStyle of(String permission, ChatStyleData style) public static class PermissionEmotes { public String permission = ""; public int opLevel = 3; - public Map emotes = Collections.EMPTY_MAP; + public Map emoticons = Collections.EMPTY_MAP; + @Deprecated + public Map emotes = null; } } diff --git a/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java b/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java index bff8231..1f8be2c 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java @@ -52,11 +52,10 @@ private void styledChat_replaceChatMessage(PlayerManager playerManager, Text ser rawMessage = StyledChatEvents.PRE_MESSAGE_CONTENT_SEND.invoker().onPreMessage(message.getRaw(), player, false); rawMessage = StyledChatUtils.formatMessage(rawMessage, handlers); - Text rawText = config.getChat(this.player, StyledChatEvents.MESSAGE_CONTENT_SEND.invoker().onMessage(handlers.size() > 0 ? PlaceholderAPI.parsePredefinedText(TextParser.parse(rawMessage, handlers), StyledChatUtils.EMOTE_PATTERN, emotes) - : new LiteralText(message.getRaw()), + : PlaceholderAPI.parsePredefinedText(new LiteralText(message.getRaw()), StyledChatUtils.EMOTE_PATTERN, emotes), player, false) ); @@ -72,14 +71,14 @@ private void styledChat_replaceChatMessage(PlayerManager playerManager, Text ser Text rawText = config.getChat(this.player, StyledChatEvents.MESSAGE_CONTENT_SEND.invoker().onMessage(handlers.size() > 0 - ? TextParser.parse(rawMessage, handlers) - : new LiteralText(message.getRaw()), + ? PlaceholderAPI.parsePredefinedText(TextParser.parse(rawMessage, handlers), StyledChatUtils.EMOTE_PATTERN, emotes) + : PlaceholderAPI.parsePredefinedText(new LiteralText(message.getRaw()), StyledChatUtils.EMOTE_PATTERN, emotes), player, false) ); Text filteredText = config.getChat(this.player, StyledChatEvents.MESSAGE_CONTENT_SEND.invoker().onMessage(handlers.size() > 0 - ? TextParser.parse(filteredMessage, handlers) - : new LiteralText(message.getFiltered()), + ? PlaceholderAPI.parsePredefinedText(TextParser.parse(filteredMessage, handlers), StyledChatUtils.EMOTE_PATTERN, emotes) + : PlaceholderAPI.parsePredefinedText(new LiteralText(message.getFiltered()), StyledChatUtils.EMOTE_PATTERN, emotes), player, true) );