Skip to content

Commit 7fdbedb

Browse files
author
games647
authored
Merge pull request #533 from Smart123s/fg-bk-nonconfict
Add 'no-conflict' option to some Floodgate config entries
2 parents baede33 + 2e83eaa commit 7fdbedb

File tree

4 files changed

+55
-13
lines changed

4 files changed

+55
-13
lines changed

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ public void sendMessage(CommandSender receiver, String message) {
256256
* <ul>
257257
* <li>allowFloodgateNameConflict
258258
* <li>autoLoginFloodgate
259+
* <li>autoRegisterFloodgate
259260
* </ul>
260261
* </p>
261262
*
@@ -264,7 +265,7 @@ public void sendMessage(CommandSender receiver, String message) {
264265
*/
265266
private boolean isValidFloodgateConfigString(String key) {
266267
String value = core.getConfig().get(key).toString().toLowerCase();
267-
if (!value.equals("true") && !value.equals("linked") && !value.equals("false")) {
268+
if (!value.equals("true") && !value.equals("linked") && !value.equals("false") && !value.equals("no-conflict")) {
268269
logger.error("Invalid value detected for {} in FastLogin/config.yml.", key);
269270
return false;
270271
}

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@
2525
*/
2626
package com.github.games647.fastlogin.bukkit.task;
2727

28+
import java.io.IOException;
29+
import java.util.Optional;
30+
2831
import org.bukkit.Bukkit;
2932
import org.bukkit.entity.Player;
3033
import org.geysermc.floodgate.api.player.FloodgatePlayer;
3134

35+
import com.github.games647.craftapi.model.Profile;
36+
import com.github.games647.craftapi.resolver.RateLimitException;
3237
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
3338
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
3439
import 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));

bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import java.util.concurrent.ConcurrentMap;
5151
import java.util.concurrent.ThreadFactory;
5252

53-
import net.md_5.bungee.BungeeServerInfo;
5453
import net.md_5.bungee.api.CommandSender;
5554
import net.md_5.bungee.api.chat.TextComponent;
5655
import net.md_5.bungee.api.connection.PendingConnection;

core/src/main/resources/config.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,14 @@ autoLogin: true
194194
# !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!!
195195
# Enabling any of these settings might lead to people gaining unauthorized access to other's accounts!
196196

197-
# This enables auto login for every player connecting through Floodgate.
198-
# Possible values: false, true, linked
199-
# Linked means that only Bedrock accounts linked to a Java account will be logged in automatically
197+
# Automatically log in players connecting through Floodgate.
198+
# Possible values:
199+
# false: Disables auto login for every player connecting through Floodgate
200+
# true: Enables auto login for every player connecting through Floodgate
201+
# linked: Only Bedrock accounts that are linked to a Java account will be logged in automatically
202+
# no-conflict: Bedrock players will only be automatically logged in if the Mojang API reports
203+
# that there is no existing Premium Java MC account with their name.
204+
# This option can be useful if you are not using 'username-prefix' in floodgate/config.yml
200205
# !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!!
201206
# Enabling this might lead to people gaining unauthorized access to other's accounts!
202207
autoLoginFloodgate: false
@@ -225,8 +230,14 @@ autoLoginFloodgate: false
225230
# Enabling this might lead to people gaining unauthorized access to other's accounts!
226231
allowFloodgateNameConflict: false
227232

228-
# This enables auto registering every player connecting through Floodgate.
229-
# autoLoginFloodgate must be 'true' for this to work
233+
# Automatically register players connecting through Floodgate.
234+
# autoLoginFloodgate must be available for the player to use this
235+
# Possible values:
236+
# false: Disables auto registering for every player connecting through Floodgate
237+
# true: Enables auto registering for every player connecting through Floodgate
238+
# no-conflict: Bedrock players will only be automatically registered if the Mojang API reports
239+
# that there is no existing Premium Java MC account with their name.
240+
# This option can be useful if you are not using 'username-prefix' in floodgate/config.yml
230241
# !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!!
231242
# Enabling this might lead to people gaining unauthorized access to other's accounts!
232243
autoRegisterFloodgate: false

0 commit comments

Comments
 (0)