mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
extract "textures" into TEXTURES_KEY constant
This commit is contained in:
@@ -2,9 +2,10 @@ package net.lionarius.skinrestorer.skin.provider;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||
import net.lionarius.skinrestorer.skin.SkinResult;
|
||||
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||
import net.lionarius.skinrestorer.util.JsonUtils;
|
||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||
import net.lionarius.skinrestorer.util.WebUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -24,7 +25,7 @@ public class MineskinSkinProvider {
|
||||
JsonObject texture = JsonUtils.parseJson(WebUtils.POSTRequest(new URL(API), USER_AGENT, TYPE, TYPE, input))
|
||||
.getAsJsonObject("data").getAsJsonObject("texture");
|
||||
|
||||
return SkinResult.success(new Property("textures", texture.get("value").getAsString(), texture.get("signature").getAsString()));
|
||||
return SkinResult.success(new Property(PlayerUtils.TEXTURES_KEY, texture.get("value").getAsString(), texture.get("signature").getAsString()));
|
||||
} catch (IOException e) {
|
||||
return SkinResult.error(e);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.gson.JsonObject;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import net.lionarius.skinrestorer.skin.SkinResult;
|
||||
import net.lionarius.skinrestorer.util.JsonUtils;
|
||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||
import net.lionarius.skinrestorer.util.WebUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -21,7 +22,7 @@ public class MojangSkinProvider {
|
||||
JsonObject texture = JsonUtils.parseJson(WebUtils.GETRequest(new URL(SESSION_SERVER + uuid + "?unsigned=false")))
|
||||
.getAsJsonArray("properties").get(0).getAsJsonObject();
|
||||
|
||||
return SkinResult.success(new Property("textures", texture.get("value").getAsString(), texture.get("signature").getAsString()));
|
||||
return SkinResult.success(new Property(PlayerUtils.TEXTURES_KEY, texture.get("value").getAsString(), texture.get("signature").getAsString()));
|
||||
} catch (Exception e) {
|
||||
return SkinResult.error(e);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import java.util.List;
|
||||
|
||||
public class PlayerUtils {
|
||||
|
||||
public static final String TEXTURES_KEY = "textures";
|
||||
|
||||
public static boolean isFakePlayer(ServerPlayerEntity player) {
|
||||
return player.getClass() != ServerPlayerEntity.class; // if the player isn't a server player entity, it must be someone's fake player
|
||||
}
|
||||
@@ -50,14 +52,14 @@ public class PlayerUtils {
|
||||
}
|
||||
|
||||
public static Property getPlayerSkin(ServerPlayerEntity player) {
|
||||
return player.getGameProfile().getProperties().get("textures").stream().findFirst().orElse(null);
|
||||
return player.getGameProfile().getProperties().get(TEXTURES_KEY).stream().findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public static void applyRestoredSkin(ServerPlayerEntity player, Property skin) {
|
||||
GameProfile profile = player.getGameProfile();
|
||||
profile.getProperties().removeAll("textures");
|
||||
profile.getProperties().removeAll(TEXTURES_KEY);
|
||||
|
||||
if (skin != null)
|
||||
profile.getProperties().put("textures", skin);
|
||||
profile.getProperties().put(TEXTURES_KEY, skin);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user