From 8557bc829a64bf956c2dd5e7e30acd752a3f9ee7 Mon Sep 17 00:00:00 2001 From: Lars van Soest Date: Wed, 7 Jun 2023 13:06:15 +0200 Subject: [PATCH] Combined bugfixes (#97) * Added client thread invoke when processing inventory changes. * Include difficulty when looking up stash from watson to distinguish warriors guild duplicates. * Set plugin version to 4.2.1. Fix area lag. Fix profiles null exception. --- build.gradle | 4 +- .../clueitems/EmoteClueItemsPlugin.java | 63 ++++++++++++------- .../runelite/clueitems/data/StashUnit.java | 6 +- .../clueitems/overlay/WidgetInspector.java | 18 +++--- .../clueitems/progress/ProgressManager.java | 6 +- 5 files changed, 62 insertions(+), 35 deletions(-) diff --git a/build.gradle b/build.gradle index aefdf82..d807887 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ repositories { mavenCentral() } -def runeLiteVersion = '1.9.11.2' +def runeLiteVersion = '1.10.4' dependencies { compileOnly group: 'net.runelite', name: 'client', version: runeLiteVersion @@ -24,7 +24,7 @@ dependencies { } group = 'com.larsvansoest.runelite' -version = '4.2.0' +version = '4.2.1' sourceCompatibility = '1.8' tasks.withType(JavaCompile) { diff --git a/src/main/java/com/larsvansoest/runelite/clueitems/EmoteClueItemsPlugin.java b/src/main/java/com/larsvansoest/runelite/clueitems/EmoteClueItemsPlugin.java index 8e41efd..eded4b2 100644 --- a/src/main/java/com/larsvansoest/runelite/clueitems/EmoteClueItemsPlugin.java +++ b/src/main/java/com/larsvansoest/runelite/clueitems/EmoteClueItemsPlugin.java @@ -104,6 +104,8 @@ public class EmoteClueItemsPlugin extends Plugin private Integer cachedPlayerConstructionLevel; private boolean readWatsonOnNextGameTick; + private boolean isPlayerLoggedIn; + @Override protected void startUp() { @@ -115,7 +117,7 @@ protected void startUp() this::addStashUnitMarkerToMap, this::removeStashUnitMarkerFromMap, "Emote Clue Items", - "v4.2.0", + "v4.2.1", "https://github.com/larsvansoest/emote-clue-items", "https://www.paypal.com/donate/?hosted_button_id=72AFNGL28LFEN" ); @@ -230,25 +232,28 @@ private void updatePlayerConstructionLevel(Integer level) { private void setupUnopenedInterfaceNotification() { - if (this.client.getGameState() == GameState.LOGGED_IN) + this.clientThread.invoke(() -> { - this.emoteClueItemsPanel.removeEmoteClueItemGridDisclaimer(); - if (this.showUnopenedInterfaceNotification) + if (this.client.getGameState() == GameState.LOGGED_IN) { - final List unopenedInterfaces = this.progressManager.getUnopenedInterfaces(); - if (this.config.notifyUnopenedInterfaces() && unopenedInterfaces.size() > 0) + this.emoteClueItemsPanel.removeEmoteClueItemGridDisclaimer(); + if (this.showUnopenedInterfaceNotification) { - final String notification = String.format("Not all items may be displayed. Please open your %s first.", String.join(", ", unopenedInterfaces)); - this.emoteClueItemsPanel.setEmoteClueItemGridDisclaimer(notification, () -> + final List unopenedInterfaces = this.progressManager.getUnopenedInterfaces(); + if (this.config.notifyUnopenedInterfaces() && unopenedInterfaces.size() > 0) { - this.showUnopenedInterfaceNotification = false; - }); + final String notification = String.format("Not all items may be displayed. Please open your %s first.", String.join(", ", unopenedInterfaces)); + this.emoteClueItemsPanel.setEmoteClueItemGridDisclaimer(notification, () -> + { + this.showUnopenedInterfaceNotification = false; + }); + } } } - } + }); } - private void toggleCollectionLog(final boolean visible) + private void toggleCollectionLog(final boolean visible) { if (visible) { @@ -280,10 +285,13 @@ protected void onGameStateChanged(final GameStateChanged event) if (event.getGameState() == GameState.LOGIN_SCREEN) { this.reset(); + this.isPlayerLoggedIn = false; } - if (event.getGameState() == GameState.LOGGED_IN) + if (!isPlayerLoggedIn && + event.getGameState() == GameState.LOGGED_IN) { this.onPlayerLoggedIn(); + this.isPlayerLoggedIn = true; } } @@ -320,13 +328,13 @@ public void onGameTick(final GameTick event) } if (this.readWatsonOnNextGameTick) { - final boolean readComplete = WidgetInspector.TryReadWatsonBoard(this.client, (watsonLocation, filled) -> { - StashUnit stashUnit = StashUnit.fromWatsonLocation(watsonLocation); + final boolean readComplete = WidgetInspector.TryReadWatsonBoard(this.client, (difficulty -> (watsonLocation, filled) -> { + StashUnit stashUnit = StashUnit.fromWatsonLocation(watsonLocation, difficulty); if(Objects.nonNull(stashUnit)) { this.progressManager.setStashUnitFilled(stashUnit, filled); this.emoteClueItemsPanel.setStashUnitFilledStatus(stashUnit, filled); } - }); + })); this.readWatsonOnNextGameTick = !readComplete; } } @@ -335,34 +343,43 @@ public void onGameTick(final GameTick event) protected void onConfigChanged(final ConfigChanged event) { final String key = event.getKey(); + + // Switching to a new config profile sets values to null; + final boolean isNull = Objects.isNull(event.getNewValue()); + final boolean isTrue = !isNull && event.getNewValue().equals("true"); + + // If null, use config default + final boolean isTrueOrDefaultTrue = isNull || isTrue; + final boolean isTrueOrDefaultFalse = !isNull && isTrue; + switch (key) { case "TrackBank": - this.progressManager.toggleBankTracking(event.getNewValue().equals("true")); + this.progressManager.toggleBankTracking(isTrueOrDefaultTrue); this.setupUnopenedInterfaceNotification(); break; case "TrackInventory": - this.progressManager.toggleInventoryTracking(event.getNewValue().equals("true")); + this.progressManager.toggleInventoryTracking(isTrueOrDefaultTrue); this.setupUnopenedInterfaceNotification(); break; case "TrackEquipment": - this.progressManager.toggleEquipmentTracking(event.getNewValue().equals("true")); + this.progressManager.toggleEquipmentTracking(isTrueOrDefaultTrue); this.setupUnopenedInterfaceNotification(); break; case "TrackGroupStorage": - this.progressManager.toggleGroupStorageTracking(event.getNewValue().equals("true")); + this.progressManager.toggleGroupStorageTracking(isTrueOrDefaultFalse); this.setupUnopenedInterfaceNotification(); break; case "NotifyUnopenedInterfaces": - this.showUnopenedInterfaceNotification = event.getNewValue().equals("true"); + this.showUnopenedInterfaceNotification = isTrueOrDefaultTrue; this.setupUnopenedInterfaceNotification(); break; case "ShowNavigation": - this.toggleCollectionLog(event.getNewValue().equals("true")); + this.toggleCollectionLog(isTrueOrDefaultTrue); break; case "AutoSyncWatsonBoard": final boolean isWatsonBoardOpen = Objects.nonNull(this.client.getWidget(493, 0)); - this.readWatsonOnNextGameTick = event.getNewValue().equals("true") && isWatsonBoardOpen; + this.readWatsonOnNextGameTick = isWatsonBoardOpen && isTrueOrDefaultFalse; break; default: break; diff --git a/src/main/java/com/larsvansoest/runelite/clueitems/data/StashUnit.java b/src/main/java/com/larsvansoest/runelite/clueitems/data/StashUnit.java index 6f2eb95..ef57e3c 100644 --- a/src/main/java/com/larsvansoest/runelite/clueitems/data/StashUnit.java +++ b/src/main/java/com/larsvansoest/runelite/clueitems/data/StashUnit.java @@ -150,7 +150,11 @@ public enum StashUnit * @param watsonLocation - The text from the watson notice board. * @return the StashUnit, null if no match was found. */ - public static StashUnit fromWatsonLocation(String watsonLocation) { + public static StashUnit fromWatsonLocation(String watsonLocation, EmoteClueDifficulty difficulty) { + // warrior guild STASHes have the same board name + if (watsonLocation.equals("Warriors' Guild bank")) { + return difficulty.equals(EmoteClueDifficulty.Elite) ? WARRIORS_GUILD_BANK : WARRIORS_GUILD_BANK_29047; + } for(StashUnit stashUnit : StashUnit.values()) { if (stashUnit.getWatsonLocation().equals(formatWatsonLocation(watsonLocation))) { return stashUnit; diff --git a/src/main/java/com/larsvansoest/runelite/clueitems/overlay/WidgetInspector.java b/src/main/java/com/larsvansoest/runelite/clueitems/overlay/WidgetInspector.java index 40a20ea..741e44c 100644 --- a/src/main/java/com/larsvansoest/runelite/clueitems/overlay/WidgetInspector.java +++ b/src/main/java/com/larsvansoest/runelite/clueitems/overlay/WidgetInspector.java @@ -28,11 +28,13 @@ package com.larsvansoest.runelite.clueitems.overlay; +import com.larsvansoest.runelite.clueitems.data.EmoteClueDifficulty; import net.runelite.api.Client; import net.runelite.api.widgets.WidgetItem; import java.util.Objects; import java.util.function.BiConsumer; +import java.util.function.Function; /** * Utility class with Runescape item container widget inspection functionality. @@ -171,16 +173,16 @@ else if (id == Widget.GROUP_STORAGE_INVENTORY.id) } } - public static boolean TryReadWatsonBoard(final Client client, final BiConsumer stashUnitFillStatusCallback) { - return TryReadWatsonBoard(Widget.WATSON_NOTICE_BOARD_BEGINNER, client, stashUnitFillStatusCallback) - | TryReadWatsonBoard(Widget.WATSON_NOTICE_BOARD_EASY, client, stashUnitFillStatusCallback) - | TryReadWatsonBoard(Widget.WATSON_NOTICE_BOARD_MEDIUM, client, stashUnitFillStatusCallback) - | TryReadWatsonBoard(Widget.WATSON_NOTICE_BOARD_HARD, client, stashUnitFillStatusCallback) - | TryReadWatsonBoard(Widget.WATSON_NOTICE_BOARD_ELITE, client, stashUnitFillStatusCallback) - | TryReadWatsonBoard(Widget.WATSON_NOTICE_BOARD_MASTER, client, stashUnitFillStatusCallback); + public static boolean TryReadWatsonBoard(final Client client, final Function> stashUnitFillStatusCallback) { + return TryReadWatsonBoard(Widget.WATSON_NOTICE_BOARD_BEGINNER, client, stashUnitFillStatusCallback.apply(EmoteClueDifficulty.Beginner)) + | TryReadWatsonBoard(Widget.WATSON_NOTICE_BOARD_EASY, client, stashUnitFillStatusCallback.apply(EmoteClueDifficulty.Easy)) + | TryReadWatsonBoard(Widget.WATSON_NOTICE_BOARD_MEDIUM, client, stashUnitFillStatusCallback.apply(EmoteClueDifficulty.Medium)) + | TryReadWatsonBoard(Widget.WATSON_NOTICE_BOARD_HARD, client, stashUnitFillStatusCallback.apply(EmoteClueDifficulty.Hard)) + | TryReadWatsonBoard(Widget.WATSON_NOTICE_BOARD_ELITE, client, stashUnitFillStatusCallback.apply(EmoteClueDifficulty.Elite)) + | TryReadWatsonBoard(Widget.WATSON_NOTICE_BOARD_MASTER, client, stashUnitFillStatusCallback.apply(EmoteClueDifficulty.Master)); } - private static boolean TryReadWatsonBoard(final Widget watsonNoticeBoard, final Client client, final BiConsumer stashUnitFillStatusCallback) { + private static boolean TryReadWatsonBoard(Widget watsonNoticeBoard, final Client client, final BiConsumer stashUnitFillStatusCallback) { final net.runelite.api.widgets.Widget stashListWidget = client.getWidget(watsonNoticeBoard.groupId, watsonNoticeBoard.childId); if (Objects.isNull(stashListWidget)) return false; final net.runelite.api.widgets.Widget[] stashListWidgetChildren = stashListWidget.getChildren(); diff --git a/src/main/java/com/larsvansoest/runelite/clueitems/progress/ProgressManager.java b/src/main/java/com/larsvansoest/runelite/clueitems/progress/ProgressManager.java index ec3ad7c..76902b5 100644 --- a/src/main/java/com/larsvansoest/runelite/clueitems/progress/ProgressManager.java +++ b/src/main/java/com/larsvansoest/runelite/clueitems/progress/ProgressManager.java @@ -30,6 +30,7 @@ public class ProgressManager { private final Client client; + private final ClientThread clientThread; private final EmoteClueItemsConfig config; private final InventoryMonitor inventoryMonitor; private final StashMonitor stashMonitor; @@ -45,6 +46,7 @@ public ProgressManager( final BiConsumer onEmoteClueItemStatusChanged) { this.client = client; + this.clientThread = clientThread; this.config = config; this.inventoryMonitor = new InventoryMonitor(config, itemManager); this.stashMonitor = new StashMonitor(configManager); @@ -92,7 +94,9 @@ public void reset() */ public void processInventoryChanges(final int containerId, final Item[] items) { - this.handleItemChanges(this.inventoryMonitor.fetchEmoteClueItemChanges(containerId, items)); + this.clientThread.invoke(() -> { + this.handleItemChanges(this.inventoryMonitor.fetchEmoteClueItemChanges(containerId, items)); + }); } /**