SlayerPlugin extends Plugin { @Subscribe public void onChatMessage(ChatMessage event) { if (event.getType() != ChatMessageType.GAMEMESSAGE && event.getType() != ChatMessageType.SPAM) { return; } String chatMsg = Text.removeTags(event.getMessage()); if (chatMsg.startsWith(CHAT_BRACELET_SLAUGHTER)) { Matcher mSlaughter = CHAT_BRACELET_SLAUGHTER_REGEX.matcher(chatMsg); amount++; slaughterChargeCount = mSlaughter.find() ? Integer.parseInt(mSlaughter.group(1)) : SLAUGHTER_CHARGE; config.slaughter(slaughterChargeCount); } if (chatMsg.startsWith(CHAT_BRACELET_EXPEDITIOUS)) { Matcher mExpeditious = CHAT_BRACELET_EXPEDITIOUS_REGEX.matcher(chatMsg); amount--; expeditiousChargeCount = mExpeditious.find() ? Integer.parseInt(mExpeditious.group(1)) : EXPEDITIOUS_CHARGE; config.expeditious(expeditiousChargeCount); } if (chatMsg.startsWith(CHAT_BRACELET_EXPEDITIOUS_CHARGE)) { Matcher mExpeditious = CHAT_BRACELET_EXPEDITIOUS_CHARGE_REGEX.matcher(chatMsg); if (!mExpeditious.find()) { return; } expeditiousChargeCount = Integer.parseInt(mExpeditious.group(1)); config.expeditious(expeditiousChargeCount); } if (chatMsg.startsWith(CHAT_BRACELET_SLAUGHTER_CHARGE)) { Matcher mSlaughter = CHAT_BRACELET_SLAUGHTER_CHARGE_REGEX.matcher(chatMsg); if (!mSlaughter.find()) { return; } slaughterChargeCount = Integer.parseInt(mSlaughter.group(1)); config.slaughter(slaughterChargeCount); } if (chatMsg.startsWith("You've completed") && (chatMsg.contains("Slayer master") || chatMsg.contains("Slayer Master"))) { Matcher mComplete = CHAT_COMPLETE_MESSAGE.matcher(chatMsg); List<String> matches = new ArrayList<>(); while (mComplete.find()) { matches.add(mComplete.group(0).replaceAll(",", "")); } int streak = -1, points = -1; switch (matches.size()) { case 0: streak = 1; break; case 1: streak = Integer.parseInt(matches.get(0)); break; case 3: streak = Integer.parseInt(matches.get(0)); points = Integer.parseInt(matches.get(2)); break; default: log.warn("Unreachable default case for message ending in '; return to Slayer master'"); } if (streak != -1) { config.streak(streak); } if (points != -1) { config.points(points); } setTask("", 0, 0); return; } if (chatMsg.equals(CHAT_GEM_COMPLETE_MESSAGE) || chatMsg.equals(CHAT_CANCEL_MESSAGE) || chatMsg.equals(CHAT_CANCEL_MESSAGE_JAD) || chatMsg.equals(CHAT_CANCEL_MESSAGE_ZUK)) { setTask("", 0, 0); return; } if (config.showSuperiorNotification() && chatMsg.equals(CHAT_SUPERIOR_MESSAGE)) { notifier.notify(CHAT_SUPERIOR_MESSAGE); return; } Matcher mProgress = CHAT_GEM_PROGRESS_MESSAGE.matcher(chatMsg); if (mProgress.find()) { String name = mProgress.group("name"); int gemAmount = Integer.parseInt(mProgress.group("amount")); String location = mProgress.group("location"); setTask(name, gemAmount, initialAmount, location); return; } final Matcher bracerProgress = COMBAT_BRACELET_TASK_UPDATE_MESSAGE.matcher(chatMsg); if (bracerProgress.find()) { final int taskAmount = Integer.parseInt(bracerProgress.group(1)); setTask(taskName, taskAmount, initialAmount); amount++; } }  @Subscribe void onGameStateChanged(GameStateChanged event); @Subscribe void onNpcSpawned(NpcSpawned npcSpawned); @Subscribe void onNpcDespawned(NpcDespawned npcDespawned); @Subscribe void onGameTick(GameTick tick); @Subscribe void onChatMessage(ChatMessage event); @Subscribe void onStatChanged(StatChanged statChanged); @Subscribe void onHitsplatApplied(HitsplatApplied hitsplatApplied); @Subscribe void onActorDeath(ActorDeath actorDeath);  }
@Test public void testPartnerTask() { ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", TASK_NEW_FROM_PARTNER, null, 0); slayerPlugin.onChatMessage(chatMessageEvent); assertEquals("Dust Devils", slayerPlugin.getTaskName()); assertEquals(377, slayerPlugin.getAmount()); }
@Test public void testCheckSlayerGem() { ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", TASK_CHECKSLAYERGEM, null, 0); slayerPlugin.onChatMessage(chatMessageEvent); assertEquals("Suqahs", slayerPlugin.getTaskName()); assertEquals(211, slayerPlugin.getAmount()); }
@Test public void testCheckSlayerGemWildernessTask() { ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", TASK_CHECKSLAYERGEM_WILDERNESS, null, 0); slayerPlugin.onChatMessage(chatMessageEvent); assertEquals("Suqahs", slayerPlugin.getTaskName()); assertEquals(211, slayerPlugin.getAmount()); assertEquals("Wilderness", slayerPlugin.getTaskLocation()); }
@Test public void testCheckSlayerGemKonarTask() { ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", TASK_CHECKSLAYERGEM_KONAR, null, 0); slayerPlugin.onChatMessage(chatMessageEvent); assertEquals("Blue dragons", slayerPlugin.getTaskName()); assertEquals(122, slayerPlugin.getAmount()); assertEquals("Ogre Enclave", slayerPlugin.getTaskLocation()); }
@Test public void testOneTask() { ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Perterter", TASK_ONE, null, 0); slayerPlugin.onChatMessage(chatMessageEvent); verify(slayerConfig).streak(1); assertEquals("", slayerPlugin.getTaskName()); assertEquals(0, slayerPlugin.getAmount()); }
@Test public void testNoPoints() { ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Perterter", TASK_COMPLETE_NO_POINTS, null, 0); slayerPlugin.onChatMessage(chatMessageEvent); verify(slayerConfig).streak(3); assertEquals("", slayerPlugin.getTaskName()); assertEquals(0, slayerPlugin.getAmount()); }
@Test public void testPoints() { ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Perterter", TASK_POINTS, null, 0); slayerPlugin.onChatMessage(chatMessageEvent); verify(slayerConfig).streak(9); assertEquals("", slayerPlugin.getTaskName()); assertEquals(0, slayerPlugin.getAmount()); verify(slayerConfig).points(18_000); }
@Test public void testLargeStreak() { ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Perterter", TASK_LARGE_STREAK, null, 0); slayerPlugin.onChatMessage(chatMessageEvent); verify(slayerConfig).streak(2465); assertEquals("", slayerPlugin.getTaskName()); assertEquals(0, slayerPlugin.getAmount()); verify(slayerConfig).points(17_566_000); }
@Test public void testTaskCompleteTurael() { ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Perterter", TASK_COMPETE_TURAEL, null, 0); slayerPlugin.onChatMessage(chatMessageEvent); verify(slayerConfig).streak(104); assertEquals("", slayerPlugin.getTaskName()); assertEquals(0, slayerPlugin.getAmount()); }
@Test public void testComplete() { slayerPlugin.setTaskName("cows"); slayerPlugin.setAmount(42); ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Perterter", TASK_COMPLETE, null, 0); slayerPlugin.onChatMessage(chatMessageEvent); assertEquals("", slayerPlugin.getTaskName()); assertEquals(0, slayerPlugin.getAmount()); }
@Test public void testCancelled() { slayerPlugin.setTaskName("cows"); slayerPlugin.setAmount(42); ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Perterter", TASK_CANCELED, null, 0); slayerPlugin.onChatMessage(chatMessageEvent); assertEquals("", slayerPlugin.getTaskName()); assertEquals(0, slayerPlugin.getAmount()); }
@Test public void testSuperiorNotification() { ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Superior", SUPERIOR_MESSAGE, null, 0); when(slayerConfig.showSuperiorNotification()).thenReturn(true); slayerPlugin.onChatMessage(chatMessageEvent); verify(notifier).notify(SUPERIOR_MESSAGE); when(slayerConfig.showSuperiorNotification()).thenReturn(false); slayerPlugin.onChatMessage(chatMessageEvent); verifyNoMoreInteractions(notifier); }