1
0
mirror of https://github.com/Suiranoil/SkinRestorer.git synced 2026-01-16 04:42:12 +00:00

move applyRestoredSkin and getPlayerSkin to PlayerUtils

This commit is contained in:
2024-06-27 19:35:42 +03:00
parent e45de1e180
commit 5b918f4b90
2 changed files with 16 additions and 13 deletions

View File

@@ -68,10 +68,10 @@ public class SkinRestorer {
for (GameProfile profile : acceptedProfiles) {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(profile.getId());
if (player == null || areSkinPropertiesEquals(skin, getPlayerSkin(player)))
if (player == null || areSkinPropertiesEquals(skin, PlayerUtils.getPlayerSkin(player)))
continue;
applyRestoredSkin(player.getGameProfile(), skin);
PlayerUtils.applyRestoredSkin(player, skin);
PlayerUtils.refreshPlayer(player);
acceptedPlayers.add(player);
}
@@ -84,17 +84,6 @@ public class SkinRestorer {
});
}
public static void applyRestoredSkin(GameProfile profile, Property skin) {
profile.getProperties().removeAll("textures");
if (skin != null)
profile.getProperties().put("textures", skin);
}
private static Property getPlayerSkin(ServerPlayerEntity player) {
return player.getGameProfile().getProperties().get("textures").stream().findFirst().orElse(null);
}
private static boolean areSkinPropertiesEquals(Property x, Property y) {
if (x == y)
return true;

View File

@@ -1,5 +1,7 @@
package net.lionarius.skinrestorer.util;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import net.minecraft.network.packet.s2c.play.*;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity;
@@ -46,4 +48,16 @@ public class PlayerUtils {
playerManager.sendStatusEffects(player);
}
}
public static Property getPlayerSkin(ServerPlayerEntity player) {
return player.getGameProfile().getProperties().get("textures").stream().findFirst().orElse(null);
}
public static void applyRestoredSkin(ServerPlayerEntity player, Property skin) {
GameProfile profile = player.getGameProfile();
profile.getProperties().removeAll("textures");
if (skin != null)
profile.getProperties().put("textures", skin);
}
}