Added floodgate API and alt account methods into player API

This commit is contained in:
Marc Baloup 2021-09-09 17:24:02 +02:00
parent 9391dcafbc
commit f2bd13a18d
3 changed files with 68 additions and 8 deletions

View File

@ -19,6 +19,10 @@
<id>sonatype-oss-snapshots</id> <id>sonatype-oss-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url> <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository> </repository>
<repository>
<id>opencollab-snapshot</id>
<url>https://repo.opencollab.dev/maven-snapshots/</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -58,6 +62,14 @@
<artifactId>javaluator</artifactId> <artifactId>javaluator</artifactId>
<version>3.0.3</version> <version>3.0.3</version>
</dependency> </dependency>
<dependency>
<groupId>org.geysermc.floodgate</groupId>
<artifactId>api</artifactId>
<version>2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -18,10 +18,33 @@ public interface IOffPlayer {
*/ */
/** /**
* Return the ID of the minecraft account.
*
* @return the id of the player * @return the id of the player
*/ */
public abstract UUID getUniqueId(); 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. * @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 * Related class instances
*/ */

View File

@ -3,6 +3,9 @@ package fr.pandacube.lib.core.players;
import java.util.Locale; import java.util.Locale;
import java.util.UUID; 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.chat.Chat;
import fr.pandacube.lib.core.db.DBException; import fr.pandacube.lib.core.db.DBException;
import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identified;
@ -33,6 +36,25 @@ public interface IOnlinePlayer extends IOffPlayer {
/*
* 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) * @throws IllegalStateException if the player was not found in the database (should never happen)
* @throws DBException if a database access error occurs * @throws DBException if a database access error occurs
@ -49,14 +71,6 @@ public interface IOnlinePlayer extends IOffPlayer {
/*
* Related class instances
*/
/* /*