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

Compare commits

...

30 Commits

Author SHA1 Message Date
acd1f888c0 Merge branch '1.20.3-multiloader' into 1.20.2-multiloader
# Conflicts:
#	common/src/main/java/net/lionarius/skinrestorer/mixin/SkullBlockEntityMixin.java
2025-07-13 20:40:54 +03:00
c192cdce7e Merge branch '1.20.5-multiloader' into 1.20.3-multiloader
# Conflicts:
#	common/src/main/java/net/lionarius/skinrestorer/mixin/SkullBlockEntityMixin.java
2025-07-13 20:39:34 +03:00
d54cb48697 Merge branch '1.21-multiloader' into 1.20.5-multiloader 2025-07-13 20:37:43 +03:00
6df0cf4fd2 Merge branch '1.21.5-multiloader' into 1.21-multiloader 2025-07-13 20:36:09 +03:00
2cec50afae Merge branch '1.21.6-multiloader' into 1.21.5-multiloader
# Conflicts:
#	gradle.properties
2025-07-13 20:35:24 +03:00
01a045541c update CHANGELOG 2025-07-13 20:30:43 +03:00
5bab96e269 bump version 2025-07-13 20:30:28 +03:00
a0b557be51 add 1.21.7 to mc version list 2025-07-13 20:21:36 +03:00
7fad7de710 check name and id for null
fixes #60 and #61
2025-07-13 20:20:14 +03:00
cfd6dcd181 Merge branch '1.20.3-multiloader' into 1.20.2-multiloader 2025-07-09 21:43:52 +03:00
06e5a2f5b7 Merge branch '1.20.5-multiloader' into 1.20.3-multiloader 2025-07-09 21:43:07 +03:00
05ef681621 Merge branch '1.21-multiloader' into 1.20.5-multiloader 2025-07-09 21:42:39 +03:00
daf0310072 Merge branch '1.21.5-multiloader' into 1.21-multiloader
# Conflicts:
#	common/src/main/java/net/lionarius/skinrestorer/skin/provider/MojangSkinProvider.java
2025-07-09 21:38:52 +03:00
a3bd44af89 Merge branch '1.21.6-multiloader' into 1.21.5-multiloader 2025-07-09 21:38:04 +03:00
8af1dd8f12 update CHANGELOG 2025-07-09 21:37:18 +03:00
1c7f97551d bump version 2025-07-09 21:37:18 +03:00
a8cc81e570 better exception logging 2025-07-09 21:37:18 +03:00
6ce3484824 rethrow io exception 2025-07-07 01:02:12 +03:00
b518305028 add exception logging 2025-07-07 00:56:32 +03:00
b38a296efa port to 1.20.2 2025-07-05 20:08:47 +03:00
d54e30749f Merge branch '1.20.3-multiloader' into 1.20.2-multiloader 2025-07-05 20:03:20 +03:00
e5134cdd71 port to 1.20.3 2025-07-05 19:58:53 +03:00
220f9c6ac3 Merge branch '1.20.5-multiloader' into 1.20.3-multiloader
# Conflicts:
#	common/src/main/java/net/lionarius/skinrestorer/compat/skinshuffle/SkinShuffleSkinRefreshV2Payload.java
#	neoforge/src/main/java/net/lionarius/skinrestorer/neoforge/compat/skinshuffle/SkinShuffleModEventHandler.java
2025-07-05 19:55:32 +03:00
742b4cb4d0 Merge branch '1.21-multiloader' into 1.20.5-multiloader
# Conflicts:
#	forge/src/main/java/net/lionarius/skinrestorer/forge/compat/skinshuffle/SkinShufflePacketHandler.java
2025-07-05 19:52:30 +03:00
1bacee4b22 Merge branch '1.21.5-multiloader' into 1.21-multiloader 2025-07-05 19:47:43 +03:00
4a87bd43ca Merge branch '1.21.6-multiloader' into 1.21.5-multiloader 2025-07-05 19:40:24 +03:00
96ea077004 update CHANGELOG 2025-07-05 19:39:23 +03:00
91eead3d1f bump version 2025-07-05 19:39:00 +03:00
2ea4d3f3e7 formatting 2025-07-05 19:21:45 +03:00
e65501e620 support custom skins for player head block 2025-07-05 19:15:22 +03:00
17 changed files with 147 additions and 38 deletions

View File

@@ -4,6 +4,20 @@ 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.2] - 2025-07-13
### Fixed
- Fix crash when head profile name is null (fixes [#60](https://github.com/Suiranoil/SkinRestorer/issues/60) and [#61](https://github.com/Suiranoil/SkinRestorer/issues/61))
## [2.4.1] - 2025-07-09
### Changed
- Log full exception and argument when unable to fetch/set skin
### Fixed
- Fixed mojang provider using offline uuids when unable to fetch actual uuid resulting in `no profile with uuid` error
## [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
- Fix crash when head profile name is null (fixes [#60](https://github.com/Suiranoil/SkinRestorer/issues/60) and [#61](https://github.com/Suiranoil/SkinRestorer/issues/61))

View File

@@ -1,10 +1,12 @@
package net.lionarius.skinrestorer;
import com.google.common.base.Throwables;
import com.mojang.authlib.GameProfile;
import com.mojang.brigadier.CommandDispatcher;
import net.lionarius.skinrestorer.command.SkinCommand;
import net.lionarius.skinrestorer.config.Config;
import net.lionarius.skinrestorer.config.provider.BuiltInProviderConfig;
import net.lionarius.skinrestorer.exception.TransparentException;
import net.lionarius.skinrestorer.platform.Services;
import net.lionarius.skinrestorer.skin.SkinIO;
import net.lionarius.skinrestorer.skin.SkinStorage;
@@ -147,7 +149,7 @@ public final class SkinRestorer {
var skinResult = result.get();
if (skinResult.isError())
return Result.<Collection<ServerPlayer>, String>error(skinResult.getErrorValue().getMessage());
throw new TransparentException(Throwables.getRootCause(skinResult.getErrorValue()));
var skinValue = SkinValue.fromProviderContextWithValue(context, skinResult.getSuccessValue().orElse(null));
@@ -156,7 +158,7 @@ public final class SkinRestorer {
return Result.<Collection<ServerPlayer>, String>success(acceptedPlayers);
}, server)
.exceptionally(e -> {
SkinRestorer.LOGGER.error(e.toString());
SkinRestorer.LOGGER.error("Failed to set skin '{}:{}'", context.name(), context.argument(), e);
return Result.error(e.getMessage());
});
}

View File

@@ -0,0 +1,19 @@
package net.lionarius.skinrestorer.exception;
import org.jetbrains.annotations.NotNull;
public class TransparentException extends RuntimeException {
public TransparentException(@NotNull Throwable cause) {
super(cause);
}
@Override
public String getMessage() {
return this.getCause().getMessage();
}
@Override
public String toString() {
return this.getLocalizedMessage();
}
}

View File

@@ -82,7 +82,7 @@ public abstract class ServerLoginPacketListenerImplMixin {
var value = SkinValue.fromProviderContextWithValue(context, result.getSuccessValue().orElse(null));
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value);
} else {
SkinRestorer.LOGGER.warn("Failed to fetch skin: {}", result.getErrorValue().getMessage());
SkinRestorer.LOGGER.warn("Failed to fetch skin '{}:{}'", context.name(), context.argument(), result.getErrorValue());
}
}
}

View File

@@ -0,0 +1,57 @@
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;
if (name == 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

@@ -10,6 +10,7 @@ import com.mojang.authlib.yggdrasil.YggdrasilEnvironment;
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
import com.mojang.util.UndashedUuid;
import net.lionarius.skinrestorer.SkinRestorer;
import net.lionarius.skinrestorer.exception.TransparentException;
import net.lionarius.skinrestorer.skin.SkinVariant;
import net.lionarius.skinrestorer.util.*;
import net.minecraft.server.players.GameProfileCache;
@@ -52,7 +53,7 @@ public final class MojangSkinProvider implements SkinProvider {
var profile = MojangSkinProvider.getProfile(name);
callback.onProfileLookupSucceeded(profile);
} catch (IOException e) {
callback.onProfileLookupFailed(name, e);
throw new TransparentException(e);
}
}
}, SkinRestorer.getConfigDir().resolve(PROFILE_CACHE_FILENAME).toFile());

View File

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

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

@@ -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)
@@ -34,6 +32,9 @@ public class SkinShufflePacketHandler {
// NO-OP
}
private SkinShufflePacketHandler() {
}
public static void sendHandshake(Connection connection) {
HANDSHAKE_INSTANCE.send(new FriendlyByteBuf(Unpooled.buffer(0, 0)), connection);
}

View File

@@ -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.2
mod_author=Lionarius
mod_homepage=https://modrinth.com/mod/skinrestorer
mod_sources=https://github.com/Suiranoil/SkinRestorer