From 5b415cea68a4f25ff0ed932d58d73d17b3a92290 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 21 Nov 2021 20:18:00 -0600 Subject: [PATCH] Remove generic usage in Api --- .../src/main/java/org/geysermc/api/Api.java | 12 +++---- .../main/java/org/geysermc/api/Geyser.java | 8 ++--- api/geyser/pom.xml | 6 ++++ .../org/geysermc/geyser/api/GeyserApi.java | 32 ++++++++++++++++++- .../java/org/geysermc/geyser/GeyserImpl.java | 5 ++- 5 files changed, 48 insertions(+), 15 deletions(-) diff --git a/api/base/src/main/java/org/geysermc/api/Api.java b/api/base/src/main/java/org/geysermc/api/Api.java index f3ee9c742..30d5dc134 100644 --- a/api/base/src/main/java/org/geysermc/api/Api.java +++ b/api/base/src/main/java/org/geysermc/api/Api.java @@ -34,10 +34,8 @@ import java.util.UUID; /** * The base API class. - * - * @param the session type */ -public interface Api { +public interface Api { /** * Gets the session from the given @@ -47,7 +45,7 @@ public interface Api { * @return the session from the given UUID, if applicable */ @Nullable - S sessionByUuid(@NonNull UUID uuid); + Session sessionByUuid(@NonNull UUID uuid); /** * Gets the session from the given @@ -57,7 +55,7 @@ public interface Api { * @return the session from the given UUID, if applicable */ @Nullable - S sessionByXuid(@NonNull String xuid); + Session sessionByXuid(@NonNull String xuid); /** * Gets the session from the given @@ -67,7 +65,7 @@ public interface Api { * @return the session from the given name, if applicable */ @Nullable - S sessionByName(@NonNull String name); + Session sessionByName(@NonNull String name); /** * Gets all the online sessions. @@ -75,5 +73,5 @@ public interface Api { * @return all the online sessions */ @NonNull - List onlineSessions(); + List onlineSessions(); } diff --git a/api/base/src/main/java/org/geysermc/api/Geyser.java b/api/base/src/main/java/org/geysermc/api/Geyser.java index 99d3f1402..99f343274 100644 --- a/api/base/src/main/java/org/geysermc/api/Geyser.java +++ b/api/base/src/main/java/org/geysermc/api/Geyser.java @@ -32,14 +32,14 @@ import org.checkerframework.checker.nullness.qual.NonNull; */ @NonNull public class Geyser { - private static Api api; + private static Api api; /** * Returns the base api. * * @return the base api */ - public static Api api() { + public static Api api() { if (api == null) { throw new RuntimeException("Api has not been registered yet!"); } @@ -55,7 +55,7 @@ public class Geyser { * @return the api of the given type */ @SuppressWarnings("unchecked") - public static > T api(@NonNull Class apiClass) { + public static T api(@NonNull Class apiClass) { if (apiClass.isInstance(api)) { return (T) api; } @@ -74,7 +74,7 @@ public class Geyser { * * @param api the api */ - public static void set(@NonNull Api api) { + public static void set(@NonNull Api api) { if (Geyser.api != null) { throw new RuntimeException("Cannot redefine already registered api!"); } diff --git a/api/geyser/pom.xml b/api/geyser/pom.xml index dc28b0648..df88b076f 100644 --- a/api/geyser/pom.xml +++ b/api/geyser/pom.xml @@ -17,6 +17,12 @@ + + org.checkerframework + checker-qual + 3.19.0 + provided + org.geysermc base-api diff --git a/api/geyser/src/main/java/org/geysermc/geyser/api/GeyserApi.java b/api/geyser/src/main/java/org/geysermc/geyser/api/GeyserApi.java index a6b4cbf78..31981914d 100644 --- a/api/geyser/src/main/java/org/geysermc/geyser/api/GeyserApi.java +++ b/api/geyser/src/main/java/org/geysermc/geyser/api/GeyserApi.java @@ -25,14 +25,20 @@ package org.geysermc.geyser.api; +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; + /** * Represents the API used in Geyser. */ -public interface GeyserApi extends Api { +public interface GeyserApi extends Api { /** * Shuts down the current Geyser instance. @@ -52,6 +58,30 @@ 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 onlineSessions(); + /** * Gets the {@link GeyserApi}. * diff --git a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java index a51dd7b40..a12a1c6d0 100644 --- a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java +++ b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java @@ -414,9 +414,8 @@ public class GeyserImpl implements GeyserApi { } @Override - @SuppressWarnings("unchecked") - public @NonNull List onlineSessions() { - return (List) (List) this.sessionManager.getAllSessions(); + public @NonNull List onlineSessions() { + return this.sessionManager.getAllSessions(); } @Override