Update to latest base api changes; proper extension *human* version checking

This commit is contained in:
onebeastchris 2024-07-20 18:01:22 +02:00
parent 74bd0bbf7c
commit 0d91e59a9a
4 changed files with 26 additions and 6 deletions

View file

@ -1,4 +1,6 @@
plugins {
// Allow blossom to mark sources root of templates
idea
id("geyser.publish-conventions")
alias(libs.plugins.blossom) apply true
}

View file

@ -23,12 +23,31 @@
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.api.util;
package org.geysermc.geyser.api;
import org.geysermc.api.util.ApiVersion;
/**
* Not a public API. For internal use only. May change without notice.
* This class is processed before compilation to insert build properties.
*/
public class BuildData {
public static final String VERSION = "{{ version }}";
class BuildData {
static final String VERSION = "{{ version }}";
static final ApiVersion API_VERSION;
static {
String[] parts = VERSION.split("\\.");
if (parts.length != 3) {
throw new RuntimeException("Invalid api version: " + VERSION);
}
try {
int human = Integer.parseInt(parts[0]);
int major = Integer.parseInt(parts[1]);
int minor = Integer.parseInt(parts[2]);
API_VERSION = new ApiVersion(human, major, minor);
} catch (Exception e) {
throw new RuntimeException("Invalid api version: " + VERSION, e);
}
}
}

View file

@ -37,7 +37,6 @@ import org.geysermc.geyser.api.event.EventRegistrar;
import org.geysermc.geyser.api.extension.ExtensionManager;
import org.geysermc.geyser.api.network.BedrockListener;
import org.geysermc.geyser.api.network.RemoteServer;
import org.geysermc.geyser.api.util.BuildData;
import org.geysermc.geyser.api.util.MinecraftVersion;
import org.geysermc.geyser.api.util.PlatformType;
@ -179,6 +178,6 @@ public interface GeyserApi extends GeyserApiBase {
* @return the current geyser api version
*/
default ApiVersion geyserApiVersion() {
return new ApiVersion(BuildData.VERSION);
return BuildData.API_VERSION;
}
}

View file

@ -195,7 +195,7 @@ public class GeyserExtensionLoader extends ExtensionLoader {
if (compatibility != ApiVersion.Compatibility.COMPATIBLE) {
// Workaround for the switch to the Geyser API version instead of the Base API version in extensions
if (compatibility == ApiVersion.Compatibility.HUMAN_DIFFER && description.majorApiVersion() == 1) {
if (compatibility == ApiVersion.Compatibility.HUMAN_DIFFER && description.humanApiVersion() == 1) {
GeyserImpl.getInstance().getLogger().warning("The extension %s requested the Base API version %s, which is deprecated in favor of specifying the Geyser API version. Please update the extension, or contact its developer."
.formatted(name, description.apiVersion()));
} else {