mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
Compare commits
71 Commits
da754aa830
...
1.20.5-mul
| Author | SHA1 | Date | |
|---|---|---|---|
|
3c2269ca6e
|
|||
|
4cf35048b0
|
|||
|
965af68461
|
|||
|
8fba8a997e
|
|||
|
a0d8f3d518
|
|||
|
aa3cb3df09
|
|||
|
0524b5dab8
|
|||
|
301428147d
|
|||
|
2e655ce1f3
|
|||
|
7dcd1d4e81
|
|||
|
1aa606038e
|
|||
|
e832e02fd4
|
|||
|
ffd2a0dba7
|
|||
|
76e801c944
|
|||
|
b5bed1c441
|
|||
|
e6b2dcb4eb
|
|||
|
5f8a868e5c
|
|||
|
fce13237f9
|
|||
|
c987d48738
|
|||
|
d54cb48697
|
|||
|
6df0cf4fd2
|
|||
|
2cec50afae
|
|||
|
05ef681621
|
|||
|
daf0310072
|
|||
|
a3bd44af89
|
|||
|
742b4cb4d0
|
|||
|
1bacee4b22
|
|||
|
4a87bd43ca
|
|||
|
fb644adbc3
|
|||
|
b4e76576c2
|
|||
|
556ecdc039
|
|||
|
ba6dc5a1e5
|
|||
|
b0333b4b7f
|
|||
|
21f00231af
|
|||
|
6f5b291008
|
|||
|
dc0d69f0f0
|
|||
|
53e0740e43
|
|||
|
ef247f1ad3
|
|||
|
1eff73e9b3
|
|||
|
3d92617e47
|
|||
|
f357e6c985
|
|||
|
50a49b33a2
|
|||
|
8de7f3a16f
|
|||
|
0feba3f4b2
|
|||
|
fcd76d9a87
|
|||
|
4b30b8b53d
|
|||
|
0921cf70bf
|
|||
|
c2afd37fae
|
|||
|
e0b1de4ae2
|
|||
|
e1a58f4246
|
|||
|
496c8d8078
|
|||
|
0070d3ab1c
|
|||
|
7ec929335b
|
|||
|
7ab9f722e8
|
|||
|
5c2a50fd98
|
|||
|
ef79818d5c
|
|||
|
0d4a0034b8
|
|||
|
d85942041b
|
|||
|
1cafc91935
|
|||
|
5d28269b94
|
|||
|
2293fc2399
|
|||
|
3971f2efbf
|
|||
|
08e7f1792b
|
|||
|
592a6ac253
|
|||
|
03dad0f8dc
|
|||
|
dda9a9632a
|
|||
|
b0d95a4d4f
|
|||
|
c650aa1386
|
|||
|
7add58da44
|
|||
|
49290171e2
|
|||
|
b72d0c1e85
|
@@ -4,6 +4,11 @@ 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/),
|
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).
|
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
|
## [2.4.3] - 2025-07-25
|
||||||
### Fixed
|
### 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 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))
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
### Fixed
|
### Added
|
||||||
- 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))
|
- Added collection skin provider (allows assigning random skins from a predefined set) (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Configuration#providerscollection))
|
||||||
- Fixed server freeze when loading player head skin
|
- 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))
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
// see https://fabricmc.net/develop/ for new versions
|
// see https://fabricmc.net/develop/ for new versions
|
||||||
id 'fabric-loom' version '1.11-SNAPSHOT' apply false
|
id 'fabric-loom' version '1.10-SNAPSHOT' apply false
|
||||||
// see https://projects.neoforged.net/neoforged/moddevgradle for new versions
|
// see https://projects.neoforged.net/neoforged/moddevgradle for new versions
|
||||||
id 'net.neoforged.moddev' version '2.0.+' apply false
|
id 'net.neoforged.moddev' version '2.0.+' apply false
|
||||||
// see https://files.minecraftforge.net/net/minecraftforge/gradle/ForgeGradle/ for new versions
|
// see https://files.minecraftforge.net/net/minecraftforge/gradle/ForgeGradle/ for new versions
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package net.lionarius.skinrestorer;
|
package net.lionarius.skinrestorer;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import net.lionarius.skinrestorer.command.SkinCommand;
|
import net.lionarius.skinrestorer.command.SkinCommand;
|
||||||
import net.lionarius.skinrestorer.config.Config;
|
import net.lionarius.skinrestorer.config.Config;
|
||||||
import net.lionarius.skinrestorer.config.provider.BuiltInProviderConfig;
|
import net.lionarius.skinrestorer.config.provider.BuiltInProviderConfig;
|
||||||
import net.lionarius.skinrestorer.exception.TransparentException;
|
import net.lionarius.skinrestorer.exception.TransparentException;
|
||||||
import net.lionarius.skinrestorer.mixin.PlayerAccessor;
|
|
||||||
import net.lionarius.skinrestorer.platform.Services;
|
import net.lionarius.skinrestorer.platform.Services;
|
||||||
import net.lionarius.skinrestorer.skin.SkinIO;
|
import net.lionarius.skinrestorer.skin.SkinIO;
|
||||||
import net.lionarius.skinrestorer.skin.SkinStorage;
|
import net.lionarius.skinrestorer.skin.SkinStorage;
|
||||||
@@ -71,7 +71,7 @@ public final class SkinRestorer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ResourceLocation resourceLocation(String name) {
|
public static ResourceLocation resourceLocation(String name) {
|
||||||
return ResourceLocation.fromNamespaceAndPath(SkinRestorer.MOD_ID, name);
|
return new ResourceLocation(SkinRestorer.MOD_ID, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String assetPath(String name) {
|
public static String assetPath(String name) {
|
||||||
@@ -88,6 +88,7 @@ public final class SkinRestorer {
|
|||||||
SkinRestorer.registerDefaultSkinProvider(MojangSkinProvider.PROVIDER_NAME, SkinProvider.MOJANG, SkinRestorer.getConfig().providersConfig().mojang());
|
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(ElyBySkinProvider.PROVIDER_NAME, SkinProvider.ELY_BY, SkinRestorer.getConfig().providersConfig().ely_by());
|
||||||
SkinRestorer.registerDefaultSkinProvider(MineskinSkinProvider.PROVIDER_NAME, SkinProvider.MINESKIN, SkinRestorer.getConfig().providersConfig().mineskin());
|
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) {
|
private static void registerDefaultSkinProvider(String defaultName, SkinProvider provider, BuiltInProviderConfig config) {
|
||||||
@@ -106,28 +107,26 @@ public final class SkinRestorer {
|
|||||||
MojangSkinProvider.reload();
|
MojangSkinProvider.reload();
|
||||||
ElyBySkinProvider.reload();
|
ElyBySkinProvider.reload();
|
||||||
MineskinSkinProvider.reload();
|
MineskinSkinProvider.reload();
|
||||||
|
CollectionSkinProvider.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<ServerPlayer> targets, SkinValue value, boolean save) {
|
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<GameProfile> targets, SkinValue value, boolean save) {
|
||||||
var acceptedPlayers = new HashSet<ServerPlayer>();
|
var acceptedPlayers = new HashSet<ServerPlayer>();
|
||||||
|
|
||||||
for (var player : targets) {
|
for (var profile : targets) {
|
||||||
var profile = player.getGameProfile();
|
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId()))
|
||||||
var skin = PlayerUtils.getPlayerSkin(profile);
|
value = value.setOriginalValue(PlayerUtils.getPlayerSkin(profile));
|
||||||
|
|
||||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.id()))
|
if (PlayerUtils.areSkinPropertiesEquals(value.value(), PlayerUtils.getPlayerSkin(profile)))
|
||||||
value = value.setOriginalValue(skin);
|
|
||||||
|
|
||||||
if (PlayerUtils.areSkinPropertiesEquals(value.value(), skin))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (save)
|
if (save)
|
||||||
SkinRestorer.getSkinStorage().setSkin(profile.id(), value);
|
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value);
|
||||||
|
|
||||||
var newProfile = PlayerUtils.applyRestoredSkin(profile, value.value());
|
PlayerUtils.applyRestoredSkin(profile, value.value());
|
||||||
((PlayerAccessor) player).setGameProfile(newProfile);
|
|
||||||
|
|
||||||
if (player.connection == null)
|
var player = server.getPlayerList().getPlayer(profile.getId());
|
||||||
|
if (player == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
PlayerUtils.refreshPlayer(player);
|
PlayerUtils.refreshPlayer(player);
|
||||||
@@ -139,13 +138,13 @@ public final class SkinRestorer {
|
|||||||
return acceptedPlayers;
|
return acceptedPlayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<ServerPlayer> targets, SkinValue value) {
|
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<GameProfile> targets, SkinValue value) {
|
||||||
return SkinRestorer.applySkin(server, targets, value, true);
|
return SkinRestorer.applySkin(server, targets, value, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CompletableFuture<Result<Collection<ServerPlayer>, String>> setSkinAsync(
|
public static CompletableFuture<Result<Collection<ServerPlayer>, String>> setSkinAsync(
|
||||||
MinecraftServer server,
|
MinecraftServer server,
|
||||||
Collection<ServerPlayer> targets,
|
Collection<GameProfile> targets,
|
||||||
SkinProviderContext context,
|
SkinProviderContext context,
|
||||||
boolean save
|
boolean save
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.lionarius.skinrestorer.command;
|
package net.lionarius.skinrestorer.command;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||||
@@ -17,12 +18,10 @@ import net.lionarius.skinrestorer.util.PlayerUtils;
|
|||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.arguments.GameProfileArgument;
|
import net.minecraft.commands.arguments.GameProfileArgument;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.server.players.NameAndId;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
@@ -73,41 +72,37 @@ public final class SkinCommand {
|
|||||||
|
|
||||||
SkinProviderContext context = null;
|
SkinProviderContext context = null;
|
||||||
var save = true;
|
var save = true;
|
||||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.id())) {
|
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId())) {
|
||||||
if (profile.properties().containsKey(PlayerUtils.TEXTURES_KEY)) {
|
if (profile.getProperties().containsKey(PlayerUtils.TEXTURES_KEY)) {
|
||||||
save = false;
|
save = false;
|
||||||
context = MojangSkinProvider.skinProviderContextFromProfile(profile);
|
context = MojangSkinProvider.skinProviderContextFromProfile(profile);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
context = SkinRestorer.getSkinStorage().getSkin(profile.id()).toProviderContext();
|
context = SkinRestorer.getSkinStorage().getSkin(profile.getId()).toProviderContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context == null)
|
if (context == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return SkinCommand.setSubcommand(src, Collections.singleton(new NameAndId(profile)), context, save, false);
|
return SkinCommand.setSubcommand(src, Collections.singleton(profile), context, save, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int resetSubcommand(
|
private static int resetSubcommand(
|
||||||
CommandSourceStack src,
|
CommandSourceStack src,
|
||||||
Collection<NameAndId> targets,
|
Collection<GameProfile> targets,
|
||||||
boolean setByOperator
|
boolean setByOperator
|
||||||
) {
|
) {
|
||||||
var updatedPlayers = new HashSet<ServerPlayer>();
|
var updatedPlayers = new HashSet<ServerPlayer>();
|
||||||
for (var nameAndId : targets) {
|
for (var profile : targets) {
|
||||||
SkinValue skin = null;
|
SkinValue skin = null;
|
||||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(nameAndId.id()))
|
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId()))
|
||||||
skin = SkinRestorer.getSkinStorage().getSkin(nameAndId.id()).replaceValueWithOriginal();
|
skin = SkinRestorer.getSkinStorage().getSkin(profile.getId()).replaceValueWithOriginal();
|
||||||
|
|
||||||
if (skin == null)
|
if (skin == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var player = src.getServer().getPlayerList().getPlayer(nameAndId.id());
|
var updatedPlayer = SkinRestorer.applySkin(src.getServer(), Collections.singleton(profile), skin, false);
|
||||||
if (player == null)
|
SkinRestorer.getSkinStorage().deleteSkin(profile.getId());
|
||||||
continue;
|
|
||||||
|
|
||||||
var updatedPlayer = SkinRestorer.applySkin(src.getServer(), Collections.singleton(player), skin, false);
|
|
||||||
SkinRestorer.getSkinStorage().deleteSkin(nameAndId.id());
|
|
||||||
|
|
||||||
updatedPlayers.addAll(updatedPlayer);
|
updatedPlayers.addAll(updatedPlayer);
|
||||||
}
|
}
|
||||||
@@ -123,24 +118,19 @@ public final class SkinCommand {
|
|||||||
if (src.getPlayer() == null)
|
if (src.getPlayer() == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return resetSubcommand(src, Collections.singleton(src.getPlayer().nameAndId()), false);
|
return resetSubcommand(src, Collections.singleton(src.getPlayer().getGameProfile()), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int setSubcommand(
|
private static int setSubcommand(
|
||||||
CommandSourceStack src,
|
CommandSourceStack src,
|
||||||
Collection<NameAndId> targets,
|
Collection<GameProfile> targets,
|
||||||
SkinProviderContext context,
|
SkinProviderContext context,
|
||||||
boolean save,
|
boolean save,
|
||||||
boolean setByOperator
|
boolean setByOperator
|
||||||
) {
|
) {
|
||||||
src.sendSystemMessage(Translation.translatableWithFallback(Translation.COMMAND_SKIN_LOADING_KEY));
|
src.sendSystemMessage(Translation.translatableWithFallback(Translation.COMMAND_SKIN_LOADING_KEY));
|
||||||
|
|
||||||
var profileTargets = targets.stream()
|
SkinRestorer.setSkinAsync(src.getServer(), targets, context, save).thenAccept(result -> {
|
||||||
.map(nameAndId -> src.getServer().getPlayerList().getPlayer(nameAndId.id()))
|
|
||||||
.filter(Objects::nonNull)
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
SkinRestorer.setSkinAsync(src.getServer(), profileTargets, context, save).thenAccept(result -> {
|
|
||||||
if (result.isError()) {
|
if (result.isError()) {
|
||||||
src.sendFailure(Translation.translatableWithFallback(
|
src.sendFailure(Translation.translatableWithFallback(
|
||||||
Translation.COMMAND_SKIN_FAILED_KEY,
|
Translation.COMMAND_SKIN_FAILED_KEY,
|
||||||
@@ -159,7 +149,7 @@ public final class SkinCommand {
|
|||||||
|
|
||||||
private static int setSubcommand(
|
private static int setSubcommand(
|
||||||
CommandSourceStack src,
|
CommandSourceStack src,
|
||||||
Collection<NameAndId> targets,
|
Collection<GameProfile> targets,
|
||||||
SkinProviderContext context,
|
SkinProviderContext context,
|
||||||
boolean setByOperator
|
boolean setByOperator
|
||||||
) {
|
) {
|
||||||
@@ -173,7 +163,7 @@ public final class SkinCommand {
|
|||||||
if (src.getPlayer() == null)
|
if (src.getPlayer() == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return setSubcommand(src, Collections.singleton(src.getPlayer().nameAndId()), context, false);
|
return setSubcommand(src, Collections.singleton(src.getPlayer().getGameProfile()), context, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int configReloadSubcommand(CommandContext<CommandSourceStack> context) {
|
private static int configReloadSubcommand(CommandContext<CommandSourceStack> context) {
|
||||||
@@ -266,7 +256,7 @@ public final class SkinCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static RequiredArgumentBuilder<CommandSourceStack, GameProfileArgument.Result> makeTargetsArgument(
|
private static RequiredArgumentBuilder<CommandSourceStack, GameProfileArgument.Result> makeTargetsArgument(
|
||||||
BiFunction<CommandContext<CommandSourceStack>, Collection<NameAndId>, Integer> consumer
|
BiFunction<CommandContext<CommandSourceStack>, Collection<GameProfile>, Integer> consumer
|
||||||
) {
|
) {
|
||||||
return argument("targets", GameProfileArgument.gameProfile())
|
return argument("targets", GameProfileArgument.gameProfile())
|
||||||
.requires(source -> source.hasPermission(2))
|
.requires(source -> source.hasPermission(2))
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class SkinShuffleCompatibility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ResourceLocation resourceLocation(String name) {
|
public static ResourceLocation resourceLocation(String name) {
|
||||||
return ResourceLocation.fromNamespaceAndPath(SkinShuffleCompatibility.MOD_ID, name);
|
return new ResourceLocation(SkinShuffleCompatibility.MOD_ID, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onPlayerJoin(ServerPlayer player) {
|
public static void onPlayerJoin(ServerPlayer player) {
|
||||||
@@ -43,7 +43,7 @@ public class SkinShuffleCompatibility {
|
|||||||
server.execute(() -> {
|
server.execute(() -> {
|
||||||
SkinRestorer.applySkin(
|
SkinRestorer.applySkin(
|
||||||
server,
|
server,
|
||||||
Collections.singleton(player),
|
Collections.singleton(player.getGameProfile()),
|
||||||
new SkinValue(SkinShuffleSkinProvider.PROVIDER_NAME, null, null, property),
|
new SkinValue(SkinShuffleSkinProvider.PROVIDER_NAME, null, null, property),
|
||||||
!server.usesAuthentication()
|
!server.usesAuthentication()
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ public final class Config implements GsonPostProcessable {
|
|||||||
|
|
||||||
private boolean fetchSkinOnFirstJoin = true;
|
private boolean fetchSkinOnFirstJoin = true;
|
||||||
|
|
||||||
|
private boolean forceFirstJoinSkinFetch = false;
|
||||||
|
|
||||||
private FirstJoinSkinProvider firstJoinSkinProvider = FirstJoinSkinProvider.MOJANG;
|
private FirstJoinSkinProvider firstJoinSkinProvider = FirstJoinSkinProvider.MOJANG;
|
||||||
|
|
||||||
private String proxy = "";
|
private String proxy = "";
|
||||||
@@ -47,6 +49,10 @@ public final class Config implements GsonPostProcessable {
|
|||||||
return this.fetchSkinOnFirstJoin;
|
return this.fetchSkinOnFirstJoin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean forceFirstJoinSkinFetch() {
|
||||||
|
return this.forceFirstJoinSkinFetch;
|
||||||
|
}
|
||||||
|
|
||||||
public FirstJoinSkinProvider firstJoinSkinProvider() {
|
public FirstJoinSkinProvider firstJoinSkinProvider() {
|
||||||
return this.firstJoinSkinProvider;
|
return this.firstJoinSkinProvider;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.lionarius.skinrestorer.config;
|
package net.lionarius.skinrestorer.config;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
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.ElyBySkinProvider;
|
||||||
import net.lionarius.skinrestorer.skin.provider.MojangSkinProvider;
|
import net.lionarius.skinrestorer.skin.provider.MojangSkinProvider;
|
||||||
|
|
||||||
@@ -8,7 +9,9 @@ public enum FirstJoinSkinProvider {
|
|||||||
@SerializedName(value = "MOJANG", alternate = {"mojang"})
|
@SerializedName(value = "MOJANG", alternate = {"mojang"})
|
||||||
MOJANG(MojangSkinProvider.PROVIDER_NAME),
|
MOJANG(MojangSkinProvider.PROVIDER_NAME),
|
||||||
@SerializedName(value = "ELY.BY", alternate = {"ely.by", "ELY_BY", "ely_by"})
|
@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;
|
private final String name;
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,13 @@ public abstract class BuiltInProviderConfig implements GsonPostProcessable {
|
|||||||
protected String name;
|
protected String name;
|
||||||
protected CacheConfig cache;
|
protected CacheConfig cache;
|
||||||
|
|
||||||
|
|
||||||
public BuiltInProviderConfig(String name, 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.name = name;
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,27 @@
|
|||||||
package net.lionarius.skinrestorer.config.provider;
|
package net.lionarius.skinrestorer.config.provider;
|
||||||
|
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.config.provider.collection.CollectionProviderConfig;
|
||||||
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||||
|
|
||||||
public final class ProvidersConfig implements GsonPostProcessable {
|
public final class ProvidersConfig implements GsonPostProcessable {
|
||||||
public static final ProvidersConfig DEFAULT = new ProvidersConfig(
|
public static final ProvidersConfig DEFAULT = new ProvidersConfig(
|
||||||
new MojangProviderConfig(),
|
new MojangProviderConfig(),
|
||||||
new ElyByProviderConfig(),
|
new ElyByProviderConfig(),
|
||||||
new MineskinProviderConfig()
|
new MineskinProviderConfig(),
|
||||||
|
new CollectionProviderConfig()
|
||||||
);
|
);
|
||||||
|
|
||||||
private MojangProviderConfig mojang;
|
private MojangProviderConfig mojang;
|
||||||
private ElyByProviderConfig ely_by;
|
private ElyByProviderConfig ely_by;
|
||||||
private MineskinProviderConfig mineskin;
|
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.mojang = mojang;
|
||||||
this.ely_by = ely_by;
|
this.ely_by = ely_by;
|
||||||
this.mineskin = mineskin;
|
this.mineskin = mineskin;
|
||||||
|
this.collection = collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MojangProviderConfig mojang() {
|
public MojangProviderConfig mojang() {
|
||||||
@@ -32,6 +36,10 @@ public final class ProvidersConfig implements GsonPostProcessable {
|
|||||||
return this.mineskin;
|
return this.mineskin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CollectionProviderConfig collection() {
|
||||||
|
return this.collection;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void gsonPostProcess() {
|
public void gsonPostProcess() {
|
||||||
if (this.mojang == null) {
|
if (this.mojang == null) {
|
||||||
@@ -48,5 +56,10 @@ public final class ProvidersConfig implements GsonPostProcessable {
|
|||||||
SkinRestorer.LOGGER.warn("Mineskin provider config is null, using default");
|
SkinRestorer.LOGGER.warn("Mineskin provider config is null, using default");
|
||||||
this.mineskin = ProvidersConfig.DEFAULT.mineskin();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer.mixin;
|
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Mutable;
|
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
|
||||||
|
|
||||||
|
|
||||||
@Mixin(Player.class)
|
|
||||||
public interface PlayerAccessor {
|
|
||||||
@Accessor("gameProfile")
|
|
||||||
@Mutable
|
|
||||||
void setGameProfile(GameProfile properties);
|
|
||||||
}
|
|
||||||
@@ -57,6 +57,6 @@ public abstract class PlayerListMixin {
|
|||||||
@Unique
|
@Unique
|
||||||
private static void skinrestorer$tryApplySkin(MinecraftServer server, ServerPlayer player) {
|
private static void skinrestorer$tryApplySkin(MinecraftServer server, ServerPlayer player) {
|
||||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(player.getUUID()))
|
if (SkinRestorer.getSkinStorage().hasSavedSkin(player.getUUID()))
|
||||||
SkinRestorer.applySkin(server, Collections.singleton(player), SkinRestorer.getSkinStorage().getSkin(player.getUUID()));
|
SkinRestorer.applySkin(server, Collections.singleton(player.getGameProfile()), SkinRestorer.getSkinStorage().getSkin(player.getUUID()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package net.lionarius.skinrestorer.mixin;
|
|||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.config.FirstJoinSkinProvider;
|
||||||
import net.lionarius.skinrestorer.skin.SkinValue;
|
import net.lionarius.skinrestorer.skin.SkinValue;
|
||||||
import net.lionarius.skinrestorer.skin.provider.SkinProviderContext;
|
import net.lionarius.skinrestorer.skin.provider.SkinProviderContext;
|
||||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||||
@@ -27,7 +28,7 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
|||||||
private CompletableFuture<Void> skinrestorer$pendingSkin;
|
private CompletableFuture<Void> skinrestorer$pendingSkin;
|
||||||
|
|
||||||
@Inject(method = "verifyLoginAndFinishConnectionSetup", at = @At(value = "INVOKE",
|
@Inject(method = "verifyLoginAndFinishConnectionSetup", at = @At(value = "INVOKE",
|
||||||
target = "Lnet/minecraft/server/players/PlayerList;canPlayerLogin(Ljava/net/SocketAddress;Lnet/minecraft/server/players/NameAndId;)Lnet/minecraft/network/chat/Component;"),
|
target = "Lnet/minecraft/server/players/PlayerList;canPlayerLogin(Ljava/net/SocketAddress;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/network/chat/Component;"),
|
||||||
cancellable = true)
|
cancellable = true)
|
||||||
public void waitForSkin(CallbackInfo ci) {
|
public void waitForSkin(CallbackInfo ci) {
|
||||||
if (skinrestorer$pendingSkin == null) {
|
if (skinrestorer$pendingSkin == null) {
|
||||||
@@ -37,14 +38,14 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
|||||||
assert profile != null;
|
assert profile != null;
|
||||||
var originalSkin = PlayerUtils.getPlayerSkin(profile);
|
var originalSkin = PlayerUtils.getPlayerSkin(profile);
|
||||||
|
|
||||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.id())) {
|
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId())) {
|
||||||
if (originalSkin != null) { // update to the latest official skin
|
if (originalSkin != null) { // update to the latest official skin
|
||||||
var value = SkinRestorer.getSkinStorage().getSkin(profile.id());
|
var value = SkinRestorer.getSkinStorage().getSkin(profile.getId());
|
||||||
SkinRestorer.getSkinStorage().setSkin(profile.id(), value.setOriginalValue(originalSkin));
|
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value.setOriginalValue(originalSkin));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SkinRestorer.getConfig().refreshSkinOnJoin()) {
|
if (SkinRestorer.getConfig().refreshSkinOnJoin()) {
|
||||||
var currentSkin = SkinRestorer.getSkinStorage().getSkin(profile.id());
|
var currentSkin = SkinRestorer.getSkinStorage().getSkin(profile.getId());
|
||||||
var context = currentSkin.toProviderContext();
|
var context = currentSkin.toProviderContext();
|
||||||
|
|
||||||
skinrestorer$fetchSkin(profile, context);
|
skinrestorer$fetchSkin(profile, context);
|
||||||
@@ -53,10 +54,16 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
|||||||
return null;
|
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(
|
var context = new SkinProviderContext(
|
||||||
SkinRestorer.getConfig().firstJoinSkinProvider().getName(),
|
provider.getName(),
|
||||||
profile.name(),
|
profile.getName(),
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
skinrestorer$fetchSkin(profile, context);
|
skinrestorer$fetchSkin(profile, context);
|
||||||
@@ -72,7 +79,7 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
|||||||
|
|
||||||
@Unique
|
@Unique
|
||||||
private static void skinrestorer$fetchSkin(GameProfile profile, SkinProviderContext context) {
|
private static void skinrestorer$fetchSkin(GameProfile profile, SkinProviderContext context) {
|
||||||
SkinRestorer.LOGGER.debug("Fetching {}'s skin", profile.name());
|
SkinRestorer.LOGGER.debug("Fetching {}'s skin", profile.getName());
|
||||||
|
|
||||||
var result = SkinRestorer.getProvider(context.name()).map(
|
var result = SkinRestorer.getProvider(context.name()).map(
|
||||||
provider -> provider.fetchSkin(context.argument(), context.variant())
|
provider -> provider.fetchSkin(context.argument(), context.variant())
|
||||||
@@ -80,7 +87,7 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
|||||||
|
|
||||||
if (!result.isError()) {
|
if (!result.isError()) {
|
||||||
var value = SkinValue.fromProviderContextWithValue(context, result.getSuccessValue().orElse(null));
|
var value = SkinValue.fromProviderContextWithValue(context, result.getSuccessValue().orElse(null));
|
||||||
SkinRestorer.getSkinStorage().setSkin(profile.id(), value);
|
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value);
|
||||||
} else {
|
} else {
|
||||||
SkinRestorer.LOGGER.warn("Failed to fetch skin '{}:{}'", context.name(), context.argument(), result.getErrorValue());
|
SkinRestorer.LOGGER.warn("Failed to fetch skin '{}:{}'", context.name(), context.argument(), result.getErrorValue());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
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.world.level.block.entity.SkullBlockEntity;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
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 {
|
||||||
|
|
||||||
|
@Inject(method = "fetchProfileByName", at = @At("HEAD"),
|
||||||
|
cancellable = true)
|
||||||
|
private static void fetchProfileByName(String name, Services services, CallbackInfoReturnable<CompletableFuture<Optional<GameProfile>>> cir) {
|
||||||
|
if (name == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var profileOpt = Optional.<GameProfile>empty();
|
||||||
|
var gameProfileInfo = ((GameProfileCacheAccessor) services.profileCache()).getProfilesByName().get(name.toLowerCase(Locale.ROOT));
|
||||||
|
|
||||||
|
if (gameProfileInfo != null)
|
||||||
|
profileOpt = Optional.of(gameProfileInfo.getProfile());
|
||||||
|
|
||||||
|
skinrestorer$replaceSkin(profileOpt, cir);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "fetchProfileById", at = @At("HEAD"),
|
||||||
|
cancellable = true)
|
||||||
|
private static void fetchProfileById(UUID id, Services services, BooleanSupplier cacheUninitialized, CallbackInfoReturnable<CompletableFuture<Optional<GameProfile>>> cir) {
|
||||||
|
if (id == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var profileOpt = services.profileCache().get(id);
|
||||||
|
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
package net.lionarius.skinrestorer.skin;
|
package net.lionarius.skinrestorer.skin;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
public enum SkinVariant {
|
public enum SkinVariant {
|
||||||
|
@SerializedName(value = "classic", alternate = {"CLASSIC"})
|
||||||
CLASSIC("classic"),
|
CLASSIC("classic"),
|
||||||
|
@SerializedName(value = "slim", alternate = {"SLIM"})
|
||||||
SLIM("slim");
|
SLIM("slim");
|
||||||
|
|
||||||
private final String name;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -106,6 +106,6 @@ public final class ElyBySkinProvider implements SkinProvider {
|
|||||||
if (response.statusCode() != 200)
|
if (response.statusCode() != 200)
|
||||||
throw new IllegalArgumentException("no profile with name " + username);
|
throw new IllegalArgumentException("no profile with name " + username);
|
||||||
|
|
||||||
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).profile();
|
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).toProfile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import org.mineskin.response.QueueResponse;
|
|||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.TimeUnit;
|
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) {
|
var mineskinVariant = switch (variant) {
|
||||||
case CLASSIC -> Variant.CLASSIC;
|
case CLASSIC -> Variant.CLASSIC;
|
||||||
case SLIM -> Variant.SLIM;
|
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)
|
.variant(mineskinVariant)
|
||||||
.name("skinrestorer-skin")
|
.name("skinrestorer-skin")
|
||||||
.visibility(Visibility.UNLISTED);
|
.visibility(Visibility.UNLISTED);
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import com.mojang.authlib.*;
|
|||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
import com.mojang.authlib.yggdrasil.YggdrasilEnvironment;
|
import com.mojang.authlib.yggdrasil.YggdrasilEnvironment;
|
||||||
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
||||||
import com.mojang.authlib.yggdrasil.response.NameAndId;
|
|
||||||
import com.mojang.util.UndashedUuid;
|
import com.mojang.util.UndashedUuid;
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
import net.lionarius.skinrestorer.exception.TransparentException;
|
import net.lionarius.skinrestorer.exception.TransparentException;
|
||||||
@@ -17,7 +16,7 @@ import net.lionarius.skinrestorer.util.JsonUtils;
|
|||||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||||
import net.lionarius.skinrestorer.util.Result;
|
import net.lionarius.skinrestorer.util.Result;
|
||||||
import net.lionarius.skinrestorer.util.WebUtils;
|
import net.lionarius.skinrestorer.util.WebUtils;
|
||||||
import net.minecraft.server.players.CachedUserNameToIdResolver;
|
import net.minecraft.server.players.GameProfileCache;
|
||||||
import net.minecraft.util.StringUtil;
|
import net.minecraft.util.StringUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -32,11 +31,13 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public final class MojangSkinProvider implements SkinProvider {
|
public final class MojangSkinProvider implements SkinProvider {
|
||||||
|
|
||||||
public static final String PROVIDER_NAME = "mojang";
|
public static final String PROVIDER_NAME = "mojang";
|
||||||
public static final String PROFILE_CACHE_FILENAME = "mojang_profile_cache.json";
|
|
||||||
private static final Environment ENVIRONMENT;
|
private static final Environment ENVIRONMENT;
|
||||||
private static final URI SERVICES_SERVER_URI;
|
private static final URI SERVICES_SERVER_URI;
|
||||||
private static final URI SESSION_SERVER_URI;
|
private static final URI SESSION_SERVER_URI;
|
||||||
private static final CachedUserNameToIdResolver PROFILE_CACHE;
|
|
||||||
|
public static final String PROFILE_CACHE_FILENAME = "mojang_profile_cache.json";
|
||||||
|
private static final GameProfileCache PROFILE_CACHE;
|
||||||
|
|
||||||
private static LoadingCache<UUID, Optional<Property>> SKIN_CACHE;
|
private static LoadingCache<UUID, Optional<Property>> SKIN_CACHE;
|
||||||
|
|
||||||
@@ -50,24 +51,11 @@ public final class MojangSkinProvider implements SkinProvider {
|
|||||||
throw new IllegalArgumentException(e);
|
throw new IllegalArgumentException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
PROFILE_CACHE = new CachedUserNameToIdResolver(new GameProfileRepository() {
|
PROFILE_CACHE = new GameProfileCache((names, callback) -> {
|
||||||
@Override
|
for (var name : names) {
|
||||||
public void findProfilesByNames(String[] names, ProfileLookupCallback callback) {
|
|
||||||
for (var name : names) {
|
|
||||||
try {
|
|
||||||
var profile = MojangSkinProvider.getProfile(name);
|
|
||||||
callback.onProfileLookupSucceeded(profile.name(), profile.id());
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new TransparentException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<NameAndId> findProfileByName(String name) {
|
|
||||||
try {
|
try {
|
||||||
var profile = MojangSkinProvider.getProfile(name);
|
var profile = MojangSkinProvider.getProfile(name);
|
||||||
return Optional.of(new NameAndId(profile.id(), profile.name()));
|
callback.onProfileLookupSucceeded(profile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new TransparentException(e);
|
throw new TransparentException(e);
|
||||||
}
|
}
|
||||||
@@ -94,7 +82,7 @@ public final class MojangSkinProvider implements SkinProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static SkinProviderContext skinProviderContextFromProfile(GameProfile gameProfile) {
|
public static SkinProviderContext skinProviderContextFromProfile(GameProfile gameProfile) {
|
||||||
return new SkinProviderContext(MojangSkinProvider.PROVIDER_NAME, gameProfile.name(), null);
|
return new SkinProviderContext(MojangSkinProvider.PROVIDER_NAME, gameProfile.getName(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -117,7 +105,7 @@ public final class MojangSkinProvider implements SkinProvider {
|
|||||||
if (cachedProfile.isEmpty())
|
if (cachedProfile.isEmpty())
|
||||||
throw new IllegalArgumentException("no profile found for " + username);
|
throw new IllegalArgumentException("no profile found for " + username);
|
||||||
|
|
||||||
return Result.success(SKIN_CACHE.get(cachedProfile.get().id()));
|
return Result.success(SKIN_CACHE.get(cachedProfile.get().getId()));
|
||||||
} catch (UncheckedExecutionException e) {
|
} catch (UncheckedExecutionException e) {
|
||||||
return Result.error((Exception) e.getCause());
|
return Result.error((Exception) e.getCause());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -132,7 +120,7 @@ public final class MojangSkinProvider implements SkinProvider {
|
|||||||
return Optional.ofNullable(textures);
|
return Optional.ofNullable(textures);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static NameAndId getProfile(final String name) throws IOException {
|
private static GameProfile getProfile(final String name) throws IOException {
|
||||||
var request = HttpRequest.newBuilder()
|
var request = HttpRequest.newBuilder()
|
||||||
.uri(MojangSkinProvider.SERVICES_SERVER_URI
|
.uri(MojangSkinProvider.SERVICES_SERVER_URI
|
||||||
.resolve("/minecraft/profile/lookup/name/")
|
.resolve("/minecraft/profile/lookup/name/")
|
||||||
@@ -147,7 +135,7 @@ public final class MojangSkinProvider implements SkinProvider {
|
|||||||
if (response.statusCode() != 200)
|
if (response.statusCode() != 200)
|
||||||
throw new IllegalArgumentException("no profile with name " + name);
|
throw new IllegalArgumentException("no profile with name " + name);
|
||||||
|
|
||||||
return JsonUtils.fromJson(response.body(), NameAndId.class);
|
return JsonUtils.fromJson(response.body(), GameProfile.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GameProfile getProfileWithProperties(UUID uuid) throws IOException {
|
private static GameProfile getProfileWithProperties(UUID uuid) throws IOException {
|
||||||
@@ -165,6 +153,6 @@ public final class MojangSkinProvider implements SkinProvider {
|
|||||||
if (response.statusCode() != 200)
|
if (response.statusCode() != 200)
|
||||||
throw new IllegalArgumentException("no profile with uuid " + uuid);
|
throw new IllegalArgumentException("no profile with uuid " + uuid);
|
||||||
|
|
||||||
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).profile();
|
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).toProfile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ public interface SkinProvider {
|
|||||||
MojangSkinProvider MOJANG = new MojangSkinProvider();
|
MojangSkinProvider MOJANG = new MojangSkinProvider();
|
||||||
ElyBySkinProvider ELY_BY = new ElyBySkinProvider();
|
ElyBySkinProvider ELY_BY = new ElyBySkinProvider();
|
||||||
MineskinSkinProvider MINESKIN = new MineskinSkinProvider();
|
MineskinSkinProvider MINESKIN = new MineskinSkinProvider();
|
||||||
|
CollectionSkinProvider COLLECTION = new CollectionSkinProvider();
|
||||||
SkinShuffleSkinProvider SKIN_SHUFFLE = new SkinShuffleSkinProvider();
|
SkinShuffleSkinProvider SKIN_SHUFFLE = new SkinShuffleSkinProvider();
|
||||||
|
|
||||||
Set<String> BUILTIN_PROVIDER_NAMES = ImmutableSet.of(
|
Set<String> BUILTIN_PROVIDER_NAMES = ImmutableSet.of(
|
||||||
@@ -20,6 +21,7 @@ public interface SkinProvider {
|
|||||||
MojangSkinProvider.PROVIDER_NAME,
|
MojangSkinProvider.PROVIDER_NAME,
|
||||||
ElyBySkinProvider.PROVIDER_NAME,
|
ElyBySkinProvider.PROVIDER_NAME,
|
||||||
MineskinSkinProvider.PROVIDER_NAME,
|
MineskinSkinProvider.PROVIDER_NAME,
|
||||||
|
CollectionSkinProvider.PROVIDER_NAME,
|
||||||
SkinShuffleSkinProvider.PROVIDER_NAME
|
SkinShuffleSkinProvider.PROVIDER_NAME
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.google.gson.Gson;
|
|||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
import com.mojang.authlib.properties.PropertyMap;
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
import com.mojang.util.UUIDTypeAdapter;
|
import com.mojang.util.UUIDTypeAdapter;
|
||||||
@@ -21,6 +22,7 @@ public final class JsonUtils {
|
|||||||
.registerTypeAdapterFactory(new PostProcessingEnabler())
|
.registerTypeAdapterFactory(new PostProcessingEnabler())
|
||||||
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter())
|
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter())
|
||||||
.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer())
|
.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer())
|
||||||
|
.registerTypeAdapter(GameProfile.class, new GameProfile.Serializer())
|
||||||
.setPrettyPrinting()
|
.setPrettyPrinting()
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package net.lionarius.skinrestorer.util;
|
package net.lionarius.skinrestorer.util;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.LinkedHashMultimap;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
import com.mojang.authlib.properties.PropertyMap;
|
|
||||||
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
||||||
import net.lionarius.skinrestorer.mixin.ChunkMapAccessor;
|
import net.lionarius.skinrestorer.mixin.ChunkMapAccessor;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
@@ -40,7 +38,7 @@ public final class PlayerUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void refreshPlayer(ServerPlayer player) {
|
public static void refreshPlayer(ServerPlayer player) {
|
||||||
ServerLevel serverLevel = player.level();
|
ServerLevel serverLevel = player.serverLevel();
|
||||||
PlayerList playerList = serverLevel.getServer().getPlayerList();
|
PlayerList playerList = serverLevel.getServer().getPlayerList();
|
||||||
ChunkMap chunkMap = serverLevel.getChunkSource().chunkMap;
|
ChunkMap chunkMap = serverLevel.getChunkSource().chunkMap;
|
||||||
|
|
||||||
@@ -87,7 +85,7 @@ public final class PlayerUtils {
|
|||||||
playerList.sendPlayerPermissionLevel(player);
|
playerList.sendPlayerPermissionLevel(player);
|
||||||
playerList.sendLevelInfo(player, serverLevel);
|
playerList.sendLevelInfo(player, serverLevel);
|
||||||
playerList.sendAllPlayerInfo(player);
|
playerList.sendAllPlayerInfo(player);
|
||||||
playerList.sendActivePlayerEffects(player);
|
PlayerUtils.sendActivePlayerEffects(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,26 +96,21 @@ public final class PlayerUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static GameProfile cloneGameProfile(GameProfile profile) {
|
public static GameProfile cloneGameProfile(GameProfile profile) {
|
||||||
var newProfile = new GameProfile(profile.id(), profile.name());
|
var newProfile = new GameProfile(profile.getId(), profile.getName());
|
||||||
newProfile.properties().putAll(profile.properties());
|
newProfile.getProperties().putAll(profile.getProperties());
|
||||||
|
|
||||||
return newProfile;
|
return newProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Property getPlayerSkin(GameProfile profile) {
|
public static Property getPlayerSkin(GameProfile profile) {
|
||||||
return Iterables.getFirst(profile.properties().get(TEXTURES_KEY), null);
|
return Iterables.getFirst(profile.getProperties().get(TEXTURES_KEY), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GameProfile applyRestoredSkin(GameProfile profile, Property skin) {
|
public static void applyRestoredSkin(GameProfile profile, Property skin) {
|
||||||
var propertiesMap = profile.properties();
|
profile.getProperties().removeAll(TEXTURES_KEY);
|
||||||
|
|
||||||
var newProperties = LinkedHashMultimap.create(propertiesMap);
|
if (skin != null)
|
||||||
newProperties.removeAll(TEXTURES_KEY);
|
profile.getProperties().put(TEXTURES_KEY, skin);
|
||||||
if (skin != null) {
|
|
||||||
newProperties.put(TEXTURES_KEY, skin);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new GameProfile(profile.id(), profile.name(), new PropertyMap(newProperties));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean areSkinPropertiesEquals(Property x, Property y) {
|
public static boolean areSkinPropertiesEquals(Property x, Property y) {
|
||||||
@@ -141,7 +134,7 @@ public final class PlayerUtils {
|
|||||||
|
|
||||||
public static GameProfile toProfile(MinecraftProfilePropertiesResponse response) {
|
public static GameProfile toProfile(MinecraftProfilePropertiesResponse response) {
|
||||||
final GameProfile profile = new GameProfile(response.id(), response.name());
|
final GameProfile profile = new GameProfile(response.id(), response.name());
|
||||||
profile.properties().putAll(response.properties());
|
profile.getProperties().putAll(response.properties());
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
public net.minecraft.server.players.GameProfileCache$GameProfileInfo
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
accessWidener v2 named
|
accessWidener v2 named
|
||||||
|
|
||||||
|
accessible class net/minecraft/server/players/GameProfileCache$GameProfileInfo
|
||||||
|
|||||||
@@ -10,7 +10,8 @@
|
|||||||
"PlayerListMixin",
|
"PlayerListMixin",
|
||||||
"ServerLoginPacketListenerImplMixin",
|
"ServerLoginPacketListenerImplMixin",
|
||||||
"TrackedEntityAccessorInvoker",
|
"TrackedEntityAccessorInvoker",
|
||||||
"PlayerAccessor"
|
"SkullBlockEntityMixin",
|
||||||
|
"GameProfileCacheAccessor"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Fabric, see https://fabricmc.net/develop/ for new versions
|
# Fabric, see https://fabricmc.net/develop/ for new versions
|
||||||
fabric_loader_version=0.15.0
|
fabric_loader_version=0.15.0
|
||||||
fabric_api_version=0.133.14+1.21.9
|
fabric_api_version=0.97.5+1.20.5
|
||||||
|
|
||||||
optional_dependencies=fabric-api
|
optional_dependencies=fabric-api
|
||||||
additional_modloaders=quilt
|
additional_modloaders=quilt
|
||||||
|
|||||||
@@ -32,6 +32,6 @@ public final class SkinShuffleCompatibility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, ServerPlayNetworking.Context context) {
|
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, ServerPlayNetworking.Context context) {
|
||||||
net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility.handleSkinRefresh(SkinRestorer.getMinecraftServer(), context.player(), payload);
|
net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility.handleSkinRefresh(context.player().getServer(), context.player(), payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ minecraft {
|
|||||||
workingDirectory rootProject.file('run/client')
|
workingDirectory rootProject.file('run/client')
|
||||||
ideaModule "${rootProject.name}.${project.name}.main"
|
ideaModule "${rootProject.name}.${project.name}.main"
|
||||||
taskName 'Client'
|
taskName 'Client'
|
||||||
property 'eventbus.api.strictRuntimeChecks', 'true'
|
|
||||||
mods {
|
mods {
|
||||||
modClientRun {
|
modClientRun {
|
||||||
source sourceSets.main
|
source sourceSets.main
|
||||||
@@ -55,7 +54,6 @@ minecraft {
|
|||||||
workingDirectory rootProject.file('run/server')
|
workingDirectory rootProject.file('run/server')
|
||||||
ideaModule "${rootProject.name}.${project.name}.main"
|
ideaModule "${rootProject.name}.${project.name}.main"
|
||||||
taskName 'Server'
|
taskName 'Server'
|
||||||
property 'eventbus.api.strictRuntimeChecks', 'true'
|
|
||||||
mods {
|
mods {
|
||||||
modServerRun {
|
modServerRun {
|
||||||
source sourceSets.main
|
source sourceSets.main
|
||||||
@@ -68,8 +66,6 @@ minecraft {
|
|||||||
dependencies {
|
dependencies {
|
||||||
minecraft "net.minecraftforge:forge:${forge_minecraft_version}-${forge_version}"
|
minecraft "net.minecraftforge:forge:${forge_minecraft_version}-${forge_version}"
|
||||||
|
|
||||||
annotationProcessor('net.minecraftforge:eventbus-validator:7.0-beta.7')
|
|
||||||
|
|
||||||
annotationProcessor('org.spongepowered:mixin:0.8.5-SNAPSHOT:processor')
|
annotationProcessor('org.spongepowered:mixin:0.8.5-SNAPSHOT:processor')
|
||||||
implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } }
|
implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } }
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Forge, see https://files.minecraftforge.net/net/minecraftforge/forge/ for new versions
|
# Forge, see https://files.minecraftforge.net/net/minecraftforge/forge/ for new versions
|
||||||
forge_version=59.0.0
|
forge_version=50.0.0
|
||||||
forge_loader_version_range=[59,)
|
forge_loader_version_range=[50,)
|
||||||
# Forge sometimes skips minor minecraft versions (like 1.20.5)
|
# Forge sometimes skips minor minecraft versions (like 1.20.5)
|
||||||
forge_minecraft_version=1.21.9
|
forge_minecraft_version=1.20.6
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
|||||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||||
import net.minecraftforge.event.server.ServerStartedEvent;
|
import net.minecraftforge.event.server.ServerStartedEvent;
|
||||||
import net.minecraftforge.event.server.ServerStoppedEvent;
|
import net.minecraftforge.event.server.ServerStoppedEvent;
|
||||||
import net.minecraftforge.eventbus.api.listener.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
|
||||||
@Mod(SkinRestorer.MOD_ID)
|
@Mod(SkinRestorer.MOD_ID)
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package net.lionarius.skinrestorer.forge.compat.skinshuffle;
|
package net.lionarius.skinrestorer.forge.compat.skinshuffle;
|
||||||
|
|
||||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
|
||||||
public final class SkinShuffleCompatibility {
|
public final class SkinShuffleCompatibility {
|
||||||
|
|
||||||
private SkinShuffleCompatibility() {}
|
private SkinShuffleCompatibility() {}
|
||||||
|
|
||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
PlayerEvent.PlayerLoggedInEvent.BUS.addListener(SkinShuffleGameEventHandler::onPlayerLoggedIn);
|
MinecraftForge.EVENT_BUS.register(SkinShuffleGameEventHandler.class);
|
||||||
|
|
||||||
SkinShufflePacketHandler.initialize();
|
SkinShufflePacketHandler.initialize();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ package net.lionarius.skinrestorer.forge.compat.skinshuffle;
|
|||||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
|
||||||
public final class SkinShuffleGameEventHandler {
|
public final class SkinShuffleGameEventHandler {
|
||||||
|
|
||||||
private SkinShuffleGameEventHandler() {}
|
private SkinShuffleGameEventHandler() {}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
public static void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
|
public static void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
|
||||||
SkinShuffleCompatibility.onPlayerJoin((ServerPlayer) event.getEntity());
|
SkinShuffleCompatibility.onPlayerJoin((ServerPlayer) event.getEntity());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +1,60 @@
|
|||||||
package net.lionarius.skinrestorer.forge.compat.skinshuffle;
|
package net.lionarius.skinrestorer.forge.compat.skinshuffle;
|
||||||
|
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
import io.netty.buffer.Unpooled;
|
||||||
import net.lionarius.skinrestorer.compat.skinshuffle.*;
|
import net.lionarius.skinrestorer.compat.skinshuffle.*;
|
||||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||||
import net.minecraft.network.Connection;
|
import net.minecraft.network.Connection;
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraftforge.event.network.CustomPayloadEvent;
|
import net.minecraftforge.event.network.CustomPayloadEvent;
|
||||||
import net.minecraftforge.network.Channel;
|
|
||||||
import net.minecraftforge.network.ChannelBuilder;
|
import net.minecraftforge.network.ChannelBuilder;
|
||||||
|
import net.minecraftforge.network.EventNetworkChannel;
|
||||||
|
|
||||||
public class SkinShufflePacketHandler {
|
public class SkinShufflePacketHandler {
|
||||||
private static final Channel<CustomPacketPayload> INSTANCE = ChannelBuilder
|
|
||||||
.named(SkinRestorer.resourceLocation("skin_shuffle_compat"))
|
private static final EventNetworkChannel HANDSHAKE_INSTANCE = ChannelBuilder
|
||||||
|
.named(SkinShuffleHandshakePayload.PACKET_ID.id())
|
||||||
.optional()
|
.optional()
|
||||||
.payloadChannel()
|
.eventNetworkChannel();
|
||||||
.any()
|
|
||||||
.clientbound()
|
|
||||||
.add(SkinShuffleHandshakePayload.PACKET_ID, SkinShuffleHandshakePayload.PACKET_CODEC, (payload, context) -> {
|
|
||||||
})
|
|
||||||
.serverbound()
|
|
||||||
.add(SkinShuffleSkinRefreshV1Payload.PACKET_ID, SkinShuffleSkinRefreshV1Payload.PACKET_CODEC, SkinShufflePacketHandler::handleSkinRefreshPacket)
|
|
||||||
.add(SkinShuffleSkinRefreshV2Payload.PACKET_ID, SkinShuffleSkinRefreshV2Payload.PACKET_CODEC, SkinShufflePacketHandler::handleSkinRefreshPacket)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
private SkinShufflePacketHandler() {
|
private static final EventNetworkChannel SKIN_REFRESH_V1_INSTANCE = ChannelBuilder
|
||||||
}
|
.named(SkinShuffleSkinRefreshV1Payload.PACKET_ID.id())
|
||||||
|
.optional()
|
||||||
|
.eventNetworkChannel()
|
||||||
|
.addListener(SkinShufflePacketHandler::skinRefreshV1Listener);
|
||||||
|
|
||||||
|
private static final EventNetworkChannel SKIN_REFRESH_V2_INSTANCE = ChannelBuilder
|
||||||
|
.named(SkinShuffleSkinRefreshV2Payload.PACKET_ID.id())
|
||||||
|
.optional()
|
||||||
|
.eventNetworkChannel()
|
||||||
|
.addListener(SkinShufflePacketHandler::skinRefreshV2Listener);
|
||||||
|
|
||||||
protected static void initialize() {
|
protected static void initialize() {
|
||||||
// NO-OP
|
// NO-OP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SkinShufflePacketHandler() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void sendHandshake(Connection connection) {
|
public static void sendHandshake(Connection connection) {
|
||||||
INSTANCE.send(SkinShuffleHandshakePayload.INSTANCE, connection);
|
HANDSHAKE_INSTANCE.send(new FriendlyByteBuf(Unpooled.buffer(0, 0)), connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void skinRefreshV1Listener(CustomPayloadEvent event) {
|
||||||
|
var payload = SkinShuffleSkinRefreshV1Payload.PACKET_CODEC.decode(event.getPayload());
|
||||||
|
handleSkinRefreshPacket(payload, event.getSource());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void skinRefreshV2Listener(CustomPayloadEvent event) {
|
||||||
|
var payload = SkinShuffleSkinRefreshV2Payload.PACKET_CODEC.decode(event.getPayload());
|
||||||
|
handleSkinRefreshPacket(payload, event.getSource());
|
||||||
|
}
|
||||||
|
|
||||||
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, CustomPayloadEvent.Context context) {
|
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, CustomPayloadEvent.Context context) {
|
||||||
var sender = context.getSender();
|
var sender = context.getSender();
|
||||||
|
|
||||||
if (!context.isServerSide() || sender == null)
|
if (!context.isServerSide() || sender == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SkinShuffleCompatibility.handleSkinRefresh(SkinRestorer.getMinecraftServer(), sender, payload);
|
SkinShuffleCompatibility.handleSkinRefresh(sender.getServer(), sender, payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ group=net.lionarius
|
|||||||
java_version=21
|
java_version=21
|
||||||
|
|
||||||
# Common
|
# Common
|
||||||
minecraft_version=1.21.9
|
minecraft_version=1.20.5
|
||||||
minecraft_version_list=1.21.9
|
minecraft_version_list=1.20.5,1.20.6
|
||||||
minecraft_version_range=[1.21.9, 1.22)
|
minecraft_version_range=[1.20.5,1.20.6]
|
||||||
mod_id=skinrestorer
|
mod_id=skinrestorer
|
||||||
mod_name=SkinRestorer
|
mod_name=SkinRestorer
|
||||||
mod_version=2.4.3
|
mod_version=2.5.0
|
||||||
mod_author=Lionarius
|
mod_author=Lionarius
|
||||||
mod_homepage=https://modrinth.com/mod/skinrestorer
|
mod_homepage=https://modrinth.com/mod/skinrestorer
|
||||||
mod_sources=https://github.com/Suiranoil/SkinRestorer
|
mod_sources=https://github.com/Suiranoil/SkinRestorer
|
||||||
@@ -18,11 +18,11 @@ credits=
|
|||||||
description=A server-side mod for managing skins.
|
description=A server-side mod for managing skins.
|
||||||
|
|
||||||
# Dependencies
|
# 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
|
# ParchmentMC mappings, see https://parchmentmc.org/docs/getting-started#choose-a-version for new versions
|
||||||
parchment_minecraft=1.21.8
|
parchment_minecraft=1.20.6
|
||||||
parchment_version=2025.09.14
|
parchment_version=2024.06.16
|
||||||
|
|
||||||
# Publishing
|
# Publishing
|
||||||
curseforge_id=443823
|
curseforge_id=443823
|
||||||
|
|||||||
@@ -55,4 +55,6 @@ dependencies {
|
|||||||
prefer mineskin_client_version
|
prefer mineskin_client_version
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
additionalRuntimeClasspath "org.mineskin:java-client:${mineskin_client_version}"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
# NeoForge, see https://projects.neoforged.net/neoforged/neoforge for new versions
|
# NeoForge, see https://projects.neoforged.net/neoforged/neoforge for new versions
|
||||||
neoforge_version=21.9.0-beta
|
neoforge_version=20.5.0-beta
|
||||||
neoforge_loader_version_range=[4,)
|
neoforge_loader_version_range=[3,)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package net.lionarius.skinrestorer.neoforge.compat.skinshuffle;
|
package net.lionarius.skinrestorer.neoforge.compat.skinshuffle;
|
||||||
|
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
|
||||||
import net.lionarius.skinrestorer.compat.skinshuffle.*;
|
import net.lionarius.skinrestorer.compat.skinshuffle.*;
|
||||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
@@ -27,6 +26,6 @@ public final class SkinShuffleModEventHandler {
|
|||||||
|
|
||||||
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, IPayloadContext context) {
|
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, IPayloadContext context) {
|
||||||
var player = (ServerPlayer) context.player();
|
var player = (ServerPlayer) context.player();
|
||||||
SkinShuffleCompatibility.handleSkinRefresh(SkinRestorer.getMinecraftServer(), player, payload);
|
SkinShuffleCompatibility.handleSkinRefresh(player.getServer(), player, payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,4 +71,4 @@ rootProject.name = 'skin-restorer'
|
|||||||
include('common')
|
include('common')
|
||||||
include('fabric')
|
include('fabric')
|
||||||
include('forge')
|
include('forge')
|
||||||
include('neoforge')
|
//include('neoforge')
|
||||||
|
|||||||
Reference in New Issue
Block a user