diff --git a/CHANGELOG.md b/CHANGELOG.md index ea5c7733..8e467a6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +# [2004.2.3] + +### Fixed +* Fixed raw json text in quest descriptions not always being recognised +* Fixed chapter and chapter group creation popups moving in and out with the chapter panel when it's not pinned + # [2004.2.2] ### Added diff --git a/common/src/main/java/dev/ftb/mods/ftbquests/client/gui/quests/ChapterPanel.java b/common/src/main/java/dev/ftb/mods/ftbquests/client/gui/quests/ChapterPanel.java index 39661d46..da078f97 100644 --- a/common/src/main/java/dev/ftb/mods/ftbquests/client/gui/quests/ChapterPanel.java +++ b/common/src/main/java/dev/ftb/mods/ftbquests/client/gui/quests/ChapterPanel.java @@ -189,7 +189,7 @@ public void onClicked(MouseButton button) { List contextMenu = new ArrayList<>(); contextMenu.add(new ContextMenuItem(Component.translatable("ftbquests.chapter"), ThemeProperties.ADD_ICON.get(), b -> { StringConfig c = new StringConfig(Pattern.compile("^.+$")); - EditStringConfigOverlay overlay = new EditStringConfigOverlay<>(parent, c, accepted -> { + EditStringConfigOverlay overlay = new EditStringConfigOverlay<>(parent.getParent(), c, accepted -> { chapterPanel.questScreen.openGui(); if (accepted && !c.getValue().isEmpty()) { @@ -209,7 +209,7 @@ public void onClicked(MouseButton button) { contextMenu.add(new ContextMenuItem(Component.translatable("ftbquests.chapter_group"), ThemeProperties.ADD_ICON.get(), b -> { StringConfig c = new StringConfig(Pattern.compile("^.+$")); - EditStringConfigOverlay overlay = new EditStringConfigOverlay<>(parent, c, accepted -> { + EditStringConfigOverlay overlay = new EditStringConfigOverlay<>(parent.getParent(), c, accepted -> { chapterPanel.questScreen.openGui(); if (accepted) { @@ -286,7 +286,7 @@ public void onClicked(MouseButton button) { playClickSound(); StringConfig c = new StringConfig(Pattern.compile("^.+$")); - EditStringConfigOverlay overlay = new EditStringConfigOverlay<>(parent, c, accepted -> { + EditStringConfigOverlay overlay = new EditStringConfigOverlay<>(parent.getParent(), c, accepted -> { chapterPanel.questScreen.openGui(); if (accepted && !c.getValue().isEmpty()) { diff --git a/common/src/main/java/dev/ftb/mods/ftbquests/util/TextUtils.java b/common/src/main/java/dev/ftb/mods/ftbquests/util/TextUtils.java index e13532c5..dbb90404 100644 --- a/common/src/main/java/dev/ftb/mods/ftbquests/util/TextUtils.java +++ b/common/src/main/java/dev/ftb/mods/ftbquests/util/TextUtils.java @@ -2,32 +2,29 @@ import com.google.gson.JsonParseException; import dev.ftb.mods.ftblibrary.util.client.ClientTextComponentUtils; -import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; - -import java.util.regex.Pattern; +import net.minecraft.network.chat.MutableComponent; public class TextUtils { - private static final Pattern JSON_TEXT_PATTERN = Pattern.compile("^[{\\[]\\s*\""); - /** - * Parse some rich text into a Component. Use vanilla-style raw JSON if possible, fall back to old-style FTB + * Parse some rich text into a Component. Use vanilla-style raw JSON if applicable, fall back to old-style FTB * Quests rich text otherwise. (FTB Quests rich text is more concise, raw JSON is much more powerful) * * @param str the raw string to parse * @return a component, which could be the error message if parsing failed */ public static Component parseRawText(String str) { - return JSON_TEXT_PATTERN.matcher(str).find() ? - deserializeRawJsonText(str) : - ClientTextComponentUtils.parse(str); - } - - private static Component deserializeRawJsonText(String raw) { - try { - return Component.Serializer.fromJson(raw); - } catch (JsonParseException e) { - return Component.literal("ERROR: " + e.getMessage()).withStyle(ChatFormatting.RED); + String str2 = str.trim(); + if (str2.startsWith("[") && str2.endsWith("]") || str2.startsWith("{") && str2.endsWith("}")) { + // could be JSON raw text, but not for definite... + try { + MutableComponent res = Component.Serializer.fromJson(str2); + if (res != null) { + return res; + } + } catch (JsonParseException ignored) { + } } + return ClientTextComponentUtils.parse(str); } } diff --git a/gradle.properties b/gradle.properties index f3cff059..fe7d040d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ archives_base_name=ftb-quests minecraft_version=1.20.4 # Build time -mod_version=2004.2.2 +mod_version=2004.2.3 maven_group=dev.ftb.mods mod_author=FTB Team