Search in sources :

Example 1 with ChatMessageBuilder

use of net.runelite.client.chat.ChatMessageBuilder 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 ChatMessageBuilder

use of net.runelite.client.chat.ChatMessageBuilder in project runelite by runelite.

the class ExaminePlugin method getItemPrice.

private void getItemPrice(ItemComposition itemComposition, int quantity) {
    // convert to unnoted id
    final boolean note = itemComposition.getNote() != -1;
    final int id = note ? itemComposition.getLinkedNoteId() : itemComposition.getId();
    ItemPrice itemPrice;
    try {
        itemPrice = itemManager.getItemPrice(id);
    } catch (IOException e) {
        log.warn("Error looking up item price", e);
        return;
    }
    int itemCompositionPrice = itemComposition.getPrice();
    final int gePrice = itemPrice == null ? 0 : itemPrice.getPrice();
    final int alchPrice = itemCompositionPrice <= 0 ? 0 : Math.round(itemCompositionPrice * HIGH_ALCHEMY_CONSTANT);
    if (gePrice > 0 || alchPrice > 0) {
        final ChatMessageBuilder message = new ChatMessageBuilder().append(ChatColorType.NORMAL).append("Price of ").append(ChatColorType.HIGHLIGHT);
        if (quantity > 1) {
            message.append(StackFormatter.formatNumber(quantity)).append(" x ");
        }
        message.append(itemComposition.getName()).append(ChatColorType.NORMAL).append(":");
        if (gePrice > 0) {
            message.append(ChatColorType.NORMAL).append(" GE average ").append(ChatColorType.HIGHLIGHT).append(StackFormatter.formatNumber(gePrice * quantity));
        }
        if (quantity > 1) {
            message.append(ChatColorType.NORMAL).append(" (").append(ChatColorType.HIGHLIGHT).append(StackFormatter.formatNumber(gePrice)).append(ChatColorType.NORMAL).append("ea)");
        }
        if (alchPrice > 0) {
            message.append(ChatColorType.NORMAL).append(" HA value ").append(ChatColorType.HIGHLIGHT).append(StackFormatter.formatNumber(alchPrice * quantity));
        }
        if (quantity > 1) {
            message.append(ChatColorType.NORMAL).append(" (").append(ChatColorType.HIGHLIGHT).append(StackFormatter.formatNumber(alchPrice)).append(ChatColorType.NORMAL).append("ea)");
        }
        chatMessageManager.queue(QueuedMessage.builder().type(ChatMessageType.EXAMINE_ITEM).runeLiteFormattedMessage(message.build()).build());
    }
}
Also used : ItemPrice(net.runelite.http.api.item.ItemPrice) IOException(java.io.IOException) ChatMessageBuilder(net.runelite.client.chat.ChatMessageBuilder)

Example 3 with ChatMessageBuilder

use of net.runelite.client.chat.ChatMessageBuilder in project runelite by runelite.

the class RaidsPlugin method onChatMessage.

@Subscribe
public void onChatMessage(ChatMessage event) {
    if (inRaidChambers && event.getType() == ChatMessageType.CLANCHAT_INFO) {
        String message = Text.removeTags(event.getMessage());
        if (config.raidsTimer() && message.startsWith(RAID_START_MESSAGE)) {
            timer = new RaidsTimer(getRaidsIcon(), this, Instant.now());
            infoBoxManager.addInfoBox(timer);
        }
        if (timer != null && message.contains(LEVEL_COMPLETE_MESSAGE)) {
            timer.timeFloor();
        }
        if (message.startsWith(RAID_COMPLETE_MESSAGE)) {
            if (timer != null) {
                timer.timeFloor();
                timer.setStopped(true);
            }
            if (config.pointsMessage()) {
                int totalPoints = client.getSetting(Varbits.TOTAL_POINTS);
                int personalPoints = client.getSetting(Varbits.PERSONAL_POINTS);
                double percentage = personalPoints / (totalPoints / 100.0);
                String chatMessage = new ChatMessageBuilder().append(ChatColorType.NORMAL).append("Total points: ").append(ChatColorType.HIGHLIGHT).append(POINTS_FORMAT.format(totalPoints)).append(ChatColorType.NORMAL).append(", Personal points: ").append(ChatColorType.HIGHLIGHT).append(POINTS_FORMAT.format(personalPoints)).append(ChatColorType.NORMAL).append(" (").append(ChatColorType.HIGHLIGHT).append(DECIMAL_FORMAT.format(percentage)).append(ChatColorType.NORMAL).append("%)").build();
                chatMessageManager.queue(QueuedMessage.builder().type(ChatMessageType.CLANCHAT_INFO).runeLiteFormattedMessage(chatMessage).build());
            }
        }
    }
}
Also used : Point(net.runelite.api.Point) ChatMessageBuilder(net.runelite.client.chat.ChatMessageBuilder) Subscribe(com.google.common.eventbus.Subscribe)

Example 4 with ChatMessageBuilder

use of net.runelite.client.chat.ChatMessageBuilder in project runelite by runelite.

the class DailyTasksPlugin method sendChatMessage.

private void sendChatMessage(String chatMessage) {
    final String message = new ChatMessageBuilder().append(ChatColorType.HIGHLIGHT).append(chatMessage).build();
    chatMessageManager.queue(QueuedMessage.builder().type(ChatMessageType.GAME).runeLiteFormattedMessage(message).build());
}
Also used : ChatMessageBuilder(net.runelite.client.chat.ChatMessageBuilder)

Example 5 with ChatMessageBuilder

use of net.runelite.client.chat.ChatMessageBuilder in project runelite by runelite.

the class ChatCommandsPlugin method itemPriceLookup.

/**
 * Looks up the item price and changes the original message to the
 * response.
 *
 * @param messageNode The chat message containing the command.
 * @param search The item given with the command.
 */
private void itemPriceLookup(MessageNode messageNode, String search) {
    SearchResult result;
    try {
        result = itemManager.searchForItem(search);
    } catch (ExecutionException ex) {
        log.warn("Unable to search for item {}", search, ex);
        return;
    }
    if (result != null && !result.getItems().isEmpty()) {
        Item item = retrieveFromList(result.getItems(), search);
        if (item == null) {
            log.debug("Unable to find item {} in result {}", search, result);
            return;
        }
        int itemId = item.getId();
        ItemPrice itemPrice;
        try {
            itemPrice = itemManager.getItemPrice(itemId);
        } catch (IOException ex) {
            log.warn("Unable to fetch item price for {}", itemId, ex);
            return;
        }
        final ChatMessageBuilder builder = new ChatMessageBuilder().append(ChatColorType.NORMAL).append("Price of ").append(ChatColorType.HIGHLIGHT).append(item.getName()).append(ChatColorType.NORMAL).append(": GE average ").append(ChatColorType.HIGHLIGHT).append(StackFormatter.formatNumber(itemPrice.getPrice()));
        ItemComposition itemComposition = itemManager.getItemComposition(itemId);
        if (itemComposition != null) {
            int alchPrice = Math.round(itemComposition.getPrice() * HIGH_ALCHEMY_CONSTANT);
            builder.append(ChatColorType.NORMAL).append(" HA value ").append(ChatColorType.HIGHLIGHT).append(StackFormatter.formatNumber(alchPrice));
        }
        String response = builder.build();
        log.debug("Setting response {}", response);
        messageNode.setRuneLiteFormatMessage(response);
        chatMessageManager.update(messageNode);
        client.refreshChat();
    }
}
Also used : Item(net.runelite.http.api.item.Item) ItemPrice(net.runelite.http.api.item.ItemPrice) ItemComposition(net.runelite.api.ItemComposition) SearchResult(net.runelite.http.api.item.SearchResult) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ChatMessageBuilder(net.runelite.client.chat.ChatMessageBuilder)

Aggregations

ChatMessageBuilder (net.runelite.client.chat.ChatMessageBuilder)5 IOException (java.io.IOException)3 ItemPrice (net.runelite.http.api.item.ItemPrice)2 Subscribe (com.google.common.eventbus.Subscribe)1 ExecutionException (java.util.concurrent.ExecutionException)1 ItemComposition (net.runelite.api.ItemComposition)1 MessageNode (net.runelite.api.MessageNode)1 Point (net.runelite.api.Point)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 Item (net.runelite.http.api.item.Item)1 SearchResult (net.runelite.http.api.item.SearchResult)1