From a9c9acbbf526c18b5253ba30710eda582bc4ecb0 Mon Sep 17 00:00:00 2001 From: Infinitay Date: Sat, 21 Feb 2026 07:17:58 -0500 Subject: [PATCH 1/2] refactor(surpriseexam): Use RuneLite's Gson to build the question logger - Inject RuneLite's Gson object - Rename and refactored EXAM_QUESTION_GSON_LOGGER -> gsonExamQuestionLogger - Gson logger is now built and destroyed in onStartUp and onShutdown respectively - Solves the plugin build issue of "uses terminally deprecated APIs" regarding creating "fresh Gson instances" --- .../surpriseexam/SurpriseExamHelper.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/randomeventhelper/randomevents/surpriseexam/SurpriseExamHelper.java b/src/main/java/randomeventhelper/randomevents/surpriseexam/SurpriseExamHelper.java index bc11d42..97668bc 100644 --- a/src/main/java/randomeventhelper/randomevents/surpriseexam/SurpriseExamHelper.java +++ b/src/main/java/randomeventhelper/randomevents/surpriseexam/SurpriseExamHelper.java @@ -7,7 +7,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; @@ -57,6 +56,9 @@ public class SurpriseExamHelper extends PluginModule @Inject private ChatMessageManager chatMessageManager; + @Inject + private Gson gson; + @Inject private SurpriseExamOverlay overlay; @@ -80,11 +82,7 @@ public class SurpriseExamHelper extends PluginModule private List examQuestionHistory; - private static final Gson EXAM_QUESTION_GSON_LOGGER = new GsonBuilder() - .registerTypeAdapterFactory(ExamQuestion.gsonTypeAdapterFactory()) - .serializeNulls() - .setPrettyPrinting() - .create(); + private Gson gsonExamQuestionLogger; private static final int[] PATTERNCARDS_INTERFACEIDS_AVAILABLE_CARD_MODELS = { InterfaceID.PatternCards.CARD_0, @@ -153,6 +151,11 @@ public void onStartUp() this.currentExamQuestion = null; this.examQuestionHistory = null; this.relationshipSystem = new OSRSItemRelationshipSystem(); + this.gsonExamQuestionLogger = this.gson.newBuilder() + .registerTypeAdapterFactory(ExamQuestion.gsonTypeAdapterFactory()) + .serializeNulls() + .setPrettyPrinting() + .create(); if (this.isLoggedIn()) { @@ -185,6 +188,7 @@ public void onShutdown() this.currentExamQuestion = null; this.examQuestionHistory = null; this.relationshipSystem = null; + this.gsonExamQuestionLogger = null; } @Override @@ -474,7 +478,7 @@ public void onCommandExecuted(CommandExecuted executedCommand) // In case people still use the old command name, lets add support both if (executedCommand.getCommand().equalsIgnoreCase("exportexampuzzle") || executedCommand.getCommand().equalsIgnoreCase("exportexampuzzles")) { - String json = EXAM_QUESTION_GSON_LOGGER.toJson(this.examQuestionHistory != null ? this.examQuestionHistory : ImmutableList.of()); + String json = gsonExamQuestionLogger.toJson(this.examQuestionHistory != null ? this.examQuestionHistory : ImmutableList.of()); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(new StringSelection(json), null); log.info(json); From 1ea4f8cbc34aa901bb731c0f7953f04cd0957b22 Mon Sep 17 00:00:00 2001 From: Infinitay Date: Sat, 21 Feb 2026 07:23:13 -0500 Subject: [PATCH 2/2] chore: Update version to 3.2.1 - Fix plugin build issue related to creating a fresh Gson instance instead of using RuneLite's - (surpriseexam) Refactored Gson exam question logger to be built via RuneLite's Gson instance --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index a026842..5351528 100644 --- a/build.gradle +++ b/build.gradle @@ -44,7 +44,7 @@ test { } group = 'randomeventhelper' -version = '3.2.0' +version = '3.2.1' tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8'