party: add party chat messages

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2019-02-05 12:15:00 +00:00
committed by Adam
parent 03674945d5
commit 00a4c627c5
7 changed files with 72 additions and 5 deletions

View File

@@ -34,6 +34,7 @@ import net.runelite.http.api.ws.messages.Handshake;
import net.runelite.http.api.ws.messages.LoginResponse; import net.runelite.http.api.ws.messages.LoginResponse;
import net.runelite.http.api.ws.messages.party.Join; import net.runelite.http.api.ws.messages.party.Join;
import net.runelite.http.api.ws.messages.party.Part; import net.runelite.http.api.ws.messages.party.Part;
import net.runelite.http.api.ws.messages.party.PartyChatMessage;
import net.runelite.http.api.ws.messages.party.UserJoin; import net.runelite.http.api.ws.messages.party.UserJoin;
import net.runelite.http.api.ws.messages.party.UserPart; import net.runelite.http.api.ws.messages.party.UserPart;
import net.runelite.http.api.ws.messages.party.UserSync; import net.runelite.http.api.ws.messages.party.UserSync;
@@ -52,6 +53,7 @@ public class WebsocketGsonFactory
messages.add(UserJoin.class); messages.add(UserJoin.class);
messages.add(UserPart.class); messages.add(UserPart.class);
messages.add(UserSync.class); messages.add(UserSync.class);
messages.add(PartyChatMessage.class);
MESSAGES = messages; MESSAGES = messages;
} }

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2019, Tomas Slusny <slusnucky@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.http.api.ws.messages.party;
import lombok.Value;
@Value
public class PartyChatMessage extends PartyMemberMessage
{
private final String value;
}

View File

@@ -112,7 +112,7 @@ public class RuneLite
private OverlayManager overlayManager; private OverlayManager overlayManager;
@Inject @Inject
private PartyService partyService; private Provider<PartyService> partyService;
@Inject @Inject
private Provider<ItemManager> itemManager; private Provider<ItemManager> itemManager;
@@ -276,13 +276,13 @@ public class RuneLite
eventBus.register(overlayManager); eventBus.register(overlayManager);
eventBus.register(drawManager); eventBus.register(drawManager);
eventBus.register(infoBoxManager); eventBus.register(infoBoxManager);
eventBus.register(partyService);
if (!isOutdated) if (!isOutdated)
{ {
// Initialize chat colors // Initialize chat colors
chatMessageManager.get().loadColors(); chatMessageManager.get().loadColors();
eventBus.register(partyService.get());
eventBus.register(overlayRenderer.get()); eventBus.register(overlayRenderer.get());
eventBus.register(clanManager.get()); eventBus.register(clanManager.get());
eventBus.register(itemManager.get()); eventBus.register(itemManager.get());

View File

@@ -25,6 +25,7 @@
*/ */
package net.runelite.client.plugins.chatfilter; package net.runelite.client.plugins.chatfilter;
import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.util.ArrayList; import java.util.ArrayList;
@@ -62,7 +63,7 @@ public class ChatFilterPlugin extends Plugin
private static final String CENSOR_MESSAGE = "Hey, everyone, I just tried to say something very silly!"; private static final String CENSOR_MESSAGE = "Hey, everyone, I just tried to say something very silly!";
private final JagexPrintableCharMatcher jagexPrintableCharMatcher = new JagexPrintableCharMatcher(); private final CharMatcher jagexPrintableCharMatcher = Text.JAGEX_PRINTABLE_CHAR_MATCHER;
private final List<Pattern> filteredPatterns = new ArrayList<>(); private final List<Pattern> filteredPatterns = new ArrayList<>();
@Inject @Inject

View File

@@ -22,7 +22,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.runelite.client.plugins.chatfilter; package net.runelite.client.util;
import com.google.common.base.CharMatcher; import com.google.common.base.CharMatcher;

View File

@@ -46,6 +46,8 @@ public class Text
private static final Joiner COMMA_JOINER = Joiner.on(",").skipNulls(); private static final Joiner COMMA_JOINER = Joiner.on(",").skipNulls();
public static final CharMatcher JAGEX_PRINTABLE_CHAR_MATCHER = new JagexPrintableCharMatcher();
/** /**
* Splits comma separated values to list of strings * Splits comma separated values to list of strings
* *

View File

@@ -33,13 +33,18 @@ import javax.inject.Singleton;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ChatMessageType;
import net.runelite.client.account.AccountSession; import net.runelite.client.account.AccountSession;
import net.runelite.client.account.SessionManager; import net.runelite.client.account.SessionManager;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.chat.QueuedMessage;
import net.runelite.client.eventbus.EventBus; import net.runelite.client.eventbus.EventBus;
import net.runelite.client.eventbus.Subscribe; import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.PartyChanged; import net.runelite.client.events.PartyChanged;
import static net.runelite.client.util.Text.JAGEX_PRINTABLE_CHAR_MATCHER;
import net.runelite.http.api.ws.messages.party.Join; import net.runelite.http.api.ws.messages.party.Join;
import net.runelite.http.api.ws.messages.party.Part; import net.runelite.http.api.ws.messages.party.Part;
import net.runelite.http.api.ws.messages.party.PartyChatMessage;
import net.runelite.http.api.ws.messages.party.UserJoin; import net.runelite.http.api.ws.messages.party.UserJoin;
import net.runelite.http.api.ws.messages.party.UserPart; import net.runelite.http.api.ws.messages.party.UserPart;
import net.runelite.http.api.ws.messages.party.UserSync; import net.runelite.http.api.ws.messages.party.UserSync;
@@ -49,10 +54,12 @@ import net.runelite.http.api.ws.messages.party.UserSync;
public class PartyService public class PartyService
{ {
public static final int PARTY_MAX = 15; public static final int PARTY_MAX = 15;
private static final int MAX_MESSAGE_LEN = 150;
private final WSClient wsClient; private final WSClient wsClient;
private final SessionManager sessionManager; private final SessionManager sessionManager;
private final EventBus eventBus; private final EventBus eventBus;
private final ChatMessageManager chat;
private final List<PartyMember> members = new ArrayList<>(); private final List<PartyMember> members = new ArrayList<>();
@Getter @Getter
@@ -65,11 +72,12 @@ public class PartyService
private String username; private String username;
@Inject @Inject
private PartyService(final WSClient wsClient, final SessionManager sessionManager, final EventBus eventBus) private PartyService(final WSClient wsClient, final SessionManager sessionManager, final EventBus eventBus, final ChatMessageManager chat)
{ {
this.wsClient = wsClient; this.wsClient = wsClient;
this.sessionManager = sessionManager; this.sessionManager = sessionManager;
this.eventBus = eventBus; this.eventBus = eventBus;
this.chat = chat;
} }
public void changeParty(UUID newParty) public void changeParty(UUID newParty)
@@ -141,6 +149,27 @@ public class PartyService
members.removeIf(member -> member.getMemberId().equals(message.getMemberId())); members.removeIf(member -> member.getMemberId().equals(message.getMemberId()));
} }
@Subscribe
public void onPartyChatMessage(final PartyChatMessage message)
{
// Remove non-printable characters, and <img> tags from message
String sentMesage = JAGEX_PRINTABLE_CHAR_MATCHER.retainFrom(message.getValue())
.replaceAll("<img=.+>", "");
// Cap the mesage length
if (sentMesage.length() > MAX_MESSAGE_LEN)
{
sentMesage = sentMesage.substring(0, MAX_MESSAGE_LEN);
}
chat.queue(QueuedMessage.builder()
.type(ChatMessageType.FRIENDSCHAT)
.sender("Party")
.name(getMemberById(message.getMemberId()).getName())
.runeLiteFormattedMessage(sentMesage)
.build());
}
public PartyMember getLocalMember() public PartyMember getLocalMember()
{ {
return getMemberByName(username); return getMemberByName(username);