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

Compare commits

..

39 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
1a5f4ab2b0 Merge branch '1.20.2-multiloader' into 1.20-multiloader 2025-05-24 14:13:19 +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
a458f3456c Merge branch '1.20.2-multiloader' into 1.20-multiloader 2025-05-03 11:30:55 +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
d351f7497c gradle properties for 1.20 2025-05-03 10:58:41 +03:00
a2279bc66e backport to 1.20 2025-05-03 10:58:25 +03:00
33586d02a3 Merge branch '1.20.2-multiloader' into 1.20-multiloader
# Conflicts:
#	gradle.properties
2025-05-03 10:53:13 +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
5da06ee325 inject at cancel-safe position 2025-05-03 09:45:53 +03:00
4a1ce7885c Merge branch '1.20.2-multiloader' into 1.20-multiloader 2025-03-27 18:35:34 +03:00
d1c0317fa1 Merge branch '1.20.2-multiloader' into 1.20-multiloader 2025-03-27 12:47:06 +03:00
694e5ebfef Merge branch '1.20.2-multiloader' into 1.20-multiloader
# Conflicts:
#	common/src/main/java/net/lionarius/skinrestorer/mixin/PlayerListMixin.java
2025-03-26 02:53:09 +03:00
048860182d Merge branch '1.20.2-multiloader' into 1.20-multiloader 2024-12-23 11:59:48 +03:00
2b8de22f70 Merge branch '1.20.2-multiloader' into 1.20-multiloader 2024-12-02 21:06:22 +03:00
e43ebdd11e Merge branch '1.20.2-multiloader' into 1.20-multiloader 2024-12-02 17:57:26 +03:00
3b88b5f5d5 Merge branch '1.20.2-multiloader' into 1.20-multiloader 2024-12-02 12:21:47 +03:00
4a3da6fd6c backport to 1.20-1.20.1 2024-12-01 23:34:34 +03:00
f6523c0d99 Merge branch '1.20.2-multiloader' into 1.20-multiloader
# Conflicts:
#	settings.gradle
2024-11-30 04:01:50 +03:00
f1ee3b4542 Merge branch 'refs/heads/1.20.2-multiloader' into 1.20-multiloader 2024-09-25 20:49:23 +03:00
bcb8cd930d backport to 1.20.0 2024-09-24 08:36:12 +03:00
8b26d81ae4 Merge branch 'refs/heads/1.20.2-multiloader' into 1.20-multiloader
# Conflicts:
#	common/src/main/java/net/lionarius/skinrestorer/mixin/ServerLoginPacketListenerImplMixin.java
2024-09-24 08:20:23 +03:00
9c9907d0ba Merge branch 'refs/heads/1.21-multiloader' into 1.20-multiloader
# Conflicts:
#	common/src/main/java/net/lionarius/skinrestorer/mixin/ServerLoginPacketListenerImplMixin.java
2024-08-20 13:53:39 +03:00
bfd8843b44 backport to 1.20-1.20.1 2024-08-04 02:36:35 +03:00
53 changed files with 167 additions and 642 deletions

1
.gitignore vendored
View File

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

View File

@@ -4,39 +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.3] - 2025-07-25
### Fixed
- Fixed crash on client when loading player head skin (fixes [#63](https://github.com/Suiranoil/SkinRestorer/issues/63) and [#64](https://github.com/Suiranoil/SkinRestorer/issues/64))
- Fixed server freeze when loading player head skin
## [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,3 +1,2 @@
### Fixed
- Fixed crash on client when loading player head skin (fixes [#63](https://github.com/Suiranoil/SkinRestorer/issues/63) and [#64](https://github.com/Suiranoil/SkinRestorer/issues/64))
- Fixed server freeze when loading player head skin
- Fixed mixin incompatibility with ModernFix (closes [#42](https://github.com/Suiranoil/SkinRestorer/issues/52))

View File

@@ -3,17 +3,14 @@ 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)
if (project.hasProperty('additional_modloaders') && !additional_modloaders.isEmpty())
{
def loaders = additional_modloaders.split(',')
for (loader in loaders)
modLoaders.add(loader)
}
type = STABLE
version = project.version
displayName = "[${project.name.capitalize()}] ${mod_name} ${mod_version}"

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;
@@ -19,7 +17,6 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.storage.LevelResource;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,7 +35,6 @@ public final class SkinRestorer {
private static Path configDir;
private static Config config;
private static TickedScheduler tickedScheduler;
private static MinecraftServer minecraftServer;
private SkinRestorer() {}
@@ -62,10 +58,6 @@ public final class SkinRestorer {
return SkinRestorer.tickedScheduler;
}
public static @Nullable MinecraftServer getMinecraftServer() {
return SkinRestorer.minecraftServer;
}
public static Optional<SkinProvider> getProvider(String name) {
return Optional.ofNullable(SkinRestorer.providersRegistry.get(name));
}
@@ -155,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));
@@ -164,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());
});
}
@@ -179,14 +171,6 @@ public final class SkinRestorer {
SkinRestorer.skinStorage = new SkinStorage(new SkinIO(worldSkinDirectory));
SkinRestorer.tickedScheduler = new TickedScheduler(server);
server.addTickable(SkinRestorer.tickedScheduler);
SkinRestorer.minecraftServer = server;
}
public static void onServerStopped(MinecraftServer server) {
SkinRestorer.skinStorage = null;
SkinRestorer.tickedScheduler = null;
SkinRestorer.minecraftServer = null;
}
public static void onCommandRegister(CommandDispatcher<CommandSourceStack> dispatcher) {

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.name().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,23 +0,0 @@
package net.lionarius.skinrestorer.compat.skinshuffle;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
public record SkinShuffleHandshakePayload() implements CustomPacketPayload {
public static final SkinShuffleHandshakePayload INSTANCE = new SkinShuffleHandshakePayload();
public static final ResourceLocation PACKET_ID = SkinShuffleCompatibility.resourceLocation("handshake");
@Override
public void write(@NotNull FriendlyByteBuf buf) {
// NO-OP
}
@Override
public @NotNull ResourceLocation id() {
return PACKET_ID;
}
}

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,35 +0,0 @@
package net.lionarius.skinrestorer.compat.skinshuffle;
import com.mojang.authlib.properties.Property;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
public record SkinShuffleSkinRefreshV1Payload(
Property textureProperty) implements CustomPacketPayload, 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.name());
buf.writeUtf(textureProperty.value());
buf.writeNullable(textureProperty.signature(), FriendlyByteBuf::writeUtf);
}
public static SkinShuffleSkinRefreshV1Payload decode(FriendlyByteBuf buf) {
return new SkinShuffleSkinRefreshV1Payload(new Property(buf.readUtf(), buf.readUtf(), buf.readNullable(FriendlyByteBuf::readUtf)));
}
@Override
public void write(@NotNull FriendlyByteBuf buf) {
encode(buf, this);
}
@Override
public @NotNull ResourceLocation id() {
return PACKET_ID;
}
}

View File

@@ -1,43 +0,0 @@
package net.lionarius.skinrestorer.compat.skinshuffle;
import com.mojang.authlib.properties.Property;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
public record SkinShuffleSkinRefreshV2Payload(
Property textureProperty) implements CustomPacketPayload, 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.name());
buf.writeUtf(textureProperty.value());
if (textureProperty.hasSignature()) {
assert textureProperty.signature() != null;
buf.writeUtf(textureProperty.signature());
}
}
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));
}
@Override
public void write(@NotNull FriendlyByteBuf buf) {
encode(buf, this);
}
@Override
public @NotNull ResourceLocation id() {
return PACKET_ID;
}
}

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

@@ -9,5 +9,5 @@ import org.spongepowered.asm.mixin.gen.Accessor;
public interface ChunkMapAccessor {
@Accessor
Int2ObjectMap<TrackedEntityAccessorInvoker> getEntityMap();
Int2ObjectMap<Object> getEntityMap();
}

View File

@@ -1,14 +0,0 @@
package net.lionarius.skinrestorer.mixin;
import net.minecraft.server.players.GameProfileCache;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.Map;
@Mixin(GameProfileCache.class)
public interface GameProfileCacheAccessor {
@Accessor
Map<String, GameProfileCache.GameProfileInfo> getProfilesByName();
}

View File

@@ -4,7 +4,6 @@ import net.lionarius.skinrestorer.SkinRestorer;
import net.minecraft.network.Connection;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.CommonListenerCookie;
import net.minecraft.server.players.PlayerList;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@@ -39,7 +38,7 @@ public abstract class PlayerListMixin {
}
@Inject(method = "placeNewPlayer", at = @At("HEAD"))
private void placeNewPlayer(Connection connection, ServerPlayer player, CommonListenerCookie cookie, CallbackInfo ci) {
private void placeNewPlayer(Connection connection, ServerPlayer player, CallbackInfo ci) {
var delay = SkinRestorer.getConfig().skinApplyDelayOnJoin();
if (delay <= 0) {

View File

@@ -21,20 +21,24 @@ import java.util.concurrent.CompletableFuture;
public abstract class ServerLoginPacketListenerImplMixin {
@Shadow @Nullable
private GameProfile authenticatedProfile;
private GameProfile gameProfile;
@Unique
private CompletableFuture<Void> skinrestorer$pendingSkin;
@Inject(method = "verifyLoginAndFinishConnectionSetup", at = @At(value = "INVOKE",
target = "Lnet/minecraft/server/players/PlayerList;canPlayerLogin(Ljava/net/SocketAddress;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/network/chat/Component;"),
cancellable = true)
@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) {
skinrestorer$pendingSkin = CompletableFuture.supplyAsync(() -> {
final var profile = authenticatedProfile;
var profile = gameProfile;
assert profile != null;
if (!profile.isComplete())
profile = createFakeProfile(profile);
var originalSkin = PlayerUtils.getPlayerSkin(profile);
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId())) {
@@ -82,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,66 +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.Util;
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.Locale;
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 = Optional.<GameProfile>empty();
var gameProfileInfo = ((GameProfileCacheAccessor) profileCache).getProfilesByName().get(name.toLowerCase(Locale.ROOT));
if (gameProfileInfo != null)
profileOpt = Optional.of(gameProfileInfo.getProfile());
skinrestorer$replaceSkin(profileOpt, cir);
}
@Unique
private static void skinrestorer$replaceSkin(Optional<GameProfile> profileOpt, CallbackInfoReturnable<CompletableFuture<Optional<GameProfile>>> cir) {
if (SkinRestorer.getMinecraftServer() == null)
return;
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);
}, Util.backgroundExecutor()));
}
}
}

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

@@ -102,6 +102,6 @@ public final class ElyBySkinProvider implements SkinProvider {
if (response.statusCode() != 200)
throw new IllegalArgumentException("no profile with name " + username);
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).toProfile();
return PlayerUtils.toProfile(JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class));
}
}

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

@@ -8,9 +8,7 @@ import com.mojang.authlib.*;
import com.mojang.authlib.properties.Property;
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;
@@ -41,19 +39,19 @@ public final class MojangSkinProvider implements SkinProvider {
try {
ENVIRONMENT = EnvironmentParser.getEnvironmentFromProperties().orElse(YggdrasilEnvironment.PROD.getEnvironment());
SERVICES_SERVER_URI = new URI(ENVIRONMENT.servicesHost());
SESSION_SERVER_URI = new URI(ENVIRONMENT.sessionHost());
SERVICES_SERVER_URI = new URI(ENVIRONMENT.getServicesHost());
SESSION_SERVER_URI = new URI(ENVIRONMENT.getSessionHost());
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
PROFILE_CACHE = new GameProfileCache((names, callback) -> {
PROFILE_CACHE = new GameProfileCache((names, agent, callback) -> {
for (var name : names) {
try {
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());
@@ -138,7 +136,7 @@ public final class MojangSkinProvider implements SkinProvider {
var request = HttpRequest.newBuilder()
.uri(MojangSkinProvider.SESSION_SERVER_URI
.resolve("/session/minecraft/profile/")
.resolve(UndashedUuid.toString(uuid) + "?unsigned=false")
.resolve(uuid.toString() + "?unsigned=false")
)
.GET()
.build();
@@ -149,6 +147,6 @@ public final class MojangSkinProvider implements SkinProvider {
if (response.statusCode() != 200)
throw new IllegalArgumentException("no profile with uuid " + uuid);
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).toProfile();
return PlayerUtils.toProfile(JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class));
}
}

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();
@@ -50,7 +47,7 @@ public final class JsonUtils {
public static JsonObject skinPropertyToJson(Property property) {
try {
JsonObject json = GSON.fromJson(new String(Base64.getDecoder().decode(property.value()), StandardCharsets.UTF_8), JsonObject.class);
JsonObject json = GSON.fromJson(new String(Base64.getDecoder().decode(property.getValue()), StandardCharsets.UTF_8), JsonObject.class);
if (json != null)
json.remove("timestamp");
@@ -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

@@ -13,6 +13,7 @@ import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.PlayerList;
import net.minecraft.world.level.biome.BiomeManager;
import java.util.*;
@@ -39,25 +40,21 @@ 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 = ((ChunkMapAccessor) chunkMap).getEntityMap().get(player.getId());
var trackedEntity = (TrackedEntityAccessorInvoker) ((ChunkMapAccessor) chunkMap).getEntityMap().get(player.getId());
if (trackedEntity != null) {
var seenBy = Set.copyOf(trackedEntity.getSeenBy());
for (var observerConnection : seenBy) {
var observer = observerConnection.getPlayer();
trackedEntity.invokeRemovePlayer(observer);
var trackedObserverEntity = ((ChunkMapAccessor) chunkMap).getEntityMap().get(observer.getId());
var trackedObserverEntity = (TrackedEntityAccessorInvoker) ((ChunkMapAccessor) chunkMap).getEntityMap().get(observer.getId());
if (trackedObserverEntity != null) {
trackedObserverEntity.invokeRemovePlayer(player);
trackedObserverEntity.invokeUpdatePlayer(player);
@@ -67,7 +64,19 @@ public final class PlayerUtils {
}
if (!player.isDeadOrDying()) {
player.connection.send(new ClientboundRespawnPacket(player.createCommonSpawnInfo(serverLevel), ClientboundRespawnPacket.KEEP_ALL_DATA));
player.connection.send(
new ClientboundRespawnPacket(
player.getLevel().dimensionTypeId(),
player.getLevel().dimension(),
BiomeManager.obfuscateSeed(player.getLevel().getSeed()),
player.gameMode.getGameModeForPlayer(),
player.gameMode.getPreviousGameModeForPlayer(),
player.getLevel().isDebug(),
player.getLevel().isFlat(),
true,
player.getLastDeathLocation()
)
);
player.connection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
player.connection.send(new ClientboundSetEntityMotionPacket(player));
var vehicle = player.getVehicle();
@@ -91,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);
}
@@ -129,8 +131,8 @@ public final class PlayerUtils {
}
public static GameProfile toProfile(MinecraftProfilePropertiesResponse response) {
final GameProfile profile = new GameProfile(response.id(), response.name());
profile.getProperties().putAll(response.properties());
final GameProfile profile = new GameProfile(response.getId(), response.getName());
profile.getProperties().putAll(response.getProperties());
return profile;
}
}

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

@@ -1 +0,0 @@
public net.minecraft.server.players.GameProfileCache$GameProfileInfo

View File

@@ -1,3 +0,0 @@
accessWidener v2 named
accessible class net/minecraft/server/players/GameProfileCache$GameProfileInfo

View File

@@ -9,9 +9,7 @@
"ChunkMapAccessor",
"PlayerListMixin",
"ServerLoginPacketListenerImplMixin",
"TrackedEntityAccessorInvoker",
"SkullBlockEntityMixin",
"GameProfileCacheAccessor"
"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,6 +1,2 @@
# Fabric, see https://fabricmc.net/develop/ for new versions
fabric_loader_version=0.15.0
fabric_api_version=0.89.0+1.20.2
optional_dependencies=fabric-api
additional_modloaders=quilt

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

@@ -15,10 +15,4 @@ public abstract class MinecraftServerMixin {
private void onServerStarted(CallbackInfo ci) {
SkinRestorer.Events.onServerStarted((MinecraftServer) (Object) this);
}
@Inject(method = "runServer",
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;onServerExit()V"))
private void onServerStopped(CallbackInfo ci) {
SkinRestorer.Events.onServerStopped((MinecraftServer) (Object) this);
}
}

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

@@ -24,13 +24,9 @@
"${mod_id}.mixins.json",
"${mod_id}.fabric.mixins.json"
],
"accessWidener": "${mod_id}.accesswidener",
"depends": {
"fabricloader": ">=${fabric_loader_version}",
"minecraft": ">=${minecraft_version}",
"java": ">=${java_version}"
},
"suggests": {
"fabric-api": "*"
}
}

View File

@@ -26,14 +26,14 @@ 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
// Automatically enable forge AccessTransformers if the file exists
// This location is hardcoded in Forge and can not be changed.
// https://github.com/MinecraftForge/MinecraftForge/blob/be1698bb1554f9c8fa2f58e32b9ab70bc4385e60/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFile.java#L123
def at = project(":common").file('src/main/resources/META-INF/accesstransformer.cfg')
def at = project(':common').file('src/main/resources/META-INF/accesstransformer.cfg')
if (at.exists()) {
accessTransformer = at
}
@@ -88,7 +88,3 @@ sourceSets.each {
it.output.resourcesDir = dir
it.java.destinationDirectory = dir
}
tasks.named('processResources') {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

View File

@@ -1,5 +1,5 @@
# Forge, see https://files.minecraftforge.net/net/minecraftforge/forge/ for new versions
forge_version=48.0.0
forge_loader_version_range=[48,)
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.2
forge_minecraft_version=1.19

View File

@@ -1,10 +1,8 @@
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.event.server.ServerStoppedEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@@ -14,9 +12,6 @@ public final class SkinRestorerForge {
public SkinRestorerForge() {
SkinRestorer.onInitialize();
if (SkinShuffleCompatibility.shouldApply())
net.lionarius.skinrestorer.forge.compat.skinshuffle.SkinShuffleCompatibility.initialize();
}
@SubscribeEvent
@@ -28,9 +23,4 @@ public final class SkinRestorerForge {
public static void onServerStarted(ServerStartedEvent event) {
SkinRestorer.Events.onServerStarted(event.getServer());
}
@SubscribeEvent
public static void onServerStopped(ServerStoppedEvent event) {
SkinRestorer.Events.onServerStopped(event.getServer());
}
}

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,60 +0,0 @@
package net.lionarius.skinrestorer.forge.compat.skinshuffle;
import io.netty.buffer.Unpooled;
import net.lionarius.skinrestorer.compat.skinshuffle.*;
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
import net.minecraft.network.Connection;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.event.network.CustomPayloadEvent;
import net.minecraftforge.network.ChannelBuilder;
import net.minecraftforge.network.EventNetworkChannel;
public class SkinShufflePacketHandler {
private static final EventNetworkChannel HANDSHAKE_INSTANCE = ChannelBuilder
.named(SkinShuffleHandshakePayload.PACKET_ID)
.optional()
.eventNetworkChannel();
private static final EventNetworkChannel SKIN_REFRESH_V1_INSTANCE = ChannelBuilder
.named(SkinShuffleSkinRefreshV1Payload.PACKET_ID)
.optional()
.eventNetworkChannel()
.addListener(SkinShufflePacketHandler::skinRefreshV1Listener);
private static final EventNetworkChannel SKIN_REFRESH_V2_INSTANCE = ChannelBuilder
.named(SkinShuffleSkinRefreshV2Payload.PACKET_ID)
.optional()
.eventNetworkChannel()
.addListener(SkinShufflePacketHandler::skinRefreshV2Listener);
protected static void initialize() {
// NO-OP
}
private SkinShufflePacketHandler() {
}
public static void sendHandshake(Connection connection) {
HANDSHAKE_INSTANCE.send(new FriendlyByteBuf(Unpooled.buffer(0, 0)), connection);
}
private static void skinRefreshV1Listener(CustomPayloadEvent event) {
var payload = SkinShuffleSkinRefreshV1Payload.decode(event.getPayload());
handleSkinRefreshPacket(payload, event.getSource());
}
private static void skinRefreshV2Listener(CustomPayloadEvent event) {
var payload = SkinShuffleSkinRefreshV2Payload.decode(event.getPayload());
handleSkinRefreshPacket(payload, event.getSource());
}
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, CustomPayloadEvent.Context context) {
var sender = context.getSender();
if (!context.isServerSide() || 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.getConnection());
}
}

View File

@@ -3,12 +3,12 @@ group=net.lionarius
java_version=17
# Common
minecraft_version=1.20.2
minecraft_version_list=1.20.2
minecraft_version_range=1.20.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.3
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.2
parchment_version=2023.12.10
parchment_minecraft=1.19.2
parchment_version=2022.11.27
# Publishing
curseforge_id=443823

View File

@@ -12,9 +12,9 @@ neoForge {
version = neoforge_version
// Automatically enable neoforge AccessTransformers if the file exists
def at = project(":common").file('src/main/resources/META-INF/accesstransformer.cfg')
def at = project(':common').file('src/main/resources/META-INF/accesstransformer.cfg')
if (at.exists()) {
accessTransformers.from(at.absolutePath)
minecraft.accessTransformers.file(at)
}
parchment {

View File

@@ -6,7 +6,6 @@ import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.event.RegisterCommandsEvent;
import net.neoforged.neoforge.event.server.ServerStartedEvent;
import net.neoforged.neoforge.event.server.ServerStoppedEvent;
@Mod(SkinRestorer.MOD_ID)
@Mod.EventBusSubscriber(modid = SkinRestorer.MOD_ID)
@@ -28,9 +27,4 @@ public final class SkinRestorerNeoForge {
public static void onServerStarted(ServerStartedEvent event) {
SkinRestorer.Events.onServerStarted(event.getServer());
}
@SubscribeEvent
public static void onServerStopped(ServerStoppedEvent event) {
SkinRestorer.Events.onServerStopped(event.getServer());
}
}

View File

@@ -71,4 +71,5 @@ rootProject.name = 'skin-restorer'
include('common')
include('fabric')
include('forge')
//include('neoforge')
// There is no NeoForge for versions <1.20.2
// include('neoforge')