Skip to content

Commit

Permalink
Backport a similar fix for 1.20.2 profile properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim203 committed Oct 13, 2023
1 parent f9b427f commit 71acc6c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
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;
Expand Down Expand Up @@ -78,7 +77,7 @@ private void applySkin0(FloodgatePlayer floodgatePlayer, SkinData skinData, bool
// 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());
Expand All @@ -100,15 +99,6 @@ private void applySkin0(FloodgatePlayer floodgatePlayer, SkinData skinData, bool
});
}

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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
Expand All @@ -70,6 +80,26 @@ public void hideAndShowPlayer(Player on, Player target) {
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(
Expand Down

0 comments on commit 71acc6c

Please sign in to comment.