From 58330bdcc2c28838772e1bbc52bc2a1d0e3eb574 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Mon, 22 Nov 2021 21:57:09 -0500 Subject: [PATCH] API: re-include some previous changes The API will not be updated/promoted until after 1.18 so the team can focus on the update. --- .../main/java/org/geysermc/api/Geyser.java | 26 +++++++++++-- .../{GeyserApi.java => GeyserApiBase.java} | 12 +----- .../org/geysermc/api/geyser/package-info.java | 29 --------------- .../org/geysermc/geyser/api/GeyserApi.java} | 37 ++++++++++++++++--- .../api/connection}/GeyserConnection.java | 2 +- 5 files changed, 56 insertions(+), 50 deletions(-) rename api/base/src/main/java/org/geysermc/api/{GeyserApi.java => GeyserApiBase.java} (89%) delete mode 100644 api/base/src/main/java/org/geysermc/api/geyser/package-info.java rename api/{base/src/main/java/org/geysermc/api/geyser/GeyserExtensionApi.java => geyser/src/main/java/org/geysermc/geyser/api/GeyserApi.java} (67%) rename api/{base/src/main/java/org/geysermc/api/geyser => geyser/src/main/java/org/geysermc/geyser/api/connection}/GeyserConnection.java (96%) diff --git a/api/base/src/main/java/org/geysermc/api/Geyser.java b/api/base/src/main/java/org/geysermc/api/Geyser.java index 64b4f02b5..c5ae7fa4d 100644 --- a/api/base/src/main/java/org/geysermc/api/Geyser.java +++ b/api/base/src/main/java/org/geysermc/api/Geyser.java @@ -32,14 +32,14 @@ import org.checkerframework.checker.nullness.qual.NonNull; */ @NonNull public class Geyser { - private static GeyserApi api; + private static GeyserApiBase api; /** * Returns the base api. * * @return the base api */ - public static GeyserApi api() { + public static GeyserApiBase api() { if (api == null) { throw new RuntimeException("Api has not been registered yet!"); } @@ -47,6 +47,26 @@ public class Geyser { return api; } + /** + * Returns the api of the given type. + * + * @param apiClass the api class + * @param the type + * @return the api of the given type + */ + @SuppressWarnings("unchecked") + public static T api(@NonNull Class apiClass) { + if (apiClass.isInstance(api)) { + return (T) api; + } + + if (api == null) { + throw new RuntimeException("Api has not been registered yet!"); + } else { + throw new RuntimeException("Api was not an instance of " + apiClass + "! Was " + api.getClass().getCanonicalName()); + } + } + /** * Registers the given api type. The api cannot be * registered if {@link #registered()} is true as @@ -54,7 +74,7 @@ public class Geyser { * * @param api the api */ - public static void set(@NonNull GeyserApi api) { + public static void set(@NonNull GeyserApiBase api) { if (Geyser.api != null) { throw new RuntimeException("Cannot redefine already registered api!"); } diff --git a/api/base/src/main/java/org/geysermc/api/GeyserApi.java b/api/base/src/main/java/org/geysermc/api/GeyserApiBase.java similarity index 89% rename from api/base/src/main/java/org/geysermc/api/GeyserApi.java rename to api/base/src/main/java/org/geysermc/api/GeyserApiBase.java index fec8cbb3c..1acf9b5f8 100644 --- a/api/base/src/main/java/org/geysermc/api/GeyserApi.java +++ b/api/base/src/main/java/org/geysermc/api/GeyserApiBase.java @@ -27,7 +27,6 @@ package org.geysermc.api; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import org.geysermc.api.geyser.GeyserExtensionApi; import org.geysermc.api.session.Connection; import java.util.List; @@ -36,7 +35,7 @@ import java.util.UUID; /** * The base API class. */ -public interface GeyserApi { +public interface GeyserApiBase { /** * Gets the session from the given UUID, if applicable. The player must be logged in to the Java server * for this to return a non-null value. @@ -75,15 +74,6 @@ public interface GeyserApi { @NonNull List onlineConnections(); - /** - * Returns this as the Geyser extension API, if the platform supports it. - * - * @return the extension API, if this platform supports it. - */ - default GeyserExtensionApi asExtensionApi() { - return null; - } - /** * @return the major API version. Bumped whenever a significant breaking change or feature addition is added. */ diff --git a/api/base/src/main/java/org/geysermc/api/geyser/package-info.java b/api/base/src/main/java/org/geysermc/api/geyser/package-info.java deleted file mode 100644 index d36f70d6b..000000000 --- a/api/base/src/main/java/org/geysermc/api/geyser/package-info.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2019-2021 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -/** - * - */ -package org.geysermc.api.geyser; \ No newline at end of file diff --git a/api/base/src/main/java/org/geysermc/api/geyser/GeyserExtensionApi.java b/api/geyser/src/main/java/org/geysermc/geyser/api/GeyserApi.java similarity index 67% rename from api/base/src/main/java/org/geysermc/api/geyser/GeyserExtensionApi.java rename to api/geyser/src/main/java/org/geysermc/geyser/api/GeyserApi.java index 2a1266d04..6a5e7ccab 100644 --- a/api/base/src/main/java/org/geysermc/api/geyser/GeyserExtensionApi.java +++ b/api/geyser/src/main/java/org/geysermc/geyser/api/GeyserApi.java @@ -23,14 +23,20 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.geyser; +package org.geysermc.geyser.api; -import org.geysermc.api.GeyserApi; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.geysermc.api.GeyserApiBase; +import org.geysermc.geyser.api.connection.GeyserConnection; + +import java.util.List; +import java.util.UUID; /** * Represents the API used in Geyser. */ -public interface GeyserExtensionApi extends GeyserApi { +public interface GeyserApi extends GeyserApiBase { /** * Shuts down the current Geyser instance. */ @@ -49,8 +55,27 @@ public interface GeyserExtensionApi extends GeyserApi { */ boolean productionEnvironment(); + /** + * {@inheritDoc} + */ @Override - default GeyserExtensionApi asExtensionApi() { - return this; - } + @Nullable GeyserConnection connectionByUuid(@NonNull UUID uuid); + + /** + * {@inheritDoc} + */ + @Override + @Nullable GeyserConnection connectionByXuid(@NonNull String xuid); + + /** + * {@inheritDoc} + */ + @Override + @Nullable GeyserConnection connectionByName(@NonNull String name); + + /** + * {@inheritDoc} + */ + @NonNull + List onlineConnections(); } diff --git a/api/base/src/main/java/org/geysermc/api/geyser/GeyserConnection.java b/api/geyser/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java similarity index 96% rename from api/base/src/main/java/org/geysermc/api/geyser/GeyserConnection.java rename to api/geyser/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java index 5c21fa1de..a38dc2f91 100644 --- a/api/base/src/main/java/org/geysermc/api/geyser/GeyserConnection.java +++ b/api/geyser/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.geyser; +package org.geysermc.geyser.api.connection; import org.geysermc.api.session.Connection;