Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
Changed EditSelfRestAction from SimpleRestAction to RestAction
Browse files Browse the repository at this point in the history
Added Null-Checks to every JsonUtil #get function
Added Null-Check to MessageReceivedEvent#isFromServer, as this resulted in wrong results

Updated the pom.xml version
  • Loading branch information
JoshiCodes committed Jun 18, 2023
1 parent f7f3865 commit 1a9f0fd
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.joshicodes</groupId>
<artifactId>rja</artifactId>
<version>1.0-beta.1a</version>
<version>1.0-beta.1b</version>

<description>
Simple Java API for Revolt.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public boolean fromBot() {
}

public boolean isFromServer() {
return message.getChannel().complete() instanceof ServerChannel;
return channel == null || message.getChannel().complete() instanceof ServerChannel;
}

@Nullable
public Server getServer() {
if(!isFromServer()) {
if(!isFromServer()) {
return null;
}
return ((ServerChannel) message.getChannel().complete()).getServer().complete();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/de/joshicodes/rja/rest/EditSelfRestAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import de.joshicodes.rja.RJA;
import de.joshicodes.rja.object.user.User;
import de.joshicodes.rja.object.user.UserStatus;
import de.joshicodes.rja.requests.RequestHandler;
import de.joshicodes.rja.requests.rest.RestResponse;
import de.joshicodes.rja.requests.rest.user.self.EditSelfUserRequest;
import de.joshicodes.rja.util.Pair;

public class EditSelfRestAction extends SimpleRestAction<User> {
public class EditSelfRestAction extends RestAction<User> {

private final EditSelfUserRequest request;

Expand Down
1 change: 0 additions & 1 deletion src/main/java/de/joshicodes/rja/rest/SimpleRestAction.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.joshicodes.rja.rest;

import de.joshicodes.rja.RJA;
import de.joshicodes.rja.requests.rest.RestRequest;
import de.joshicodes.rja.util.Pair;

import java.util.function.Supplier;
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/de/joshicodes/rja/util/JsonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
public class JsonUtil {

public static String getString(JsonObject object, String key, String def) {
if(object == null) return def;
if(object.has(key)) {
JsonElement element = object.get(key);
if(element.isJsonPrimitive()) {
Expand All @@ -17,6 +18,7 @@ public static String getString(JsonObject object, String key, String def) {
}

public static int getInt(JsonObject object, String key, int i) {
if(object == null) return i;
if(object.has(key)) {
JsonElement element = object.get(key);
if(element.isJsonPrimitive()) {
Expand All @@ -27,6 +29,7 @@ public static int getInt(JsonObject object, String key, int i) {
}

public static boolean getBoolean(JsonObject object, String key, boolean b) {
if(object == null) return b;
if(object.has(key)) {
JsonElement element = object.get(key);
if(element.isJsonPrimitive()) {
Expand All @@ -37,16 +40,18 @@ public static boolean getBoolean(JsonObject object, String key, boolean b) {
}

public static JsonObject getObject(JsonObject object, String key, JsonObject o) {
if(object == null) return o;
if(object.has(key)) {
JsonElement element = object.get(key);
if(element.isJsonObject()) {
return element.getAsJsonObject();
}
}
return null;
return o;
}

public static JsonArray getArray(JsonObject object, String key, JsonArray def) {
if(object == null) return def;
if(object.has(key)) {
JsonElement element = object.get(key);
if(element.isJsonArray()) {
Expand Down

0 comments on commit 1a9f0fd

Please sign in to comment.