discord: 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);
|
||||||
|
|||||||
@@ -153,7 +153,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,6 +30,7 @@ import net.runelite.http.api.ws.messages.party.PartyMemberMessage;
|
|||||||
|
|
||||||
@Value
|
@Value
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public
|
||||||
class DiscordUserInfo extends PartyMemberMessage
|
class DiscordUserInfo extends PartyMemberMessage
|
||||||
{
|
{
|
||||||
private final String userId;
|
private final String userId;
|
||||||
|
|||||||
@@ -24,10 +24,13 @@
|
|||||||
*/
|
*/
|
||||||
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;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.lang.reflect.Member;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -60,6 +63,7 @@ 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;
|
||||||
@@ -68,6 +72,7 @@ import net.runelite.client.input.KeyListener;
|
|||||||
import net.runelite.client.input.KeyManager;
|
import net.runelite.client.input.KeyManager;
|
||||||
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.discord.DiscordUserInfo;
|
||||||
import net.runelite.client.plugins.party.data.PartyData;
|
import net.runelite.client.plugins.party.data.PartyData;
|
||||||
import net.runelite.client.plugins.party.data.PartyTilePingData;
|
import net.runelite.client.plugins.party.data.PartyTilePingData;
|
||||||
import net.runelite.client.plugins.party.messages.LocationUpdate;
|
import net.runelite.client.plugins.party.messages.LocationUpdate;
|
||||||
@@ -81,9 +86,8 @@ 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.messages.party.UserJoin;
|
import net.runelite.http.api.ws.WebsocketMessage;
|
||||||
import net.runelite.http.api.ws.messages.party.UserPart;
|
import net.runelite.http.api.ws.messages.party.*;
|
||||||
import net.runelite.http.api.ws.messages.party.UserSync;
|
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "Party",
|
name = "Party",
|
||||||
@@ -126,6 +130,9 @@ public class PartyPlugin extends Plugin implements KeyListener
|
|||||||
@Inject
|
@Inject
|
||||||
private ChatMessageManager chatMessageManager;
|
private ChatMessageManager chatMessageManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private EventBus eventBus;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named("developerMode")
|
@Named("developerMode")
|
||||||
boolean developerMode;
|
boolean developerMode;
|
||||||
@@ -486,6 +493,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.*;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.WebSocket;
|
import okhttp3.WebSocket;
|
||||||
@@ -167,15 +167,16 @@ 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
|
||||||
|
|||||||
Reference in New Issue
Block a user