grounditems: make priceChecks threadsafe

This commit is contained in:
Max Weber
2020-03-26 11:25:31 -06:00
parent 1f09833022
commit 6b1da824a8

View File

@@ -28,6 +28,7 @@ package net.runelite.client.plugins.grounditems;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.EvictingQueue;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Provides;
import java.awt.Color;
import java.awt.Rectangle;
@@ -163,7 +164,7 @@ public class GroundItemsPlugin extends Plugin
@Getter
private final Map<GroundItem.GroundItemKey, GroundItem> collectedGroundItems = new LinkedHashMap<>();
private final Map<Integer, Color> priceChecks = new LinkedHashMap<>();
private Map<Integer, Color> priceChecks = ImmutableMap.of();
private LoadingCache<NamedQuantity, Boolean> highlightedItems;
private LoadingCache<NamedQuantity, Boolean> hiddenItems;
private final Queue<Integer> droppedItemQueue = EvictingQueue.create(16); // recently dropped items
@@ -429,32 +430,33 @@ public class GroundItemsPlugin extends Plugin
.build(new WildcardMatchLoader(hiddenItemList));
// Cache colors
priceChecks.clear();
ImmutableMap.Builder<Integer, Color> priceCheckBuilder = ImmutableMap.builder();
if (config.getHighlightOverValue() > 0)
{
priceChecks.put(config.getHighlightOverValue(), config.highlightedColor());
priceCheckBuilder.put(config.getHighlightOverValue(), config.highlightedColor());
}
if (config.insaneValuePrice() > 0)
{
priceChecks.put(config.insaneValuePrice(), config.insaneValueColor());
priceCheckBuilder.put(config.insaneValuePrice(), config.insaneValueColor());
}
if (config.highValuePrice() > 0)
{
priceChecks.put(config.highValuePrice(), config.highValueColor());
priceCheckBuilder.put(config.highValuePrice(), config.highValueColor());
}
if (config.mediumValuePrice() > 0)
{
priceChecks.put(config.mediumValuePrice(), config.mediumValueColor());
priceCheckBuilder.put(config.mediumValuePrice(), config.mediumValueColor());
}
if (config.lowValuePrice() > 0)
{
priceChecks.put(config.lowValuePrice(), config.lowValueColor());
priceCheckBuilder.put(config.lowValuePrice(), config.lowValueColor());
}
priceChecks = priceCheckBuilder.build();
}
@Subscribe