diff --git a/build.gradle b/build.gradle index 8bce5d0a9..5a4f8a1a7 100644 --- a/build.gradle +++ b/build.gradle @@ -101,12 +101,7 @@ dependencies { compile(group: 'org.reflections', name: 'reflections', version: '0.9.11') { exclude group: 'com.google.guava', module: 'guava' } - // https://mvnrepository.com/artifact/club.minnced/discord-rpc-release - // discord rpc - //compile group: 'club.minnced', name: 'discord-rpc-release', version: 'v3.3.0' -// compile 'club.minnced:java-discord-rpc:2.0.2' - //compile 'club.minnced:java-discord-rpc:%VERSION%' - + compile 'club.minnced:java-discord-rpc:v2.0.1' } processResources { diff --git a/src/main/java/club/minnced/discord/rpc/DiscordEventHandlers.java b/src/main/java/club/minnced/discord/rpc/DiscordEventHandlers.java deleted file mode 100644 index fc85f9537..000000000 --- a/src/main/java/club/minnced/discord/rpc/DiscordEventHandlers.java +++ /dev/null @@ -1,120 +0,0 @@ -package club.minnced.discord.rpc; - -import com.sun.jna.Callback; -import com.sun.jna.Structure; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -/* -typedef struct DiscordEventHandlers { - void (*ready)(DiscordUser*); - void (*disconnected)(int errorCode, const char* message); - void (*errored)(int errorCode, const char* message); - void (*joinGame)(const char* joinSecret); - void (*spectateGame)(const char* spectateSecret); - void (*joinRequest)(const DiscordUser* request); -} DiscordEventHandlers; - */ -/** - * Struct containing handlers for RPC events - *
Provided handlers can be null. - */ -public class DiscordEventHandlers extends Structure -{ - /** - * Handler function for the ready event - */ - public interface OnReady extends Callback - { - void accept(DiscordUser user); - } - - /** - * Handler function for the exceptional events (error, disconnect) - */ - public interface OnStatus extends Callback - { - void accept(int errorCode, String message); - } - - /** - * Handler function for game update events (joinGame, spectateGame) - */ - public interface OnGameUpdate extends Callback - { - void accept(String secret); - } - - /** - * Handler function for user join requests - */ - public interface OnJoinRequest extends Callback - { - void accept(DiscordUser request); - } - - private static final List FIELD_ORDER = Collections.unmodifiableList(Arrays.asList( - "ready", - "disconnected", - "errored", - "joinGame", - "spectateGame", - "joinRequest" - )); - - /** - * Called when the RPC connection has been established - */ - public OnReady ready; - /** - * Called when the RPC connection has been severed - */ - public OnStatus disconnected; - /** - * Called when an internal error is caught within the SDK - */ - public OnStatus errored; - /** - * Called when the logged in user joined a game - */ - public OnGameUpdate joinGame; - /** - * Called when the logged in user joined to spectate a game - */ - public OnGameUpdate spectateGame; - /** - * Called when another discord user wants to join the game of the logged in user - */ - public OnJoinRequest joinRequest; - - @Override - public boolean equals(Object o) - { - if (this == o) - return true; - if (!(o instanceof DiscordEventHandlers)) - return false; - DiscordEventHandlers that = (DiscordEventHandlers) o; - return Objects.equals(ready, that.ready) - && Objects.equals(disconnected, that.disconnected) - && Objects.equals(errored, that.errored) - && Objects.equals(joinGame, that.joinGame) - && Objects.equals(spectateGame, that.spectateGame) - && Objects.equals(joinRequest, that.joinRequest); - } - - @Override - public int hashCode() - { - return Objects.hash(ready, disconnected, errored, joinGame, spectateGame, joinRequest); - } - - @Override - protected List getFieldOrder() - { - return FIELD_ORDER; - } -} diff --git a/src/main/java/club/minnced/discord/rpc/DiscordRPC.java b/src/main/java/club/minnced/discord/rpc/DiscordRPC.java deleted file mode 100644 index 86df1f487..000000000 --- a/src/main/java/club/minnced/discord/rpc/DiscordRPC.java +++ /dev/null @@ -1,153 +0,0 @@ -package club.minnced.discord.rpc; - -import com.sun.jna.Library; -import com.sun.jna.Native; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -/** - * Core library binding for the official Discord RPC SDK. - *
Use {@link #INSTANCE} to access this library. - * - *

Supported Architectures

- * - */ -public interface DiscordRPC extends Library -{ - /** - * Library instance. - */ - DiscordRPC INSTANCE = Native.loadLibrary("discord-rpc", DiscordRPC.class); - - /** - * Used to decline a request via {@link #Discord_Respond(String, int)} - * @see #DISCORD_REPLY_YES - */ - int DISCORD_REPLY_NO = 0; - /** - * Used to accept a request via {@link #Discord_Respond(String, int)} - * @see #DISCORD_REPLY_NO - */ - int DISCORD_REPLY_YES = 1; - /** - * Currently unsused response, treated like NO. - * Used with {@link #Discord_Respond(String, int)} - * @see #DISCORD_REPLY_NO - */ - int DISCORD_REPLY_IGNORE = 2; - - /** - * Initializes the library, supply with application details and event handlers. - * Handlers are only called when the {@link #Discord_RunCallbacks()} method is invoked! - *
Before closing the application it is recommended to call {@link #Discord_Shutdown()} - * - * @param applicationId - * The ID for this RPC application, - * retrieved from the developer dashboard - * @param handlers - * Nullable instance of {@link club.minnced.discord.rpc.DiscordEventHandlers} - * @param autoRegister - * {@code true} to automatically call {@link #Discord_RegisterSteamGame(String, String)} or {@link #Discord_Register(String, String)} - * @param steamId - * Possible steam ID of the running game - */ - void Discord_Initialize(@Nonnull String applicationId, - @Nullable DiscordEventHandlers handlers, - boolean autoRegister, - @Nullable String steamId); - - /** - * Shuts the RPC connection down. - * If not currently connected, this does nothing. - */ - void Discord_Shutdown(); - - /** - * Executes the registered handlers for currently queued events. - *
If this is not called the handlers will not receive any events! - * - *

It is recommended to call this in a 2 second interval - */ - void Discord_RunCallbacks(); - - /** - * Polls events from the RPC pipe and pushes the currently queued presence. - *
This will be performed automatically if the attached binary - * has an enabled IO thread (default) - * - *

If the IO-Thread has been enabled this will not be supported! - */ - void Discord_UpdateConnection(); - - /** - * Updates the currently set presence of the logged in user. - *
Note that the client only updates its presence every 15 seconds - * and queues all additional presence updates. - * - * @param struct - * The new presence to use - * - * @see club.minnced.discord.rpc.DiscordRichPresence - */ - void Discord_UpdatePresence(@Nullable DiscordRichPresence struct); - - /** - * Clears the currently set presence. - */ - void Discord_ClearPresence(); - - /** - * Responds to the given user with the specified reply type. - * - *

Possible Replies

- * - * - * @param userid - * The id of the user to respond to - * @param reply - * The reply type - * - * @see club.minnced.discord.rpc.DiscordUser#userId DiscordUser.userId - */ - void Discord_Respond(@Nonnull String userid, int reply); - - /** - * Updates the registered event handlers to the provided struct. - * - * @param handlers - * The handlers to update to, or null - */ - void Discord_UpdateHandlers(@Nullable DiscordEventHandlers handlers); - - /** - * Registers the given application so it can be run by the discord client. {@code discord-://} - * - * @param applicationId - * The ID of the application to register - * @param command - * The command for the application startup, or {@code null} to use the - * current executable's path - */ - void Discord_Register(String applicationId, String command); - - /** - * Similar to {@link #Discord_Register(String, String)} but uses the steam - * game's installation path. - * - * @param applicationId - * The ID of the application to register - * @param steamId - * The steam ID for the game - */ - void Discord_RegisterSteamGame(String applicationId, String steamId); -} diff --git a/src/main/java/club/minnced/discord/rpc/DiscordRichPresence.java b/src/main/java/club/minnced/discord/rpc/DiscordRichPresence.java deleted file mode 100644 index 4aa4510e2..000000000 --- a/src/main/java/club/minnced/discord/rpc/DiscordRichPresence.java +++ /dev/null @@ -1,213 +0,0 @@ -package club.minnced.discord.rpc; - -import com.sun.jna.Structure; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -/* -typedef struct DiscordRichPresence { - const char* state; // max 128 bytes - const char* details; // max 128 bytes - int64_t startTimestamp; - int64_t endTimestamp; - const char* largeImageKey; // max 32 bytes - const char* largeImageText; // max 128 bytes - const char* smallImageKey; // max 32 bytes - const char* smallImageText; // max 128 bytes - const char* partyId; // max 128 bytes - int partySize; - int partyMax; - const char* matchSecret; // max 128 bytes - const char* joinSecret; // max 128 bytes - const char* spectateSecret; // max 128 bytes - int8_t instance; -} DiscordRichPresence; - */ - -/** - * Struct binding for a RichPresence - */ -public class DiscordRichPresence extends Structure -{ - private static final List FIELD_ORDER = Collections.unmodifiableList(Arrays.asList( - "state", - "details", - "startTimestamp", - "endTimestamp", - "largeImageKey", - "largeImageText", - "smallImageKey", - "smallImageText", - "partyId", - "partySize", - "partyMax", - "matchSecret", - "joinSecret", - "spectateSecret", - "instance" - )); - - public DiscordRichPresence(String encoding) { - super(); - setStringEncoding(encoding); - } - - public DiscordRichPresence() { - this("UTF-8"); - } - - /** - * The user's current party status. - *
Example: "Looking to Play", "Playing Solo", "In a Group" - * - *

Maximum: 128 characters - */ - public String state; - - /** - * What the player is currently doing. - *
Example: "Competitive - Captain's Mode", "In Queue", "Unranked PvP" - * - *

Maximum: 128 characters - */ - public String details; - - /** - * Unix timestamp (seconds) for the start of the game. - *
Example: 1507665886 - */ - public long startTimestamp; - - /** - * Unix timestamp (seconds) for the start of the game. - *
Example: 1507665886 - */ - public long endTimestamp; - - /** - * Name of the uploaded image for the large profile artwork. - *
Example: "default" - * - *

Maximum: 32 characters - */ - public String largeImageKey; - - /** - * Tooltip for the largeImageKey. - *
Example: "Blade's Edge Arena", "Numbani", "Danger Zone" - * - *

Maximum: 128 characters - */ - public String largeImageText; - - /** - * Name of the uploaded image for the small profile artwork. - *
Example: "rogue" - * - *

Maximum: 32 characters - */ - public String smallImageKey; - - /** - * Tooltip for the smallImageKey. - *
Example: "Rogue - Level 100" - * - *

Maximum: 128 characters - */ - public String smallImageText; - - /** - * ID of the player's party, lobby, or group. - *
Example: "ae488379-351d-4a4f-ad32-2b9b01c91657" - * - *

Maximum: 128 characters - */ - public String partyId; - - /** - * Current size of the player's party, lobby, or group. - *
Example: 1 - */ - public int partySize; - - /** - * Maximum size of the player's party, lobby, or group. - *
Example: 5 - */ - public int partyMax; - - /** - * Unique hashed string for Spectate and Join. - * Required to enable match interactive buttons in the user's presence. - *
Example: "MmhuZToxMjMxMjM6cWl3amR3MWlqZA==" - * - *

Maximum: 128 characters - */ - public String matchSecret; - - /** - * Unique hashed string for Spectate button. - * This will enable the "Spectate" button on the user's presence if whitelisted. - *
Example: "MTIzNDV8MTIzNDV8MTMyNDU0" - * - *

Maximum: 128 characters - */ - public String joinSecret; - - /** - * Unique hashed string for chat invitations and Ask to Join. - * This will enable the "Ask to Join" button on the user's presence if whitelisted. - *
Example: "MTI4NzM0OjFpMmhuZToxMjMxMjM=" - * - *

Maximum: 128 characters - */ - public String spectateSecret; - - /** - * Marks the matchSecret as a game session with a specific beginning and end. - * Boolean value of 0 or 1. - *
Example: 1 - */ - public byte instance; - - @Override - public boolean equals(Object o) - { - if (this == o) - return true; - if (!(o instanceof DiscordRichPresence)) - return false; - DiscordRichPresence presence = (DiscordRichPresence) o; - return startTimestamp == presence.startTimestamp - && endTimestamp == presence.endTimestamp - && partySize == presence.partySize - && partyMax == presence.partyMax - && instance == presence.instance - && Objects.equals(state, presence.state) - && Objects.equals(details, presence.details) - && Objects.equals(largeImageKey, presence.largeImageKey) - && Objects.equals(largeImageText, presence.largeImageText) - && Objects.equals(smallImageKey, presence.smallImageKey) - && Objects.equals(smallImageText, presence.smallImageText) - && Objects.equals(partyId, presence.partyId) - && Objects.equals(matchSecret, presence.matchSecret) - && Objects.equals(joinSecret, presence.joinSecret) - && Objects.equals(spectateSecret, presence.spectateSecret); - } - - @Override - public int hashCode() - { - return Objects.hash(state, details, startTimestamp, endTimestamp, largeImageKey, largeImageText, smallImageKey, - smallImageText, partyId, partySize, partyMax, matchSecret, joinSecret, spectateSecret, instance); - } - - @Override - protected List getFieldOrder() - { - return FIELD_ORDER; - } -} diff --git a/src/main/java/club/minnced/discord/rpc/DiscordUser.java b/src/main/java/club/minnced/discord/rpc/DiscordUser.java deleted file mode 100644 index 24173e09a..000000000 --- a/src/main/java/club/minnced/discord/rpc/DiscordUser.java +++ /dev/null @@ -1,85 +0,0 @@ -package club.minnced.discord.rpc; - -import com.sun.jna.Structure; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -/* -typedef struct DiscordUser { - const char* userId; - const char* username; - const char* discriminator; - const char* avatar; -} DiscordUser; - */ - -/** - * Struct binding for a discord join request. - */ -public class DiscordUser extends Structure -{ - private static final List FIELD_ORDER = Collections.unmodifiableList(Arrays.asList( - "userId", - "username", - "discriminator", - "avatar" - )); - - public DiscordUser(String encoding) { - super(); - setStringEncoding(encoding); - } - - public DiscordUser() { - this("UTF-8"); - } - - /** - * The userId for the user that requests to join - */ - public String userId; - - /** - * The username of the user that requests to join - */ - public String username; - - /** - * The discriminator of the user that requests to join - */ - public String discriminator; - - /** - * The avatar of the user that requests to join - */ - public String avatar; - - @Override - public boolean equals(Object o) - { - if (this == o) - return true; - if (!(o instanceof DiscordUser)) - return false; - DiscordUser that = (DiscordUser) o; - return Objects.equals(userId, that.userId) - && Objects.equals(username, that.username) - && Objects.equals(discriminator, that.discriminator) - && Objects.equals(avatar, that.avatar); - } - - @Override - public int hashCode() - { - return Objects.hash(userId, username, discriminator, avatar); - } - - @Override - protected List getFieldOrder() - { - return FIELD_ORDER; - } -}