Search in sources :

Example 1 with SingleHiscoreSkillResult

use of net.runelite.http.api.hiscore.SingleHiscoreSkillResult in project runelite by runelite.

the class ChatCommandsPlugin method playerSkillLookup.

/**
 * Looks up the player skill and changes the original message to the
 * response.
 *
 * @param setMessage The chat message containing the command.
 * @param search The item given with the command.
 */
private void playerSkillLookup(ChatMessageType type, SetMessage setMessage, String search) {
    search = SkillAbbreviations.getFullName(search);
    String player;
    if (type.equals(ChatMessageType.PRIVATE_MESSAGE_SENT)) {
        player = client.getLocalPlayer().getName();
    } else {
        player = sanitize(setMessage.getName());
    }
    HiscoreSkill skill;
    try {
        skill = HiscoreSkill.valueOf(search.toUpperCase());
    } catch (IllegalArgumentException i) {
        return;
    }
    try {
        SingleHiscoreSkillResult result = hiscoreClient.lookup(player, skill);
        Skill hiscoreSkill = result.getSkill();
        String response = new ChatMessageBuilder().append(ChatColorType.NORMAL).append("Level ").append(ChatColorType.HIGHLIGHT).append(skill.getName()).append(": ").append(String.valueOf(hiscoreSkill.getLevel())).append(ChatColorType.NORMAL).append(" Experience: ").append(ChatColorType.HIGHLIGHT).append(String.format("%,d", hiscoreSkill.getExperience())).append(ChatColorType.NORMAL).append(" Rank: ").append(ChatColorType.HIGHLIGHT).append(String.format("%,d", hiscoreSkill.getRank())).build();
        log.debug("Setting response {}", response);
        final MessageNode messageNode = setMessage.getMessageNode();
        messageNode.setRuneLiteFormatMessage(response);
        chatMessageManager.update(messageNode);
        client.refreshChat();
    } catch (IOException ex) {
        log.warn("unable to look up skill {} for {}", skill, search, ex);
    }
}
Also used : Skill(net.runelite.http.api.hiscore.Skill) HiscoreSkill(net.runelite.http.api.hiscore.HiscoreSkill) MessageNode(net.runelite.api.MessageNode) SingleHiscoreSkillResult(net.runelite.http.api.hiscore.SingleHiscoreSkillResult) IOException(java.io.IOException) HiscoreSkill(net.runelite.http.api.hiscore.HiscoreSkill) ChatMessageBuilder(net.runelite.client.chat.ChatMessageBuilder)

Example 2 with SingleHiscoreSkillResult

use of net.runelite.http.api.hiscore.SingleHiscoreSkillResult in project runelite by runelite.

the class HiscoreController method singleSkillLookup.

@RequestMapping("/{endpoint}/{skillName}")
public SingleHiscoreSkillResult singleSkillLookup(@PathVariable HiscoreEndpoint endpoint, @PathVariable String skillName, @RequestParam String username) throws IOException {
    HiscoreSkill skill = HiscoreSkill.valueOf(skillName.toUpperCase());
    // RS api only supports looking up all stats
    HiscoreResultBuilder result = hiscoreService.lookupUsername(username, endpoint);
    // Find the skill to return
    Skill requested = result.getSkill(skill.ordinal());
    SingleHiscoreSkillResult skillResult = new SingleHiscoreSkillResult();
    skillResult.setPlayer(username);
    skillResult.setSkillName(skillName);
    skillResult.setSkill(requested);
    return skillResult;
}
Also used : Skill(net.runelite.http.api.hiscore.Skill) HiscoreSkill(net.runelite.http.api.hiscore.HiscoreSkill) SingleHiscoreSkillResult(net.runelite.http.api.hiscore.SingleHiscoreSkillResult) HiscoreSkill(net.runelite.http.api.hiscore.HiscoreSkill) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

HiscoreSkill (net.runelite.http.api.hiscore.HiscoreSkill)2 SingleHiscoreSkillResult (net.runelite.http.api.hiscore.SingleHiscoreSkillResult)2 Skill (net.runelite.http.api.hiscore.Skill)2 IOException (java.io.IOException)1 MessageNode (net.runelite.api.MessageNode)1 ChatMessageBuilder (net.runelite.client.chat.ChatMessageBuilder)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1