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 5bb9630550..1a52129220 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 @@ -109,6 +109,7 @@ public class ChatCommandsPlugin extends Plugin private boolean logKills; private HiscoreEndpoint hiscoreEndpoint; // hiscore endpoint for current player private String lastBossKill; + private int lastPb = -1; @Inject private Client client; @@ -223,7 +224,17 @@ public class ChatCommandsPlugin extends Plugin int kc = Integer.parseInt(matcher.group(2)); setKc(boss, kc); - lastBossKill = boss; + // We either already have the pb, or need to remember the boss for the upcoming pb + if (lastPb > -1) + { + log.debug("Got out-of-order personal best for {}: {}", boss, lastPb); + setPb(boss, lastPb); + lastPb = -1; + } + else + { + lastBossKill = boss; + } return; } @@ -291,19 +302,16 @@ public class ChatCommandsPlugin extends Plugin setKc("Barrows Chests", kc); } - if (lastBossKill != null) + matcher = KILL_DURATION_PATTERN.matcher(message); + if (matcher.find()) { - matcher = KILL_DURATION_PATTERN.matcher(message); - if (matcher.find()) - { - matchPb(matcher); - } + matchPb(matcher); + } - matcher = NEW_PB_PATTERN.matcher(message); - if (matcher.find()) - { - matchPb(matcher); - } + matcher = NEW_PB_PATTERN.matcher(message); + if (matcher.find()) + { + matchPb(matcher); } lastBossKill = null; @@ -316,8 +324,19 @@ public class ChatCommandsPlugin extends Plugin if (s.length == 2) { int seconds = Integer.parseInt(s[0]) * 60 + Integer.parseInt(s[1]); - log.debug("Got personal best for {}: {}", lastBossKill, seconds); - setPb(lastBossKill, seconds); + if (lastBossKill != null) + { + // Most bosses sent boss kill message, and then pb message, so we + // use the remembered lastBossKill + log.debug("Got personal best for {}: {}", lastBossKill, seconds); + setPb(lastBossKill, seconds); + lastPb = -1; + } + else + { + // Some bosses send the pb message, and then the kill message! + lastPb = seconds; + } } } 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 9582e41ba2..9f74ebf22b 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 @@ -296,4 +296,34 @@ public class ChatCommandsPluginTest verify(configManager).setConfiguration(eq("personalbest.adam"), eq("tzkal-zuk"), eq(134 * 60 + 52)); verify(configManager).setConfiguration(eq("killcount.adam"), eq("tzkal-zuk"), eq(3)); } + + @Test + public void testGgNewPb() + { + when(client.getUsername()).thenReturn("Adam"); + + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Fight duration: