TimersPlugin extends Plugin { @Subscribe public void onChatMessage(ChatMessage event) { if (event.getType() != ChatMessageType.SPAM && event.getType() != ChatMessageType.GAMEMESSAGE) { return; } if (event.getMessage().equals(ENDURANCE_EFFECT_MESSAGE)) { wasWearingEndurance = true; } if (config.showStamina() && (event.getMessage().equals(STAMINA_DRINK_MESSAGE) || event.getMessage().equals(STAMINA_SHARED_DRINK_MESSAGE))) { createStaminaTimer(); } if (event.getMessage().equals(STAMINA_EXPIRED_MESSAGE) || event.getMessage().equals(GAUNTLET_ENTER_MESSAGE)) { removeGameTimer(STAMINA); staminaTimer = null; } if (config.showAntiFire() && event.getMessage().equals(ANTIFIRE_DRINK_MESSAGE)) { createGameTimer(ANTIFIRE); } if (config.showAntiFire() && event.getMessage().equals(EXTENDED_ANTIFIRE_DRINK_MESSAGE)) { createGameTimer(EXANTIFIRE); } if (config.showGodWarsAltar() && event.getMessage().equalsIgnoreCase(GOD_WARS_ALTAR_MESSAGE)) { createGameTimer(GOD_WARS_ALTAR); } if (config.showAntiFire() && event.getMessage().equals(EXTENDED_SUPER_ANTIFIRE_DRINK_MESSAGE)) { createGameTimer(EXSUPERANTIFIRE); } if (config.showAntiFire() && event.getMessage().equals(ANTIFIRE_EXPIRED_MESSAGE)) { removeGameTimer(ANTIFIRE); removeGameTimer(EXANTIFIRE); } if (config.showOverload() && event.getMessage().startsWith("You drink some of your") && event.getMessage().contains("overload")) { if (client.getVar(Varbits.IN_RAID) == 1) { createGameTimer(OVERLOAD_RAID); } else { createGameTimer(OVERLOAD); } } if (config.showCannon() && (event.getMessage().equals(CANNON_FURNACE_MESSAGE) || event.getMessage().contains(CANNON_REPAIR_MESSAGE))) { TimerTimer cannonTimer = createGameTimer(CANNON); cannonTimer.setTooltip(cannonTimer.getTooltip() + " - World " + client.getWorld()); } if (config.showCannon() && event.getMessage().equals(CANNON_PICKUP_MESSAGE)) { removeGameTimer(CANNON); } if (config.showMagicImbue() && event.getMessage().equals(MAGIC_IMBUE_MESSAGE)) { createGameTimer(MAGICIMBUE); } if (event.getMessage().equals(MAGIC_IMBUE_EXPIRED_MESSAGE)) { removeGameTimer(MAGICIMBUE); } if (config.showTeleblock()) { Matcher m = TELEBLOCK_PATTERN.matcher(event.getMessage()); if (m.find()) { String minss = m.group("mins"); String secss = m.group("secs"); int mins = Integer.parseInt(minss); int secs = secss != null ? Integer.parseInt(secss) : 0; createGameTimer(TELEBLOCK, Duration.ofSeconds(mins * 60 + secs)); } else if (event.getMessage().contains(KILLED_TELEBLOCK_OPPONENT_TEXT)) { removeGameTimer(TELEBLOCK); } } if (config.showAntiFire() && event.getMessage().contains(SUPER_ANTIFIRE_DRINK_MESSAGE)) { createGameTimer(SUPERANTIFIRE); } if (config.showAntiFire() && event.getMessage().equals(SUPER_ANTIFIRE_EXPIRED_MESSAGE)) { removeGameTimer(SUPERANTIFIRE); } if (config.showImbuedHeart() && event.getMessage().equals(IMBUED_HEART_READY_MESSAGE)) { removeGameTimer(IMBUEDHEART); } if (config.showPrayerEnhance() && event.getMessage().startsWith("You drink some of your") && event.getMessage().contains("prayer enhance")) { createGameTimer(PRAYER_ENHANCE); } if (config.showPrayerEnhance() && event.getMessage().equals(PRAYER_ENHANCE_EXPIRED)) { removeGameTimer(PRAYER_ENHANCE); } if (config.showCharge() && event.getMessage().equals(CHARGE_MESSAGE)) { createGameTimer(CHARGE); } if (config.showCharge() && event.getMessage().equals(CHARGE_EXPIRED_MESSAGE)) { removeGameTimer(CHARGE); } if (config.showStaffOfTheDead() && event.getMessage().contains(STAFF_OF_THE_DEAD_SPEC_MESSAGE)) { createGameTimer(STAFF_OF_THE_DEAD); } if (config.showStaffOfTheDead() && event.getMessage().contains(STAFF_OF_THE_DEAD_SPEC_EXPIRED_MESSAGE)) { removeGameTimer(STAFF_OF_THE_DEAD); } if (config.showFreezes() && event.getMessage().equals(FROZEN_MESSAGE)) { freezeTimer = createGameTimer(ICEBARRAGE); freezeTime = client.getTickCount(); } if (config.showDivine()) { Matcher mDivine = DIVINE_POTION_PATTERN.matcher(event.getMessage()); if (mDivine.find()) { switch (mDivine.group(1)) { case "super attack": createGameTimer(DIVINE_SUPER_ATTACK); break; case "super strength": createGameTimer(DIVINE_SUPER_STRENGTH); break; case "super defence": createGameTimer(DIVINE_SUPER_DEFENCE); break; case "combat": createGameTimer(DIVINE_SUPER_COMBAT); break; case "ranging": createGameTimer(DIVINE_RANGING); break; case "magic": createGameTimer(DIVINE_MAGIC); break; case "bastion": createGameTimer(DIVINE_BASTION); break; case "battlemage": createGameTimer(DIVINE_BATTLEMAGE); break; } } } if (config.showTzhaarTimers()) { String message = event.getMessage(); Matcher matcher = TZHAAR_COMPLETE_MESSAGE.matcher(message); if (message.contains(TZHAAR_DEFEATED_MESSAGE) || matcher.matches()) { removeTzhaarTimer(); config.tzhaarStartTime(null); config.tzhaarLastTime(null); return; } Instant now = Instant.now(); matcher = TZHAAR_PAUSED_MESSAGE.matcher(message); if (matcher.find()) { config.tzhaarLastTime(now); createTzhaarTimer(); return; } matcher = TZHAAR_WAVE_MESSAGE.matcher(message); if (!matcher.find()) { return; } if (config.tzhaarStartTime() == null) { int wave = Integer.parseInt(matcher.group(1)); if (wave == 1) { if (isInInferno()) { config.tzhaarStartTime(now.minus(Duration.ofSeconds(6))); } else { config.tzhaarStartTime(now); } createTzhaarTimer(); } } else if (config.tzhaarLastTime() != null) { log.debug("Unpausing tzhaar timer"); Instant tzhaarStartTime = config.tzhaarStartTime(); tzhaarStartTime = tzhaarStartTime.plus(Duration.between(config.tzhaarLastTime(), now)); config.tzhaarStartTime(tzhaarStartTime); config.tzhaarLastTime(null); createTzhaarTimer(); } } }  @Subscribe void onVarbitChanged(VarbitChanged event); @Subscribe void onWidgetHiddenChanged(WidgetHiddenChanged event); @Subscribe void onConfigChanged(ConfigChanged event); @Subscribe void onMenuOptionClicked(MenuOptionClicked event); @Subscribe void onChatMessage(ChatMessage event); @Subscribe void onGameTick(GameTick event); @Subscribe void onGameStateChanged(GameStateChanged gameStateChanged); @Subscribe void onAnimationChanged(AnimationChanged event); @Subscribe void onGraphicChanged(GraphicChanged event); @Subscribe void onItemContainerChanged(ItemContainerChanged itemContainerChanged); @Subscribe void onNpcDespawned(NpcDespawned npcDespawned); @Subscribe void onActorDeath(ActorDeath actorDeath);  }
@Test public void testHalfTeleblock() { when(timersConfig.showTeleblock()).thenReturn(true); ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "<col=4f006f>A Tele Block spell has been cast on you by Runelite. It will expire in 2 minutes, 30 seconds.</col>", "", 0); timersPlugin.onChatMessage(chatMessage); ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager).addInfoBox(captor.capture()); TimerTimer infoBox = (TimerTimer) captor.getValue(); assertEquals(GameTimer.TELEBLOCK, infoBox.getTimer()); assertEquals(Duration.ofSeconds(2 * 60 + 30), infoBox.getDuration()); }
@Test public void testFullTeleblock() { when(timersConfig.showTeleblock()).thenReturn(true); ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "<col=4f006f>A Tele Block spell has been cast on you by Runelite. It will expire in 5 minutes.</col>", "", 0); timersPlugin.onChatMessage(chatMessage); ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager).addInfoBox(captor.capture()); TimerTimer infoBox = (TimerTimer) captor.getValue(); assertEquals(GameTimer.TELEBLOCK, infoBox.getTimer()); assertEquals(Duration.ofMinutes(5), infoBox.getDuration()); }
@Test public void testDmmHalfTb() { when(timersConfig.showTeleblock()).thenReturn(true); ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "<col=4f006f>A Tele Block spell has been cast on you by Runelite. It will expire in 1 minute, 15 seconds.</col>", "", 0); timersPlugin.onChatMessage(chatMessage); ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager).addInfoBox(captor.capture()); TimerTimer infoBox = (TimerTimer) captor.getValue(); assertEquals(GameTimer.TELEBLOCK, infoBox.getTimer()); assertEquals(Duration.ofSeconds(60 + 15), infoBox.getDuration()); }
@Test public void testDmmFullTb() { when(timersConfig.showTeleblock()).thenReturn(true); ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "<col=4f006f>A Tele Block spell has been cast on you by Runelite. It will expire in 2 minutes, 30 seconds.</col>", "", 0); timersPlugin.onChatMessage(chatMessage); ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager).addInfoBox(captor.capture()); TimerTimer infoBox = (TimerTimer) captor.getValue(); assertEquals(GameTimer.TELEBLOCK, infoBox.getTimer()); assertEquals(Duration.ofSeconds(60 * 2 + 30), infoBox.getDuration()); }
@Test public void testDivineBastion() { when(timersConfig.showDivine()).thenReturn(true); ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "You drink some of your divine bastion potion.", "", 0); timersPlugin.onChatMessage(chatMessage); ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager).addInfoBox(captor.capture()); TimerTimer infoBox = (TimerTimer) captor.getValue(); assertEquals(GameTimer.DIVINE_BASTION, infoBox.getTimer()); }
@Test public void testDivineBattlemage() { when(timersConfig.showDivine()).thenReturn(true); ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "You drink some of your divine battlemage potion.", "", 0); timersPlugin.onChatMessage(chatMessage); ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager).addInfoBox(captor.capture()); TimerTimer infoBox = (TimerTimer) captor.getValue(); assertEquals(GameTimer.DIVINE_BATTLEMAGE, infoBox.getTimer()); }
@Test public void testTransparentChatboxTb() { when(timersConfig.showTeleblock()).thenReturn(true); ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "<col=c356ef>A Tele Block spell has been cast on you by Alexsuperfly. It will expire in 5 minutes.</col>", "", 0); timersPlugin.onChatMessage(chatMessage); ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager).addInfoBox(captor.capture()); TimerTimer infoBox = (TimerTimer) captor.getValue(); assertEquals(GameTimer.TELEBLOCK, infoBox.getTimer()); assertEquals(Duration.ofMinutes(5), infoBox.getDuration()); }
@Test public void testTransparentChatboxTbRemoved() { when(timersConfig.showTeleblock()).thenReturn(true); ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "<col=c356ef>Your Tele Block has been removed because you killed Alexsuperfly.</col>", "", 0); timersPlugin.onChatMessage(chatMessage); verify(infoBoxManager, atLeastOnce()).removeIf(any()); }
@Test public void testMageArena2TbFull() { when(timersConfig.showTeleblock()).thenReturn(true); ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "<col=c356ef>A Tele Block spell has been cast on you. It will expire in 2 minutes.</col>", "", 0); timersPlugin.onChatMessage(chatMessage); ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager).addInfoBox(captor.capture()); TimerTimer infoBox = (TimerTimer) captor.getValue(); assertEquals(GameTimer.TELEBLOCK, infoBox.getTimer()); assertEquals(Duration.ofMinutes(2), infoBox.getDuration()); }
@Test public void testMageArena2TbHalf() { when(timersConfig.showTeleblock()).thenReturn(true); ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "<col=c356ef>A Tele Block spell has been cast on you. It will expire in 1 minute.</col>", "", 0); timersPlugin.onChatMessage(chatMessage); ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager).addInfoBox(captor.capture()); TimerTimer infoBox = (TimerTimer) captor.getValue(); assertEquals(GameTimer.TELEBLOCK, infoBox.getTimer()); assertEquals(Duration.ofMinutes(1), infoBox.getDuration()); }
@Test public void testStamina() { when(timersConfig.showStamina()).thenReturn(true); ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "You drink some of your stamina potion.", "", 0); timersPlugin.onChatMessage(chatMessage); ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager).addInfoBox(captor.capture()); TimerTimer infoBox = (TimerTimer) captor.getValue(); assertEquals(GameTimer.STAMINA, infoBox.getTimer()); assertEquals(Duration.ofMinutes(2), infoBox.getDuration()); }
@Test public void testTzhaarTimer() { when(timersConfig.showTzhaarTimers()).thenReturn(true); when(client.getMapRegions()).thenReturn(new int[]{TimersPlugin.FIGHT_CAVES_REGION_ID}); class InstantRef { Instant i; } InstantRef startTime = new InstantRef(); when(timersConfig.tzhaarStartTime()).then(a -> startTime.i); doAnswer((Answer<Void>) invocationOnMock -> { Object argument = invocationOnMock.getArguments()[0]; startTime.i = (Instant) argument; return null; }).when(timersConfig).tzhaarStartTime(nullable(Instant.class)); InstantRef lastTime = new InstantRef(); when(timersConfig.tzhaarLastTime()).then(a -> lastTime.i); doAnswer((Answer<Void>) invocationOnMock -> { Object argument = invocationOnMock.getArguments()[0]; lastTime.i = (Instant) argument; return null; }).when(timersConfig).tzhaarLastTime(nullable(Instant.class)); ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", "<col=ef1020>Wave: 1</col>", "", 0); timersPlugin.onChatMessage(chatMessage); ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager, times(1)).addInfoBox(captor.capture()); assertTrue(captor.getValue() instanceof ElapsedTimer); chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", "<col=ef1020>The Inferno has been paused. You may now log out.", "", 0); timersPlugin.onChatMessage(chatMessage); verify(infoBoxManager, times(1)).removeInfoBox(captor.capture()); verify(infoBoxManager, times(2)).addInfoBox(captor.capture()); assertTrue(captor.getValue() instanceof ElapsedTimer); ElapsedTimer timer = (ElapsedTimer) captor.getValue(); assertNotEquals(timer.getLastTime(), null); Instant oldTime = ((ElapsedTimer) captor.getValue()).getStartTime(); chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", "<col=ef1020>Wave: 2</col>", "", 0); timersPlugin.onChatMessage(chatMessage); verify(infoBoxManager, times(2)).removeInfoBox(captor.capture()); verify(infoBoxManager, times(3)).addInfoBox(captor.capture()); assertTrue(captor.getValue() instanceof ElapsedTimer); timer = (ElapsedTimer) captor.getValue(); assertNull(timer.getLastTime()); chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", "You have been defeated!", "", 0); timersPlugin.onChatMessage(chatMessage); verify(infoBoxManager, times(3)).removeInfoBox(captor.capture()); verify(infoBoxManager, times(3)).addInfoBox(captor.capture()); }
@Test public void testInfernoTimerStartOffset() { when(timersConfig.showTzhaarTimers()).thenReturn(true); when(client.getMapRegions()).thenReturn(new int[]{TimersPlugin.INFERNO_REGION_ID}); class InstantRef { Instant i; } InstantRef startTime = new InstantRef(); when(timersConfig.tzhaarStartTime()).then(a -> startTime.i); doAnswer((Answer<Void>) invocationOnMock -> { Object argument = invocationOnMock.getArguments()[0]; startTime.i = (Instant) argument; return null; }).when(timersConfig).tzhaarStartTime(nullable(Instant.class)); ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", "<col=ef1020>Wave: 1</col>", "", 0); timersPlugin.onChatMessage(chatMessage); ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager, times(1)).addInfoBox(captor.capture()); assertTrue(captor.getValue() instanceof ElapsedTimer); ElapsedTimer timer = (ElapsedTimer) captor.getValue(); assertEquals("00:06", timer.getText()); }