Skip to content

Commit 2700b3e

Browse files
Implement floodgate api version 2.0
1 parent dbe9ac2 commit 2700b3e

File tree

4 files changed

+60
-6
lines changed

4 files changed

+60
-6
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.github.games647.fastlogin.bungee.hook.floodgate;
2+
3+
import java.util.UUID;
4+
5+
public interface FloodgateHook {
6+
7+
boolean isBedrockPlayer(UUID uuid);
8+
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.github.games647.fastlogin.bungee.hook.floodgate;
2+
3+
import org.geysermc.floodgate.FloodgateAPI;
4+
5+
import java.util.UUID;
6+
7+
public class FloodgateV1Hook implements FloodgateHook {
8+
9+
@Override
10+
public boolean isBedrockPlayer(UUID uuid) {
11+
return FloodgateAPI.isBedrockPlayer(uuid);
12+
}
13+
14+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.github.games647.fastlogin.bungee.hook.floodgate;
2+
3+
import org.geysermc.floodgate.api.FloodgateApi;
4+
import org.geysermc.floodgate.api.InstanceHolder;
5+
6+
import java.util.UUID;
7+
8+
public class FloodgateV2Hook implements FloodgateHook {
9+
10+
private FloodgateApi floodgateApi;
11+
12+
public FloodgateV2Hook() {
13+
this.floodgateApi = InstanceHolder.getApi();
14+
}
15+
16+
@Override
17+
public boolean isBedrockPlayer(UUID uuid) {
18+
return floodgateApi.isFloodgatePlayer(uuid);
19+
}
20+
21+
}

bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
import com.github.games647.craftapi.UUIDAdapter;
2929
import com.github.games647.fastlogin.bungee.BungeeLoginSession;
3030
import com.github.games647.fastlogin.bungee.FastLoginBungee;
31+
import com.github.games647.fastlogin.bungee.hook.floodgate.FloodgateHook;
32+
import com.github.games647.fastlogin.bungee.hook.floodgate.FloodgateV1Hook;
33+
import com.github.games647.fastlogin.bungee.hook.floodgate.FloodgateV2Hook;
3134
import com.github.games647.fastlogin.bungee.task.AsyncPremiumCheck;
3235
import com.github.games647.fastlogin.bungee.task.ForceLoginTask;
3336
import com.github.games647.fastlogin.core.RateLimiter;
@@ -99,11 +102,21 @@ public class ConnectListener implements Listener {
99102
private final RateLimiter rateLimiter;
100103
private final Property[] emptyProperties = {};
101104
private final String floodgateVersion;
105+
private final FloodgateHook floodgateHook;
102106

103107
public ConnectListener(FastLoginBungee plugin, RateLimiter rateLimiter, String floodgateVersion) {
104108
this.plugin = plugin;
105109
this.rateLimiter = rateLimiter;
106110
this.floodgateVersion = floodgateVersion;
111+
112+
// Get the appropriate floodgate api hook based on the version
113+
if (floodgateVersion.startsWith("1")) {
114+
this.floodgateHook = new FloodgateV1Hook();
115+
} else if (floodgateVersion.startsWith("2")) {
116+
this.floodgateHook = new FloodgateV2Hook();
117+
} else {
118+
this.floodgateHook = null;
119+
}
107120
}
108121

109122
@EventHandler
@@ -211,12 +224,9 @@ private boolean isBedrockPlayer(UUID correctedUUID) {
211224
// Floodgate will set a correct UUID at the beginning of the PreLoginEvent
212225
// and will cancel the online mode login for those players
213226
// Therefore we just ignore those
214-
if (floodgateVersion.startsWith("1")) {
215-
return FloodgateAPI.isBedrockPlayer(correctedUUID);
216-
} else if (floodgateVersion.startsWith("2")) {
217-
return FloodgateAPI.isBedrockPlayer(correctedUUID);
227+
if (floodgateHook == null) {
228+
return false;
218229
}
219-
220-
return false;
230+
return this.floodgateHook.isBedrockPlayer(correctedUUID);
221231
}
222232
}

0 commit comments

Comments
 (0)