mirror of
https://github.com/GeyserMC/Floodgate.git
synced 2025-12-19 14:59:20 +00:00
Made Floodgate compatible with latest Spigot changes
This commit is contained in:
@@ -167,31 +167,35 @@ public final class SpigotDataHandler extends CommonDataHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the player his GameProfile, we can't change the username without this
|
|
||||||
GameProfile gameProfile = new GameProfile(
|
GameProfile gameProfile = new GameProfile(
|
||||||
player.getCorrectUniqueId(), player.getCorrectUsername()
|
player.getCorrectUniqueId(), player.getCorrectUsername()
|
||||||
);
|
);
|
||||||
setValue(packetListener, ClassNames.LOGIN_PROFILE, gameProfile);
|
|
||||||
|
|
||||||
// we have to fake the offline player (login) cycle
|
// we have to fake the offline player (login) cycle
|
||||||
// just like on Spigot:
|
|
||||||
|
|
||||||
Object loginHandler = ClassNames.LOGIN_HANDLER_CONSTRUCTOR.newInstance(packetListener);
|
|
||||||
|
|
||||||
if (ClassNames.IS_PRE_1_20_2) {
|
if (ClassNames.IS_PRE_1_20_2) {
|
||||||
// 1.20.1 and below
|
// 1.20.1 and below
|
||||||
|
// - set profile, otherwise the username doesn't change
|
||||||
// LoginListener#initUUID
|
// - LoginListener#initUUID
|
||||||
// new LoginHandler().fireEvents();
|
// - new LoginHandler().fireEvents();
|
||||||
|
|
||||||
// and the tick of LoginListener will do the rest
|
// and the tick of LoginListener will do the rest
|
||||||
|
|
||||||
|
Object loginHandler = ClassNames.LOGIN_HANDLER_CONSTRUCTOR.newInstance(packetListener);
|
||||||
|
setValue(packetListener, ClassNames.LOGIN_PROFILE, gameProfile);
|
||||||
ClassNames.INIT_UUID.invoke(packetListener);
|
ClassNames.INIT_UUID.invoke(packetListener);
|
||||||
ClassNames.FIRE_LOGIN_EVENTS.invoke(loginHandler);
|
ClassNames.FIRE_LOGIN_EVENTS.invoke(loginHandler);
|
||||||
} else {
|
} else if (!ClassNames.IS_POST_LOGIN_HANDLER) {
|
||||||
// 1.20.2 and above we directly register the profile
|
// 1.20.2 until somewhere in 1.20.4 we can directly register the profile
|
||||||
|
|
||||||
|
Object loginHandler = ClassNames.LOGIN_HANDLER_CONSTRUCTOR.newInstance(packetListener);
|
||||||
ClassNames.FIRE_LOGIN_EVENTS_GAME_PROFILE.invoke(loginHandler, gameProfile);
|
ClassNames.FIRE_LOGIN_EVENTS_GAME_PROFILE.invoke(loginHandler, gameProfile);
|
||||||
|
} else {
|
||||||
|
// somewhere during 1.20.4 md_5 moved stuff to CraftBukkit
|
||||||
|
|
||||||
|
// LoginListener#callPlayerPreLoginEvents(GameProfile)
|
||||||
|
// LoginListener#startClientVerification(GameProfile)
|
||||||
|
ClassNames.CALL_PLAYER_PRE_LOGIN_EVENTS.invoke(packetListener, gameProfile);
|
||||||
|
ClassNames.START_CLIENT_VERIFICATION.invoke(packetListener, gameProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.pipeline().remove(this);
|
ctx.pipeline().remove(this);
|
||||||
|
|||||||
@@ -59,11 +59,10 @@ public class ClassNames {
|
|||||||
public static final Class<?> HANDSHAKE_PACKET;
|
public static final Class<?> HANDSHAKE_PACKET;
|
||||||
public static final Class<?> LOGIN_START_PACKET;
|
public static final Class<?> LOGIN_START_PACKET;
|
||||||
public static final Class<?> LOGIN_LISTENER;
|
public static final Class<?> LOGIN_LISTENER;
|
||||||
public static final Class<?> LOGIN_HANDLER;
|
|
||||||
@Nullable public static final Class<?> CLIENT_INTENT;
|
@Nullable public static final Class<?> CLIENT_INTENT;
|
||||||
|
|
||||||
public static final Constructor<OfflinePlayer> CRAFT_OFFLINE_PLAYER_CONSTRUCTOR;
|
public static final Constructor<OfflinePlayer> CRAFT_OFFLINE_PLAYER_CONSTRUCTOR;
|
||||||
public static final Constructor<?> LOGIN_HANDLER_CONSTRUCTOR;
|
@Nullable public static final Constructor<?> LOGIN_HANDLER_CONSTRUCTOR;
|
||||||
@Nullable public static final Constructor<?> HANDSHAKE_PACKET_CONSTRUCTOR;
|
@Nullable public static final Constructor<?> HANDSHAKE_PACKET_CONSTRUCTOR;
|
||||||
|
|
||||||
public static final Field SOCKET_ADDRESS;
|
public static final Field SOCKET_ADDRESS;
|
||||||
@@ -84,13 +83,17 @@ public class ClassNames {
|
|||||||
@Nullable public static final Method INIT_UUID;
|
@Nullable public static final Method INIT_UUID;
|
||||||
@Nullable public static final Method FIRE_LOGIN_EVENTS;
|
@Nullable public static final Method FIRE_LOGIN_EVENTS;
|
||||||
@Nullable public static final Method FIRE_LOGIN_EVENTS_GAME_PROFILE;
|
@Nullable public static final Method FIRE_LOGIN_EVENTS_GAME_PROFILE;
|
||||||
|
@Nullable public static final Method CALL_PLAYER_PRE_LOGIN_EVENTS;
|
||||||
|
@Nullable public static final Method START_CLIENT_VERIFICATION;
|
||||||
|
|
||||||
public static final Field BUNGEE;
|
public static final Field BUNGEE;
|
||||||
|
|
||||||
public static final boolean IS_FOLIA;
|
public static final boolean IS_FOLIA;
|
||||||
public static final boolean IS_PRE_1_20_2;
|
public static final boolean IS_PRE_1_20_2;
|
||||||
|
public static final boolean IS_POST_LOGIN_HANDLER;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
// ahhhhhhh, this class should really be reworked at this point
|
||||||
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||||
SPIGOT_MAPPING_PREFIX = "net.minecraft.server." + version;
|
SPIGOT_MAPPING_PREFIX = "net.minecraft.server." + version;
|
||||||
|
|
||||||
@@ -167,6 +170,14 @@ public class ClassNames {
|
|||||||
INIT_UUID = getMethod(LOGIN_LISTENER, "initUUID");
|
INIT_UUID = getMethod(LOGIN_LISTENER, "initUUID");
|
||||||
IS_PRE_1_20_2 = INIT_UUID != null;
|
IS_PRE_1_20_2 = INIT_UUID != null;
|
||||||
|
|
||||||
|
// somewhere during 1.20.4 md_5 moved PreLogin logic to CraftBukkit
|
||||||
|
CALL_PLAYER_PRE_LOGIN_EVENTS = getMethod(
|
||||||
|
LOGIN_LISTENER,
|
||||||
|
"callPlayerPreLoginEvents",
|
||||||
|
GameProfile.class
|
||||||
|
);
|
||||||
|
IS_POST_LOGIN_HANDLER = CALL_PLAYER_PRE_LOGIN_EVENTS != null;
|
||||||
|
|
||||||
if (IS_PRE_1_20_2) {
|
if (IS_PRE_1_20_2) {
|
||||||
Class<?> packetListenerClass = getClassOrFallback(
|
Class<?> packetListenerClass = getClassOrFallback(
|
||||||
"net.minecraft.network.PacketListener",
|
"net.minecraft.network.PacketListener",
|
||||||
@@ -183,22 +194,37 @@ public class ClassNames {
|
|||||||
}
|
}
|
||||||
checkNotNull(PACKET_LISTENER, "Packet listener");
|
checkNotNull(PACKET_LISTENER, "Packet listener");
|
||||||
|
|
||||||
LOGIN_HANDLER = getClassOrFallback(
|
if (IS_POST_LOGIN_HANDLER) {
|
||||||
|
makeAccessible(CALL_PLAYER_PRE_LOGIN_EVENTS);
|
||||||
|
|
||||||
|
START_CLIENT_VERIFICATION = getMethod(LOGIN_LISTENER, "b", GameProfile.class);
|
||||||
|
checkNotNull(START_CLIENT_VERIFICATION, "startClientVerification");
|
||||||
|
makeAccessible(START_CLIENT_VERIFICATION);
|
||||||
|
|
||||||
|
LOGIN_HANDLER_CONSTRUCTOR = null;
|
||||||
|
FIRE_LOGIN_EVENTS = null;
|
||||||
|
FIRE_LOGIN_EVENTS_GAME_PROFILE = null;
|
||||||
|
} else {
|
||||||
|
Class<?> loginHandler = getClassOrFallback(
|
||||||
"net.minecraft.server.network.LoginListener$LoginHandler",
|
"net.minecraft.server.network.LoginListener$LoginHandler",
|
||||||
nmsPackage + "LoginListener$LoginHandler"
|
nmsPackage + "LoginListener$LoginHandler"
|
||||||
);
|
);
|
||||||
|
|
||||||
LOGIN_HANDLER_CONSTRUCTOR =
|
LOGIN_HANDLER_CONSTRUCTOR =
|
||||||
ReflectionUtils.getConstructor(LOGIN_HANDLER, true, LOGIN_LISTENER);
|
ReflectionUtils.getConstructor(loginHandler, true, LOGIN_LISTENER);
|
||||||
checkNotNull(LOGIN_HANDLER_CONSTRUCTOR, "LoginHandler constructor");
|
checkNotNull(LOGIN_HANDLER_CONSTRUCTOR, "LoginHandler constructor");
|
||||||
|
|
||||||
FIRE_LOGIN_EVENTS = getMethod(LOGIN_HANDLER, "fireEvents");
|
FIRE_LOGIN_EVENTS = getMethod(loginHandler, "fireEvents");
|
||||||
|
|
||||||
// LoginHandler().fireEvents(GameProfile)
|
// LoginHandler().fireEvents(GameProfile)
|
||||||
FIRE_LOGIN_EVENTS_GAME_PROFILE = getMethod(LOGIN_HANDLER, "fireEvents", GameProfile.class);
|
FIRE_LOGIN_EVENTS_GAME_PROFILE = getMethod(loginHandler, "fireEvents",
|
||||||
|
GameProfile.class);
|
||||||
checkNotNull(FIRE_LOGIN_EVENTS, FIRE_LOGIN_EVENTS_GAME_PROFILE,
|
checkNotNull(FIRE_LOGIN_EVENTS, FIRE_LOGIN_EVENTS_GAME_PROFILE,
|
||||||
"fireEvents from LoginHandler", "fireEvents(GameProfile) from LoginHandler");
|
"fireEvents from LoginHandler", "fireEvents(GameProfile) from LoginHandler");
|
||||||
|
|
||||||
|
START_CLIENT_VERIFICATION = null;
|
||||||
|
}
|
||||||
|
|
||||||
PAPER_DISABLE_USERNAME_VALIDATION = getField(LOGIN_LISTENER,
|
PAPER_DISABLE_USERNAME_VALIDATION = getField(LOGIN_LISTENER,
|
||||||
"iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation");
|
"iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user