diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/main/MainErosController.kt b/src/main/java/de/bixilon/minosoft/gui/eros/main/MainErosController.kt
index 19fd4f22f..edb60d0de 100644
--- a/src/main/java/de/bixilon/minosoft/gui/eros/main/MainErosController.kt
+++ b/src/main/java/de/bixilon/minosoft/gui/eros/main/MainErosController.kt
@@ -79,7 +79,7 @@ class MainErosController : JavaFXWindowController() {
override fun init() {
logoFX.image = JavaFXUtil.MINOSOFT_LOGO
- versionTextFX.text = "Minosoft " + GitInfo.IS_INITIALIZED.decide(GitInfo.GIT_COMMIT_ID, StaticConfiguration.VERSION)
+ versionTextFX.text = "Minosoft " + GitInfo.IS_INITIALIZED.decide(GitInfo.GIT_COMMIT_ID_ABBREV, StaticConfiguration.VERSION)
iconMap = mapOf(
ErosMainActivities.PlAY to playIconFX,
ErosMainActivities.SETTINGS to settingsIconFX,
diff --git a/src/main/java/de/bixilon/minosoft/util/HTTP.java b/src/main/java/de/bixilon/minosoft/util/HTTP.java
deleted file mode 100644
index 9812ea1fd..000000000
--- a/src/main/java/de/bixilon/minosoft/util/HTTP.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Minosoft
- * Copyright (C) 2020 Moritz Zwerger
- *
- * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program. If not, see .
- *
- * This software is not affiliated with Mojang AB, the original developer of Minecraft.
- */
-
-package de.bixilon.minosoft.util;
-
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.http.HttpClient;
-import java.net.http.HttpRequest;
-import java.net.http.HttpResponse;
-import java.util.HashMap;
-
-@Deprecated
-public final class HTTP {
-
- public static HttpResponse postJson(String url, String json, HashMap headers) throws IOException, InterruptedException {
- headers.put("Content-Type", "application/json");
- headers.put("Accept", "application/json");
-
- HttpClient client = HttpClient.newHttpClient();
- HttpRequest request = HttpRequest.newBuilder()
- .uri(URI.create(url))
- .POST(HttpRequest.BodyPublishers.ofString(json))
- .headers(Util.headersMapToArray(headers))
- .build();
- return client.send(request, HttpResponse.BodyHandlers.ofString());
- }
-
- public static HttpResponse postJson(String url, JsonObject json) throws IOException, InterruptedException {
- return postJson(url, Util.GSON.toJson(json), new HashMap<>());
- }
-
- public static HttpResponse postJson(String url, String json) throws IOException, InterruptedException {
- return postJson(url, json, new HashMap<>());
- }
-
- public static HttpResponse get(String url, HashMap headers) throws IOException, InterruptedException {
- HttpClient client = HttpClient.newHttpClient();
- HttpRequest request = HttpRequest.newBuilder()
- .uri(URI.create(url))
- .headers(Util.headersMapToArray(headers))
- .build();
- return client.send(request, HttpResponse.BodyHandlers.ofString());
- }
-
- public static HttpResponse get(String url) throws IOException, InterruptedException {
- return get(url, new HashMap<>());
- }
-
-
- public static JsonElement getJson(String url, HashMap headers) throws IOException, InterruptedException {
- HttpResponse response = get(url, headers);
- if (response.statusCode() != 200) {
- throw new IOException();
- }
- return JsonParser.parseString(response.body());
- }
-
- public static JsonElement getJson(String url) throws IOException, InterruptedException {
- return getJson(url, new HashMap<>());
- }
-
- public static HttpResponse postData(String url, HashMap data) throws IOException, InterruptedException {
- HttpClient client = HttpClient.newHttpClient();
- HttpRequest request = HttpRequest.newBuilder()
- .uri(URI.create(url))
- .POST(HttpRequest.BodyPublishers.ofString(Util.mapToUrlQuery(data)))
- .header("Content-Type", "application/x-www-form-urlencoded")
- .build();
- return client.send(request, HttpResponse.BodyHandlers.ofString());
- }
-}
diff --git a/src/main/java/de/bixilon/minosoft/util/KUtil.kt b/src/main/java/de/bixilon/minosoft/util/KUtil.kt
index fdbcbfb07..b7aa48abd 100644
--- a/src/main/java/de/bixilon/minosoft/util/KUtil.kt
+++ b/src/main/java/de/bixilon/minosoft/util/KUtil.kt
@@ -282,6 +282,10 @@ object KUtil {
return this.nullCast()
}
+ fun Any?.asList(): List {
+ return this.unsafeCast()
+ }
+
fun Any.toJson(beautiful: Boolean = false, adapter: JsonAdapter = JSONSerializer.ANY_ADAPTER): String {
val buffer = Buffer()
val jsonWriter: JsonWriter = JsonWriter.of(buffer)
@@ -308,6 +312,15 @@ object KUtil {
}
}
+ fun Any?.toLong(): Long {
+ return when (this) {
+ is Long -> this
+ is Number -> this.toLong()
+ is Int -> this.toLong()
+ else -> TODO()
+ }
+ }
+
fun Any?.toDouble(): Double {
return when (this) {
is Double -> this
diff --git a/src/main/java/de/bixilon/minosoft/util/http/HTTP2.kt b/src/main/java/de/bixilon/minosoft/util/http/HTTP2.kt
index 4feddd611..e2a7c4cdf 100644
--- a/src/main/java/de/bixilon/minosoft/util/http/HTTP2.kt
+++ b/src/main/java/de/bixilon/minosoft/util/http/HTTP2.kt
@@ -59,4 +59,26 @@ object HTTP2 {
)
)
}
+
+ fun String.get(bodyBuilder: (String) -> Response, headers: Map = mapOf()): HTTPResponse {
+ val client = HttpClient.newHttpClient()
+ val request = HttpRequest.newBuilder()
+ .uri(URI.create(this))
+ .GET()
+ .headers(*headers.headers())
+ .build()
+
+ val response = client.send(request, HttpResponse.BodyHandlers.ofString())
+ return HTTPResponse(response.statusCode(), bodyBuilder(response.body()))
+ }
+
+ fun String.getJson(headers: Map = mapOf()): HTTPResponse