itemmanager: sanity check wiki prices

Try to avoid excessive item price manipulation by requiring the guide price to be within a configured threshold of the official price.
This commit is contained in:
Adam
2022-02-01 16:55:21 -05:00
parent b37d46e488
commit aaf4adaea0
4 changed files with 40 additions and 5 deletions

View File

@@ -67,7 +67,12 @@
<!-- design -->
<rule ref="category/java/design.xml/AvoidThrowingNewInstanceOfSameException"/>
<rule ref="category/java/design.xml/FinalFieldCouldBeStatic"/>
<rule ref="category/java/design.xml/ImmutableField"/>
<rule ref="category/java/design.xml/ImmutableField">
<properties>
<property name="ignoredAnnotations"
value="lombok.Setter|lombok.Getter|lombok.Builder|lombok.Data|lombok.RequiredArgsConstructor|lombok.AllArgsConstructor|lombok.Value|lombok.NoArgsConstructor|javax.inject.Inject|com.google.inject.Inject"/>
</properties>
</rule>
<rule ref="category/java/design.xml/SimplifyBooleanExpressions"/>
<rule ref="category/java/design.xml/SimplifyConditional"/>
<rule ref="category/java/design.xml/UselessOverridingMethod"/>

View File

@@ -28,6 +28,7 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.IOException;
@@ -41,7 +42,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
@@ -84,6 +85,14 @@ public class ItemManager
private final ItemClient itemClient;
private final RuneLiteConfig runeLiteConfig;
@Inject(optional = true)
@Named("activePriceThreshold")
private double activePriceThreshold = 5;
@Inject(optional = true)
@Named("lowPriceThreshold")
private int lowPriceThreshold = 1000;
private Map<Integer, ItemPrice> itemPrices = Collections.emptyMap();
private Map<Integer, ItemStats> itemStats = Collections.emptyMap();
private final LoadingCache<ImageKey, AsyncBufferedImage> itemImages;
@@ -288,7 +297,7 @@ public class ItemManager
if (ip != null)
{
price = useWikiPrice && ip.getWikiPrice() > 0 ? ip.getWikiPrice() : ip.getPrice();
price = useWikiPrice ? getWikiPrice(ip) : ip.getPrice();
}
}
else
@@ -302,6 +311,27 @@ public class ItemManager
return price;
}
/**
* Get the wiki price for an item, with checks to try and avoid excessive price manipulation
* @param itemPrice
* @return
*/
public int getWikiPrice(ItemPrice itemPrice)
{
final int wikiPrice = itemPrice.getWikiPrice();
final int jagPrice = itemPrice.getPrice();
if (wikiPrice <= 0)
{
return jagPrice;
}
if (wikiPrice <= lowPriceThreshold)
{
return wikiPrice;
}
int d = jagPrice - (int) (jagPrice * activePriceThreshold);
return wikiPrice >= jagPrice - d && wikiPrice <= jagPrice + d ? wikiPrice : jagPrice;
}
/**
* Look up an item's stats
* @param itemId item id

View File

@@ -1287,7 +1287,7 @@ public class ChatCommandsPlugin extends Plugin
ItemPrice item = retrieveFromList(results, search);
int itemId = item.getId();
int itemPrice = runeLiteConfig.useWikiItemPrices() && item.getWikiPrice() > 0 ? item.getWikiPrice() : item.getPrice();
int itemPrice = runeLiteConfig.useWikiItemPrices() ? itemManager.getWikiPrice(item) : item.getPrice();
final ChatMessageBuilder builder = new ChatMessageBuilder()
.append(ChatColorType.NORMAL)

View File

@@ -215,7 +215,7 @@ class GrandExchangeSearchPanel extends JPanel
ItemComposition itemComp = itemManager.getItemComposition(itemId);
ItemStats itemStats = itemManager.getItemStats(itemId, false);
int itemPrice = useActivelyTradedPrice && item.getWikiPrice() > 0 ? item.getWikiPrice() : item.getPrice();
int itemPrice = useActivelyTradedPrice ? itemManager.getWikiPrice(item) : item.getPrice();
int itemLimit = itemStats != null ? itemStats.getGeLimit() : 0;
final int haPrice = itemComp.getHaPrice();
AsyncBufferedImage itemImage = itemManager.getImage(itemId);