From eb96a488e41449840d61489d2100b44475286f53 Mon Sep 17 00:00:00 2001 From: Tom Bolks Date: Sat, 12 Nov 2022 22:11:57 +0100 Subject: [PATCH 1/6] Fixed death notifcation when monster dies and has same name as the player. --- src/main/java/universalDiscord/notifiers/DeathNotifier.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/universalDiscord/notifiers/DeathNotifier.java b/src/main/java/universalDiscord/notifiers/DeathNotifier.java index 1f27b8b..688115e 100644 --- a/src/main/java/universalDiscord/notifiers/DeathNotifier.java +++ b/src/main/java/universalDiscord/notifiers/DeathNotifier.java @@ -1,5 +1,6 @@ package universalDiscord.notifiers; +import net.runelite.api.Player; import net.runelite.api.events.ActorDeath; import universalDiscord.UniversalDiscordPlugin; import universalDiscord.Utils; @@ -30,7 +31,8 @@ public void handleNotify() { public boolean shouldNotify() { return isEnabled() && lastActorDeath != null - && Objects.equals(lastActorDeath.getActor().getName(), Utils.getPlayerName()); + && lastActorDeath.getActor() instanceof Player + && Objects.equals(((Player) lastActorDeath.getActor()).getId(), plugin.client.getLocalPlayer().getId()); } @Override From 937d5ab6f69a69b2cde5828beca44bee51a7b08d Mon Sep 17 00:00:00 2001 From: Tom Bolks Date: Sat, 12 Nov 2022 22:35:41 +0100 Subject: [PATCH 2/6] moved some logic to it's own function --- .../universalDiscord/notifiers/DeathNotifier.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/universalDiscord/notifiers/DeathNotifier.java b/src/main/java/universalDiscord/notifiers/DeathNotifier.java index 688115e..860e9cd 100644 --- a/src/main/java/universalDiscord/notifiers/DeathNotifier.java +++ b/src/main/java/universalDiscord/notifiers/DeathNotifier.java @@ -30,9 +30,16 @@ public void handleNotify() { @Override public boolean shouldNotify() { return isEnabled() - && lastActorDeath != null - && lastActorDeath.getActor() instanceof Player - && Objects.equals(((Player) lastActorDeath.getActor()).getId(), plugin.client.getLocalPlayer().getId()); + && lastActorDeathIsLocalPlayer(); + } + + public boolean lastActorDeathIsLocalPlayer() { + if (lastActorDeath != null && lastActorDeath.getActor() instanceof Player) { + Player lastPlayerDeath = (Player) lastActorDeath.getActor(); + return Objects.equals(lastPlayerDeath.getId(), plugin.client.getLocalPlayer().getId()); + } + + return false; } @Override From 62d9ddf8116e54b3475b618643797ed9c956f609 Mon Sep 17 00:00:00 2001 From: Tom Bolks Date: Sat, 12 Nov 2022 22:42:18 +0100 Subject: [PATCH 3/6] Reduced the code a bit. --- src/main/java/universalDiscord/notifiers/DeathNotifier.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/universalDiscord/notifiers/DeathNotifier.java b/src/main/java/universalDiscord/notifiers/DeathNotifier.java index 860e9cd..4e95224 100644 --- a/src/main/java/universalDiscord/notifiers/DeathNotifier.java +++ b/src/main/java/universalDiscord/notifiers/DeathNotifier.java @@ -34,9 +34,8 @@ public boolean shouldNotify() { } public boolean lastActorDeathIsLocalPlayer() { - if (lastActorDeath != null && lastActorDeath.getActor() instanceof Player) { - Player lastPlayerDeath = (Player) lastActorDeath.getActor(); - return Objects.equals(lastPlayerDeath.getId(), plugin.client.getLocalPlayer().getId()); + if (lastActorDeath != null) { + return Objects.equals(lastActorDeath.getActor(), plugin.client.getLocalPlayer()); } return false; From b9aa32bf314bbee2b12194472f2b8dcef885ec15 Mon Sep 17 00:00:00 2001 From: Tom Bolks Date: Sat, 12 Nov 2022 23:05:34 +0100 Subject: [PATCH 4/6] Added config option to select a thumbnail for when player dies. --- src/main/java/universalDiscord/DeathThumbnail.java | 14 ++++++++++++++ .../universalDiscord/UniversalDiscordConfig.java | 13 ++++++++++++- .../universalDiscord/notifiers/DeathNotifier.java | 10 ++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/main/java/universalDiscord/DeathThumbnail.java diff --git a/src/main/java/universalDiscord/DeathThumbnail.java b/src/main/java/universalDiscord/DeathThumbnail.java new file mode 100644 index 0000000..faa109b --- /dev/null +++ b/src/main/java/universalDiscord/DeathThumbnail.java @@ -0,0 +1,14 @@ +package universalDiscord; + +public enum DeathThumbnail { + NONE(null), + DEATH("https://oldschool.runescape.wiki/images/Death.png"), + GRAVE("https://oldschool.runescape.wiki/images/Grave.png"), + ANGEL_GRAVE("https://oldschool.runescape.wiki/images/Grave_%28Angel%29.png"); + + public final String thumbnailUrl; + + DeathThumbnail(String thumbnailUrl) { + this.thumbnailUrl = thumbnailUrl; + } +} diff --git a/src/main/java/universalDiscord/UniversalDiscordConfig.java b/src/main/java/universalDiscord/UniversalDiscordConfig.java index 81e8d8e..12a9971 100644 --- a/src/main/java/universalDiscord/UniversalDiscordConfig.java +++ b/src/main/java/universalDiscord/UniversalDiscordConfig.java @@ -249,11 +249,22 @@ default boolean notifyDeath() { return false; } + @ConfigItem( + keyName = "deathThumbnail", + name = "Thumbnail to use", + description = "Send a thumbnail with the notification", + position = 2, + section = deathSection + ) + default DeathThumbnail deathThumbnail() { + return DeathThumbnail.DEATH; + } + @ConfigItem( keyName = "deathSendImage", name = "Send Image", description = "Send image with the notification", - position = 2, + position = 3, section = deathSection ) default boolean deathSendImage() { diff --git a/src/main/java/universalDiscord/notifiers/DeathNotifier.java b/src/main/java/universalDiscord/notifiers/DeathNotifier.java index 4e95224..5333e77 100644 --- a/src/main/java/universalDiscord/notifiers/DeathNotifier.java +++ b/src/main/java/universalDiscord/notifiers/DeathNotifier.java @@ -2,9 +2,11 @@ import net.runelite.api.Player; import net.runelite.api.events.ActorDeath; +import universalDiscord.DeathThumbnail; import universalDiscord.UniversalDiscordPlugin; import universalDiscord.Utils; import universalDiscord.message.MessageBuilder; +import universalDiscord.message.discord.Image; import javax.inject.Inject; import java.util.Objects; @@ -22,6 +24,10 @@ public void handleNotify() { String notifyMessage = Utils.replaceCommonPlaceholders(plugin.config.deathNotifyMessage()); MessageBuilder messageBuilder = MessageBuilder.textAsEmbed(notifyMessage, plugin.config.deathSendImage()); + String thumbnailUrl = deathThumbNail().thumbnailUrl; + if (thumbnailUrl != null) { + messageBuilder.webhookBody.getEmbeds().stream().findFirst().ifPresent((embed -> embed.setThumbnail(new Image(thumbnailUrl)))); + } plugin.messageHandler.sendMessage(messageBuilder); reset(); @@ -41,6 +47,10 @@ public boolean lastActorDeathIsLocalPlayer() { return false; } + public DeathThumbnail deathThumbNail() { + return plugin.config.deathThumbnail(); + } + @Override public boolean isEnabled() { return plugin.config.notifyDeath(); From 4de84fecc217b6cf8dee96afcd2fbdb4f0de55b6 Mon Sep 17 00:00:00 2001 From: Tom Bolks Date: Sat, 12 Nov 2022 23:14:28 +0100 Subject: [PATCH 5/6] Added bones --- src/main/java/universalDiscord/DeathThumbnail.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/universalDiscord/DeathThumbnail.java b/src/main/java/universalDiscord/DeathThumbnail.java index faa109b..8d10372 100644 --- a/src/main/java/universalDiscord/DeathThumbnail.java +++ b/src/main/java/universalDiscord/DeathThumbnail.java @@ -4,6 +4,7 @@ public enum DeathThumbnail { NONE(null), DEATH("https://oldschool.runescape.wiki/images/Death.png"), GRAVE("https://oldschool.runescape.wiki/images/Grave.png"), + BONES("https://oldschool.runescape.wiki/images/Bones_detail.png"), ANGEL_GRAVE("https://oldschool.runescape.wiki/images/Grave_%28Angel%29.png"); public final String thumbnailUrl; From d1af2a3bc4f20e70e37e04ee27d5a25e648ecebf Mon Sep 17 00:00:00 2001 From: Tom Bolks Date: Sat, 12 Nov 2022 23:17:44 +0100 Subject: [PATCH 6/6] Sorted the death configs --- .../UniversalDiscordConfig.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/universalDiscord/UniversalDiscordConfig.java b/src/main/java/universalDiscord/UniversalDiscordConfig.java index 12a9971..2ab528d 100644 --- a/src/main/java/universalDiscord/UniversalDiscordConfig.java +++ b/src/main/java/universalDiscord/UniversalDiscordConfig.java @@ -250,32 +250,32 @@ default boolean notifyDeath() { } @ConfigItem( - keyName = "deathThumbnail", - name = "Thumbnail to use", - description = "Send a thumbnail with the notification", + keyName = "deathSendImage", + name = "Send Image", + description = "Send image with the notification", position = 2, section = deathSection ) - default DeathThumbnail deathThumbnail() { - return DeathThumbnail.DEATH; + default boolean deathSendImage() { + return false; } @ConfigItem( - keyName = "deathSendImage", - name = "Send Image", - description = "Send image with the notification", + keyName = "deathThumbnail", + name = "Thumbnail to use", + description = "Send a thumbnail with the notification", position = 3, section = deathSection ) - default boolean deathSendImage() { - return false; + default DeathThumbnail deathThumbnail() { + return DeathThumbnail.DEATH; } @ConfigItem( keyName = "deathNotifMessage", name = "Notification Message", description = "The message to be sent through the webhook. Use %USERNAME% to insert your username", - position = 3, + position = 4, section = deathSection ) default String deathNotifyMessage() {