mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Initial api draft
This commit is contained in:
parent
2c663e0ee5
commit
83ddbd7d1a
412 changed files with 1473 additions and 1131 deletions
27
api/base/pom.xml
Normal file
27
api/base/pom.xml
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>geyser-parent</artifactId>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<version>1.4.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>base-api</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>16</maven.compiler.source>
|
||||
<maven.compiler.target>16</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.checkerframework</groupId>
|
||||
<artifactId>checker-qual</artifactId>
|
||||
<version>3.19.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
79
api/base/src/main/java/org/geysermc/api/Api.java
Normal file
79
api/base/src/main/java/org/geysermc/api/Api.java
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.geysermc.api.session.Session;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* The base API class.
|
||||
*
|
||||
* @param <S> the session type
|
||||
*/
|
||||
public interface Api<S extends Session> {
|
||||
|
||||
/**
|
||||
* Gets the session from the given
|
||||
* UUID, if applicable.
|
||||
*
|
||||
* @param uuid the UUID of the session
|
||||
* @return the session from the given UUID, if applicable
|
||||
*/
|
||||
@Nullable
|
||||
S sessionByUuid(@NonNull UUID uuid);
|
||||
|
||||
/**
|
||||
* Gets the session from the given
|
||||
* XUID, if applicable.
|
||||
*
|
||||
* @param xuid the XUID of the session
|
||||
* @return the session from the given UUID, if applicable
|
||||
*/
|
||||
@Nullable
|
||||
S sessionByXuid(@NonNull String xuid);
|
||||
|
||||
/**
|
||||
* Gets the session from the given
|
||||
* name, if applicable.
|
||||
*
|
||||
* @param name the uuid of the session
|
||||
* @return the session from the given name, if applicable
|
||||
*/
|
||||
@Nullable
|
||||
S sessionByName(@NonNull String name);
|
||||
|
||||
/**
|
||||
* Gets all the online sessions.
|
||||
*
|
||||
* @return all the online sessions
|
||||
*/
|
||||
@NonNull
|
||||
List<S> onlineSessions();
|
||||
}
|
94
api/base/src/main/java/org/geysermc/api/Geyser.java
Normal file
94
api/base/src/main/java/org/geysermc/api/Geyser.java
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* General API class for Geyser.
|
||||
*/
|
||||
@NonNull
|
||||
public class Geyser {
|
||||
private static Api<?> api;
|
||||
|
||||
/**
|
||||
* Returns the base api.
|
||||
*
|
||||
* @return the base api
|
||||
*/
|
||||
public static Api<?> api() {
|
||||
if (api == null) {
|
||||
throw new RuntimeException("Api has not been registered yet!");
|
||||
}
|
||||
|
||||
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
|
||||
* an api has already been specified.
|
||||
*
|
||||
* @param api the api
|
||||
*/
|
||||
public static void set(@NonNull Api<?> api) {
|
||||
if (Geyser.api != null) {
|
||||
throw new RuntimeException("Cannot redefine already registered api!");
|
||||
}
|
||||
|
||||
Geyser.api = api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the api has been registered and
|
||||
* is ready for usage.
|
||||
*
|
||||
* @return if the api has been registered
|
||||
*/
|
||||
public static boolean registered() {
|
||||
return api != null;
|
||||
}
|
||||
}
|
58
api/base/src/main/java/org/geysermc/api/session/Session.java
Normal file
58
api/base/src/main/java/org/geysermc/api/session/Session.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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.session;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Represents a player session.
|
||||
*/
|
||||
@NonNull
|
||||
public interface Session {
|
||||
|
||||
/**
|
||||
* Gets the name of the session.
|
||||
*
|
||||
* @return the name of the session
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* Gets the {@link UUID} of the session.
|
||||
*
|
||||
* @return the UUID of the session
|
||||
*/
|
||||
UUID uuid();
|
||||
|
||||
/**
|
||||
* Gets the XUID of the session.
|
||||
*
|
||||
* @return the XUID of the session
|
||||
*/
|
||||
String xuid();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue