mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
Compare commits
67 Commits
9298cad91d
...
1.19.3-mul
| Author | SHA1 | Date | |
|---|---|---|---|
|
20141e0320
|
|||
|
ee36a8b7f0
|
|||
|
748e9911c0
|
|||
|
63a8ff18b5
|
|||
|
41793a904f
|
|||
|
3c2269ca6e
|
|||
|
4cf35048b0
|
|||
|
965af68461
|
|||
|
8fba8a997e
|
|||
|
a0d8f3d518
|
|||
|
aa3cb3df09
|
|||
|
0524b5dab8
|
|||
|
301428147d
|
|||
|
2e655ce1f3
|
|||
|
7dcd1d4e81
|
|||
|
1aa606038e
|
|||
|
e832e02fd4
|
|||
|
ffd2a0dba7
|
|||
|
76e801c944
|
|||
|
da754aa830
|
|||
|
69a561f679
|
|||
|
b5bed1c441
|
|||
|
f36390a3d5
|
|||
|
24b956a91c
|
|||
|
2233f28c68
|
|||
|
9c9f02667c
|
|||
|
abcb37fc6b
|
|||
|
b3b524c53a
|
|||
|
e6b2dcb4eb
|
|||
|
5f8a868e5c
|
|||
|
fce13237f9
|
|||
|
c987d48738
|
|||
|
583205febc
|
|||
|
fb7a4d11e9
|
|||
|
1d8472e35c
|
|||
|
f604ac2c8b
|
|||
|
8d4c2e9f83
|
|||
|
84a06898a2
|
|||
|
11ecf88eb2
|
|||
|
7849aa9be2
|
|||
|
47b59e61d1
|
|||
|
bdaf27e68a
|
|||
|
a59c920307
|
|||
|
45c438b03e
|
|||
|
b2fed5be60
|
|||
|
7958f26acf
|
|||
|
90e6bf554e
|
|||
|
6c96dcfd4a
|
|||
|
20ff29e8d9
|
|||
|
474f601cc3
|
|||
|
1aeedf9cb4
|
|||
|
ff43c18634
|
|||
|
02082e6a2a
|
|||
|
bd983e10ec
|
|||
|
c695e66a94
|
|||
|
c9bf691544
|
|||
|
1a6327f91c
|
|||
|
034d4863b7
|
|||
|
59ea3eb160
|
|||
|
768125d11d
|
|||
|
276c670902
|
|||
|
eeb405dd96
|
|||
|
3509b2e63c
|
|||
|
f4ade5f29d
|
|||
|
1ed4c8fd17
|
|||
|
4fb3972416
|
|||
|
cb0756902a
|
10
CHANGELOG.md
10
CHANGELOG.md
@@ -4,6 +4,16 @@ 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.5.0] - 2026-01-14
|
||||
### Added
|
||||
- Added collection skin provider (allows assigning random skins from a predefined set)
|
||||
- Added `forceFirstJoinSkinFetch` config option to force skin fetch on first join even if player already has a skin
|
||||
|
||||
## [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))
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
### 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))
|
||||
### Added
|
||||
- Added collection skin provider (allows assigning random skins from a predefined set) (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Configuration#providerscollection))
|
||||
- Added `forceFirstJoinSkinFetch` config option to force skin fetch on first join even if player already has a skin (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Configuration#forcefirstjoinskinfetch))
|
||||
|
||||
@@ -6,6 +6,14 @@ publishMods {
|
||||
file = project.layout.buildDirectory.file("libs/${project.archivesBaseName}-${project.version}.jar").map { it.asFile }.getOrNull()
|
||||
|
||||
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}"
|
||||
|
||||
@@ -19,6 +19,7 @@ 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;
|
||||
|
||||
@@ -37,6 +38,7 @@ public final class SkinRestorer {
|
||||
private static Path configDir;
|
||||
private static Config config;
|
||||
private static TickedScheduler tickedScheduler;
|
||||
private static MinecraftServer minecraftServer;
|
||||
|
||||
private SkinRestorer() {}
|
||||
|
||||
@@ -60,6 +62,10 @@ 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));
|
||||
}
|
||||
@@ -82,6 +88,7 @@ public final class SkinRestorer {
|
||||
SkinRestorer.registerDefaultSkinProvider(MojangSkinProvider.PROVIDER_NAME, SkinProvider.MOJANG, SkinRestorer.getConfig().providersConfig().mojang());
|
||||
SkinRestorer.registerDefaultSkinProvider(ElyBySkinProvider.PROVIDER_NAME, SkinProvider.ELY_BY, SkinRestorer.getConfig().providersConfig().ely_by());
|
||||
SkinRestorer.registerDefaultSkinProvider(MineskinSkinProvider.PROVIDER_NAME, SkinProvider.MINESKIN, SkinRestorer.getConfig().providersConfig().mineskin());
|
||||
SkinRestorer.registerDefaultSkinProvider(CollectionSkinProvider.PROVIDER_NAME, SkinProvider.COLLECTION, SkinRestorer.getConfig().providersConfig().collection());
|
||||
}
|
||||
|
||||
private static void registerDefaultSkinProvider(String defaultName, SkinProvider provider, BuiltInProviderConfig config) {
|
||||
@@ -100,6 +107,7 @@ public final class SkinRestorer {
|
||||
MojangSkinProvider.reload();
|
||||
ElyBySkinProvider.reload();
|
||||
MineskinSkinProvider.reload();
|
||||
CollectionSkinProvider.reload();
|
||||
}
|
||||
|
||||
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<GameProfile> targets, SkinValue value, boolean save) {
|
||||
@@ -173,6 +181,14 @@ 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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package net.lionarius.skinrestorer.compat.skinshuffle;
|
||||
|
||||
import com.mojang.authlib.properties.Property;
|
||||
|
||||
public interface SkinShuffleSkinRefreshPayload {
|
||||
Property textureProperty();
|
||||
}
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@ public final class Config implements GsonPostProcessable {
|
||||
|
||||
private boolean fetchSkinOnFirstJoin = true;
|
||||
|
||||
private boolean forceFirstJoinSkinFetch = false;
|
||||
|
||||
private FirstJoinSkinProvider firstJoinSkinProvider = FirstJoinSkinProvider.MOJANG;
|
||||
|
||||
private String proxy = "";
|
||||
@@ -47,6 +49,10 @@ public final class Config implements GsonPostProcessable {
|
||||
return this.fetchSkinOnFirstJoin;
|
||||
}
|
||||
|
||||
public boolean forceFirstJoinSkinFetch() {
|
||||
return this.forceFirstJoinSkinFetch;
|
||||
}
|
||||
|
||||
public FirstJoinSkinProvider firstJoinSkinProvider() {
|
||||
return this.firstJoinSkinProvider;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.lionarius.skinrestorer.config;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import net.lionarius.skinrestorer.skin.provider.CollectionSkinProvider;
|
||||
import net.lionarius.skinrestorer.skin.provider.ElyBySkinProvider;
|
||||
import net.lionarius.skinrestorer.skin.provider.MojangSkinProvider;
|
||||
|
||||
@@ -8,7 +9,9 @@ public enum FirstJoinSkinProvider {
|
||||
@SerializedName(value = "MOJANG", alternate = {"mojang"})
|
||||
MOJANG(MojangSkinProvider.PROVIDER_NAME),
|
||||
@SerializedName(value = "ELY.BY", alternate = {"ely.by", "ELY_BY", "ely_by"})
|
||||
ELY_BY(ElyBySkinProvider.PROVIDER_NAME);
|
||||
ELY_BY(ElyBySkinProvider.PROVIDER_NAME),
|
||||
@SerializedName(value = "COLLECTION", alternate = {"collection"})
|
||||
COLLECTION(CollectionSkinProvider.PROVIDER_NAME);
|
||||
|
||||
private final String name;
|
||||
|
||||
|
||||
@@ -8,8 +8,13 @@ public abstract class BuiltInProviderConfig implements GsonPostProcessable {
|
||||
protected String name;
|
||||
protected CacheConfig cache;
|
||||
|
||||
|
||||
public BuiltInProviderConfig(String name, CacheConfig cache) {
|
||||
this.enabled = true;
|
||||
this(name, cache, true);
|
||||
}
|
||||
|
||||
public BuiltInProviderConfig(String name, CacheConfig cache, boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
this.name = name;
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
@@ -1,23 +1,27 @@
|
||||
package net.lionarius.skinrestorer.config.provider;
|
||||
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.config.provider.collection.CollectionProviderConfig;
|
||||
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||
|
||||
public final class ProvidersConfig implements GsonPostProcessable {
|
||||
public static final ProvidersConfig DEFAULT = new ProvidersConfig(
|
||||
new MojangProviderConfig(),
|
||||
new ElyByProviderConfig(),
|
||||
new MineskinProviderConfig()
|
||||
new MineskinProviderConfig(),
|
||||
new CollectionProviderConfig()
|
||||
);
|
||||
|
||||
private MojangProviderConfig mojang;
|
||||
private ElyByProviderConfig ely_by;
|
||||
private MineskinProviderConfig mineskin;
|
||||
private CollectionProviderConfig collection;
|
||||
|
||||
public ProvidersConfig(MojangProviderConfig mojang, ElyByProviderConfig ely_by, MineskinProviderConfig mineskin) {
|
||||
public ProvidersConfig(MojangProviderConfig mojang, ElyByProviderConfig ely_by, MineskinProviderConfig mineskin, CollectionProviderConfig collection) {
|
||||
this.mojang = mojang;
|
||||
this.ely_by = ely_by;
|
||||
this.mineskin = mineskin;
|
||||
this.collection = collection;
|
||||
}
|
||||
|
||||
public MojangProviderConfig mojang() {
|
||||
@@ -32,6 +36,10 @@ public final class ProvidersConfig implements GsonPostProcessable {
|
||||
return this.mineskin;
|
||||
}
|
||||
|
||||
public CollectionProviderConfig collection() {
|
||||
return this.collection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gsonPostProcess() {
|
||||
if (this.mojang == null) {
|
||||
@@ -48,5 +56,10 @@ public final class ProvidersConfig implements GsonPostProcessable {
|
||||
SkinRestorer.LOGGER.warn("Mineskin provider config is null, using default");
|
||||
this.mineskin = ProvidersConfig.DEFAULT.mineskin();
|
||||
}
|
||||
|
||||
if (this.collection == null) {
|
||||
SkinRestorer.LOGGER.warn("Collection provider config is null, using default");
|
||||
this.collection = ProvidersConfig.DEFAULT.collection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.lionarius.skinrestorer.config.provider.collection;
|
||||
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
import net.lionarius.skinrestorer.config.provider.BuiltInProviderConfig;
|
||||
import net.lionarius.skinrestorer.config.provider.CacheConfig;
|
||||
import net.lionarius.skinrestorer.skin.provider.CollectionSkinProvider;
|
||||
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class CollectionProviderConfig extends BuiltInProviderConfig implements GsonPostProcessable {
|
||||
private static final CacheConfig DEFAULT_CACHE_VALUE = new CacheConfig(true, 604800);
|
||||
|
||||
@JsonAdapter(CollectionSkinSourceListDeserializer.class)
|
||||
private List<CollectionSkinSource> sources = new ArrayList<>();
|
||||
|
||||
public CollectionProviderConfig() {
|
||||
super(CollectionSkinProvider.PROVIDER_NAME, DEFAULT_CACHE_VALUE, false);
|
||||
}
|
||||
|
||||
public List<CollectionSkinSource> sources() {
|
||||
return this.sources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gsonPostProcess() {
|
||||
if (this.sources == null) {
|
||||
this.sources = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package net.lionarius.skinrestorer.config.provider.collection;
|
||||
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public final class CollectionSkinFile implements CollectionSkinSource, GsonPostProcessable {
|
||||
private String path = "";
|
||||
private SkinVariant variant = SkinVariant.CLASSIC;
|
||||
|
||||
@Override
|
||||
public @Nullable URI uri() {
|
||||
if (this.path.isEmpty())
|
||||
return null;
|
||||
|
||||
try {
|
||||
var filePath = SkinRestorer.getConfigDir().resolve(this.path);
|
||||
|
||||
if (!Files.exists(filePath)) {
|
||||
SkinRestorer.LOGGER.warn("Skin file does not exist: {}", this.path);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!Files.isRegularFile(filePath)) {
|
||||
SkinRestorer.LOGGER.warn("Skin path is not a file: {}", this.path);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!this.path.toLowerCase().endsWith(".png")) {
|
||||
SkinRestorer.LOGGER.warn("Skin file is not a PNG file: {}", this.path);
|
||||
return null;
|
||||
}
|
||||
|
||||
return filePath.toUri();
|
||||
} catch (Exception e) {
|
||||
SkinRestorer.LOGGER.warn("Invalid file path: {}", this.path, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SkinVariant variant() {
|
||||
return this.variant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gsonPostProcess() {
|
||||
if (this.path == null) {
|
||||
this.path = "";
|
||||
}
|
||||
if (this.variant == null) {
|
||||
this.variant = SkinVariant.CLASSIC;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.lionarius.skinrestorer.config.provider.collection;
|
||||
|
||||
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public interface CollectionSkinSource {
|
||||
@Nullable URI uri();
|
||||
|
||||
SkinVariant variant();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package net.lionarius.skinrestorer.config.provider.collection;
|
||||
|
||||
import com.google.gson.*;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CollectionSkinSourceListDeserializer implements JsonSerializer<List<CollectionSkinSource>>, JsonDeserializer<List<CollectionSkinSource>> {
|
||||
@Override
|
||||
public JsonElement serialize(List<CollectionSkinSource> src, Type typeOfT, JsonSerializationContext context) {
|
||||
return context.serialize(src, List.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CollectionSkinSource> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
List<CollectionSkinSource> sources = new ArrayList<>();
|
||||
|
||||
if (json.isJsonArray()) {
|
||||
for (JsonElement element : json.getAsJsonArray()) {
|
||||
if (element.isJsonObject()) {
|
||||
JsonObject obj = element.getAsJsonObject();
|
||||
if (obj.has("url")) {
|
||||
sources.add(context.deserialize(obj, CollectionSkinUrl.class));
|
||||
} else if (obj.has("path")) {
|
||||
sources.add(context.deserialize(obj, CollectionSkinFile.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sources;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.lionarius.skinrestorer.config.provider.collection;
|
||||
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public final class CollectionSkinUrl implements CollectionSkinSource, GsonPostProcessable {
|
||||
private String url = "";
|
||||
private SkinVariant variant = SkinVariant.CLASSIC;
|
||||
|
||||
@Override
|
||||
public @Nullable URI uri() {
|
||||
try {
|
||||
if (this.url.isEmpty())
|
||||
return null;
|
||||
|
||||
return new URI(this.url);
|
||||
} catch (Exception e) {
|
||||
SkinRestorer.LOGGER.warn("Invalid URI: {}", this.url, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SkinVariant variant() {
|
||||
return this.variant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gsonPostProcess() {
|
||||
if (this.url == null) {
|
||||
this.url = "";
|
||||
}
|
||||
if (this.variant == null) {
|
||||
this.variant = SkinVariant.CLASSIC;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,5 +9,5 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
public interface ChunkMapAccessor {
|
||||
|
||||
@Accessor
|
||||
Int2ObjectMap<Object> getEntityMap();
|
||||
Int2ObjectMap<TrackedEntityAccessorInvoker> getEntityMap();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
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();
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package net.lionarius.skinrestorer.mixin;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.config.FirstJoinSkinProvider;
|
||||
import net.lionarius.skinrestorer.skin.SkinValue;
|
||||
import net.lionarius.skinrestorer.skin.provider.SkinProviderContext;
|
||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||
@@ -57,9 +58,15 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (originalSkin == null && SkinRestorer.getConfig().fetchSkinOnFirstJoin()) {
|
||||
var config = SkinRestorer.getConfig();
|
||||
var provider = config.firstJoinSkinProvider();
|
||||
|
||||
var shouldFetch = (originalSkin == null && config.fetchSkinOnFirstJoin()) ||
|
||||
(originalSkin != null && config.forceFirstJoinSkinFetch() && provider != FirstJoinSkinProvider.MOJANG);
|
||||
|
||||
if (shouldFetch) {
|
||||
var context = new SkinProviderContext(
|
||||
SkinRestorer.getConfig().firstJoinSkinProvider().getName(),
|
||||
provider.getName(),
|
||||
profile.getName(),
|
||||
null
|
||||
);
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -30,7 +31,11 @@ public abstract class SkullBlockEntityMixin {
|
||||
if (profile == null || profile.isComplete() || profile.getName() == null)
|
||||
return;
|
||||
|
||||
var profileOpt = profileCache.get(profile.getName());
|
||||
var profileOpt = Optional.<GameProfile>empty();
|
||||
var gameProfileInfo = ((GameProfileCacheAccessor) profileCache).getProfilesByName().get(profile.getName().toLowerCase(Locale.ROOT));
|
||||
|
||||
if (gameProfileInfo != null)
|
||||
profileOpt = Optional.of(gameProfileInfo.getProfile());
|
||||
|
||||
skinrestorer$replaceSkin(profileOpt, profileConsumer, ci);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
package net.lionarius.skinrestorer.platform.services;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public interface CompatibilityHelper {
|
||||
|
||||
void skinShuffle_sendHandshake(ServerPlayer player);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package net.lionarius.skinrestorer.skin;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public enum SkinVariant {
|
||||
|
||||
@SerializedName(value = "classic", alternate = {"CLASSIC"})
|
||||
CLASSIC("classic"),
|
||||
@SerializedName(value = "slim", alternate = {"SLIM"})
|
||||
SLIM("slim");
|
||||
|
||||
private final String name;
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package net.lionarius.skinrestorer.skin.provider;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import it.unimi.dsi.fastutil.Pair;
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.config.provider.collection.CollectionSkinSource;
|
||||
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||
import net.lionarius.skinrestorer.util.Result;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class CollectionSkinProvider implements SkinProvider {
|
||||
|
||||
public static final String PROVIDER_NAME = "collection";
|
||||
|
||||
private static LoadingCache<Integer, Optional<Property>> SKIN_CACHE;
|
||||
|
||||
private static List<Pair<URI, SkinVariant>> COLLECTION_SKINS;
|
||||
|
||||
public static void reload() {
|
||||
COLLECTION_SKINS = loadCollectionSkins();
|
||||
|
||||
createCache();
|
||||
}
|
||||
|
||||
private static List<Pair<URI, SkinVariant>> loadCollectionSkins() {
|
||||
List<Pair<URI, SkinVariant>> skins = new ArrayList<>();
|
||||
|
||||
var config = SkinRestorer.getConfig().providersConfig().collection();
|
||||
|
||||
for (CollectionSkinSource source : config.sources()) {
|
||||
var uri = source.uri();
|
||||
if (uri != null) {
|
||||
skins.add(Pair.of(uri, source.variant()));
|
||||
}
|
||||
}
|
||||
|
||||
return skins;
|
||||
}
|
||||
|
||||
private static void createCache() {
|
||||
var config = SkinRestorer.getConfig().providersConfig().collection();
|
||||
var time = config.cache().enabled() ? config.cache().duration() : 0;
|
||||
|
||||
SKIN_CACHE = CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(time, TimeUnit.SECONDS)
|
||||
.build(new CacheLoader<>() {
|
||||
@Override
|
||||
public @NotNull Optional<Property> load(@NotNull Integer key) throws Exception {
|
||||
var skinEntry = COLLECTION_SKINS.get(key);
|
||||
return MineskinSkinProvider.loadSkin(skinEntry.first(), skinEntry.second());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArgumentName() {
|
||||
return "seed";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasVariantSupport() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Optional<Property>, Exception> fetchSkin(String argument, SkinVariant variant) {
|
||||
if (COLLECTION_SKINS.isEmpty()) {
|
||||
return Result.error(new IllegalStateException("No collection skins configured"));
|
||||
}
|
||||
|
||||
var skinIndex = Math.abs(argument.hashCode()) % COLLECTION_SKINS.size();
|
||||
|
||||
try {
|
||||
return Result.success(SKIN_CACHE.get(skinIndex));
|
||||
} catch (UncheckedExecutionException e) {
|
||||
return Result.error((Exception) e.getCause());
|
||||
} catch (Exception e) {
|
||||
return Result.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@ import org.mineskin.response.QueueResponse;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -94,13 +96,18 @@ public final class MineskinSkinProvider implements SkinProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private static Optional<Property> loadSkin(URI uri, SkinVariant variant) throws Exception {
|
||||
static Optional<Property> loadSkin(URI uri, SkinVariant variant) throws Exception {
|
||||
var mineskinVariant = switch (variant) {
|
||||
case CLASSIC -> Variant.CLASSIC;
|
||||
case SLIM -> Variant.SLIM;
|
||||
};
|
||||
|
||||
var request = GenerateRequest.url(uri)
|
||||
var request = "file".equals(uri.getScheme())
|
||||
? GenerateRequest.upload(Files.newInputStream(Path.of(uri)))
|
||||
.variant(mineskinVariant)
|
||||
.name("skinrestorer-skin")
|
||||
.visibility(Visibility.UNLISTED)
|
||||
: GenerateRequest.url(uri)
|
||||
.variant(mineskinVariant)
|
||||
.name("skinrestorer-skin")
|
||||
.visibility(Visibility.UNLISTED);
|
||||
|
||||
@@ -13,6 +13,7 @@ public interface SkinProvider {
|
||||
MojangSkinProvider MOJANG = new MojangSkinProvider();
|
||||
ElyBySkinProvider ELY_BY = new ElyBySkinProvider();
|
||||
MineskinSkinProvider MINESKIN = new MineskinSkinProvider();
|
||||
CollectionSkinProvider COLLECTION = new CollectionSkinProvider();
|
||||
SkinShuffleSkinProvider SKIN_SHUFFLE = new SkinShuffleSkinProvider();
|
||||
|
||||
Set<String> BUILTIN_PROVIDER_NAMES = ImmutableSet.of(
|
||||
@@ -20,6 +21,7 @@ public interface SkinProvider {
|
||||
MojangSkinProvider.PROVIDER_NAME,
|
||||
ElyBySkinProvider.PROVIDER_NAME,
|
||||
MineskinSkinProvider.PROVIDER_NAME,
|
||||
CollectionSkinProvider.PROVIDER_NAME,
|
||||
SkinShuffleSkinProvider.PROVIDER_NAME
|
||||
);
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
||||
import net.lionarius.skinrestorer.mixin.ChunkMapAccessor;
|
||||
import net.lionarius.skinrestorer.mixin.TrackedEntityAccessorInvoker;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.*;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
@@ -40,25 +39,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 ClientboundPlayerInfoRemovePacket(List.of(player.getUUID())));
|
||||
playerList.broadcastAll(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(Collections.singleton(player)));
|
||||
|
||||
var trackedEntity = (TrackedEntityAccessorInvoker) ((ChunkMapAccessor) chunkMap).getEntityMap().get(player.getId());
|
||||
var trackedEntity = ((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 = (TrackedEntityAccessorInvoker) ((ChunkMapAccessor) chunkMap).getEntityMap().get(observer.getId());
|
||||
var trackedObserverEntity = ((ChunkMapAccessor) chunkMap).getEntityMap().get(observer.getId());
|
||||
if (trackedObserverEntity != null) {
|
||||
trackedObserverEntity.invokeRemovePlayer(player);
|
||||
trackedObserverEntity.invokeUpdatePlayer(player);
|
||||
@@ -70,16 +65,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(),
|
||||
player.getLevel().isDebug(),
|
||||
player.getLevel().isFlat(),
|
||||
(byte) 3,
|
||||
player.getLastDeathLocation(),
|
||||
player.getPortalCooldown()
|
||||
player.getLastDeathLocation()
|
||||
)
|
||||
);
|
||||
player.connection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
|
||||
|
||||
1
common/src/main/resources/META-INF/accesstransformer.cfg
Normal file
1
common/src/main/resources/META-INF/accesstransformer.cfg
Normal file
@@ -0,0 +1 @@
|
||||
public net.minecraft.server.players.GameProfileCache$GameProfileInfo
|
||||
3
common/src/main/resources/skinrestorer.accesswidener
Normal file
3
common/src/main/resources/skinrestorer.accesswidener
Normal file
@@ -0,0 +1,3 @@
|
||||
accessWidener v2 named
|
||||
|
||||
accessible class net/minecraft/server/players/GameProfileCache$GameProfileInfo
|
||||
@@ -10,7 +10,8 @@
|
||||
"PlayerListMixin",
|
||||
"ServerLoginPacketListenerImplMixin",
|
||||
"TrackedEntityAccessorInvoker",
|
||||
"SkullBlockEntityMixin"
|
||||
"SkullBlockEntityMixin",
|
||||
"GameProfileCacheAccessor"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
@@ -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}")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# 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
|
||||
additional_modloaders=quilt
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -15,4 +15,10 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,12 +24,10 @@
|
||||
"${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": "*"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ minecraft {
|
||||
// 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,3 +88,7 @@ sourceSets.each {
|
||||
it.output.resourcesDir = dir
|
||||
it.java.destinationDirectory = dir
|
||||
}
|
||||
|
||||
tasks.named('processResources') {
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
}
|
||||
|
||||
@@ -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=44.0.0
|
||||
forge_loader_version_range=[44,)
|
||||
# Forge sometimes skips minor minecraft versions (like 1.20.5)
|
||||
forge_minecraft_version=1.20
|
||||
forge_minecraft_version=1.19.3
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
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;
|
||||
|
||||
@@ -13,9 +13,6 @@ public final class SkinRestorerForge {
|
||||
|
||||
public SkinRestorerForge() {
|
||||
SkinRestorer.onInitialize();
|
||||
|
||||
if (SkinShuffleCompatibility.shouldApply())
|
||||
net.lionarius.skinrestorer.forge.compat.skinshuffle.SkinShuffleCompatibility.initialize();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
@@ -27,4 +24,9 @@ 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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.3
|
||||
minecraft_version_list=1.19.3
|
||||
minecraft_version_range=[1.19.3,1.19.4)
|
||||
mod_id=skinrestorer
|
||||
mod_name=SkinRestorer
|
||||
mod_version=2.4.2
|
||||
mod_version=2.5.0
|
||||
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.2.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.3
|
||||
parchment_version=2023.06.25
|
||||
|
||||
# Publishing
|
||||
curseforge_id=443823
|
||||
|
||||
@@ -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()) {
|
||||
minecraft.accessTransformers.file(at)
|
||||
accessTransformers.from(at.absolutePath)
|
||||
}
|
||||
|
||||
parchment {
|
||||
|
||||
@@ -6,6 +6,7 @@ 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)
|
||||
@@ -27,4 +28,9 @@ 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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user