Merge pull request #532 from Smart123s/fg-bk-ncshare

Share Floodgate name conflict check between Protocol Plugins
This commit is contained in:
games647
2021-06-14 10:37:11 +02:00
committed by GitHub
9 changed files with 150 additions and 39 deletions
@@ -276,7 +276,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
* @param name the name of the plugin
* @return true if the plugin is installed
*/
private boolean isPluginInstalled(String name) {
public boolean isPluginInstalled(String name) {
//the plugin may be enabled after FastLogin, so isPluginEnabled()
//won't work here
return Bukkit.getServer().getPluginManager().getPlugin(name) != null;
@@ -37,11 +37,8 @@ import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent;
import java.security.PublicKey;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.geysermc.floodgate.api.FloodgateApi;
import org.geysermc.floodgate.api.player.FloodgatePlayer;
public class NameCheckTask extends JoinManagement<Player, CommandSender, ProtocolLibLoginSource>
implements Runnable {
@@ -55,6 +52,7 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
private final Player player;
private final String username;
public NameCheckTask(FastLoginBukkit plugin, PacketEvent packetEvent, Random random,
Player player, String username, PublicKey publicKey) {
super(plugin.getCore(), plugin.getCore().getAuthPluginHook());
@@ -70,12 +68,6 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
@Override
public void run() {
try {
// check if the player is connecting through Geyser
if (!plugin.getCore().getConfig().get("allowFloodgateNameConflict").toString().equalsIgnoreCase("false")
&& getFloodgatePlayer(username) != null) {
plugin.getLog().info("Skipping name conflict checking for player {}", username);
return;
}
super.onLogin(username, new ProtocolLibLoginSource(packetEvent, player, random, publicKey));
} finally {
ProtocolLibrary.getProtocolManager().getAsynchronousManager().signalPacketTransmission(packetEvent);
@@ -119,16 +111,4 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
BukkitLoginSession loginSession = new BukkitLoginSession(username, profile);
plugin.putSession(player.getAddress(), loginSession);
}
private static FloodgatePlayer getFloodgatePlayer(String username) {
if (Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate")) {
// the Floodgate API requires UUID, which is inaccessible at NameCheckTask.java
for (FloodgatePlayer floodgatePlayer : FloodgateApi.getInstance().getPlayers()) {
if (floodgatePlayer.getUsername().equals(username)) {
return floodgatePlayer;
}
}
}
return null;
}
}
@@ -41,6 +41,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import protocolsupport.api.events.ConnectionCloseEvent;
import protocolsupport.api.events.PlayerLoginStartEvent;
import protocolsupport.api.events.PlayerProfileCompleteEvent;
@@ -75,7 +76,8 @@ public class ProtocolSupportListener extends JoinManagement<Player, CommandSende
//remove old data every time on a new login in order to keep the session only for one person
plugin.removeSession(address);
super.onLogin(username, new ProtocolLoginSource(loginStartEvent));
ProtocolLoginSource source = new ProtocolLoginSource(loginStartEvent);
super.onLogin(username, source);
}
@EventHandler
@@ -51,25 +51,10 @@ public class FloodgateAuthTask implements Runnable {
plugin.getLog().info(
"Player {} is connecting through Geyser Floodgate.",
player.getName());
String allowNameConflict = plugin.getCore().getConfig().get("allowFloodgateNameConflict").toString().toLowerCase();
// check if the Bedrock player is linked to a Java account
boolean isLinked = floodgatePlayer.getLinkedPlayer() != null;
if (allowNameConflict.equals("linked") && !isLinked) {
plugin.getLog().info(
"Bedrock Player {}'s name conflits an existing Java Premium Player's name",
player.getName());
// kicking must be synchronous
// https://www.spigotmc.org/threads/asynchronous-player-kick-problem.168580/
Bukkit.getScheduler().runTask(plugin, new Runnable() {
public void run() {
player.kickPlayer("This name is allready in use by a Premium Java Player");
}
});
return;
}
AuthPlugin<Player> authPlugin = plugin.getCore().getAuthPluginHook();
String autoLoginFloodgate = plugin.getCore().getConfig().get("autoLoginFloodgate").toString().toLowerCase();