From 0fa078d8f1b83494412a9345ca1b8129d01bf131 Mon Sep 17 00:00:00 2001 From: Jordan Atwood Date: Sat, 6 Feb 2021 17:19:40 -0800 Subject: [PATCH] notifier: Add username to tray notification title This also removes the player's ingame name from notifications which are referring to the active player in favor of the title. --- .../java/net/runelite/client/Notifier.java | 20 +++++++++++++++- .../client/plugins/fishing/FishingPlugin.java | 2 +- .../grounditems/GroundItemsPlugin.java | 6 +---- .../idlenotifier/IdleNotifierPlugin.java | 24 +++++++++---------- .../plugins/regenmeter/RegenMeterPlugin.java | 2 +- .../grounditems/GroundItemsPluginTest.java | 10 ++------ .../idlenotifier/IdleNotifierPluginTest.java | 13 ++++------ 7 files changed, 41 insertions(+), 36 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/Notifier.java b/runelite-client/src/main/java/net/runelite/client/Notifier.java index 8184cf9f98..53963e4b1b 100644 --- a/runelite-client/src/main/java/net/runelite/client/Notifier.java +++ b/runelite-client/src/main/java/net/runelite/client/Notifier.java @@ -59,6 +59,7 @@ import net.runelite.api.ChatMessageType; import net.runelite.api.Client; import net.runelite.api.Constants; import net.runelite.api.GameState; +import net.runelite.api.Player; import net.runelite.client.chat.ChatColorType; import net.runelite.client.chat.ChatMessageBuilder; import net.runelite.client.chat.ChatMessageManager; @@ -175,7 +176,7 @@ public class Notifier if (runeLiteConfig.enableTrayNotifications()) { - sendNotification(appName, message, type); + sendNotification(buildTitle(), message, type); } switch (runeLiteConfig.notificationSound()) @@ -210,6 +211,23 @@ public class Notifier log.debug(message); } + private String buildTitle() + { + Player player = client.getLocalPlayer(); + if (player == null) + { + return appName; + } + + String name = player.getName(); + if (Strings.isNullOrEmpty(name)) + { + return appName; + } + + return appName + " - " + name; + } + public void processFlash(final Graphics2D graphics) { FlashNotification flashNotification = runeLiteConfig.flashNotification(); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/fishing/FishingPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/fishing/FishingPlugin.java index 0c5fa99dc2..e782b81428 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/fishing/FishingPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/fishing/FishingPlugin.java @@ -377,7 +377,7 @@ public class FishingPlugin extends Plugin { if (!trawlerNotificationSent) { - notifier.notify("[" + client.getLocalPlayer().getName() + "] has low Fishing Trawler activity!"); + notifier.notify("You have low Fishing Trawler activity!"); trawlerNotificationSent = true; } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java index e7e79b5186..b7a8fc6500 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java @@ -59,7 +59,6 @@ import net.runelite.api.ItemContainer; import net.runelite.api.ItemID; import net.runelite.api.MenuAction; import net.runelite.api.MenuEntry; -import net.runelite.api.Player; import net.runelite.api.Tile; import net.runelite.api.TileItem; import net.runelite.api.coords.WorldPoint; @@ -643,11 +642,8 @@ public class GroundItemsPlugin extends Plugin return; } - final Player local = client.getLocalPlayer(); final StringBuilder notificationStringBuilder = new StringBuilder() - .append('[') - .append(local.getName()) - .append("] received a ") + .append("You received a ") .append(dropType) .append(" drop: ") .append(item.getName()); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifierPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifierPlugin.java index 79ca4413e3..6d7dcec442 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifierPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifierPlugin.java @@ -438,64 +438,64 @@ public class IdleNotifierPlugin extends Plugin if (config.logoutIdle() && checkIdleLogout()) { - notifier.notify("[" + local.getName() + "] is about to log out from idling too long!"); + notifier.notify("You are about to log out from idling too long!"); } if (check6hrLogout()) { - notifier.notify("[" + local.getName() + "] is about to log out from being online for 6 hours!"); + notifier.notify("You are about to log out from being online for 6 hours!"); } if (config.animationIdle() && checkAnimationIdle(waitDuration, local)) { - notifier.notify("[" + local.getName() + "] is now idle!"); + notifier.notify("You are now idle!"); } if (config.movementIdle() && checkMovementIdle(waitDuration, local)) { - notifier.notify("[" + local.getName() + "] has stopped moving!"); + notifier.notify("You have stopped moving!"); } if (config.interactionIdle() && checkInteractionIdle(waitDuration, local)) { if (lastInteractWasCombat) { - notifier.notify("[" + local.getName() + "] is now out of combat!"); + notifier.notify("You are now out of combat!"); } else { - notifier.notify("[" + local.getName() + "] is now idle!"); + notifier.notify("You are now idle!"); } } if (checkLowHitpoints()) { - notifier.notify("[" + local.getName() + "] has low hitpoints!"); + notifier.notify("You have low hitpoints!"); } if (checkLowPrayer()) { - notifier.notify("[" + local.getName() + "] has low prayer!"); + notifier.notify("You have low prayer!"); } if (checkLowEnergy()) { - notifier.notify("[" + local.getName() + "] has low run energy!"); + notifier.notify("You have low run energy!"); } if (checkHighEnergy()) { - notifier.notify("[" + local.getName() + "] has restored run energy!"); + notifier.notify("You have restored run energy!"); } if (checkLowOxygen()) { - notifier.notify("[" + local.getName() + "] has low oxygen!"); + notifier.notify("You have low oxygen!"); } if (checkFullSpecEnergy()) { - notifier.notify("[" + local.getName() + "] has restored spec energy!"); + notifier.notify("You have restored spec energy!"); } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/regenmeter/RegenMeterPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/regenmeter/RegenMeterPlugin.java index 6339ce5486..2160148401 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/regenmeter/RegenMeterPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/regenmeter/RegenMeterPlugin.java @@ -166,7 +166,7 @@ public class RegenMeterPlugin extends Plugin if (config.getNotifyBeforeHpRegenSeconds() > 0 && currentHP < maxHP && shouldNotifyHpRegenThisTick(ticksPerHPRegen)) { - notifier.notify("[" + client.getLocalPlayer().getName() + "] regenerates their next hitpoint soon!"); + notifier.notify("Your next hitpoint will regenerate soon!"); } } diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/grounditems/GroundItemsPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/grounditems/GroundItemsPluginTest.java index bc9c2536a1..48d6296ca5 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/grounditems/GroundItemsPluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/grounditems/GroundItemsPluginTest.java @@ -109,13 +109,7 @@ public class GroundItemsPluginTest return null; }).when(executor).execute(any(Runnable.class)); - when(client.getLocalPlayer()).then(a -> - { - Player player = mock(Player.class); - when(player.getName()).thenReturn("Adam"); - return player; - }); - + when(client.getLocalPlayer()).thenReturn(mock(Player.class)); when(config.getHiddenItems()).thenReturn(""); } @@ -149,6 +143,6 @@ public class GroundItemsPluginTest groundItemsPlugin.onItemSpawned(new ItemSpawned(tile, tileItem)); - verify(notifier).notify("[Adam] received a highlighted drop: Abyssal whip"); + verify(notifier).notify("You received a highlighted drop: Abyssal whip"); } } \ No newline at end of file diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/idlenotifier/IdleNotifierPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/idlenotifier/IdleNotifierPluginTest.java index 59c84d3086..bb91fffcb8 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/idlenotifier/IdleNotifierPluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/idlenotifier/IdleNotifierPluginTest.java @@ -62,8 +62,6 @@ import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class IdleNotifierPluginTest { - private static final String PLAYER_NAME = "Deathbeam"; - @Mock @Bind private Client client; @@ -116,7 +114,6 @@ public class IdleNotifierPluginTest when(fishingSpot.getName()).thenReturn("Fishing spot"); // Mock player - when(player.getName()).thenReturn(PLAYER_NAME); when(player.getAnimation()).thenReturn(AnimationID.IDLE); when(client.getLocalPlayer()).thenReturn(player); @@ -145,7 +142,7 @@ public class IdleNotifierPluginTest when(player.getAnimation()).thenReturn(AnimationID.IDLE); plugin.onAnimationChanged(animationChanged); plugin.onGameTick(new GameTick()); - verify(notifier).notify("[" + PLAYER_NAME + "] is now idle!"); + verify(notifier).notify("You are now idle!"); } @Test @@ -201,7 +198,7 @@ public class IdleNotifierPluginTest when(player.getInteracting()).thenReturn(null); plugin.onInteractingChanged(new InteractingChanged(player, null)); plugin.onGameTick(new GameTick()); - verify(notifier).notify("[" + PLAYER_NAME + "] is now out of combat!"); + verify(notifier).notify("You are now out of combat!"); } @Test @@ -292,7 +289,7 @@ public class IdleNotifierPluginTest plugin.onInteractingChanged(new InteractingChanged(player, null)); plugin.onGameTick(new GameTick()); - verify(notifier).notify("[" + PLAYER_NAME + "] is now idle!"); + verify(notifier).notify("You are now idle!"); } @Test @@ -306,7 +303,7 @@ public class IdleNotifierPluginTest when(client.getVar(eq(VarPlayer.SPECIAL_ATTACK_PERCENT))).thenReturn(500); // 50% plugin.onGameTick(new GameTick()); - verify(notifier).notify(eq("[" + PLAYER_NAME + "] has restored spec energy!")); + verify(notifier).notify(eq("You have restored spec energy!")); } @Test @@ -321,6 +318,6 @@ public class IdleNotifierPluginTest // No movement here plugin.onGameTick(new GameTick()); - verify(notifier).notify(eq("[" + PLAYER_NAME + "] has stopped moving!")); + verify(notifier).notify(eq("You have stopped moving!")); } } \ No newline at end of file