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 5bc0e9e167..0e8a4569fe 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 @@ -1,6 +1,7 @@ /* * Copyright (c) 2017, Devin French * Copyright (c) 2019, Aleios + * Copyright (c) 2020, Unmoon * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -450,4 +451,22 @@ 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); } 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 d6f99539d3..fc91487230 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 @@ -1,6 +1,7 @@ /* * Copyright (c) 2017, Seth * Copyright (c) 2019, Aleios + * Copyright (c) 2020, Unmoon * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -115,6 +116,15 @@ class ItemChargeOverlay extends WidgetItemOverlay charges = config.amuletOfBounty(); } + else if (itemId == ItemID.CHRONICLE) + { + if (!config.showTeleportCharges()) + { + return; + } + + charges = config.chronicle(); + } else { ItemWithCharge chargeItem = ItemWithCharge.findItem(itemId); 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 651cc1185e..bc4ef469ef 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 @@ -2,6 +2,7 @@ * Copyright (c) 2017, Seth * Copyright (c) 2018, Hydrox6 * Copyright (c) 2019, Aleios + * Copyright (c) 2020, Unmoon * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -60,6 +61,7 @@ import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.infobox.InfoBoxManager; +import net.runelite.client.util.Text; @PluginDescriptor( name = "Item Charges", @@ -75,7 +77,7 @@ public class ItemChargePlugin extends Plugin "Your dodgy necklace protects you\\..*It has (\\d+) charges? left\\."); 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 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( @@ -84,23 +86,33 @@ public class ItemChargePlugin extends Plugin private static final Pattern RING_OF_FORGING_CHECK_PATTERN = Pattern.compile( "You can smelt ([0-9]+|one) more pieces? of iron ore before a ring melts\\."); private static final String RING_OF_FORGING_USED_TEXT = "You retrieve a bar of iron."; - private static final String RING_OF_FORGING_BREAK_TEXT = "Your Ring of Forging has melted."; + private static final String RING_OF_FORGING_BREAK_TEXT = "Your Ring of Forging has melted."; private static final Pattern AMULET_OF_CHEMISTRY_CHECK_PATTERN = Pattern.compile( "Your amulet of chemistry has (\\d) charges? left\\." ); private static final Pattern AMULET_OF_CHEMISTRY_USED_PATTERN = Pattern.compile( - "Your amulet of chemistry helps you create a \\d-dose potion\\. (?:)?It has (\\d|one) charges? left\\." + "Your amulet of chemistry helps you create a \\d-dose potion\\. It has (\\d|one) charges? left\\." ); private static final Pattern AMULET_OF_CHEMISTRY_BREAK_PATTERN = Pattern.compile( - "Your amulet of chemistry helps you create a \\d-dose potion\\. (?:)?It then crumbles to dust\\." + "Your amulet of chemistry helps you create a \\d-dose potion\\. It then crumbles to dust\\." ); private static final Pattern AMULET_OF_BOUNTY_CHECK_PATTERN = Pattern.compile( "Your amulet of bounty has (\\d+) charges? left\\." ); private static final Pattern AMULET_OF_BOUNTY_USED_PATTERN = Pattern.compile( - "Your amulet of bounty saves some seeds for you\\. (?:)?It has (\\d) charges? left\\." + "Your amulet of bounty saves some seeds for you\\. It has (\\d) charges? left\\." ); - private static final String AMULET_OF_BOUNTY_BREAK_TEXT = "Your amulet of bounty saves some seeds for you. It then crumbles to dust."; + private static final String AMULET_OF_BOUNTY_BREAK_TEXT = "Your amulet of bounty saves some seeds for you. It then crumbles to dust."; + private static final Pattern CHRONICLE_ADD_PATTERN = Pattern.compile( + "You add (?:\\d+|a single) charges? to your book\\. It now has (\\d+|one) charges?\\." + ); + private static final Pattern CHRONICLE_USE_AND_CHECK_PATTERN = Pattern.compile( + "Your book has (\\d+) charges left\\." + ); + private static final String CHRONICLE_FULL_TEXT = "Your book is fully charged! It has 1,000 charges already."; + private static final String CHRONICLE_ONE_CHARGE_TEXT = "You have one charge left in your book."; + private static final String CHRONICLE_EMPTY_TEXT = "Your book has run out of charges."; + private static final String CHRONICLE_NO_CHARGES_TEXT = "Your book does not have any charges. Purchase some Teleport Cards from Diango."; private static final int MAX_DODGY_CHARGES = 10; private static final int MAX_BINDING_CHARGES = 16; @@ -218,7 +230,7 @@ public class ItemChargePlugin extends Plugin { if (event.getType() == ChatMessageType.GAMEMESSAGE || event.getType() == ChatMessageType.SPAM) { - String message = event.getMessage(); + String message = Text.removeTags(event.getMessage()); Matcher dodgyCheckMatcher = DODGY_CHECK_PATTERN.matcher(message); Matcher dodgyProtectMatcher = DODGY_PROTECT_PATTERN.matcher(message); Matcher dodgyBreakMatcher = DODGY_BREAK_PATTERN.matcher(message); @@ -230,6 +242,8 @@ public class ItemChargePlugin extends Plugin Matcher amuletOfChemistryBreakMatcher = AMULET_OF_CHEMISTRY_BREAK_PATTERN.matcher(message); Matcher amuletOfBountyCheckMatcher = AMULET_OF_BOUNTY_CHECK_PATTERN.matcher(message); Matcher amuletOfBountyUsedMatcher = AMULET_OF_BOUNTY_USED_PATTERN.matcher(message); + Matcher chronicleAddMatcher = CHRONICLE_ADD_PATTERN.matcher(message); + Matcher chronicleUseAndCheckMatcher = CHRONICLE_USE_AND_CHECK_PATTERN.matcher(message); if (config.recoilNotification() && message.contains(RING_OF_RECOIL_BREAK_MESSAGE)) { @@ -346,6 +360,35 @@ public class ItemChargePlugin extends Plugin updateRingOfForgingCharges(MAX_RING_OF_FORGING_CHARGES); } + else if (chronicleAddMatcher.find()) + { + final String match = chronicleAddMatcher.group(1); + + if (match.equals("one")) + { + config.chronicle(1); + } + else + { + config.chronicle(Integer.parseInt(match)); + } + } + else if (chronicleUseAndCheckMatcher.find()) + { + config.chronicle(Integer.parseInt(chronicleUseAndCheckMatcher.group(1))); + } + else if (message.equals(CHRONICLE_ONE_CHARGE_TEXT)) + { + config.chronicle(1); + } + else if (message.equals(CHRONICLE_EMPTY_TEXT) || message.equals(CHRONICLE_NO_CHARGES_TEXT)) + { + config.chronicle(0); + } + else if (message.equals(CHRONICLE_FULL_TEXT)) + { + config.chronicle(1000); + } } } 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 b0bb7da687..a3f5fb7a78 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 @@ -1,5 +1,6 @@ /* * Copyright (c) 2017, Mitchell + * Copyright (c) 2020, Unmoon * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -42,5 +43,6 @@ enum ItemChargeType SACK, RING_OF_FORGING, GUTHIX_REST, + CHRONICLE, POTION, } 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 9af0327a04..c59741ac52 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 @@ -1,6 +1,7 @@ /* * Copyright (c) 2019, Tomas Slusny * Copyright (c) 2019, Aleios + * Copyright (c) 2020, Unmoon * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,6 +41,7 @@ enum ItemWithSlot 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; diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/itemcharges/ItemChargePluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/itemcharges/ItemChargePluginTest.java index 44694dfce8..42572e9006 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/itemcharges/ItemChargePluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/itemcharges/ItemChargePluginTest.java @@ -72,6 +72,18 @@ public class ItemChargePluginTest private static final String BREAK_AMULET_OF_CHEMISTRY_3_DOSES = "Your amulet of chemistry helps you create a 3-dose potion. It then crumbles to dust."; private static final String BREAK_AMULET_OF_CHEMISTRY_2_DOSES = "Your amulet of chemistry helps you create a 2-dose potion. It then crumbles to dust."; + private static final String CHRONICLE_CHECK_CHARGES_FULL = "Your book has 1000 charges left."; + private static final String CHRONICLE_CHECK_CHARGES_ONE = "You have one charge left in your book."; + private static final String CHRONICLE_CHECK_CHARGES_EMPTY = "Your book has run out of charges."; + private static final String CHRONICLE_TELEPORT = "Your book has 999 charges left."; + private static final String CHRONICLE_TELEPORT_ONE = "You have one charge left in your book."; + private static final String CHRONICLE_TELEPORT_EMPTY = "Your book has run out of charges."; + private static final String CHRONICLE_TELEPORT_FAIL = "Your book does not have any charges. Purchase some Teleport Cards from Diango."; + private static final String CHRONICLE_ADD_SINGLE_CHARGE = "You add a single charge to your book. It now has one charge."; + private static final String CHRONICLE_ADD_SINGLE_CHARGE_FULL = "You add a single charge to your book. It now has 1000 charges."; + private static final String CHRONICLE_ADD_MULTIPLE_CHARGES = "You add 5 charges to your book. It now has 5 charges."; + private static final String CHRONICLE_ADD_FULL = "Your book is fully charged! It has 1,000 charges already."; + @Mock @Bind private Client client; @@ -198,5 +210,59 @@ public class ItemChargePluginTest verify(config).amuletOfChemistry(eq(5)); reset(config); + chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_CHECK_CHARGES_FULL, "", 0); + itemChargePlugin.onChatMessage(chatMessage); + verify(config).chronicle(eq(1000)); + reset(config); + + chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_CHECK_CHARGES_ONE, "", 0); + itemChargePlugin.onChatMessage(chatMessage); + verify(config).chronicle(eq(1)); + reset(config); + + chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_CHECK_CHARGES_EMPTY, "", 0); + itemChargePlugin.onChatMessage(chatMessage); + verify(config).chronicle(eq(0)); + reset(config); + + chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_TELEPORT, "", 0); + itemChargePlugin.onChatMessage(chatMessage); + verify(config).chronicle(eq(999)); + reset(config); + + chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_TELEPORT_ONE, "", 0); + itemChargePlugin.onChatMessage(chatMessage); + verify(config).chronicle(eq(1)); + reset(config); + + chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_TELEPORT_EMPTY, "", 0); + itemChargePlugin.onChatMessage(chatMessage); + verify(config).chronicle(eq(0)); + reset(config); + + chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_TELEPORT_FAIL, "", 0); + itemChargePlugin.onChatMessage(chatMessage); + verify(config).chronicle(eq(0)); + reset(config); + + chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_ADD_SINGLE_CHARGE, "", 0); + itemChargePlugin.onChatMessage(chatMessage); + verify(config).chronicle(eq(1)); + reset(config); + + chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_ADD_SINGLE_CHARGE_FULL, "", 0); + itemChargePlugin.onChatMessage(chatMessage); + verify(config).chronicle(eq(1000)); + reset(config); + + chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_ADD_MULTIPLE_CHARGES, "", 0); + itemChargePlugin.onChatMessage(chatMessage); + verify(config).chronicle(eq(5)); + reset(config); + + chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHRONICLE_ADD_FULL, "", 0); + itemChargePlugin.onChatMessage(chatMessage); + verify(config).chronicle(eq(1000)); + reset(config); } } \ No newline at end of file