Search in sources :

Example 1 with Skill

use of net.runelite.http.api.hiscore.Skill 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 Skill

use of net.runelite.http.api.hiscore.Skill 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)

Example 3 with Skill

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

the class XpMapperTest method testHiscoreResultToXpData.

@Test
public void testHiscoreResultToXpData() {
    HiscoreResult hiscoreResult = new HiscoreResult();
    hiscoreResult.setAgility(new Skill(42, 9, 9001));
    XpData xpData = XpMapper.INSTANCE.hiscoreResultToXpData(hiscoreResult);
    assertEquals(42, xpData.getAgility_rank());
    assertEquals(9001, xpData.getAgility_xp());
}
Also used : Skill(net.runelite.http.api.hiscore.Skill) XpData(net.runelite.http.api.xp.XpData) HiscoreResult(net.runelite.http.api.hiscore.HiscoreResult) Test(org.junit.Test)

Example 4 with Skill

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

the class HiscoreService method lookupUsername.

public HiscoreResultBuilder lookupUsername(String username, HttpUrl hiscoreUrl) throws IOException {
    HttpUrl url = hiscoreUrl.newBuilder().addQueryParameter("player", username).build();
    log.debug("Built URL {}", url);
    Request okrequest = new Request.Builder().url(url).build();
    String responseStr;
    try (Response okresponse = RuneLiteAPI.CLIENT.newCall(okrequest).execute()) {
        if (!okresponse.isSuccessful()) {
            switch(HttpStatus.valueOf(okresponse.code())) {
                case NOT_FOUND:
                    throw new NotFoundException();
                default:
                    throw new InternalServerErrorException("Error retrieving data from Jagex Hiscores: " + okresponse.message());
            }
        }
        responseStr = okresponse.body().string();
    }
    CSVParser parser = CSVParser.parse(responseStr, CSVFormat.DEFAULT);
    HiscoreResultBuilder hiscoreBuilder = new HiscoreResultBuilder();
    hiscoreBuilder.setPlayer(username);
    int count = 0;
    for (CSVRecord record : parser.getRecords()) {
        if (count++ >= HiscoreSkill.values().length) {
            log.warn("Jagex Hiscore API returned unexpected data");
            // rest is other things?
            break;
        }
        // rank, level, experience
        int rank = Integer.parseInt(record.get(0));
        int level = Integer.parseInt(record.get(1));
        // items that are not skills do not have an experience parameter
        long experience = -1;
        if (record.size() == 3) {
            experience = Long.parseLong(record.get(2));
        }
        Skill skill = new Skill(rank, level, experience);
        hiscoreBuilder.setNextSkill(skill);
    }
    return hiscoreBuilder;
}
Also used : Request(okhttp3.Request) NotFoundException(net.runelite.http.service.util.exception.NotFoundException) HttpUrl(okhttp3.HttpUrl) HiscoreEndpoint(net.runelite.http.api.hiscore.HiscoreEndpoint) Response(okhttp3.Response) Skill(net.runelite.http.api.hiscore.Skill) HiscoreSkill(net.runelite.http.api.hiscore.HiscoreSkill) CSVParser(org.apache.commons.csv.CSVParser) InternalServerErrorException(net.runelite.http.service.util.exception.InternalServerErrorException) CSVRecord(org.apache.commons.csv.CSVRecord)

Aggregations

Skill (net.runelite.http.api.hiscore.Skill)4 HiscoreSkill (net.runelite.http.api.hiscore.HiscoreSkill)3 SingleHiscoreSkillResult (net.runelite.http.api.hiscore.SingleHiscoreSkillResult)2 IOException (java.io.IOException)1 MessageNode (net.runelite.api.MessageNode)1 ChatMessageBuilder (net.runelite.client.chat.ChatMessageBuilder)1 HiscoreEndpoint (net.runelite.http.api.hiscore.HiscoreEndpoint)1 HiscoreResult (net.runelite.http.api.hiscore.HiscoreResult)1 XpData (net.runelite.http.api.xp.XpData)1 InternalServerErrorException (net.runelite.http.service.util.exception.InternalServerErrorException)1 NotFoundException (net.runelite.http.service.util.exception.NotFoundException)1 HttpUrl (okhttp3.HttpUrl)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1 CSVParser (org.apache.commons.csv.CSVParser)1 CSVRecord (org.apache.commons.csv.CSVRecord)1 Test (org.junit.Test)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1