ChatCommandsPlugin extends Plugin { @Subscribe public void onChatMessage(ChatMessage chatMessage) { if (chatMessage.getType() != ChatMessageType.TRADE && chatMessage.getType() != ChatMessageType.GAMEMESSAGE && chatMessage.getType() != ChatMessageType.SPAM && chatMessage.getType() != ChatMessageType.FRIENDSCHATNOTIFICATION) { return; } String message = chatMessage.getMessage(); Matcher matcher = KILLCOUNT_PATTERN.matcher(message); if (matcher.find()) { String boss = matcher.group(1); int kc = Integer.parseInt(matcher.group(2)); setKc(boss, kc); if (lastPb > -1) { log.debug("Got out-of-order personal best for {}: {}", boss, lastPb); setPb(boss, lastPb); lastPb = -1; } else { lastBossKill = boss; } return; } matcher = WINTERTODT_PATTERN.matcher(message); if (matcher.find()) { int kc = Integer.parseInt(matcher.group(1)); setKc("Wintertodt", kc); } matcher = RAIDS_PATTERN.matcher(message); if (matcher.find()) { String boss = matcher.group(1); int kc = Integer.parseInt(matcher.group(2)); setKc(boss, kc); if (lastPb > -1) { int currentPb = getPb(boss); if (currentPb <= 0 || lastPb < currentPb) { setPb(boss, lastPb); } lastPb = -1; } lastBossKill = boss; return; } matcher = DUEL_ARENA_WINS_PATTERN.matcher(message); if (matcher.find()) { final int oldWins = getKc("Duel Arena Wins"); final int wins = Integer.parseInt(matcher.group(2)); final String result = matcher.group(1); int winningStreak = getKc("Duel Arena Win Streak"); int losingStreak = getKc("Duel Arena Lose Streak"); if (result.equals("won") && wins > oldWins) { losingStreak = 0; winningStreak += 1; } else if (result.equals("were defeated")) { losingStreak += 1; winningStreak = 0; } else { log.warn("unrecognized duel streak chat message: {}", message); } setKc("Duel Arena Wins", wins); setKc("Duel Arena Win Streak", winningStreak); setKc("Duel Arena Lose Streak", losingStreak); } matcher = DUEL_ARENA_LOSSES_PATTERN.matcher(message); if (matcher.find()) { int losses = Integer.parseInt(matcher.group(1)); setKc("Duel Arena Losses", losses); } matcher = BARROWS_PATTERN.matcher(message); if (matcher.find()) { int kc = Integer.parseInt(matcher.group(1)); setKc("Barrows Chests", kc); } matcher = KILL_DURATION_PATTERN.matcher(message); if (matcher.find()) { matchPb(matcher); } matcher = NEW_PB_PATTERN.matcher(message); if (matcher.find()) { matchPb(matcher); } matcher = RAIDS_PB_PATTERN.matcher(message); if (matcher.find()) { matchPb(matcher); } matcher = RAIDS_DURATION_PATTERN.matcher(message); if (matcher.find()) { matchPb(matcher); } matcher = TOB_WAVE_PB_PATTERN.matcher(message); if (matcher.find()) { matchPb(matcher); } matcher = TOB_WAVE_DURATION_PATTERN.matcher(message); if (matcher.find()) { matchPb(matcher); } matcher = HS_PB_PATTERN.matcher(message); if (matcher.find()) { int floor = Integer.parseInt(matcher.group("floor")); String floortime = matcher.group("floortime"); String floorpb = matcher.group("floorpb"); String otime = matcher.group("otime"); String opb = matcher.group("opb"); String pb = MoreObjects.firstNonNull(floorpb, floortime); setPb("Hallowed Sepulchre Floor " + floor, timeStringToSeconds(pb)); if (otime != null) { pb = MoreObjects.firstNonNull(opb, otime); setPb("Hallowed Sepulchre", timeStringToSeconds(pb)); } } matcher = HS_KC_FLOOR_PATTERN.matcher(message); if (matcher.find()) { int floor = Integer.parseInt(matcher.group(1)); int kc = Integer.parseInt(matcher.group(2)); setKc("Hallowed Sepulchre Floor " + floor, kc); } matcher = HS_KC_GHC_PATTERN.matcher(message); if (matcher.find()) { int kc = Integer.parseInt(matcher.group(1)); setKc("Hallowed Sepulchre", kc); } lastBossKill = null; }  @Override void startUp(); @Override void shutDown(); @Subscribe void onChatMessage(ChatMessage chatMessage); @Subscribe void onGameTick(GameTick event); @Subscribe void onWidgetLoaded(WidgetLoaded widget); @Subscribe void onGameStateChanged(GameStateChanged event); @Subscribe void onVarbitChanged(VarbitChanged varbitChanged);  }
@Test public void testCorporealBeastKill() { ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your Corporeal Beast kill count is: <col=ff0000>4</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessageEvent); verify(configManager).setConfiguration("killcount.adam", "corporeal beast", 4); }
@Test public void testTheatreOfBlood() { ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Wave 'The Final Challenge' complete! Duration: <col=ff0000>5:04</col><br>Theatre of Blood wave completion time: <col=ff0000>37:04</col> (Personal best!)", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Theatre of Blood count is: <col=ff0000>73</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessageEvent); verify(configManager).setConfiguration("killcount.adam", "theatre of blood", 73); verify(configManager).setConfiguration("personalbest.adam", "theatre of blood", 37 * 60 + 4); }
@Test public void testTheatreOfBloodUnknownPB() { ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Wave 'The Final Challenge' complete! Duration: <col=ff0000>5:04</col><br>Theatre of Blood wave completion time: <col=ff0000>38:17</col><br></col>Personal best: 37:04", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Theatre of Blood count is: <col=ff0000>73</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessageEvent); verify(configManager).setConfiguration("killcount.adam", "theatre of blood", 73); verify(configManager).setConfiguration("personalbest.adam", "theatre of blood", 37 * 60 + 4); }
@Test public void testTheatreOfBloodNoPB() { when(configManager.getConfiguration("personalbest.adam", "theatre of blood", int.class)).thenReturn(37 * 60 + 4); ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Wave 'The Final Challenge' complete! Duration: <col=ff0000>5:04</col><br>Theatre of Blood wave completion time: <col=ff0000>38:17</col><br></col>Personal best: 37:10", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Theatre of Blood count is: <col=ff0000>73</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessageEvent); verify(configManager).setConfiguration("killcount.adam", "theatre of blood", 73); verify(configManager, never()).setConfiguration(eq("personalbest.adam"), eq("theatre of blood"), anyInt()); }
@Test public void testWintertodt() { ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your subdued Wintertodt count is: <col=ff0000>4</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessageEvent); verify(configManager).setConfiguration("killcount.adam", "wintertodt", 4); }
@Test public void testKreearra() { ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your Kree'arra kill count is: <col=ff0000>4</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessageEvent); verify(configManager).setConfiguration("killcount.adam", "kree'arra", 4); }
@Test public void testBarrows() { ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your Barrows chest count is: <col=ff0000>277</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessageEvent); verify(configManager).setConfiguration("killcount.adam", "barrows chests", 277); }
@Test public void testHerbiboar() { ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your herbiboar harvest count is: <col=ff0000>4091</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessageEvent); verify(configManager).setConfiguration("killcount.adam", "herbiboar", 4091); }
@Test public void testGauntlet() { ChatMessage gauntletMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Gauntlet completion count is: <col=ff0000>123</col>.", null, 0); chatCommandsPlugin.onChatMessage(gauntletMessage); verify(configManager).setConfiguration("killcount.adam", "gauntlet", 123); }
@Test public void testCorruptedGauntlet() { ChatMessage corruptedGauntletMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Corrupted Gauntlet completion count is: <col=ff0000>4729</col>.", null, 0); chatCommandsPlugin.onChatMessage(corruptedGauntletMessage); verify(configManager).setConfiguration("killcount.adam", "corrupted gauntlet", 4729); }
@Test public void testPersonalBest() { final String FIGHT_DURATION = "Fight duration: <col=ff0000>2:06</col>. Personal best: 1:19."; ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Kree'arra kill count is: <col=ff0000>4</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); chatMessage = new ChatMessage(null, GAMEMESSAGE, "", FIGHT_DURATION, null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration(eq("personalbest.adam"), eq("kree'arra"), eq(79)); }
@Test public void testPersonalBestNoTrailingPeriod() { final String FIGHT_DURATION = "Fight duration: <col=ff0000>0:59</col>. Personal best: 0:55"; ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Zulrah kill count is: <col=ff0000>4</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); chatMessage = new ChatMessage(null, GAMEMESSAGE, "", FIGHT_DURATION, null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration(eq("personalbest.adam"), eq("zulrah"), eq(55)); }
@Test public void testNewPersonalBest() { final String NEW_PB = "Fight duration: <col=ff0000>3:01</col> (new personal best)."; ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Kree'arra kill count is: <col=ff0000>4</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); chatMessage = new ChatMessage(null, GAMEMESSAGE, "", NEW_PB, null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration(eq("personalbest.adam"), eq("kree'arra"), eq(181)); }
@Test public void testDuelArenaWin() { ChatMessage chatMessageEvent = new ChatMessage(null, TRADE, "", "You won! You have now won 27 duels.", null, 0); chatCommandsPlugin.onChatMessage(chatMessageEvent); verify(configManager).setConfiguration("killcount.adam", "duel arena wins", 27); verify(configManager).setConfiguration("killcount.adam", "duel arena win streak", 1); }
@Test public void testDuelArenaWin2() { ChatMessage chatMessageEvent = new ChatMessage(null, TRADE, "", "You were defeated! You have won 22 duels.", null, 0); chatCommandsPlugin.onChatMessage(chatMessageEvent); verify(configManager).setConfiguration("killcount.adam", "duel arena wins", 22); }
@Test public void testDuelArenaLose() { ChatMessage chatMessageEvent = new ChatMessage(null, TRADE, "", "You have now lost 999 duels.", null, 0); chatCommandsPlugin.onChatMessage(chatMessageEvent); verify(configManager).setConfiguration("killcount.adam", "duel arena losses", 999); }
@Test public void testAgilityLap() { final String NEW_PB = "Lap duration: <col=ff0000>1:01</col> (new personal best)."; ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Prifddinas Agility Course lap count is: <col=ff0000>2</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); chatMessage = new ChatMessage(null, GAMEMESSAGE, "", NEW_PB, null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration(eq("personalbest.adam"), eq("prifddinas agility course"), eq(61)); verify(configManager).setConfiguration(eq("killcount.adam"), eq("prifddinas agility course"), eq(2)); }
@Test public void testZukNewPb() { ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your TzKal-Zuk kill count is: <col=ff0000>2</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Duration: <col=ff0000>104:31</col> (new personal best)", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration(eq("personalbest.adam"), eq("tzkal-zuk"), eq(104 * 60 + 31)); verify(configManager).setConfiguration(eq("killcount.adam"), eq("tzkal-zuk"), eq(2)); }
@Test public void testZukKill() { ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your TzKal-Zuk kill count is: <col=ff0000>3</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Duration: <col=ff0000>172:18</col>. Personal best: 134:52", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); 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() { ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Fight duration: <col=ff0000>1:36</col> (new personal best)", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Grotesque Guardians kill count is: <col=ff0000>179</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration(eq("personalbest.adam"), eq("grotesque guardians"), eq(96)); verify(configManager).setConfiguration(eq("killcount.adam"), eq("grotesque guardians"), eq(179)); }
@Test public void testGgKill() { ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Fight duration: <col=ff0000>2:41</col>. Personal best: 2:14", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Grotesque Guardians kill count is: <col=ff0000>32</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration(eq("personalbest.adam"), eq("grotesque guardians"), eq(2 * 60 + 14)); verify(configManager).setConfiguration(eq("killcount.adam"), eq("grotesque guardians"), eq(32)); }
@Test public void testGuantletPersonalBest() { ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: <col=ff0000>10:24</col>. Personal best: 7:59.", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Gauntlet completion count is: <col=ff0000>124</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration(eq("killcount.adam"), eq("gauntlet"), eq(124)); verify(configManager).setConfiguration(eq("personalbest.adam"), eq("gauntlet"), eq(7 * 60 + 59)); }
@Test public void testGuantletNewPersonalBest() { ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: <col=ff0000>10:24</col> (new personal best).", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Gauntlet completion count is: <col=ff0000>124</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration(eq("personalbest.adam"), eq("gauntlet"), eq(10 * 60 + 24)); verify(configManager).setConfiguration(eq("killcount.adam"), eq("gauntlet"), eq(124)); }
@Test public void testCoXKill() { ChatMessage chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "<col=ef20ff>Congratulations - your raid is complete!</col><br>Team size: <col=ff0000>24+ players</col> Duration:</col> <col=ff0000>37:04</col> (new personal best)</col>>", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Chambers of Xeric count is: <col=ff0000>51</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration(eq("killcount.adam"), eq("chambers of xeric"), eq(51)); verify(configManager).setConfiguration(eq("personalbest.adam"), eq("chambers of xeric"), eq(37 * 60 + 4)); }
@Test public void testCoXKillUnknownPb() { when(configManager.getConfiguration("personalbest.adam", "chambers of xeric", int.class)).thenReturn(25 * 60 + 14); ChatMessage chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "<col=ef20ff>Congratulations - your raid is complete!</col><br>Team size: <col=ff0000>11-15 players</col> Duration:</col> <col=ff0000>23:25</col> Personal best: </col><col=ff0000>20:19</col>", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Chambers of Xeric count is: <col=ff0000>52</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration("killcount.adam", "chambers of xeric", 52); verify(configManager).setConfiguration("personalbest.adam", "chambers of xeric", 20 * 60 + 19); }
@Test public void testCoXKillNoPb() { when(configManager.getConfiguration(anyString(), anyString(), any())).thenReturn(2224); ChatMessage chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "<col=ef20ff>Congratulations - your raid is complete!</col><br>Team size: <col=ff0000>3 players</col> Duration:</col> <col=ff0000>37:10</col> (new personal best)</col>", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Chambers of Xeric count is: <col=ff0000>52</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); 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 testHsFloorNoPb() { ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 1 time: <col=ff0000>1:19</col>. Personal best: 0:28", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration("personalbest.adam", "hallowed sepulchre floor 1", 28); }
@Test public void testHsFloorPb() { ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 2 time: <col=ff0000>0:47</col> (new personal best)", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration("personalbest.adam", "hallowed sepulchre floor 2", 47); }
@Test public void testHsOverallPb_Pb() { ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: <col=ff0000>4:46</col> (new personal best)<br>Overall time: <col=ff0000>9:53</col> (new personal best)<br>", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration("personalbest.adam", "hallowed sepulchre floor 5", 4 * 60 + 46); verify(configManager).setConfiguration("personalbest.adam", "hallowed sepulchre", 9 * 60 + 53); }
@Test public void testHsOverallPb_NoPb() { ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: <col=ff0000>3:26</col> (new personal best)<br>Overall time: <col=ff0000>9:17</col>. Personal best: 9:15<br>", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration("personalbest.adam", "hallowed sepulchre floor 5", 3 * 60 + 26); verify(configManager).setConfiguration("personalbest.adam", "hallowed sepulchre", 9 * 60 + 15); }
@Test public void testHsOverallNoPb_NoPb() { ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: <col=ff0000>3:56</col>. Personal best: 3:05<br>Overall time: <col=ff0000>9:14</col>. Personal best: 7:49<br>", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration("personalbest.adam", "hallowed sepulchre floor 5", 3 * 60 + 5); verify(configManager).setConfiguration("personalbest.adam", "hallowed sepulchre", 7 * 60 + 49); }
@Test public void testHsOverallNoPb_Pb() { ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: <col=ff0000>3:10</col>. Personal best: 3:04<br>Overall time: <col=ff0000>7:47</col> (new personal best)<br>", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration("personalbest.adam", "hallowed sepulchre floor 5", 3 * 60 + 4); verify(configManager).setConfiguration("personalbest.adam", "hallowed sepulchre", 7 * 60 + 47); }
@Test public void testHsFloorKc() { ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "You have completed Floor 5 of the Hallowed Sepulchre! Total completions: <col=ff0000>81</col>.", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration("killcount.adam", "hallowed sepulchre floor 5", 81); }
@Test public void testHsGhcKc() { ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "You have opened the Grand Hallowed Coffin <col=ff0000>36</col> times!", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); verify(configManager).setConfiguration("killcount.adam", "hallowed sepulchre", 36); }