mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
Compare commits
10 Commits
1.21.9-mul
...
965af68461
| Author | SHA1 | Date | |
|---|---|---|---|
|
965af68461
|
|||
|
8fba8a997e
|
|||
|
b5bed1c441
|
|||
|
c987d48738
|
|||
|
2cec50afae
|
|||
|
a3bd44af89
|
|||
|
4a87bd43ca
|
|||
|
556ecdc039
|
|||
|
21f00231af
|
|||
|
6f5b291008
|
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
// 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
|
||||
id 'net.neoforged.moddev' version '2.0.+' apply false
|
||||
// see https://files.minecraftforge.net/net/minecraftforge/gradle/ForgeGradle/ for new versions
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package net.lionarius.skinrestorer;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.lionarius.skinrestorer.command.SkinCommand;
|
||||
import net.lionarius.skinrestorer.config.Config;
|
||||
import net.lionarius.skinrestorer.config.provider.BuiltInProviderConfig;
|
||||
import net.lionarius.skinrestorer.exception.TransparentException;
|
||||
import net.lionarius.skinrestorer.mixin.PlayerAccessor;
|
||||
import net.lionarius.skinrestorer.platform.Services;
|
||||
import net.lionarius.skinrestorer.skin.SkinIO;
|
||||
import net.lionarius.skinrestorer.skin.SkinStorage;
|
||||
@@ -110,26 +110,23 @@ public final class SkinRestorer {
|
||||
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>();
|
||||
|
||||
for (var player : targets) {
|
||||
var profile = player.getGameProfile();
|
||||
var skin = PlayerUtils.getPlayerSkin(profile);
|
||||
for (var profile : targets) {
|
||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId()))
|
||||
value = value.setOriginalValue(PlayerUtils.getPlayerSkin(profile));
|
||||
|
||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.id()))
|
||||
value = value.setOriginalValue(skin);
|
||||
|
||||
if (PlayerUtils.areSkinPropertiesEquals(value.value(), skin))
|
||||
if (PlayerUtils.areSkinPropertiesEquals(value.value(), PlayerUtils.getPlayerSkin(profile)))
|
||||
continue;
|
||||
|
||||
if (save)
|
||||
SkinRestorer.getSkinStorage().setSkin(profile.id(), value);
|
||||
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value);
|
||||
|
||||
var newProfile = PlayerUtils.applyRestoredSkin(profile, value.value());
|
||||
((PlayerAccessor) player).setGameProfile(newProfile);
|
||||
PlayerUtils.applyRestoredSkin(profile, value.value());
|
||||
|
||||
if (player.connection == null)
|
||||
var player = server.getPlayerList().getPlayer(profile.getId());
|
||||
if (player == null)
|
||||
continue;
|
||||
|
||||
PlayerUtils.refreshPlayer(player);
|
||||
@@ -141,13 +138,13 @@ public final class SkinRestorer {
|
||||
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);
|
||||
}
|
||||
|
||||
public static CompletableFuture<Result<Collection<ServerPlayer>, String>> setSkinAsync(
|
||||
MinecraftServer server,
|
||||
Collection<ServerPlayer> targets,
|
||||
Collection<GameProfile> targets,
|
||||
SkinProviderContext context,
|
||||
boolean save
|
||||
) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.lionarius.skinrestorer.command;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
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.arguments.GameProfileArgument;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.players.NameAndId;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
@@ -73,41 +72,37 @@ public final class SkinCommand {
|
||||
|
||||
SkinProviderContext context = null;
|
||||
var save = true;
|
||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.id())) {
|
||||
if (profile.properties().containsKey(PlayerUtils.TEXTURES_KEY)) {
|
||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId())) {
|
||||
if (profile.getProperties().containsKey(PlayerUtils.TEXTURES_KEY)) {
|
||||
save = false;
|
||||
context = MojangSkinProvider.skinProviderContextFromProfile(profile);
|
||||
}
|
||||
} else {
|
||||
context = SkinRestorer.getSkinStorage().getSkin(profile.id()).toProviderContext();
|
||||
context = SkinRestorer.getSkinStorage().getSkin(profile.getId()).toProviderContext();
|
||||
}
|
||||
|
||||
if (context == null)
|
||||
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(
|
||||
CommandSourceStack src,
|
||||
Collection<NameAndId> targets,
|
||||
Collection<GameProfile> targets,
|
||||
boolean setByOperator
|
||||
) {
|
||||
var updatedPlayers = new HashSet<ServerPlayer>();
|
||||
for (var nameAndId : targets) {
|
||||
for (var profile : targets) {
|
||||
SkinValue skin = null;
|
||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(nameAndId.id()))
|
||||
skin = SkinRestorer.getSkinStorage().getSkin(nameAndId.id()).replaceValueWithOriginal();
|
||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId()))
|
||||
skin = SkinRestorer.getSkinStorage().getSkin(profile.getId()).replaceValueWithOriginal();
|
||||
|
||||
if (skin == null)
|
||||
continue;
|
||||
|
||||
var player = src.getServer().getPlayerList().getPlayer(nameAndId.id());
|
||||
if (player == null)
|
||||
continue;
|
||||
|
||||
var updatedPlayer = SkinRestorer.applySkin(src.getServer(), Collections.singleton(player), skin, false);
|
||||
SkinRestorer.getSkinStorage().deleteSkin(nameAndId.id());
|
||||
var updatedPlayer = SkinRestorer.applySkin(src.getServer(), Collections.singleton(profile), skin, false);
|
||||
SkinRestorer.getSkinStorage().deleteSkin(profile.getId());
|
||||
|
||||
updatedPlayers.addAll(updatedPlayer);
|
||||
}
|
||||
@@ -123,24 +118,19 @@ public final class SkinCommand {
|
||||
if (src.getPlayer() == null)
|
||||
return 0;
|
||||
|
||||
return resetSubcommand(src, Collections.singleton(src.getPlayer().nameAndId()), false);
|
||||
return resetSubcommand(src, Collections.singleton(src.getPlayer().getGameProfile()), false);
|
||||
}
|
||||
|
||||
private static int setSubcommand(
|
||||
CommandSourceStack src,
|
||||
Collection<NameAndId> targets,
|
||||
Collection<GameProfile> targets,
|
||||
SkinProviderContext context,
|
||||
boolean save,
|
||||
boolean setByOperator
|
||||
) {
|
||||
src.sendSystemMessage(Translation.translatableWithFallback(Translation.COMMAND_SKIN_LOADING_KEY));
|
||||
|
||||
var profileTargets = targets.stream()
|
||||
.map(nameAndId -> src.getServer().getPlayerList().getPlayer(nameAndId.id()))
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
|
||||
SkinRestorer.setSkinAsync(src.getServer(), profileTargets, context, save).thenAccept(result -> {
|
||||
SkinRestorer.setSkinAsync(src.getServer(), targets, context, save).thenAccept(result -> {
|
||||
if (result.isError()) {
|
||||
src.sendFailure(Translation.translatableWithFallback(
|
||||
Translation.COMMAND_SKIN_FAILED_KEY,
|
||||
@@ -159,7 +149,7 @@ public final class SkinCommand {
|
||||
|
||||
private static int setSubcommand(
|
||||
CommandSourceStack src,
|
||||
Collection<NameAndId> targets,
|
||||
Collection<GameProfile> targets,
|
||||
SkinProviderContext context,
|
||||
boolean setByOperator
|
||||
) {
|
||||
@@ -173,7 +163,7 @@ public final class SkinCommand {
|
||||
if (src.getPlayer() == null)
|
||||
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) {
|
||||
@@ -266,7 +256,7 @@ public final class SkinCommand {
|
||||
}
|
||||
|
||||
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())
|
||||
.requires(source -> source.hasPermission(2))
|
||||
|
||||
@@ -43,7 +43,7 @@ public class SkinShuffleCompatibility {
|
||||
server.execute(() -> {
|
||||
SkinRestorer.applySkin(
|
||||
server,
|
||||
Collections.singleton(player),
|
||||
Collections.singleton(player.getGameProfile()),
|
||||
new SkinValue(SkinShuffleSkinProvider.PROVIDER_NAME, null, null, property),
|
||||
!server.usesAuthentication()
|
||||
);
|
||||
|
||||
@@ -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
|
||||
private static void skinrestorer$tryApplySkin(MinecraftServer server, ServerPlayer player) {
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
||||
private CompletableFuture<Void> skinrestorer$pendingSkin;
|
||||
|
||||
@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)
|
||||
public void waitForSkin(CallbackInfo ci) {
|
||||
if (skinrestorer$pendingSkin == null) {
|
||||
@@ -38,14 +38,14 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
||||
assert profile != null;
|
||||
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
|
||||
var value = SkinRestorer.getSkinStorage().getSkin(profile.id());
|
||||
SkinRestorer.getSkinStorage().setSkin(profile.id(), value.setOriginalValue(originalSkin));
|
||||
var value = SkinRestorer.getSkinStorage().getSkin(profile.getId());
|
||||
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value.setOriginalValue(originalSkin));
|
||||
}
|
||||
|
||||
if (SkinRestorer.getConfig().refreshSkinOnJoin()) {
|
||||
var currentSkin = SkinRestorer.getSkinStorage().getSkin(profile.id());
|
||||
var currentSkin = SkinRestorer.getSkinStorage().getSkin(profile.getId());
|
||||
var context = currentSkin.toProviderContext();
|
||||
|
||||
skinrestorer$fetchSkin(profile, context);
|
||||
@@ -63,7 +63,7 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
||||
if (shouldFetch) {
|
||||
var context = new SkinProviderContext(
|
||||
provider.getName(),
|
||||
profile.name(),
|
||||
profile.getName(),
|
||||
null
|
||||
);
|
||||
skinrestorer$fetchSkin(profile, context);
|
||||
@@ -79,7 +79,7 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
||||
|
||||
@Unique
|
||||
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(
|
||||
provider -> provider.fetchSkin(context.argument(), context.variant())
|
||||
@@ -87,7 +87,7 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
||||
|
||||
if (!result.isError()) {
|
||||
var value = SkinValue.fromProviderContextWithValue(context, result.getSuccessValue().orElse(null));
|
||||
SkinRestorer.getSkinStorage().setSkin(profile.id(), value);
|
||||
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value);
|
||||
} else {
|
||||
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().forName("getProfile")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,6 +106,6 @@ public final class ElyBySkinProvider implements SkinProvider {
|
||||
if (response.statusCode() != 200)
|
||||
throw new IllegalArgumentException("no profile with name " + username);
|
||||
|
||||
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).profile();
|
||||
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).toProfile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.mojang.authlib.*;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.yggdrasil.YggdrasilEnvironment;
|
||||
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
||||
import com.mojang.authlib.yggdrasil.response.NameAndId;
|
||||
import com.mojang.util.UndashedUuid;
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
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.Result;
|
||||
import net.lionarius.skinrestorer.util.WebUtils;
|
||||
import net.minecraft.server.players.CachedUserNameToIdResolver;
|
||||
import net.minecraft.server.players.GameProfileCache;
|
||||
import net.minecraft.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -32,11 +31,13 @@ import java.util.concurrent.TimeUnit;
|
||||
public final class MojangSkinProvider implements SkinProvider {
|
||||
|
||||
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 URI SERVICES_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;
|
||||
|
||||
@@ -50,13 +51,13 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
|
||||
PROFILE_CACHE = new CachedUserNameToIdResolver(new GameProfileRepository() {
|
||||
PROFILE_CACHE = new GameProfileCache(new GameProfileRepository() {
|
||||
@Override
|
||||
public void findProfilesByNames(String[] names, ProfileLookupCallback callback) {
|
||||
for (var name : names) {
|
||||
try {
|
||||
var profile = MojangSkinProvider.getProfile(name);
|
||||
callback.onProfileLookupSucceeded(profile.name(), profile.id());
|
||||
callback.onProfileLookupSucceeded(profile);
|
||||
} catch (IOException e) {
|
||||
throw new TransparentException(e);
|
||||
}
|
||||
@@ -64,10 +65,10 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<NameAndId> findProfileByName(String name) {
|
||||
public Optional<GameProfile> findProfileByName(String name) {
|
||||
try {
|
||||
var profile = MojangSkinProvider.getProfile(name);
|
||||
return Optional.of(new NameAndId(profile.id(), profile.name()));
|
||||
return Optional.of(profile);
|
||||
} catch (IOException e) {
|
||||
throw new TransparentException(e);
|
||||
}
|
||||
@@ -94,7 +95,7 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
}
|
||||
|
||||
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
|
||||
@@ -117,7 +118,7 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
if (cachedProfile.isEmpty())
|
||||
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) {
|
||||
return Result.error((Exception) e.getCause());
|
||||
} catch (Exception e) {
|
||||
@@ -132,7 +133,7 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
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()
|
||||
.uri(MojangSkinProvider.SERVICES_SERVER_URI
|
||||
.resolve("/minecraft/profile/lookup/name/")
|
||||
@@ -147,7 +148,7 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
if (response.statusCode() != 200)
|
||||
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 {
|
||||
@@ -165,6 +166,6 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
if (response.statusCode() != 200)
|
||||
throw new IllegalArgumentException("no profile with uuid " + uuid);
|
||||
|
||||
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).profile();
|
||||
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).toProfile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.mojang.util.UUIDTypeAdapter;
|
||||
@@ -21,6 +22,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())
|
||||
.setPrettyPrinting()
|
||||
.create();
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package net.lionarius.skinrestorer.util;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
||||
import net.lionarius.skinrestorer.mixin.ChunkMapAccessor;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -40,7 +38,7 @@ public final class PlayerUtils {
|
||||
}
|
||||
|
||||
public static void refreshPlayer(ServerPlayer player) {
|
||||
ServerLevel serverLevel = player.level();
|
||||
ServerLevel serverLevel = player.serverLevel();
|
||||
PlayerList playerList = serverLevel.getServer().getPlayerList();
|
||||
ChunkMap chunkMap = serverLevel.getChunkSource().chunkMap;
|
||||
|
||||
@@ -98,26 +96,21 @@ public final class PlayerUtils {
|
||||
}
|
||||
|
||||
public static GameProfile cloneGameProfile(GameProfile profile) {
|
||||
var newProfile = new GameProfile(profile.id(), profile.name());
|
||||
newProfile.properties().putAll(profile.properties());
|
||||
var newProfile = new GameProfile(profile.getId(), profile.getName());
|
||||
newProfile.getProperties().putAll(profile.getProperties());
|
||||
|
||||
return newProfile;
|
||||
}
|
||||
|
||||
public static Property getPlayerSkin(GameProfile profile) {
|
||||
return Iterables.getFirst(profile.properties().get(TEXTURES_KEY), null);
|
||||
return Iterables.getFirst(profile.getProperties().get(TEXTURES_KEY), null);
|
||||
}
|
||||
|
||||
public static GameProfile applyRestoredSkin(GameProfile profile, Property skin) {
|
||||
var propertiesMap = profile.properties();
|
||||
public static void applyRestoredSkin(GameProfile profile, Property skin) {
|
||||
profile.getProperties().removeAll(TEXTURES_KEY);
|
||||
|
||||
var newProperties = LinkedHashMultimap.create(propertiesMap);
|
||||
newProperties.removeAll(TEXTURES_KEY);
|
||||
if (skin != null) {
|
||||
newProperties.put(TEXTURES_KEY, skin);
|
||||
}
|
||||
|
||||
return new GameProfile(profile.id(), profile.name(), new PropertyMap(newProperties));
|
||||
if (skin != null)
|
||||
profile.getProperties().put(TEXTURES_KEY, skin);
|
||||
}
|
||||
|
||||
public static boolean areSkinPropertiesEquals(Property x, Property y) {
|
||||
@@ -141,7 +134,7 @@ public final class PlayerUtils {
|
||||
|
||||
public static GameProfile toProfile(MinecraftProfilePropertiesResponse response) {
|
||||
final GameProfile profile = new GameProfile(response.id(), response.name());
|
||||
profile.properties().putAll(response.properties());
|
||||
profile.getProperties().putAll(response.properties());
|
||||
return profile;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
public net.minecraft.server.players.GameProfileCache$GameProfileInfo
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
accessWidener v2 named
|
||||
|
||||
accessible class net/minecraft/server/players/GameProfileCache$GameProfileInfo
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
"refmap": "${mod_id}.refmap.json",
|
||||
"mixins": [
|
||||
"ChunkMapAccessor",
|
||||
"PlayerAccessor",
|
||||
"PlayerListMixin",
|
||||
"ServerLoginPacketListenerImplMixin",
|
||||
"TrackedEntityAccessorInvoker"
|
||||
"TrackedEntityAccessorInvoker",
|
||||
"SkullBlockEntityMixin",
|
||||
"GameProfileCacheAccessor"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Fabric, see https://fabricmc.net/develop/ for new versions
|
||||
fabric_loader_version=0.15.0
|
||||
fabric_api_version=0.133.14+1.21.9
|
||||
fabric_api_version=0.119.5+1.21.5
|
||||
|
||||
optional_dependencies=fabric-api
|
||||
additional_modloaders=quilt
|
||||
|
||||
@@ -32,6 +32,6 @@ public final class SkinShuffleCompatibility {
|
||||
}
|
||||
|
||||
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')
|
||||
ideaModule "${rootProject.name}.${project.name}.main"
|
||||
taskName 'Client'
|
||||
property 'eventbus.api.strictRuntimeChecks', 'true'
|
||||
mods {
|
||||
modClientRun {
|
||||
source sourceSets.main
|
||||
@@ -55,7 +54,6 @@ minecraft {
|
||||
workingDirectory rootProject.file('run/server')
|
||||
ideaModule "${rootProject.name}.${project.name}.main"
|
||||
taskName 'Server'
|
||||
property 'eventbus.api.strictRuntimeChecks', 'true'
|
||||
mods {
|
||||
modServerRun {
|
||||
source sourceSets.main
|
||||
@@ -68,8 +66,6 @@ minecraft {
|
||||
dependencies {
|
||||
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')
|
||||
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_version=59.0.0
|
||||
forge_loader_version_range=[59,)
|
||||
forge_version=55.0.0
|
||||
forge_loader_version_range=[55,)
|
||||
# Forge sometimes skips minor minecraft versions (like 1.20.5)
|
||||
forge_minecraft_version=1.21.9
|
||||
forge_minecraft_version=1.21.5
|
||||
|
||||
@@ -5,7 +5,7 @@ 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.listener.SubscribeEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod(SkinRestorer.MOD_ID)
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package net.lionarius.skinrestorer.forge.compat.skinshuffle;
|
||||
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public final class SkinShuffleCompatibility {
|
||||
|
||||
private SkinShuffleCompatibility() {}
|
||||
|
||||
public static void initialize() {
|
||||
PlayerEvent.PlayerLoggedInEvent.BUS.addListener(SkinShuffleGameEventHandler::onPlayerLoggedIn);
|
||||
MinecraftForge.EVENT_BUS.register(SkinShuffleGameEventHandler.class);
|
||||
|
||||
SkinShufflePacketHandler.initialize();
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ 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());
|
||||
}
|
||||
|
||||
@@ -40,6 +40,6 @@ public class SkinShufflePacketHandler {
|
||||
if (!context.isServerSide() || sender == null)
|
||||
return;
|
||||
|
||||
SkinShuffleCompatibility.handleSkinRefresh(SkinRestorer.getMinecraftServer(), sender, payload);
|
||||
SkinShuffleCompatibility.handleSkinRefresh(sender.getServer(), sender, payload);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ group=net.lionarius
|
||||
java_version=21
|
||||
|
||||
# Common
|
||||
minecraft_version=1.21.9
|
||||
minecraft_version_list=1.21.9,1.21.10
|
||||
minecraft_version_range=[1.21.9, 1.21.10]
|
||||
minecraft_version=1.21.5
|
||||
minecraft_version_list=1.21.5
|
||||
minecraft_version_range=[1.21.5, 1.21.6)
|
||||
mod_id=skinrestorer
|
||||
mod_name=SkinRestorer
|
||||
mod_version=2.5.0
|
||||
@@ -21,8 +21,8 @@ description=A server-side mod for managing skins.
|
||||
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.21.9
|
||||
parchment_version=2025.10.05
|
||||
parchment_minecraft=1.21.5
|
||||
parchment_version=2025.06.15
|
||||
|
||||
# Publishing
|
||||
curseforge_id=443823
|
||||
|
||||
@@ -55,4 +55,6 @@ dependencies {
|
||||
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_version=21.9.0-beta
|
||||
neoforge_version=21.5.0-beta
|
||||
neoforge_loader_version_range=[4,)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.lionarius.skinrestorer.neoforge.compat.skinshuffle;
|
||||
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.*;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@@ -27,6 +26,6 @@ public final class SkinShuffleModEventHandler {
|
||||
|
||||
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, IPayloadContext context) {
|
||||
var player = (ServerPlayer) context.player();
|
||||
SkinShuffleCompatibility.handleSkinRefresh(SkinRestorer.getMinecraftServer(), player, payload);
|
||||
SkinShuffleCompatibility.handleSkinRefresh(player.getServer(), player, payload);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user