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

Compare commits

..

4 Commits

23 changed files with 57 additions and 175 deletions

1
.gitignore vendored
View File

@@ -30,4 +30,3 @@ bin/
.architectury-transformer/
run/
scripts/

View File

@@ -4,34 +4,6 @@ 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
## [2.3.4] - 2025-06-19
### Added
- Added support for minecraft 1.21.6
## [2.3.3] - 2025-06-01
### Fixed
- Fixed forge mixin crash (closes [#54](https://github.com/Suiranoil/SkinRestorer/issues/53))
### Removed
- Removed minecraft 1.19 support
## [2.3.2] - 2025-05-24
### Fixed
- Fixed mixin incompatibility with ModernFix (closes [#42](https://github.com/Suiranoil/SkinRestorer/issues/52))

View File

@@ -1,2 +1,2 @@
### 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))
- Fixed mixin incompatibility with ModernFix (closes [#42](https://github.com/Suiranoil/SkinRestorer/issues/52))

View File

@@ -3,7 +3,12 @@ plugins {
}
publishMods {
file = project.layout.buildDirectory.file("libs/${project.archivesBaseName}-${project.version}.jar").map { it.asFile }.getOrNull()
if (project.name == 'fabric')
file = remapJar.archiveFile
else if (project.name == 'neoforge')
file = jar.archiveFile
else
file = tasks.named('jarJar').get().archiveFile
modLoaders.add(project.name)
type = STABLE

View File

@@ -1,12 +1,10 @@
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;
@@ -149,7 +147,7 @@ public final class SkinRestorer {
var skinResult = result.get();
if (skinResult.isError())
throw new TransparentException(Throwables.getRootCause(skinResult.getErrorValue()));
return Result.<Collection<ServerPlayer>, String>error(skinResult.getErrorValue().getMessage());
var skinValue = SkinValue.fromProviderContextWithValue(context, skinResult.getSuccessValue().orElse(null));
@@ -158,7 +156,7 @@ public final class SkinRestorer {
return Result.<Collection<ServerPlayer>, String>success(acceptedPlayers);
}, server)
.exceptionally(e -> {
SkinRestorer.LOGGER.error("Failed to set skin '{}:{}'", context.name(), context.argument(), e);
SkinRestorer.LOGGER.error(e.toString());
return Result.error(e.getMessage());
});
}

View File

@@ -128,7 +128,7 @@ public final class SkinCommand {
boolean save,
boolean setByOperator
) {
src.sendSystemMessage(Translation.translatableWithFallback(Translation.COMMAND_SKIN_LOADING_KEY));
src.sendSuccess(Translation.translatableWithFallback(Translation.COMMAND_SKIN_LOADING_KEY), false);
SkinRestorer.setSkinAsync(src.getServer(), targets, context, save).thenAccept(result -> {
if (result.isError()) {

View File

@@ -1,19 +0,0 @@
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

@@ -32,8 +32,8 @@ public class Java11RequestHandler extends RequestHandler {
private final Gson gson;
private final HttpClient httpClient;
public Java11RequestHandler(String baseUrl, String userAgent, String apiKey, int timeout, Gson gson, InetSocketAddress proxy) {
super(baseUrl, userAgent, apiKey, timeout, gson);
public Java11RequestHandler(String userAgent, String apiKey, int timeout, Gson gson, InetSocketAddress proxy) {
super(userAgent, apiKey, timeout, gson);
this.gson = gson;
HttpClient.Builder clientBuilder = HttpClient.newBuilder()
@@ -85,7 +85,6 @@ public class Java11RequestHandler extends RequestHandler {
public <T, R extends MineSkinResponse<T>> R getJson(String url, Class<T> clazz, ResponseConstructor<T, R> constructor)
throws IOException {
url = this.baseUrl + url;
MineSkinClientImpl.LOGGER.fine("GET " + url);
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
@@ -111,7 +110,6 @@ public class Java11RequestHandler extends RequestHandler {
public <T, R extends MineSkinResponse<T>> R postJson(String url, JsonObject data, Class<T> clazz, ResponseConstructor<T, R> constructor)
throws IOException {
url = this.baseUrl + url;
MineSkinClientImpl.LOGGER.fine("POST " + url);
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
@@ -139,7 +137,6 @@ public class Java11RequestHandler extends RequestHandler {
public <T, R extends MineSkinResponse<T>> R postFormDataFile(String url, String key, String filename, InputStream in, Map<String, String> data, Class<T> clazz, ResponseConstructor<T, R> constructor)
throws IOException {
url = this.baseUrl + url;
MineSkinClientImpl.LOGGER.fine("POST " + url);
String boundary = "mineskin-" + System.currentTimeMillis();

View File

@@ -23,12 +23,12 @@ public abstract class ServerLoginPacketListenerImplMixin {
@Shadow @Nullable
private GameProfile gameProfile;
@Shadow
protected abstract GameProfile createFakeProfile(GameProfile original);
@Unique
private CompletableFuture<Void> skinrestorer$pendingSkin;
@Shadow
protected abstract GameProfile createFakeProfile(GameProfile original);
@Inject(method = "handleAcceptedLogin", at = @At(value = "HEAD"), cancellable = true)
public void waitForSkin(CallbackInfo ci) {
if (skinrestorer$pendingSkin == null) {
@@ -86,7 +86,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 '{}:{}'", context.name(), context.argument(), result.getErrorValue());
SkinRestorer.LOGGER.warn("Failed to fetch skin: {}", result.getErrorValue().getMessage());
}
}
}

View File

@@ -1,53 +0,0 @@
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.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.CallbackInfo;
import java.util.Optional;
import java.util.function.Consumer;
@Mixin(SkullBlockEntity.class)
public abstract class SkullBlockEntityMixin {
@Shadow
private static GameProfileCache profileCache;
@Inject(method = "updateGameprofile", at = @At("HEAD"),
cancellable = true)
private static void fetchProfileByName(GameProfile profile, Consumer<GameProfile> profileConsumer, CallbackInfo ci) {
if (profileCache == null)
return;
if (profile == null || profile.isComplete() || profile.getName() == null)
return;
var profileOpt = profileCache.get(profile.getName());
skinrestorer$replaceSkin(profileOpt, profileConsumer, ci);
}
@Unique
private static void skinrestorer$replaceSkin(Optional<GameProfile> profileOpt, Consumer<GameProfile> profileConsumer, CallbackInfo ci) {
if (profileOpt.isEmpty())
return;
var profile = PlayerUtils.cloneGameProfile(profileOpt.get());
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId())) {
var skin = SkinRestorer.getSkinStorage().getSkin(profile.getId(), false);
PlayerUtils.applyRestoredSkin(profile, skin.value());
profileConsumer.accept(profile);
ci.cancel();
}
}
}

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,22 +17,15 @@ public class SkinStorage {
return this.skinMap.containsKey(uuid) || this.skinIO.skinExists(uuid);
}
public SkinValue getSkin(UUID uuid, boolean cache) {
public SkinValue getSkin(UUID uuid) {
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

@@ -43,8 +43,7 @@ public final class MineskinSkinProvider implements SkinProvider {
.userAgent(WebUtils.USER_AGENT)
.gson(JsonUtils.GSON)
.timeout((int) Duration.ofSeconds(config.requestTimeout()).toMillis())
.requestHandler((baseUrl, userAgent, apiKey, timeout, gson) -> new Java11RequestHandler(
baseUrl,
.requestHandler((userAgent, apiKey, timeout, gson) -> new Java11RequestHandler(
userAgent,
apiKey,
timeout,

View File

@@ -9,7 +9,6 @@ import com.mojang.authlib.properties.Property;
import com.mojang.authlib.yggdrasil.YggdrasilEnvironment;
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
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 +51,7 @@ public final class MojangSkinProvider implements SkinProvider {
var profile = MojangSkinProvider.getProfile(name);
callback.onProfileLookupSucceeded(profile);
} catch (IOException e) {
throw new TransparentException(e);
callback.onProfileLookupFailed(new GameProfile(null, name), e);
}
}
}, SkinRestorer.getConfigDir().resolve(PROFILE_CACHE_FILENAME).toFile());

View File

@@ -100,13 +100,6 @@ 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,18 +19,6 @@ 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;
}
@@ -81,4 +69,16 @@ 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,6 +13,8 @@ import java.time.temporal.ChronoUnit;
public final class WebUtils {
private WebUtils() {}
public static final String USER_AGENT;
private static HttpClient HTTP_CLIENT = null;
@@ -21,8 +23,6 @@ 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,8 +9,7 @@
"ChunkMapAccessor",
"PlayerListMixin",
"ServerLoginPacketListenerImplMixin",
"TrackedEntityAccessorInvoker",
"SkullBlockEntityMixin"
"TrackedEntityAccessorInvoker"
],
"injectors": {
"defaultRequire": 1

View File

@@ -26,7 +26,7 @@ tasks.named('jarJar') {
}
minecraft {
mappings channel: 'parchment', version: "${parchment_minecraft}-${parchment_version}-${minecraft_version}"
mappings channel: 'parchment', version: "${parchment_version}-${parchment_minecraft}"
copyIdeResources = true //Calls processResources when in dev

View File

@@ -1,5 +1,5 @@
# Forge, see https://files.minecraftforge.net/net/minecraftforge/forge/ for new versions
forge_version=42.0.0
forge_loader_version_range=[42,)
forge_version=41.0.1
forge_loader_version_range=[41,)
# Forge sometimes skips minor minecraft versions (like 1.20.5)
forge_minecraft_version=1.19.1
forge_minecraft_version=1.19

View File

@@ -3,12 +3,12 @@ group=net.lionarius
java_version=17
# Common
minecraft_version=1.19.1
minecraft_version_list=1.19.1,1.19.2
minecraft_version_range=[1.19.1,1.19.2]
minecraft_version=1.19
minecraft_version_list=1.19
minecraft_version_range=[1.19,1.19.1)
mod_id=skinrestorer
mod_name=SkinRestorer
mod_version=2.4.2
mod_version=2.3.2
mod_author=Lionarius
mod_homepage=https://modrinth.com/mod/skinrestorer
mod_sources=https://github.com/Suiranoil/SkinRestorer
@@ -18,7 +18,7 @@ credits=
description=A server-side mod for managing skins.
# Dependencies
mineskin_client_version=3.0.6-SNAPSHOT
mineskin_client_version=3.0.1-SNAPSHOT
# ParchmentMC mappings, see https://parchmentmc.org/docs/getting-started#choose-a-version for new versions
parchment_minecraft=1.19.2