Search in sources :

Example 11 with ItemPrice

use of net.runelite.http.api.item.ItemPrice 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)

Example 12 with ItemPrice

use of net.runelite.http.api.item.ItemPrice in project runelite by runelite.

the class GrandExchangeSearchPanel method priceLookup.

private void priceLookup(boolean exactMatch) {
    String lookup = searchBox.getText();
    if (Strings.isNullOrEmpty(lookup)) {
        return;
    }
    // Input is not empty, add searching label
    searchItemsPanel.removeAll();
    showSearchString("Searching...");
    SearchResult result;
    try {
        result = itemManager.searchForItem(lookup);
    } catch (ExecutionException ex) {
        log.warn("Unable to search for item {}", lookup, ex);
        showSearchString("Error performing search");
        return;
    }
    if (result != null && !result.getItems().isEmpty()) {
        itemClient = new ItemClient();
        for (Item item : result.getItems()) {
            int itemId = item.getId();
            ItemComposition itemComp = client.getItemDefinition(itemId);
            if (itemComp == null) {
                continue;
            }
            ItemPrice itemPrice = null;
            try {
                itemPrice = itemManager.getItemPrice(itemId);
            } catch (IOException ex) {
                log.warn("Unable to fetch item price for {}", itemId, ex);
            }
            BufferedImage itemImage = null;
            try {
                itemImage = itemClient.getIcon(itemId);
            } catch (IOException ex) {
                log.warn("Unable to fetch item icon for {}", itemId, ex);
            }
            if (itemImage == null) {
                log.warn("Unable to fetch item icon for {}", itemId);
            }
            ITEMS_LIST.add(new GrandExchangeItems(itemImage, item.getName(), itemId, itemPrice != null ? itemPrice.getPrice() : 0, itemComp.getPrice() * 0.6));
            // If using hotkey to lookup item, stop after finding match.
            if (exactMatch && item.getName().equalsIgnoreCase(lookup)) {
                break;
            }
        }
    }
    SwingUtilities.invokeLater(() -> {
        for (GrandExchangeItems item : ITEMS_LIST) {
            GrandExchangeItemPanel panel = new GrandExchangeItemPanel(item.getIcon(), item.getName(), item.getItemId(), item.getGePrice(), item.getHaPrice());
            searchItemsPanel.add(panel);
        }
        ITEMS_LIST.clear();
        // Remove searching label after search is complete
        showSearchString(null);
    });
}
Also used : Item(net.runelite.http.api.item.Item) ItemClient(net.runelite.http.api.item.ItemClient) 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) BufferedImage(java.awt.image.BufferedImage)

Aggregations

ItemPrice (net.runelite.http.api.item.ItemPrice)12 ItemComposition (net.runelite.api.ItemComposition)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ExecutionException (java.util.concurrent.ExecutionException)3 LocalPoint (net.runelite.api.coords.LocalPoint)2 ChatMessageBuilder (net.runelite.client.chat.ChatMessageBuilder)2 Item (net.runelite.http.api.item.Item)2 SearchResult (net.runelite.http.api.item.SearchResult)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Subscribe (com.google.common.eventbus.Subscribe)1 Color (java.awt.Color)1 BufferedImage (java.awt.image.BufferedImage)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Nullable (javax.annotation.Nullable)1 Item (net.runelite.api.Item)1 ItemLayer (net.runelite.api.ItemLayer)1