Repository: pajlads/DinkPlugin
Pull request #82 (2022-12-04 02:39:27)

feat: add loot notifier option to skip player loot
Add a setting for loot notifier to ignore player loot events


Felanbird: Does it make sense to just say PvP loot?

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2a83bb5..295acd7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,7 @@
 ## Unreleased
 
+- Minor: Add loot notifier setting to ignore player loot. (#82)
+
 ## 1.1.1
 
 - Minor: Use notifier-specific screenshot filenames. (#79)
diff --git a/src/main/java/dinkplugin/DinkPluginConfig.java b/src/main/java/dinkplugin/DinkPluginConfig.java
index dbcc9a5..7fc2d85 100644
--- a/src/main/java/dinkplugin/DinkPluginConfig.java
+++ b/src/main/java/dinkplugin/DinkPluginConfig.java
@@ -400,11 +400,22 @@ public interface DinkPluginConfig extends Config {
         return 0;
     }
 
+    @ConfigItem(
+        keyName = "lootIncludePlayer",
+        name = "Include PK Loot",
+        description = "Allow notifications for loot from player kills",
+        position = 34,
+        section = lootSection
+    )
+    default boolean includePlayerLoot() {
+        return true;
+    }
+
     @ConfigItem(
         keyName = "lootNotifMessage",
         name = "Notification Message",
         description = "The message to be sent through the webhook. Use %USERNAME% to insert your username, %LOOT% to insert the loot and %SOURCE% to show the source of the loot",
-        position = 34,
+        position = 35,
         section = lootSection
     )
     default String lootNotifyMessage() {
diff --git a/src/main/java/dinkplugin/Utils.java b/src/main/java/dinkplugin/Utils.java
index 2029e48..f8de8bd 100644
--- a/src/main/java/dinkplugin/Utils.java
+++ b/src/main/java/dinkplugin/Utils.java
@@ -44,7 +44,9 @@ public class Utils {
 
     private static final Set<WorldType> IGNORED_WORLDS = EnumSet.of(WorldType.PVP_ARENA, WorldType.QUEST_SPEEDRUNNING, WorldType.NOSAVE_MODE, WorldType.TOURNAMENT_WORLD);
 
+    private static final Set<Integer> LMS_REGIONS = ImmutableSet.of(13658, 13659, 13660, 13914, 13915, 13916, 13918, 13919, 13920, 14174, 14175, 14176, 14430, 14431, 14432);
     private static final Set<Integer> POH_REGIONS = ImmutableSet.of(7257, 7513, 7514, 7769, 7770, 8025, 8026);
+    private static final Set<Integer> SOUL_REGIONS = ImmutableSet.of(8493, 8749, 9005);
 
     private static final BinaryOperator<Item> SUM_ITEM_QUANTITIES = (a, b) -> new Item(a.getId(), a.getQuantity() + b.getQuantity());
     private static final BinaryOperator<ItemStack> SUM_ITEM_STACK_QUANTITIES = (a, b) -> new ItemStack(a.getId(), a.getQuantity() + b.getQuantity(), a.getLocation());
@@ -101,6 +103,10 @@ public class Utils {
         return client.getVarbitValue(CASTLE_WARS_COUNTDOWN) > 0 || client.getVarbitValue(CASTLE_WARS_CATAPULT_X_AXIS_OFFSET) > 0 || client.getVarbitValue(CASTLE_WARS_CATAPULT_Y_AXIS_OFFSET) > 0;
     }
 
+    public static boolean isLastManStanding(Client client) {
+        return LMS_REGIONS.contains(client.getLocalPlayer().getWorldLocation().getRegionID());
+    }
+
     public static boolean isPestControl(Client client) {
         Widget widget = client.getWidget(WidgetInfo.PEST_CONTROL_BLUE_SHIELD);
         return widget != null;
@@ -114,6 +120,10 @@ public class Utils {
         return isCastleWars(client) || isPestControl(client) || isPlayerOwnedHouse(client);
     }
 
+    public static boolean isSoulWars(Client client) {
+        return SOUL_REGIONS.contains(client.getLocalPlayer().getWorldLocation().getRegionID());
+    }
+
     public static String getPlayerName(Client client) {
         return client.getLocalPlayer().getName();
     }
diff --git a/src/main/java/dinkplugin/notifiers/LootNotifier.java b/src/main/java/dinkplugin/notifiers/LootNotifier.java
index a7ae207..b4fb807 100644
--- a/src/main/java/dinkplugin/notifiers/LootNotifier.java
+++ b/src/main/java/dinkplugin/notifiers/LootNotifier.java
@@ -42,8 +42,10 @@ public class LootNotifier extends BaseNotifier {
     }
 
     public void onPlayerLootReceived(PlayerLootReceived event) {
-        // TODO: player loot should be a configurable toggle
-        if (isEnabled())
+        if (Utils.isCastleWars(client) || Utils.isLastManStanding(client) || Utils.isSoulWars(client))
+            return;
+
+        if (config.includePlayerLoot() && isEnabled())
             this.handleNotify(event.getItems(), event.getPlayer().getName());
     }
 


Test patch:
diff --git a/src/test/java/dinkplugin/notifiers/LootNotifierTest.java b/src/test/java/dinkplugin/notifiers/LootNotifierTest.java
index ed1e8e1..4993768 100644
--- a/src/test/java/dinkplugin/notifiers/LootNotifierTest.java
+++ b/src/test/java/dinkplugin/notifiers/LootNotifierTest.java
@@ -8,6 +8,7 @@ import dinkplugin.notifiers.data.SerializedItemStack;
 import net.runelite.api.ItemID;
 import net.runelite.api.NPC;
 import net.runelite.api.Player;
+import net.runelite.api.coords.WorldPoint;
 import net.runelite.client.events.NpcLootReceived;
 import net.runelite.client.events.PlayerLootReceived;
 import net.runelite.client.game.ItemManager;
@@ -54,8 +55,13 @@ class LootNotifierTest extends MockedNotifierTest {
         when(config.lootSendImage()).thenReturn(false);
         when(config.lootIcons()).thenReturn(false);
         when(config.minLootValue()).thenReturn(500);
+        when(config.includePlayerLoot()).thenReturn(true);
         when(config.lootNotifyMessage()).thenReturn("%USERNAME% has looted: %LOOT% from %SOURCE% for %TOTAL_VALUE% gp");
 
+        // init client mocks
+        WorldPoint location = new WorldPoint(0, 0, 0);
+        when(localPlayer.getWorldLocation()).thenReturn(location);
+
         // init item mocks
         mockItem(itemManager, ItemID.RUBY, RUBY_PRICE, "Ruby");
         mockItem(itemManager, ItemID.OPAL, OPAL_PRICE, "Opal");
@@ -149,6 +155,21 @@ class LootNotifierTest extends MockedNotifierTest {
         );
     }
 
+    @Test
+    void testIgnorePlayer() {
+        // prepare mocks
+        Player player = mock(Player.class);
+        when(player.getName()).thenReturn(LOOTED_NAME);
+        when(config.includePlayerLoot()).thenReturn(false);
+
+        // fire event
+        PlayerLootReceived event = new PlayerLootReceived(player, Arrays.asList(new ItemStack(ItemID.RUBY, 1, null), new ItemStack(ItemID.TUNA, 1, null)));
+        notifier.onPlayerLootReceived(event);
+
+        // ensure no notification
+        verify(messageHandler, never()).createMessage(any(), anyBoolean(), any());
+    }
+
     @Test
     void testNotifyMultiple() {
         // fire event