Skip to content

Commit 411148b

Browse files
committed
No longer reference 'Floodgate' in JoinManagement
Referencing 'FloodgatePlayer' in JoinManagement.java and it's subclasses has cause ProtocolLib to fail to register an event when Floodgate was not installed.
1 parent af0ef2a commit 411148b

File tree

10 files changed

+127
-155
lines changed

10 files changed

+127
-155
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ private boolean isValidFloodgateConfigString(String key) {
278278
* @param name the name of the plugin
279279
* @return true if the plugin is installed
280280
*/
281-
private boolean isPluginInstalled(String name) {
281+
public boolean isPluginInstalled(String name) {
282282
//the plugin may be enabled after FastLogin, so isPluginEnabled()
283283
//won't work here
284284
return Bukkit.getServer().getPluginManager().getPlugin(name) != null;

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/floodgate/FloodgateHook.java

Lines changed: 0 additions & 55 deletions
This file was deleted.

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
3131
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
3232
import com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPreLoginEvent;
33-
import com.github.games647.fastlogin.bukkit.hook.floodgate.FloodgateHook;
3433
import com.github.games647.fastlogin.core.StoredProfile;
3534
import com.github.games647.fastlogin.core.shared.JoinManagement;
3635
import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent;
@@ -40,7 +39,6 @@
4039

4140
import org.bukkit.command.CommandSender;
4241
import org.bukkit.entity.Player;
43-
import org.geysermc.floodgate.api.player.FloodgatePlayer;
4442

4543
public class NameCheckTask extends JoinManagement<Player, CommandSender, ProtocolLibLoginSource>
4644
implements Runnable {
@@ -54,10 +52,9 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
5452
private final Player player;
5553
private final String username;
5654

57-
private final FloodgateHook floodgateHook;
5855

5956
public NameCheckTask(FastLoginBukkit plugin, PacketEvent packetEvent, Random random,
60-
Player player, String username, PublicKey publicKey, FloodgateHook floodgateHook) {
57+
Player player, String username, PublicKey publicKey) {
6158
super(plugin.getCore(), plugin.getCore().getAuthPluginHook());
6259

6360
this.plugin = plugin;
@@ -66,7 +63,6 @@ public NameCheckTask(FastLoginBukkit plugin, PacketEvent packetEvent, Random ran
6663
this.random = random;
6764
this.player = player;
6865
this.username = username;
69-
this.floodgateHook = floodgateHook;
7066
}
7167

7268
@Override
@@ -116,13 +112,4 @@ public void startCrackedSession(ProtocolLibLoginSource source, StoredProfile pro
116112
BukkitLoginSession loginSession = new BukkitLoginSession(username, profile);
117113
plugin.putSession(player.getAddress(), loginSession);
118114
}
119-
120-
@Override
121-
protected FloodgatePlayer getFloodgatePlayer(Object id) {
122-
if ((id instanceof String)) {
123-
return floodgateHook.getFloodgatePlayer((String) id);
124-
}
125-
return null;
126-
}
127-
128115
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import com.comphenix.protocol.events.PacketContainer;
3232
import com.comphenix.protocol.events.PacketEvent;
3333
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
34-
import com.github.games647.fastlogin.bukkit.hook.floodgate.FloodgateHook;
3534
import com.github.games647.fastlogin.core.RateLimiter;
3635

3736
import java.security.KeyPair;
@@ -50,7 +49,6 @@ public class ProtocolLibListener extends PacketAdapter {
5049
private final SecureRandom random = new SecureRandom();
5150
private final KeyPair keyPair = EncryptionUtil.generateKeyPair();
5251
private final RateLimiter rateLimiter;
53-
private final FloodgateHook floodgateHook;
5452

5553
public ProtocolLibListener(FastLoginBukkit plugin, RateLimiter rateLimiter) {
5654
//run async in order to not block the server, because we are making api calls to Mojang
@@ -61,7 +59,6 @@ public ProtocolLibListener(FastLoginBukkit plugin, RateLimiter rateLimiter) {
6159

6260
this.plugin = plugin;
6361
this.rateLimiter = rateLimiter;
64-
this.floodgateHook = new FloodgateHook();
6562
}
6663

6764
public static void register(FastLoginBukkit plugin, RateLimiter rateLimiter) {
@@ -116,8 +113,7 @@ private void onLogin(PacketEvent packetEvent, Player player) {
116113
plugin.getLog().trace("GameProfile {} with {} connecting", sessionKey, username);
117114

118115
packetEvent.getAsyncMarker().incrementProcessingDelay();
119-
Runnable nameCheckTask = new NameCheckTask(plugin, packetEvent, random, player, username, keyPair.getPublic(),
120-
floodgateHook);
116+
Runnable nameCheckTask = new NameCheckTask(plugin, packetEvent, random, player, username, keyPair.getPublic());
121117
plugin.getScheduler().runAsync(nameCheckTask);
122118
}
123119
}

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
3030
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
3131
import com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPreLoginEvent;
32-
import com.github.games647.fastlogin.bukkit.hook.floodgate.FloodgateHook;
3332
import com.github.games647.fastlogin.core.RateLimiter;
3433
import com.github.games647.fastlogin.core.StoredProfile;
3534
import com.github.games647.fastlogin.core.shared.JoinManagement;
@@ -52,14 +51,12 @@ public class ProtocolSupportListener extends JoinManagement<Player, CommandSende
5251

5352
private final FastLoginBukkit plugin;
5453
private final RateLimiter rateLimiter;
55-
private final FloodgateHook floodgateHook;
5654

5755
public ProtocolSupportListener(FastLoginBukkit plugin, RateLimiter rateLimiter) {
5856
super(plugin.getCore(), plugin.getCore().getAuthPluginHook());
5957

6058
this.plugin = plugin;
6159
this.rateLimiter = rateLimiter;
62-
this.floodgateHook = new FloodgateHook();
6360
}
6461

6562
@EventHandler
@@ -129,12 +126,4 @@ public void startCrackedSession(ProtocolLoginSource source, StoredProfile profil
129126
BukkitLoginSession loginSession = new BukkitLoginSession(username, profile);
130127
plugin.putSession(source.getAddress(), loginSession);
131128
}
132-
133-
@Override
134-
protected Object getFloodgatePlayer(Object id) {
135-
if ((id instanceof String)) {
136-
return floodgateHook.getFloodgatePlayer((String) id);
137-
}
138-
return null;
139-
}
140129
}

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

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

53+
import net.md_5.bungee.BungeeServerInfo;
5354
import net.md_5.bungee.api.CommandSender;
5455
import net.md_5.bungee.api.chat.TextComponent;
5556
import net.md_5.bungee.api.connection.PendingConnection;
@@ -189,4 +190,9 @@ public ThreadFactory getThreadFactory() {
189190
public AsyncScheduler getScheduler() {
190191
return scheduler;
191192
}
193+
194+
@Override
195+
public boolean isPluginInstalled(String name) {
196+
return getProxy().getPluginManager().getPlugin(name) != null;
197+
}
192198
}

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

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

28-
import org.geysermc.floodgate.api.player.FloodgatePlayer;
29-
3028
import com.github.games647.fastlogin.bungee.BungeeLoginSession;
3129
import com.github.games647.fastlogin.bungee.BungeeLoginSource;
3230
import com.github.games647.fastlogin.bungee.FastLoginBungee;
@@ -91,10 +89,4 @@ public void requestPremiumLogin(BungeeLoginSource source, StoredProfile profile,
9189
public void startCrackedSession(BungeeLoginSource source, StoredProfile profile, String username) {
9290
plugin.getSession().put(source.getConnection(), new BungeeLoginSession(username, false, profile));
9391
}
94-
95-
@Override
96-
protected FloodgatePlayer getFloodgatePlayer(Object id) {
97-
// force disabled for BungeeCord for now
98-
return null;
99-
}
10092
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2015-2021 <Your name and contributors>
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all
16+
* copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
* SOFTWARE.
25+
*/
26+
package com.github.games647.fastlogin.core.hooks;
27+
28+
import java.io.IOException;
29+
import java.util.Optional;
30+
31+
import com.github.games647.craftapi.model.Profile;
32+
import com.github.games647.craftapi.resolver.RateLimitException;
33+
import com.github.games647.fastlogin.core.shared.FastLoginCore;
34+
import com.github.games647.fastlogin.core.shared.LoginSource;
35+
36+
import org.geysermc.floodgate.api.FloodgateApi;
37+
import org.geysermc.floodgate.api.player.FloodgatePlayer;
38+
39+
public class FloodgateHook<P extends C, C, S extends LoginSource> {
40+
41+
private final FastLoginCore<P, C, ?> core;
42+
43+
public FloodgateHook(FastLoginCore<P, C, ?> core) {
44+
this.core = core;
45+
}
46+
47+
/**
48+
* Check if the player's name conflicts an existing Java player's name, and
49+
* kick them if it does
50+
*
51+
* @param username the name of the player
52+
* @param source an instance of LoginSource
53+
*/
54+
public void checkFloodgateNameConflict(String username, LoginSource source, FloodgatePlayer floodgatePlayer) {
55+
String allowConflict = core.getConfig().get("allowFloodgateNameConflict").toString().toLowerCase();
56+
57+
// check if the Bedrock player is linked to a Java account
58+
boolean isLinked = ((FloodgatePlayer) floodgatePlayer).getLinkedPlayer() != null;
59+
60+
if (allowConflict.equals("false")
61+
|| allowConflict.equals("linked") && !isLinked) {
62+
63+
// check for conflicting Premium Java name
64+
Optional<Profile> premiumUUID = Optional.empty();
65+
try {
66+
premiumUUID = core.getResolver().findProfile(username);
67+
} catch (IOException | RateLimitException e) {
68+
core.getPlugin().getLog().error(
69+
"Could not check wether Floodgate Player {}'s name conflicts a premium Java player's name.",
70+
username);
71+
try {
72+
source.kick("Could not check if your name conflicts an existing Java Premium Player's name");
73+
} catch (Exception e1) {
74+
core.getPlugin().getLog().error("Could not kick Player {}", username);
75+
}
76+
}
77+
78+
if (premiumUUID.isPresent()) {
79+
core.getPlugin().getLog().info("Bedrock Player {}'s name conflicts an existing Java Premium Player's name",
80+
username);
81+
try {
82+
source.kick("Your name conflicts an existing Java Premium Player's name");
83+
} catch (Exception e) {
84+
core.getPlugin().getLog().error("Could not kick Player {}", username);
85+
}
86+
}
87+
} else {
88+
core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username);
89+
}
90+
}
91+
92+
/**
93+
* The FloodgateApi does not support querying players by name, so this function
94+
* iterates over every online FloodgatePlayer and checks if the requested
95+
* username can be found
96+
*
97+
* @param username the name of the player
98+
* @return FloodgatePlayer if found, null otherwise
99+
*/
100+
public FloodgatePlayer getFloodgatePlayer(String username) {
101+
if (core.getPlugin().isPluginInstalled("floodgate")) {
102+
for (FloodgatePlayer floodgatePlayer : FloodgateApi.getInstance().getPlayers()) {
103+
if (floodgatePlayer.getUsername().equals(username)) {
104+
return floodgatePlayer;
105+
}
106+
}
107+
}
108+
return null;
109+
}
110+
111+
}

0 commit comments

Comments
 (0)