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

Compare commits

..

19 Commits

Author SHA1 Message Date
42f9103f72 Merge branch '1.19.1-multiloader' into 1.19-multiloader 2025-05-24 14:39:05 +03:00
e4b03a9989 Merge branch '1.19.3-multiloader' into 1.19.1-multiloader 2025-05-24 14:33:11 +03:00
034d4863b7 Merge branch '1.19.4-multiloader' into 1.19.3-multiloader 2025-05-24 14:21:37 +03:00
59ea3eb160 Merge branch '1.20-multiloader' into 1.19.4-multiloader 2025-05-24 14:17:51 +03:00
4af85d2c6c Merge branch '1.19.1-multiloader' into 1.19-multiloader 2025-05-03 11:32:50 +03:00
c36eb4db8c Merge branch '1.19.3-multiloader' into 1.19.1-multiloader 2025-05-03 11:32:23 +03:00
768125d11d Merge branch '1.19.4-multiloader' into 1.19.3-multiloader 2025-05-03 11:31:53 +03:00
276c670902 Merge branch '1.20-multiloader' into 1.19.4-multiloader 2025-05-03 11:31:23 +03:00
90e4e2c2c9 backport to 1.19 2025-05-03 11:13:58 +03:00
1f265a0802 gradle properties for 1.19 2025-05-03 11:09:36 +03:00
e16fbffa5c gradle properties for 1.19.2 2025-05-03 11:05:40 +03:00
b67ea1bb29 Merge branch '1.19.3-multiloader' into 1.19.1-multiloader
# Conflicts:
#	gradle.properties
2025-05-03 11:04:29 +03:00
eeb405dd96 gradle properties for 1.19.3 2025-05-03 11:03:18 +03:00
3509b2e63c Merge branch '1.19.4-multiloader' into 1.19.3-multiloader
# Conflicts:
#	gradle.properties
2025-05-03 11:02:17 +03:00
f4ade5f29d gradle properties for 1.19.4 2025-05-03 11:01:26 +03:00
1ed4c8fd17 Merge branch '1.20-multiloader' into 1.19.4-multiloader
# Conflicts:
#	gradle.properties
2025-05-03 10:59:41 +03:00
17e2d1a7c3 backport to 1.19.1 2025-05-03 10:04:18 +03:00
4fb3972416 backport to 1.19.3 2025-05-03 09:46:28 +03:00
cb0756902a backport to 1.19.4 2025-05-03 09:46:13 +03:00
43 changed files with 135 additions and 514 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()) {
@@ -169,7 +169,7 @@ public final class SkinCommand {
private static int configReloadSubcommand(CommandContext<CommandSourceStack> context) {
SkinRestorer.reloadConfig();
context.getSource().sendSuccess(() -> Translation.translatableWithFallback(
context.getSource().sendSuccess(Translation.translatableWithFallback(
Translation.COMMAND_SKIN_CONFIG_RELOADED_KEY
), true);
@@ -178,7 +178,7 @@ public final class SkinCommand {
private static void sendResponse(CommandSourceStack src, Collection<ServerPlayer> updatedPlayers, boolean setByOperator) {
if (updatedPlayers.isEmpty()) {
src.sendSuccess(() -> Translation.translatableWithFallback(
src.sendSuccess(Translation.translatableWithFallback(
Translation.COMMAND_SKIN_NO_CHANGES_KEY
), true);
return;
@@ -187,12 +187,12 @@ public final class SkinCommand {
if (setByOperator) {
var playersComponent = PlayerUtils.createPlayerListComponent(updatedPlayers);
src.sendSuccess(() -> Translation.translatableWithFallback(
src.sendSuccess(Translation.translatableWithFallback(
Translation.COMMAND_SKIN_AFFECTED_PLAYERS_KEY,
playersComponent
), true);
} else {
src.sendSuccess(() -> Translation.translatableWithFallback(
src.sendSuccess(Translation.translatableWithFallback(
Translation.COMMAND_SKIN_OK_KEY
), true);
}

View File

@@ -1,55 +0,0 @@
package net.lionarius.skinrestorer.compat.skinshuffle;
import net.lionarius.skinrestorer.SkinRestorer;
import net.lionarius.skinrestorer.platform.Services;
import net.lionarius.skinrestorer.skin.SkinValue;
import net.lionarius.skinrestorer.skin.provider.SkinShuffleSkinProvider;
import net.lionarius.skinrestorer.util.PlayerUtils;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import java.util.Collections;
public class SkinShuffleCompatibility {
public static final String MOD_ID = "skinshuffle";
private static final boolean SHOULD_APPLY = !Services.PLATFORM.isModLoaded(SkinShuffleCompatibility.MOD_ID);
private SkinShuffleCompatibility() {}
public static boolean shouldApply() {
return SkinShuffleCompatibility.SHOULD_APPLY;
}
public static ResourceLocation resourceLocation(String name) {
return new ResourceLocation(SkinShuffleCompatibility.MOD_ID, name);
}
public static void onPlayerJoin(ServerPlayer player) {
Services.COMPATIBILITY.skinShuffle_sendHandshake(player);
}
public static void handleSkinRefresh(MinecraftServer server, ServerPlayer player, SkinShuffleSkinRefreshPayload payload) {
var property = payload.textureProperty();
if (!property.getName().equals(PlayerUtils.TEXTURES_KEY))
return;
if (!property.hasSignature())
return;
server.execute(() -> {
SkinRestorer.applySkin(
server,
Collections.singleton(player.getGameProfile()),
new SkinValue(SkinShuffleSkinProvider.PROVIDER_NAME, null, null, property),
!server.usesAuthentication()
);
if (server.usesAuthentication() && SkinRestorer.getSkinStorage().hasSavedSkin(player.getUUID()))
SkinRestorer.getSkinStorage().deleteSkin(player.getUUID());
});
}
}

View File

@@ -1,10 +0,0 @@
package net.lionarius.skinrestorer.compat.skinshuffle;
import net.minecraft.resources.ResourceLocation;
public record SkinShuffleHandshakePayload() {
public static final SkinShuffleHandshakePayload INSTANCE = new SkinShuffleHandshakePayload();
public static final ResourceLocation PACKET_ID = SkinShuffleCompatibility.resourceLocation("handshake");
}

View File

@@ -1,7 +0,0 @@
package net.lionarius.skinrestorer.compat.skinshuffle;
import com.mojang.authlib.properties.Property;
public interface SkinShuffleSkinRefreshPayload {
Property textureProperty();
}

View File

@@ -1,23 +0,0 @@
package net.lionarius.skinrestorer.compat.skinshuffle;
import com.mojang.authlib.properties.Property;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
public record SkinShuffleSkinRefreshV1Payload(
Property textureProperty) implements SkinShuffleSkinRefreshPayload {
public static final ResourceLocation PACKET_ID = SkinShuffleCompatibility.resourceLocation("refresh");
public static void encode(FriendlyByteBuf buf, SkinShuffleSkinRefreshV1Payload value) {
var textureProperty = value.textureProperty();
buf.writeUtf(textureProperty.getName());
buf.writeUtf(textureProperty.getValue());
buf.writeNullable(textureProperty.getSignature(), FriendlyByteBuf::writeUtf);
}
public static SkinShuffleSkinRefreshV1Payload decode(FriendlyByteBuf buf) {
return new SkinShuffleSkinRefreshV1Payload(new Property(buf.readUtf(), buf.readUtf(), buf.readNullable(FriendlyByteBuf::readUtf)));
}
}

View File

@@ -1,31 +0,0 @@
package net.lionarius.skinrestorer.compat.skinshuffle;
import com.mojang.authlib.properties.Property;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
public record SkinShuffleSkinRefreshV2Payload(
Property textureProperty) implements SkinShuffleSkinRefreshPayload {
public static final ResourceLocation PACKET_ID = SkinShuffleCompatibility.resourceLocation("skin_refresh");
public static void encode(FriendlyByteBuf buf, SkinShuffleSkinRefreshV2Payload value) {
var textureProperty = value.textureProperty();
buf.writeBoolean(textureProperty.hasSignature());
buf.writeUtf(textureProperty.getName());
buf.writeUtf(textureProperty.getValue());
if (textureProperty.hasSignature()) {
assert textureProperty.getSignature() != null;
buf.writeUtf(textureProperty.getSignature());
}
}
public static SkinShuffleSkinRefreshV2Payload decode(FriendlyByteBuf buf) {
if (buf.readBoolean()) {
return new SkinShuffleSkinRefreshV2Payload(new Property(buf.readUtf(), buf.readUtf(), buf.readUtf()));
}
return new SkinShuffleSkinRefreshV2Payload(new Property(buf.readUtf(), buf.readUtf(), null));
}
}

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

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

@@ -1,8 +1,4 @@
package net.lionarius.skinrestorer.platform.services;
import net.minecraft.server.level.ServerPlayer;
public interface CompatibilityHelper {
void skinShuffle_sendHandshake(ServerPlayer player);
}

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

@@ -9,11 +9,25 @@ import org.jetbrains.annotations.Nullable;
import java.util.Objects;
public record SkinValue(@NotNull String provider, @Nullable String argument, @Nullable SkinVariant variant,
@Nullable Property value, @Nullable Property originalValue) implements GsonPostProcessable {
public final class SkinValue implements GsonPostProcessable {
public static final SkinValue EMPTY = new SkinValue(EmptySkinProvider.PROVIDER_NAME, null, null, null);
private @NotNull String provider;
private @Nullable String argument;
private @Nullable SkinVariant variant;
private @Nullable Property value;
private @Nullable Property originalValue;
public SkinValue(@NotNull String provider, @Nullable String argument, @Nullable SkinVariant variant,
@Nullable Property value, @Nullable Property originalValue) {
this.provider = provider;
this.argument = argument;
this.variant = variant;
this.value = value;
this.originalValue = originalValue;
}
public SkinValue(String provider, String argument, SkinVariant variant, Property value) {
this(provider, argument, variant, value, null);
}
@@ -38,4 +52,23 @@ public record SkinValue(@NotNull String provider, @Nullable String argument, @Nu
public void gsonPostProcess() {
Objects.requireNonNull(this.provider);
}
public @NotNull String provider() {
return provider;
}
public @Nullable String argument() {
return argument;
}
public @Nullable SkinVariant variant() {
return variant;}
public @Nullable Property value() {
return value;
}
public @Nullable Property originalValue() {
return originalValue;
}
}

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

@@ -39,11 +39,11 @@ public final class Translation {
}
public static MutableComponent translatableWithFallback(String key) {
return Component.translatableWithFallback(key, Translation.get(key));
return Component.translatable(Translation.get(key));
}
public static MutableComponent translatableWithFallback(String key, Object... args) {
return Component.translatableWithFallback(key, Translation.get(key), args);
return Component.translatable(Translation.get(key), args);
}
public static void reloadTranslations() {

View File

@@ -1,9 +1,6 @@
package net.lionarius.skinrestorer.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.*;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
@@ -22,7 +19,7 @@ public final class JsonUtils {
.registerTypeAdapterFactory(new PostProcessingEnabler())
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter())
.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer())
.registerTypeAdapter(GameProfile.class, new GameProfile.Serializer())
.registerTypeAdapter(GameProfile.class, new GameProfileSerializer())
.setPrettyPrinting()
.create();
@@ -60,4 +57,26 @@ public final class JsonUtils {
return null;
}
}
private static class GameProfileSerializer implements JsonSerializer<GameProfile>, JsonDeserializer<GameProfile> {
@Override
public GameProfile deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException {
final JsonObject object = (JsonObject) json;
final UUID id = object.has("id") ? context.deserialize(object.get("id"), UUID.class) : null;
final String name = object.has("name") ? object.getAsJsonPrimitive("name").getAsString() : null;
return new GameProfile(id, name);
}
@Override
public JsonElement serialize(final GameProfile src, final Type typeOfSrc, final JsonSerializationContext context) {
final JsonObject result = new JsonObject();
if (src.getId() != null) {
result.add("id", context.serialize(src.getId()));
}
if (src.getName() != null) {
result.addProperty("name", src.getName());
}
return result;
}
}
}

View File

@@ -40,16 +40,12 @@ public final class PlayerUtils {
}
public static void refreshPlayer(ServerPlayer player) {
ServerLevel serverLevel = player.serverLevel();
ServerLevel serverLevel = player.getLevel();
PlayerList playerList = serverLevel.getServer().getPlayerList();
ChunkMap chunkMap = serverLevel.getChunkSource().chunkMap;
playerList.broadcastAll(new ClientboundBundlePacket(
List.of(
new ClientboundPlayerInfoRemovePacket(List.of(player.getUUID())),
ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(Collections.singleton(player))
)
));
playerList.broadcastAll(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, player));
playerList.broadcastAll(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, player));
var trackedEntity = (TrackedEntityAccessorInvoker) ((ChunkMapAccessor) chunkMap).getEntityMap().get(player.getId());
if (trackedEntity != null) {
@@ -70,16 +66,15 @@ public final class PlayerUtils {
if (!player.isDeadOrDying()) {
player.connection.send(
new ClientboundRespawnPacket(
player.level().dimensionTypeId(),
player.level().dimension(),
BiomeManager.obfuscateSeed(player.serverLevel().getSeed()),
player.getLevel().dimensionTypeId(),
player.getLevel().dimension(),
BiomeManager.obfuscateSeed(player.getLevel().getSeed()),
player.gameMode.getGameModeForPlayer(),
player.gameMode.getPreviousGameModeForPlayer(),
player.level().isDebug(),
player.serverLevel().isFlat(),
(byte) 3,
player.getLastDeathLocation(),
player.getPortalCooldown()
player.getLevel().isDebug(),
player.getLevel().isFlat(),
true,
player.getLastDeathLocation()
)
);
player.connection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
@@ -105,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

@@ -14,8 +14,6 @@ dependencies {
}
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
modCompileOnly "net.fabricmc.fabric-api:fabric-api:${fabric_api_version}"
include implementation("org.mineskin:java-client:${mineskin_client_version}")
}

View File

@@ -1,5 +1,2 @@
# Fabric, see https://fabricmc.net/develop/ for new versions
fabric_loader_version=0.15.0
fabric_api_version=0.83.0+1.20
optional_dependencies=fabric-api

View File

@@ -2,18 +2,11 @@ package net.lionarius.skinrestorer.fabric;
import net.fabricmc.api.ModInitializer;
import net.lionarius.skinrestorer.SkinRestorer;
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
import net.lionarius.skinrestorer.platform.Services;
public final class SkinRestorerFabric implements ModInitializer {
public static final boolean FABRIC_API_LOADED = Services.PLATFORM.isModLoaded("fabric-api");
@Override
public void onInitialize() {
SkinRestorer.onInitialize();
if (SkinShuffleCompatibility.shouldApply())
net.lionarius.skinrestorer.fabric.compat.skinshuffle.SkinShuffleCompatibility.initialize();
}
}

View File

@@ -1,46 +0,0 @@
package net.lionarius.skinrestorer.fabric.compat.skinshuffle;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.lionarius.skinrestorer.SkinRestorer;
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleSkinRefreshPayload;
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleSkinRefreshV1Payload;
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleSkinRefreshV2Payload;
import net.lionarius.skinrestorer.fabric.SkinRestorerFabric;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
public final class SkinShuffleCompatibility {
private SkinShuffleCompatibility() {}
public static void initialize() {
if (!SkinRestorerFabric.FABRIC_API_LOADED) {
SkinRestorer.LOGGER.warn("fabric-api is not loaded, SkinShuffle compatibility will not be available");
return;
}
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility.onPlayerJoin(handler.getPlayer()));
ServerPlayNetworking.registerGlobalReceiver(SkinShuffleSkinRefreshV1Payload.PACKET_ID, SkinShuffleCompatibility::handleSkinRefreshV1Packet);
ServerPlayNetworking.registerGlobalReceiver(SkinShuffleSkinRefreshV2Payload.PACKET_ID, SkinShuffleCompatibility::handleSkinRefreshV2Packet);
}
private static void handleSkinRefreshV1Packet(MinecraftServer server, ServerPlayer player, ServerGamePacketListenerImpl listener, FriendlyByteBuf buf, PacketSender sender) {
var payload = SkinShuffleSkinRefreshV1Payload.decode(buf);
SkinShuffleCompatibility.handleSkinRefreshPacket(payload, server, player);
}
private static void handleSkinRefreshV2Packet(MinecraftServer server, ServerPlayer player, ServerGamePacketListenerImpl listener, FriendlyByteBuf buf, PacketSender sender) {
var payload = SkinShuffleSkinRefreshV2Payload.decode(buf);
SkinShuffleCompatibility.handleSkinRefreshPacket(payload, server, player);
}
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, MinecraftServer server, ServerPlayer player) {
net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility.handleSkinRefresh(server, player, payload);
}
}

View File

@@ -1,14 +1,6 @@
package net.lionarius.skinrestorer.fabric.platform;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleHandshakePayload;
import net.lionarius.skinrestorer.platform.services.CompatibilityHelper;
import net.minecraft.server.level.ServerPlayer;
public final class FabricCompatibilityHelper implements CompatibilityHelper {
@Override
public void skinShuffle_sendHandshake(ServerPlayer player) {
ServerPlayNetworking.send(player, SkinShuffleHandshakePayload.PACKET_ID, PacketByteBufs.empty());
}
}

View File

@@ -28,8 +28,5 @@
"fabricloader": ">=${fabric_loader_version}",
"minecraft": ">=${minecraft_version}",
"java": ">=${java_version}"
},
"suggests": {
"fabric-api": "*"
}
}

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=46.0.1
forge_loader_version_range=[46,)
forge_version=41.0.1
forge_loader_version_range=[41,)
# Forge sometimes skips minor minecraft versions (like 1.20.5)
forge_minecraft_version=1.20
forge_minecraft_version=1.19

View File

@@ -1,7 +1,6 @@
package net.lionarius.skinrestorer.forge;
import net.lionarius.skinrestorer.SkinRestorer;
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.server.ServerStartedEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@@ -13,9 +12,6 @@ public final class SkinRestorerForge {
public SkinRestorerForge() {
SkinRestorer.onInitialize();
if (SkinShuffleCompatibility.shouldApply())
net.lionarius.skinrestorer.forge.compat.skinshuffle.SkinShuffleCompatibility.initialize();
}
@SubscribeEvent

View File

@@ -1,14 +0,0 @@
package net.lionarius.skinrestorer.forge.compat.skinshuffle;
import net.minecraftforge.common.MinecraftForge;
public final class SkinShuffleCompatibility {
private SkinShuffleCompatibility() {}
public static void initialize() {
MinecraftForge.EVENT_BUS.register(SkinShuffleGameEventHandler.class);
SkinShufflePacketHandler.initialize();
}
}

View File

@@ -1,16 +0,0 @@
package net.lionarius.skinrestorer.forge.compat.skinshuffle;
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
public final class SkinShuffleGameEventHandler {
private SkinShuffleGameEventHandler() {}
@SubscribeEvent
public static void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
SkinShuffleCompatibility.onPlayerJoin((ServerPlayer) event.getEntity());
}
}

View File

@@ -1,68 +0,0 @@
package net.lionarius.skinrestorer.forge.compat.skinshuffle;
import io.netty.buffer.Unpooled;
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
import net.lionarius.skinrestorer.compat.skinshuffle.*;
import net.minecraft.network.Connection;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
import net.minecraftforge.network.NetworkEvent;
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.event.EventNetworkChannel;
public class SkinShufflePacketHandler {
private static final EventNetworkChannel HANDSHAKE_INSTANCE = NetworkRegistry.ChannelBuilder
.named(SkinShuffleHandshakePayload.PACKET_ID)
.clientAcceptedVersions(NetworkRegistry.acceptMissingOr(""))
.serverAcceptedVersions(NetworkRegistry.acceptMissingOr(""))
.networkProtocolVersion(() -> "")
.eventNetworkChannel();
private static final EventNetworkChannel SKIN_REFRESH_V1_INSTANCE = NetworkRegistry.ChannelBuilder
.named(SkinShuffleSkinRefreshV1Payload.PACKET_ID)
.clientAcceptedVersions(NetworkRegistry.acceptMissingOr(""))
.serverAcceptedVersions(NetworkRegistry.acceptMissingOr(""))
.networkProtocolVersion(() -> "")
.eventNetworkChannel();
private static final EventNetworkChannel SKIN_REFRESH_V2_INSTANCE = NetworkRegistry.ChannelBuilder
.named(SkinShuffleSkinRefreshV2Payload.PACKET_ID)
.clientAcceptedVersions(NetworkRegistry.acceptMissingOr(""))
.serverAcceptedVersions(NetworkRegistry.acceptMissingOr(""))
.networkProtocolVersion(() -> "")
.eventNetworkChannel();
protected static void initialize() {
SKIN_REFRESH_V1_INSTANCE.addListener(SkinShufflePacketHandler::skinRefreshV1Listener);
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))));
}
private static void skinRefreshV1Listener(NetworkEvent.ClientCustomPayloadEvent event) {
var payload = SkinShuffleSkinRefreshV1Payload.decode(event.getPayload());
handleSkinRefreshPacket(payload, event.getSource().get());
event.getSource().get().setPacketHandled(true);
}
private static void skinRefreshV2Listener(NetworkEvent.ClientCustomPayloadEvent event) {
var payload = SkinShuffleSkinRefreshV2Payload.decode(event.getPayload());
handleSkinRefreshPacket(payload, event.getSource().get());
event.getSource().get().setPacketHandled(true);
}
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, NetworkEvent.Context context) {
var sender = context.getSender();
if (!context.getDirection().getReceptionSide().isServer() || sender == null)
return;
SkinShuffleCompatibility.handleSkinRefresh(sender.getServer(), sender, payload);
}
}

View File

@@ -1,13 +1,6 @@
package net.lionarius.skinrestorer.forge.platform;
import net.lionarius.skinrestorer.forge.compat.skinshuffle.SkinShufflePacketHandler;
import net.lionarius.skinrestorer.platform.services.CompatibilityHelper;
import net.minecraft.server.level.ServerPlayer;
public final class ForgeCompatibilityHelper implements CompatibilityHelper {
@Override
public void skinShuffle_sendHandshake(ServerPlayer player) {
SkinShufflePacketHandler.sendHandshake(player.connection.connection);
}
}

View File

@@ -3,12 +3,12 @@ group=net.lionarius
java_version=17
# Common
minecraft_version=1.20
minecraft_version_list=1.20,1.20.1
minecraft_version_range=[1.20, 1.20.1]
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,11 +18,11 @@ 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.20.1
parchment_version=2023.09.03
parchment_minecraft=1.19.2
parchment_version=2022.11.27
# Publishing
curseforge_id=443823