1
0
mirror of https://github.com/GeyserMC/Floodgate.git synced 2025-12-19 14:59:20 +00:00

Add ProtocolSupport support (#43)

* Add ProtocolSupport support

This commit hooks into ProtocolSupport to prevent it from attempting an online connection with the Floodgate player. This has been tested with linked accounts and BungeeCord.

Co-authored-by: Tim203 <mctim203@gmail.com>
This commit is contained in:
Camotoy
2020-07-29 06:51:11 -04:00
committed by GitHub
parent d44377032b
commit 9c0b331125
5 changed files with 61 additions and 1 deletions

View File

@@ -16,6 +16,10 @@
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>Jitpack</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
@@ -43,6 +47,12 @@
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.ProtocolSupport</groupId>
<artifactId>ProtocolSupport</artifactId>
<version>5f712a969a</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>

View File

@@ -14,6 +14,7 @@ import org.geysermc.floodgate.command.LinkAccountCommand;
import org.geysermc.floodgate.command.UnlinkAccountCommand;
import org.geysermc.floodgate.injector.BukkitInjector;
import org.geysermc.floodgate.util.CommandUtil;
import org.geysermc.floodgate.util.ProtocolSupportUtil;
import org.geysermc.floodgate.util.ReflectionUtil;
import java.util.logging.Level;
@@ -52,6 +53,9 @@ public class BukkitPlugin extends JavaPlugin implements Listener {
// Register the plugin as an event listener to we get join and leave events
Bukkit.getServer().getPluginManager().registerEvents(this, this);
// Check for ProtocolSupport
ProtocolSupportUtil.checkForProtocolSupport(this);
}
@Override

View File

@@ -7,7 +7,10 @@ import lombok.RequiredArgsConstructor;
import org.geysermc.floodgate.HandshakeHandler.HandshakeResult;
import org.geysermc.floodgate.injector.BukkitInjector;
import org.geysermc.floodgate.util.BedrockData;
import org.geysermc.floodgate.util.ProtocolSupportUtil;
import org.geysermc.floodgate.util.ReflectionUtil;
import protocolsupport.protocol.ConnectionImpl;
import protocolsupport.protocol.packet.handler.AbstractLoginListener;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
@@ -94,7 +97,7 @@ public class PacketHandler extends SimpleChannelInboundHandler<Object> {
}
plugin.getLogger().info("Added " + fPlayer.getCorrectUsername() + " " + fPlayer.getCorrectUniqueId());
} else if (isLogin) {
if (!bungee) {
if (!bungee && !ProtocolSupportUtil.isProtocolSupport) {
// we have to fake the offline player cycle
Object loginListener = packetListenerField.get(networkManager);
@@ -106,6 +109,14 @@ public class PacketHandler extends SimpleChannelInboundHandler<Object> {
fireEventsMethod.invoke(loginHandlerConstructor.newInstance(loginListener)); // new LoginHandler().fireEvents();
setValue(loginListener, protocolStateField, readyToAcceptState); // LoginLister#protocolState = READY_TO_ACCEPT
// The tick of LoginListener will do the rest
} else if (ProtocolSupportUtil.isProtocolSupport && !bungee) { // Has to be managed separately or else we get kicked
ConnectionImpl connection = ConnectionImpl.getFromChannel(ctx.channel());
// Set correct UUID and name on PS's end
connection.getLoginProfile().setName(fPlayer.getCorrectUsername());
connection.getLoginProfile().setOriginalName(fPlayer.getCorrectUsername());
connection.getLoginProfile().setUUID(fPlayer.getCorrectUniqueId());
connection.getLoginProfile().setOriginalUUID(fPlayer.getCorrectUniqueId());
((AbstractLoginListener) connection.getNetworkManagerWrapper().getPacketListener()).handleLoginStart(fPlayer.getCorrectUsername());
}
}
} finally {

View File

@@ -0,0 +1,34 @@
package org.geysermc.floodgate.util;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.geysermc.floodgate.FloodgateAPI;
import protocolsupport.api.events.PlayerLoginStartEvent;
public class ProtocolSupportUtil implements Listener {
public static boolean isProtocolSupport = false;
public static void checkForProtocolSupport(Plugin floodgate) {
if (Bukkit.getServer().getPluginManager().getPlugin("ProtocolSupport") != null) {
isProtocolSupport = true;
Bukkit.getServer().getPluginManager().registerEvents(new ProtocolSupportUtil(), floodgate);
}
}
/**
* Force ProtocolSupport to handle Bedrock users in offline mode, otherwise they kick us
* @param event ProtocolSupport's player login start event
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onLoginStart(final PlayerLoginStartEvent event) {
if (event.getConnection().getProfile().getUUID() == null) return; // A normal player that doesn't have a UUID set
if (FloodgateAPI.isBedrockPlayer(event.getConnection().getProfile().getUUID())) {
event.setOnlineMode(false); // Otherwise ProtocolSupport attempts to connect with online mode
}
}
}

View File

@@ -5,6 +5,7 @@ author: ${project.organization.name}
website: ${project.url}
main: org.geysermc.floodgate.BukkitPlugin
api-version: 1.13
softdepend: ["ProtocolSupport"]
commands:
linkaccount:
description: Link your Java and Bedrock accounts