1
0
mirror of https://github.com/Suiranoil/SkinRestorer.git synced 2026-01-16 04:42:12 +00:00

Merge branch '1.20.2-multiloader' into 1.20-multiloader

# Conflicts:
#	forge/src/main/java/net/lionarius/skinrestorer/forge/compat/skinshuffle/SkinShufflePacketHandler.java
This commit is contained in:
2025-07-05 20:10:51 +03:00
13 changed files with 110 additions and 36 deletions

View File

@@ -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

View File

@@ -1,2 +1,2 @@
### Fixed
- Fix mod not loading on client
### Added
- Added support for player heads

View File

@@ -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());

View File

@@ -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();

View File

@@ -0,0 +1,54 @@
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.server.players.GameProfileCache;
import net.minecraft.world.level.block.entity.SkullBlockEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
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 {
@Shadow
private static GameProfileCache profileCache;
@Inject(method = "fetchGameProfile", at = @At("HEAD"),
cancellable = true)
private static void fetchProfileByName(String name, CallbackInfoReturnable<CompletableFuture<Optional<GameProfile>>> cir) {
if (profileCache == null)
return;
var profileOpt = 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);
}));
}
}
}

View File

@@ -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()

View File

@@ -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)

View File

@@ -105,6 +105,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);
}

View File

@@ -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));
}
}

View File

@@ -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();
}

View File

@@ -9,7 +9,8 @@
"ChunkMapAccessor",
"PlayerListMixin",
"ServerLoginPacketListenerImplMixin",
"TrackedEntityAccessorInvoker"
"TrackedEntityAccessorInvoker",
"SkullBlockEntityMixin"
],
"injectors": {
"defaultRequire": 1

View File

@@ -11,9 +11,7 @@ import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.event.EventNetworkChannel;
public class SkinShufflePacketHandler {
private SkinShufflePacketHandler() {
}
private static final EventNetworkChannel HANDSHAKE_INSTANCE = NetworkRegistry.ChannelBuilder
.named(SkinShuffleHandshakePayload.PACKET_ID)
.clientAcceptedVersions(NetworkRegistry.acceptMissingOr(""))
@@ -40,6 +38,9 @@ public class SkinShufflePacketHandler {
SKIN_REFRESH_V2_INSTANCE.addListener(SkinShufflePacketHandler::skinRefreshV2Listener);
}
private SkinShufflePacketHandler() {
}
public static void sendHandshake(Connection connection) {
connection.send(new ClientboundCustomPayloadPacket(SkinShuffleHandshakePayload.PACKET_ID, new FriendlyByteBuf(Unpooled.buffer(0, 0))));
}

View File

@@ -8,7 +8,7 @@ minecraft_version_list=1.20,1.20.1
minecraft_version_range=[1.20, 1.20.1]
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