Skip to content

Commit b0ef1a5

Browse files
committed
Move Floodgate conflict chechking to core
The FloodgateApi is the same for Bukkit and Bungee, so the Floodgate related code could be used in a future Bungee implementation too. Currently, Bungee will report Floodgate disabled to core, so the upstream Floodgate implementation will be used there. If enough code will be moved to core, I might consider enabling these features to BungeeCord too.
1 parent 25254b2 commit b0ef1a5

File tree

6 files changed

+61
-24
lines changed

6 files changed

+61
-24
lines changed

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
import org.bukkit.Bukkit;
4141
import org.bukkit.command.CommandSender;
4242
import org.bukkit.entity.Player;
43-
import org.geysermc.floodgate.api.FloodgateApi;
44-
import org.geysermc.floodgate.api.player.FloodgatePlayer;
4543

4644
public class NameCheckTask extends JoinManagement<Player, CommandSender, ProtocolLibLoginSource>
4745
implements Runnable {
@@ -70,13 +68,8 @@ public NameCheckTask(FastLoginBukkit plugin, PacketEvent packetEvent, Random ran
7068
@Override
7169
public void run() {
7270
try {
73-
// check if the player is connecting through Geyser
74-
if (!plugin.getCore().getConfig().get("allowFloodgateNameConflict").toString().equalsIgnoreCase("false")
75-
&& getFloodgatePlayer(username) != null) {
76-
plugin.getLog().info("Skipping name conflict checking for player {}", username);
77-
return;
78-
}
79-
super.onLogin(username, new ProtocolLibLoginSource(packetEvent, player, random, publicKey));
71+
boolean floodgateAvailable = Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate");
72+
super.onLogin(username, new ProtocolLibLoginSource(packetEvent, player, random, publicKey), floodgateAvailable);
8073
} finally {
8174
ProtocolLibrary.getProtocolManager().getAsynchronousManager().signalPacketTransmission(packetEvent);
8275
}
@@ -121,15 +114,4 @@ public void startCrackedSession(ProtocolLibLoginSource source, StoredProfile pro
121114
plugin.putSession(player.getAddress(), loginSession);
122115
}
123116

124-
private static FloodgatePlayer getFloodgatePlayer(String username) {
125-
if (Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate")) {
126-
// the Floodgate API requires UUID, which is inaccessible at NameCheckTask.java
127-
for (FloodgatePlayer floodgatePlayer : FloodgateApi.getInstance().getPlayers()) {
128-
if (floodgatePlayer.getUsername().equals(username)) {
129-
return floodgatePlayer;
130-
}
131-
}
132-
}
133-
return null;
134-
}
135117
}

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void onLoginStart(PlayerLoginStartEvent loginStartEvent) {
7575
//remove old data every time on a new login in order to keep the session only for one person
7676
plugin.removeSession(address);
7777

78-
super.onLogin(username, new ProtocolLoginSource(loginStartEvent));
78+
super.onLogin(username, new ProtocolLoginSource(loginStartEvent), false);
7979
}
8080

8181
@EventHandler

bungee/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
<!-- Version 2.0 -->
137137
<dependency>
138138
<groupId>org.geysermc.floodgate</groupId>
139-
<artifactId>bungee</artifactId>
139+
<artifactId>api</artifactId>
140140
<version>2.0-SNAPSHOT</version>
141141
<scope>provided</scope>
142142
</dependency>

bungee/src/main/java/com/github/games647/fastlogin/bungee/task/AsyncPremiumCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void run() {
6262
plugin.getSession().remove(connection);
6363

6464
try {
65-
super.onLogin(username, new BungeeLoginSource(connection, preLoginEvent));
65+
super.onLogin(username, new BungeeLoginSource(connection, preLoginEvent), false);
6666
} finally {
6767
preLoginEvent.completeIntent(plugin);
6868
}

core/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
<id>codemc-repo</id>
5454
<url>https://repo.codemc.io/repository/maven-public/</url>
5555
</repository>
56+
57+
<!-- Floodgate -->
58+
<repository>
59+
<id>nukkitx-snapshot</id>
60+
<url>https://repo.nukkitx.com/maven-snapshots/</url>
61+
</repository>
5662
</repositories>
5763

5864
<dependencies>
@@ -92,6 +98,14 @@
9298
<version>0.4</version>
9399
</dependency>
94100

101+
<!--Floodgate for Xbox Live Authentication-->
102+
<dependency>
103+
<groupId>org.geysermc.floodgate</groupId>
104+
<artifactId>api</artifactId>
105+
<version>2.0-SNAPSHOT</version>
106+
<scope>provided</scope>
107+
</dependency>
108+
95109
<!-- APIs we can use because they are available in all platforms (Spigot, Bungee) -->
96110
<dependency>
97111
<groupId>com.google.guava</groupId>

core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333

3434
import java.util.Optional;
3535

36+
import org.geysermc.floodgate.api.FloodgateApi;
37+
import org.geysermc.floodgate.api.player.FloodgatePlayer;
38+
3639
import net.md_5.bungee.config.Configuration;
3740

3841
public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
@@ -45,8 +48,28 @@ public JoinManagement(FastLoginCore<P, C, ?> core, AuthPlugin<P> authHook) {
4548
this.authHook = authHook;
4649
}
4750

48-
public void onLogin(String username, S source) {
51+
public void onLogin(String username, S source, boolean floodgateAvailable) {
4952
core.getPlugin().getLog().info("Handling player {}", username);
53+
54+
// check if the player is connecting through Geyser
55+
if (floodgateAvailable && getFloodgatePlayer(username) != null) {
56+
if (core.getConfig().get("allowFloodgateNameConflict").toString().equalsIgnoreCase("false")) {
57+
core.getPlugin().getLog().info(
58+
"Bedrock Player {}'s name conflits an existing Java Premium Player's name",
59+
username);
60+
try {
61+
source.kick("Your name conflits an existing Java Premium Player's name");
62+
} catch (Exception e) {
63+
e.printStackTrace();
64+
core.getPlugin().getLog().error("Could not kick Player {}", username);
65+
}
66+
} else {
67+
core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username);
68+
return;
69+
}
70+
71+
}
72+
5073
StoredProfile profile = core.getStorage().loadProfile(username);
5174
if (profile == null) {
5275
return;
@@ -130,6 +153,24 @@ private boolean checkNameChange(S source, String username, Profile profile) {
130153

131154
return false;
132155
}
156+
157+
/**
158+
* Get a FloodgatePlayyer by their name.
159+
* This is not supported by FloodgateApi.
160+
* <br>
161+
* <b>WARNING: This method does not check if the floodgate plugin is actually installed on the server!</b>
162+
* @param username the name of the player
163+
* @return FloodgatePlayer if found, null if the player is not online
164+
*/
165+
protected static FloodgatePlayer getFloodgatePlayer(String username) {
166+
// the Floodgate API requires UUID, which is inaccessible at NameCheckTask.java
167+
for (FloodgatePlayer floodgatePlayer : FloodgateApi.getInstance().getPlayers()) {
168+
if (floodgatePlayer.getUsername().equals(username)) {
169+
return floodgatePlayer;
170+
}
171+
}
172+
return null;
173+
}
133174

134175
public abstract FastLoginPreLoginEvent callFastLoginPreLoginEvent(String username, S source, StoredProfile profile);
135176

0 commit comments

Comments
 (0)