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 b1eb61e5c2..cdc14ad925 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 @@ -151,6 +151,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; static class WorldMap { @@ -878,4 +879,10 @@ public class WidgetID { static final int CONTAINER = 0; } + + static class CountersLog + { + 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 ca21604055..5d54ded21d 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 @@ -456,6 +456,8 @@ public enum WidgetInfo ADVENTURE_LOG(WidgetID.ADVENTURE_LOG_ID, WidgetID.AdventureLog.CONTAINER), + COUNTERS_LOG_TEXT(WidgetID.COUNTERS_LOG_GROUP_ID, WidgetID.CountersLog.TEXT), + WORLD_SWITCHER_LIST(WidgetID.WORLD_SWITCHER_GROUP_ID, WidgetID.WorldSwitcher.WORLD_LIST), FOSSIL_ISLAND_OXYGENBAR(WidgetID.FOSSIL_ISLAND_OXYGENBAR_ID, WidgetID.FossilOxygen.FOSSIL_ISLAND_OXYGEN_BAR), 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 20d6073957..ae704913b7 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,6 +56,7 @@ 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.KILL_LOGS_GROUP_ID; +import static net.runelite.api.widgets.WidgetID.COUNTERS_LOG_GROUP_ID; import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.chat.ChatColorType; import net.runelite.client.chat.ChatCommandManager; @@ -69,7 +70,7 @@ import net.runelite.client.input.KeyManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.util.QuantityFormatter; -import static net.runelite.client.util.Text.sanitize; +import net.runelite.client.util.Text; import net.runelite.http.api.chat.ChatClient; import net.runelite.http.api.chat.Duels; import net.runelite.http.api.hiscore.HiscoreClient; @@ -99,6 +100,7 @@ public class ChatCommandsPlugin extends Plugin private static final Pattern DUEL_ARENA_WINS_PATTERN = Pattern.compile("You (were defeated|won)! You have(?: now)? won (\\d+) duels?"); private static final Pattern DUEL_ARENA_LOSSES_PATTERN = Pattern.compile("You have(?: now)? lost (\\d+) duels?"); private static final Pattern ADVENTURE_LOG_TITLE_PATTERN = Pattern.compile("The Exploits of (.+)"); + private static final Pattern ADVENTURE_LOG_PB_PATTERN = Pattern.compile("([a-zA-Z]+(?: [a-zA-Z]+)*) Fastest (?:kill|run): ([0-9:]+)"); private static final String TOTAL_LEVEL_COMMAND_STRING = "!total"; private static final String PRICE_COMMAND_STRING = "!price"; @@ -122,6 +124,7 @@ public class ChatCommandsPlugin extends Plugin private boolean bossLogLoaded; private boolean advLogLoaded; + private boolean countersLogLoaded; private String pohOwner; private HiscoreEndpoint hiscoreEndpoint; // hiscore endpoint for current player private String lastBossKill; @@ -436,6 +439,20 @@ public class ChatCommandsPlugin extends Plugin } } } + + if (countersLogLoaded && pohOwner.equals(client.getLocalPlayer().getName())) + { + countersLogLoaded = false; + + String counterText = Text.sanitizeMultilineText(client.getWidget(WidgetInfo.COUNTERS_LOG_TEXT).getText()); + Matcher mCounterText = ADVENTURE_LOG_PB_PATTERN.matcher(counterText); + while (mCounterText.find()) + { + String bossName = mCounterText.group(1); + String pbTime = mCounterText.group(2); + setPb(longBossName(bossName), timeStringToSeconds(pbTime)); + } + } } @Subscribe @@ -449,6 +466,9 @@ public class ChatCommandsPlugin extends Plugin case KILL_LOGS_GROUP_ID: bossLogLoaded = true; break; + case COUNTERS_LOG_GROUP_ID: + countersLogLoaded = true; + break; } } @@ -523,7 +543,7 @@ public class ChatCommandsPlugin extends Plugin } else { - player = sanitize(chatMessage.getName()); + player = Text.sanitize(chatMessage.getName()); } search = longBossName(search); @@ -604,7 +624,7 @@ public class ChatCommandsPlugin extends Plugin } else { - player = sanitize(chatMessage.getName()); + player = Text.sanitize(chatMessage.getName()); } Duels duels; @@ -661,7 +681,7 @@ public class ChatCommandsPlugin extends Plugin } else { - player = sanitize(chatMessage.getName()); + player = Text.sanitize(chatMessage.getName()); } int qp; @@ -735,7 +755,7 @@ public class ChatCommandsPlugin extends Plugin } else { - player = sanitize(chatMessage.getName()); + player = Text.sanitize(chatMessage.getName()); } search = longBossName(search); @@ -818,7 +838,7 @@ public class ChatCommandsPlugin extends Plugin } else { - player = sanitize(chatMessage.getName()); + player = Text.sanitize(chatMessage.getName()); } int gc; @@ -1028,7 +1048,7 @@ public class ChatCommandsPlugin extends Plugin } else { - player = sanitize(chatMessage.getName()); + player = Text.sanitize(chatMessage.getName()); } try @@ -1296,7 +1316,7 @@ public class ChatCommandsPlugin extends Plugin private HiscoreLookup getCorrectLookupFor(final ChatMessage chatMessage) { Player localPlayer = client.getLocalPlayer(); - final String player = sanitize(chatMessage.getName()); + final String player = Text.sanitize(chatMessage.getName()); // If we are sending the message then just use the local hiscore endpoint for the world if (chatMessage.getType().equals(ChatMessageType.PRIVATECHATOUT) @@ -1426,6 +1446,7 @@ public class ChatCommandsPlugin extends Plugin return "Corporeal Beast"; case "jad": + case "tzhaar fight cave": return "TzTok-Jad"; case "kq": @@ -1545,11 +1566,13 @@ public class ChatCommandsPlugin extends Plugin // The Gauntlet case "gaunt": case "gauntlet": + case "the gauntlet": return "Gauntlet"; // Corrupted Gauntlet case "cgaunt": case "cgauntlet": + case "the corrupted gauntlet": return "Corrupted Gauntlet"; case "the nightmare": 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 a7ff4ea8e1..27de559692 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 @@ -33,9 +33,16 @@ import static net.runelite.api.ChatMessageType.FRIENDSCHATNOTIFICATION; import static net.runelite.api.ChatMessageType.GAMEMESSAGE; import static net.runelite.api.ChatMessageType.TRADE; import net.runelite.api.Client; +import net.runelite.api.Player; import net.runelite.api.events.ChatMessage; +import net.runelite.api.events.GameTick; +import net.runelite.api.events.WidgetLoaded; +import net.runelite.api.widgets.Widget; +import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.config.ChatColorConfig; import net.runelite.client.config.ConfigManager; +import static net.runelite.api.widgets.WidgetID.ADVENTURE_LOG_ID; +import static net.runelite.api.widgets.WidgetID.COUNTERS_LOG_GROUP_ID; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -45,7 +52,9 @@ import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.never; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import org.mockito.junit.MockitoJUnitRunner; @@ -351,4 +360,134 @@ public class ChatCommandsPluginTest verify(configManager).setConfiguration(eq("killcount.adam"), eq("chambers of xeric"), eq(52)); verify(configManager, never()).setConfiguration(eq("personalbest.adam"), eq("chambers of xeric"), anyInt()); } + + @Test + public void testAdventureLogCountersPage() + { + Player player = mock(Player.class); + when(player.getName()).thenReturn(PLAYER_NAME); + when(client.getLocalPlayer()).thenReturn(player); + + Widget advLogWidget = mock(Widget.class); + Widget advLogExploitsTextWidget = mock(Widget.class); + when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget); + when(advLogExploitsTextWidget.getText()).thenReturn("The Exploits of " + PLAYER_NAME); + when(client.getWidget(WidgetInfo.ADVENTURE_LOG)).thenReturn(advLogWidget); + + WidgetLoaded advLogEvent = new WidgetLoaded(); + advLogEvent.setGroupId(ADVENTURE_LOG_ID); + chatCommandsPlugin.onWidgetLoaded(advLogEvent); + chatCommandsPlugin.onGameTick(new GameTick()); + + String COUNTER_TEXT = "Duel Arena
Wins: 4
Losses: 2" + + "

Last Man Standing
Rank: 0" + + "

Treasure Trails
Beginner: 0
Easy: 7" + + "
Medium: 28
Hard: 108
Elite: 15" + + "
Master: 27
Rank: Novice" + + "

Chompy Hunting
Kills: 1,000
Rank: Ogre Expert" + + "

Order of the White Knights
Rank: Master
with a kill score of 1,300" + + "

TzHaar Fight Cave
Fastest run: 38:10" + + "

Inferno
Fastest run: -

Zulrah
" + + "Fastest kill: 5:48

Vorkath
Fastest kill: 1:21" + + "

Galvek
Fastest kill: -

Grotesque Guardians
" + + "Fastest kill: 2:49

Alchemical Hydra
Fastest kill: -" + + "

Hespori
Fastest kill: 0:57

Nightmare
" + + "Fastest kill: 3:30

The Gauntlet
Fastest run: -" + + "

The Corrupted Gauntlet
Fastest run: -

Fragment of Seren
" + + "Fastest kill: -

Barbarian Assault
High-level gambles: " + + "15

Fremennik spirits rested: 0"; + + Widget countersPage = mock(Widget.class); + when(countersPage.getText()).thenReturn(COUNTER_TEXT); + when(client.getWidget(WidgetInfo.COUNTERS_LOG_TEXT)).thenReturn(countersPage); + + WidgetLoaded countersLogEvent = new WidgetLoaded(); + countersLogEvent.setGroupId(COUNTERS_LOG_GROUP_ID); + chatCommandsPlugin.onWidgetLoaded(countersLogEvent); + chatCommandsPlugin.onGameTick(new GameTick()); + + verify(configManager).setConfiguration(eq("personalbest.adam"), eq("tztok-jad"), eq(38 * 60 + 10)); + verify(configManager).setConfiguration(eq("personalbest.adam"), eq("zulrah"), eq(5 * 60 + 48)); + verify(configManager).setConfiguration(eq("personalbest.adam"), eq("vorkath"), eq(1 * 60 + 21)); + verify(configManager).setConfiguration(eq("personalbest.adam"), eq("grotesque guardians"), eq(2 * 60 + 49)); + verify(configManager).setConfiguration(eq("personalbest.adam"), eq("hespori"), eq(57)); + verify(configManager).setConfiguration(eq("personalbest.adam"), eq("nightmare"), eq( 3 * 60 + 30)); + } + + @Test + public void testAdventurerLogCountersPage2() + { + Player player = mock(Player.class); + when(player.getName()).thenReturn(PLAYER_NAME); + when(client.getLocalPlayer()).thenReturn(player); + + Widget advLogWidget = mock(Widget.class); + Widget advLogExploitsTextWidget = mock(Widget.class); + when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget); + when(advLogExploitsTextWidget.getText()).thenReturn("The Exploits of " + PLAYER_NAME); + when(client.getWidget(WidgetInfo.ADVENTURE_LOG)).thenReturn(advLogWidget); + + WidgetLoaded advLogEvent = new WidgetLoaded(); + advLogEvent.setGroupId(ADVENTURE_LOG_ID); + chatCommandsPlugin.onWidgetLoaded(advLogEvent); + chatCommandsPlugin.onGameTick(new GameTick()); + + String COUNTER_TEXT = "Duel Arena
Wins: 12
Losses: 20" + + "

Last Man Standing
Rank: 0" + + "

Treasure Trails
Beginner: 1
Easy: 4" + + "
Medium: 35
Hard: 66
Elite: 2" + + "
Master: 0
Rank: Novice" + + "

Chompy Hunting
Kills: 300
Rank: Ogre Forester" + + "

Order of the White Knights
Rank: Unrated
with a kill score of 99" + + "

TzHaar Fight Cave
Fastest run: 65:12" + + "

Inferno
Fastest run: -

Zulrah
" + + "Fastest kill: 2:55

Vorkath
Fastest kill: 1:37" + + "

Galvek
Fastest kill: -

Grotesque Guardians
" + + "Fastest kill: -

Alchemical Hydra
Fastest kill: -" + + "

Hespori
Fastest kill: 1:42

Nightmare
" + + "Fastest kill: -

The Gauntlet
Fastest run: -" + + "

The Corrupted Gauntlet
Fastest run: -

Fragment of Seren
" + + "Fastest kill: -

Barbarian Assault
High-level gambles: " + + "0

Fremennik spirits rested: 0"; + + Widget countersPage = mock(Widget.class); + when(countersPage.getText()).thenReturn(COUNTER_TEXT); + when(client.getWidget(WidgetInfo.COUNTERS_LOG_TEXT)).thenReturn(countersPage); + + WidgetLoaded countersLogEvent = new WidgetLoaded(); + countersLogEvent.setGroupId(COUNTERS_LOG_GROUP_ID); + chatCommandsPlugin.onWidgetLoaded(countersLogEvent); + chatCommandsPlugin.onGameTick(new GameTick()); + + verify(configManager).setConfiguration(eq("personalbest.adam"), eq("tztok-jad"), eq(65 * 60 + 12)); + verify(configManager).setConfiguration(eq("personalbest.adam"), eq("zulrah"), eq(2 * 60 + 55)); + verify(configManager).setConfiguration(eq("personalbest.adam"), eq("vorkath"), eq(1 * 60 + 37)); + verify(configManager).setConfiguration(eq("personalbest.adam"), eq("hespori"), eq(1 * 60 + 42)); + } + + @Test + public void testNotYourAdventureLogCountersPage() + { + Player player = mock(Player.class); + when(player.getName()).thenReturn(PLAYER_NAME); + when(client.getLocalPlayer()).thenReturn(player); + + Widget advLogWidget = mock(Widget.class); + Widget advLogExploitsTextWidget = mock(Widget.class); + when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget); + when(advLogExploitsTextWidget.getText()).thenReturn("The Exploits of " + "not the player"); + when(client.getWidget(WidgetInfo.ADVENTURE_LOG)).thenReturn(advLogWidget); + + WidgetLoaded advLogEvent = new WidgetLoaded(); + advLogEvent.setGroupId(ADVENTURE_LOG_ID); + chatCommandsPlugin.onWidgetLoaded(advLogEvent); + chatCommandsPlugin.onGameTick(new GameTick()); + + WidgetLoaded countersLogEvent = new WidgetLoaded(); + countersLogEvent.setGroupId(COUNTERS_LOG_GROUP_ID); + chatCommandsPlugin.onWidgetLoaded(countersLogEvent); + chatCommandsPlugin.onGameTick(new GameTick()); + + verifyNoMoreInteractions(configManager); + } }