ChatCommandsPlugin extends Plugin { private void playerSkillLookup(ChatMessage chatMessage, String message) { if (!config.lvl()) { return; } String search; if (message.equalsIgnoreCase(TOTAL_LEVEL_COMMAND_STRING)) { search = "total"; } else { if (message.length() <= LEVEL_COMMAND_STRING.length()) { return; } search = message.substring(LEVEL_COMMAND_STRING.length() + 1); } search = SkillAbbreviations.getFullName(search); final HiscoreSkill skill; try { skill = HiscoreSkill.valueOf(search.toUpperCase()); } catch (IllegalArgumentException i) { return; } final HiscoreLookup lookup = getCorrectLookupFor(chatMessage); try { final SingleHiscoreSkillResult result = hiscoreClient.lookup(lookup.getName(), skill, lookup.getEndpoint()); if (result == null) { log.warn("unable to look up skill {} for {}: not found", skill, search); return; } final Skill hiscoreSkill = result.getSkill(); ChatMessageBuilder chatMessageBuilder = new ChatMessageBuilder() .append(ChatColorType.NORMAL) .append("Level ") .append(ChatColorType.HIGHLIGHT) .append(skill.getName()).append(": ").append(String.valueOf(hiscoreSkill.getLevel())) .append(ChatColorType.NORMAL); if (hiscoreSkill.getExperience() != -1) { chatMessageBuilder.append(" Experience: ") .append(ChatColorType.HIGHLIGHT) .append(String.format("%,d", hiscoreSkill.getExperience())) .append(ChatColorType.NORMAL); } if (hiscoreSkill.getRank() != -1) { chatMessageBuilder.append(" Rank: ") .append(ChatColorType.HIGHLIGHT) .append(String.format("%,d", hiscoreSkill.getRank())); } final String response = chatMessageBuilder.build(); log.debug("Setting response {}", response); final MessageNode messageNode = chatMessage.getMessageNode(); messageNode.setRuneLiteFormatMessage(response); chatMessageManager.update(messageNode); client.refreshChat(); } catch (IOException ex) { log.warn("unable to look up skill {} for {}", skill, search, ex); } }  @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 testPlayerSkillLookup() throws IOException { Player player = mock(Player.class); when(player.getName()).thenReturn(PLAYER_NAME); when(client.getLocalPlayer()).thenReturn(player); when(chatCommandsConfig.lvl()).thenReturn(true); ArgumentCaptor<BiConsumer<ChatMessage, String>> captor = ArgumentCaptor.forClass(BiConsumer.class); verify(chatCommandManager).registerCommandAsync(eq("!lvl"), captor.capture()); BiConsumer<ChatMessage, String> value = captor.getValue(); SingleHiscoreSkillResult skillResult = new SingleHiscoreSkillResult(); skillResult.setPlayer(PLAYER_NAME); skillResult.setSkill(new Skill(10, 1000, -1)); when(hiscoreClient.lookup(PLAYER_NAME, HiscoreSkill.ZULRAH, null)).thenReturn(skillResult); MessageNode messageNode = mock(MessageNode.class); ChatMessage chatMessage = new ChatMessage(); chatMessage.setType(ChatMessageType.PUBLICCHAT); chatMessage.setName(PLAYER_NAME); chatMessage.setMessageNode(messageNode); value.accept(chatMessage, "!lvl zulrah"); verify(messageNode).setRuneLiteFormatMessage("<colNORMAL>Level <colHIGHLIGHT>Zulrah: 1000<colNORMAL> Rank: <colHIGHLIGHT>10"); }