From f2bd13a18d5b06a99cac5a3efbea1d5e558ff7f0 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Thu, 9 Sep 2021 17:24:02 +0200 Subject: [PATCH] Added floodgate API and alt account methods into player API --- Core/pom.xml | 12 +++++++ .../lib/core/players/IOffPlayer.java | 34 +++++++++++++++++++ .../lib/core/players/IOnlinePlayer.java | 30 +++++++++++----- 3 files changed, 68 insertions(+), 8 deletions(-) diff --git a/Core/pom.xml b/Core/pom.xml index fdd87ea..a96adf4 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -19,6 +19,10 @@ sonatype-oss-snapshots https://oss.sonatype.org/content/repositories/snapshots/ + + opencollab-snapshot + https://repo.opencollab.dev/maven-snapshots/ + @@ -58,6 +62,14 @@ javaluator 3.0.3 + + + + org.geysermc.floodgate + api + 2.0-SNAPSHOT + provided + diff --git a/Core/src/main/java/fr/pandacube/lib/core/players/IOffPlayer.java b/Core/src/main/java/fr/pandacube/lib/core/players/IOffPlayer.java index ee1c602..a648be2 100644 --- a/Core/src/main/java/fr/pandacube/lib/core/players/IOffPlayer.java +++ b/Core/src/main/java/fr/pandacube/lib/core/players/IOffPlayer.java @@ -18,10 +18,33 @@ public interface IOffPlayer { */ /** + * Return the ID of the minecraft account. + * * @return the id of the player */ public abstract UUID getUniqueId(); + + /** + * Tells if the current account is an alt account generated by Pandacube. + * + * An alt account uses a specific bit in the UUID to distinguish themselves from the original account. + */ + public default boolean isAltAccount() { + return (getUniqueId().getMostSignificantBits() & 0x8000L) == 0x8000L; + } + + /** + * Gets the index of the current alt account generated by Pandacube. + * + * The first generated alt account will be numbered 1, the second 2, ... + * + * This method will return undetermined value if {@link #isAltAccount()} is false. + */ + public default int getAltIndex() { + return (int) (getUniqueId().getMostSignificantBits() >> 8) & 0xF; + } + /** * @return the last known player name of this player, or null if this player never joined the network. */ @@ -38,6 +61,17 @@ public interface IOffPlayer { + /* + * Floodgate related stuff + */ + + public default boolean isBedrockAccount() { + int v = getUniqueId().version(); + return v == 0 || v == 8; // also 8 if one day we supports alt accounts for floodgate players + } + + + /* * Related class instances */ diff --git a/Core/src/main/java/fr/pandacube/lib/core/players/IOnlinePlayer.java b/Core/src/main/java/fr/pandacube/lib/core/players/IOnlinePlayer.java index 783aa7f..ae6fbf1 100644 --- a/Core/src/main/java/fr/pandacube/lib/core/players/IOnlinePlayer.java +++ b/Core/src/main/java/fr/pandacube/lib/core/players/IOnlinePlayer.java @@ -3,6 +3,9 @@ package fr.pandacube.lib.core.players; import java.util.Locale; import java.util.UUID; +import org.geysermc.floodgate.api.FloodgateApi; +import org.geysermc.floodgate.api.player.FloodgatePlayer; + import fr.pandacube.lib.core.chat.Chat; import fr.pandacube.lib.core.db.DBException; import net.kyori.adventure.identity.Identified; @@ -31,7 +34,26 @@ public interface IOnlinePlayer extends IOffPlayer { public abstract String getWorldName(); + + + /* + * Floodgate related + */ + + public default boolean isBedrockClient() { + return FloodgateApi.getInstance().isFloodgatePlayer(getUniqueId()); + } + + public default FloodgatePlayer getBedrockClient() { + return FloodgateApi.getInstance().getPlayer(getUniqueId()); + } + + + + /* + * Related class instances + */ /** * @throws IllegalStateException if the player was not found in the database (should never happen) @@ -49,14 +71,6 @@ public interface IOnlinePlayer extends IOffPlayer { - /* - * Related class instances - */ - - - - - /*