cannon plugin: make ammo notification threshold configurable
Co-authored-by: Lucas Childers <LucasChilders@users.noreply.github.com> Co-authored-by: redrumyliad <jzomerlei@gmail.com>
This commit is contained in:
@@ -29,24 +29,42 @@ import net.runelite.client.config.Alpha;
|
|||||||
import net.runelite.client.config.Config;
|
import net.runelite.client.config.Config;
|
||||||
import net.runelite.client.config.ConfigGroup;
|
import net.runelite.client.config.ConfigGroup;
|
||||||
import net.runelite.client.config.ConfigItem;
|
import net.runelite.client.config.ConfigItem;
|
||||||
|
import net.runelite.client.config.Range;
|
||||||
|
import static net.runelite.client.plugins.cannon.CannonPlugin.MAX_CBALLS;
|
||||||
|
|
||||||
@ConfigGroup("cannon")
|
@ConfigGroup("cannon")
|
||||||
public interface CannonConfig extends Config
|
public interface CannonConfig extends Config
|
||||||
{
|
{
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
keyName = "showEmptyCannonNotification",
|
keyName = "showEmptyCannonNotification",
|
||||||
name = "Empty cannon notification",
|
name = "Enable cannon notifications",
|
||||||
description = "Configures whether to notify you that the cannon is empty"
|
description = "Configures whether to notify you when your cannon is low on cannonballs",
|
||||||
|
position = 1
|
||||||
)
|
)
|
||||||
default boolean showEmptyCannonNotification()
|
default boolean showCannonNotifications()
|
||||||
{
|
{
|
||||||
return true;
|
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. <br>Regardless of this value, a notification will still be sent when your cannon is empty.",
|
||||||
|
position = 2
|
||||||
|
)
|
||||||
|
default int lowWarningThreshold()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
keyName = "showInfobox",
|
keyName = "showInfobox",
|
||||||
name = "Show Cannonball infobox",
|
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()
|
default boolean showInfobox()
|
||||||
{
|
{
|
||||||
@@ -56,7 +74,8 @@ public interface CannonConfig extends Config
|
|||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
keyName = "showDoubleHitSpot",
|
keyName = "showDoubleHitSpot",
|
||||||
name = "Show double hit spots",
|
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()
|
default boolean showDoubleHitSpot()
|
||||||
{
|
{
|
||||||
@@ -67,7 +86,8 @@ public interface CannonConfig extends Config
|
|||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
keyName = "highlightDoubleHitColor",
|
keyName = "highlightDoubleHitColor",
|
||||||
name = "Color of double hit spots",
|
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()
|
default Color highlightDoubleHitColor()
|
||||||
{
|
{
|
||||||
@@ -77,7 +97,8 @@ public interface CannonConfig extends Config
|
|||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
keyName = "showCannonSpots",
|
keyName = "showCannonSpots",
|
||||||
name = "Show common cannon spots",
|
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()
|
default boolean showCannonSpots()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -71,10 +71,11 @@ import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
|||||||
public class CannonPlugin extends Plugin
|
public class CannonPlugin extends Plugin
|
||||||
{
|
{
|
||||||
private static final Pattern NUMBER_PATTERN = Pattern.compile("([0-9]+)");
|
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 CannonCounter counter;
|
||||||
private boolean skipProjectileCheckThisTick;
|
private boolean skipProjectileCheckThisTick;
|
||||||
|
private boolean cannonBallNotificationSent;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private int cballsLeft;
|
private int cballsLeft;
|
||||||
@@ -139,6 +140,7 @@ public class CannonPlugin extends Plugin
|
|||||||
overlayManager.remove(cannonSpotOverlay);
|
overlayManager.remove(cannonSpotOverlay);
|
||||||
cannonPlaced = false;
|
cannonPlaced = false;
|
||||||
cannonPosition = null;
|
cannonPosition = null;
|
||||||
|
cannonBallNotificationSent = false;
|
||||||
cballsLeft = 0;
|
cballsLeft = 0;
|
||||||
removeCounter();
|
removeCounter();
|
||||||
skipProjectileCheckThisTick = false;
|
skipProjectileCheckThisTick = false;
|
||||||
@@ -275,6 +277,12 @@ public class CannonPlugin extends Plugin
|
|||||||
if (!skipProjectileCheckThisTick)
|
if (!skipProjectileCheckThisTick)
|
||||||
{
|
{
|
||||||
cballsLeft--;
|
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++;
|
cballsLeft++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cannonBallNotificationSent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getMessage().contains("Your cannon is out of ammo!"))
|
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.
|
// extra check is a good idea.
|
||||||
cballsLeft = 0;
|
cballsLeft = 0;
|
||||||
|
|
||||||
if (config.showEmptyCannonNotification())
|
if (config.showCannonNotifications())
|
||||||
{
|
{
|
||||||
notifier.notify("Your cannon is out of ammo!");
|
notifier.notify("Your cannon is out of ammo!");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user