use of net.runelite.http.api.hiscore.HiscoreSkill 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.HiscoreSkill in project runelite by runelite.
the class HiscorePanel method makeSkillPanel.
private JPanel makeSkillPanel(String skillName, HiscoreSkill skill) {
JLabel label = new JLabel();
label.setText("--");
// Store the skill that the label displays so we can tell them apart
label.putClientProperty(SKILL_NAME, skillName);
label.putClientProperty(SKILL, skill);
String skillIcon = "skill_icons_small/" + skillName.toLowerCase() + ".png";
log.debug("Loading skill icon from {}", skillIcon);
try {
BufferedImage icon;
synchronized (ImageIO.class) {
icon = ImageIO.read(HiscorePanel.class.getResourceAsStream(skillIcon));
}
label.setIcon(new ImageIcon(icon));
} catch (IOException ex) {
log.warn(null, ex);
}
// Show skill details on hover
label.addMouseListener(new MouseInputAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
JLabel source = (JLabel) e.getSource();
String skillName = (String) source.getClientProperty(SKILL_NAME);
HiscoreSkill skill = (HiscoreSkill) label.getClientProperty(SKILL);
changeDetail(skillName, skill);
}
});
skillLabels.add(label);
JPanel skillPanel = new JPanel();
skillPanel.add(skillLabels.get(skillLabels.size() - 1));
return skillPanel;
}
use of net.runelite.http.api.hiscore.HiscoreSkill in project runelite by runelite.
the class HiscorePanel method lookup.
private void lookup() {
String lookup = input.getText();
details.setText("Loading...");
lookup = sanitize(lookup);
if (Strings.isNullOrEmpty(lookup)) {
return;
}
for (JLabel label : skillLabels) {
label.setText("--");
}
try {
HiscoreEndpoint endpoint = HiscoreEndpoint.valueOf(endpointButtonGroup.getSelection().getActionCommand());
log.debug("Hiscore endpoint " + endpoint.name() + " selected");
result = client.lookup(lookup, endpoint);
} catch (IOException ex) {
log.warn("Error fetching Hiscore data " + ex.getMessage());
details.setText("Error fetching Hiscore data");
return;
}
for (JLabel label : skillLabels) {
String skillName = (String) label.getClientProperty(SKILL_NAME);
HiscoreSkill skill = (HiscoreSkill) label.getClientProperty(SKILL);
if (skillName.equals("Combat")) {
if (result.getPlayer() != null) {
int combatLevel = Experience.getCombatLevel(result.getAttack().getLevel(), result.getStrength().getLevel(), result.getDefence().getLevel(), result.getHitpoints().getLevel(), result.getMagic().getLevel(), result.getRanged().getLevel(), result.getPrayer().getLevel());
label.setText(Integer.toString(combatLevel));
}
} else if (result.getSkill(skill) != null && result.getSkill(skill).getRank() != -1) {
label.setText(Integer.toString(result.getSkill(skill).getLevel()));
}
}
// Clear details panel
details.setFont(UIManager.getFont("Label.font").deriveFont(Font.ITALIC));
details.setText("Hover over a skill for details");
}
use of net.runelite.http.api.hiscore.HiscoreSkill 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;
}
Aggregations