Migrate to Floodgate v2.0

This removes support for Floodgate 1.x
This commit is contained in:
Smart123s
2021-03-29 14:49:33 +02:00
parent f7fd94e983
commit 870d1ee281
4 changed files with 18 additions and 31 deletions

View File

@ -162,19 +162,11 @@
</exclusions> </exclusions>
</dependency> </dependency>
<!--Geyser for Bedrock Edition support-->
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>connector</artifactId>
<version>1.2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--Floodgate for Xbox Live Authentication--> <!--Floodgate for Xbox Live Authentication-->
<dependency> <dependency>
<groupId>org.geysermc</groupId> <groupId>org.geysermc.floodgate</groupId>
<artifactId>floodgate-bukkit</artifactId> <artifactId>api</artifactId>
<version>1.0-SNAPSHOT</version> <version>2.0-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@ -13,7 +13,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result; import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.geysermc.connector.GeyserConnector; import org.geysermc.floodgate.api.FloodgateApi;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
/** /**
@ -48,7 +48,8 @@ public class ConnectionListener implements Listener {
// having the login session from the login process // having the login session from the login process
BukkitLoginSession session = plugin.getSession(player.getAddress()); BukkitLoginSession session = plugin.getSession(player.getAddress());
if (GeyserConnector.getInstance().getPlayerByUuid(player.getUniqueId()) != null) { if (Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate") &&
FloodgateApi.getInstance().getPlayer(player.getUniqueId()) != null) {
Runnable floodgateAuthTask = new FloodgateAuthTask(plugin, player); Runnable floodgateAuthTask = new FloodgateAuthTask(plugin, player);
Bukkit.getScheduler().runTaskAsynchronously(plugin, floodgateAuthTask); Bukkit.getScheduler().runTaskAsynchronously(plugin, floodgateAuthTask);
} else if (session == null) { } else if (session == null) {

View File

@ -15,9 +15,8 @@ import java.util.Random;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.geysermc.connector.GeyserConnector; import org.geysermc.floodgate.api.FloodgateApi;
import org.geysermc.connector.common.AuthType; import org.geysermc.floodgate.api.player.FloodgatePlayer;
import org.geysermc.connector.network.session.GeyserSession;
public class NameCheckTask extends JoinManagement<Player, CommandSender, ProtocolLibLoginSource> public class NameCheckTask extends JoinManagement<Player, CommandSender, ProtocolLibLoginSource>
implements Runnable { implements Runnable {
@ -48,7 +47,7 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
try { try {
// check if the player is connecting through Geyser // check if the player is connecting through Geyser
if (!plugin.getCore().getConfig().getString("allowFloodgateNameConflict").equalsIgnoreCase("false") if (!plugin.getCore().getConfig().getString("allowFloodgateNameConflict").equalsIgnoreCase("false")
&& getGeyserPlayer(username) != null) { && getFloodgatePlayer(username) != null) {
plugin.getLog().info("Skipping name conflict checking for player {}", username); plugin.getLog().info("Skipping name conflict checking for player {}", username);
return; return;
} }
@ -97,17 +96,12 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
plugin.putSession(player.getAddress(), loginSession); plugin.putSession(player.getAddress(), loginSession);
} }
private static GeyserSession getGeyserPlayer(String username) { private static FloodgatePlayer getFloodgatePlayer(String username) {
if (Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate-bukkit") && if (Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate")) {
Bukkit.getServer().getPluginManager().isPluginEnabled("Geyser-Spigot") &&
GeyserConnector.getInstance().getDefaultAuthType() == AuthType.FLOODGATE) {
// the Floodgate API requires UUID, which is inaccessible at NameCheckTask.java // the Floodgate API requires UUID, which is inaccessible at NameCheckTask.java
// the Floodgate API has a return value for Java (non-bedrock) players, if they for (FloodgatePlayer floodgatePlayer : FloodgateApi.getInstance().getPlayers()) {
// are linked to a Bedrock account if (floodgatePlayer.getUsername().equals(username)) {
// workaround: iterate over Geyser's player's usernames return floodgatePlayer;
for (GeyserSession geyserPlayer : GeyserConnector.getInstance().getPlayers()) {
if (geyserPlayer.getName().equals(username)) {
return geyserPlayer;
} }
} }
} }

View File

@ -2,8 +2,8 @@ package com.github.games647.fastlogin.bukkit.task;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.geysermc.floodgate.FloodgateAPI; import org.geysermc.floodgate.api.FloodgateApi;
import org.geysermc.floodgate.FloodgatePlayer; import org.geysermc.floodgate.api.player.FloodgatePlayer;
import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
@ -22,13 +22,13 @@ public class FloodgateAuthTask implements Runnable {
@Override @Override
public void run() { public void run() {
FloodgatePlayer floodgatePlayer = FloodgateAPI.getPlayer(player.getUniqueId()); FloodgatePlayer floodgatePlayer = FloodgateApi.getInstance().getPlayer(player.getUniqueId());
plugin.getLog().info( plugin.getLog().info(
"Player {} is connecting through Geyser Floodgate.", "Player {} is connecting through Geyser Floodgate.",
player.getName()); player.getName());
String allowNameConflict = plugin.getCore().getConfig().getString("allowFloodgateNameConflict"); String allowNameConflict = plugin.getCore().getConfig().getString("allowFloodgateNameConflict");
// check if the Bedrock player is linked to a Java account // check if the Bedrock player is linked to a Java account
boolean isLinked = floodgatePlayer.fetchLinkedPlayer() != null; boolean isLinked = floodgatePlayer.getLinkedPlayer() != null;
if (allowNameConflict.equalsIgnoreCase("linked") && !isLinked) { if (allowNameConflict.equalsIgnoreCase("linked") && !isLinked) {
plugin.getLog().info( plugin.getLog().info(
"Bedrock Player {}'s name conflits an existing Java Premium Player's name", "Bedrock Player {}'s name conflits an existing Java Premium Player's name",