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);
}
}
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;
}
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());
}
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;
}
Aggregations