diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml
index adfb8ab..22c786e 100644
--- a/dependency-reduced-pom.xml
+++ b/dependency-reduced-pom.xml
@@ -4,7 +4,7 @@
com.frosthex
timingsystem.restapi
timingsystem.restapi
- 0.0.4
+ 0.0.5
http://maven.apache.org
src
diff --git a/pom.xml b/pom.xml
index 1f4780c..c1c70fe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
com.frosthex
timingsystem.restapi
- 0.0.5
+ 0.0.6
jar
timingsystem.restapi
http://maven.apache.org
diff --git a/src/com/frosthex/timingsystem/restapi/TimingSystemRESTApiPlugin.java b/src/com/frosthex/timingsystem/restapi/TimingSystemRESTApiPlugin.java
index bdedcb4..550e6db 100644
--- a/src/com/frosthex/timingsystem/restapi/TimingSystemRESTApiPlugin.java
+++ b/src/com/frosthex/timingsystem/restapi/TimingSystemRESTApiPlugin.java
@@ -37,7 +37,7 @@ public class TimingSystemRESTApiPlugin extends JavaPlugin {
private static TimingSystemRESTApiPlugin instance;
private static final int BSTATS_PLUGIN_ID = 18069;
- private static final String[] TIMING_SYSTEM_SUPPORTED_VERSIONS = {"1.2", "1.3"};
+ private static final String[] TIMING_SYSTEM_SUPPORTED_VERSIONS = {"1.2", "1.3", "1.5"};
public static ConsoleCommandSender clogger = Bukkit.getServer().getConsoleSender();
public static Logger log = Bukkit.getLogger();
@@ -108,7 +108,7 @@ public void onEnable() {
// Commands
getCommand("timingsystemrestapi").setExecutor(new TimingSystemRestApiCommand());
- // Strike the flint, ignite the spark IN 20 seconds
+ // Strike the flint, ignite the spark in 20 seconds
if (getConfig().getBoolean("rest_api_enabled")) {
Bukkit.getScheduler().runTaskLaterAsynchronously(instance, new Runnable() {
diff --git a/src/com/frosthex/timingsystem/restapi/network/SparkManager.java b/src/com/frosthex/timingsystem/restapi/network/SparkManager.java
index 606362e..13ab22b 100644
--- a/src/com/frosthex/timingsystem/restapi/network/SparkManager.java
+++ b/src/com/frosthex/timingsystem/restapi/network/SparkManager.java
@@ -52,14 +52,14 @@ public static void initSpark() {
port(port);
staticFiles.externalLocation(pathToPublicHtmlFolder);
- before("/api/v1/readonly/*", (request, response) -> {
+ before("/api/*/readonly/*", (request, response) -> {
// Allow all origins
response.header("Access-Control-Allow-Origin", "*");
// Authenticate READ ONLY
String apiKey = request.queryParams("api_key");
if (apiKey == null) {
- halt(401, "{\"error\":true,\"errorMessage\":\"Couldn't read api_key. Please provide a valid api_key in your request.\"}");
+ halt(401, "{\"error\":true,\"error_message\":\"Couldn't read api_key. Please provide a valid api_key in your request.\"}");
}
boolean authenticated = false;
@@ -72,13 +72,13 @@ public static void initSpark() {
}
if (!authenticated) {
- halt(401, "{\"error\":true,\"errorMessage\":\"Unknown api_key. Please provide a valid api_key in your request.\"}");
+ halt(401, "{\"error\":true,\"error_message\":\"Unknown api_key. Please provide a valid api_key in your request.\"}");
}
// TODO RATE LIMIT HERE
});
- before("/api/v1/readwrite/*", (request, response) -> {
+ before("/api/*/readwrite/*", (request, response) -> {
// Allow all origins
response.header("Access-Control-Allow-Origin", "*");
@@ -90,7 +90,7 @@ public static void initSpark() {
var tracks = TimingSystemAPI.getTracks();
if (tracks == null) {
- halt(401, "{\"error\":true,\"errorMessage\":\"Something went wrong TimingSystemAPI.getTracks() is null.\"}");
+ halt(401, "{\"error\":true,\"error_message\":\"Something went wrong. TimingSystemAPI.getTracks() is null.\"}");
}
JsonObject tracksResponseObject = new JsonObject();
@@ -112,17 +112,70 @@ public static void initSpark() {
return tracksResponseObject.toString();
});
+ // /api/v2/readonly/tracks
+ get("/api/v2/readonly/tracks", (request, response) -> {
+ var tracks = TimingSystemAPI.getTracks();
+
+ if (tracks == null) {
+ halt(401, "{\"error\":true,\"error_message\":\"Something went wrong. TimingSystemAPI.getTracks() is null.\"}");
+ }
+
+ JsonObject tracksResponseObject = new JsonObject();
+
+ tracksResponseObject.addProperty("number", tracks.size());
+
+ JsonArray tracksListObject = new JsonArray();
+
+ for (Track track : tracks) {
+ if (track.getCommandName() == null) {
+ continue;
+ }
+ JsonObject trackObj = new JsonObject();
+ trackObj.addProperty("command_name", track.getCommandName());
+ trackObj.addProperty("display_name", track.getDisplayName());
+ trackObj.addProperty("mode", track.getModeAsString());
+ trackObj.addProperty("type", track.getTypeAsString());
+ trackObj.addProperty("open", track.isOpen());
+ trackObj.addProperty("date_created", track.getDateCreated());
+ trackObj.addProperty("id", track.getId());
+ trackObj.addProperty("total_attempts", track.getTotalAttempts());
+ trackObj.addProperty("total_finishes", track.getTotalFinishes());
+ trackObj.addProperty("total_time_spent", track.getTotalTimeSpent());
+ trackObj.addProperty("weight", track.getWeight());
+ trackObj.addProperty("gui_item", track.getGuiItem().toString());
+ JsonArray optionsArray = new JsonArray();
+ for (char c : track.getOptions()) {
+ optionsArray.add(c);
+ }
+ trackObj.add("options", optionsArray);
+ trackObj.addProperty("owner", track.getOwner().getUniqueId().toString());
+ trackObj.add("spawn_location", serializeLocation(track.getSpawnLocation()));
+ JsonArray tagsArray = new JsonArray();
+ for (TrackTag trackTag : track.getTags()) {
+ tagsArray.add(trackTag.getValue());
+ }
+ trackObj.add("tags", tagsArray);
+
+ tracksListObject.add(trackObj);
+ }
+
+ tracksResponseObject.add("tracks", tracksListObject);
+
+ response.status(200);
+ return tracksResponseObject.toString();
+ });
+
// /api/v1/readonly/tracks/:trackname
get("/api/v1/readonly/tracks/:trackname", (request, response) -> {
String trackInternalName = request.params("trackname");
if (trackInternalName == null) {
- halt(401, "{\"error\":true,\"errorMessage\":\"Something went wrong. The track name provided is null.\"}");
+ halt(401, "{\"error\":true,\"error_message\":\"Something went wrong. The track name provided is null.\"}");
}
Optional