SlayerPlugin extends Plugin { void taskLookup(ChatMessage chatMessage, String message) { if (!config.taskCommand()) { return; } ChatMessageType type = chatMessage.getType(); final String player; if (type.equals(ChatMessageType.PRIVATECHATOUT)) { player = client.getLocalPlayer().getName(); } else { player = Text.removeTags(chatMessage.getName()) .replace('\u00A0', ' '); } net.runelite.http.api.chat.Task task; try { task = chatClient.getTask(player); } catch (IOException ex) { log.debug("unable to lookup slayer task", ex); return; } if (TASK_STRING_VALIDATION.matcher(task.getTask()).find() || task.getTask().length() > TASK_STRING_MAX_LENGTH || TASK_STRING_VALIDATION.matcher(task.getLocation()).find() || task.getLocation().length() > TASK_STRING_MAX_LENGTH || Task.getTask(task.getTask()) == null || !Task.LOCATIONS.contains(task.getLocation())) { log.debug("Validation failed for task name or location: {}", task); return; } int killed = task.getInitialAmount() - task.getAmount(); StringBuilder sb = new StringBuilder(); sb.append(task.getTask()); if (!Strings.isNullOrEmpty(task.getLocation())) { sb.append(" (").append(task.getLocation()).append(")"); } sb.append(": "); if (killed < 0) { sb.append(task.getAmount()).append(" left"); } else { sb.append(killed).append('/').append(task.getInitialAmount()).append(" killed"); } String response = new ChatMessageBuilder() .append(ChatColorType.NORMAL) .append("Slayer Task: ") .append(ChatColorType.HIGHLIGHT) .append(sb.toString()) .build(); final MessageNode messageNode = chatMessage.getMessageNode(); messageNode.setRuneLiteFormatMessage(response); chatMessageManager.update(messageNode); client.refreshChat(); }  @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 testTaskLookup() throws IOException { net.runelite.http.api.chat.Task task = new net.runelite.http.api.chat.Task(); task.setTask("Abyssal demons"); task.setLocation("Abyss"); task.setAmount(42); task.setInitialAmount(42); when(slayerConfig.taskCommand()).thenReturn(true); when(chatClient.getTask(anyString())).thenReturn(task); ChatMessage setMessage = new ChatMessage(); setMessage.setType(ChatMessageType.PUBLICCHAT); setMessage.setName("Adam"); setMessage.setMessageNode(mock(MessageNode.class)); slayerPlugin.taskLookup(setMessage, "!task"); verify(chatMessageManager).update(any(MessageNode.class)); }