3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-04 23:30:17 +01:00

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.
Dieser Commit ist enthalten in:
Camotoy 2021-11-22 21:57:09 -05:00
Ursprung c3eaee6267
Commit 58330bdcc2
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
5 geänderte Dateien mit 56 neuen und 50 gelöschten Zeilen

Datei anzeigen

@ -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 <T> the type
* @return the api of the given type
*/
@SuppressWarnings("unchecked")
public static <T extends GeyserApiBase> T api(@NonNull Class<T> 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!");
}

Datei anzeigen

@ -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<? extends Connection> 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.
*/

Datei anzeigen

@ -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;

Datei anzeigen

@ -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<? extends GeyserConnection> onlineConnections();
}

Datei anzeigen

@ -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;