Initial api draft

This commit is contained in:
RednedEpic 2021-11-21 12:36:42 -06:00
parent 2c663e0ee5
commit 83ddbd7d1a
412 changed files with 1473 additions and 1131 deletions

27
api/base/pom.xml Normal file
View 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>

View 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();
}

View 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;
}
}

View file

@ -23,37 +23,36 @@
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.api;
package org.geysermc.api.session;
import org.geysermc.geyser.api.logger.GeyserLogger;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.UUID;
/**
* General API class for Geyser.
* Represents a player session.
*/
public abstract class Geyser {
private static Geyser instance;
@NonNull
public interface Session {
/**
* Gets the logger used by Geyser.
* Gets the name of the session.
*
* @return the logger used by Geyser
* @return the name of the session
*/
public abstract GeyserLogger getLogger();
String name();
/**
* Returns the current {@link Geyser} instance.
* Gets the {@link UUID} of the session.
*
* @return the current Geyser instance
* @return the UUID of the session
*/
public static Geyser getInstance() {
return instance;
}
UUID uuid();
protected static void setInstance(Geyser instance) {
if (Geyser.instance != null) {
throw new RuntimeException("Cannot redefine singleton Geyser!");
}
Geyser.instance = instance;
}
/**
* Gets the XUID of the session.
*
* @return the XUID of the session
*/
String xuid();
}

27
api/geyser/pom.xml Normal file
View 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>geyser-api</artifactId>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>base-api</artifactId>
<version>1.4.3-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,63 @@
/*
* 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.geyser.api;
import org.geysermc.api.Api;
import org.geysermc.api.Geyser;
import org.geysermc.geyser.api.session.GeyserSession;
/**
* Represents the API used in Geyser.
*/
public interface GeyserApi extends Api<GeyserSession> {
/**
* 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();
/**
* Gets the {@link GeyserApi}.
*
* @return the Geyser API
*/
static GeyserApi api() {
return Geyser.api(GeyserApi.class);
}
}

View file

@ -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.geyser.api.session;
import org.geysermc.api.session.Session;
/**
* Represents a player session used in Geyser.
*/
public interface GeyserSession extends Session {
}

View file

@ -9,11 +9,16 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>api</artifactId>
<artifactId>api-parent</artifactId>
<packaging>pom</packaging>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<modules>
<module>base</module>
<module>geyser</module>
</modules>
</project>

View file

@ -1,92 +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.geyser.api.logger;
public interface GeyserLogger {
/**
* Logs a severe message to console
*
* @param message the message to log
*/
void severe(String message);
/**
* Logs a severe message and an exception to console
*
* @param message the message to log
* @param error the error to throw
*/
void severe(String message, Throwable error);
/**
* Logs an error message to console
*
* @param message the message to log
*/
void error(String message);
/**
* Logs an error message and an exception to console
*
* @param message the message to log
* @param error the error to throw
*/
void error(String message, Throwable error);
/**
* Logs a warning message to console
*
* @param message the message to log
*/
void warning(String message);
/**
* Logs an info message to console
*
* @param message the message to log
*/
void info(String message);
/**
* Logs a debug message to console
*
* @param message the message to log
*/
void debug(String message);
/**
* Sets if the logger should print debug messages
*
* @param debug if the logger should print debug messages
*/
void setDebug(boolean debug);
/**
* If debug is enabled for this logger
*/
boolean isDebug();
}