From ac18ef605469dd6efd81cb275af45d62a38b0be6 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 16 Jan 2022 15:58:47 -0600 Subject: [PATCH] Remove adventure usage in API Unfortunately due to various platforms we support not having adventure support, we are unable to fully implement adventure into our API without having issues with shading or conflicts with other plugins. May look into what we can do in regards to classloading in the future but unfortunately it may not be a possibility at this point in time to support adventure inside of the API. --- api/geyser/pom.xml | 12 +++-------- .../api/extension/ExtensionManager.java | 16 +++++++------- .../extension/GeyserExtensionManager.java | 21 +++++++++---------- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/api/geyser/pom.xml b/api/geyser/pom.xml index b2f448589..435643b0a 100644 --- a/api/geyser/pom.xml +++ b/api/geyser/pom.xml @@ -33,9 +33,9 @@ provided - net.kyori - adventure-api - ${adventure.version} + org.geysermc + base-api + 2.0.0-SNAPSHOT compile @@ -44,11 +44,5 @@ 1.27 compile - - org.geysermc - base-api - 2.0.0-SNAPSHOT - compile - \ No newline at end of file diff --git a/api/geyser/src/main/java/org/geysermc/geyser/api/extension/ExtensionManager.java b/api/geyser/src/main/java/org/geysermc/geyser/api/extension/ExtensionManager.java index 65387a8c7..65d6c66da 100644 --- a/api/geyser/src/main/java/org/geysermc/geyser/api/extension/ExtensionManager.java +++ b/api/geyser/src/main/java/org/geysermc/geyser/api/extension/ExtensionManager.java @@ -25,10 +25,8 @@ package org.geysermc.geyser.api.extension; -import net.kyori.adventure.key.Key; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.Map; @@ -45,7 +43,7 @@ public abstract class ExtensionManager { * @return an extension with the given name */ @Nullable - public abstract Extension extension(@NotNull String name); + public abstract Extension extension(@NonNull String name); /** * Enables the given {@link Extension}. @@ -68,7 +66,7 @@ public abstract class ExtensionManager { * @return the extension loader for loading the given extension */ @Nullable - public abstract ExtensionLoader extensionLoader(@NotNull Extension extension); + public abstract ExtensionLoader extensionLoader(@NonNull Extension extension); /** * Gets all the {@link Extension}s currently loaded. @@ -85,7 +83,7 @@ public abstract class ExtensionManager { * @return the extension loader at the given identifier */ @Nullable - public abstract ExtensionLoader extensionLoader(@NonNull Key identifier); + public abstract ExtensionLoader extensionLoader(@NonNull String identifier); /** * Registers an {@link ExtensionLoader} with the given identifier. @@ -93,7 +91,7 @@ public abstract class ExtensionManager { * @param identifier the identifier * @param extensionLoader the extension loader */ - public abstract void registerExtensionLoader(@NonNull Key identifier, @NotNull ExtensionLoader extensionLoader); + public abstract void registerExtensionLoader(@NonNull String identifier, @NonNull ExtensionLoader extensionLoader); /** * Gets all the currently registered {@link ExtensionLoader}s. @@ -101,7 +99,7 @@ public abstract class ExtensionManager { * @return all the currently registered extension loaders */ @NonNull - public abstract Map extensionLoaders(); + public abstract Map extensionLoaders(); /** * Registers an {@link Extension} with the given {@link ExtensionLoader}. @@ -109,12 +107,12 @@ public abstract class ExtensionManager { * @param extension the extension * @param loader the loader */ - public abstract void register(@NotNull Extension extension, @NotNull ExtensionLoader loader); + public abstract void register(@NonNull Extension extension, @NonNull ExtensionLoader loader); /** * Loads all extensions from the given {@link ExtensionLoader}. */ - protected final void loadAllExtensions(@NotNull ExtensionLoader extensionLoader) { + protected final void loadAllExtensions(@NonNull ExtensionLoader extensionLoader) { extensionLoader.loadAllExtensions(this); } } diff --git a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionManager.java b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionManager.java index 936cde471..c125d010b 100644 --- a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionManager.java +++ b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionManager.java @@ -34,12 +34,12 @@ import org.geysermc.geyser.api.extension.ExtensionManager; import org.geysermc.geyser.api.extension.ExtensionLoader; import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.text.GeyserLocale; -import org.jetbrains.annotations.NotNull; import java.util.*; +import java.util.stream.Collectors; public class GeyserExtensionManager extends ExtensionManager { - private static final Key BASE_KEY = Key.key("geysermc", "base"); + private static final Key BASE_EXTENSION_LOADER_KEY = Key.key("geysermc", "base"); private final Map extensions = new LinkedHashMap<>(); private final Map extensionsLoaders = new LinkedHashMap<>(); @@ -47,8 +47,7 @@ public class GeyserExtensionManager extends ExtensionManager { public void init() { GeyserImpl.getInstance().getLogger().info(GeyserLocale.getLocaleStringLog("geyser.extensions.load.loading")); - this.registerExtensionLoader(BASE_KEY, new GeyserExtensionLoader()); - + Registries.EXTENSION_LOADERS.register(BASE_EXTENSION_LOADER_KEY, new GeyserExtensionLoader()); for (ExtensionLoader loader : this.extensionLoaders().values()) { this.loadAllExtensions(loader); } @@ -130,23 +129,23 @@ public class GeyserExtensionManager extends ExtensionManager { @Nullable @Override - public ExtensionLoader extensionLoader(@NonNull Key identifier) { - return Registries.EXTENSION_LOADERS.get(identifier); + public ExtensionLoader extensionLoader(@NonNull String identifier) { + return Registries.EXTENSION_LOADERS.get(Key.key(identifier)); } @Override - public void registerExtensionLoader(@NonNull Key identifier, @NotNull ExtensionLoader extensionLoader) { - Registries.EXTENSION_LOADERS.register(identifier, extensionLoader); + public void registerExtensionLoader(@NonNull String identifier, @NonNull ExtensionLoader extensionLoader) { + Registries.EXTENSION_LOADERS.register(Key.key(identifier), extensionLoader); } @NonNull @Override - public Map extensionLoaders() { - return Collections.unmodifiableMap(Registries.EXTENSION_LOADERS.get()); + public Map extensionLoaders() { + return Registries.EXTENSION_LOADERS.get().entrySet().stream().collect(Collectors.toMap(key -> key.getKey().asString(), Map.Entry::getValue)); } @Override - public void register(@NotNull Extension extension, @NotNull ExtensionLoader loader) { + public void register(@NonNull Extension extension, @NonNull ExtensionLoader loader) { this.extensionsLoaders.put(extension, loader); this.extensions.put(extension.name(), extension); }