Repository: pajlads/DinkPlugin (java)

Issue:
Death: 3 item icons posted on Death while no option to enable or disable this
**Dink version:** 1.1.2
When posting a death, 3 icons of certain items are posted below the screenshot, this also happens when the screenshot feature is off.

![Dink deaths 3 icons](https://user-images.githubusercontent.com/11279045/206911931-c77c5284-f480-45b2-957e-b6729748165d.png)

There's no option on the Deaths section to disable or enable this.

Pull request:
feat: add toggle for protected items on death embed
Closes #90


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b399851..8662e8b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
 ## Unreleased
 
 - Minor: Add better descriptions for `Min Value` settings. (#100)
+- Minor: Add death notifier setting to disable kept item embeds. (#99)
 - Minor: Add clue and loot notifier setting to skip screenshots for low item values. (#98)
 - Minor: Add level up setting to skip notifications below a specified level. (#97)
 - Minor: Retry failed webhook messages with exponential backoff. (#94)
diff --git a/src/main/java/dinkplugin/DinkPluginConfig.java b/src/main/java/dinkplugin/DinkPluginConfig.java
index 926bb3b..28dc926 100644
--- a/src/main/java/dinkplugin/DinkPluginConfig.java
+++ b/src/main/java/dinkplugin/DinkPluginConfig.java
@@ -488,11 +488,22 @@ public interface DinkPluginConfig extends Config {
         return false;
     }
 
+    @ConfigItem(
+        keyName = "deathEmbedProtected",
+        name = "Embed Kept Items",
+        description = "Whether embeds of the protected items should be sent to the webhook",
+        position = 42,
+        section = deathSection
+    )
+    default boolean deathEmbedKeptItems() {
+        return true;
+    }
+
     @ConfigItem(
         keyName = "deathNotifMessage",
         name = "Notification Message",
         description = "The message to be sent through the webhook. Use %USERNAME% to insert your username, %VALUELOST% to insert the GE value of the stuff you lost",
-        position = 42,
+        position = 43,
         section = deathSection
     )
     default String deathNotifyMessage() {
@@ -503,7 +514,7 @@ public interface DinkPluginConfig extends Config {
         keyName = "deathNotifPvpEnabled",
         name = "Distinguish PvP deaths",
         description = "Should the plugin use a different message for dying in PvP?",
-        position = 43,
+        position = 44,
         section = deathSection
     )
     default boolean deathNotifPvpEnabled() {
@@ -514,7 +525,7 @@ public interface DinkPluginConfig extends Config {
         keyName = "deathNotifPvpMessage",
         name = "PvP notification message",
         description = "The message to be sent through the webhook. Use %PKER% to insert the killer, %USERNAME% to insert your username, %VALUELOST% to insert the GE value of the stuff you lost",
-        position = 44,
+        position = 45,
         section = deathSection
     )
     default String deathNotifPvpMessage() {
diff --git a/src/main/java/dinkplugin/notifiers/DeathNotifier.java b/src/main/java/dinkplugin/notifiers/DeathNotifier.java
index 98e1f65..1850dea 100644
--- a/src/main/java/dinkplugin/notifiers/DeathNotifier.java
+++ b/src/main/java/dinkplugin/notifiers/DeathNotifier.java
@@ -26,6 +26,7 @@ import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -100,12 +101,23 @@ public class DeathNotifier extends BaseNotifier {
             .limit(3)
             .toArray();
 
-        List<NotificationBody.Embed> lostItemEmbeds = Utils.buildEmbeds(topLostItemIds);
         List<SerializedItemStack> topLostStacks = getTopLostStacks(itemManager, lostItems, topLostItemIds);
         List<SerializedItemStack> keptStacks = keptItems.stream()
             .map(Pair::getKey)
             .map(item -> Utils.stackFromItem(itemManager, item))
             .collect(Collectors.toList());
+        List<NotificationBody.Embed> keptItemEmbeds;
+        if (config.deathEmbedKeptItems()) {
+            keptItemEmbeds = Utils.buildEmbeds(
+                keptItems.stream()
+                    .map(Pair::getKey)
+                    .mapToInt(Item::getId)
+                    .distinct()
+                    .toArray()
+            );
+        } else {
+            keptItemEmbeds = Collections.emptyList();
+        }
 
         DeathNotificationData extra = new DeathNotificationData(
             losePrice,
@@ -118,7 +130,7 @@ public class DeathNotifier extends BaseNotifier {
         createMessage(config.deathSendImage(), NotificationBody.builder()
             .content(notifyMessage)
             .extra(extra)
-            .embeds(lostItemEmbeds)
+            .embeds(keptItemEmbeds)
             .screenshotFile("deathImage.png")
             .type(NotificationType.DEATH)
             .build());


Test patch:
diff --git a/src/test/java/dinkplugin/notifiers/DeathNotifierTest.java b/src/test/java/dinkplugin/notifiers/DeathNotifierTest.java
index 49621bc..d72e1d3 100644
--- a/src/test/java/dinkplugin/notifiers/DeathNotifierTest.java
+++ b/src/test/java/dinkplugin/notifiers/DeathNotifierTest.java
@@ -57,6 +57,7 @@ class DeathNotifierTest extends MockedNotifierTest {
         when(config.notifyDeath()).thenReturn(true);
         when(config.deathNotifPvpEnabled()).thenReturn(true);
         when(config.deathSendImage()).thenReturn(false);
+        when(config.deathEmbedKeptItems()).thenReturn(true);
         when(config.deathNotifyMessage()).thenReturn("%USERNAME% has died, losing %VALUELOST% gp");
         when(config.deathNotifPvpMessage()).thenReturn("%USERNAME% has been PKed by %PKER% for %VALUELOST% gp");
 
@@ -119,8 +120,11 @@ class DeathNotifierTest extends MockedNotifierTest {
         List<SerializedItemStack> lost = Collections.singletonList(
             new SerializedItemStack(ItemID.TUNA, 1, TUNA_PRICE, "Tuna")
         );
-        List<NotificationBody.Embed> embeds = Collections.singletonList(
-            new NotificationBody.Embed(new NotificationBody.UrlEmbed("https://static.runelite.net/cache/item/icon/" + ItemID.TUNA + ".png"))
+        List<NotificationBody.Embed> embeds = Arrays.asList(
+            new NotificationBody.Embed(new NotificationBody.UrlEmbed("https://static.runelite.net/cache/item/icon/" + ItemID.RUBY + ".png")),
+            new NotificationBody.Embed(new NotificationBody.UrlEmbed("https://static.runelite.net/cache/item/icon/" + ItemID.SHARK + ".png")),
+            new NotificationBody.Embed(new NotificationBody.UrlEmbed("https://static.runelite.net/cache/item/icon/" + ItemID.OPAL + ".png")),
+            new NotificationBody.Embed(new NotificationBody.UrlEmbed("https://static.runelite.net/cache/item/icon/" + ItemID.COAL + ".png"))
         );
         verify(messageHandler).createMessage(
             PRIMARY_WEBHOOK_URL,