mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
adapt to new base api changes
This commit is contained in:
parent
507819d66f
commit
4e68ca09fe
3 changed files with 37 additions and 20 deletions
|
|
@ -58,6 +58,14 @@ public interface ExtensionDescription {
|
|||
@NonNull
|
||||
String main();
|
||||
|
||||
/**
|
||||
* Gets the extension's human api version
|
||||
*
|
||||
* @return the extension's human api version
|
||||
*/
|
||||
int humanApiVersion();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the extension's major api version
|
||||
*
|
||||
|
|
@ -73,11 +81,13 @@ public interface ExtensionDescription {
|
|||
int minorApiVersion();
|
||||
|
||||
/**
|
||||
* Gets the extension's patch api version
|
||||
*
|
||||
* @return the extension's patch api version
|
||||
* No longer in use. Geyser is now using an adaption of the romantic versioning scheme.
|
||||
* See <a href="https://gist.github.com/Redned235/a24a593026c11308dbcf73ab6e9d07d1">here</a> for details.
|
||||
*/
|
||||
int patchApiVersion();
|
||||
@Deprecated(forRemoval = true)
|
||||
default int patchApiVersion() {
|
||||
return minorApiVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the extension's api version.
|
||||
|
|
@ -85,7 +95,7 @@ public interface ExtensionDescription {
|
|||
* @return the extension's api version
|
||||
*/
|
||||
default String apiVersion() {
|
||||
return majorApiVersion() + "." + minorApiVersion() + "." + patchApiVersion();
|
||||
return humanApiVersion() + "." + majorApiVersion() + "." + minorApiVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -43,9 +43,9 @@ import java.util.regex.Pattern;
|
|||
public record GeyserExtensionDescription(@NonNull String id,
|
||||
@NonNull String name,
|
||||
@NonNull String main,
|
||||
int humanApiVersion,
|
||||
int majorApiVersion,
|
||||
int minorApiVersion,
|
||||
int patchApiVersion,
|
||||
@NonNull String version,
|
||||
@NonNull List<String> authors) implements ExtensionDescription {
|
||||
|
||||
|
|
@ -82,9 +82,9 @@ public record GeyserExtensionDescription(@NonNull String id,
|
|||
throw new InvalidDescriptionException(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_format", name, apiVersion));
|
||||
}
|
||||
String[] api = apiVersion.split("\\.");
|
||||
int majorApi = Integer.parseUnsignedInt(api[0]);
|
||||
int minorApi = Integer.parseUnsignedInt(api[1]);
|
||||
int patchApi = Integer.parseUnsignedInt(api[2]);
|
||||
int humanApi = Integer.parseUnsignedInt(api[0]);
|
||||
int majorApi = Integer.parseUnsignedInt(api[1]);
|
||||
int minorApi = Integer.parseUnsignedInt(api[2]);
|
||||
|
||||
List<String> authors = new ArrayList<>();
|
||||
if (source.author != null) {
|
||||
|
|
@ -94,7 +94,7 @@ public record GeyserExtensionDescription(@NonNull String id,
|
|||
authors.addAll(source.authors);
|
||||
}
|
||||
|
||||
return new GeyserExtensionDescription(id, name, main, majorApi, minorApi, patchApi, version, authors);
|
||||
return new GeyserExtensionDescription(id, name, main, humanApi, majorApi, minorApi, version, authors);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
|||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.geysermc.api.util.ApiVersion;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.api.GeyserApi;
|
||||
import org.geysermc.geyser.api.event.ExtensionEventBus;
|
||||
|
|
@ -49,6 +50,7 @@ import java.nio.file.FileSystems;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
|
@ -184,18 +186,23 @@ public class GeyserExtensionLoader extends ExtensionLoader {
|
|||
return;
|
||||
}
|
||||
|
||||
// Completely different API version - or if the extension requires new API features, being backwards compatible
|
||||
if (!GeyserApi.api().geyserApiVersion().isCompatible(description.majorApiVersion(), description.minorApiVersion(), description.patchApiVersion())) {
|
||||
// Check whether an extensions' requested api version is compatible
|
||||
ApiVersion.Compatibility compatibility = GeyserApi.api().geyserApiVersion().supportsRequestedVersion(
|
||||
description.humanApiVersion(),
|
||||
description.majorApiVersion(),
|
||||
description.minorApiVersion()
|
||||
);
|
||||
|
||||
// workaround for the switch to Geyser API version
|
||||
// remove this at some point - probably when we hit 2.0
|
||||
if (description.majorApiVersion() != 1) {
|
||||
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_version", name, description.apiVersion()));
|
||||
return;
|
||||
} else {
|
||||
GeyserImpl.getInstance().getLogger().warning("The extension " + name + " relies on the Base API version 1.0.0, which is deprecated in favor of specifying the Geyser API version. Please update the extension, or contact its developer.");
|
||||
}
|
||||
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) {
|
||||
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 {
|
||||
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_version", name, description.apiVersion()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
GeyserExtensionContainer container = this.loadExtension(path, description);
|
||||
extensions.put(id, path);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue