Fix plugin startup without ProtocolLib installed

Referencing `ProtocolLibrary` in FastLoginBukkit (even in an unreachable
code block) causes Bukkit servers to throw a NoClassDefFoundError on
startup.
Fix based on commit 0082cc6536
This commit is contained in:
Smart123s
2022-01-29 10:48:27 +01:00
parent 8a01ddc231
commit 7951c4c893
2 changed files with 11 additions and 2 deletions

View File

@ -25,7 +25,6 @@
*/
package com.github.games647.fastlogin.bukkit;
import com.comphenix.protocol.ProtocolLibrary;
import com.github.games647.fastlogin.bukkit.command.CrackedCommand;
import com.github.games647.fastlogin.bukkit.command.PremiumCommand;
import com.github.games647.fastlogin.bukkit.listener.ConnectionListener;
@ -121,7 +120,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
if (isPluginInstalled("floodgate")) {
if (getConfig().getBoolean("floodgatePrefixWorkaround")){
ProtocolLibrary.getProtocolManager().addPacketListener(new ManualNameChange(this, floodgateService));
ManualNameChange.register(this, floodgateService);
logger.info("Floodgate prefix injection workaround has been enabled.");
logger.info("If you have problems joining the server, try disabling it in the configuration.");
} else {

View File

@ -36,6 +36,8 @@ import org.geysermc.floodgate.api.FloodgateApi;
import static com.comphenix.protocol.PacketType.Login.Client.START;
import com.comphenix.protocol.ProtocolLibrary;
/**
* Manually inject Floodgate player name prefixes.
* <br>
@ -57,6 +59,14 @@ public class ManualNameChange extends PacketAdapter {
this.floodgate = floodgate;
}
public static void register(FastLoginBukkit plugin, FloodgateService floodgate) {
// they will be created with a static builder, because otherwise it will throw a NoClassDefFoundError
ProtocolLibrary.getProtocolManager()
.getAsynchronousManager()
.registerAsyncHandler(new ManualNameChange(plugin, floodgate))
.start();
}
@Override
public void onPacketReceiving(PacketEvent packetEvent) {
PacketContainer packet = packetEvent.getPacket();