Skip to content

Commit

Permalink
Combined bugfixes (#97)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
larsvansoest authored Jun 7, 2023
1 parent 78b9c90 commit 8557bc8
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 35 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,7 +24,7 @@ dependencies {
}

group = 'com.larsvansoest.runelite'
version = '4.2.0'
version = '4.2.1'
sourceCompatibility = '1.8'

tasks.withType(JavaCompile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public class EmoteClueItemsPlugin extends Plugin
private Integer cachedPlayerConstructionLevel;
private boolean readWatsonOnNextGameTick;

private boolean isPlayerLoggedIn;

@Override
protected void startUp()
{
Expand All @@ -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"
);
Expand Down Expand Up @@ -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<String> 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<String> 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)
{
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -171,16 +173,16 @@ else if (id == Widget.GROUP_STORAGE_INVENTORY.id)
}
}

public static boolean TryReadWatsonBoard(final Client client, final BiConsumer<String, Boolean> 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<EmoteClueDifficulty, BiConsumer<String, Boolean>> 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<String, Boolean> stashUnitFillStatusCallback) {
private static boolean TryReadWatsonBoard(Widget watsonNoticeBoard, final Client client, final BiConsumer<String, Boolean> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,6 +46,7 @@ public ProgressManager(
final BiConsumer<EmoteClueItem, StatusPanel.Status> onEmoteClueItemStatusChanged)
{
this.client = client;
this.clientThread = clientThread;
this.config = config;
this.inventoryMonitor = new InventoryMonitor(config, itemManager);
this.stashMonitor = new StashMonitor(configManager);
Expand Down Expand Up @@ -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));
});
}

/**
Expand Down

0 comments on commit 8557bc8

Please # to comment.