mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
API: change player class to Connection
This commit is contained in:
parent
5b415cea68
commit
966c2155ad
394 changed files with 1103 additions and 1114 deletions
|
@ -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!");
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import org.geysermc.api.session.Connection;
|
||||
|
||||
/**
|
||||
* Represents a player session used in Geyser.
|
||||
*/
|
||||
public interface GeyserConnection extends Connection {
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import org.geysermc.api.GeyserApi;
|
||||
|
||||
/**
|
||||
* Represents the API used in Geyser.
|
||||
*/
|
||||
public interface GeyserExtensionApi extends GeyserApi {
|
||||
/**
|
||||
* Shuts down the current Geyser instance.
|
||||
*/
|
||||
void shutdown();
|
||||
|
||||
/**
|
||||
* Reloads the current Geyser instance.
|
||||
*/
|
||||
void reload();
|
||||
|
||||
/**
|
||||
* Gets if this Geyser instance is running in an IDE. This only needs to be used in cases where files
|
||||
* expected to be in a jarfile are not present.
|
||||
*
|
||||
* @return true if the version number is not 'DEV'.
|
||||
*/
|
||||
boolean productionEnvironment();
|
||||
|
||||
@Override
|
||||
default GeyserExtensionApi asExtensionApi() {
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -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;
|
|
@ -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();
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue