2525 */
2626package com .github .games647 .fastlogin .bukkit .task ;
2727
28+ import java .io .IOException ;
29+ import java .util .Optional ;
30+
2831import org .bukkit .Bukkit ;
2932import org .bukkit .entity .Player ;
3033import org .geysermc .floodgate .api .player .FloodgatePlayer ;
3134
35+ import com .github .games647 .craftapi .model .Profile ;
36+ import com .github .games647 .craftapi .resolver .RateLimitException ;
3237import com .github .games647 .fastlogin .bukkit .BukkitLoginSession ;
3338import com .github .games647 .fastlogin .bukkit .FastLoginBukkit ;
3439import com .github .games647 .fastlogin .core .StoredProfile ;
@@ -54,11 +59,11 @@ public void run() {
5459
5560 // check if the Bedrock player is linked to a Java account
5661 boolean isLinked = floodgatePlayer .getLinkedPlayer () != null ;
57-
5862 AuthPlugin <Player > authPlugin = plugin .getCore ().getAuthPluginHook ();
5963
6064 String autoLoginFloodgate = plugin .getCore ().getConfig ().get ("autoLoginFloodgate" ).toString ().toLowerCase ();
61- boolean autoRegisterFloodgate = plugin .getCore ().getConfig ().getBoolean ("autoRegisterFloodgate" );
65+ String autoRegisterFloodgate = plugin .getCore ().getConfig ().get ("autoRegisterFloodgate" ).toString ().toLowerCase ();
66+ String allowNameConflict = plugin .getCore ().getConfig ().get ("allowFloodgateNameConflict" ).toString ().toLowerCase ();
6267
6368 boolean isRegistered ;
6469 try {
@@ -69,21 +74,47 @@ public void run() {
6974 player .getName ());
7075 return ;
7176 }
72-
73- if (!isRegistered && !autoRegisterFloodgate ) {
77+
78+ //decide if checks should be made for conflicting Java player names
79+ if (!isLinked //linked players have the same name as their Java profile
80+ // if allowNameConflict is 'false' or 'linked' and the player had a conflicting
81+ // name, than they would have been kicked in FloodgateHook#checkNameConflict
82+ && allowNameConflict .equals ("true" ) &&
83+ (
84+ autoLoginFloodgate .equals ("no-conflict" )
85+ || !isRegistered && autoRegisterFloodgate .equals ("no-conflict" ))
86+ ) {
87+ // check for conflicting Premium Java name
88+ Optional <Profile > premiumUUID = Optional .empty ();
89+ try {
90+ premiumUUID = plugin .getCore ().getResolver ().findProfile (player .getName ());
91+ } catch (IOException | RateLimitException e ) {
92+ plugin .getLog ().error (
93+ "Could not check wether Floodgate Player {}'s name conflits a premium Java player's name." ,
94+ player .getName ());
95+ return ;
96+ }
97+
98+ //stop execution if player's name is conflicting
99+ if (premiumUUID .isPresent ()) {
100+ return ;
101+ }
102+ }
103+
104+ if (!isRegistered && autoRegisterFloodgate .equals ("false" )) {
74105 plugin .getLog ().info (
75106 "Auto registration is disabled for Floodgate players in config.yml" );
76107 return ;
77108 }
78-
109+
79110 // logging in from bedrock for a second time threw an error with UUID
80111 StoredProfile profile = plugin .getCore ().getStorage ().loadProfile (player .getName ());
81112 if (profile == null ) {
82113 profile = new StoredProfile (player .getUniqueId (), player .getName (), true , player .getAddress ().toString ());
83114 }
84115
85116 BukkitLoginSession session = new BukkitLoginSession (player .getName (), isRegistered , profile );
86-
117+
87118 // enable auto login based on the value of 'autoLoginFloodgate' in config.yml
88119 session .setVerified (autoLoginFloodgate .equals ("true" )
89120 || (autoLoginFloodgate .equals ("linked" ) && isLinked ));
0 commit comments