mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
Compare commits
12 Commits
b5bed1c441
...
1.21.9-mul
| Author | SHA1 | Date | |
|---|---|---|---|
|
a0d8f3d518
|
|||
|
aa3cb3df09
|
|||
|
0524b5dab8
|
|||
|
301428147d
|
|||
|
2e655ce1f3
|
|||
|
7dcd1d4e81
|
|||
|
1aa606038e
|
|||
|
e832e02fd4
|
|||
|
ffd2a0dba7
|
|||
|
76e801c944
|
|||
|
da754aa830
|
|||
|
69a561f679
|
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [2.5.0] - 2026-01-14
|
||||||
|
### Added
|
||||||
|
- Added collection skin provider (allows assigning random skins from a predefined set)
|
||||||
|
- Added `forceFirstJoinSkinFetch` config option to force skin fetch on first join even if player already has a skin
|
||||||
|
|
||||||
## [2.4.3] - 2025-07-25
|
## [2.4.3] - 2025-07-25
|
||||||
### Fixed
|
### Fixed
|
||||||
- Fixed crash on client when loading player head skin (fixes [#63](https://github.com/Suiranoil/SkinRestorer/issues/63) and [#64](https://github.com/Suiranoil/SkinRestorer/issues/64))
|
- Fixed crash on client when loading player head skin (fixes [#63](https://github.com/Suiranoil/SkinRestorer/issues/63) and [#64](https://github.com/Suiranoil/SkinRestorer/issues/64))
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
### Fixed
|
### Added
|
||||||
- Fixed crash on client when loading player head skin (fixes [#63](https://github.com/Suiranoil/SkinRestorer/issues/63) and [#64](https://github.com/Suiranoil/SkinRestorer/issues/64))
|
- Added collection skin provider (allows assigning random skins from a predefined set) (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Configuration#providerscollection))
|
||||||
- Fixed server freeze when loading player head skin
|
- Added `forceFirstJoinSkinFetch` config option to force skin fetch on first join even if player already has a skin (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Configuration#forcefirstjoinskinfetch))
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ public final class SkinRestorer {
|
|||||||
SkinRestorer.registerDefaultSkinProvider(MojangSkinProvider.PROVIDER_NAME, SkinProvider.MOJANG, SkinRestorer.getConfig().providersConfig().mojang());
|
SkinRestorer.registerDefaultSkinProvider(MojangSkinProvider.PROVIDER_NAME, SkinProvider.MOJANG, SkinRestorer.getConfig().providersConfig().mojang());
|
||||||
SkinRestorer.registerDefaultSkinProvider(ElyBySkinProvider.PROVIDER_NAME, SkinProvider.ELY_BY, SkinRestorer.getConfig().providersConfig().ely_by());
|
SkinRestorer.registerDefaultSkinProvider(ElyBySkinProvider.PROVIDER_NAME, SkinProvider.ELY_BY, SkinRestorer.getConfig().providersConfig().ely_by());
|
||||||
SkinRestorer.registerDefaultSkinProvider(MineskinSkinProvider.PROVIDER_NAME, SkinProvider.MINESKIN, SkinRestorer.getConfig().providersConfig().mineskin());
|
SkinRestorer.registerDefaultSkinProvider(MineskinSkinProvider.PROVIDER_NAME, SkinProvider.MINESKIN, SkinRestorer.getConfig().providersConfig().mineskin());
|
||||||
|
SkinRestorer.registerDefaultSkinProvider(CollectionSkinProvider.PROVIDER_NAME, SkinProvider.COLLECTION, SkinRestorer.getConfig().providersConfig().collection());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerDefaultSkinProvider(String defaultName, SkinProvider provider, BuiltInProviderConfig config) {
|
private static void registerDefaultSkinProvider(String defaultName, SkinProvider provider, BuiltInProviderConfig config) {
|
||||||
@@ -106,6 +107,7 @@ public final class SkinRestorer {
|
|||||||
MojangSkinProvider.reload();
|
MojangSkinProvider.reload();
|
||||||
ElyBySkinProvider.reload();
|
ElyBySkinProvider.reload();
|
||||||
MineskinSkinProvider.reload();
|
MineskinSkinProvider.reload();
|
||||||
|
CollectionSkinProvider.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<ServerPlayer> targets, SkinValue value, boolean save) {
|
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<ServerPlayer> targets, SkinValue value, boolean save) {
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ public final class Config implements GsonPostProcessable {
|
|||||||
|
|
||||||
private boolean fetchSkinOnFirstJoin = true;
|
private boolean fetchSkinOnFirstJoin = true;
|
||||||
|
|
||||||
|
private boolean forceFirstJoinSkinFetch = false;
|
||||||
|
|
||||||
private FirstJoinSkinProvider firstJoinSkinProvider = FirstJoinSkinProvider.MOJANG;
|
private FirstJoinSkinProvider firstJoinSkinProvider = FirstJoinSkinProvider.MOJANG;
|
||||||
|
|
||||||
private String proxy = "";
|
private String proxy = "";
|
||||||
@@ -47,6 +49,10 @@ public final class Config implements GsonPostProcessable {
|
|||||||
return this.fetchSkinOnFirstJoin;
|
return this.fetchSkinOnFirstJoin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean forceFirstJoinSkinFetch() {
|
||||||
|
return this.forceFirstJoinSkinFetch;
|
||||||
|
}
|
||||||
|
|
||||||
public FirstJoinSkinProvider firstJoinSkinProvider() {
|
public FirstJoinSkinProvider firstJoinSkinProvider() {
|
||||||
return this.firstJoinSkinProvider;
|
return this.firstJoinSkinProvider;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.lionarius.skinrestorer.config;
|
package net.lionarius.skinrestorer.config;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.CollectionSkinProvider;
|
||||||
import net.lionarius.skinrestorer.skin.provider.ElyBySkinProvider;
|
import net.lionarius.skinrestorer.skin.provider.ElyBySkinProvider;
|
||||||
import net.lionarius.skinrestorer.skin.provider.MojangSkinProvider;
|
import net.lionarius.skinrestorer.skin.provider.MojangSkinProvider;
|
||||||
|
|
||||||
@@ -8,7 +9,9 @@ public enum FirstJoinSkinProvider {
|
|||||||
@SerializedName(value = "MOJANG", alternate = {"mojang"})
|
@SerializedName(value = "MOJANG", alternate = {"mojang"})
|
||||||
MOJANG(MojangSkinProvider.PROVIDER_NAME),
|
MOJANG(MojangSkinProvider.PROVIDER_NAME),
|
||||||
@SerializedName(value = "ELY.BY", alternate = {"ely.by", "ELY_BY", "ely_by"})
|
@SerializedName(value = "ELY.BY", alternate = {"ely.by", "ELY_BY", "ely_by"})
|
||||||
ELY_BY(ElyBySkinProvider.PROVIDER_NAME);
|
ELY_BY(ElyBySkinProvider.PROVIDER_NAME),
|
||||||
|
@SerializedName(value = "COLLECTION", alternate = {"collection"})
|
||||||
|
COLLECTION(CollectionSkinProvider.PROVIDER_NAME);
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,13 @@ public abstract class BuiltInProviderConfig implements GsonPostProcessable {
|
|||||||
protected String name;
|
protected String name;
|
||||||
protected CacheConfig cache;
|
protected CacheConfig cache;
|
||||||
|
|
||||||
|
|
||||||
public BuiltInProviderConfig(String name, CacheConfig cache) {
|
public BuiltInProviderConfig(String name, CacheConfig cache) {
|
||||||
this.enabled = true;
|
this(name, cache, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BuiltInProviderConfig(String name, CacheConfig cache, boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,27 @@
|
|||||||
package net.lionarius.skinrestorer.config.provider;
|
package net.lionarius.skinrestorer.config.provider;
|
||||||
|
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.config.provider.collection.CollectionProviderConfig;
|
||||||
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||||
|
|
||||||
public final class ProvidersConfig implements GsonPostProcessable {
|
public final class ProvidersConfig implements GsonPostProcessable {
|
||||||
public static final ProvidersConfig DEFAULT = new ProvidersConfig(
|
public static final ProvidersConfig DEFAULT = new ProvidersConfig(
|
||||||
new MojangProviderConfig(),
|
new MojangProviderConfig(),
|
||||||
new ElyByProviderConfig(),
|
new ElyByProviderConfig(),
|
||||||
new MineskinProviderConfig()
|
new MineskinProviderConfig(),
|
||||||
|
new CollectionProviderConfig()
|
||||||
);
|
);
|
||||||
|
|
||||||
private MojangProviderConfig mojang;
|
private MojangProviderConfig mojang;
|
||||||
private ElyByProviderConfig ely_by;
|
private ElyByProviderConfig ely_by;
|
||||||
private MineskinProviderConfig mineskin;
|
private MineskinProviderConfig mineskin;
|
||||||
|
private CollectionProviderConfig collection;
|
||||||
|
|
||||||
public ProvidersConfig(MojangProviderConfig mojang, ElyByProviderConfig ely_by, MineskinProviderConfig mineskin) {
|
public ProvidersConfig(MojangProviderConfig mojang, ElyByProviderConfig ely_by, MineskinProviderConfig mineskin, CollectionProviderConfig collection) {
|
||||||
this.mojang = mojang;
|
this.mojang = mojang;
|
||||||
this.ely_by = ely_by;
|
this.ely_by = ely_by;
|
||||||
this.mineskin = mineskin;
|
this.mineskin = mineskin;
|
||||||
|
this.collection = collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MojangProviderConfig mojang() {
|
public MojangProviderConfig mojang() {
|
||||||
@@ -32,6 +36,10 @@ public final class ProvidersConfig implements GsonPostProcessable {
|
|||||||
return this.mineskin;
|
return this.mineskin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CollectionProviderConfig collection() {
|
||||||
|
return this.collection;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void gsonPostProcess() {
|
public void gsonPostProcess() {
|
||||||
if (this.mojang == null) {
|
if (this.mojang == null) {
|
||||||
@@ -48,5 +56,10 @@ public final class ProvidersConfig implements GsonPostProcessable {
|
|||||||
SkinRestorer.LOGGER.warn("Mineskin provider config is null, using default");
|
SkinRestorer.LOGGER.warn("Mineskin provider config is null, using default");
|
||||||
this.mineskin = ProvidersConfig.DEFAULT.mineskin();
|
this.mineskin = ProvidersConfig.DEFAULT.mineskin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.collection == null) {
|
||||||
|
SkinRestorer.LOGGER.warn("Collection provider config is null, using default");
|
||||||
|
this.collection = ProvidersConfig.DEFAULT.collection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider.collection;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.JsonAdapter;
|
||||||
|
import net.lionarius.skinrestorer.config.provider.BuiltInProviderConfig;
|
||||||
|
import net.lionarius.skinrestorer.config.provider.CacheConfig;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.CollectionSkinProvider;
|
||||||
|
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public final class CollectionProviderConfig extends BuiltInProviderConfig implements GsonPostProcessable {
|
||||||
|
private static final CacheConfig DEFAULT_CACHE_VALUE = new CacheConfig(true, 604800);
|
||||||
|
|
||||||
|
@JsonAdapter(CollectionSkinSourceListDeserializer.class)
|
||||||
|
private List<CollectionSkinSource> sources = new ArrayList<>();
|
||||||
|
|
||||||
|
public CollectionProviderConfig() {
|
||||||
|
super(CollectionSkinProvider.PROVIDER_NAME, DEFAULT_CACHE_VALUE, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CollectionSkinSource> sources() {
|
||||||
|
return this.sources;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void gsonPostProcess() {
|
||||||
|
if (this.sources == null) {
|
||||||
|
this.sources = new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider.collection;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
|
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public final class CollectionSkinFile implements CollectionSkinSource, GsonPostProcessable {
|
||||||
|
private String path = "";
|
||||||
|
private SkinVariant variant = SkinVariant.CLASSIC;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable URI uri() {
|
||||||
|
if (this.path.isEmpty())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
var filePath = SkinRestorer.getConfigDir().resolve(this.path);
|
||||||
|
|
||||||
|
if (!Files.exists(filePath)) {
|
||||||
|
SkinRestorer.LOGGER.warn("Skin file does not exist: {}", this.path);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Files.isRegularFile(filePath)) {
|
||||||
|
SkinRestorer.LOGGER.warn("Skin path is not a file: {}", this.path);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.path.toLowerCase().endsWith(".png")) {
|
||||||
|
SkinRestorer.LOGGER.warn("Skin file is not a PNG file: {}", this.path);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return filePath.toUri();
|
||||||
|
} catch (Exception e) {
|
||||||
|
SkinRestorer.LOGGER.warn("Invalid file path: {}", this.path, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SkinVariant variant() {
|
||||||
|
return this.variant;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void gsonPostProcess() {
|
||||||
|
if (this.path == null) {
|
||||||
|
this.path = "";
|
||||||
|
}
|
||||||
|
if (this.variant == null) {
|
||||||
|
this.variant = SkinVariant.CLASSIC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider.collection;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
public interface CollectionSkinSource {
|
||||||
|
@Nullable URI uri();
|
||||||
|
|
||||||
|
SkinVariant variant();
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider.collection;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CollectionSkinSourceListDeserializer implements JsonSerializer<List<CollectionSkinSource>>, JsonDeserializer<List<CollectionSkinSource>> {
|
||||||
|
@Override
|
||||||
|
public JsonElement serialize(List<CollectionSkinSource> src, Type typeOfT, JsonSerializationContext context) {
|
||||||
|
return context.serialize(src, List.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CollectionSkinSource> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||||
|
throws JsonParseException {
|
||||||
|
List<CollectionSkinSource> sources = new ArrayList<>();
|
||||||
|
|
||||||
|
if (json.isJsonArray()) {
|
||||||
|
for (JsonElement element : json.getAsJsonArray()) {
|
||||||
|
if (element.isJsonObject()) {
|
||||||
|
JsonObject obj = element.getAsJsonObject();
|
||||||
|
if (obj.has("url")) {
|
||||||
|
sources.add(context.deserialize(obj, CollectionSkinUrl.class));
|
||||||
|
} else if (obj.has("path")) {
|
||||||
|
sources.add(context.deserialize(obj, CollectionSkinFile.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sources;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider.collection;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
|
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
public final class CollectionSkinUrl implements CollectionSkinSource, GsonPostProcessable {
|
||||||
|
private String url = "";
|
||||||
|
private SkinVariant variant = SkinVariant.CLASSIC;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable URI uri() {
|
||||||
|
try {
|
||||||
|
if (this.url.isEmpty())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new URI(this.url);
|
||||||
|
} catch (Exception e) {
|
||||||
|
SkinRestorer.LOGGER.warn("Invalid URI: {}", this.url, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SkinVariant variant() {
|
||||||
|
return this.variant;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void gsonPostProcess() {
|
||||||
|
if (this.url == null) {
|
||||||
|
this.url = "";
|
||||||
|
}
|
||||||
|
if (this.variant == null) {
|
||||||
|
this.variant = SkinVariant.CLASSIC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package net.lionarius.skinrestorer.mixin;
|
|||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.config.FirstJoinSkinProvider;
|
||||||
import net.lionarius.skinrestorer.skin.SkinValue;
|
import net.lionarius.skinrestorer.skin.SkinValue;
|
||||||
import net.lionarius.skinrestorer.skin.provider.SkinProviderContext;
|
import net.lionarius.skinrestorer.skin.provider.SkinProviderContext;
|
||||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||||
@@ -53,9 +54,15 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (originalSkin == null && SkinRestorer.getConfig().fetchSkinOnFirstJoin()) {
|
var config = SkinRestorer.getConfig();
|
||||||
|
var provider = config.firstJoinSkinProvider();
|
||||||
|
|
||||||
|
var shouldFetch = (originalSkin == null && config.fetchSkinOnFirstJoin()) ||
|
||||||
|
(originalSkin != null && config.forceFirstJoinSkinFetch() && provider != FirstJoinSkinProvider.MOJANG);
|
||||||
|
|
||||||
|
if (shouldFetch) {
|
||||||
var context = new SkinProviderContext(
|
var context = new SkinProviderContext(
|
||||||
SkinRestorer.getConfig().firstJoinSkinProvider().getName(),
|
provider.getName(),
|
||||||
profile.name(),
|
profile.name(),
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package net.lionarius.skinrestorer.skin;
|
package net.lionarius.skinrestorer.skin;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
public enum SkinVariant {
|
public enum SkinVariant {
|
||||||
|
@SerializedName(value = "classic", alternate = {"CLASSIC"})
|
||||||
CLASSIC("classic"),
|
CLASSIC("classic"),
|
||||||
|
@SerializedName(value = "slim", alternate = {"SLIM"})
|
||||||
SLIM("slim");
|
SLIM("slim");
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package net.lionarius.skinrestorer.skin.provider;
|
||||||
|
|
||||||
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
import com.google.common.cache.CacheLoader;
|
||||||
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import it.unimi.dsi.fastutil.Pair;
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.config.provider.collection.CollectionSkinSource;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
|
import net.lionarius.skinrestorer.util.Result;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public final class CollectionSkinProvider implements SkinProvider {
|
||||||
|
|
||||||
|
public static final String PROVIDER_NAME = "collection";
|
||||||
|
|
||||||
|
private static LoadingCache<Integer, Optional<Property>> SKIN_CACHE;
|
||||||
|
|
||||||
|
private static List<Pair<URI, SkinVariant>> COLLECTION_SKINS;
|
||||||
|
|
||||||
|
public static void reload() {
|
||||||
|
COLLECTION_SKINS = loadCollectionSkins();
|
||||||
|
|
||||||
|
createCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<Pair<URI, SkinVariant>> loadCollectionSkins() {
|
||||||
|
List<Pair<URI, SkinVariant>> skins = new ArrayList<>();
|
||||||
|
|
||||||
|
var config = SkinRestorer.getConfig().providersConfig().collection();
|
||||||
|
|
||||||
|
for (CollectionSkinSource source : config.sources()) {
|
||||||
|
var uri = source.uri();
|
||||||
|
if (uri != null) {
|
||||||
|
skins.add(Pair.of(uri, source.variant()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return skins;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void createCache() {
|
||||||
|
var config = SkinRestorer.getConfig().providersConfig().collection();
|
||||||
|
var time = config.cache().enabled() ? config.cache().duration() : 0;
|
||||||
|
|
||||||
|
SKIN_CACHE = CacheBuilder.newBuilder()
|
||||||
|
.expireAfterWrite(time, TimeUnit.SECONDS)
|
||||||
|
.build(new CacheLoader<>() {
|
||||||
|
@Override
|
||||||
|
public @NotNull Optional<Property> load(@NotNull Integer key) throws Exception {
|
||||||
|
var skinEntry = COLLECTION_SKINS.get(key);
|
||||||
|
return MineskinSkinProvider.loadSkin(skinEntry.first(), skinEntry.second());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getArgumentName() {
|
||||||
|
return "seed";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasVariantSupport() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<Optional<Property>, Exception> fetchSkin(String argument, SkinVariant variant) {
|
||||||
|
if (COLLECTION_SKINS.isEmpty()) {
|
||||||
|
return Result.error(new IllegalStateException("No collection skins configured"));
|
||||||
|
}
|
||||||
|
|
||||||
|
var skinIndex = Math.abs(argument.hashCode()) % COLLECTION_SKINS.size();
|
||||||
|
|
||||||
|
try {
|
||||||
|
return Result.success(SKIN_CACHE.get(skinIndex));
|
||||||
|
} catch (UncheckedExecutionException e) {
|
||||||
|
return Result.error((Exception) e.getCause());
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,8 @@ import org.mineskin.response.QueueResponse;
|
|||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -94,13 +96,18 @@ public final class MineskinSkinProvider implements SkinProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Optional<Property> loadSkin(URI uri, SkinVariant variant) throws Exception {
|
static Optional<Property> loadSkin(URI uri, SkinVariant variant) throws Exception {
|
||||||
var mineskinVariant = switch (variant) {
|
var mineskinVariant = switch (variant) {
|
||||||
case CLASSIC -> Variant.CLASSIC;
|
case CLASSIC -> Variant.CLASSIC;
|
||||||
case SLIM -> Variant.SLIM;
|
case SLIM -> Variant.SLIM;
|
||||||
};
|
};
|
||||||
|
|
||||||
var request = GenerateRequest.url(uri)
|
var request = "file".equals(uri.getScheme())
|
||||||
|
? GenerateRequest.upload(Files.newInputStream(Path.of(uri)))
|
||||||
|
.variant(mineskinVariant)
|
||||||
|
.name("skinrestorer-skin")
|
||||||
|
.visibility(Visibility.UNLISTED)
|
||||||
|
: GenerateRequest.url(uri)
|
||||||
.variant(mineskinVariant)
|
.variant(mineskinVariant)
|
||||||
.name("skinrestorer-skin")
|
.name("skinrestorer-skin")
|
||||||
.visibility(Visibility.UNLISTED);
|
.visibility(Visibility.UNLISTED);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ public interface SkinProvider {
|
|||||||
MojangSkinProvider MOJANG = new MojangSkinProvider();
|
MojangSkinProvider MOJANG = new MojangSkinProvider();
|
||||||
ElyBySkinProvider ELY_BY = new ElyBySkinProvider();
|
ElyBySkinProvider ELY_BY = new ElyBySkinProvider();
|
||||||
MineskinSkinProvider MINESKIN = new MineskinSkinProvider();
|
MineskinSkinProvider MINESKIN = new MineskinSkinProvider();
|
||||||
|
CollectionSkinProvider COLLECTION = new CollectionSkinProvider();
|
||||||
SkinShuffleSkinProvider SKIN_SHUFFLE = new SkinShuffleSkinProvider();
|
SkinShuffleSkinProvider SKIN_SHUFFLE = new SkinShuffleSkinProvider();
|
||||||
|
|
||||||
Set<String> BUILTIN_PROVIDER_NAMES = ImmutableSet.of(
|
Set<String> BUILTIN_PROVIDER_NAMES = ImmutableSet.of(
|
||||||
@@ -20,6 +21,7 @@ public interface SkinProvider {
|
|||||||
MojangSkinProvider.PROVIDER_NAME,
|
MojangSkinProvider.PROVIDER_NAME,
|
||||||
ElyBySkinProvider.PROVIDER_NAME,
|
ElyBySkinProvider.PROVIDER_NAME,
|
||||||
MineskinSkinProvider.PROVIDER_NAME,
|
MineskinSkinProvider.PROVIDER_NAME,
|
||||||
|
CollectionSkinProvider.PROVIDER_NAME,
|
||||||
SkinShuffleSkinProvider.PROVIDER_NAME
|
SkinShuffleSkinProvider.PROVIDER_NAME
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,10 @@
|
|||||||
"refmap": "${mod_id}.refmap.json",
|
"refmap": "${mod_id}.refmap.json",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"ChunkMapAccessor",
|
"ChunkMapAccessor",
|
||||||
|
"PlayerAccessor",
|
||||||
"PlayerListMixin",
|
"PlayerListMixin",
|
||||||
"ServerLoginPacketListenerImplMixin",
|
"ServerLoginPacketListenerImplMixin",
|
||||||
"TrackedEntityAccessorInvoker",
|
"TrackedEntityAccessorInvoker"
|
||||||
"PlayerAccessor"
|
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ java_version=21
|
|||||||
|
|
||||||
# Common
|
# Common
|
||||||
minecraft_version=1.21.9
|
minecraft_version=1.21.9
|
||||||
minecraft_version_list=1.21.9
|
minecraft_version_list=1.21.9,1.21.10
|
||||||
minecraft_version_range=[1.21.9, 1.22)
|
minecraft_version_range=[1.21.9, 1.21.10]
|
||||||
mod_id=skinrestorer
|
mod_id=skinrestorer
|
||||||
mod_name=SkinRestorer
|
mod_name=SkinRestorer
|
||||||
mod_version=2.4.3
|
mod_version=2.5.0
|
||||||
mod_author=Lionarius
|
mod_author=Lionarius
|
||||||
mod_homepage=https://modrinth.com/mod/skinrestorer
|
mod_homepage=https://modrinth.com/mod/skinrestorer
|
||||||
mod_sources=https://github.com/Suiranoil/SkinRestorer
|
mod_sources=https://github.com/Suiranoil/SkinRestorer
|
||||||
@@ -18,11 +18,11 @@ credits=
|
|||||||
description=A server-side mod for managing skins.
|
description=A server-side mod for managing skins.
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
mineskin_client_version=3.0.6-SNAPSHOT
|
mineskin_client_version=3.2.1-SNAPSHOT
|
||||||
|
|
||||||
# ParchmentMC mappings, see https://parchmentmc.org/docs/getting-started#choose-a-version for new versions
|
# ParchmentMC mappings, see https://parchmentmc.org/docs/getting-started#choose-a-version for new versions
|
||||||
parchment_minecraft=1.21.8
|
parchment_minecraft=1.21.9
|
||||||
parchment_version=2025.09.14
|
parchment_version=2025.10.05
|
||||||
|
|
||||||
# Publishing
|
# Publishing
|
||||||
curseforge_id=443823
|
curseforge_id=443823
|
||||||
|
|||||||
Reference in New Issue
Block a user