API: change player class to Connection

This commit is contained in:
Camotoy 2021-11-22 14:52:26 -05:00
parent 5b415cea68
commit 966c2155ad
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
394 changed files with 1103 additions and 1114 deletions

View file

@ -32,14 +32,14 @@ import org.checkerframework.checker.nullness.qual.NonNull;
*/
@NonNull
public class Geyser {
private static Api api;
private static GeyserApi api;
/**
* Returns the base api.
*
* @return the base api
*/
public static Api api() {
public static GeyserApi api() {
if (api == null) {
throw new RuntimeException("Api has not been registered yet!");
}
@ -47,26 +47,6 @@ 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 Api> 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
@ -74,7 +54,7 @@ public class Geyser {
*
* @param api the api
*/
public static void set(@NonNull Api api) {
public static void set(@NonNull GeyserApi api) {
if (Geyser.api != null) {
throw new RuntimeException("Cannot redefine already registered api!");
}

View file

@ -27,7 +27,8 @@ package org.geysermc.api;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.api.session.Session;
import org.geysermc.api.geyser.GeyserExtensionApi;
import org.geysermc.api.session.Connection;
import java.util.List;
import java.util.UUID;
@ -35,17 +36,16 @@ import java.util.UUID;
/**
* The base API class.
*/
public interface Api {
public interface GeyserApi {
/**
* Gets the session from the given
* UUID, if applicable.
* 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.
*
* @param uuid the UUID of the session
* @return the session from the given UUID, if applicable
*/
@Nullable
Session sessionByUuid(@NonNull UUID uuid);
Connection connectionByUuid(@NonNull UUID uuid);
/**
* Gets the session from the given
@ -55,7 +55,7 @@ public interface Api {
* @return the session from the given UUID, if applicable
*/
@Nullable
Session sessionByXuid(@NonNull String xuid);
Connection connectionByXuid(@NonNull String xuid);
/**
* Gets the session from the given
@ -65,7 +65,7 @@ public interface Api {
* @return the session from the given name, if applicable
*/
@Nullable
Session sessionByName(@NonNull String name);
Connection connectionByName(@NonNull String name);
/**
* Gets all the online sessions.
@ -73,5 +73,28 @@ public interface Api {
* @return all the online sessions
*/
@NonNull
List<? extends Session> onlineSessions();
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.
*/
default int majorApiVersion() {
return 0;
}
/**
* @return the minor API version. May be bumped for new API additions.
*/
default int minorApiVersion() {
return 0;
}
}

View file

@ -23,12 +23,12 @@
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.api.session;
package org.geysermc.api.geyser;
import org.geysermc.api.session.Session;
import org.geysermc.api.session.Connection;
/**
* Represents a player session used in Geyser.
*/
public interface GeyserSession extends Session {
public interface GeyserConnection extends Connection {
}

View file

@ -23,23 +23,14 @@
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.api;
package org.geysermc.api.geyser;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.api.Api;
import org.geysermc.api.Geyser;
import org.geysermc.api.session.Session;
import org.geysermc.geyser.api.session.GeyserSession;
import java.util.List;
import java.util.UUID;
import org.geysermc.api.GeyserApi;
/**
* Represents the API used in Geyser.
*/
public interface GeyserApi extends Api {
public interface GeyserExtensionApi extends GeyserApi {
/**
* Shuts down the current Geyser instance.
*/
@ -58,36 +49,8 @@ public interface GeyserApi extends Api {
*/
boolean productionEnvironment();
/**
* {@inheritDoc}
*/
@Override
@Nullable GeyserSession sessionByUuid(@NonNull UUID uuid);
/**
* {@inheritDoc}
*/
@Override
@Nullable GeyserSession sessionByXuid(@NonNull String xuid);
/**
* {@inheritDoc}
*/
@Override
@Nullable GeyserSession sessionByName(@NonNull String name);
/**
* {@inheritDoc}
*/
@NonNull
List<? extends GeyserSession> onlineSessions();
/**
* Gets the {@link GeyserApi}.
*
* @return the Geyser API
*/
static GeyserApi api() {
return Geyser.api(GeyserApi.class);
default GeyserExtensionApi asExtensionApi() {
return this;
}
}

View file

@ -0,0 +1,29 @@
/*
* 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;

View file

@ -30,29 +30,30 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.UUID;
/**
* Represents a player session.
* Represents a player connection.
*/
@NonNull
public interface Session {
public interface Connection {
/**
* Gets the name of the session.
* Gets the name of the connection.
*
* @return the name of the session
* @return the name of the connection
*/
String name();
/**
* Gets the {@link UUID} of the session.
* Gets the {@link UUID} of the connection.
*
* @return the UUID of the session
* @return the UUID of the connection
*/
UUID uuid();
/**
* Gets the XUID of the session.
* Gets the XUID of the connection.
*
* @return the XUID of the session
* @return the XUID of the connection
*/
String xuid();
}