mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
add ely.by provider
This commit is contained in:
@@ -59,6 +59,7 @@ public final class SkinRestorer {
|
||||
|
||||
SkinRestorer.providersRegistry.register(EmptySkinProvider.PROVIDER_NAME, SkinProvider.EMPTY, false);
|
||||
SkinRestorer.providersRegistry.register(MojangSkinProvider.PROVIDER_NAME, SkinProvider.MOJANG);
|
||||
SkinRestorer.providersRegistry.register(ElyBySkinProvider.PROVIDER_NAME, SkinProvider.ELY_BY);
|
||||
SkinRestorer.providersRegistry.register(MineskinSkinProvider.PROVIDER_NAME, SkinProvider.MINESKIN);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
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.util.JsonUtils;
|
||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||
import net.lionarius.skinrestorer.util.Result;
|
||||
import net.lionarius.skinrestorer.util.WebUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class ElyBySkinProvider implements SkinProvider {
|
||||
public static final String PROVIDER_NAME = "ely.by";
|
||||
|
||||
private static final URI API_URI;
|
||||
|
||||
static {
|
||||
try {
|
||||
API_URI = new URI("http://skinsystem.ely.by/");
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArgumentName() {
|
||||
return "username";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasVariantSupport() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Optional<Property>, Exception> getSkin(String username, SkinVariant variant) {
|
||||
try {
|
||||
var profile = ElyBySkinProvider.getElyByProfile(username);
|
||||
|
||||
var properties = profile.getAsJsonArray("properties");
|
||||
var textures = PlayerUtils.findTexturesProperty(properties);
|
||||
|
||||
return Result.ofNullable(textures);
|
||||
} catch (Exception e) {
|
||||
return Result.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static JsonObject getElyByProfile(String username) throws IOException {
|
||||
var request = HttpRequest.newBuilder()
|
||||
.uri(ElyBySkinProvider.API_URI
|
||||
.resolve("textures/signed/")
|
||||
.resolve(username + "?unsigned=false")
|
||||
)
|
||||
.GET()
|
||||
.build();
|
||||
|
||||
var response = WebUtils.executeRequest(request);
|
||||
WebUtils.throwOnClientErrors(response);
|
||||
|
||||
if (response.statusCode() != 200)
|
||||
throw new IllegalArgumentException("no profile with name " + username);
|
||||
|
||||
return JsonUtils.parseJson(response.body());
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package net.lionarius.skinrestorer.skin.provider;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||
import net.lionarius.skinrestorer.util.JsonUtils;
|
||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||
import net.lionarius.skinrestorer.util.Result;
|
||||
import net.lionarius.skinrestorer.util.WebUtils;
|
||||
|
||||
@@ -52,7 +52,7 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
var profile = MojangSkinProvider.getMojangProfile(uuid);
|
||||
|
||||
var properties = profile.getAsJsonArray("properties");
|
||||
var textures = MojangSkinProvider.findTexturesProperty(properties);
|
||||
var textures = PlayerUtils.findTexturesProperty(properties);
|
||||
|
||||
return Result.ofNullable(textures);
|
||||
} catch (Exception e) {
|
||||
@@ -60,27 +60,6 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private static Property findTexturesProperty(JsonArray properties) {
|
||||
Property textures = null;
|
||||
for (var property : properties) {
|
||||
var propertyObject = property.getAsJsonObject();
|
||||
if (propertyObject == null)
|
||||
continue;
|
||||
|
||||
try {
|
||||
textures = JsonUtils.fromJson(propertyObject, Property.class);
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
if (textures == null)
|
||||
throw new IllegalStateException("no textures in profile");
|
||||
|
||||
return textures;
|
||||
}
|
||||
|
||||
private static String getUuid(final String name) throws IOException {
|
||||
var request = HttpRequest.newBuilder()
|
||||
.uri(MojangSkinProvider.API_URI
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.Optional;
|
||||
public interface SkinProvider {
|
||||
EmptySkinProvider EMPTY = new EmptySkinProvider();
|
||||
MojangSkinProvider MOJANG = new MojangSkinProvider();
|
||||
ElyBySkinProvider ELY_BY = new ElyBySkinProvider();
|
||||
MineskinSkinProvider MINESKIN = new MineskinSkinProvider();
|
||||
|
||||
String getArgumentName();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.lionarius.skinrestorer.util;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
@@ -120,4 +121,25 @@ public final class PlayerUtils {
|
||||
|
||||
return xJson.equals(yJson);
|
||||
}
|
||||
|
||||
public static Property findTexturesProperty(JsonArray properties) {
|
||||
Property textures = null;
|
||||
for (var property : properties) {
|
||||
var propertyObject = property.getAsJsonObject();
|
||||
if (propertyObject == null)
|
||||
continue;
|
||||
|
||||
try {
|
||||
textures = JsonUtils.fromJson(propertyObject, Property.class);
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
if (textures == null)
|
||||
throw new IllegalStateException("no textures in profile");
|
||||
|
||||
return textures;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user