Skip to content

Commit

Permalink
[Fix] Fixed a cast exception that can occur with discriminator or `…
Browse files Browse the repository at this point in the history
…global_name`

- This further refines the future-proofing, and fixes an issue that can occur with no global name
  • Loading branch information
CDAGaming committed Jul 24, 2023
1 parent 74f08b2 commit eda7a16
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/jagrosh/discordipc/IPCClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,8 @@ private void readPipe(final IPCClient instance) {
final JsonObject u = data.getAsJsonObject("user");
final User user = new User(
u.getAsJsonPrimitive("username").getAsString(),
u.has("global_name") ? u.getAsJsonPrimitive("global_name").getAsString() : null,
u.has("discriminator") ? u.getAsJsonPrimitive("discriminator").getAsString() : "0",
u.has("global_name") && u.get("global_name").isJsonPrimitive() ? u.getAsJsonPrimitive("global_name").getAsString() : null,
u.has("discriminator") && u.get("discriminator").isJsonPrimitive() ? u.getAsJsonPrimitive("discriminator").getAsString() : "0",
Long.parseLong(u.getAsJsonPrimitive("id").getAsString()),
u.has("avatar") && u.get("avatar").isJsonPrimitive() ? u.getAsJsonPrimitive("avatar").getAsString() : null
);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/jagrosh/discordipc/entities/pipe/Pipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public static Pipe openPipe(IPCClient ipcClient, long clientId, HashMap<String,

pipe.currentUser = new User(
userData.getAsJsonPrimitive("username").getAsString(),
userData.has("global_name") ? userData.getAsJsonPrimitive("global_name").getAsString() : null,
userData.has("discriminator") ? userData.getAsJsonPrimitive("discriminator").getAsString() : "0",
userData.has("global_name") && userData.get("global_name").isJsonPrimitive() ? userData.getAsJsonPrimitive("global_name").getAsString() : null,
userData.has("discriminator") && userData.get("discriminator").isJsonPrimitive() ? userData.getAsJsonPrimitive("discriminator").getAsString() : "0",
Long.parseLong(userData.getAsJsonPrimitive("id").getAsString()),
userData.has("avatar") && userData.get("avatar").isJsonPrimitive() ? userData.getAsJsonPrimitive("avatar").getAsString() : null
);
Expand Down

0 comments on commit eda7a16

Please sign in to comment.