From eb96a488e41449840d61489d2100b44475286f53 Mon Sep 17 00:00:00 2001 From: Tom Bolks Date: Sat, 12 Nov 2022 22:11:57 +0100 Subject: [PATCH 1/3] 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/3] 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/3] 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;