Only add Floodgate prefixes if they are needed

Without this patch, Java players would also get a prefix.
This commit is contained in:
Smart123s
2021-06-29 15:57:44 +02:00
parent b92911bf26
commit 03850ae4f2
2 changed files with 12 additions and 2 deletions

View File

@ -120,7 +120,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
if (isPluginInstalled("floodgate")) {
if (getConfig().getBoolean("floodgatePrefixWorkaround")){
ProtocolLibrary.getProtocolManager().addPacketListener(new ManualNameChange(this));
ProtocolLibrary.getProtocolManager().addPacketListener(new ManualNameChange(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

@ -30,6 +30,7 @@ import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService;
import org.geysermc.floodgate.api.FloodgateApi;
@ -45,18 +46,27 @@ import static com.comphenix.protocol.PacketType.Login.Client.START;
*/
public class ManualNameChange extends PacketAdapter {
public ManualNameChange(FastLoginBukkit plugin) {
private final FloodgateService floodgate;
public ManualNameChange(FastLoginBukkit plugin, FloodgateService floodgate) {
super(params()
.plugin(plugin)
.types(START));
this.plugin = plugin;
this.floodgate = floodgate;
}
@Override
public void onPacketReceiving(PacketEvent packetEvent) {
PacketContainer packet = packetEvent.getPacket();
WrappedGameProfile originalProfile = packet.getGameProfiles().read(0);
if (floodgate.getBedrockPlayer(originalProfile.getName()) == null) {
//not a Floodgate player, no need to add a prefix
return;
}
packet.setMeta("original_name", originalProfile.getName());
String prefixedName = FloodgateApi.getInstance().getPlayerPrefix() + originalProfile.getName();
WrappedGameProfile updatedProfile = originalProfile.withName(prefixedName);