Skip to content
This repository was archived by the owner on Oct 23, 2021. It is now read-only.

Commit 02e17c6

Browse files
Merge pull request #6 from MinnDevelopment/javadoc
1.2 Javadoc & Sources Closes #7 Closes #1
2 parents ac5097e + cdd98ec commit 02e17c6

File tree

8 files changed

+365
-13
lines changed

8 files changed

+365
-13
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ src/test/*
22
out/*
33
build/*
44
.idea/*
5+
.classpath
6+
.settings/*
7+
bin/*
8+
.project

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
[ ![jitpack](https://jitpack.io/v/MinnDevelopment/Java-DiscordRPC.svg) ](https://jitpack.io/#MinnDevelopment/Java-DiscordRPC)
22
# Java-DiscordRPC
33

4-
This library contains Java bindings for [Discord's official RPC SDK](https://github.com/discordapp/discord-rpc) using JNA.
4+
This library contains Java bindings for [Discord's official RPC SDK](https://github.com/discordapp/discord-rpc) using JNA.
55

66
This project provides binaries for `linux-x86-64`, `win32-x86-64` and `darwin`.
77

8-
If, on macOS, you get the following message:
9-
```
10-
Error in LSRegisterURL: -10811
11-
```
12-
it can safely be ignored.
8+
If, on macOS, you get the following message which can be ignored: `Error in LSRegisterURL: -10811`
9+
10+
## Documentation
11+
12+
You can see the official discord documentation in the [API Documentation](https://discordapp.com/developers/docs/rich-presence/how-to).
13+
<br>Alternatively you may visist the javadoc at [jitpack](https://jitpack.io/com/github/MinnDevelopment/Java-DiscordRPC/master-SNAPSHOT/javadoc/index.html).
1314

1415
## Examples
1516

1617
```java
1718
import club.minnced.discord.rpc.*;
1819

1920
public class Main {
20-
2121
public static void main(String[] args) {
2222
DiscordRPC lib = DiscordRPC.INSTANCE;
2323
String applicationId = "";
@@ -39,12 +39,15 @@ public class Main {
3939
}
4040
}, "RPC-Callback-Handler").start();
4141
}
42-
4342
}
4443
```
4544

45+
> Note: To reveal this presence you have to start a window for your application.
46+
4647
## License
48+
4749
Java-DiscordRPC is licensed under the Apache 2.0 License. The base DiscordRPC is licensed under the MIT license.
4850

4951
## Contributing
52+
5053
Find something that is lacking? Fork the project and pull request!

build.gradle

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
*/
1616
plugins {
1717
id 'com.github.johnrengelman.shadow' version '2.0.1'
18+
id 'maven-publish'
1819
}
1920

2021
group 'club.minnced'
21-
version '1.0-SNAPSHOT'
22+
version '1.2'
2223

2324
apply plugin: 'java'
2425

25-
build.dependsOn shadowJar
26+
2627

2728
sourceCompatibility = 1.8
2829
targetCompatibility = 1.8
@@ -34,3 +35,72 @@ repositories {
3435
dependencies {
3536
compile 'net.java.dev.jna:jna:4.4.0'
3637
}
38+
39+
wrapper {
40+
gradleVersion = '4.2.1'
41+
}
42+
43+
// Publishing
44+
45+
task sources(type: Copy) {
46+
from 'src/main/java'
47+
into "$buildDir/sources"
48+
}
49+
50+
classes.dependsOn sources
51+
52+
jar {
53+
baseName = project.name
54+
manifest {
55+
attributes 'Implementation-Version': version
56+
attributes 'Target-Platforms': 'win32-x86-64, linux-x86-64, darwin'
57+
}
58+
59+
dependsOn sources
60+
}
61+
62+
javadoc {
63+
failOnError = false
64+
options.encoding = 'UTF-8'
65+
options.addStringOption('-html5') // jdk-9 docs
66+
67+
dependsOn sources
68+
source = sources.destinationDir
69+
}
70+
71+
task sourcesJar(type: Jar, dependsOn: classes) {
72+
classifier = 'sources'
73+
from "$buildDir/sources"
74+
}
75+
76+
task javadocJar(type: Jar, dependsOn: javadoc) {
77+
classifier = 'javadoc'
78+
from javadoc.destinationDir
79+
}
80+
81+
publishing {
82+
publications {
83+
MavenProject(MavenPublication) {
84+
from components.java
85+
groupId group
86+
artifactId archivesBaseName
87+
version version
88+
89+
artifact javadocJar
90+
artifact sourcesJar
91+
}
92+
}
93+
}
94+
95+
build {
96+
dependsOn clean
97+
dependsOn jar
98+
dependsOn javadocJar
99+
dependsOn sourcesJar
100+
dependsOn shadowJar
101+
102+
jar.mustRunAfter clean
103+
javadocJar.mustRunAfter jar
104+
sourcesJar.mustRunAfter javadocJar
105+
shadowJar.mustRunAfter sourcesJar
106+
}

src/main/java/club/minnced/discord/rpc/DiscordEventHandlers.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,39 @@
3333
void (*joinRequest)(const DiscordJoinRequest* request);
3434
} DiscordEventHandlers;
3535
*/
36-
36+
/**
37+
* Struct containing handlers for RPC events
38+
* <br>Provided handlers can be null.
39+
*/
3740
public class DiscordEventHandlers extends Structure
3841
{
42+
/**
43+
* Handler function for the ready event
44+
*/
3945
public interface OnReady extends Callback
4046
{
4147
void accept();
4248
}
4349

50+
/**
51+
* Handler function for the exceptional events (error, disconnect)
52+
*/
4453
public interface OnStatus extends Callback
4554
{
4655
void accept(int errorCode, String message);
4756
}
4857

58+
/**
59+
* Handler function for game update events (joinGame, spectateGame)
60+
*/
4961
public interface OnGameUpdate extends Callback
5062
{
5163
void accept(String secret);
5264
}
5365

66+
/**
67+
* Handler function for user join requests
68+
*/
5469
public interface OnJoinRequest extends Callback
5570
{
5671
void accept(DiscordJoinRequest request);
@@ -65,11 +80,29 @@ public interface OnJoinRequest extends Callback
6580
"joinRequest"
6681
));
6782

83+
/**
84+
* Called when the RPC connection has been established
85+
*/
6886
public OnReady ready;
87+
/**
88+
* Called when the RPC connection has been severed
89+
*/
6990
public OnStatus disconnected;
91+
/**
92+
* Called when an internal error is caught within the SDK
93+
*/
7094
public OnStatus errored;
95+
/**
96+
* Called when the logged in user joined a game
97+
*/
7198
public OnGameUpdate joinGame;
99+
/**
100+
* Called when the logged in user joined to spectate a game
101+
*/
72102
public OnGameUpdate spectateGame;
103+
/**
104+
* Called when another discord user wants to join the game of the logged in user
105+
*/
73106
public OnJoinRequest joinRequest;
74107

75108
@Override

src/main/java/club/minnced/discord/rpc/DiscordJoinRequest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
const char* avatar;
3030
} DiscordJoinRequest;
3131
*/
32-
32+
/**
33+
* Struct binding for a discord join request.
34+
*/
3335
public class DiscordJoinRequest extends Structure
3436
{
3537
private static final List<String> FIELD_ORDER = Collections.unmodifiableList(Arrays.asList(
@@ -38,8 +40,17 @@ public class DiscordJoinRequest extends Structure
3840
"avatar"
3941
));
4042

43+
/**
44+
* The userId for the user that requests to join
45+
*/
4146
public String userId;
47+
/**
48+
* The username of the user that requests to join
49+
*/
4250
public String username;
51+
/**
52+
* The avatar of the user that requests to join
53+
*/
4354
public String avatar;
4455

4556
@Override

src/main/java/club/minnced/discord/rpc/DiscordRPC.java

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,134 @@
1919
import com.sun.jna.Library;
2020
import com.sun.jna.Native;
2121

22+
/**
23+
* Core library binding for the official <a href="https://github.com/discordapp/discord-rpc" target="_blank">Discord RPC SDK</a>.
24+
* <br>Use {@link #INSTANCE} to access this library.
25+
*
26+
* <h1>Supported Architectures</h1>
27+
* <ul>
28+
* <li>Windows x86-64</li>
29+
* <li>Linux x86-64</li>
30+
* <li>Darwin</li>
31+
* </ul>
32+
*/
2233
public interface DiscordRPC extends Library
2334
{
35+
/**
36+
* Library instance.
37+
*/
2438
DiscordRPC INSTANCE = Native.loadLibrary("discord-rpc", DiscordRPC.class);
2539

40+
/**
41+
* Used to decline a request via {@link #Discord_Respond(String, int)}
42+
* @see #DISCORD_REPLY_YES
43+
*/
2644
int DISCORD_REPLY_NO = 0;
45+
/**
46+
* Used to accept a request via {@link #Discord_Respond(String, int)}
47+
* @see #DISCORD_REPLY_NO
48+
*/
2749
int DISCORD_REPLY_YES = 1;
50+
/**
51+
* Currently unsused response, treated like NO.
52+
* Used with {@link #Discord_Respond(String, int)}
53+
* @see #DISCORD_REPLY_NO
54+
*/
2855
int DISCORD_REPLY_IGNORE = 2;
2956

57+
/**
58+
* Initializes the library, supply with application details and event handlers.
59+
* Handlers are only called when the {@link #Discord_RunCallbacks()} method is invoked!
60+
* <br><b>Before closing the application it is recommended to call {@link #Discord_Shutdown()}</b>
61+
*
62+
* @param applicationId
63+
* The ID for this RPC application,
64+
* retrieved from the <a href="https://discordappc.com/developers/applications/me" target="_blank">developer dashboard</a>
65+
* @param handlers
66+
* Nullable instance of {@link club.minnced.discord.rpc.DiscordEventHandlers}
67+
* @param autoRegister
68+
* {@code true} to automatically call {@link #Discord_RegisterSteamGame(String, String)} or {@link #Discord_Register(String, String)}
69+
* @param steamId
70+
* Possible steam ID of the running game
71+
*/
3072
void Discord_Initialize(String applicationId,
3173
DiscordEventHandlers handlers,
3274
boolean autoRegister,
3375
String steamId);
76+
77+
/**
78+
* Shuts the RPC connection down.
79+
* If not currently connected, this does nothing.
80+
*/
3481
void Discord_Shutdown();
3582

83+
/**
84+
* Executes the registered handlers for currently queued events.
85+
* <br>If this is not called the handlers will not receive any events!
86+
*
87+
* <p>It is recommended to call this in a <u>2 second interval</u>
88+
*/
3689
void Discord_RunCallbacks();
90+
91+
/**
92+
* Polls events from the RPC pipe and pushes the currently queued presence.
93+
* <br>This will be performed automatically if the attached binary
94+
* has an enabled IO thread (default)
95+
*
96+
* <p><b>If the IO-Thread has been enabled this will not be supported!</b>
97+
*/
3798
void Discord_UpdateConnection();
3899

100+
/**
101+
* Updates the currently set presence of the logged in user.
102+
* <br>Note that the client only updates its presence every <b>15 seconds</b>
103+
* and queues all additional presence updates.
104+
*
105+
* @param struct
106+
* The new presence to use, or null to reset
107+
*
108+
* @see club.minnced.discord.rpc.DiscordRichPresence
109+
*/
39110
void Discord_UpdatePresence(DiscordRichPresence struct);
111+
112+
/**
113+
* Responds to the given user with the specified reply type.
114+
*
115+
* <h1>Possible Replies</h1>
116+
* <ul>
117+
* <li>{@link #DISCORD_REPLY_NO}</li>
118+
* <li>{@link #DISCORD_REPLY_YES}</li>
119+
* <li>{@link #DISCORD_REPLY_IGNORE}</li>
120+
* </ul>
121+
*
122+
* @param userid
123+
* The id of the user to respond to
124+
* @param reply
125+
* The reply type
126+
*
127+
* @see club.minnced.discord.rpc.DiscordJoinRequest#userId DiscordJoinRequest.userId
128+
*/
40129
void Discord_Respond(String userid, int reply);
130+
131+
/**
132+
* Registers the given application so it can be run by the discord client. {@code discord-<appid>://}
133+
*
134+
* @param applicationId
135+
* The ID of the application to register
136+
* @param command
137+
* The command for the application startup, or {@code null} to use the
138+
* current executable's path
139+
*/
140+
void Discord_Register(String applicationId, String command);
141+
142+
/**
143+
* Similar to {@link #Discord_Register(String, String)} but uses the steam
144+
* game's installation path.
145+
*
146+
* @param applicationId
147+
* The ID of the application to register
148+
* @param steamId
149+
* The steam ID for the game
150+
*/
151+
void Discord_RegisterSteamGame(String applicationId, String steamId);
41152
}

0 commit comments

Comments
 (0)