Check if Geyser and Floodgate are installed before accessing them

This commit is contained in:
Smart123s
2021-03-20 13:38:41 +01:00
parent 57e797f1be
commit 0cbf2a4e20
3 changed files with 31 additions and 22 deletions

View File

@ -48,20 +48,23 @@ public class ConnectionListener implements Listener {
// cases: Paper (firing BungeeCord message before PlayerJoinEvent) or not running BungeeCord and already
// having the login session from the login process
BukkitLoginSession session = plugin.getSession(player.getAddress());
FloodgatePlayer floodgatePlayer = FloodgateAPI.getPlayer(player.getUniqueId());
if (floodgatePlayer != null) {
StoredProfile profile = plugin.getCore().getStorage().loadProfile(player.getName());
if(Bukkit.getServer().getPluginManager().getPlugin("Geyser-Spigot") != null &&
Bukkit.getServer().getPluginManager().getPlugin("floodgate-bukkit") != null) {
//TODO: Does this return null if a player is connected through Geyser Online mode?
FloodgatePlayer floodgatePlayer = FloodgateAPI.getPlayer(player.getUniqueId());
if (floodgatePlayer != null) {
StoredProfile profile = plugin.getCore().getStorage().loadProfile(player.getName());
//create fake session to make auto login work
session = new BukkitLoginSession(player.getName(), profile.isSaved());
session.setVerified(true);
//start auto login
//TODO: configurate auto login for floodgate players
//TODO: fix bug: registering as bedrock player breaks java auto login
Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session);
Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask);
} else if (session == null) {
//create fake session to make auto login work
session = new BukkitLoginSession(player.getName(), profile.isSaved());
session.setVerified(true);
//TODO: configurate auto login for floodgate players
//TODO: fix bug: registering as bedrock player breaks java auto login
}
}
if (session == null) {
String sessionId = plugin.getSessionId(player.getAddress());
plugin.getLog().info("No on-going login session for player: {} with ID {}", player, sessionId);
} else {

View File

@ -12,6 +12,7 @@ import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent;
import java.security.PublicKey;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.geysermc.connector.GeyserConnector;
@ -46,15 +47,17 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
public void run() {
try {
// check if the player is connecting through Geyser
if (GeyserConnector.getInstance().getDefaultAuthType() == AuthType.FLOODGATE) {
// the Floodgate API requires UUID, which is inaccessible at this state
// workaround: iterate over Geyser's player's usernames
for (GeyserSession geyserPlayer : GeyserConnector.getInstance().getPlayers()) {
if (geyserPlayer.getName().equals(username)) {
plugin.getLog().info(
"Player {} is connecting through Geyser Floodgate.",
username);
return;
if(Bukkit.getServer().getPluginManager().getPlugin("Geyser-Spigot") != null) {
if (GeyserConnector.getInstance().getDefaultAuthType() == AuthType.FLOODGATE) {
// the Floodgate API requires UUID, which is inaccessible at this state
// workaround: iterate over Geyser's player's usernames
for (GeyserSession geyserPlayer : GeyserConnector.getInstance().getPlayers()) {
if (geyserPlayer.getName().equals(username)) {
plugin.getLog().info(
"Player {} is connecting through Geyser Floodgate.",
username);
return;
}
}
}
}

View File

@ -20,6 +20,9 @@ softdepend:
- ProtocolLib
# Premium variable
- PlaceholderAPI
# Floodgate
- floodgate-bukkit
- Geyser-Spigot
# Auth plugins
- AuthMe
- LoginSecurity