Search in sources :

Example 1 with MessageNode

use of net.runelite.api.MessageNode 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 MessageNode

use of net.runelite.api.MessageNode in project runelite by runelite.

the class ChatMessageManager method add.

private void add(QueuedMessage message) {
    final Client client = clientProvider.get();
    // this updates chat cycle
    client.addChatMessage(message.getType(), MoreObjects.firstNonNull(message.getName(), ""), MoreObjects.firstNonNull(message.getValue(), message.getRuneLiteFormattedMessage()), message.getSender());
    // Get last message from line buffer (the one we just added)
    final ChatLineBuffer chatLineBuffer = client.getChatLineMap().get(message.getType().getType());
    final MessageNode[] lines = chatLineBuffer.getLines();
    final MessageNode line = lines[0];
    // Update the message with RuneLite additions
    line.setRuneLiteFormatMessage(message.getRuneLiteFormattedMessage());
    update(line);
}
Also used : ChatLineBuffer(net.runelite.api.ChatLineBuffer) MessageNode(net.runelite.api.MessageNode) Client(net.runelite.api.Client)

Example 3 with MessageNode

use of net.runelite.api.MessageNode in project runelite by runelite.

the class ChatCommandsPlugin method onSetMessage.

/**
 * Checks if the chat message is a command.
 *
 * @param setMessage The chat message.
 */
@Subscribe
public void onSetMessage(SetMessage setMessage) {
    if (client.getGameState() != GameState.LOGGED_IN) {
        return;
    }
    switch(setMessage.getType()) {
        case PUBLIC:
        case CLANCHAT:
        case PRIVATE_MESSAGE_RECEIVED:
        case PRIVATE_MESSAGE_SENT:
            break;
        default:
            return;
    }
    String message = setMessage.getValue();
    MessageNode messageNode = setMessage.getMessageNode();
    // clear RuneLite formatted message as the message node is
    // being reused
    messageNode.setRuneLiteFormatMessage(null);
    if (config.lvl() && message.toLowerCase().equals("!total")) {
        log.debug("Running total level lookup");
        executor.submit(() -> playerSkillLookup(setMessage.getType(), setMessage, "total"));
    } else if (config.price() && message.toLowerCase().startsWith("!price") && message.length() > 7) {
        String search = message.substring(7);
        log.debug("Running price lookup for {}", search);
        executor.submit(() -> itemPriceLookup(setMessage.getMessageNode(), search));
    } else if (config.lvl() && message.toLowerCase().startsWith("!lvl") && message.length() > 5) {
        String search = message.substring(5);
        log.debug("Running level lookup for {}", search);
        executor.submit(() -> playerSkillLookup(setMessage.getType(), setMessage, search));
    }
}
Also used : MessageNode(net.runelite.api.MessageNode) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

MessageNode (net.runelite.api.MessageNode)3 Subscribe (com.google.common.eventbus.Subscribe)1 IOException (java.io.IOException)1 ChatLineBuffer (net.runelite.api.ChatLineBuffer)1 Client (net.runelite.api.Client)1 ChatMessageBuilder (net.runelite.client.chat.ChatMessageBuilder)1 HiscoreSkill (net.runelite.http.api.hiscore.HiscoreSkill)1 SingleHiscoreSkillResult (net.runelite.http.api.hiscore.SingleHiscoreSkillResult)1 Skill (net.runelite.http.api.hiscore.Skill)1