Skip to content

Commit

Permalink
[Change] Code Cleanup
Browse files Browse the repository at this point in the history
- Corrected documentation for several files
- Enforce Java 8+ behaviors, fully dropping Java 7 support (As tools exist now to handle downgrading)
  • Loading branch information
CDAGaming committed May 31, 2024
1 parent e8bba88 commit f9ca31c
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 16 deletions.
7 changes: 1 addition & 6 deletions src/main/java/com/jagrosh/discordipc/IPCClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -656,12 +656,7 @@ private void checkConnected(boolean connected) {
private void startReading() {
final IPCClient localInstance = this;

readThread = new Thread(new Runnable() {
@Override
public void run() {
IPCClient.this.readPipe(localInstance);
}
}, "IPCClient-Reader");
readThread = new Thread(() -> IPCClient.this.readPipe(localInstance), "IPCClient-Reader");
readThread.setDaemon(true);

if (debugMode) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/jagrosh/discordipc/IPCListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ public interface IPCListener {

/**
* Fired whenever a RichPresence activity informs us that
* a user has clicked a "ask to join" button.
* a user has clicked an "ask to join" button.
* <p>
* As opposed to {@link #onActivityJoin(IPCClient, String)},
* this also provides packaged {@link User} data.
*
* @param client The IPCClient receiving the event.
* @param secret The secret of the event, determined by the implementation and specified by the user.
* @param user The user who clicked the clicked the event, containing data on the account.
* @param user The user who clicked the event, containing data on the account.
*/
void onActivityJoinRequest(IPCClient client, String secret, User user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* @author John Grosh (john.a.grosh@gmail.com)
*/
public class RichPresence {
private static final int MAX_ALLOWED_BUTTONS = 2;
private final String state;
private final String details;
private final long startTimestamp;
Expand Down Expand Up @@ -75,7 +76,7 @@ public RichPresence(String state, String details, long startTimestamp, long endT
* Constructs a {@link JsonObject} representing a payload to send to discord
* to update a user's Rich Presence.
*
* <p>This is purely internal, and should not ever need to be called outside of
* <p>This is purely internal, and should not ever need to be called outside
* the library.
*
* @return A JSONObject payload for updating a user's Rich Presence.
Expand Down Expand Up @@ -161,7 +162,7 @@ public JsonObject toJson() {
if (secrets.has("join") || secrets.has("spectate") || secrets.has("match")) {
finalObject.add("secrets", secrets);
}
if (buttons != null && !buttons.isJsonNull() && buttons.size() > 0 && buttons.size() < 3) {
if (buttons != null && !buttons.isJsonNull() && !buttons.isEmpty() && buttons.size() <= MAX_ALLOWED_BUTTONS) {
finalObject.add("buttons", buttons);
}
finalObject.addProperty("instance", instance);
Expand Down Expand Up @@ -427,7 +428,7 @@ public Builder setButtons(JsonArray buttons) {
* Marks the {@link #setMatchSecret(String) matchSecret} as a game
* session with a specific beginning and end.
*
* @param instance Whether or not the {@code matchSecret} is a game
* @param instance Whether the {@code matchSecret} is a game
* with a specific beginning and end.
* @return This Builder.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/jagrosh/discordipc/entities/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.jagrosh.discordipc.IPCListener;

/**
* A encapsulation of a Discord User's data provided when a
* An encapsulation of a Discord User's data provided when a
* {@link IPCListener IPCListener} fires
* {@link IPCListener#onActivityJoinRequest(IPCClient, String, User)
* onActivityJoinRequest}.
Expand Down Expand Up @@ -155,7 +155,7 @@ public String getEffectiveAvatarUrl() {
}

/**
* Gets whether or not this User is a bot.
* Gets whether this User is a bot.
* <p>
* While, at the time of writing this documentation, bots cannot
* use Rich Presence features, there may be a time in the future
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ public void send(Packet.OpCode op, JsonObject data) {
* @param data The data to parse with.
* @return the resulting {@link Packet}
*/
@SuppressWarnings("deprecation")
public Packet receive(Packet.OpCode op, byte[] data) {
JsonObject packetData = new JsonParser().parse(new String(data)).getAsJsonObject();
Packet p = new Packet(op, packetData, ipcClient.getEncoding());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public enum PipeStatus {
* Status for when the Pipe has unexpectedly disconnected, either because
* of an exception, and/or due to bad data.
* <p>
* When the status of an Pipe becomes this, a call to
* When the status of a Pipe becomes this, a call to
* {@link IPCListener#onDisconnect(IPCClient, Throwable)} will be made if one
* has been provided to the IPCClient.
* <p>
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/jagrosh/discordipc/impl/Backoff.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.jagrosh.discordipc.impl;

import java.util.Random;
import java.util.concurrent.TimeUnit;

public class Backoff {
private final long minAmount;
private final long maxAmount;
private final Random randGenerator;
private long current;
private int fails;
private final Random randGenerator;

public Backoff(long min, long max) {
this.minAmount = min;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/jagrosh/discordipc/impl/WinRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Map;
import java.util.prefs.Preferences;

@SuppressWarnings("NegativeIntConstantInLongContext")
public class WinRegistry {
public static final int HKEY_CURRENT_USER = 0x80000001;
public static final int HKEY_LOCAL_MACHINE = 0x80000002;
Expand Down

0 comments on commit f9ca31c

Please sign in to comment.