Repository: pajlads/DinkPlugin (java)

Issue:
Distinguish between killing/pickpocketing/misc
Currently no data is passed around if the loot was acquired via a kill, a pickpocket, or other miscellaneous acquisition.

Is it possible to include this additional information in "extra"?

Pull request description:
feat: include loot category in extra data
Closes #195


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 078ad6e..ebdfd7e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,6 @@
 ## Unreleased
 
+- Minor: Include loot source category in notification metadata. (#196)
 - Minor: Avoid death notifications for more safe activities: Barbarian Assault, Chambers of Xeric, Clan Wars, Last Man Standing, Nightmare Zone, Soul Wars, TzHaar Fight Pit. (#194)
 - Minor: Avoid unwarranted settings warnings when world hopping. (#183)
 - Minor: Include number of quest completions and quest points in quest notifications. (#178)
diff --git a/README.md b/README.md
index 6dba02f..e339fcf 100644
--- a/README.md
+++ b/README.md
@@ -247,7 +247,8 @@ Lastly, Dink makes exceptions for Inferno and TzHaar Fight Cave; deaths in these
         "name": "Some item"
       }
     ],
-    "source": "Giant rat"
+    "source": "Giant rat",
+    "category": "NPC"
   },
   "type": "LOOT"
 }
diff --git a/src/main/java/dinkplugin/notifiers/LootNotifier.java b/src/main/java/dinkplugin/notifiers/LootNotifier.java
index d91fd40..bc47be2 100644
--- a/src/main/java/dinkplugin/notifiers/LootNotifier.java
+++ b/src/main/java/dinkplugin/notifiers/LootNotifier.java
@@ -50,7 +50,7 @@ public class LootNotifier extends BaseNotifier {
 
     public void onNpcLootReceived(NpcLootReceived event) {
         if (isEnabled())
-            this.handleNotify(event.getItems(), event.getNpc().getName());
+            this.handleNotify(event.getItems(), event.getNpc().getName(), LootRecordType.NPC);
     }
 
     public void onPlayerLootReceived(PlayerLootReceived event) {
@@ -58,7 +58,7 @@ public class LootNotifier extends BaseNotifier {
             return;
 
         if (config.includePlayerLoot() && isEnabled())
-            this.handleNotify(event.getItems(), event.getPlayer().getName());
+            this.handleNotify(event.getItems(), event.getPlayer().getName(), LootRecordType.PLAYER);
     }
 
     public void onLootReceived(LootReceived lootReceived) {
@@ -71,7 +71,7 @@ public class LootNotifier extends BaseNotifier {
                 return;
             }
 
-            this.handleNotify(lootReceived.getItems(), lootReceived.getName());
+            this.handleNotify(lootReceived.getItems(), lootReceived.getName(), lootReceived.getType());
         }
     }
 
@@ -90,7 +90,7 @@ public class LootNotifier extends BaseNotifier {
                             1,
                             client.getLocalPlayer().getLocalLocation()
                         );
-                        this.handleNotify(Collections.singletonList(item), "The Font of Consumption");
+                        this.handleNotify(Collections.singletonList(item), "The Font of Consumption", LootRecordType.EVENT);
                     } else {
                         Widget widget = client.getWidget(WidgetInfo.DIALOG_SPRITE);
                         log.warn(
@@ -106,7 +106,7 @@ public class LootNotifier extends BaseNotifier {
         }
     }
 
-    private void handleNotify(Collection<ItemStack> items, String dropper) {
+    private void handleNotify(Collection<ItemStack> items, String dropper, LootRecordType type) {
         final int minValue = config.minLootValue();
         final boolean icons = config.lootIcons();
 
@@ -142,7 +142,7 @@ public class LootNotifier extends BaseNotifier {
                 NotificationBody.builder()
                     .text(notifyMessage)
                     .embeds(embeds)
-                    .extra(new LootNotificationData(serializedItems, dropper))
+                    .extra(new LootNotificationData(serializedItems, dropper, type))
                     .type(NotificationType.LOOT)
                     .build()
             );
diff --git a/src/main/java/dinkplugin/notifiers/data/LootNotificationData.java b/src/main/java/dinkplugin/notifiers/data/LootNotificationData.java
index c6aca0f..599ba2e 100644
--- a/src/main/java/dinkplugin/notifiers/data/LootNotificationData.java
+++ b/src/main/java/dinkplugin/notifiers/data/LootNotificationData.java
@@ -4,6 +4,7 @@ import dinkplugin.message.Field;
 import dinkplugin.util.ItemUtils;
 import lombok.EqualsAndHashCode;
 import lombok.Value;
+import net.runelite.http.api.loottracker.LootRecordType;
 
 import java.util.Collections;
 import java.util.List;
@@ -13,6 +14,7 @@ import java.util.List;
 public class LootNotificationData extends NotificationData {
     List<SerializedItemStack> items;
     String source;
+    LootRecordType category;
 
     @Override
     public List<Field> getFields() {


Test patch:
diff --git a/src/test/java/dinkplugin/notifiers/LootNotifierTest.java b/src/test/java/dinkplugin/notifiers/LootNotifierTest.java
index aa0d8ac..757c64b 100644
--- a/src/test/java/dinkplugin/notifiers/LootNotifierTest.java
+++ b/src/test/java/dinkplugin/notifiers/LootNotifierTest.java
@@ -85,7 +85,7 @@ class LootNotifierTest extends MockedNotifierTest {
             false,
             NotificationBody.builder()
                 .text(String.format("%s has looted: %s from %s for %d gp", PLAYER_NAME, "1 x Ruby (" + RUBY_PRICE + ")", name, RUBY_PRICE))
-                .extra(new LootNotificationData(Collections.singletonList(new SerializedItemStack(ItemID.RUBY, 1, RUBY_PRICE, "Ruby")), name))
+                .extra(new LootNotificationData(Collections.singletonList(new SerializedItemStack(ItemID.RUBY, 1, RUBY_PRICE, "Ruby")), name, LootRecordType.NPC))
                 .type(NotificationType.LOOT)
                 .build()
         );
@@ -117,7 +117,7 @@ class LootNotifierTest extends MockedNotifierTest {
             false,
             NotificationBody.builder()
                 .text(String.format("%s has looted: %s from %s for %d gp", PLAYER_NAME, "1 x Ruby (" + RUBY_PRICE + ")", LOOTED_NAME, RUBY_PRICE))
-                .extra(new LootNotificationData(Collections.singletonList(new SerializedItemStack(ItemID.RUBY, 1, RUBY_PRICE, "Ruby")), LOOTED_NAME))
+                .extra(new LootNotificationData(Collections.singletonList(new SerializedItemStack(ItemID.RUBY, 1, RUBY_PRICE, "Ruby")), LOOTED_NAME, LootRecordType.PICKPOCKET))
                 .type(NotificationType.LOOT)
                 .build()
         );
@@ -146,7 +146,7 @@ class LootNotifierTest extends MockedNotifierTest {
             false,
             NotificationBody.builder()
                 .text(String.format("%s has looted: %s from %s for %d gp", PLAYER_NAME, "1 x Ruby (" + RUBY_PRICE + ")", source, RUBY_PRICE))
-                .extra(new LootNotificationData(Collections.singletonList(new SerializedItemStack(ItemID.RUBY, 1, RUBY_PRICE, "Ruby")), source))
+                .extra(new LootNotificationData(Collections.singletonList(new SerializedItemStack(ItemID.RUBY, 1, RUBY_PRICE, "Ruby")), source, LootRecordType.EVENT))
                 .type(NotificationType.LOOT)
                 .build()
         );
@@ -181,7 +181,7 @@ class LootNotifierTest extends MockedNotifierTest {
             false,
             NotificationBody.builder()
                 .text(String.format("%s has looted: %s from %s for %s gp", PLAYER_NAME, "1 x Ruby (" + RUBY_PRICE + ")", LOOTED_NAME, QuantityFormatter.quantityToStackSize(RUBY_PRICE + TUNA_PRICE)))
-                .extra(new LootNotificationData(Arrays.asList(new SerializedItemStack(ItemID.RUBY, 1, RUBY_PRICE, "Ruby"), new SerializedItemStack(ItemID.TUNA, 1, TUNA_PRICE, "Tuna")), LOOTED_NAME))
+                .extra(new LootNotificationData(Arrays.asList(new SerializedItemStack(ItemID.RUBY, 1, RUBY_PRICE, "Ruby"), new SerializedItemStack(ItemID.TUNA, 1, TUNA_PRICE, "Tuna")), LOOTED_NAME, LootRecordType.PLAYER))
                 .type(NotificationType.LOOT)
                 .build()
         );
@@ -226,7 +226,7 @@ class LootNotifierTest extends MockedNotifierTest {
             false,
             NotificationBody.builder()
                 .text(String.format("%s has looted: %s from %s for %s gp", PLAYER_NAME, loot, LOOTED_NAME, QuantityFormatter.quantityToStackSize(total)))
-                .extra(new LootNotificationData(Arrays.asList(new SerializedItemStack(ItemID.RUBY, 1, RUBY_PRICE, "Ruby"), new SerializedItemStack(ItemID.OPAL, 1, OPAL_PRICE, "Opal"), new SerializedItemStack(ItemID.TUNA, 1, TUNA_PRICE, "Tuna")), LOOTED_NAME))
+                .extra(new LootNotificationData(Arrays.asList(new SerializedItemStack(ItemID.RUBY, 1, RUBY_PRICE, "Ruby"), new SerializedItemStack(ItemID.OPAL, 1, OPAL_PRICE, "Opal"), new SerializedItemStack(ItemID.TUNA, 1, TUNA_PRICE, "Tuna")), LOOTED_NAME, LootRecordType.EVENT))
                 .type(NotificationType.LOOT)
                 .build()
         );
@@ -258,7 +258,7 @@ class LootNotifierTest extends MockedNotifierTest {
             false,
             NotificationBody.builder()
                 .text(String.format("%s has looted: %s from %s for %s gp", PLAYER_NAME, loot, LOOTED_NAME, QuantityFormatter.quantityToStackSize(total)))
-                .extra(new LootNotificationData(Collections.singletonList(new SerializedItemStack(ItemID.TUNA, 5, TUNA_PRICE, "Tuna")), LOOTED_NAME))
+                .extra(new LootNotificationData(Collections.singletonList(new SerializedItemStack(ItemID.TUNA, 5, TUNA_PRICE, "Tuna")), LOOTED_NAME, LootRecordType.EVENT))
                 .type(NotificationType.LOOT)
                 .build()
         );
@@ -290,7 +290,7 @@ class LootNotifierTest extends MockedNotifierTest {
             false,
             NotificationBody.builder()
                 .text(String.format("%s has looted: %s from %s for %s gp", PLAYER_NAME, "1 x Abyssal Whip (" + formattedPrice + ")", source, formattedPrice))
-                .extra(new LootNotificationData(Collections.singletonList(new SerializedItemStack(ItemID.ABYSSAL_WHIP, 1, whipPrice, "Abyssal Whip")), source))
+                .extra(new LootNotificationData(Collections.singletonList(new SerializedItemStack(ItemID.ABYSSAL_WHIP, 1, whipPrice, "Abyssal Whip")), source, LootRecordType.EVENT))
                 .type(NotificationType.LOOT)
                 .build()
         );