runelite-client: use new bulk item price api
This commit is contained in:
@@ -169,4 +169,35 @@ public class ItemClient
|
|||||||
throw new IOException(ex);
|
throw new IOException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ItemPrice[] getPrices() throws IOException
|
||||||
|
{
|
||||||
|
HttpUrl.Builder urlBuilder = RuneLiteAPI.getApiBase().newBuilder()
|
||||||
|
.addPathSegment("item")
|
||||||
|
.addPathSegment("prices");
|
||||||
|
|
||||||
|
HttpUrl url = urlBuilder.build();
|
||||||
|
|
||||||
|
logger.debug("Built URI: {}", url);
|
||||||
|
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
|
||||||
|
{
|
||||||
|
if (!response.isSuccessful())
|
||||||
|
{
|
||||||
|
logger.warn("Error looking up prices: {}", response.message());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
InputStream in = response.body().byteStream();
|
||||||
|
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), ItemPrice[].class);
|
||||||
|
}
|
||||||
|
catch (JsonParseException ex)
|
||||||
|
{
|
||||||
|
throw new IOException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,11 +30,8 @@ import com.google.common.cache.LoadingCache;
|
|||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.Arrays;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -65,23 +62,13 @@ public class ItemManager
|
|||||||
private final boolean stackable;
|
private final boolean stackable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* not yet looked up
|
|
||||||
*/
|
|
||||||
static final ItemPrice EMPTY = new ItemPrice();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* has no price
|
|
||||||
*/
|
|
||||||
static final ItemPrice NONE = new ItemPrice();
|
|
||||||
|
|
||||||
private final Client client;
|
private final Client client;
|
||||||
private final ScheduledExecutorService scheduledExecutorService;
|
private final ScheduledExecutorService scheduledExecutorService;
|
||||||
private final ClientThread clientThread;
|
private final ClientThread clientThread;
|
||||||
|
|
||||||
private final ItemClient itemClient = new ItemClient();
|
private final ItemClient itemClient = new ItemClient();
|
||||||
private final LoadingCache<String, SearchResult> itemSearches;
|
private final LoadingCache<String, SearchResult> itemSearches;
|
||||||
private final LoadingCache<Integer, ItemPrice> itemPriceCache;
|
private final ConcurrentMap<Integer, ItemPrice> itemPrices = new ConcurrentHashMap<>();
|
||||||
private final LoadingCache<ImageKey, AsyncBufferedImage> itemImages;
|
private final LoadingCache<ImageKey, AsyncBufferedImage> itemImages;
|
||||||
private final LoadingCache<Integer, ItemComposition> itemCompositions;
|
private final LoadingCache<Integer, ItemComposition> itemCompositions;
|
||||||
|
|
||||||
@@ -92,10 +79,7 @@ public class ItemManager
|
|||||||
this.scheduledExecutorService = executor;
|
this.scheduledExecutorService = executor;
|
||||||
this.clientThread = clientThread;
|
this.clientThread = clientThread;
|
||||||
|
|
||||||
itemPriceCache = CacheBuilder.newBuilder()
|
scheduledExecutorService.scheduleWithFixedDelay(this::loadPrices, 0, 30, TimeUnit.MINUTES);
|
||||||
.maximumSize(1024L)
|
|
||||||
.expireAfterAccess(1, TimeUnit.HOURS)
|
|
||||||
.build(new ItemPriceLoader(executor, itemClient));
|
|
||||||
|
|
||||||
itemSearches = CacheBuilder.newBuilder()
|
itemSearches = CacheBuilder.newBuilder()
|
||||||
.maximumSize(512L)
|
.maximumSize(512L)
|
||||||
@@ -134,6 +118,28 @@ public class ItemManager
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadPrices()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ItemPrice[] prices = itemClient.getPrices();
|
||||||
|
if (prices != null)
|
||||||
|
{
|
||||||
|
itemPrices.clear();
|
||||||
|
for (ItemPrice price : prices)
|
||||||
|
{
|
||||||
|
itemPrices.put(price.getItem().getId(), price);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("Loaded {} prices", itemPrices.size());
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
log.warn("error loading prices!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGameStateChanged(final GameStateChanged event)
|
public void onGameStateChanged(final GameStateChanged event)
|
||||||
{
|
{
|
||||||
@@ -144,137 +150,15 @@ public class ItemManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look up an item's price asynchronously.
|
* Look up an item's price
|
||||||
*
|
|
||||||
* @param itemId item id
|
|
||||||
* @return the price, or null if the price is not yet loaded
|
|
||||||
*/
|
|
||||||
public ItemPrice getItemPriceAsync(int itemId)
|
|
||||||
{
|
|
||||||
itemId = ItemMapping.mapFirst(itemId);
|
|
||||||
|
|
||||||
ItemPrice itemPrice = itemPriceCache.getIfPresent(itemId);
|
|
||||||
if (itemPrice != null && itemPrice != EMPTY)
|
|
||||||
{
|
|
||||||
return itemPrice == NONE ? null : itemPrice;
|
|
||||||
}
|
|
||||||
|
|
||||||
itemPriceCache.refresh(itemId);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Look up an item's price from the price cache
|
|
||||||
*
|
|
||||||
* @param itemId
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public ItemPrice getCachedItemPrice(int itemId)
|
|
||||||
{
|
|
||||||
itemId = ItemMapping.mapFirst(itemId);
|
|
||||||
|
|
||||||
ItemPrice itemPrice = itemPriceCache.getIfPresent(itemId);
|
|
||||||
if (itemPrice != null && itemPrice != EMPTY && itemPrice != NONE)
|
|
||||||
{
|
|
||||||
return itemPrice;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Look up bulk item prices asynchronously
|
|
||||||
*
|
|
||||||
* @param itemIds array of item Ids
|
|
||||||
* @return a future called with the looked up prices
|
|
||||||
*/
|
|
||||||
public CompletableFuture<ItemPrice[]> getItemPriceBatch(Collection<Integer> itemIds)
|
|
||||||
{
|
|
||||||
final List<Integer> lookup = new ArrayList<>();
|
|
||||||
final List<ItemPrice> existing = new ArrayList<>();
|
|
||||||
for (int itemId : itemIds)
|
|
||||||
{
|
|
||||||
for (int mappedItemId : ItemMapping.map(itemId))
|
|
||||||
{
|
|
||||||
ItemPrice itemPrice = itemPriceCache.getIfPresent(mappedItemId);
|
|
||||||
if (itemPrice != null)
|
|
||||||
{
|
|
||||||
existing.add(itemPrice);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lookup.add(mappedItemId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// All cached?
|
|
||||||
if (lookup.isEmpty())
|
|
||||||
{
|
|
||||||
return CompletableFuture.completedFuture(existing.toArray(new ItemPrice[existing.size()]));
|
|
||||||
}
|
|
||||||
|
|
||||||
final CompletableFuture<ItemPrice[]> future = new CompletableFuture<>();
|
|
||||||
scheduledExecutorService.execute(() ->
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Do a query for the items not in the cache
|
|
||||||
ItemPrice[] itemPrices = itemClient.lookupItemPrice(lookup.toArray(new Integer[lookup.size()]));
|
|
||||||
for (int itemId : lookup)
|
|
||||||
{
|
|
||||||
itemPriceCache.put(itemId, NONE);
|
|
||||||
}
|
|
||||||
if (itemPrices != null)
|
|
||||||
{
|
|
||||||
for (ItemPrice itemPrice : itemPrices)
|
|
||||||
{
|
|
||||||
itemPriceCache.put(itemPrice.getItem().getId(), itemPrice);
|
|
||||||
}
|
|
||||||
// Append these to the already cached items
|
|
||||||
existing.addAll(Arrays.asList(itemPrices));
|
|
||||||
}
|
|
||||||
future.complete(existing.toArray(new ItemPrice[existing.size()]));
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
// cache unable to lookup
|
|
||||||
for (int itemId : lookup)
|
|
||||||
{
|
|
||||||
itemPriceCache.put(itemId, NONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
future.completeExceptionally(ex);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return future;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Look up an item's price synchronously
|
|
||||||
*
|
*
|
||||||
* @param itemId item id
|
* @param itemId item id
|
||||||
* @return item price
|
* @return item price
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
public ItemPrice getItemPrice(int itemId) throws IOException
|
public ItemPrice getItemPrice(int itemId)
|
||||||
{
|
{
|
||||||
itemId = ItemMapping.mapFirst(itemId);
|
itemId = ItemMapping.mapFirst(itemId);
|
||||||
|
return itemPrices.get(itemId);
|
||||||
ItemPrice itemPrice = itemPriceCache.getIfPresent(itemId);
|
|
||||||
if (itemPrice != null && itemPrice != EMPTY)
|
|
||||||
{
|
|
||||||
return itemPrice == NONE ? null : itemPrice;
|
|
||||||
}
|
|
||||||
|
|
||||||
itemPrice = itemClient.lookupItemPrice(itemId);
|
|
||||||
if (itemPrice == null)
|
|
||||||
{
|
|
||||||
itemPriceCache.put(itemId, NONE);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
itemPriceCache.put(itemId, itemPrice);
|
|
||||||
return itemPrice;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
||||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
package net.runelite.client.game;
|
|
||||||
|
|
||||||
import com.google.common.cache.CacheLoader;
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
|
||||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
|
||||||
import com.google.common.util.concurrent.MoreExecutors;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import static net.runelite.client.game.ItemManager.EMPTY;
|
|
||||||
import static net.runelite.client.game.ItemManager.NONE;
|
|
||||||
import net.runelite.http.api.item.ItemClient;
|
|
||||||
import net.runelite.http.api.item.ItemPrice;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
class ItemPriceLoader extends CacheLoader<Integer, ItemPrice>
|
|
||||||
{
|
|
||||||
private final ListeningExecutorService executorService;
|
|
||||||
private final ItemClient client;
|
|
||||||
|
|
||||||
ItemPriceLoader(ScheduledExecutorService executor, ItemClient client)
|
|
||||||
{
|
|
||||||
this.executorService = MoreExecutors.listeningDecorator(executor);
|
|
||||||
this.client = client;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemPrice load(Integer key) throws Exception
|
|
||||||
{
|
|
||||||
// guava's Cache doesn't support null values
|
|
||||||
return EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ListenableFuture<ItemPrice> reload(Integer key, ItemPrice oldValue)
|
|
||||||
{
|
|
||||||
log.debug("Submitting lookup for item {}", key);
|
|
||||||
|
|
||||||
return executorService.submit(() -> fetch(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemPrice fetch(Integer key)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ItemPrice itemPrice = client.lookupItemPrice(key);
|
|
||||||
if (itemPrice == null)
|
|
||||||
{
|
|
||||||
return NONE;
|
|
||||||
}
|
|
||||||
return itemPrice;
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
log.warn("unable to look up item!", ex);
|
|
||||||
return NONE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -28,7 +28,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -61,9 +60,6 @@ class BankCalculation
|
|||||||
@Getter
|
@Getter
|
||||||
private long haPrice;
|
private long haPrice;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private boolean finished;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BankCalculation(QueryRunner queryRunner, ItemManager itemManager, BankValueConfig config)
|
BankCalculation(QueryRunner queryRunner, ItemManager itemManager, BankValueConfig config)
|
||||||
{
|
{
|
||||||
@@ -87,7 +83,6 @@ class BankCalculation
|
|||||||
log.debug("Calculating new bank value...");
|
log.debug("Calculating new bank value...");
|
||||||
|
|
||||||
gePrice = haPrice = 0;
|
gePrice = haPrice = 0;
|
||||||
finished = false;
|
|
||||||
|
|
||||||
List<Integer> itemIds = new ArrayList<>();
|
List<Integer> itemIds = new ArrayList<>();
|
||||||
|
|
||||||
@@ -137,65 +132,32 @@ class BankCalculation
|
|||||||
// Now do the calculations
|
// Now do the calculations
|
||||||
if (config.showGE() && !itemIds.isEmpty())
|
if (config.showGE() && !itemIds.isEmpty())
|
||||||
{
|
{
|
||||||
CompletableFuture<ItemPrice[]> future = itemManager.getItemPriceBatch(itemIds);
|
for (WidgetItem widgetItem : widgetItems)
|
||||||
future.whenComplete((ItemPrice[] itemPrices, Throwable ex) ->
|
|
||||||
{
|
{
|
||||||
if (ex != null)
|
int itemId = widgetItem.getId();
|
||||||
|
int quantity = widgetItem.getQuantity();
|
||||||
|
|
||||||
|
if (itemId <= 0 || quantity == 0
|
||||||
|
|| itemId == ItemID.COINS_995 || itemId == ItemID.PLATINUM_TOKEN)
|
||||||
{
|
{
|
||||||
log.debug("Error looking up item prices", ex);
|
continue;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemPrices == null)
|
long price = 0;
|
||||||
|
for (int mappedItemId : ItemMapping.map(itemId))
|
||||||
{
|
{
|
||||||
log.debug("Error looking up item prices");
|
ItemPrice cachedItemPrice = itemManager.getItemPrice(mappedItemId);
|
||||||
return;
|
if (cachedItemPrice == null)
|
||||||
}
|
|
||||||
|
|
||||||
log.debug("Price lookup is complete. {} prices.", itemPrices.length);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
for (WidgetItem widgetItem : widgetItems)
|
|
||||||
{
|
{
|
||||||
int itemId = widgetItem.getId();
|
// this happens to items which have no ge price
|
||||||
int quantity = widgetItem.getQuantity();
|
continue;
|
||||||
|
|
||||||
if (itemId <= 0 || quantity == 0
|
|
||||||
|| itemId == ItemID.COINS_995 || itemId == ItemID.PLATINUM_TOKEN)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
long price = 0;
|
|
||||||
for (int mappedItemId : ItemMapping.map(itemId))
|
|
||||||
{
|
|
||||||
ItemPrice cachedItemPrice = itemManager.getCachedItemPrice(mappedItemId);
|
|
||||||
if (cachedItemPrice == null)
|
|
||||||
{
|
|
||||||
// this happens to items which have no ge price
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
price += cachedItemPrice.getPrice();
|
|
||||||
}
|
|
||||||
|
|
||||||
gePrice += price * quantity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
price += cachedItemPrice.getPrice();
|
||||||
}
|
}
|
||||||
catch (Exception ex2)
|
|
||||||
{
|
gePrice += price * quantity;
|
||||||
log.warn("error calculating price", ex2);
|
}
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
finished = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
finished = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,10 +72,7 @@ public class BankValuePlugin extends Plugin
|
|||||||
|
|
||||||
bankTitle.save();
|
bankTitle.save();
|
||||||
calculate(widgetBankTitleBar);
|
calculate(widgetBankTitleBar);
|
||||||
if (bankCalculation.isFinished())
|
bankTitle.update(bankCalculation.getGePrice(), bankCalculation.getHaPrice());
|
||||||
{
|
|
||||||
bankTitle.update(bankCalculation.getGePrice(), bankCalculation.getHaPrice());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calculate(Widget bankTitleBar)
|
private void calculate(Widget bankTitleBar)
|
||||||
|
|||||||
@@ -27,11 +27,8 @@ package net.runelite.client.plugins.barrows;
|
|||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -113,8 +110,6 @@ public class BarrowsPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private BarrowsConfig config;
|
private BarrowsConfig config;
|
||||||
|
|
||||||
private long chestPrice;
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
BarrowsConfig provideConfig(ConfigManager configManager)
|
BarrowsConfig provideConfig(ConfigManager configManager)
|
||||||
{
|
{
|
||||||
@@ -215,7 +210,7 @@ public class BarrowsPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
ItemContainer barrowsRewardContainer = client.getItemContainer(InventoryID.BARROWS_REWARD);
|
ItemContainer barrowsRewardContainer = client.getItemContainer(InventoryID.BARROWS_REWARD);
|
||||||
Item[] items = barrowsRewardContainer.getItems();
|
Item[] items = barrowsRewardContainer.getItems();
|
||||||
chestPrice = 0;
|
long chestPrice = 0;
|
||||||
|
|
||||||
for (Item item : items)
|
for (Item item : items)
|
||||||
{
|
{
|
||||||
@@ -225,55 +220,29 @@ public class BarrowsPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CompletableFuture<ItemPrice[]> future = itemManager.getItemPriceBatch(
|
for (Item item : items)
|
||||||
Arrays.stream(items).map(Item::getId).collect(Collectors.toList()));
|
|
||||||
future.whenComplete((ItemPrice[] itemPrices, Throwable ex) ->
|
|
||||||
{
|
{
|
||||||
if (ex != null)
|
ItemPrice cachedItemPrice = itemManager.getItemPrice(item.getId());
|
||||||
|
if (cachedItemPrice == null)
|
||||||
{
|
{
|
||||||
log.debug("Error looking up item prices", ex);
|
continue;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemPrices == null)
|
long itemStack = (long) cachedItemPrice.getPrice() * (long) item.getQuantity();
|
||||||
{
|
chestPrice += itemStack;
|
||||||
log.debug("Error looking up item prices");
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
log.debug("Price lookup is complete. {} prices.", itemPrices.length);
|
final ChatMessageBuilder message = new ChatMessageBuilder()
|
||||||
|
.append(ChatColorType.HIGHLIGHT)
|
||||||
|
.append("Your chest is worth around ")
|
||||||
|
.append(StackFormatter.formatNumber(chestPrice))
|
||||||
|
.append(" coins.")
|
||||||
|
.append(ChatColorType.NORMAL);
|
||||||
|
|
||||||
try
|
chatMessageManager.queue(QueuedMessage.builder()
|
||||||
{
|
.type(ChatMessageType.EXAMINE_ITEM)
|
||||||
for (Item item : items)
|
.runeLiteFormattedMessage(message.build())
|
||||||
{
|
.build());
|
||||||
ItemPrice cachedItemPrice = itemManager.getCachedItemPrice(item.getId());
|
|
||||||
if (cachedItemPrice == null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
long itemStack = (long) cachedItemPrice.getPrice() * (long) item.getQuantity();
|
|
||||||
chestPrice += itemStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
final ChatMessageBuilder message = new ChatMessageBuilder()
|
|
||||||
.append(ChatColorType.HIGHLIGHT)
|
|
||||||
.append("Your chest is worth around ")
|
|
||||||
.append(StackFormatter.formatNumber(chestPrice))
|
|
||||||
.append(" coins.")
|
|
||||||
.append(ChatColorType.NORMAL);
|
|
||||||
|
|
||||||
chatMessageManager.queue(QueuedMessage.builder()
|
|
||||||
.type(ChatMessageType.EXAMINE_ITEM)
|
|
||||||
.runeLiteFormattedMessage(message.build())
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
catch (Exception ex2)
|
|
||||||
{
|
|
||||||
log.warn("error calculating price", ex2);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,17 +189,7 @@ public class ChatCommandsPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
int itemId = item.getId();
|
int itemId = item.getId();
|
||||||
ItemPrice itemPrice;
|
ItemPrice itemPrice = itemManager.getItemPrice(itemId);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
itemPrice = itemManager.getItemPrice(itemId);
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
log.warn("Unable to fetch item price for {}", itemId, ex);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final ChatMessageBuilder builder = new ChatMessageBuilder()
|
final ChatMessageBuilder builder = new ChatMessageBuilder()
|
||||||
.append(ChatColorType.NORMAL)
|
.append(ChatColorType.NORMAL)
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ package net.runelite.client.plugins.examine;
|
|||||||
import com.google.common.cache.Cache;
|
import com.google.common.cache.Cache;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
@@ -271,14 +270,9 @@ public class ExaminePlugin extends Plugin
|
|||||||
final boolean note = itemComposition.getNote() != -1;
|
final boolean note = itemComposition.getNote() != -1;
|
||||||
final int id = note ? itemComposition.getLinkedNoteId() : itemComposition.getId();
|
final int id = note ? itemComposition.getLinkedNoteId() : itemComposition.getId();
|
||||||
|
|
||||||
ItemPrice itemPrice;
|
ItemPrice itemPrice = itemManager.getItemPrice(id);
|
||||||
try
|
if (itemPrice == null)
|
||||||
{
|
{
|
||||||
itemPrice = itemManager.getItemPrice(id);
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
log.warn("Error looking up item price", e);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -225,16 +225,7 @@ class GrandExchangeSearchPanel extends JPanel
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemPrice itemPrice = null;
|
ItemPrice itemPrice = itemManager.getItemPrice(itemId);
|
||||||
try
|
|
||||||
{
|
|
||||||
itemPrice = itemManager.getItemPrice(itemId);
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
log.warn("Unable to fetch item price for {}", itemId, ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
AsyncBufferedImage itemImage = itemManager.getImage(itemId);
|
AsyncBufferedImage itemImage = itemManager.getImage(itemId);
|
||||||
|
|
||||||
itemsList.add(new GrandExchangeItems(itemImage, item.getName(), itemId, itemPrice != null ? itemPrice.getPrice() : 0, itemComp.getPrice() * 0.6));
|
itemsList.add(new GrandExchangeItems(itemImage, item.getName(), itemId, itemPrice != null ? itemPrice.getPrice() : 0, itemComp.getPrice() * 0.6));
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ public class GroundItemsOverlay extends Overlay
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update GE price for item
|
// Update GE price for item
|
||||||
final ItemPrice itemPrice = itemManager.getItemPriceAsync(item.getItemId());
|
final ItemPrice itemPrice = itemManager.getItemPrice(item.getItemId());
|
||||||
|
|
||||||
if (itemPrice != null && itemPrice.getPrice() > 0)
|
if (itemPrice != null && itemPrice.getPrice() > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -403,7 +403,7 @@ public class GroundItemsPlugin extends Plugin
|
|||||||
|
|
||||||
final ItemComposition itemComposition = itemManager.getItemComposition(itemId);
|
final ItemComposition itemComposition = itemManager.getItemComposition(itemId);
|
||||||
final int realItemId = itemComposition.getNote() != -1 ? itemComposition.getLinkedNoteId() : itemComposition.getId();
|
final int realItemId = itemComposition.getNote() != -1 ? itemComposition.getLinkedNoteId() : itemComposition.getId();
|
||||||
final ItemPrice itemPrice = itemManager.getItemPriceAsync(realItemId);
|
final ItemPrice itemPrice = itemManager.getItemPrice(realItemId);
|
||||||
final int price = itemPrice == null ? itemComposition.getPrice() : itemPrice.getPrice();
|
final int price = itemPrice == null ? itemComposition.getPrice() : itemPrice.getPrice();
|
||||||
final int haPrice = Math.round(itemComposition.getPrice() * HIGH_ALCHEMY_CONSTANT) * quantity;
|
final int haPrice = Math.round(itemComposition.getPrice() * HIGH_ALCHEMY_CONSTANT) * quantity;
|
||||||
final int gePrice = quantity * price;
|
final int gePrice = quantity * price;
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ class ItemPricesOverlay extends Overlay
|
|||||||
|
|
||||||
if (config.showGEPrice())
|
if (config.showGEPrice())
|
||||||
{
|
{
|
||||||
final ItemPrice price = itemManager.getItemPriceAsync(id);
|
final ItemPrice price = itemManager.getItemPrice(id);
|
||||||
if (price != null)
|
if (price != null)
|
||||||
{
|
{
|
||||||
gePrice = price.getPrice();
|
gePrice = price.getPrice();
|
||||||
|
|||||||
Reference in New Issue
Block a user