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 // cases: Paper (firing BungeeCord message before PlayerJoinEvent) or not running BungeeCord and already
// 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());
FloodgatePlayer floodgatePlayer = FloodgateAPI.getPlayer(player.getUniqueId());
if (floodgatePlayer != null) { if(Bukkit.getServer().getPluginManager().getPlugin("Geyser-Spigot") != null &&
StoredProfile profile = plugin.getCore().getStorage().loadProfile(player.getName()); 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 //create fake session to make auto login work
session = new BukkitLoginSession(player.getName(), profile.isSaved()); session = new BukkitLoginSession(player.getName(), profile.isSaved());
session.setVerified(true); session.setVerified(true);
//start auto login //TODO: configurate auto login for floodgate players
//TODO: configurate auto login for floodgate players //TODO: fix bug: registering as bedrock player breaks java auto login
//TODO: fix bug: registering as bedrock player breaks java auto login }
Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session); }
Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask); if (session == null) {
} else if (session == null) {
String sessionId = plugin.getSessionId(player.getAddress()); String sessionId = plugin.getSessionId(player.getAddress());
plugin.getLog().info("No on-going login session for player: {} with ID {}", player, sessionId); plugin.getLog().info("No on-going login session for player: {} with ID {}", player, sessionId);
} else { } else {

View File

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

View File

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