From 671ef69db698d19c81bdbd56dec823f38cf27e33 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 21 Jul 2021 14:33:42 -0400 Subject: [PATCH] chat commands: use script event for loading col log pets --- .../main/java/net/runelite/api/ScriptID.java | 3 + .../chatcommands/ChatCommandsPlugin.java | 81 ++++++++++--------- .../chatcommands/ChatCommandsPluginTest.java | 18 ++--- 3 files changed, 54 insertions(+), 48 deletions(-) diff --git a/runelite-api/src/main/java/net/runelite/api/ScriptID.java b/runelite-api/src/main/java/net/runelite/api/ScriptID.java index 846bd76b1f..dbde2ad2a4 100644 --- a/runelite-api/src/main/java/net/runelite/api/ScriptID.java +++ b/runelite-api/src/main/java/net/runelite/api/ScriptID.java @@ -364,4 +364,7 @@ public final class ScriptID */ @ScriptArguments(integer = 6) public static final int SETTINGS_ZOOM_SLIDER_ONDRAG = 3896; + + @ScriptArguments(integer = 6) + public static final int COLLECTION_DRAW_LIST = 2730; } \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java index fe8b03cd26..61faf69878 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java @@ -56,18 +56,19 @@ import net.runelite.api.IndexedSprite; import net.runelite.api.ItemComposition; import net.runelite.api.MessageNode; import net.runelite.api.Player; +import net.runelite.api.ScriptID; import net.runelite.api.VarPlayer; import net.runelite.api.Varbits; import net.runelite.api.WorldType; import net.runelite.api.events.ChatMessage; import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameTick; +import net.runelite.api.events.ScriptPostFired; import net.runelite.api.events.VarbitChanged; import net.runelite.api.events.WidgetLoaded; import net.runelite.api.vars.AccountType; import net.runelite.api.widgets.Widget; import static net.runelite.api.widgets.WidgetID.ADVENTURE_LOG_ID; -import static net.runelite.api.widgets.WidgetID.COLLECTION_LOG_ID; import static net.runelite.api.widgets.WidgetID.GENERIC_SCROLL_GROUP_ID; import static net.runelite.api.widgets.WidgetID.KILL_LOGS_GROUP_ID; import net.runelite.api.widgets.WidgetInfo; @@ -155,7 +156,6 @@ public class ChatCommandsPlugin extends Plugin private boolean bossLogLoaded; private boolean advLogLoaded; private boolean scrollInterfaceLoaded; - private boolean collectionLogLoaded; private String pohOwner; private HiscoreEndpoint hiscoreEndpoint; // hiscore endpoint for current player private String lastBossKill; @@ -599,39 +599,6 @@ public class ChatCommandsPlugin extends Plugin } } - if (collectionLogLoaded && (pohOwner == null || pohOwner.equals(client.getLocalPlayer().getName()))) - { - collectionLogLoaded = false; - - Widget collectionLogEntryHeader = client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_HEADER); - if (collectionLogEntryHeader != null && collectionLogEntryHeader.getChildren() != null) - { - Widget entryTitle = collectionLogEntryHeader.getChild(COL_LOG_ENTRY_HEADER_TITLE_INDEX); - // Make sure that the player is looking in the All Pets tab of the collection log - if (entryTitle.getText().equals("All Pets")) - { - Widget collectionLogEntryItems = client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_ITEMS); - if (collectionLogEntryItems != null && collectionLogEntryItems.getChildren() != null) - { - List petList = new ArrayList<>(); - for (Widget child : collectionLogEntryItems.getChildren()) - { - if (child.getOpacity() == 0) - { - Pet pet = Pet.findPet(Text.removeTags(child.getName())); - if (pet != null) - { - petList.add(pet); - } - } - } - - setPetList(petList); - } - } - } - } - if (bossLogLoaded && (pohOwner == null || pohOwner.equals(client.getLocalPlayer().getName()))) { bossLogLoaded = false; @@ -700,6 +667,47 @@ public class ChatCommandsPlugin extends Plugin } } + @Subscribe + public void onScriptPostFired(ScriptPostFired scriptPostFired) + { + if (scriptPostFired.getScriptId() != ScriptID.COLLECTION_DRAW_LIST) + { + return; + } + + if (pohOwner == null || pohOwner.equals(client.getLocalPlayer().getName())) + { + Widget collectionLogEntryHeader = client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_HEADER); + if (collectionLogEntryHeader != null && collectionLogEntryHeader.getChildren() != null) + { + Widget entryTitle = collectionLogEntryHeader.getChild(COL_LOG_ENTRY_HEADER_TITLE_INDEX); + // Make sure that the player is looking in the All Pets tab of the collection log + if (entryTitle.getText().equals("All Pets")) + { + Widget collectionLogEntryItems = client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_ITEMS); + if (collectionLogEntryItems != null && collectionLogEntryItems.getChildren() != null) + { + List petList = new ArrayList<>(); + for (Widget child : collectionLogEntryItems.getChildren()) + { + if (child.getOpacity() == 0) + { + Pet pet = Pet.findPet(Text.removeTags(child.getName())); + if (pet != null) + { + petList.add(pet); + } + } + } + + setPetList(petList); + log.debug("Loaded {} pets", petList.size()); + } + } + } + } + } + @Subscribe public void onWidgetLoaded(WidgetLoaded widget) { @@ -708,9 +716,6 @@ public class ChatCommandsPlugin extends Plugin case ADVENTURE_LOG_ID: advLogLoaded = true; break; - case COLLECTION_LOG_ID: - collectionLogLoaded = true; - break; case KILL_LOGS_GROUP_ID: bossLogLoaded = true; break; diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java index 0f2b4da035..0bd4dcac5a 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java @@ -39,12 +39,13 @@ import static net.runelite.api.ChatMessageType.TRADE; import net.runelite.api.Client; import net.runelite.api.MessageNode; import net.runelite.api.Player; +import net.runelite.api.ScriptID; import net.runelite.api.events.ChatMessage; import net.runelite.api.events.GameTick; +import net.runelite.api.events.ScriptPostFired; import net.runelite.api.events.WidgetLoaded; import net.runelite.api.widgets.Widget; import static net.runelite.api.widgets.WidgetID.ADVENTURE_LOG_ID; -import static net.runelite.api.widgets.WidgetID.COLLECTION_LOG_ID; import static net.runelite.api.widgets.WidgetID.GENERIC_SCROLL_GROUP_ID; import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.chat.ChatCommandManager; @@ -986,9 +987,8 @@ public class ChatCommandsPluginTest when(logEntryItemsWidget.getChildren()).thenReturn(logPetEntriesWidget); - WidgetLoaded logEvent = new WidgetLoaded(); - logEvent.setGroupId(COLLECTION_LOG_ID); - chatCommandsPlugin.onWidgetLoaded(logEvent); + ScriptPostFired scriptPostFired = new ScriptPostFired(ScriptID.COLLECTION_DRAW_LIST); + chatCommandsPlugin.onScriptPostFired(scriptPostFired); chatCommandsPlugin.onGameTick(new GameTick()); @@ -1024,9 +1024,8 @@ public class ChatCommandsPluginTest when(logEntryItemsWidget.getChildren()).thenReturn(logPetEntriesWidget); - WidgetLoaded logEvent = new WidgetLoaded(); - logEvent.setGroupId(COLLECTION_LOG_ID); - chatCommandsPlugin.onWidgetLoaded(logEvent); + ScriptPostFired scriptPostFired = new ScriptPostFired(ScriptID.COLLECTION_DRAW_LIST); + chatCommandsPlugin.onScriptPostFired(scriptPostFired); chatCommandsPlugin.onGameTick(new GameTick()); @@ -1062,9 +1061,8 @@ public class ChatCommandsPluginTest when(logEntryItemsWidget.getChildren()).thenReturn(logPetEntriesWidget); - WidgetLoaded logEvent = new WidgetLoaded(); - logEvent.setGroupId(COLLECTION_LOG_ID); - chatCommandsPlugin.onWidgetLoaded(logEvent); + ScriptPostFired scriptPostFired = new ScriptPostFired(ScriptID.COLLECTION_DRAW_LIST); + chatCommandsPlugin.onScriptPostFired(scriptPostFired); chatCommandsPlugin.onGameTick(new GameTick());