mirror of
https://github.com/GeyserMC/Floodgate.git
synced 2025-12-19 14:59:20 +00:00
Backport a similar fix for 1.20.2 profile properties
This commit is contained in:
@@ -39,7 +39,6 @@ import org.geysermc.floodgate.api.player.FloodgatePlayer;
|
||||
import org.geysermc.floodgate.event.EventBus;
|
||||
import org.geysermc.floodgate.event.skin.SkinApplyEventImpl;
|
||||
import org.geysermc.floodgate.skin.SkinApplier;
|
||||
import org.geysermc.floodgate.skin.SkinDataImpl;
|
||||
import org.geysermc.floodgate.util.ClassNames;
|
||||
import org.geysermc.floodgate.util.ReflectionUtils;
|
||||
import org.geysermc.floodgate.util.SpigotVersionSpecificMethods;
|
||||
@@ -78,7 +77,7 @@ public final class SpigotSkinApplier implements SkinApplier {
|
||||
// MultiMap from Guava. Floodgate relocates Guava.
|
||||
PropertyMap properties = profile.getProperties();
|
||||
|
||||
SkinData currentSkin = currentSkin(properties);
|
||||
SkinData currentSkin = versionSpecificMethods.currentSkin(properties);
|
||||
|
||||
SkinApplyEvent event = new SkinApplyEventImpl(floodgatePlayer, currentSkin, skinData);
|
||||
event.setCancelled(floodgatePlayer.isLinked());
|
||||
@@ -100,15 +99,6 @@ public final class SpigotSkinApplier implements SkinApplier {
|
||||
});
|
||||
}
|
||||
|
||||
private SkinData currentSkin(PropertyMap properties) {
|
||||
for (Property texture : properties.get("textures")) {
|
||||
if (!texture.getValue().isEmpty()) {
|
||||
return new SkinDataImpl(texture.getValue(), texture.getSignature());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void replaceSkin(PropertyMap properties, SkinData skinData) {
|
||||
properties.removeAll("textures");
|
||||
Property property = new Property("textures", skinData.value(), skinData.signature());
|
||||
|
||||
@@ -25,17 +25,24 @@
|
||||
|
||||
package org.geysermc.floodgate.util;
|
||||
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.geysermc.floodgate.SpigotPlugin;
|
||||
import org.geysermc.floodgate.api.event.skin.SkinApplyEvent;
|
||||
import org.geysermc.floodgate.skin.SkinDataImpl;
|
||||
|
||||
public final class SpigotVersionSpecificMethods {
|
||||
private static final Method GET_SPIGOT;
|
||||
private static final Method OLD_GET_LOCALE;
|
||||
private static final boolean NEW_VISIBILITY;
|
||||
|
||||
private static final Method NEW_PROPERTY_VALUE;
|
||||
private static final Method NEW_PROPERTY_SIGNATURE;
|
||||
|
||||
static {
|
||||
GET_SPIGOT = ReflectionUtils.getMethod(Player.class, "spigot");
|
||||
OLD_GET_LOCALE = ReflectionUtils.getMethod(Player.Spigot.class, "getLocale");
|
||||
@@ -44,6 +51,9 @@ public final class SpigotVersionSpecificMethods {
|
||||
Player.class, "hidePlayer",
|
||||
Plugin.class, Player.class
|
||||
);
|
||||
|
||||
NEW_PROPERTY_VALUE = ReflectionUtils.getMethod(Property.class, "value");
|
||||
NEW_PROPERTY_SIGNATURE = ReflectionUtils.getMethod(Property.class, "signature");
|
||||
}
|
||||
|
||||
private final SpigotPlugin plugin;
|
||||
@@ -70,6 +80,26 @@ public final class SpigotVersionSpecificMethods {
|
||||
hideAndShowPlayer0(on, target);
|
||||
}
|
||||
|
||||
public SkinApplyEvent.SkinData currentSkin(PropertyMap properties) {
|
||||
for (Property property : properties.get("textures")) {
|
||||
String value;
|
||||
String signature;
|
||||
if (NEW_PROPERTY_VALUE != null) {
|
||||
value = ReflectionUtils.castedInvoke(property, NEW_PROPERTY_VALUE);
|
||||
signature = ReflectionUtils.castedInvoke(property, NEW_PROPERTY_SIGNATURE);
|
||||
} else {
|
||||
value = property.getValue();
|
||||
signature = property.getSignature();
|
||||
}
|
||||
|
||||
//noinspection DataFlowIssue
|
||||
if (!value.isEmpty()) {
|
||||
return new SkinDataImpl(value, signature);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void schedule(Runnable runnable, long delay) {
|
||||
if (ClassNames.IS_FOLIA) {
|
||||
plugin.getServer().getAsyncScheduler().runDelayed(
|
||||
|
||||
Reference in New Issue
Block a user