mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
Merge branch '1.20.3-multiloader' into 1.20.2-multiloader
This commit is contained in:
@@ -4,6 +4,10 @@ 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/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [2.4.0] - 2025-07-05
|
||||
### Fixed
|
||||
- Added support for player heads
|
||||
|
||||
## [2.3.5] - 2025-06-21
|
||||
### Fixed
|
||||
- Fix mod not loading on client
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
### Fixed
|
||||
- Fix mod not loading on client
|
||||
### Added
|
||||
- Added support for player heads
|
||||
|
||||
@@ -5,20 +5,20 @@ import net.lionarius.skinrestorer.SkinRestorer;
|
||||
public final class CacheConfig {
|
||||
private boolean enabled;
|
||||
private long duration;
|
||||
|
||||
|
||||
public CacheConfig(boolean enabled, long duration) {
|
||||
this.enabled = enabled;
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
|
||||
public boolean enabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
|
||||
public long duration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
|
||||
void validate(CacheConfig defaultValue) {
|
||||
if (this.duration <= 0) {
|
||||
SkinRestorer.LOGGER.warn("Cache duration is less than or equal to zero, defaulting to {}", defaultValue.duration());
|
||||
|
||||
@@ -9,41 +9,41 @@ public final class ProvidersConfig implements GsonPostProcessable {
|
||||
new ElyByProviderConfig(),
|
||||
new MineskinProviderConfig()
|
||||
);
|
||||
|
||||
|
||||
private MojangProviderConfig mojang;
|
||||
private ElyByProviderConfig ely_by;
|
||||
private MineskinProviderConfig mineskin;
|
||||
|
||||
|
||||
public ProvidersConfig(MojangProviderConfig mojang, ElyByProviderConfig ely_by, MineskinProviderConfig mineskin) {
|
||||
this.mojang = mojang;
|
||||
this.ely_by = ely_by;
|
||||
this.mineskin = mineskin;
|
||||
}
|
||||
|
||||
|
||||
public MojangProviderConfig mojang() {
|
||||
return this.mojang;
|
||||
}
|
||||
|
||||
|
||||
public ElyByProviderConfig ely_by() {
|
||||
return this.ely_by;
|
||||
}
|
||||
|
||||
|
||||
public MineskinProviderConfig mineskin() {
|
||||
return this.mineskin;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void gsonPostProcess() {
|
||||
if (this.mojang == null) {
|
||||
SkinRestorer.LOGGER.warn("Mojang provider config is null, using default");
|
||||
this.mojang = ProvidersConfig.DEFAULT.mojang();
|
||||
}
|
||||
|
||||
|
||||
if (this.ely_by == null) {
|
||||
SkinRestorer.LOGGER.warn("Ely.By provider config is null, using default");
|
||||
this.ely_by = ProvidersConfig.DEFAULT.ely_by();
|
||||
}
|
||||
|
||||
|
||||
if (this.mineskin == null) {
|
||||
SkinRestorer.LOGGER.warn("Mineskin provider config is null, using default");
|
||||
this.mineskin = ProvidersConfig.DEFAULT.mineskin();
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package net.lionarius.skinrestorer.mixin;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||
import net.minecraft.server.Services;
|
||||
import net.minecraft.world.level.block.entity.SkullBlockEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
@Mixin(SkullBlockEntity.class)
|
||||
public abstract class SkullBlockEntityMixin {
|
||||
|
||||
@Inject(method = "loadProfile", at = @At("HEAD"),
|
||||
cancellable = true)
|
||||
private static void fetchProfileByName(String name, Services services, BooleanSupplier hasCache, CallbackInfoReturnable<CompletableFuture<Optional<GameProfile>>> cir) {
|
||||
var profileOpt = services.profileCache().get(name);
|
||||
|
||||
skinrestorer$replaceSkin(profileOpt, cir);
|
||||
}
|
||||
|
||||
@Unique
|
||||
private static void skinrestorer$replaceSkin(Optional<GameProfile> profileOpt, CallbackInfoReturnable<CompletableFuture<Optional<GameProfile>>> cir) {
|
||||
if (profileOpt.isEmpty())
|
||||
return;
|
||||
|
||||
var profile = PlayerUtils.cloneGameProfile(profileOpt.get());
|
||||
|
||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId())) {
|
||||
cir.setReturnValue(CompletableFuture.supplyAsync(() -> {
|
||||
var skin = SkinRestorer.getSkinStorage().getSkin(profile.getId(), false);
|
||||
PlayerUtils.applyRestoredSkin(profile, skin.value());
|
||||
|
||||
return Optional.of(profile);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,11 @@ import java.util.ServiceLoader;
|
||||
|
||||
public final class Services {
|
||||
|
||||
private Services() {}
|
||||
|
||||
public final static PlatformHelper PLATFORM = load(PlatformHelper.class);
|
||||
public final static CompatibilityHelper COMPATIBILITY = load(CompatibilityHelper.class);
|
||||
|
||||
private Services() {}
|
||||
|
||||
private static <T> T load(Class<T> clazz) {
|
||||
final T loadedService = ServiceLoader.load(clazz)
|
||||
.findFirst()
|
||||
|
||||
@@ -17,15 +17,22 @@ public class SkinStorage {
|
||||
return this.skinMap.containsKey(uuid) || this.skinIO.skinExists(uuid);
|
||||
}
|
||||
|
||||
public SkinValue getSkin(UUID uuid) {
|
||||
public SkinValue getSkin(UUID uuid, boolean cache) {
|
||||
if (!skinMap.containsKey(uuid)) {
|
||||
var skin = skinIO.loadSkin(uuid);
|
||||
if (!cache)
|
||||
return skin;
|
||||
|
||||
setSkin(uuid, skin);
|
||||
}
|
||||
|
||||
return skinMap.get(uuid);
|
||||
}
|
||||
|
||||
public SkinValue getSkin(UUID uuid) {
|
||||
return this.getSkin(uuid, true);
|
||||
}
|
||||
|
||||
public void removeSkin(UUID uuid, boolean save) {
|
||||
var skin = skinMap.remove(uuid);
|
||||
if (skin != null && save)
|
||||
|
||||
@@ -91,6 +91,13 @@ public final class PlayerUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static GameProfile cloneGameProfile(GameProfile profile) {
|
||||
var newProfile = new GameProfile(profile.getId(), profile.getName());
|
||||
newProfile.getProperties().putAll(profile.getProperties());
|
||||
|
||||
return newProfile;
|
||||
}
|
||||
|
||||
public static Property getPlayerSkin(GameProfile profile) {
|
||||
return Iterables.getFirst(profile.getProperties().get(TEXTURES_KEY), null);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,18 @@ public class Result<S, E> {
|
||||
this.errorValue = errorValue;
|
||||
}
|
||||
|
||||
public static <S, E> Result<S, E> success(@NotNull S successValue) {
|
||||
return new Result<>(successValue, null);
|
||||
}
|
||||
|
||||
public static <S, E> Result<S, E> error(@NotNull E errorValue) {
|
||||
return new Result<>(null, errorValue);
|
||||
}
|
||||
|
||||
public static <S, E> Result<Optional<S>, E> ofNullable(S successValue) {
|
||||
return Result.success(Optional.ofNullable(successValue));
|
||||
}
|
||||
|
||||
public S getSuccessValue() {
|
||||
return successValue;
|
||||
}
|
||||
@@ -69,16 +81,4 @@ public class Result<S, E> {
|
||||
public int hashCode() {
|
||||
return Objects.hash(successValue, errorValue);
|
||||
}
|
||||
|
||||
public static <S, E> Result<S, E> success(@NotNull S successValue) {
|
||||
return new Result<>(successValue, null);
|
||||
}
|
||||
|
||||
public static <S, E> Result<S, E> error(@NotNull E errorValue) {
|
||||
return new Result<>(null, errorValue);
|
||||
}
|
||||
|
||||
public static <S, E> Result<Optional<S>, E> ofNullable(S successValue) {
|
||||
return Result.success(Optional.ofNullable(successValue));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,6 @@ import java.time.temporal.ChronoUnit;
|
||||
|
||||
public final class WebUtils {
|
||||
|
||||
private WebUtils() {}
|
||||
|
||||
public static final String USER_AGENT;
|
||||
|
||||
private static HttpClient HTTP_CLIENT = null;
|
||||
@@ -23,6 +21,8 @@ public final class WebUtils {
|
||||
USER_AGENT = String.format("SkinRestorer/%d", System.currentTimeMillis() % 65535);
|
||||
}
|
||||
|
||||
private WebUtils() {}
|
||||
|
||||
public static void recreateHttpClient() {
|
||||
HTTP_CLIENT = WebUtils.buildClient();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
"ChunkMapAccessor",
|
||||
"PlayerListMixin",
|
||||
"ServerLoginPacketListenerImplMixin",
|
||||
"TrackedEntityAccessorInvoker"
|
||||
"TrackedEntityAccessorInvoker",
|
||||
"SkullBlockEntityMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
@@ -10,8 +10,6 @@ import net.minecraftforge.network.ChannelBuilder;
|
||||
import net.minecraftforge.network.EventNetworkChannel;
|
||||
|
||||
public class SkinShufflePacketHandler {
|
||||
private SkinShufflePacketHandler() {
|
||||
}
|
||||
|
||||
private static final EventNetworkChannel HANDSHAKE_INSTANCE = ChannelBuilder
|
||||
.named(SkinShuffleHandshakePayload.PACKET_ID)
|
||||
@@ -33,6 +31,9 @@ public class SkinShufflePacketHandler {
|
||||
protected static void initialize() {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
private SkinShufflePacketHandler() {
|
||||
}
|
||||
|
||||
public static void sendHandshake(Connection connection) {
|
||||
HANDSHAKE_INSTANCE.send(new FriendlyByteBuf(Unpooled.buffer(0, 0)), connection);
|
||||
|
||||
@@ -8,7 +8,7 @@ minecraft_version_list=1.20.2
|
||||
minecraft_version_range=1.20.2
|
||||
mod_id=skinrestorer
|
||||
mod_name=SkinRestorer
|
||||
mod_version=2.3.5
|
||||
mod_version=2.4.0
|
||||
mod_author=Lionarius
|
||||
mod_homepage=https://modrinth.com/mod/skinrestorer
|
||||
mod_sources=https://github.com/Suiranoil/SkinRestorer
|
||||
|
||||
Reference in New Issue
Block a user