diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonConfig.java index 29a1496f85..05ba93da2e 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonConfig.java @@ -29,24 +29,42 @@ import net.runelite.client.config.Alpha; import net.runelite.client.config.Config; import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigItem; +import net.runelite.client.config.Range; +import static net.runelite.client.plugins.cannon.CannonPlugin.MAX_CBALLS; @ConfigGroup("cannon") public interface CannonConfig extends Config { @ConfigItem( keyName = "showEmptyCannonNotification", - name = "Empty cannon notification", - description = "Configures whether to notify you that the cannon is empty" + name = "Enable cannon notifications", + description = "Configures whether to notify you when your cannon is low on cannonballs", + position = 1 ) - default boolean showEmptyCannonNotification() + default boolean showCannonNotifications() { return true; } + @Range( + max = MAX_CBALLS + ) + @ConfigItem( + keyName = "lowWarningThreshold", + name = "Low Warning Threshold", + description = "Configures the number of cannonballs remaining before a notification is sent.
Regardless of this value, a notification will still be sent when your cannon is empty.", + position = 2 + ) + default int lowWarningThreshold() + { + return 0; + } + @ConfigItem( keyName = "showInfobox", name = "Show Cannonball infobox", - description = "Configures whether to show the cannonballs in an infobox" + description = "Configures whether to show the cannonballs in an infobox", + position = 3 ) default boolean showInfobox() { @@ -56,7 +74,8 @@ public interface CannonConfig extends Config @ConfigItem( keyName = "showDoubleHitSpot", name = "Show double hit spots", - description = "Configures whether to show the NPC double hit spot" + description = "Configures whether to show the NPC double hit spot", + position = 4 ) default boolean showDoubleHitSpot() { @@ -67,7 +86,8 @@ public interface CannonConfig extends Config @ConfigItem( keyName = "highlightDoubleHitColor", name = "Color of double hit spots", - description = "Configures the highlight color of double hit spots" + description = "Configures the highlight color of double hit spots", + position = 5 ) default Color highlightDoubleHitColor() { @@ -77,7 +97,8 @@ public interface CannonConfig extends Config @ConfigItem( keyName = "showCannonSpots", name = "Show common cannon spots", - description = "Configures whether to show common cannon spots or not" + description = "Configures whether to show common cannon spots or not", + position = 6 ) default boolean showCannonSpots() { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonPlugin.java index 6462b89e7f..39bcc3b01c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonPlugin.java @@ -71,10 +71,11 @@ import net.runelite.client.ui.overlay.infobox.InfoBoxManager; public class CannonPlugin extends Plugin { private static final Pattern NUMBER_PATTERN = Pattern.compile("([0-9]+)"); - private static final int MAX_CBALLS = 30; + static final int MAX_CBALLS = 30; private CannonCounter counter; private boolean skipProjectileCheckThisTick; + private boolean cannonBallNotificationSent; @Getter private int cballsLeft; @@ -139,6 +140,7 @@ public class CannonPlugin extends Plugin overlayManager.remove(cannonSpotOverlay); cannonPlaced = false; cannonPosition = null; + cannonBallNotificationSent = false; cballsLeft = 0; removeCounter(); skipProjectileCheckThisTick = false; @@ -275,6 +277,12 @@ public class CannonPlugin extends Plugin if (!skipProjectileCheckThisTick) { cballsLeft--; + + if (config.showCannonNotifications() && !cannonBallNotificationSent && cballsLeft > 0 && config.lowWarningThreshold() >= cballsLeft) + { + notifier.notify(String.format("Your cannon has %d cannon balls remaining!", cballsLeft)); + cannonBallNotificationSent = true; + } } } } @@ -338,6 +346,8 @@ public class CannonPlugin extends Plugin cballsLeft++; } } + + cannonBallNotificationSent = false; } if (event.getMessage().contains("Your cannon is out of ammo!")) @@ -349,7 +359,7 @@ public class CannonPlugin extends Plugin // extra check is a good idea. cballsLeft = 0; - if (config.showEmptyCannonNotification()) + if (config.showCannonNotifications()) { notifier.notify("Your cannon is out of ammo!"); }