From b0677e68e95c9e58872b106cc7615a4e2cfc5302 Mon Sep 17 00:00:00 2001 From: Max Weber Date: Wed, 3 Jun 2020 15:51:04 -0600 Subject: [PATCH] chatcommands: don't throw every tick if the player has opened a scroll This interface is used in many other places --- .../net/runelite/api/widgets/WidgetID.java | 5 +- .../net/runelite/api/widgets/WidgetInfo.java | 2 +- .../chatcommands/ChatCommandsPlugin.java | 53 ++++++++++--------- .../chatcommands/ChatCommandsPluginTest.java | 12 ++--- 4 files changed, 37 insertions(+), 35 deletions(-) diff --git a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java index 2a9927894a..7f31f41813 100644 --- a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java +++ b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java @@ -152,7 +152,7 @@ public class WidgetID public static final int LMS_GROUP_ID = 333; public static final int LMS_INGAME_GROUP_ID = 328; public static final int ADVENTURE_LOG_ID = 187; - public static final int COUNTERS_LOG_GROUP_ID = 625; + public static final int GENERIC_SCROLL_GROUP_ID = 625; public static final int GAUNTLET_TIMER_GROUP_ID = 637; public static final int BANK_PIN_GROUP_ID = 213; @@ -915,9 +915,8 @@ public class WidgetID static final int CONTAINER = 0; } - static class CountersLog + static class GenericScroll { - static final int OWNER = 4; static final int TEXT = 6; } diff --git a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java index 1372874a20..f9534c96f1 100644 --- a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java +++ b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java @@ -488,7 +488,7 @@ public enum WidgetInfo ADVENTURE_LOG(WidgetID.ADVENTURE_LOG_ID, WidgetID.AdventureLog.CONTAINER), - COUNTERS_LOG_TEXT(WidgetID.COUNTERS_LOG_GROUP_ID, WidgetID.CountersLog.TEXT), + GENERIC_SCROLL_TEXT(WidgetID.GENERIC_SCROLL_GROUP_ID, WidgetID.GenericScroll.TEXT), WORLD_SWITCHER_LIST(WidgetID.WORLD_SWITCHER_GROUP_ID, WidgetID.WorldSwitcher.WORLD_LIST), 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 0b129164af..7549d22106 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,7 +56,7 @@ 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.COUNTERS_LOG_GROUP_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; import net.runelite.client.chat.ChatColorType; @@ -132,7 +132,7 @@ public class ChatCommandsPlugin extends Plugin private boolean bossLogLoaded; private boolean advLogLoaded; - private boolean countersLogLoaded; + private boolean scrollInterfaceLoaded; private String pohOwner; private HiscoreEndpoint hiscoreEndpoint; // hiscore endpoint for current player private String lastBossKill; @@ -497,36 +497,39 @@ public class ChatCommandsPlugin extends Plugin } } - if (countersLogLoaded && pohOwner.equals(client.getLocalPlayer().getName())) + if (scrollInterfaceLoaded) { - countersLogLoaded = false; + scrollInterfaceLoaded = false; - String counterText = Text.sanitizeMultilineText(client.getWidget(WidgetInfo.COUNTERS_LOG_TEXT).getText()); - Matcher mCounterText = ADVENTURE_LOG_PB_PATTERN.matcher(counterText); - while (mCounterText.find()) + if (client.getLocalPlayer().getName().equals(pohOwner)) { - String bossName = longBossName(mCounterText.group(1)); - if (bossName.equalsIgnoreCase("chambers of xeric") || - bossName.equalsIgnoreCase("chambers of xeric challenge mode")) + String counterText = Text.sanitizeMultilineText(client.getWidget(WidgetInfo.GENERIC_SCROLL_TEXT).getText()); + Matcher mCounterText = ADVENTURE_LOG_PB_PATTERN.matcher(counterText); + while (mCounterText.find()) { - Matcher mCoxRuns = ADVENTURE_LOG_COX_PB_PATTERN.matcher(mCounterText.group()); - int bestPbTime = Integer.MAX_VALUE; - while (mCoxRuns.find()) + String bossName = longBossName(mCounterText.group(1)); + if (bossName.equalsIgnoreCase("chambers of xeric") || + bossName.equalsIgnoreCase("chambers of xeric challenge mode")) { - bestPbTime = Math.min(timeStringToSeconds(mCoxRuns.group(1)), bestPbTime); + Matcher mCoxRuns = ADVENTURE_LOG_COX_PB_PATTERN.matcher(mCounterText.group()); + int bestPbTime = Integer.MAX_VALUE; + while (mCoxRuns.find()) + { + bestPbTime = Math.min(timeStringToSeconds(mCoxRuns.group(1)), bestPbTime); + } + // So we don't reset people's already saved PB's if they had one before the update + int currentPb = getPb(bossName); + if (currentPb == 0 || currentPb > bestPbTime) + { + setPb(bossName, bestPbTime); + } } - // So we don't reset people's already saved PB's if they had one before the update - int currentPb = getPb(bossName); - if (currentPb == 0 || currentPb > bestPbTime) + else { - setPb(bossName, bestPbTime); + String pbTime = mCounterText.group(2); + setPb(bossName, timeStringToSeconds(pbTime)); } } - else - { - String pbTime = mCounterText.group(2); - setPb(bossName, timeStringToSeconds(pbTime)); - } } } } @@ -542,8 +545,8 @@ public class ChatCommandsPlugin extends Plugin case KILL_LOGS_GROUP_ID: bossLogLoaded = true; break; - case COUNTERS_LOG_GROUP_ID: - countersLogLoaded = true; + case GENERIC_SCROLL_GROUP_ID: + scrollInterfaceLoaded = 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 5de68a0cb7..8c45359e61 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 @@ -43,7 +43,7 @@ import net.runelite.api.events.GameTick; 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.COUNTERS_LOG_GROUP_ID; +import static net.runelite.api.widgets.WidgetID.GENERIC_SCROLL_GROUP_ID; import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.chat.ChatCommandManager; import net.runelite.client.chat.ChatMessageManager; @@ -465,10 +465,10 @@ public class ChatCommandsPluginTest Widget countersPage = mock(Widget.class); when(countersPage.getText()).thenReturn(COUNTER_TEXT); - when(client.getWidget(WidgetInfo.COUNTERS_LOG_TEXT)).thenReturn(countersPage); + when(client.getWidget(WidgetInfo.GENERIC_SCROLL_TEXT)).thenReturn(countersPage); WidgetLoaded countersLogEvent = new WidgetLoaded(); - countersLogEvent.setGroupId(COUNTERS_LOG_GROUP_ID); + countersLogEvent.setGroupId(GENERIC_SCROLL_GROUP_ID); chatCommandsPlugin.onWidgetLoaded(countersLogEvent); chatCommandsPlugin.onGameTick(new GameTick()); @@ -521,10 +521,10 @@ public class ChatCommandsPluginTest Widget countersPage = mock(Widget.class); when(countersPage.getText()).thenReturn(COUNTER_TEXT); - when(client.getWidget(WidgetInfo.COUNTERS_LOG_TEXT)).thenReturn(countersPage); + when(client.getWidget(WidgetInfo.GENERIC_SCROLL_TEXT)).thenReturn(countersPage); WidgetLoaded countersLogEvent = new WidgetLoaded(); - countersLogEvent.setGroupId(COUNTERS_LOG_GROUP_ID); + countersLogEvent.setGroupId(GENERIC_SCROLL_GROUP_ID); chatCommandsPlugin.onWidgetLoaded(countersLogEvent); chatCommandsPlugin.onGameTick(new GameTick()); @@ -555,7 +555,7 @@ public class ChatCommandsPluginTest chatCommandsPlugin.onGameTick(new GameTick()); WidgetLoaded countersLogEvent = new WidgetLoaded(); - countersLogEvent.setGroupId(COUNTERS_LOG_GROUP_ID); + countersLogEvent.setGroupId(GENERIC_SCROLL_GROUP_ID); chatCommandsPlugin.onWidgetLoaded(countersLogEvent); chatCommandsPlugin.onGameTick(new GameTick());