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.
This commit is contained in:
Smart123s committed 2021-06-13 14:24:14 +02:00
1 parent af0ef2aed9
commit 411148b560
10 files changed
+127 -155

No files matched your search

@@ -278,7 +278,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;
@@ -1,55 +0,0 @@
/*
* SPDX-License-Identifier: MIT
*
* The MIT License (MIT)
*
* Copyright (c) 2015-2021 <Your name and contributors>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.games647.fastlogin.bukkit.hook.floodgate;
import org.bukkit.Bukkit;
import org.geysermc.floodgate.api.FloodgateApi;
import org.geysermc.floodgate.api.player.FloodgatePlayer;
public class FloodgateHook {
public FloodgateHook() { }
/**
* The FloodgateApi does not support querying players by name, so this function
* iterates over every online FloodgatePlayer and checks if the requested
* username can be found
*
* @param username the name of the player
* @return FloodgatePlayer if found, null otherwise
*/
public FloodgatePlayer getFloodgatePlayer(String username) {
if (Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate")) {
for (FloodgatePlayer floodgatePlayer : FloodgateApi.getInstance().getPlayers()) {
if (floodgatePlayer.getUsername().equals(username)) {
return floodgatePlayer;
}
}
}
return null;
}
}
@@ -30,7 +30,6 @@ import com.comphenix.protocol.events.PacketEvent;
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPreLoginEvent;
import com.github.games647.fastlogin.bukkit.hook.floodgate.FloodgateHook;
import com.github.games647.fastlogin.core.StoredProfile;
import com.github.games647.fastlogin.core.shared.JoinManagement;
import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent;
@@ -40,7 +39,6 @@ import java.util.Random;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.geysermc.floodgate.api.player.FloodgatePlayer;
public class NameCheckTask extends JoinManagement<Player, CommandSender, ProtocolLibLoginSource>
implements Runnable {
@@ -54,10 +52,9 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
private final Player player;
private final String username;
private final FloodgateHook floodgateHook;
public NameCheckTask(FastLoginBukkit plugin, PacketEvent packetEvent, Random random,
Player player, String username, PublicKey publicKey, FloodgateHook floodgateHook) {
Player player, String username, PublicKey publicKey) {
super(plugin.getCore(), plugin.getCore().getAuthPluginHook());
this.plugin = plugin;
@@ -66,7 +63,6 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
this.random = random;
this.player = player;
this.username = username;
this.floodgateHook = floodgateHook;
}
@Override
@@ -116,13 +112,4 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
BukkitLoginSession loginSession = new BukkitLoginSession(username, profile);
plugin.putSession(player.getAddress(), loginSession);
}
@Override
protected FloodgatePlayer getFloodgatePlayer(Object id) {
if ((id instanceof String)) {
return floodgateHook.getFloodgatePlayer((String) id);
}
return null;
}
}
@@ -31,7 +31,6 @@ import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.hook.floodgate.FloodgateHook;
import com.github.games647.fastlogin.core.RateLimiter;
import java.security.KeyPair;
@@ -50,7 +49,6 @@ public class ProtocolLibListener extends PacketAdapter {
private final SecureRandom random = new SecureRandom();
private final KeyPair keyPair = EncryptionUtil.generateKeyPair();
private final RateLimiter rateLimiter;
private final FloodgateHook floodgateHook;
public ProtocolLibListener(FastLoginBukkit plugin, RateLimiter rateLimiter) {
//run async in order to not block the server, because we are making api calls to Mojang
@@ -61,7 +59,6 @@ public class ProtocolLibListener extends PacketAdapter {
this.plugin = plugin;
this.rateLimiter = rateLimiter;
this.floodgateHook = new FloodgateHook();
}
public static void register(FastLoginBukkit plugin, RateLimiter rateLimiter) {
@@ -116,8 +113,7 @@ public class ProtocolLibListener extends PacketAdapter {
plugin.getLog().trace("GameProfile {} with {} connecting", sessionKey, username);
packetEvent.getAsyncMarker().incrementProcessingDelay();
Runnable nameCheckTask = new NameCheckTask(plugin, packetEvent, random, player, username, keyPair.getPublic(),
floodgateHook);
Runnable nameCheckTask = new NameCheckTask(plugin, packetEvent, random, player, username, keyPair.getPublic());
plugin.getScheduler().runAsync(nameCheckTask);
}
}
@@ -29,7 +29,6 @@ import com.github.games647.craftapi.UUIDAdapter;
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPreLoginEvent;
import com.github.games647.fastlogin.bukkit.hook.floodgate.FloodgateHook;
import com.github.games647.fastlogin.core.RateLimiter;
import com.github.games647.fastlogin.core.StoredProfile;
import com.github.games647.fastlogin.core.shared.JoinManagement;
@@ -52,14 +51,12 @@ public class ProtocolSupportListener extends JoinManagement<Player, CommandSende
private final FastLoginBukkit plugin;
private final RateLimiter rateLimiter;
private final FloodgateHook floodgateHook;
public ProtocolSupportListener(FastLoginBukkit plugin, RateLimiter rateLimiter) {
super(plugin.getCore(), plugin.getCore().getAuthPluginHook());
this.plugin = plugin;
this.rateLimiter = rateLimiter;
this.floodgateHook = new FloodgateHook();
}
@EventHandler
@@ -129,12 +126,4 @@ public class ProtocolSupportListener extends JoinManagement<Player, CommandSende
BukkitLoginSession loginSession = new BukkitLoginSession(username, profile);
plugin.putSession(source.getAddress(), loginSession);
}
@Override
protected Object getFloodgatePlayer(Object id) {
if ((id instanceof String)) {
return floodgateHook.getFloodgatePlayer((String) id);
}
return null;
}
}