Moved the base api to a separate repo

This commit is contained in:
Tim203 2023-02-09 17:31:00 +01:00
parent 25c2d30881
commit 21885949c7
No known key found for this signature in database
GPG Key ID: 736F3CD49EF01DBF
47 changed files with 19 additions and 565 deletions

View File

@ -1,7 +0,0 @@
dependencies {
api(libs.cumulus)
api(libs.events) {
exclude(group = "com.google.guava", module = "guava")
exclude(group = "org.lanternpowered", module = "lmbda")
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (c) 2019-2022 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 GeyserApiBase api;
/**
* Returns the base api.
*
* @return the base api
*/
@NonNull
public static GeyserApiBase 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 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 #isRegistered()} is true as
* an api has already been specified.
*
* @param api the api
*/
public static void set(@NonNull GeyserApiBase 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 isRegistered() {
return api != null;
}
}

View File

@ -1,130 +0,0 @@
/*
* Copyright (c) 2019-2022 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.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.common.value.qual.IntRange;
import org.geysermc.api.connection.Connection;
import org.geysermc.cumulus.form.Form;
import org.geysermc.cumulus.form.util.FormBuilder;
import java.util.List;
import java.util.UUID;
/**
* The base API class.
*/
public interface GeyserApiBase {
/**
* Gets the connection 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 connection
* @return the connection from the given UUID, if applicable
*/
@Nullable
Connection connectionByUuid(@NonNull UUID uuid);
/**
* Gets the connection from the given XUID, if applicable. This method only works for online connections.
*
* @param xuid the XUID of the session
* @return the connection from the given UUID, if applicable
*/
@Nullable
Connection connectionByXuid(@NonNull String xuid);
/**
* Method to determine if the given <b>online</b> player is a Bedrock player.
*
* @param uuid the uuid of the online player
* @return true if the given online player is a Bedrock player
*/
boolean isBedrockPlayer(@NonNull UUID uuid);
/**
* Sends a form to the given connection and opens it.
*
* @param uuid the uuid of the connection to open it on
* @param form the form to send
* @return whether the form was successfully sent
*/
boolean sendForm(@NonNull UUID uuid, @NonNull Form form);
/**
* Sends a form to the given connection and opens it.
*
* @param uuid the uuid of the connection to open it on
* @param formBuilder the formBuilder to send
* @return whether the form was successfully sent
*/
boolean sendForm(@NonNull UUID uuid, @NonNull FormBuilder<?, ?, ?> formBuilder);
/**
* Transfer the given connection to a server. A Bedrock player can successfully transfer to the same server they are
* currently playing on.
*
* @param uuid the uuid of the connection
* @param address the address of the server
* @param port the port of the server
* @return true if the transfer was a success
*/
boolean transfer(@NonNull UUID uuid, @NonNull String address, @IntRange(from = 0, to = 65535) int port);
/**
* Returns all the online connections.
*/
@NonNull
List<? extends Connection> onlineConnections();
/**
* Returns the amount of online connections.
*/
int onlineConnectionsCount();
/**
* Returns the prefix used by Floodgate. Will be null when the auth-type isn't Floodgate.
*/
@MonotonicNonNull
String usernamePrefix();
/**
* Returns the major API version. Bumped whenever a significant breaking change or feature addition is added.
*/
default int majorApiVersion() {
return 1;
}
/**
* Returns the minor API version. May be bumped for new API additions.
*/
default int minorApiVersion() {
return 0;
}
}

View File

@ -1,121 +0,0 @@
/*
* Copyright (c) 2019-2022 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.connection;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.common.value.qual.IntRange;
import org.geysermc.api.util.BedrockPlatform;
import org.geysermc.api.util.InputMode;
import org.geysermc.api.util.UiProfile;
import org.geysermc.cumulus.form.Form;
import org.geysermc.cumulus.form.util.FormBuilder;
import java.util.UUID;
/**
* Represents a player connection.
*/
public interface Connection {
/**
* Returns the bedrock name of the connection.
*/
@NonNull String bedrockUsername();
/**
* Returns the java name of the connection.
*/
@MonotonicNonNull
String javaUsername();
/**
* Returns the UUID of the connection.
*/
@MonotonicNonNull
UUID javaUuid();
/**
* Returns the XUID of the connection.
*/
@NonNull String xuid();
/**
* Returns the version of the Bedrock client.
*/
@NonNull String version();
/**
* Returns the platform that the connection is playing on.
*/
@NonNull BedrockPlatform platform();
/**
* Returns the language code of the connection.
*/
@NonNull String languageCode();
/**
* Returns the User Interface Profile of the connection.
*/
@NonNull UiProfile uiProfile();
/**
* Returns the Input Mode of the Bedrock client.
*/
@NonNull InputMode inputMode();
/**
* Returns whether the connection is linked.
* This will always return false when the auth-type isn't Floodgate.
*/
boolean isLinked();
/**
* Sends a form to the connection and opens it.
*
* @param form the form to send
* @return whether the form was successfully sent
*/
boolean sendForm(@NonNull Form form);
/**
* Sends a form to the connection and opens it.
*
* @param formBuilder the formBuilder to send
* @return whether the form was successfully sent
*/
boolean sendForm(@NonNull FormBuilder<?, ?, ?> formBuilder);
/**
* Transfer the connection to a server. A Bedrock player can successfully transfer to the same server they are
* currently playing on.
*
* @param address the address of the server
* @param port the port of the server
* @return true if the transfer was a success
*/
boolean transfer(@NonNull String address, @IntRange(from = 0, to = 65535) int port);
}

View File

@ -1,73 +0,0 @@
/*
* Copyright (c) 2019-2022 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.util;
import org.checkerframework.checker.nullness.qual.NonNull;
public enum BedrockPlatform {
UNKNOWN("Unknown"),
GOOGLE("Android"),
IOS("iOS"),
OSX("macOS"),
AMAZON("Amazon"),
GEARVR("Gear VR"),
HOLOLENS("Hololens"),
UWP("Windows"),
WIN32("Windows x86"),
DEDICATED("Dedicated"),
TVOS("Apple TV"),
PS4("PS4"),
NX("Switch"),
XBOX("Xbox One"),
WINDOWS_PHONE("Windows Phone");
private static final BedrockPlatform[] VALUES = values();
private final String displayName;
BedrockPlatform(String displayName) {
this.displayName = displayName;
}
/**
* Get the BedrockPlatform from the identifier.
*
* @param id the BedrockPlatform identifier
* @return The BedrockPlatform or {@link #UNKNOWN} if the platform wasn't found
*/
@NonNull
public static BedrockPlatform fromId(int id) {
return id < VALUES.length ? VALUES[id] : VALUES[0];
}
/**
* @return friendly display name of platform.
*/
@Override
public String toString() {
return displayName;
}
}

View File

@ -1,49 +0,0 @@
/*
* Copyright (c) 2019-2022 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.util;
import org.checkerframework.checker.nullness.qual.NonNull;
public enum InputMode {
UNKNOWN,
KEYBOARD_MOUSE,
TOUCH,
CONTROLLER,
VR;
private static final InputMode[] VALUES = values();
/**
* Get the InputMode from the identifier.
*
* @param id the InputMode identifier
* @return The InputMode or {@link #UNKNOWN} if the mode wasn't found
*/
@NonNull
public static InputMode fromId(int id) {
return VALUES.length > id ? VALUES[id] : VALUES[0];
}
}

View File

@ -1,45 +0,0 @@
/*
* Copyright (c) 2019-2022 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.util;
import org.checkerframework.checker.nullness.qual.NonNull;
public enum UiProfile {
CLASSIC, POCKET;
private static final UiProfile[] VALUES = values();
/**
* Get the UiProfile from the identifier.
*
* @param id the UiProfile identifier
* @return The UiProfile or {@link #CLASSIC} if the profile wasn't found
*/
@NonNull
public static UiProfile fromId(int id) {
return VALUES.length > id ? VALUES[id] : VALUES[0];
}
}

7
api/build.gradle.kts Normal file
View File

@ -0,0 +1,7 @@
plugins {
id("geyser.publish-conventions")
}
dependencies {
api(libs.base.api)
}

View File

@ -1,14 +0,0 @@
plugins {
id("geyser.api-conventions")
}
dependencies {
api(projects.api)
}
publishing {
publications.named<MavenPublication>("mavenJava") {
groupId = rootProject.group as String + ".geyser"
artifactId = "api"
}
}

View File

@ -1,9 +0,0 @@
plugins {
id("geyser.publish-conventions")
}
tasks {
shadowJar {
archiveBaseName.set(archiveBaseName.get() + "-api")
}
}

View File

@ -5,7 +5,7 @@ plugins {
}
allprojects {
group = "org.geysermc"
group = "org.geysermc.geyser"
version = "2.1.0-SNAPSHOT"
description = "Allows for players from Minecraft: Bedrock Edition to join Minecraft: Java Edition servers."
@ -23,8 +23,6 @@ val platforms = setOf(
projects.velocity
).map { it.dependencyProject }
val api: Project = projects.api.dependencyProject
subprojects {
apply {
plugin("java-library")
@ -32,16 +30,8 @@ subprojects {
plugin("geyser.build-logic")
}
val relativePath = projectDir.relativeTo(rootProject.projectDir).path
if (relativePath.contains("api")) {
plugins.apply("geyser.api-conventions")
} else {
group = rootProject.group as String + ".geyser"
when (this) {
in platforms -> plugins.apply("geyser.platform-conventions")
api -> plugins.apply("geyser.publish-conventions")
else -> plugins.apply("geyser.base-conventions")
}
when (this) {
in platforms -> plugins.apply("geyser.platform-conventions")
else -> plugins.apply("geyser.base-conventions")
}
}

View File

@ -7,7 +7,7 @@ plugins {
}
dependencies {
api(projects.geyserApi)
api(projects.api)
api(projects.common)
// Jackson JSON and YAML serialization

View File

@ -1,4 +1,7 @@
[versions]
base-api = "1.0.0-SNAPSHOT"
cumulus = "1.1.1"
events = "1.0-SNAPSHOT"
jackson = "2.14.0"
fastutil = "8.5.2"
netty = "4.1.80.Final"
@ -14,8 +17,6 @@ adventure = "4.12.0-20220629.025215-9"
adventure-platform = "4.1.2"
junit = "4.13.1"
checkerframework = "3.19.0"
cumulus = "1.1.1"
events = "1.0-SNAPSHOT"
log4j = "2.17.1"
jline = "3.21.0"
terminalconsoleappender = "1.2.0"
@ -31,6 +32,10 @@ fabric-loader = "0.14.8"
fabric-api = "0.58.5+1.19.1"
[libraries]
base-api = { group = "org.geysermc.api", name = "base-api", version.ref = "base-api" }
cumulus = { group = "org.geysermc.cumulus", name = "cumulus", version.ref = "cumulus" }
events = { group = "org.geysermc.event", name = "events", version.ref = "events" }
jackson-annotations = { group = "com.fasterxml.jackson.core", name = "jackson-annotations", version.ref = "jackson" }
jackson-core = { group = "com.fasterxml.jackson.core", name = "jackson-databind", version.ref = "jackson" }
jackson-dataformat-yaml = { group = "com.fasterxml.jackson.dataformat", name = "jackson-dataformat-yaml", version.ref = "jackson" }
@ -74,8 +79,6 @@ adapters-spigot = { group = "org.geysermc.geyser.adapters", name = "spigot-all",
bungeecord-proxy = { group = "com.github.SpigotMC.BungeeCord", name = "bungeecord-proxy", version.ref = "bungeecord" }
checker-qual = { group = "org.checkerframework", name = "checker-qual", version.ref = "checkerframework" }
commodore = { group = "me.lucko", name = "commodore", version.ref = "commodore" }
cumulus = { group = "org.geysermc.cumulus", name = "cumulus", version.ref = "cumulus" }
events = { group = "org.geysermc.event", name = "events", version.ref = "events" }
guava = { group = "com.google.guava", name = "guava", version.ref = "guava" }
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
junit = { group = "junit", name = "junit", version.ref = "junit" }

View File

@ -62,7 +62,6 @@ rootProject.name = "geyser-parent"
include(":ap")
include(":api")
include(":geyser-api")
include(":bungeecord")
include(":fabric")
include(":spigot")
@ -73,8 +72,6 @@ include(":common")
include(":core")
// Specify project dirs
project(":api").projectDir = file("api/base")
project(":geyser-api").projectDir = file("api/geyser")
project(":bungeecord").projectDir = file("bootstrap/bungeecord")
project(":fabric").projectDir = file("bootstrap/fabric")
project(":spigot").projectDir = file("bootstrap/spigot")