From 0489d7de9d1e7df9cb34f29e9621fa869b099e5d Mon Sep 17 00:00:00 2001
From: TheStonedTurtle <29030969+TheStonedTurtle@users.noreply.github.com>
Date: Thu, 21 Feb 2019 11:41:48 -0800
Subject: [PATCH] Add binding necklace to Item Charge plugin
---
.../plugins/itemcharges/ItemChargeConfig.java | 42 +++++++++++-
.../itemcharges/ItemChargeOverlay.java | 9 +++
.../plugins/itemcharges/ItemChargePlugin.java | 66 +++++++++++++++++++
.../plugins/itemcharges/ItemChargeType.java | 3 +-
.../plugins/itemcharges/ItemWithSlot.java | 1 +
5 files changed, 119 insertions(+), 2 deletions(-)
diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeConfig.java
index 28c503b20a..275aa31d24 100644
--- a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeConfig.java
+++ b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeConfig.java
@@ -204,11 +204,51 @@ public interface ItemChargeConfig extends Config
return false;
}
+ @ConfigItem(
+ keyName = "showBindingNecklaceCharges",
+ name = "Show Binding Necklace Charges",
+ description = "Configures if binding necklace item charge is shown",
+ position = 15
+ )
+ default boolean showBindingNecklaceCharges()
+ {
+ 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",
+ description = "Configures if the binding necklace breaking notification is shown",
+ position = 16
+ )
+ default boolean bindingNotification()
+ {
+ return true;
+ }
+
@ConfigItem(
keyName = "showInfoboxes",
name = "Show Infoboxes",
description = "Configures whether to show an infobox equipped charge items",
- position = 15
+ position = 17
)
default boolean showInfoboxes()
{
diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeOverlay.java
index 27bb35b21d..ca289d4013 100644
--- a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeOverlay.java
+++ b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeOverlay.java
@@ -84,6 +84,15 @@ class ItemChargeOverlay extends Overlay
charges = config.dodgyNecklace();
}
+ else if (item.getId() == ItemID.BINDING_NECKLACE)
+ {
+ if (!config.showBindingNecklaceCharges())
+ {
+ continue;
+ }
+
+ charges = config.bindingNecklace();
+ }
else
{
ItemWithCharge chargeItem = ItemWithCharge.findItem(item.getId());
diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargePlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargePlugin.java
index 7d3b1f0cc6..1ddf3924bc 100644
--- a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargePlugin.java
+++ b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargePlugin.java
@@ -64,8 +64,14 @@ public class ItemChargePlugin extends Plugin
private static final Pattern DODGY_BREAK_PATTERN = Pattern.compile(
"Your dodgy necklace protects you\\..*It then crumbles to dust\\.");
private static final String RING_OF_RECOIL_BREAK_MESSAGE = "
Your Ring of Recoil has shattered.";
+ private static final Pattern BINDING_CHECK_PATTERN = Pattern.compile(
+ "You have ([0-9]+|one) charges? left before your Binding necklace disintegrates\\.");
+ private static final Pattern BINDING_USED_PATTERN = Pattern.compile(
+ "You bind the temple's power into (mud|lava|steam|dust|smoke|mist) runes\\.");
+ private static final String BINDING_BREAK_TEXT = "Your Binding necklace has disintegrated.";
private static final int MAX_DODGY_CHARGES = 10;
+ private static final int MAX_BINDING_CHARGES = 16;
@Inject
private Client client;
@@ -135,6 +141,11 @@ public class ItemChargePlugin extends Plugin
{
removeInfobox(ItemWithSlot.DODGY_NECKLACE);
}
+
+ if (!config.showBindingNecklaceCharges())
+ {
+ removeInfobox(ItemWithSlot.BINDING_NECKLACE);
+ }
}
@Subscribe
@@ -144,6 +155,9 @@ public class ItemChargePlugin extends Plugin
Matcher dodgyCheckMatcher = DODGY_CHECK_PATTERN.matcher(message);
Matcher dodgyProtectMatcher = DODGY_PROTECT_PATTERN.matcher(message);
Matcher dodgyBreakMatcher = DODGY_BREAK_PATTERN.matcher(message);
+ Matcher bindingNecklaceCheckMatcher = BINDING_CHECK_PATTERN.matcher(event.getMessage());
+ Matcher bindingNecklaceUsedMatcher = BINDING_USED_PATTERN.matcher(event.getMessage());
+
if (event.getType() == ChatMessageType.GAMEMESSAGE || event.getType() == ChatMessageType.SPAM)
{
if (config.recoilNotification() && message.contains(RING_OF_RECOIL_BREAK_MESSAGE))
@@ -167,6 +181,32 @@ public class ItemChargePlugin extends Plugin
{
updateDodgyNecklaceCharges(Integer.parseInt(dodgyProtectMatcher.group(1)));
}
+ else if (message.contains(BINDING_BREAK_TEXT))
+ {
+ if (config.bindingNotification())
+ {
+ notifier.notify(BINDING_BREAK_TEXT);
+ }
+
+ // This chat message triggers before the used message so add 1 to the max charges to ensure proper sync
+ updateBindingNecklaceCharges(MAX_BINDING_CHARGES + 1);
+ }
+ else if (bindingNecklaceUsedMatcher.find())
+ {
+ updateBindingNecklaceCharges(config.bindingNecklace() - 1);
+ }
+ else if (bindingNecklaceCheckMatcher.find())
+ {
+ final String match = bindingNecklaceCheckMatcher.group(1);
+
+ int charges = 1;
+ if (!match.equals("one"))
+ {
+ charges = Integer.parseInt(match);
+ }
+
+ updateBindingNecklaceCharges(charges);
+ }
}
}
@@ -194,6 +234,11 @@ public class ItemChargePlugin extends Plugin
{
updateJewelleryInfobox(ItemWithSlot.ABYSSAL_BRACELET, items);
}
+
+ if (config.showBindingNecklaceCharges())
+ {
+ updateJewelleryInfobox(ItemWithSlot.BINDING_NECKLACE, items);
+ }
}
private void updateDodgyNecklaceCharges(final int value)
@@ -213,6 +258,23 @@ public class ItemChargePlugin extends Plugin
}
}
+ private void updateBindingNecklaceCharges(final int value)
+ {
+ config.bindingNecklace(value);
+
+ if (config.showInfoboxes() && config.showBindingNecklaceCharges())
+ {
+ final ItemContainer itemContainer = client.getItemContainer(InventoryID.EQUIPMENT);
+
+ if (itemContainer == null)
+ {
+ return;
+ }
+
+ updateJewelleryInfobox(ItemWithSlot.BINDING_NECKLACE, itemContainer.getItems());
+ }
+ }
+
private void updateJewelleryInfobox(ItemWithSlot item, Item[] items)
{
for (final EquipmentInventorySlot equipmentInventorySlot : item.getSlots())
@@ -245,6 +307,10 @@ public class ItemChargePlugin extends Plugin
{
charges = config.dodgyNecklace();
}
+ else if (id == ItemID.BINDING_NECKLACE && type == ItemWithSlot.BINDING_NECKLACE)
+ {
+ charges = config.bindingNecklace();
+ }
}
else if (itemWithCharge.getType() == type.getType())
{
diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeType.java b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeType.java
index cbe5d20ff3..d941bf0962 100644
--- a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeType.java
+++ b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeType.java
@@ -33,5 +33,6 @@ enum ItemChargeType
TELEPORT,
WATERCAN,
WATERSKIN,
- DODGY_NECKLACE
+ DODGY_NECKLACE,
+ BINDING_NECKLACE
}
diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemWithSlot.java b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemWithSlot.java
index 3fbd2bac66..4ec4aa36be 100644
--- a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemWithSlot.java
+++ b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemWithSlot.java
@@ -34,6 +34,7 @@ enum ItemWithSlot
{
ABYSSAL_BRACELET(ItemChargeType.ABYSSAL_BRACELET, EquipmentInventorySlot.GLOVES),
DODGY_NECKLACE(ItemChargeType.DODGY_NECKLACE, EquipmentInventorySlot.AMULET),
+ BINDING_NECKLACE(ItemChargeType.BINDING_NECKLACE, EquipmentInventorySlot.AMULET),
TELEPORT(ItemChargeType.TELEPORT, EquipmentInventorySlot.WEAPON, EquipmentInventorySlot.AMULET, EquipmentInventorySlot.GLOVES, EquipmentInventorySlot.RING);
private final ItemChargeType type;