Add proper versioning

This commit is contained in:
Bjorn Beishline 2026-02-13 01:18:32 -07:00
parent 45d4ff1c0c
commit 56eff72525
2 changed files with 39 additions and 22 deletions

2
.gitignore vendored
View File

@ -19,6 +19,8 @@ java/patchbukkit/build/
java/patchbukkit/bin/
java/protoc-gen-ffi/build/
java/protoc-gen-ffi/bin/
java/patchbukkit-test-plugin/build/
java/patchbukkit-test-plugin/bin/
!rust/build/
# Examples

View File

@ -1,36 +1,51 @@
package org.patchbukkit;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.bukkit.Bukkit;
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() {
String result = "Unknown-Version";
return BUKKIT_VERSION;
}
InputStream stream = Bukkit.class.getClassLoader().getResourceAsStream(
"META-INF/maven/io.papermc.paper/paper-api/pom.properties"
);
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;
public static String getCurrentApiVersion() {
return API_VERSION;
}
}