From b61974e2be3d7f4a41f6db61fe8af160780f4b42 Mon Sep 17 00:00:00 2001 From: asdf <11447537+rl-enjoyer@users.noreply.github.com> Date: Tue, 24 Mar 2026 09:01:47 -0400 Subject: [PATCH] persist listedPrice in offer JSON export MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The listedPrice field (the user's GE offer price) was marked transient, so it was lost on serialization. External tools reading lastOffers from the JSON export had no way to know the offer price for unfilled slots (the existing "p" field only records avg fill price, which is 0 when nothing has filled). Remove transient and add @SerializedName("lp") so the listed price is written to disk. Backward compatible — old files without "lp" deserialize to 0 (same as today), and lastOffers is overwritten on login anyway. Also add OfferEventSerializationTest with round-trip and backward compat test cases, and register in TestRunner. Co-Authored-By: Claude Opus 4.6 --- .../flippingutilities/model/OfferEvent.java | 6 +- .../OfferEventSerializationTest.java | 97 +++++++++++++++++++ .../com/flippingutilities/TestRunner.java | 3 +- 3 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 src/test/java/com/flippingutilities/OfferEventSerializationTest.java diff --git a/src/main/java/com/flippingutilities/model/OfferEvent.java b/src/main/java/com/flippingutilities/model/OfferEvent.java index 2afe02ed..b44361e3 100644 --- a/src/main/java/com/flippingutilities/model/OfferEvent.java +++ b/src/main/java/com/flippingutilities/model/OfferEvent.java @@ -93,8 +93,10 @@ public class OfferEvent //Used in theGeHistoryTabOfferPanel and RecipeFlipPanel private transient String itemName; - //used in the live slot view to show what price something was listed at - private transient int listedPrice; + //used in the live slot view to show what price something was listed at. + //persisted so external tools can see the offer price for unfilled slots. + @SerializedName("lp") + private int listedPrice; private transient int spent; /** diff --git a/src/test/java/com/flippingutilities/OfferEventSerializationTest.java b/src/test/java/com/flippingutilities/OfferEventSerializationTest.java new file mode 100644 index 00000000..fe7287d1 --- /dev/null +++ b/src/test/java/com/flippingutilities/OfferEventSerializationTest.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2020, Belieal + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.flippingutilities; + +import com.flippingutilities.model.OfferEvent; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import net.runelite.api.GrandExchangeOfferState; +import net.runelite.http.api.RuneLiteAPI; +import org.junit.Test; + +import java.time.Instant; +import java.util.UUID; + +import static org.junit.Assert.*; + +public class OfferEventSerializationTest +{ + private final Gson gson = RuneLiteAPI.GSON; + + @Test + public void listedPriceSurvivesRoundTrip() + { + OfferEvent offer = new OfferEvent( + UUID.randomUUID().toString(), + false, // selling + 2283, // item id + 0, // currentQuantityInTrade (nothing filled) + 0, // price (no fills yet) + Instant.parse("2024-01-01T00:00:00Z"), + 1, // slot + GrandExchangeOfferState.SELLING, + 0, // tickArrivedAt + 0, // ticksSinceFirstOffer + 1560, // totalQuantityInTrade + null, // tradeStartedAt + false, // beforeLogin + null, // madeBy (transient) + null, // itemName (transient) + 136, // listedPrice — the offer price we want persisted + 0); // spent (transient) + + String json = gson.toJson(offer); + + // Verify "lp" key is present in output + JsonObject obj = new JsonParser().parse(json).getAsJsonObject(); + assertTrue("JSON should contain 'lp' key", obj.has("lp")); + assertEquals(136, obj.get("lp").getAsInt()); + + // Round-trip: deserialize and verify listedPrice survived + OfferEvent restored = gson.fromJson(json, OfferEvent.class); + assertEquals(136, restored.getListedPrice()); + assertEquals(2283, restored.getItemId()); + assertEquals(0, restored.getPreTaxPrice()); + assertEquals(1560, restored.getTotalQuantityInTrade()); + assertEquals(GrandExchangeOfferState.SELLING, restored.getState()); + } + + @Test + public void oldJsonWithoutListedPriceDefaultsToZero() + { + // Simulate JSON from before this change — no "lp" field + String oldJson = "{\"uuid\":\"abc\",\"b\":true,\"id\":4151,\"cQIT\":10,\"p\":1500," + + "\"t\":{\"seconds\":1704067200,\"nanos\":0}," + + "\"s\":3,\"st\":\"BUYING\",\"tAA\":0,\"tSFO\":5,\"tQIT\":100}"; + + OfferEvent restored = gson.fromJson(oldJson, OfferEvent.class); + assertEquals(0, restored.getListedPrice()); + assertEquals(4151, restored.getItemId()); + assertEquals(100, restored.getTotalQuantityInTrade()); + } +} diff --git a/src/test/java/com/flippingutilities/TestRunner.java b/src/test/java/com/flippingutilities/TestRunner.java index c08bead2..6e841608 100644 --- a/src/test/java/com/flippingutilities/TestRunner.java +++ b/src/test/java/com/flippingutilities/TestRunner.java @@ -36,7 +36,8 @@ @RunWith(Suite.class) @Suite.SuiteClasses({ HistoryManagerTest.class, - FlippingPluginTest.class + FlippingPluginTest.class, + OfferEventSerializationTest.class }) public class TestRunner {