Add proper versioning
This commit is contained in:
parent
45d4ff1c0c
commit
56eff72525
2
.gitignore
vendored
2
.gitignore
vendored
@ -19,6 +19,8 @@ java/patchbukkit/build/
|
|||||||
java/patchbukkit/bin/
|
java/patchbukkit/bin/
|
||||||
java/protoc-gen-ffi/build/
|
java/protoc-gen-ffi/build/
|
||||||
java/protoc-gen-ffi/bin/
|
java/protoc-gen-ffi/bin/
|
||||||
|
java/patchbukkit-test-plugin/build/
|
||||||
|
java/patchbukkit-test-plugin/bin/
|
||||||
!rust/build/
|
!rust/build/
|
||||||
|
|
||||||
# Examples
|
# Examples
|
||||||
|
|||||||
@ -1,36 +1,51 @@
|
|||||||
package org.patchbukkit;
|
package org.patchbukkit;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Properties;
|
import java.io.InputStreamReader;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
public final class Versioning {
|
public final class Versioning {
|
||||||
|
private static final String BUKKIT_VERSION;
|
||||||
|
private static final String API_VERSION;
|
||||||
|
|
||||||
|
static {
|
||||||
|
String bukkitVersion = "Unknown-Version";
|
||||||
|
String apiVersion = null;
|
||||||
|
try (final InputStream stream = Bukkit.class.getClassLoader().getResourceAsStream("apiVersioning.json")) {
|
||||||
|
if (stream == null) {
|
||||||
|
throw new IOException("apiVersioning.json not found in classpath");
|
||||||
|
}
|
||||||
|
|
||||||
|
final JsonObject jsonObject = new Gson()
|
||||||
|
.fromJson(new BufferedReader(new InputStreamReader(stream)), JsonObject.class);
|
||||||
|
|
||||||
|
if (jsonObject == null) {
|
||||||
|
throw new IOException("apiVersioning.json is not a valid JSON file");
|
||||||
|
}
|
||||||
|
|
||||||
|
bukkitVersion = jsonObject.get("version").getAsString();
|
||||||
|
apiVersion = jsonObject.get("currentApiVersion").getAsString();
|
||||||
|
} catch (final IOException ex) {
|
||||||
|
Logger.getLogger(Versioning.class.getName()).log(Level.SEVERE, "Could not get Bukkit version!", ex);
|
||||||
|
}
|
||||||
|
BUKKIT_VERSION = bukkitVersion;
|
||||||
|
if (apiVersion == null) {
|
||||||
|
apiVersion = "Unknown-Version";
|
||||||
|
}
|
||||||
|
API_VERSION = apiVersion;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getBukkitVersion() {
|
public static String getBukkitVersion() {
|
||||||
String result = "Unknown-Version";
|
return BUKKIT_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
InputStream stream = Bukkit.class.getClassLoader().getResourceAsStream(
|
public static String getCurrentApiVersion() {
|
||||||
"META-INF/maven/io.papermc.paper/paper-api/pom.properties"
|
return API_VERSION;
|
||||||
);
|
|
||||||
Properties properties = new Properties();
|
|
||||||
|
|
||||||
if (stream != null) {
|
|
||||||
try {
|
|
||||||
properties.load(stream);
|
|
||||||
|
|
||||||
result = properties.getProperty("version");
|
|
||||||
} catch (IOException ex) {
|
|
||||||
Logger.getLogger(Versioning.class.getName()).log(
|
|
||||||
Level.SEVERE,
|
|
||||||
"Could not get Bukkit version!",
|
|
||||||
ex
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user