item charges: simplify infobox creation logic

This looks at the worn items and matches them to known items with
charges, instead of checking the worn items for each known item with
charges. Additionally it associates guthix rest to potions, because
previously they did not have a config option, and adds an infobox for
the chronicle.
This commit is contained in:
Adam
2021-05-09 12:46:51 -04:00
parent 18bd40c702
commit 6dca841c87
8 changed files with 202 additions and 429 deletions

View File

@@ -27,14 +27,16 @@ package net.runelite.client.plugins.itemcharges;
import java.awt.Color;
import java.awt.image.BufferedImage;
import lombok.Getter;
import lombok.ToString;
import net.runelite.api.EquipmentInventorySlot;
import net.runelite.client.ui.overlay.infobox.Counter;
@Getter
@ToString
class ItemChargeInfobox extends Counter
{
private final ItemChargePlugin plugin;
private final ItemWithSlot item;
private final int item;
private final EquipmentInventorySlot slot;
ItemChargeInfobox(
@@ -42,7 +44,7 @@ class ItemChargeInfobox extends Counter
BufferedImage image,
String name,
int charges,
ItemWithSlot item,
int item,
EquipmentInventorySlot slot)
{
super(image, plugin, charges);

View File

@@ -30,9 +30,19 @@ import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import javax.inject.Inject;
import net.runelite.api.ItemID;
import net.runelite.api.widgets.WidgetItem;
import static net.runelite.client.plugins.itemcharges.ItemChargeType.*;
import static net.runelite.client.plugins.itemcharges.ItemChargeType.ABYSSAL_BRACELET;
import static net.runelite.client.plugins.itemcharges.ItemChargeType.AMULET_OF_BOUNTY;
import static net.runelite.client.plugins.itemcharges.ItemChargeType.AMULET_OF_CHEMISTRY;
import static net.runelite.client.plugins.itemcharges.ItemChargeType.BELLOWS;
import static net.runelite.client.plugins.itemcharges.ItemChargeType.FRUIT_BASKET;
import static net.runelite.client.plugins.itemcharges.ItemChargeType.FUNGICIDE_SPRAY;
import static net.runelite.client.plugins.itemcharges.ItemChargeType.IMPBOX;
import static net.runelite.client.plugins.itemcharges.ItemChargeType.POTION;
import static net.runelite.client.plugins.itemcharges.ItemChargeType.SACK;
import static net.runelite.client.plugins.itemcharges.ItemChargeType.TELEPORT;
import static net.runelite.client.plugins.itemcharges.ItemChargeType.WATERCAN;
import static net.runelite.client.plugins.itemcharges.ItemChargeType.WATERSKIN;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.overlay.WidgetItemOverlay;
import net.runelite.client.ui.overlay.components.TextComponent;
@@ -62,86 +72,15 @@ class ItemChargeOverlay extends WidgetItemOverlay
graphics.setFont(FontManager.getRunescapeSmallFont());
int charges;
if (itemId == ItemID.DODGY_NECKLACE)
ItemWithConfig itemWithConfig = ItemWithConfig.findItem(itemId);
if (itemWithConfig != null)
{
if (!config.showDodgyCount())
if (!itemWithConfig.getType().getEnabled().apply(config))
{
return;
}
charges = itemChargePlugin.getItemCharges(ItemChargeConfig.KEY_DODGY_NECKLACE);
}
else if (itemId == ItemID.BINDING_NECKLACE)
{
if (!config.showBindingNecklaceCharges())
{
return;
}
charges = itemChargePlugin.getItemCharges(ItemChargeConfig.KEY_BINDING_NECKLACE);
}
else if (itemId >= ItemID.EXPLORERS_RING_1 && itemId <= ItemID.EXPLORERS_RING_4)
{
if (!config.showExplorerRingCharges())
{
return;
}
charges = itemChargePlugin.getItemCharges(ItemChargeConfig.KEY_EXPLORERS_RING);
}
else if (itemId == ItemID.RING_OF_FORGING)
{
if (!config.showRingOfForgingCount())
{
return;
}
charges = itemChargePlugin.getItemCharges(ItemChargeConfig.KEY_RING_OF_FORGING);
}
else if (itemId == ItemID.AMULET_OF_CHEMISTRY)
{
if (!config.showAmuletOfChemistryCharges())
{
return;
}
charges = itemChargePlugin.getItemCharges(ItemChargeConfig.KEY_AMULET_OF_CHEMISTRY);
}
else if (itemId == ItemID.AMULET_OF_BOUNTY)
{
if (!config.showAmuletOfBountyCharges())
{
return;
}
charges = itemChargePlugin.getItemCharges(ItemChargeConfig.KEY_AMULET_OF_BOUNTY);
}
else if (itemId == ItemID.CHRONICLE)
{
if (!config.showTeleportCharges())
{
return;
}
charges = itemChargePlugin.getItemCharges(ItemChargeConfig.KEY_CHRONICLE);
}
else if (itemId == ItemID.BRACELET_OF_SLAUGHTER)
{
if (!config.showBraceletOfSlaughterCharges())
{
return;
}
charges = itemChargePlugin.getItemCharges(ItemChargeConfig.KEY_BRACELET_OF_SLAUGHTER);
}
else if (itemId == ItemID.EXPEDITIOUS_BRACELET)
{
if (!config.showExpeditiousBraceletCharges())
{
return;
}
charges = itemChargePlugin.getItemCharges(ItemChargeConfig.KEY_EXPEDITIOUS_BRACELET);
charges = itemChargePlugin.getItemCharges(itemWithConfig.getConfigKey());
}
else
{

View File

@@ -31,6 +31,8 @@ import com.google.common.primitives.Ints;
import com.google.inject.Provides;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.util.EnumMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject;
@@ -167,6 +169,7 @@ public class ItemChargePlugin extends Plugin
// Limits destroy callback to once per tick
private int lastCheckTick;
private final Map<EquipmentInventorySlot, ItemChargeInfobox> infoboxes = new EnumMap<>(EquipmentInventorySlot.class);
@Provides
ItemChargeConfig getConfig(ConfigManager configManager)
@@ -185,6 +188,7 @@ public class ItemChargePlugin extends Plugin
{
overlayManager.remove(overlay);
infoBoxManager.removeIf(ItemChargeInfobox.class::isInstance);
infoboxes.clear();
lastCheckTick = -1;
}
@@ -196,51 +200,7 @@ public class ItemChargePlugin extends Plugin
return;
}
if (!config.showInfoboxes())
{
infoBoxManager.removeIf(ItemChargeInfobox.class::isInstance);
return;
}
if (!config.showTeleportCharges())
{
removeInfobox(ItemWithSlot.TELEPORT);
}
if (!config.showAmuletOfChemistryCharges())
{
removeInfobox(ItemWithSlot.AMULET_OF_CHEMISTY);
}
if (!config.showAmuletOfBountyCharges())
{
removeInfobox(ItemWithSlot.AMULET_OF_BOUNTY);
}
if (!config.showAbyssalBraceletCharges())
{
removeInfobox(ItemWithSlot.ABYSSAL_BRACELET);
}
if (!config.showDodgyCount())
{
removeInfobox(ItemWithSlot.DODGY_NECKLACE);
}
if (!config.showBindingNecklaceCharges())
{
removeInfobox(ItemWithSlot.BINDING_NECKLACE);
}
if (!config.showExplorerRingCharges())
{
removeInfobox(ItemWithSlot.EXPLORER_RING);
}
if (!config.showRingOfForgingCount())
{
removeInfobox(ItemWithSlot.RING_OF_FORGING);
}
clientThread.invoke(this::updateInfoboxes);
}
@Subscribe
@@ -457,62 +417,12 @@ public class ItemChargePlugin extends Plugin
@Subscribe
public void onItemContainerChanged(ItemContainerChanged event)
{
if (event.getItemContainer() != client.getItemContainer(InventoryID.EQUIPMENT) || !config.showInfoboxes())
if (event.getContainerId() != InventoryID.EQUIPMENT.getId())
{
return;
}
final Item[] items = event.getItemContainer().getItems();
if (config.showTeleportCharges())
{
updateJewelleryInfobox(ItemWithSlot.TELEPORT, items);
}
if (config.showDodgyCount())
{
updateJewelleryInfobox(ItemWithSlot.DODGY_NECKLACE, items);
}
if (config.showAbyssalBraceletCharges())
{
updateJewelleryInfobox(ItemWithSlot.ABYSSAL_BRACELET, items);
}
if (config.showBindingNecklaceCharges())
{
updateJewelleryInfobox(ItemWithSlot.BINDING_NECKLACE, items);
}
if (config.showExplorerRingCharges())
{
updateJewelleryInfobox(ItemWithSlot.EXPLORER_RING, items);
}
if (config.showRingOfForgingCount())
{
updateJewelleryInfobox(ItemWithSlot.RING_OF_FORGING, items);
}
if (config.showAmuletOfChemistryCharges())
{
updateJewelleryInfobox(ItemWithSlot.AMULET_OF_CHEMISTY, items);
}
if (config.showAmuletOfBountyCharges())
{
updateJewelleryInfobox(ItemWithSlot.AMULET_OF_BOUNTY, items);
}
if (config.showBraceletOfSlaughterCharges())
{
updateJewelleryInfobox(ItemWithSlot.BRACELET_OF_SLAUGHTER, items);
}
if (config.showExpeditiousBraceletCharges())
{
updateJewelleryInfobox(ItemWithSlot.EXPEDITIOUS_BRACELET, items);
}
updateInfoboxes();
}
@Subscribe
@@ -582,138 +492,50 @@ public class ItemChargePlugin extends Plugin
private void updateDodgyNecklaceCharges(final int value)
{
setItemCharges(ItemChargeConfig.KEY_DODGY_NECKLACE, value);
if (config.showInfoboxes() && config.showDodgyCount())
{
final ItemContainer itemContainer = client.getItemContainer(InventoryID.EQUIPMENT);
if (itemContainer == null)
{
return;
}
updateJewelleryInfobox(ItemWithSlot.DODGY_NECKLACE, itemContainer.getItems());
}
updateInfoboxes();
}
private void updateAmuletOfChemistryCharges(final int value)
{
setItemCharges(ItemChargeConfig.KEY_AMULET_OF_CHEMISTRY, value);
if (config.showInfoboxes() && config.showAmuletOfChemistryCharges())
{
final ItemContainer itemContainer = client.getItemContainer(InventoryID.EQUIPMENT);
if (itemContainer == null)
{
return;
}
updateJewelleryInfobox(ItemWithSlot.AMULET_OF_CHEMISTY, itemContainer.getItems());
}
updateInfoboxes();
}
private void updateAmuletOfBountyCharges(final int value)
{
setItemCharges(ItemChargeConfig.KEY_AMULET_OF_BOUNTY, value);
if (config.showInfoboxes() && config.showAmuletOfBountyCharges())
{
final ItemContainer itemContainer = client.getItemContainer(InventoryID.EQUIPMENT);
if (itemContainer == null)
{
return;
}
updateJewelleryInfobox(ItemWithSlot.AMULET_OF_BOUNTY, itemContainer.getItems());
}
updateInfoboxes();
}
private void updateBindingNecklaceCharges(final int value)
{
setItemCharges(ItemChargeConfig.KEY_BINDING_NECKLACE, value);
if (config.showInfoboxes() && config.showBindingNecklaceCharges())
{
final ItemContainer itemContainer = client.getItemContainer(InventoryID.EQUIPMENT);
if (itemContainer == null)
{
return;
}
updateJewelleryInfobox(ItemWithSlot.BINDING_NECKLACE, itemContainer.getItems());
}
updateInfoboxes();
}
private void updateExplorerRingCharges(final int value)
{
// Note: Varbit counts upwards. We count down from the maximum charges.
setItemCharges(ItemChargeConfig.KEY_EXPLORERS_RING, MAX_EXPLORER_RING_CHARGES - value);
if (config.showInfoboxes() && config.showExplorerRingCharges())
{
final ItemContainer itemContainer = client.getItemContainer(InventoryID.EQUIPMENT);
if (itemContainer == null)
{
return;
}
updateJewelleryInfobox(ItemWithSlot.EXPLORER_RING, itemContainer.getItems());
}
updateInfoboxes();
}
private void updateRingOfForgingCharges(final int value)
{
setItemCharges(ItemChargeConfig.KEY_RING_OF_FORGING, value);
if (config.showInfoboxes() && config.showRingOfForgingCount())
{
final ItemContainer itemContainer = client.getItemContainer(InventoryID.EQUIPMENT);
if (itemContainer == null)
{
return;
}
updateJewelleryInfobox(ItemWithSlot.RING_OF_FORGING, itemContainer.getItems());
}
updateInfoboxes();
}
private void updateBraceletOfSlaughterCharges(final int value)
{
setItemCharges(ItemChargeConfig.KEY_BRACELET_OF_SLAUGHTER, value);
if (config.showInfoboxes() && config.showBraceletOfSlaughterCharges())
{
final ItemContainer itemContainer = client.getItemContainer(InventoryID.EQUIPMENT);
if (itemContainer == null)
{
return;
}
updateJewelleryInfobox(ItemWithSlot.BRACELET_OF_SLAUGHTER, itemContainer.getItems());
}
updateInfoboxes();
}
private void updateExpeditiousBraceletCharges(final int value)
{
setItemCharges(ItemChargeConfig.KEY_EXPEDITIOUS_BRACELET, value);
if (config.showInfoboxes() && config.showExpeditiousBraceletCharges())
{
final ItemContainer itemContainer = client.getItemContainer(InventoryID.EQUIPMENT);
if (itemContainer == null)
{
return;
}
updateJewelleryInfobox(ItemWithSlot.EXPEDITIOUS_BRACELET, itemContainer.getItems());
}
updateInfoboxes();
}
private void checkDestroyWidget()
@@ -738,81 +560,85 @@ public class ItemChargePlugin extends Plugin
}
}
private void updateJewelleryInfobox(ItemWithSlot item, Item[] items)
private void updateInfoboxes()
{
for (final EquipmentInventorySlot equipmentInventorySlot : item.getSlots())
{
updateJewelleryInfobox(item, items, equipmentInventorySlot);
}
}
final ItemContainer itemContainer = client.getItemContainer(InventoryID.EQUIPMENT);
private void updateJewelleryInfobox(ItemWithSlot type, Item[] items, EquipmentInventorySlot slot)
{
removeInfobox(type, slot);
if (slot.getSlotIdx() >= items.length)
if (itemContainer == null)
{
return;
}
final int id = items[slot.getSlotIdx()].getId();
if (id < 0)
final Item[] items = itemContainer.getItems();
boolean showInfoboxes = config.showInfoboxes();
for (EquipmentInventorySlot slot : EquipmentInventorySlot.values())
{
return;
}
if (slot.getSlotIdx() >= items.length)
{
break;
}
final ItemWithCharge itemWithCharge = ItemWithCharge.findItem(id);
int charges = -1;
Item i = items[slot.getSlotIdx()];
int id = i.getId();
ItemChargeType type = null;
int charges = -1;
if (itemWithCharge == null)
{
if (id == ItemID.DODGY_NECKLACE && type == ItemWithSlot.DODGY_NECKLACE)
final ItemWithCharge itemWithCharge = ItemWithCharge.findItem(id);
if (itemWithCharge != null)
{
charges = getItemCharges(ItemChargeConfig.KEY_DODGY_NECKLACE);
type = itemWithCharge.getType();
charges = itemWithCharge.getCharges();
}
else if (id == ItemID.BINDING_NECKLACE && type == ItemWithSlot.BINDING_NECKLACE)
else
{
charges = getItemCharges(ItemChargeConfig.KEY_BINDING_NECKLACE);
final ItemWithConfig itemWithConfig = ItemWithConfig.findItem(id);
if (itemWithConfig != null)
{
type = itemWithConfig.getType();
charges = getItemCharges(itemWithConfig.getConfigKey());
}
}
else if ((id >= ItemID.EXPLORERS_RING_1 && id <= ItemID.EXPLORERS_RING_4) && type == ItemWithSlot.EXPLORER_RING)
boolean enabled = type != null && type.getEnabled().apply(config);
if (showInfoboxes && enabled && charges > 0)
{
charges = getItemCharges(ItemChargeConfig.KEY_EXPLORERS_RING);
ItemChargeInfobox infobox = infoboxes.get(slot);
if (infobox != null)
{
if (infobox.getItem() == id)
{
if (infobox.getCount() == charges)
{
continue;
}
log.debug("Updating infobox count for {}", infobox);
infobox.setCount(charges);
continue;
}
log.debug("Rebuilding infobox {}", infobox);
infoBoxManager.removeInfoBox(infobox);
infoboxes.remove(slot);
}
final String name = itemManager.getItemComposition(id).getName();
final BufferedImage image = itemManager.getImage(id);
infobox = new ItemChargeInfobox(this, image, name, charges, id, slot);
infoBoxManager.addInfoBox(infobox);
infoboxes.put(slot, infobox);
}
else if (id == ItemID.RING_OF_FORGING && type == ItemWithSlot.RING_OF_FORGING)
else
{
charges = getItemCharges(ItemChargeConfig.KEY_RING_OF_FORGING);
}
else if (id == ItemID.AMULET_OF_CHEMISTRY && type == ItemWithSlot.AMULET_OF_CHEMISTY)
{
charges = getItemCharges(ItemChargeConfig.KEY_AMULET_OF_CHEMISTRY);
}
else if (id == ItemID.AMULET_OF_BOUNTY && type == ItemWithSlot.AMULET_OF_BOUNTY)
{
charges = getItemCharges(ItemChargeConfig.KEY_AMULET_OF_BOUNTY);
}
else if (id == ItemID.BRACELET_OF_SLAUGHTER && type == ItemWithSlot.BRACELET_OF_SLAUGHTER)
{
charges = getItemCharges(ItemChargeConfig.KEY_BRACELET_OF_SLAUGHTER);
}
else if (id == ItemID.EXPEDITIOUS_BRACELET && type == ItemWithSlot.EXPEDITIOUS_BRACELET)
{
charges = getItemCharges(ItemChargeConfig.KEY_EXPEDITIOUS_BRACELET);
ItemChargeInfobox infobox = infoboxes.remove(slot);
if (infobox != null)
{
log.debug("Removing infobox {}", infobox);
infoBoxManager.removeInfoBox(infobox);
}
}
}
else if (itemWithCharge.getType() == type.getType())
{
charges = itemWithCharge.getCharges();
}
if (charges <= 0)
{
return;
}
final String name = itemManager.getItemComposition(id).getName();
final BufferedImage image = itemManager.getImage(id);
final ItemChargeInfobox infobox = new ItemChargeInfobox(this, image, name, charges, type, slot);
infoBoxManager.addInfoBox(infobox);
}
int getItemCharges(String key)
@@ -835,25 +661,6 @@ public class ItemChargePlugin extends Plugin
configManager.setRSProfileConfiguration(ItemChargeConfig.GROUP, key, value);
}
private void removeInfobox(final ItemWithSlot item)
{
infoBoxManager.removeIf(t -> t instanceof ItemChargeInfobox && ((ItemChargeInfobox) t).getItem() == item);
}
private void removeInfobox(final ItemWithSlot item, final EquipmentInventorySlot slot)
{
infoBoxManager.removeIf(t ->
{
if (!(t instanceof ItemChargeInfobox))
{
return false;
}
final ItemChargeInfobox i = (ItemChargeInfobox) t;
return i.getItem() == item && i.getSlot() == slot;
});
}
Color getColor(int charges)
{
Color color = Color.WHITE;

View File

@@ -25,26 +25,32 @@
*/
package net.runelite.client.plugins.itemcharges;
import java.util.function.Function;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
enum ItemChargeType
{
ABYSSAL_BRACELET,
AMULET_OF_CHEMISTRY,
AMULET_OF_BOUNTY,
BELLOWS,
BRACELET_OF_SLAUGHTER,
EXPEDITIOUS_BRACELET,
FUNGICIDE_SPRAY,
IMPBOX,
TELEPORT,
WATERCAN,
WATERSKIN,
DODGY_NECKLACE,
BINDING_NECKLACE,
EXPLORER_RING,
FRUIT_BASKET,
SACK,
RING_OF_FORGING,
GUTHIX_REST,
CHRONICLE,
POTION,
ABYSSAL_BRACELET(ItemChargeConfig::showAbyssalBraceletCharges),
AMULET_OF_CHEMISTRY(ItemChargeConfig::showAmuletOfChemistryCharges),
AMULET_OF_BOUNTY(ItemChargeConfig::showAmuletOfBountyCharges),
BELLOWS(ItemChargeConfig::showBellowCharges),
BRACELET_OF_SLAUGHTER(ItemChargeConfig::showBraceletOfSlaughterCharges),
EXPEDITIOUS_BRACELET(ItemChargeConfig::showExpeditiousBraceletCharges),
FUNGICIDE_SPRAY(ItemChargeConfig::showFungicideCharges),
IMPBOX(ItemChargeConfig::showImpCharges),
TELEPORT(ItemChargeConfig::showTeleportCharges),
WATERCAN(ItemChargeConfig::showWateringCanCharges),
WATERSKIN(ItemChargeConfig::showWaterskinCharges),
DODGY_NECKLACE(ItemChargeConfig::showDodgyCount),
BINDING_NECKLACE(ItemChargeConfig::showBindingNecklaceCharges),
EXPLORER_RING(ItemChargeConfig::showExplorerRingCharges),
FRUIT_BASKET(ItemChargeConfig::showBasketCharges),
SACK(ItemChargeConfig::showSackCharges),
RING_OF_FORGING(ItemChargeConfig::showRingOfForgingCount),
POTION(ItemChargeConfig::showPotionDoseCount);
private final Function<ItemChargeConfig, Boolean> enabled;
}

View File

@@ -231,10 +231,10 @@ enum ItemWithCharge
GLORYT4(TELEPORT, AMULET_OF_GLORY_T4, 4),
GLORYT5(TELEPORT, AMULET_OF_GLORY_T5, 5),
GLORYT6(TELEPORT, AMULET_OF_GLORY_T6, 6),
GREST1(GUTHIX_REST, GUTHIX_REST1, 1),
GREST2(GUTHIX_REST, GUTHIX_REST2, 2),
GREST3(GUTHIX_REST, GUTHIX_REST3, 3),
GREST4(GUTHIX_REST, GUTHIX_REST4, 4),
GREST1(POTION, GUTHIX_REST1, 1),
GREST2(POTION, GUTHIX_REST2, 2),
GREST3(POTION, GUTHIX_REST3, 3),
GREST4(POTION, GUTHIX_REST4, 4),
GUTHIX_BAL1(POTION, GUTHIX_BALANCE1, 1),
GUTHIX_BAL2(POTION, GUTHIX_BALANCE2, 2),
GUTHIX_BAL3(POTION, GUTHIX_BALANCE3, 3),

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 2021, 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.plugins.itemcharges;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import javax.annotation.Nullable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.runelite.api.ItemID;
@AllArgsConstructor
@Getter
enum ItemWithConfig
{
DODGY_NECKLACE(ItemID.DODGY_NECKLACE, ItemChargeConfig.KEY_DODGY_NECKLACE, ItemChargeType.DODGY_NECKLACE),
BINDING_NECKLACE(ItemID.BINDING_NECKLACE, ItemChargeConfig.KEY_BINDING_NECKLACE, ItemChargeType.BINDING_NECKLACE),
EXPLORERS_RING_1(ItemID.EXPLORERS_RING_1, ItemChargeConfig.KEY_EXPLORERS_RING, ItemChargeType.EXPLORER_RING),
EXPLORERS_RING_2(ItemID.EXPLORERS_RING_2, ItemChargeConfig.KEY_EXPLORERS_RING, ItemChargeType.EXPLORER_RING),
EXPLORERS_RING_3(ItemID.EXPLORERS_RING_3, ItemChargeConfig.KEY_EXPLORERS_RING, ItemChargeType.EXPLORER_RING),
EXPLORERS_RING_4(ItemID.EXPLORERS_RING_4, ItemChargeConfig.KEY_EXPLORERS_RING, ItemChargeType.EXPLORER_RING),
RING_OF_FORGING(ItemID.RING_OF_FORGING, ItemChargeConfig.KEY_RING_OF_FORGING, ItemChargeType.RING_OF_FORGING),
AMULET_OF_CHEMISTRY(ItemID.AMULET_OF_CHEMISTRY, ItemChargeConfig.KEY_AMULET_OF_CHEMISTRY, ItemChargeType.AMULET_OF_CHEMISTRY),
AMULET_OF_BOUNTY(ItemID.AMULET_OF_BOUNTY, ItemChargeConfig.KEY_AMULET_OF_BOUNTY, ItemChargeType.AMULET_OF_BOUNTY),
BRACELET_OF_SLAUGHTER(ItemID.BRACELET_OF_SLAUGHTER, ItemChargeConfig.KEY_BRACELET_OF_SLAUGHTER, ItemChargeType.BRACELET_OF_SLAUGHTER),
EXPEDITIOUS_BRACELET(ItemID.EXPEDITIOUS_BRACELET, ItemChargeConfig.KEY_EXPEDITIOUS_BRACELET, ItemChargeType.EXPEDITIOUS_BRACELET),
CHRONICLE(ItemID.CHRONICLE, ItemChargeConfig.KEY_CHRONICLE, ItemChargeType.TELEPORT);
private final int itemId;
private final String configKey;
private final ItemChargeType type;
private static final Map<Integer, ItemWithConfig> ID_MAP;
static
{
ImmutableMap.Builder<Integer, ItemWithConfig> builder = new ImmutableMap.Builder<>();
for (ItemWithConfig item : values())
{
builder.put(item.getItemId(), item);
}
ID_MAP = builder.build();
}
@Nullable
static ItemWithConfig findItem(int itemId)
{
return ID_MAP.get(itemId);
}
}

View File

@@ -1,57 +0,0 @@
/*
* Copyright (c) 2019, Tomas Slusny <slusnucky@gmail.com>
* Copyright (c) 2019, Aleios <https://github.com/aleios>
* Copyright (c) 2020, Unmoon <https://github.com/unmoon>
* 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.plugins.itemcharges;
import com.google.common.collect.Sets;
import java.util.Set;
import lombok.Getter;
import net.runelite.api.EquipmentInventorySlot;
@Getter
enum ItemWithSlot
{
ABYSSAL_BRACELET(ItemChargeType.ABYSSAL_BRACELET, EquipmentInventorySlot.GLOVES),
AMULET_OF_CHEMISTY(ItemChargeType.AMULET_OF_CHEMISTRY, EquipmentInventorySlot.AMULET),
AMULET_OF_BOUNTY(ItemChargeType.AMULET_OF_BOUNTY, EquipmentInventorySlot.AMULET),
BRACELET_OF_SLAUGHTER(ItemChargeType.BRACELET_OF_SLAUGHTER, EquipmentInventorySlot.GLOVES),
DODGY_NECKLACE(ItemChargeType.DODGY_NECKLACE, EquipmentInventorySlot.AMULET),
EXPEDITIOUS_BRACELET(ItemChargeType.EXPEDITIOUS_BRACELET, EquipmentInventorySlot.GLOVES),
BINDING_NECKLACE(ItemChargeType.BINDING_NECKLACE, EquipmentInventorySlot.AMULET),
EXPLORER_RING(ItemChargeType.EXPLORER_RING, EquipmentInventorySlot.RING),
RING_OF_FORGING(ItemChargeType.RING_OF_FORGING, EquipmentInventorySlot.RING),
CHRONICLE(ItemChargeType.CHRONICLE, EquipmentInventorySlot.SHIELD),
TELEPORT(ItemChargeType.TELEPORT, EquipmentInventorySlot.WEAPON, EquipmentInventorySlot.AMULET, EquipmentInventorySlot.GLOVES, EquipmentInventorySlot.RING);
private final ItemChargeType type;
private final Set<EquipmentInventorySlot> slots;
ItemWithSlot(final ItemChargeType type, final EquipmentInventorySlot... slots)
{
this.type = type;
this.slots = Sets.newHashSet(slots);
}
}

View File

@@ -32,6 +32,7 @@ import java.util.concurrent.ScheduledExecutorService;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.InventoryID;
import net.runelite.api.Item;
import net.runelite.api.ItemContainer;
import net.runelite.api.ItemID;
import net.runelite.api.events.ChatMessage;
@@ -173,6 +174,7 @@ public class ItemChargePluginTest
ItemContainer equipmentItemContainer = mock(ItemContainer.class);
when(client.getItemContainer(InventoryID.EQUIPMENT)).thenReturn(equipmentItemContainer);
when(equipmentItemContainer.contains(ItemID.RING_OF_FORGING)).thenReturn(true);
when(equipmentItemContainer.getItems()).thenReturn(new Item[0]);
// Run message
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", USED_RING_OF_FORGING, "", 0);
itemChargePlugin.onChatMessage(chatMessage);