Repository: pajlads/DinkPlugin (java)

Issue:
Setting to skip virtual levels
I would like a setting to disable notifications for virtual levels (i.e. I only want notifications for levels 1-99).
This should probably be a simple checkbox, where the default value should 

Discussion points:
Should it be a positive checkbox? "Notify for virtual levels" where true would be default
Should it be a negative checkbox? "Skip virtual levels" where false would be default

Pull request:
feat: add setting to ignore virtual levels
Closes #121


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b6f8ddd..8abe9b4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,6 @@
 ## Unreleased
 
+- Minor: Add setting to skip virtual level notifications. (#122)
 - Minor: Update the README to be less confusing to users. (#123)
 - Minor: Update embed icons for level up and slayer task notifications. (#119)
 
diff --git a/src/main/java/dinkplugin/DinkPluginConfig.java b/src/main/java/dinkplugin/DinkPluginConfig.java
index 7a534da..13fd924 100644
--- a/src/main/java/dinkplugin/DinkPluginConfig.java
+++ b/src/main/java/dinkplugin/DinkPluginConfig.java
@@ -419,11 +419,22 @@ public interface DinkPluginConfig extends Config {
         return true;
     }
 
+    @ConfigItem(
+        keyName = "levelNotifyVirtual",
+        name = "Notify on Virtual Levels",
+        description = "Whether notifications should be fired beyond level 99",
+        position = 22,
+        section = levelSection
+    )
+    default boolean levelNotifyVirtual() {
+        return true;
+    }
+
     @ConfigItem(
         keyName = "levelInterval",
         name = "Notify Interval",
         description = "Interval between when a notification should be sent",
-        position = 22,
+        position = 23,
         section = levelSection
     )
     default int levelInterval() {
@@ -434,7 +445,7 @@ public interface DinkPluginConfig extends Config {
         keyName = "levelMinValue",
         name = "Minimum Skill Level",
         description = "The minimum skill level required to send a notification. Useful for filtering out low-level notifications",
-        position = 23,
+        position = 24,
         section = levelSection
     )
     default int levelMinValue() {
@@ -445,7 +456,7 @@ public interface DinkPluginConfig extends Config {
         keyName = "levelNotifMessage",
         name = "Notification Message",
         description = "The message to be sent through the webhook. Use %USERNAME% to insert your username and %SKILL% to insert the levelled skill(s)",
-        position = 24,
+        position = 25,
         section = levelSection
     )
     default String levelNotifyMessage() {
diff --git a/src/main/java/dinkplugin/notifiers/LevelNotifier.java b/src/main/java/dinkplugin/notifiers/LevelNotifier.java
index 7a2ac3e..2a8dce9 100644
--- a/src/main/java/dinkplugin/notifiers/LevelNotifier.java
+++ b/src/main/java/dinkplugin/notifiers/LevelNotifier.java
@@ -126,6 +126,8 @@ public class LevelNotifier extends BaseNotifier {
     private boolean checkLevelInterval(int level) {
         if (level < config.levelMinValue())
             return false;
+        if (level > 99 && !config.levelNotifyVirtual())
+            return false;
         int interval = config.levelInterval();
         return interval <= 1
             || level == 99


Test patch:
diff --git a/src/test/java/dinkplugin/notifiers/LevelNotifierTest.java b/src/test/java/dinkplugin/notifiers/LevelNotifierTest.java
index 42a88e6..88237a2 100644
--- a/src/test/java/dinkplugin/notifiers/LevelNotifierTest.java
+++ b/src/test/java/dinkplugin/notifiers/LevelNotifierTest.java
@@ -33,6 +33,7 @@ class LevelNotifierTest extends MockedNotifierTest {
         // init config mocks
         when(config.notifyLevel()).thenReturn(true);
         when(config.levelSendImage()).thenReturn(false);
+        when(config.levelNotifyVirtual()).thenReturn(true);
         when(config.levelInterval()).thenReturn(5);
         when(config.levelNotifyMessage()).thenReturn("%USERNAME% has levelled %SKILL%");
 
@@ -137,6 +138,21 @@ class LevelNotifierTest extends MockedNotifierTest {
         verify(messageHandler, never()).createMessage(any(), anyBoolean(), any());
     }
 
+    @Test
+    void testIgnoreVirtual() {
+        // update config mock
+        when(config.levelNotifyVirtual()).thenReturn(false);
+
+        // fire skill event
+        plugin.onStatChanged(new StatChanged(Skill.ATTACK, 15_000_000, 99, 100));
+
+        // let ticks pass
+        IntStream.range(0, 4).forEach(i -> notifier.onTick());
+
+        // ensure no notification occurred
+        verify(messageHandler, never()).createMessage(any(), anyBoolean(), any());
+    }
+
     @Test
     void testDisabled() {
         // disable notifier