ge plugin: use wiki prices for actively traded price

This commit is contained in:
Adam
2021-03-09 14:26:38 -05:00
parent d5dda05d55
commit 5fc1f0260d
2 changed files with 14 additions and 63 deletions

View File

@@ -57,13 +57,13 @@ public interface GrandExchangeConfig extends Config
@ConfigItem(
position = 3,
keyName = "enableOsbPrices",
name = "Enable OSB actively traded prices",
description = "Shows the OSBuddy actively traded price on the GE buy interface"
keyName = "showActivelyTradedPrice",
name = "Enable actively traded prices",
description = "Shows the actively traded price on the GE buy interface, sourced from the RuneScape wiki"
)
default boolean enableOsbPrices()
default boolean showActivelyTradedPrice()
{
return false;
return true;
}
@ConfigItem(

View File

@@ -36,7 +36,6 @@ import com.google.gson.Gson;
import com.google.inject.Provides;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.time.Duration;
@@ -48,7 +47,6 @@ import java.util.EnumSet;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.ToIntFunction;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@@ -105,7 +103,6 @@ import net.runelite.http.api.ge.GrandExchangeClient;
import net.runelite.http.api.ge.GrandExchangeTrade;
import net.runelite.http.api.item.ItemStats;
import net.runelite.http.api.osbuddy.OSBGrandExchangeClient;
import net.runelite.http.api.osbuddy.OSBGrandExchangeResult;
import net.runelite.http.api.worlds.WorldType;
import okhttp3.OkHttpClient;
import org.apache.commons.lang3.time.DurationFormatUtils;
@@ -124,7 +121,6 @@ public class GrandExchangePlugin extends Plugin
private static final int GE_LOGIN_BURST_WINDOW = 2; // ticks
private static final int OFFER_CONTAINER_ITEM = 21;
private static final int OFFER_DEFAULT_ITEM_ID = 6512;
private static final String OSB_GE_TEXT = "<br>OSBuddy Actively traded price: ";
private static final String BUY_LIMIT_GE_TEXT = "<br>Buy limit: ";
private static final String BUY_LIMIT_KEY = "buylimit";
@@ -173,9 +169,6 @@ public class GrandExchangePlugin extends Plugin
@Inject
private Notifier notifier;
@Inject
private ScheduledExecutorService executorService;
@Inject
private SessionManager sessionManager;
@@ -189,16 +182,10 @@ public class GrandExchangePlugin extends Plugin
private Widget grandExchangeItem;
private String grandExchangeExamine;
private int osbItem;
private OSBGrandExchangeResult osbGrandExchangeResult;
@Inject
private GrandExchangeClient grandExchangeClient;
private int lastLoginTick;
@Inject
private OSBGrandExchangeClient osbGrandExchangeClient;
private boolean wasFuzzySearch;
private String machineUuid;
@@ -318,9 +305,6 @@ public class GrandExchangePlugin extends Plugin
grandExchangeClient.setUuid(null);
}
osbItem = -1;
osbGrandExchangeResult = null;
lastLoginTick = -1;
}
@@ -880,50 +864,17 @@ public class GrandExchangePlugin extends Plugin
}
}
if (config.showActivelyTradedPrice())
{
final int price = itemManager.getItemPriceWithSource(itemId, true);
if (price > 0)
{
text += "<br>Actively traded price: " + QuantityFormatter.formatNumber(price);
}
}
grandExchangeExamine = text;
geText.setText(text);
if (!config.enableOsbPrices())
{
return;
}
// If we already have the result, use it
if (osbGrandExchangeResult != null && osbGrandExchangeResult.getItem_id() == itemId && osbGrandExchangeResult.getOverall_average() > 0)
{
grandExchangeExamine = text + OSB_GE_TEXT + QuantityFormatter.formatNumber(osbGrandExchangeResult.getOverall_average());
geText.setText(grandExchangeExamine);
}
if (osbItem == itemId)
{
// avoid starting duplicate lookups
return;
}
osbItem = itemId;
log.debug("Looking up OSB item price {}", itemId);
final String start = text;
executorService.submit(() ->
{
try
{
final OSBGrandExchangeResult result = osbGrandExchangeClient.lookupItem(itemId);
if (result != null && result.getOverall_average() > 0)
{
osbGrandExchangeResult = result;
// Update the text on the widget too
grandExchangeExamine = start + OSB_GE_TEXT + QuantityFormatter.formatNumber(result.getOverall_average());
geText.setText(grandExchangeExamine);
}
}
catch (IOException e)
{
log.debug("Error getting price of item {}", itemId, e);
}
});
}
static void openGeLink(String name, int itemId)