item charges: use RSProfiles for items with stored charges
This commit is contained in:
@@ -32,9 +32,19 @@ import net.runelite.client.config.ConfigGroup;
|
||||
import net.runelite.client.config.ConfigItem;
|
||||
import net.runelite.client.config.ConfigSection;
|
||||
|
||||
@ConfigGroup("itemCharge")
|
||||
@ConfigGroup(ItemChargeConfig.GROUP)
|
||||
public interface ItemChargeConfig extends Config
|
||||
{
|
||||
String GROUP = "itemCharge";
|
||||
|
||||
String KEY_AMULET_OF_BOUNTY = "amuletOfBounty";
|
||||
String KEY_AMULET_OF_CHEMISTRY = "amuletOfChemistry";
|
||||
String KEY_BINDING_NECKLACE = "bindingNecklace";
|
||||
String KEY_CHRONICLE = "chronicle";
|
||||
String KEY_DODGY_NECKLACE = "dodgyNecklace";
|
||||
String KEY_EXPLORERS_RING = "explorerRing";
|
||||
String KEY_RING_OF_FORGING = "ringOfForging";
|
||||
|
||||
@ConfigSection(
|
||||
name = "Charge Settings",
|
||||
description = "Configuration for which charges should be displayed",
|
||||
@@ -129,24 +139,6 @@ public interface ItemChargeConfig extends Config
|
||||
return true;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "dodgyNecklace",
|
||||
name = "",
|
||||
description = "",
|
||||
hidden = true
|
||||
)
|
||||
default int dodgyNecklace()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "dodgyNecklace",
|
||||
name = "",
|
||||
description = ""
|
||||
)
|
||||
void dodgyNecklace(int dodgyNecklace);
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "showImpCharges",
|
||||
name = "Imp-in-a-box charges",
|
||||
@@ -255,24 +247,6 @@ public interface ItemChargeConfig extends Config
|
||||
return true;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "amuletOfChemistry",
|
||||
name = "",
|
||||
description = "",
|
||||
hidden = true
|
||||
)
|
||||
default int amuletOfChemistry()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "amuletOfChemistry",
|
||||
name = "",
|
||||
description = ""
|
||||
)
|
||||
void amuletOfChemistry(int amuletOfChemistry);
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "showAmuletOfBountyCharges",
|
||||
name = "Amulet of Bounty Charges",
|
||||
@@ -285,24 +259,6 @@ public interface ItemChargeConfig extends Config
|
||||
return true;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "amuletOfBounty",
|
||||
name = "",
|
||||
description = "",
|
||||
hidden = true
|
||||
)
|
||||
default int amuletOfBounty()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "amuletOfBounty",
|
||||
name = "",
|
||||
description = ""
|
||||
)
|
||||
void amuletOfBounty(int amuletOfBounty);
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "recoilNotification",
|
||||
name = "Ring of Recoil Notification",
|
||||
@@ -327,24 +283,6 @@ public interface ItemChargeConfig extends Config
|
||||
return true;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "bindingNecklace",
|
||||
name = "",
|
||||
description = "",
|
||||
hidden = true
|
||||
)
|
||||
default int bindingNecklace()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "bindingNecklace",
|
||||
name = "",
|
||||
description = ""
|
||||
)
|
||||
void bindingNecklace(int bindingNecklace);
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "bindingNotification",
|
||||
name = "Binding Necklace Notification",
|
||||
@@ -369,24 +307,6 @@ public interface ItemChargeConfig extends Config
|
||||
return true;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "explorerRing",
|
||||
name = "",
|
||||
description = "",
|
||||
hidden = true
|
||||
)
|
||||
default int explorerRing()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "explorerRing",
|
||||
name = "",
|
||||
description = ""
|
||||
)
|
||||
void explorerRing(int explorerRing);
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "showRingOfForgingCount",
|
||||
name = "Ring of Forging Charges",
|
||||
@@ -399,24 +319,6 @@ public interface ItemChargeConfig extends Config
|
||||
return true;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "ringOfForging",
|
||||
name = "",
|
||||
description = "",
|
||||
hidden = true
|
||||
)
|
||||
default int ringOfForging()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "ringOfForging",
|
||||
name = "",
|
||||
description = ""
|
||||
)
|
||||
void ringOfForging(int ringOfForging);
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "ringOfForgingNotification",
|
||||
name = "Ring of Forging Notification",
|
||||
@@ -451,22 +353,4 @@ public interface ItemChargeConfig extends Config
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "chronicle",
|
||||
name = "",
|
||||
description = "",
|
||||
hidden = true
|
||||
)
|
||||
default int chronicle()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "chronicle",
|
||||
name = "",
|
||||
description = ""
|
||||
)
|
||||
void chronicle(int chronicle);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class ItemChargeOverlay extends WidgetItemOverlay
|
||||
return;
|
||||
}
|
||||
|
||||
charges = config.dodgyNecklace();
|
||||
charges = itemChargePlugin.getItemCharges(ItemChargeConfig.KEY_DODGY_NECKLACE);
|
||||
}
|
||||
else if (itemId == ItemID.BINDING_NECKLACE)
|
||||
{
|
||||
@@ -78,7 +78,7 @@ class ItemChargeOverlay extends WidgetItemOverlay
|
||||
return;
|
||||
}
|
||||
|
||||
charges = config.bindingNecklace();
|
||||
charges = itemChargePlugin.getItemCharges(ItemChargeConfig.KEY_BINDING_NECKLACE);
|
||||
}
|
||||
else if (itemId >= ItemID.EXPLORERS_RING_1 && itemId <= ItemID.EXPLORERS_RING_4)
|
||||
{
|
||||
@@ -87,7 +87,7 @@ class ItemChargeOverlay extends WidgetItemOverlay
|
||||
return;
|
||||
}
|
||||
|
||||
charges = config.explorerRing();
|
||||
charges = itemChargePlugin.getItemCharges(ItemChargeConfig.KEY_EXPLORERS_RING);
|
||||
}
|
||||
else if (itemId == ItemID.RING_OF_FORGING)
|
||||
{
|
||||
@@ -96,7 +96,7 @@ class ItemChargeOverlay extends WidgetItemOverlay
|
||||
return;
|
||||
}
|
||||
|
||||
charges = config.ringOfForging();
|
||||
charges = itemChargePlugin.getItemCharges(ItemChargeConfig.KEY_RING_OF_FORGING);
|
||||
}
|
||||
else if (itemId == ItemID.AMULET_OF_CHEMISTRY)
|
||||
{
|
||||
@@ -105,7 +105,7 @@ class ItemChargeOverlay extends WidgetItemOverlay
|
||||
return;
|
||||
}
|
||||
|
||||
charges = config.amuletOfChemistry();
|
||||
charges = itemChargePlugin.getItemCharges(ItemChargeConfig.KEY_AMULET_OF_CHEMISTRY);
|
||||
}
|
||||
else if (itemId == ItemID.AMULET_OF_BOUNTY)
|
||||
{
|
||||
@@ -114,7 +114,7 @@ class ItemChargeOverlay extends WidgetItemOverlay
|
||||
return;
|
||||
}
|
||||
|
||||
charges = config.amuletOfBounty();
|
||||
charges = itemChargePlugin.getItemCharges(ItemChargeConfig.KEY_AMULET_OF_BOUNTY);
|
||||
}
|
||||
else if (itemId == ItemID.CHRONICLE)
|
||||
{
|
||||
@@ -123,7 +123,7 @@ class ItemChargeOverlay extends WidgetItemOverlay
|
||||
return;
|
||||
}
|
||||
|
||||
charges = config.chronicle();
|
||||
charges = itemChargePlugin.getItemCharges(ItemChargeConfig.KEY_CHRONICLE);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -129,6 +129,9 @@ public class ItemChargePlugin extends Plugin
|
||||
@Inject
|
||||
private ClientThread clientThread;
|
||||
|
||||
@Inject
|
||||
private ConfigManager configManager;
|
||||
|
||||
@Inject
|
||||
private OverlayManager overlayManager;
|
||||
|
||||
@@ -173,7 +176,7 @@ public class ItemChargePlugin extends Plugin
|
||||
@Subscribe
|
||||
public void onConfigChanged(ConfigChanged event)
|
||||
{
|
||||
if (!event.getGroup().equals("itemCharge"))
|
||||
if (!event.getGroup().equals(ItemChargeConfig.GROUP))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -310,7 +313,7 @@ public class ItemChargePlugin extends Plugin
|
||||
}
|
||||
else if (bindingNecklaceUsedMatcher.find())
|
||||
{
|
||||
updateBindingNecklaceCharges(config.bindingNecklace() - 1);
|
||||
updateBindingNecklaceCharges(getItemCharges(ItemChargeConfig.KEY_BINDING_NECKLACE) - 1);
|
||||
}
|
||||
else if (bindingNecklaceCheckMatcher.find())
|
||||
{
|
||||
@@ -347,7 +350,7 @@ public class ItemChargePlugin extends Plugin
|
||||
|
||||
if (equipment.contains(ItemID.RING_OF_FORGING))
|
||||
{
|
||||
int charges = Ints.constrainToRange(config.ringOfForging() - 1, 0, MAX_RING_OF_FORGING_CHARGES);
|
||||
int charges = Ints.constrainToRange(getItemCharges(ItemChargeConfig.KEY_RING_OF_FORGING) - 1, 0, MAX_RING_OF_FORGING_CHARGES);
|
||||
updateRingOfForgingCharges(charges);
|
||||
}
|
||||
}
|
||||
@@ -366,28 +369,28 @@ public class ItemChargePlugin extends Plugin
|
||||
|
||||
if (match.equals("one"))
|
||||
{
|
||||
config.chronicle(1);
|
||||
setItemCharges(ItemChargeConfig.KEY_CHRONICLE, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
config.chronicle(Integer.parseInt(match));
|
||||
setItemCharges(ItemChargeConfig.KEY_CHRONICLE, Integer.parseInt(match));
|
||||
}
|
||||
}
|
||||
else if (chronicleUseAndCheckMatcher.find())
|
||||
{
|
||||
config.chronicle(Integer.parseInt(chronicleUseAndCheckMatcher.group(1)));
|
||||
setItemCharges(ItemChargeConfig.KEY_CHRONICLE, Integer.parseInt(chronicleUseAndCheckMatcher.group(1)));
|
||||
}
|
||||
else if (message.equals(CHRONICLE_ONE_CHARGE_TEXT))
|
||||
{
|
||||
config.chronicle(1);
|
||||
setItemCharges(ItemChargeConfig.KEY_CHRONICLE, 1);
|
||||
}
|
||||
else if (message.equals(CHRONICLE_EMPTY_TEXT) || message.equals(CHRONICLE_NO_CHARGES_TEXT))
|
||||
{
|
||||
config.chronicle(0);
|
||||
setItemCharges(ItemChargeConfig.KEY_CHRONICLE, 0);
|
||||
}
|
||||
else if (message.equals(CHRONICLE_FULL_TEXT))
|
||||
{
|
||||
config.chronicle(1000);
|
||||
setItemCharges(ItemChargeConfig.KEY_CHRONICLE, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -501,7 +504,7 @@ public class ItemChargePlugin extends Plugin
|
||||
|
||||
private void updateDodgyNecklaceCharges(final int value)
|
||||
{
|
||||
config.dodgyNecklace(value);
|
||||
setItemCharges(ItemChargeConfig.KEY_DODGY_NECKLACE, value);
|
||||
|
||||
if (config.showInfoboxes() && config.showDodgyCount())
|
||||
{
|
||||
@@ -518,7 +521,7 @@ public class ItemChargePlugin extends Plugin
|
||||
|
||||
private void updateAmuletOfChemistryCharges(final int value)
|
||||
{
|
||||
config.amuletOfChemistry(value);
|
||||
setItemCharges(ItemChargeConfig.KEY_AMULET_OF_CHEMISTRY, value);
|
||||
|
||||
if (config.showInfoboxes() && config.showAmuletOfChemistryCharges())
|
||||
{
|
||||
@@ -535,7 +538,7 @@ public class ItemChargePlugin extends Plugin
|
||||
|
||||
private void updateAmuletOfBountyCharges(final int value)
|
||||
{
|
||||
config.amuletOfBounty(value);
|
||||
setItemCharges(ItemChargeConfig.KEY_AMULET_OF_BOUNTY, value);
|
||||
|
||||
if (config.showInfoboxes() && config.showAmuletOfBountyCharges())
|
||||
{
|
||||
@@ -552,7 +555,7 @@ public class ItemChargePlugin extends Plugin
|
||||
|
||||
private void updateBindingNecklaceCharges(final int value)
|
||||
{
|
||||
config.bindingNecklace(value);
|
||||
setItemCharges(ItemChargeConfig.KEY_BINDING_NECKLACE, value);
|
||||
|
||||
if (config.showInfoboxes() && config.showBindingNecklaceCharges())
|
||||
{
|
||||
@@ -570,7 +573,7 @@ public class ItemChargePlugin extends Plugin
|
||||
private void updateExplorerRingCharges(final int value)
|
||||
{
|
||||
// Note: Varbit counts upwards. We count down from the maximum charges.
|
||||
config.explorerRing(MAX_EXPLORER_RING_CHARGES - value);
|
||||
setItemCharges(ItemChargeConfig.KEY_EXPLORERS_RING, MAX_EXPLORER_RING_CHARGES - value);
|
||||
|
||||
if (config.showInfoboxes() && config.showExplorerRingCharges())
|
||||
{
|
||||
@@ -587,7 +590,7 @@ public class ItemChargePlugin extends Plugin
|
||||
|
||||
private void updateRingOfForgingCharges(final int value)
|
||||
{
|
||||
config.ringOfForging(value);
|
||||
setItemCharges(ItemChargeConfig.KEY_RING_OF_FORGING, value);
|
||||
|
||||
if (config.showInfoboxes() && config.showRingOfForgingCount())
|
||||
{
|
||||
@@ -654,27 +657,27 @@ public class ItemChargePlugin extends Plugin
|
||||
{
|
||||
if (id == ItemID.DODGY_NECKLACE && type == ItemWithSlot.DODGY_NECKLACE)
|
||||
{
|
||||
charges = config.dodgyNecklace();
|
||||
charges = getItemCharges(ItemChargeConfig.KEY_DODGY_NECKLACE);
|
||||
}
|
||||
else if (id == ItemID.BINDING_NECKLACE && type == ItemWithSlot.BINDING_NECKLACE)
|
||||
{
|
||||
charges = config.bindingNecklace();
|
||||
charges = getItemCharges(ItemChargeConfig.KEY_BINDING_NECKLACE);
|
||||
}
|
||||
else if ((id >= ItemID.EXPLORERS_RING_1 && id <= ItemID.EXPLORERS_RING_4) && type == ItemWithSlot.EXPLORER_RING)
|
||||
{
|
||||
charges = config.explorerRing();
|
||||
charges = getItemCharges(ItemChargeConfig.KEY_EXPLORERS_RING);
|
||||
}
|
||||
else if (id == ItemID.RING_OF_FORGING && type == ItemWithSlot.RING_OF_FORGING)
|
||||
{
|
||||
charges = config.ringOfForging();
|
||||
charges = getItemCharges(ItemChargeConfig.KEY_RING_OF_FORGING);
|
||||
}
|
||||
else if (id == ItemID.AMULET_OF_CHEMISTRY && type == ItemWithSlot.AMULET_OF_CHEMISTY)
|
||||
{
|
||||
charges = config.amuletOfChemistry();
|
||||
charges = getItemCharges(ItemChargeConfig.KEY_AMULET_OF_CHEMISTRY);
|
||||
}
|
||||
else if (id == ItemID.AMULET_OF_BOUNTY && type == ItemWithSlot.AMULET_OF_BOUNTY)
|
||||
{
|
||||
charges = config.amuletOfBounty();
|
||||
charges = getItemCharges(ItemChargeConfig.KEY_AMULET_OF_BOUNTY);
|
||||
}
|
||||
}
|
||||
else if (itemWithCharge.getType() == type.getType())
|
||||
@@ -693,6 +696,26 @@ public class ItemChargePlugin extends Plugin
|
||||
infoBoxManager.addInfoBox(infobox);
|
||||
}
|
||||
|
||||
int getItemCharges(String key)
|
||||
{
|
||||
// Migrate old non-profile configurations
|
||||
Integer i = configManager.getConfiguration(ItemChargeConfig.GROUP, key, Integer.class);
|
||||
if (i != null)
|
||||
{
|
||||
configManager.unsetConfiguration(ItemChargeConfig.GROUP, key);
|
||||
configManager.setRSProfileConfiguration(ItemChargeConfig.GROUP, key, i);
|
||||
return i;
|
||||
}
|
||||
|
||||
i = configManager.getRSProfileConfiguration(ItemChargeConfig.GROUP, key, Integer.class);
|
||||
return i == null ? -1 : i;
|
||||
}
|
||||
|
||||
private void setItemCharges(String key, int value)
|
||||
{
|
||||
configManager.setRSProfileConfiguration(ItemChargeConfig.GROUP, key, value);
|
||||
}
|
||||
|
||||
private void removeInfobox(final ItemWithSlot item)
|
||||
{
|
||||
infoBoxManager.removeIf(t -> t instanceof ItemChargeInfobox && ((ItemChargeInfobox) t).getItem() == item);
|
||||
|
||||
Reference in New Issue
Block a user