Search in sources :

Example 1 with HiscoreSkill

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);
    }
}
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 HiscoreSkill

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;
}
Also used : ImageIcon(javax.swing.ImageIcon) JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) JLabel(javax.swing.JLabel) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) MouseInputAdapter(javax.swing.event.MouseInputAdapter) HiscoreSkill(net.runelite.http.api.hiscore.HiscoreSkill) ImageIO(javax.imageio.ImageIO)

Example 3 with HiscoreSkill

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");
}
Also used : JLabel(javax.swing.JLabel) IOException(java.io.IOException) HiscoreEndpoint(net.runelite.http.api.hiscore.HiscoreEndpoint) HiscoreSkill(net.runelite.http.api.hiscore.HiscoreSkill) HiscoreEndpoint(net.runelite.http.api.hiscore.HiscoreEndpoint)

Example 4 with HiscoreSkill

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;
}
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)4 IOException (java.io.IOException)3 JLabel (javax.swing.JLabel)2 SingleHiscoreSkillResult (net.runelite.http.api.hiscore.SingleHiscoreSkillResult)2 Skill (net.runelite.http.api.hiscore.Skill)2 MouseEvent (java.awt.event.MouseEvent)1 BufferedImage (java.awt.image.BufferedImage)1 ImageIO (javax.imageio.ImageIO)1 ImageIcon (javax.swing.ImageIcon)1 JPanel (javax.swing.JPanel)1 MouseInputAdapter (javax.swing.event.MouseInputAdapter)1 MessageNode (net.runelite.api.MessageNode)1 ChatMessageBuilder (net.runelite.client.chat.ChatMessageBuilder)1 HiscoreEndpoint (net.runelite.http.api.hiscore.HiscoreEndpoint)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1