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:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user