From e1af75191edf9bce5e9d9b441b85b36f535eee0f Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sat, 20 Mar 2021 18:28:32 +0100 Subject: [PATCH] Implement autoLoginFloodgate & autoRegisterFloodgate config options Knwon Bug: Profile.isSaved() is 'false' when logging in from Bedrock after auto registering through Bedrock so FastLogin will try to register for a second time, insted of logging in --- .../bukkit/listener/ConnectionListener.java | 20 +++++++++++-------- core/src/main/resources/config.yml | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java index ab066866..838e8710 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java @@ -71,8 +71,9 @@ public class ConnectionListener implements Listener { "Player {} is connecting through Geyser Floodgate.", player.getName()); String allowNameConflict = plugin.getCore().getConfig().getString("allowFloodgateNameConflict"); - if (allowNameConflict.equalsIgnoreCase("linked") && - floodgatePlayer.fetchLinkedPlayer() == null) { + // check if the Bedrock player is linked to a Java account + boolean isLinked = floodgatePlayer.fetchLinkedPlayer() != null; + if (allowNameConflict.equalsIgnoreCase("linked") && !isLinked) { plugin.getLog().info( "Bedrock Player {}'s name conflits an existing Java Premium Player's name", player.getName()); @@ -88,13 +89,16 @@ public class ConnectionListener implements Listener { StoredProfile profile = plugin.getCore().getStorage().loadProfile(player.getName()); + String autoLoginFloodgate = plugin.getCore().getConfig().getString("autoLoginFloodgate"); + boolean autoRegisterFloodgate = plugin.getCore().getConfig().getBoolean("autoRegisterFloodgate"); + // 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 - + // the player should only be registered (=> parm. registered = false) if + // the player is not registered and autoRegister is enabled in the config + session = new BukkitLoginSession(player.getName(), profile.isSaved() || !autoRegisterFloodgate); + // enable auto login based on the value of 'autoLoginFloodgate' in config.yml + session.setVerified(autoLoginFloodgate.equalsIgnoreCase("true") + || (autoLoginFloodgate.equalsIgnoreCase("linked") && isLinked)); } } if (session == null) { diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index 6b7bb6f3..3d0f12eb 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -212,6 +212,7 @@ autoLoginFloodgate: 'false' allowFloodgateNameConflict: 'false' # This enables auto registering every player connecting through Floodgate. +# autoLoginFloodgate must be 'true' for this to work autoRegisterFloodgate: false # Database configuration