grounditems: don't crash when having a duplicate highlight value
This commit is contained in:
@@ -28,7 +28,7 @@ package net.runelite.client.plugins.grounditems;
|
|||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.google.common.collect.EvictingQueue;
|
import com.google.common.collect.EvictingQueue;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
@@ -48,6 +48,7 @@ import javax.inject.Inject;
|
|||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import lombok.Value;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.Constants;
|
import net.runelite.api.Constants;
|
||||||
import net.runelite.api.GameState;
|
import net.runelite.api.GameState;
|
||||||
@@ -100,6 +101,13 @@ import net.runelite.client.util.Text;
|
|||||||
)
|
)
|
||||||
public class GroundItemsPlugin extends Plugin
|
public class GroundItemsPlugin extends Plugin
|
||||||
{
|
{
|
||||||
|
@Value
|
||||||
|
static class PriceHighlight
|
||||||
|
{
|
||||||
|
private final int price;
|
||||||
|
private final Color color;
|
||||||
|
}
|
||||||
|
|
||||||
// ItemID for coins
|
// ItemID for coins
|
||||||
private static final int COINS = ItemID.COINS_995;
|
private static final int COINS = ItemID.COINS_995;
|
||||||
// Ground item menu options
|
// Ground item menu options
|
||||||
@@ -168,7 +176,7 @@ public class GroundItemsPlugin extends Plugin
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final Map<GroundItem.GroundItemKey, GroundItem> collectedGroundItems = new LinkedHashMap<>();
|
private final Map<GroundItem.GroundItemKey, GroundItem> collectedGroundItems = new LinkedHashMap<>();
|
||||||
private Map<Integer, Color> priceChecks = ImmutableMap.of();
|
private List<PriceHighlight> priceChecks = ImmutableList.of();
|
||||||
private LoadingCache<NamedQuantity, Boolean> highlightedItems;
|
private LoadingCache<NamedQuantity, Boolean> highlightedItems;
|
||||||
private LoadingCache<NamedQuantity, Boolean> hiddenItems;
|
private LoadingCache<NamedQuantity, Boolean> hiddenItems;
|
||||||
private final Queue<Integer> droppedItemQueue = EvictingQueue.create(16); // recently dropped items
|
private final Queue<Integer> droppedItemQueue = EvictingQueue.create(16); // recently dropped items
|
||||||
@@ -434,30 +442,30 @@ public class GroundItemsPlugin extends Plugin
|
|||||||
.build(new WildcardMatchLoader(hiddenItemList));
|
.build(new WildcardMatchLoader(hiddenItemList));
|
||||||
|
|
||||||
// Cache colors
|
// Cache colors
|
||||||
ImmutableMap.Builder<Integer, Color> priceCheckBuilder = ImmutableMap.builder();
|
ImmutableList.Builder<PriceHighlight> priceCheckBuilder = ImmutableList.builder();
|
||||||
if (config.getHighlightOverValue() > 0)
|
if (config.getHighlightOverValue() > 0)
|
||||||
{
|
{
|
||||||
priceCheckBuilder.put(config.getHighlightOverValue(), config.highlightedColor());
|
priceCheckBuilder.add(new PriceHighlight(config.getHighlightOverValue(), config.highlightedColor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.insaneValuePrice() > 0)
|
if (config.insaneValuePrice() > 0)
|
||||||
{
|
{
|
||||||
priceCheckBuilder.put(config.insaneValuePrice(), config.insaneValueColor());
|
priceCheckBuilder.add(new PriceHighlight(config.insaneValuePrice(), config.insaneValueColor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.highValuePrice() > 0)
|
if (config.highValuePrice() > 0)
|
||||||
{
|
{
|
||||||
priceCheckBuilder.put(config.highValuePrice(), config.highValueColor());
|
priceCheckBuilder.add(new PriceHighlight(config.highValuePrice(), config.highValueColor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.mediumValuePrice() > 0)
|
if (config.mediumValuePrice() > 0)
|
||||||
{
|
{
|
||||||
priceCheckBuilder.put(config.mediumValuePrice(), config.mediumValueColor());
|
priceCheckBuilder.add(new PriceHighlight(config.mediumValuePrice(), config.mediumValueColor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.lowValuePrice() > 0)
|
if (config.lowValuePrice() > 0)
|
||||||
{
|
{
|
||||||
priceCheckBuilder.put(config.lowValuePrice(), config.lowValueColor());
|
priceCheckBuilder.add(new PriceHighlight(config.lowValuePrice(), config.lowValueColor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
priceChecks = priceCheckBuilder.build();
|
priceChecks = priceCheckBuilder.build();
|
||||||
@@ -589,26 +597,26 @@ public class GroundItemsPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
ValueCalculationMode mode = config.valueCalculationMode();
|
ValueCalculationMode mode = config.valueCalculationMode();
|
||||||
for (Map.Entry<Integer, Color> entry : priceChecks.entrySet())
|
for (PriceHighlight highlight : priceChecks)
|
||||||
{
|
{
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case GE:
|
case GE:
|
||||||
if (gePrice > entry.getKey())
|
if (gePrice > highlight.getPrice())
|
||||||
{
|
{
|
||||||
return entry.getValue();
|
return highlight.getColor();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case HA:
|
case HA:
|
||||||
if (haPrice > entry.getKey())
|
if (haPrice > highlight.getPrice())
|
||||||
{
|
{
|
||||||
return entry.getValue();
|
return highlight.getColor();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: // case HIGHEST
|
default: // case HIGHEST
|
||||||
if (gePrice > entry.getKey() || haPrice > entry.getKey())
|
if (gePrice > highlight.getPrice() || haPrice > highlight.getPrice())
|
||||||
{
|
{
|
||||||
return entry.getValue();
|
return highlight.getColor();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user