Use ChatMessageManager to send game messages in Notifier

Supersedes/closes #6168

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2018-10-29 12:31:17 +01:00
parent 5481151e3c
commit a879b503eb

View File

@@ -47,6 +47,8 @@ import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ChatMessageType; import net.runelite.api.ChatMessageType;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.GameState; import net.runelite.api.GameState;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.chat.QueuedMessage;
import net.runelite.client.config.RuneLiteConfig; import net.runelite.client.config.RuneLiteConfig;
import net.runelite.client.ui.ClientUI; import net.runelite.client.ui.ClientUI;
import net.runelite.client.util.ColorUtil; import net.runelite.client.util.ColorUtil;
@@ -73,6 +75,7 @@ public class Notifier
private final RuneLiteConfig runeLiteConfig; private final RuneLiteConfig runeLiteConfig;
private final ClientUI clientUI; private final ClientUI clientUI;
private final ScheduledExecutorService executorService; private final ScheduledExecutorService executorService;
private final ChatMessageManager chatMessageManager;
private final Path notifyIconPath; private final Path notifyIconPath;
private final boolean terminalNotifierAvailable; private final boolean terminalNotifierAvailable;
private Instant flashStart; private Instant flashStart;
@@ -83,13 +86,15 @@ public class Notifier
final Client client, final Client client,
final RuneLiteConfig runeliteConfig, final RuneLiteConfig runeliteConfig,
final RuneLiteProperties runeLiteProperties, final RuneLiteProperties runeLiteProperties,
final ScheduledExecutorService executorService) final ScheduledExecutorService executorService,
final ChatMessageManager chatMessageManager)
{ {
this.client = client; this.client = client;
this.appName = runeLiteProperties.getTitle(); this.appName = runeLiteProperties.getTitle();
this.clientUI = clientUI; this.clientUI = clientUI;
this.runeLiteConfig = runeliteConfig; this.runeLiteConfig = runeliteConfig;
this.executorService = executorService; this.executorService = executorService;
this.chatMessageManager = chatMessageManager;
this.notifyIconPath = RuneLite.RUNELITE_DIR.toPath().resolve("icon.png"); this.notifyIconPath = RuneLite.RUNELITE_DIR.toPath().resolve("icon.png");
// First check if we are running in launcher // First check if we are running in launcher
@@ -127,13 +132,13 @@ public class Notifier
Toolkit.getDefaultToolkit().beep(); Toolkit.getDefaultToolkit().beep();
} }
if (runeLiteConfig.enableGameMessageNotification()) if (runeLiteConfig.enableGameMessageNotification() && client.getGameState() == GameState.LOGGED_IN)
{ {
if (client.getGameState() == GameState.LOGGED_IN) chatMessageManager.queue(QueuedMessage.builder()
{ .type(ChatMessageType.GAME)
client.addChatMessage(ChatMessageType.GAME, appName, .name(appName)
ColorUtil.wrapWithColorTag(message, MESSAGE_COLOR), ""); .value(ColorUtil.wrapWithColorTag(message, MESSAGE_COLOR))
} .build());
} }
if (runeLiteConfig.enableFlashNotification()) if (runeLiteConfig.enableFlashNotification())