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

Re-added support for BungeeCord 1.18

Metrics showed that more than 33% of the BungeeCord platform users still use a 1.18.x version
This commit is contained in:
Tim203
2022-06-11 14:12:13 +02:00
parent 5d5713ed9e
commit af4030ac12
4 changed files with 71 additions and 37 deletions

View File

@@ -25,27 +25,48 @@
package org.geysermc.floodgate.pluginmessage;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.geysermc.floodgate.util.ReflectionUtils.getFieldOfType;
import static org.geysermc.floodgate.util.ReflectionUtils.setValue;
import static org.geysermc.floodgate.util.ReflectionUtils.getMethodByName;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import lombok.RequiredArgsConstructor;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.connection.InitialHandler;
import net.md_5.bungee.connection.LoginResult;
import net.md_5.bungee.protocol.Property;
import org.geysermc.floodgate.api.logger.FloodgateLogger;
import org.geysermc.floodgate.api.player.FloodgatePlayer;
import org.geysermc.floodgate.skin.SkinApplier;
import org.geysermc.floodgate.skin.SkinData;
import org.geysermc.floodgate.util.ReflectionUtils;
@RequiredArgsConstructor
public final class BungeeSkinApplier implements SkinApplier {
private static final Field LOGIN_RESULT;
private static final Field LOGIN_RESULT_FIELD;
private static final Method SET_PROPERTIES_METHOD;
private static final Class<?> PROPERTY_CLASS;
private static final Constructor<?> PROPERTY_CONSTRUCTOR;
static {
LOGIN_RESULT = getFieldOfType(InitialHandler.class, LoginResult.class);
LOGIN_RESULT_FIELD = getFieldOfType(InitialHandler.class, LoginResult.class);
checkNotNull(LOGIN_RESULT_FIELD, "LoginResult field cannot be null");
SET_PROPERTIES_METHOD = getMethodByName(LoginResult.class, "setProperties", true);
PROPERTY_CLASS = ReflectionUtils.getClassOrFallbackPrefixed(
"protocol.Property", "connection.LoginResult.Property"
);
PROPERTY_CONSTRUCTOR = ReflectionUtils.getConstructor(
PROPERTY_CLASS, true,
String.class, String.class, String.class
);
checkNotNull(PROPERTY_CONSTRUCTOR, "Property constructor cannot be null");
}
private final FloodgateLogger logger;
@@ -71,11 +92,17 @@ public final class BungeeSkinApplier implements SkinApplier {
if (loginResult == null) {
// id and name are unused and properties will be overridden
loginResult = new LoginResult(null, null, null);
setValue(handler, LOGIN_RESULT, loginResult);
ReflectionUtils.setValue(handler, LOGIN_RESULT_FIELD, loginResult);
}
Property property = new Property("textures", skinData.getValue(), skinData.getSignature());
Object property = ReflectionUtils.newInstance(
PROPERTY_CONSTRUCTOR,
"textures", skinData.getValue(), skinData.getSignature()
);
loginResult.setProperties(new Property[]{property});
Object propertyArray = Array.newInstance(PROPERTY_CLASS, 1);
Array.set(propertyArray, 0, property);
ReflectionUtils.invoke(loginResult, SET_PROPERTIES_METHOD, propertyArray);
}
}