Merge pull request #2191 from open-osrs/party-time
discord: fix party support
This commit is contained in:
@@ -29,6 +29,7 @@ import net.runelite.api.events.Event;
|
|||||||
public class WebsocketMessage implements Event
|
public class WebsocketMessage implements Event
|
||||||
{
|
{
|
||||||
protected boolean _party;
|
protected boolean _party;
|
||||||
|
public String text;
|
||||||
|
|
||||||
public boolean isParty()
|
public boolean isParty()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ import net.runelite.client.ui.overlay.arrow.ArrowWorldOverlay;
|
|||||||
import net.runelite.client.ui.overlay.infobox.InfoBoxOverlay;
|
import net.runelite.client.ui.overlay.infobox.InfoBoxOverlay;
|
||||||
import net.runelite.client.ui.overlay.tooltip.TooltipOverlay;
|
import net.runelite.client.ui.overlay.tooltip.TooltipOverlay;
|
||||||
import net.runelite.client.ui.overlay.worldmap.WorldMapOverlay;
|
import net.runelite.client.ui.overlay.worldmap.WorldMapOverlay;
|
||||||
|
import net.runelite.client.ws.PartyService;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@@ -161,6 +162,9 @@ public class RuneLite
|
|||||||
@Inject
|
@Inject
|
||||||
private Provider<ChatboxPanelManager> chatboxPanelManager;
|
private Provider<ChatboxPanelManager> chatboxPanelManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Provider<PartyService> partyService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Hooks hooks;
|
private Hooks hooks;
|
||||||
|
|
||||||
@@ -248,7 +252,6 @@ public class RuneLite
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SentryClient client = Sentry.init("https://fa31d674e44247fa93966c69a903770f@sentry.io/1811856");
|
SentryClient client = Sentry.init("https://fa31d674e44247fa93966c69a903770f@sentry.io/1811856");
|
||||||
client.setRelease(RuneLiteProperties.getPlusVersion());
|
client.setRelease(RuneLiteProperties.getPlusVersion());
|
||||||
|
|
||||||
@@ -299,7 +302,6 @@ public class RuneLite
|
|||||||
true));
|
true));
|
||||||
|
|
||||||
injector.getInstance(RuneLite.class).start();
|
injector.getInstance(RuneLite.class).start();
|
||||||
|
|
||||||
final long end = System.currentTimeMillis();
|
final long end = System.currentTimeMillis();
|
||||||
final RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();
|
final RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();
|
||||||
final long uptime = rb.getUptime();
|
final long uptime = rb.getUptime();
|
||||||
@@ -372,6 +374,7 @@ public class RuneLite
|
|||||||
xpDropManager.get();
|
xpDropManager.get();
|
||||||
playerManager.get();
|
playerManager.get();
|
||||||
chatboxPanelManager.get();
|
chatboxPanelManager.get();
|
||||||
|
partyService.get();
|
||||||
|
|
||||||
eventBus.subscribe(GameStateChanged.class, this, hooks::onGameStateChanged);
|
eventBus.subscribe(GameStateChanged.class, this, hooks::onGameStateChanged);
|
||||||
eventBus.subscribe(ScriptCallbackEvent.class, this, hooks::onScriptCallbackEvent);
|
eventBus.subscribe(ScriptCallbackEvent.class, this, hooks::onScriptCallbackEvent);
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ public class DiscordPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
partyService.setUsername(discordService.getCurrentUser().username + "#" + discordService.getCurrentUser().discriminator);
|
partyService.setUsername(discordService.getCurrentUser().username + "#" + discordService.getCurrentUser().discriminator);
|
||||||
}
|
}
|
||||||
|
wsClient.unregisterMessage(DiscordUserInfo.class);
|
||||||
wsClient.registerMessage(DiscordUserInfo.class);
|
wsClient.registerMessage(DiscordUserInfo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import net.runelite.http.api.ws.messages.party.PartyMemberMessage;
|
|||||||
|
|
||||||
@Value
|
@Value
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
class DiscordUserInfo extends PartyMemberMessage
|
public class DiscordUserInfo extends PartyMemberMessage
|
||||||
{
|
{
|
||||||
private final String userId;
|
private final String userId;
|
||||||
private final String avatarId;
|
private final String avatarId;
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.party;
|
package net.runelite.client.plugins.party;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import com.google.inject.Binder;
|
import com.google.inject.Binder;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
@@ -60,12 +62,14 @@ import net.runelite.client.chat.ChatMessageBuilder;
|
|||||||
import net.runelite.client.chat.ChatMessageManager;
|
import net.runelite.client.chat.ChatMessageManager;
|
||||||
import net.runelite.client.chat.QueuedMessage;
|
import net.runelite.client.chat.QueuedMessage;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
|
import net.runelite.client.eventbus.EventBus;
|
||||||
import net.runelite.client.eventbus.Subscribe;
|
import net.runelite.client.eventbus.Subscribe;
|
||||||
import net.runelite.client.events.ConfigChanged;
|
import net.runelite.client.events.ConfigChanged;
|
||||||
import net.runelite.client.events.OverlayMenuClicked;
|
import net.runelite.client.events.OverlayMenuClicked;
|
||||||
import net.runelite.client.events.PartyChanged;
|
import net.runelite.client.events.PartyChanged;
|
||||||
import net.runelite.client.input.KeyListener;
|
import net.runelite.client.input.KeyListener;
|
||||||
import net.runelite.client.input.KeyManager;
|
import net.runelite.client.input.KeyManager;
|
||||||
|
import net.runelite.client.plugins.discord.DiscordUserInfo;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
import net.runelite.client.plugins.PluginType;
|
import net.runelite.client.plugins.PluginType;
|
||||||
@@ -82,6 +86,10 @@ import net.runelite.client.util.ColorUtil;
|
|||||||
import net.runelite.client.ws.PartyMember;
|
import net.runelite.client.ws.PartyMember;
|
||||||
import net.runelite.client.ws.PartyService;
|
import net.runelite.client.ws.PartyService;
|
||||||
import net.runelite.client.ws.WSClient;
|
import net.runelite.client.ws.WSClient;
|
||||||
|
import net.runelite.http.api.ws.WebsocketMessage;
|
||||||
|
import net.runelite.http.api.ws.messages.party.Join;
|
||||||
|
import net.runelite.http.api.ws.messages.party.PartyChatMessage;
|
||||||
|
import net.runelite.http.api.ws.messages.party.PartyMemberMessage;
|
||||||
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;
|
||||||
@@ -95,49 +103,37 @@ import net.runelite.http.api.ws.messages.party.UserSync;
|
|||||||
@Singleton
|
@Singleton
|
||||||
public class PartyPlugin extends Plugin implements KeyListener
|
public class PartyPlugin extends Plugin implements KeyListener
|
||||||
{
|
{
|
||||||
@Inject
|
@Getter(AccessLevel.PACKAGE)
|
||||||
private Client client;
|
private final Map<UUID, PartyData> partyDataMap = Collections.synchronizedMap(new HashMap<>());
|
||||||
|
@Getter(AccessLevel.PACKAGE)
|
||||||
@Inject
|
private final List<PartyTilePingData> pendingTilePings = Collections.synchronizedList(new ArrayList<>());
|
||||||
private PartyService party;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private WSClient ws;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private OverlayManager overlayManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private PartyStatsOverlay partyStatsOverlay;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private PartyPingOverlay partyPingOverlay;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private KeyManager keyManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private WSClient wsClient;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private WorldMapPointManager worldMapManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private PartyConfig config;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ChatMessageManager chatMessageManager;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named("developerMode")
|
@Named("developerMode")
|
||||||
boolean developerMode;
|
boolean developerMode;
|
||||||
|
@Inject
|
||||||
@Getter(AccessLevel.PACKAGE)
|
private Client client;
|
||||||
private final Map<UUID, PartyData> partyDataMap = Collections.synchronizedMap(new HashMap<>());
|
@Inject
|
||||||
|
private PartyService party;
|
||||||
@Getter(AccessLevel.PACKAGE)
|
@Inject
|
||||||
private final List<PartyTilePingData> pendingTilePings = Collections.synchronizedList(new ArrayList<>());
|
private WSClient ws;
|
||||||
|
@Inject
|
||||||
|
private OverlayManager overlayManager;
|
||||||
|
@Inject
|
||||||
|
private PartyStatsOverlay partyStatsOverlay;
|
||||||
|
@Inject
|
||||||
|
private PartyPingOverlay partyPingOverlay;
|
||||||
|
@Inject
|
||||||
|
private KeyManager keyManager;
|
||||||
|
@Inject
|
||||||
|
private WSClient wsClient;
|
||||||
|
@Inject
|
||||||
|
private WorldMapPointManager worldMapManager;
|
||||||
|
@Inject
|
||||||
|
private PartyConfig config;
|
||||||
|
@Inject
|
||||||
|
private ChatMessageManager chatMessageManager;
|
||||||
|
@Inject
|
||||||
|
private EventBus eventBus;
|
||||||
private int lastHp, lastPray;
|
private int lastHp, lastPray;
|
||||||
private boolean hotkeyDown, doSync;
|
private boolean hotkeyDown, doSync;
|
||||||
private boolean sendAlert;
|
private boolean sendAlert;
|
||||||
@@ -488,6 +484,83 @@ public class PartyPlugin extends Plugin implements KeyListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
private void onPartyMemberMessage(PartyMemberMessage event)
|
||||||
|
{
|
||||||
|
JsonObject jobj = new Gson().fromJson(event.text, JsonObject.class);
|
||||||
|
if (jobj.get("type").getAsString().equals("SkillUpdate"))
|
||||||
|
{
|
||||||
|
Skill skillToUpdate = Skill.valueOf(jobj.get("skill").getAsString());
|
||||||
|
SkillUpdate skillUpdateEvent = new SkillUpdate(skillToUpdate, jobj.get("value").getAsInt(), jobj.get("max").getAsInt());
|
||||||
|
skillUpdateEvent.setMemberId(event.getMemberId());
|
||||||
|
eventBus.post(SkillUpdate.class, skillUpdateEvent);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jobj.get("type").getAsString().equals("LocationUpdate"))
|
||||||
|
{
|
||||||
|
WorldPoint worldPoint = new WorldPoint(jobj.get("worldPoint").getAsJsonObject().get("x").getAsInt(), jobj.get("worldPoint").getAsJsonObject().get("y").getAsInt(), jobj.get("worldPoint").getAsJsonObject().get("plane").getAsInt());
|
||||||
|
LocationUpdate locationUpdate = new LocationUpdate(worldPoint);
|
||||||
|
locationUpdate.setMemberId(event.getMemberId());
|
||||||
|
eventBus.post(LocationUpdate.class, locationUpdate);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jobj.get("type").getAsString().equals("DiscordUserInfo"))
|
||||||
|
{
|
||||||
|
DiscordUserInfo info = new DiscordUserInfo(jobj.get("userId").getAsString(), jobj.get("avatarId").getAsString());
|
||||||
|
info.setMemberId(event.getMemberId());
|
||||||
|
eventBus.post(DiscordUserInfo.class, info);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
private void onWebsocketMessage(WebsocketMessage event)
|
||||||
|
{
|
||||||
|
JsonObject jobj = new Gson().fromJson(event.text, JsonObject.class);
|
||||||
|
if (jobj.get("type").getAsString().equals("UserJoin"))
|
||||||
|
{
|
||||||
|
UserJoin joinEvent = new UserJoin(UUID.fromString(jobj.get("memberId").getAsString()), UUID.fromString(jobj.get("partyId").getAsString()), jobj.get("name").getAsString());
|
||||||
|
eventBus.post(UserJoin.class, joinEvent);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (jobj.get("type").getAsString().equals("Join"))
|
||||||
|
{
|
||||||
|
Join joinEvent = new Join(UUID.fromString(jobj.get("partyId").getAsString()), jobj.get("name").getAsString());
|
||||||
|
eventBus.post(Join.class, joinEvent);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (jobj.get("type").getAsString().equals("PartyChatMessage"))
|
||||||
|
{
|
||||||
|
PartyChatMessage partyChatMessageEvent = new PartyChatMessage(jobj.get("value").getAsString());
|
||||||
|
eventBus.post(PartyChatMessage.class, partyChatMessageEvent);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (jobj.get("type").getAsString().equals("UserPart"))
|
||||||
|
{
|
||||||
|
UserPart userPartEvent = new UserPart(UUID.fromString(jobj.get("memberId").getAsString()));
|
||||||
|
eventBus.post(UserPart.class, userPartEvent);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (jobj.get("type").getAsString().equals("UserSync"))
|
||||||
|
{
|
||||||
|
UserSync userPartEvent = new UserSync();
|
||||||
|
eventBus.post(UserSync.class, userPartEvent);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (jobj.get("type").getAsString().equals("TilePing"))
|
||||||
|
{
|
||||||
|
WorldPoint worldPoint = new WorldPoint(jobj.get("worldPoint").getAsJsonObject().get("x").getAsInt(), jobj.get("worldPoint").getAsJsonObject().get("y").getAsInt(), jobj.get("worldPoint").getAsJsonObject().get("plane").getAsInt());
|
||||||
|
TilePing tilePing = new TilePing(worldPoint);
|
||||||
|
eventBus.post(TilePing.class, tilePing);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("Unhandled WS event: {}", event.text);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
PartyData getPartyData(final UUID uuid)
|
PartyData getPartyData(final UUID uuid)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ import net.runelite.http.api.RuneLiteAPI;
|
|||||||
import net.runelite.http.api.ws.WebsocketGsonFactory;
|
import net.runelite.http.api.ws.WebsocketGsonFactory;
|
||||||
import net.runelite.http.api.ws.WebsocketMessage;
|
import net.runelite.http.api.ws.WebsocketMessage;
|
||||||
import net.runelite.http.api.ws.messages.Handshake;
|
import net.runelite.http.api.ws.messages.Handshake;
|
||||||
import net.runelite.http.api.ws.messages.party.PartyMessage;
|
import net.runelite.http.api.ws.messages.party.PartyMemberMessage;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.WebSocket;
|
import okhttp3.WebSocket;
|
||||||
@@ -148,9 +148,17 @@ public class WSClient extends WebSocketListener implements AutoCloseable
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onOpen(@NotNull WebSocket webSocket, @NotNull Response response)
|
public void onClosed(@NotNull WebSocket webSocket, int code, @NotNull String reason)
|
||||||
{
|
{
|
||||||
log.info("Websocket {} opened", webSocket);
|
log.info("Websocket {} closed: {}/{}", webSocket, code, reason);
|
||||||
|
this.webSocket = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NotNull WebSocket webSocket, @NotNull Throwable t, Response response)
|
||||||
|
{
|
||||||
|
log.warn("Error in websocket {}:{}", response, t);
|
||||||
|
this.webSocket = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -167,28 +175,21 @@ public class WSClient extends WebSocketListener implements AutoCloseable
|
|||||||
log.debug("Failed to deserialize message", e);
|
log.debug("Failed to deserialize message", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
message.text = text;
|
||||||
|
|
||||||
if (message.isParty() && !(message instanceof PartyMessage))
|
if (message instanceof PartyMemberMessage)
|
||||||
{
|
{
|
||||||
// spoofed message?
|
eventBus.post(PartyMemberMessage.class, message);
|
||||||
return;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
eventBus.post(WebsocketMessage.class, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("Got: {}", text);
|
|
||||||
eventBus.post(PartyMessage.class, message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClosed(@NotNull WebSocket webSocket, int code, @NotNull String reason)
|
public void onOpen(@NotNull WebSocket webSocket, @NotNull Response response)
|
||||||
{
|
{
|
||||||
log.info("Websocket {} closed: {}/{}", webSocket, code, reason);
|
log.info("Websocket {} opened", webSocket);
|
||||||
this.webSocket = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NotNull WebSocket webSocket, @NotNull Throwable t, Response response)
|
|
||||||
{
|
|
||||||
log.warn("Error in websocket {}:{}", response, t);
|
|
||||||
this.webSocket = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user