Merge pull request #603 from joey-colon/odxs/chat-notifications-private-message
Updated Chat Notifications Plugin - Added incoming PM notification
This commit is contained in:
@@ -97,4 +97,15 @@ public interface ChatNotificationsConfig extends Config
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 6,
|
||||
keyName = "notifyOnPm",
|
||||
name = "Notify on private messsage",
|
||||
description = "Notifies you whenever a private message was received"
|
||||
)
|
||||
default boolean notifyOnPm()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,10 @@ package net.runelite.client.plugins.chatnotifications;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import static java.util.regex.Pattern.quote;
|
||||
@@ -76,6 +79,9 @@ public class ChatNotificationsPlugin extends Plugin
|
||||
private String usernameReplacer = "";
|
||||
private Pattern highlightMatcher = null;
|
||||
|
||||
// Private message cache used to avoid duplicate notifications from ChatHistory.
|
||||
private Set<Integer> privateMessageHashes = new HashSet<>();
|
||||
|
||||
@Provides
|
||||
ChatNotificationsConfig provideConfig(ConfigManager configManager)
|
||||
{
|
||||
@@ -88,6 +94,12 @@ public class ChatNotificationsPlugin extends Plugin
|
||||
updateHighlights();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutDown()
|
||||
{
|
||||
this.privateMessageHashes.clear();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGameStateChanged(GameStateChanged event)
|
||||
{
|
||||
@@ -151,6 +163,19 @@ public class ChatNotificationsPlugin extends Plugin
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case PRIVATECHAT:
|
||||
case MODPRIVATECHAT:
|
||||
if (config.notifyOnPm())
|
||||
{
|
||||
int messageHash = this.buildMessageHash(chatMessage);
|
||||
if (this.privateMessageHashes.contains(messageHash))
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.privateMessageHashes.add(messageHash);
|
||||
notifier.notify("Private message received from " + chatMessage.getName());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (usernameMatcher == null && client.getLocalPlayer() != null && client.getLocalPlayer().getName() != null)
|
||||
@@ -208,6 +233,11 @@ public class ChatNotificationsPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
private int buildMessageHash(ChatMessage message)
|
||||
{
|
||||
return (message.getName() + message.getMessage()).hashCode();
|
||||
}
|
||||
|
||||
private void sendNotification(ChatMessage message)
|
||||
{
|
||||
String name = Text.removeTags(message.getName());
|
||||
|
||||
Reference in New Issue
Block a user