67 lines
1.7 KiB
Java
67 lines
1.7 KiB
Java
|
package xyz.etztech.core.web;
|
||
|
|
||
|
import com.google.gson.JsonArray;
|
||
|
import com.google.gson.JsonElement;
|
||
|
import com.google.gson.JsonObject;
|
||
|
import com.google.gson.JsonParser;
|
||
|
import org.bukkit.ChatColor;
|
||
|
|
||
|
import java.util.logging.Logger;
|
||
|
|
||
|
public class CoreResponse {
|
||
|
|
||
|
protected JsonObject json;
|
||
|
private Boolean status;
|
||
|
private String message;
|
||
|
|
||
|
private static Logger log = Logger.getLogger("Minecraft");
|
||
|
|
||
|
public CoreResponse(JsonArray httpResponse) {
|
||
|
json = httpResponse.get(0).getAsJsonObject();
|
||
|
setStatus(json.get("status").getAsBoolean());
|
||
|
setMessage(json.get("message").getAsString());
|
||
|
}
|
||
|
|
||
|
public CoreResponse(JsonObject httpResponse) {
|
||
|
json = httpResponse;
|
||
|
setStatus(httpResponse.get("status").getAsBoolean());
|
||
|
setMessage(httpResponse.get("message").getAsString());
|
||
|
}
|
||
|
|
||
|
public CoreResponse(String rawReponse) {
|
||
|
JsonParser parser = new JsonParser();
|
||
|
try {
|
||
|
json = (JsonObject) parser.parse(rawReponse);
|
||
|
setStatus(json.get("status").getAsBoolean());
|
||
|
setMessage(json.get("message").getAsString());
|
||
|
} catch (Exception ex) {
|
||
|
log.warning("Could not parse JSON result");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public Boolean getStatus() {
|
||
|
return status;
|
||
|
}
|
||
|
|
||
|
public void setStatus(Boolean status) {
|
||
|
this.status = status;
|
||
|
}
|
||
|
|
||
|
public String getMessage() {
|
||
|
return message;
|
||
|
}
|
||
|
|
||
|
public void setMessage(String message) {
|
||
|
this.message = message;
|
||
|
}
|
||
|
|
||
|
|
||
|
public String getMCMessage() {
|
||
|
if (status) {
|
||
|
return ChatColor.GREEN + message;
|
||
|
} else {
|
||
|
return ChatColor.RED + message;
|
||
|
}
|
||
|
}
|
||
|
}
|