mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
port to 1.21.9
This commit is contained in:
@@ -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;
|
||||
@@ -108,23 +108,26 @@ public final class SkinRestorer {
|
||||
MineskinSkinProvider.reload();
|
||||
}
|
||||
|
||||
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<GameProfile> targets, SkinValue value, boolean save) {
|
||||
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<ServerPlayer> targets, SkinValue value, boolean save) {
|
||||
var acceptedPlayers = new HashSet<ServerPlayer>();
|
||||
|
||||
for (var profile : targets) {
|
||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId()))
|
||||
value = value.setOriginalValue(PlayerUtils.getPlayerSkin(profile));
|
||||
for (var player : targets) {
|
||||
var profile = player.getGameProfile();
|
||||
var skin = PlayerUtils.getPlayerSkin(profile);
|
||||
|
||||
if (PlayerUtils.areSkinPropertiesEquals(value.value(), PlayerUtils.getPlayerSkin(profile)))
|
||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.id()))
|
||||
value = value.setOriginalValue(skin);
|
||||
|
||||
if (PlayerUtils.areSkinPropertiesEquals(value.value(), skin))
|
||||
continue;
|
||||
|
||||
if (save)
|
||||
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value);
|
||||
SkinRestorer.getSkinStorage().setSkin(profile.id(), value);
|
||||
|
||||
PlayerUtils.applyRestoredSkin(profile, value.value());
|
||||
var newProfile = PlayerUtils.applyRestoredSkin(profile, value.value());
|
||||
((PlayerAccessor) player).setGameProfile(newProfile);
|
||||
|
||||
var player = server.getPlayerList().getPlayer(profile.getId());
|
||||
if (player == null)
|
||||
if (player.connection == null)
|
||||
continue;
|
||||
|
||||
PlayerUtils.refreshPlayer(player);
|
||||
@@ -136,13 +139,13 @@ public final class SkinRestorer {
|
||||
return acceptedPlayers;
|
||||
}
|
||||
|
||||
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<GameProfile> targets, SkinValue value) {
|
||||
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<ServerPlayer> targets, SkinValue value) {
|
||||
return SkinRestorer.applySkin(server, targets, value, true);
|
||||
}
|
||||
|
||||
public static CompletableFuture<Result<Collection<ServerPlayer>, String>> setSkinAsync(
|
||||
MinecraftServer server,
|
||||
Collection<GameProfile> targets,
|
||||
Collection<ServerPlayer> targets,
|
||||
SkinProviderContext context,
|
||||
boolean save
|
||||
) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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;
|
||||
@@ -18,10 +17,12 @@ 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;
|
||||
@@ -72,37 +73,41 @@ public final class SkinCommand {
|
||||
|
||||
SkinProviderContext context = null;
|
||||
var save = true;
|
||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId())) {
|
||||
if (profile.getProperties().containsKey(PlayerUtils.TEXTURES_KEY)) {
|
||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.id())) {
|
||||
if (profile.properties().containsKey(PlayerUtils.TEXTURES_KEY)) {
|
||||
save = false;
|
||||
context = MojangSkinProvider.skinProviderContextFromProfile(profile);
|
||||
}
|
||||
} else {
|
||||
context = SkinRestorer.getSkinStorage().getSkin(profile.getId()).toProviderContext();
|
||||
context = SkinRestorer.getSkinStorage().getSkin(profile.id()).toProviderContext();
|
||||
}
|
||||
|
||||
if (context == null)
|
||||
return 0;
|
||||
|
||||
return SkinCommand.setSubcommand(src, Collections.singleton(profile), context, save, false);
|
||||
return SkinCommand.setSubcommand(src, Collections.singleton(new NameAndId(profile)), context, save, false);
|
||||
}
|
||||
|
||||
private static int resetSubcommand(
|
||||
CommandSourceStack src,
|
||||
Collection<GameProfile> targets,
|
||||
Collection<NameAndId> targets,
|
||||
boolean setByOperator
|
||||
) {
|
||||
var updatedPlayers = new HashSet<ServerPlayer>();
|
||||
for (var profile : targets) {
|
||||
for (var nameAndId : targets) {
|
||||
SkinValue skin = null;
|
||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId()))
|
||||
skin = SkinRestorer.getSkinStorage().getSkin(profile.getId()).replaceValueWithOriginal();
|
||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(nameAndId.id()))
|
||||
skin = SkinRestorer.getSkinStorage().getSkin(nameAndId.id()).replaceValueWithOriginal();
|
||||
|
||||
if (skin == null)
|
||||
continue;
|
||||
|
||||
var updatedPlayer = SkinRestorer.applySkin(src.getServer(), Collections.singleton(profile), skin, false);
|
||||
SkinRestorer.getSkinStorage().deleteSkin(profile.getId());
|
||||
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());
|
||||
|
||||
updatedPlayers.addAll(updatedPlayer);
|
||||
}
|
||||
@@ -118,19 +123,24 @@ public final class SkinCommand {
|
||||
if (src.getPlayer() == null)
|
||||
return 0;
|
||||
|
||||
return resetSubcommand(src, Collections.singleton(src.getPlayer().getGameProfile()), false);
|
||||
return resetSubcommand(src, Collections.singleton(src.getPlayer().nameAndId()), false);
|
||||
}
|
||||
|
||||
private static int setSubcommand(
|
||||
CommandSourceStack src,
|
||||
Collection<GameProfile> targets,
|
||||
Collection<NameAndId> targets,
|
||||
SkinProviderContext context,
|
||||
boolean save,
|
||||
boolean setByOperator
|
||||
) {
|
||||
src.sendSystemMessage(Translation.translatableWithFallback(Translation.COMMAND_SKIN_LOADING_KEY));
|
||||
|
||||
SkinRestorer.setSkinAsync(src.getServer(), targets, context, save).thenAccept(result -> {
|
||||
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 -> {
|
||||
if (result.isError()) {
|
||||
src.sendFailure(Translation.translatableWithFallback(
|
||||
Translation.COMMAND_SKIN_FAILED_KEY,
|
||||
@@ -149,7 +159,7 @@ public final class SkinCommand {
|
||||
|
||||
private static int setSubcommand(
|
||||
CommandSourceStack src,
|
||||
Collection<GameProfile> targets,
|
||||
Collection<NameAndId> targets,
|
||||
SkinProviderContext context,
|
||||
boolean setByOperator
|
||||
) {
|
||||
@@ -163,7 +173,7 @@ public final class SkinCommand {
|
||||
if (src.getPlayer() == null)
|
||||
return 0;
|
||||
|
||||
return setSubcommand(src, Collections.singleton(src.getPlayer().getGameProfile()), context, false);
|
||||
return setSubcommand(src, Collections.singleton(src.getPlayer().nameAndId()), context, false);
|
||||
}
|
||||
|
||||
private static int configReloadSubcommand(CommandContext<CommandSourceStack> context) {
|
||||
@@ -256,7 +266,7 @@ public final class SkinCommand {
|
||||
}
|
||||
|
||||
private static RequiredArgumentBuilder<CommandSourceStack, GameProfileArgument.Result> makeTargetsArgument(
|
||||
BiFunction<CommandContext<CommandSourceStack>, Collection<GameProfile>, Integer> consumer
|
||||
BiFunction<CommandContext<CommandSourceStack>, Collection<NameAndId>, 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.getGameProfile()),
|
||||
Collections.singleton(player),
|
||||
new SkinValue(SkinShuffleSkinProvider.PROVIDER_NAME, null, null, property),
|
||||
!server.usesAuthentication()
|
||||
);
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package net.lionarius.skinrestorer.mixin;
|
||||
|
||||
import net.minecraft.server.players.GameProfileCache;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(GameProfileCache.class)
|
||||
public interface GameProfileCacheAccessor {
|
||||
|
||||
@Accessor
|
||||
Map<String, GameProfileCache.GameProfileInfo> getProfilesByName();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
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.getGameProfile()), SkinRestorer.getSkinStorage().getSkin(player.getUUID()));
|
||||
SkinRestorer.applySkin(server, Collections.singleton(player), SkinRestorer.getSkinStorage().getSkin(player.getUUID()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,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;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/network/chat/Component;"),
|
||||
target = "Lnet/minecraft/server/players/PlayerList;canPlayerLogin(Ljava/net/SocketAddress;Lnet/minecraft/server/players/NameAndId;)Lnet/minecraft/network/chat/Component;"),
|
||||
cancellable = true)
|
||||
public void waitForSkin(CallbackInfo ci) {
|
||||
if (skinrestorer$pendingSkin == null) {
|
||||
@@ -37,14 +37,14 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
||||
assert profile != null;
|
||||
var originalSkin = PlayerUtils.getPlayerSkin(profile);
|
||||
|
||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId())) {
|
||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.id())) {
|
||||
if (originalSkin != null) { // update to the latest official skin
|
||||
var value = SkinRestorer.getSkinStorage().getSkin(profile.getId());
|
||||
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value.setOriginalValue(originalSkin));
|
||||
var value = SkinRestorer.getSkinStorage().getSkin(profile.id());
|
||||
SkinRestorer.getSkinStorage().setSkin(profile.id(), value.setOriginalValue(originalSkin));
|
||||
}
|
||||
|
||||
if (SkinRestorer.getConfig().refreshSkinOnJoin()) {
|
||||
var currentSkin = SkinRestorer.getSkinStorage().getSkin(profile.getId());
|
||||
var currentSkin = SkinRestorer.getSkinStorage().getSkin(profile.id());
|
||||
var context = currentSkin.toProviderContext();
|
||||
|
||||
skinrestorer$fetchSkin(profile, context);
|
||||
@@ -56,7 +56,7 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
||||
if (originalSkin == null && SkinRestorer.getConfig().fetchSkinOnFirstJoin()) {
|
||||
var context = new SkinProviderContext(
|
||||
SkinRestorer.getConfig().firstJoinSkinProvider().getName(),
|
||||
profile.getName(),
|
||||
profile.name(),
|
||||
null
|
||||
);
|
||||
skinrestorer$fetchSkin(profile, context);
|
||||
@@ -72,7 +72,7 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
||||
|
||||
@Unique
|
||||
private static void skinrestorer$fetchSkin(GameProfile profile, SkinProviderContext context) {
|
||||
SkinRestorer.LOGGER.debug("Fetching {}'s skin", profile.getName());
|
||||
SkinRestorer.LOGGER.debug("Fetching {}'s skin", profile.name());
|
||||
|
||||
var result = SkinRestorer.getProvider(context.name()).map(
|
||||
provider -> provider.fetchSkin(context.argument(), context.variant())
|
||||
@@ -80,7 +80,7 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
||||
|
||||
if (!result.isError()) {
|
||||
var value = SkinValue.fromProviderContextWithValue(context, result.getSuccessValue().orElse(null));
|
||||
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value);
|
||||
SkinRestorer.getSkinStorage().setSkin(profile.id(), value);
|
||||
} else {
|
||||
SkinRestorer.LOGGER.warn("Failed to fetch skin '{}:{}'", context.name(), context.argument(), result.getErrorValue());
|
||||
}
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
package net.lionarius.skinrestorer.mixin;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.server.Services;
|
||||
import net.minecraft.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).toProfile();
|
||||
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).profile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.mojang.authlib.*;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.yggdrasil.YggdrasilEnvironment;
|
||||
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
||||
import com.mojang.authlib.yggdrasil.response.NameAndId;
|
||||
import com.mojang.util.UndashedUuid;
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.exception.TransparentException;
|
||||
@@ -16,7 +17,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.GameProfileCache;
|
||||
import net.minecraft.server.players.CachedUserNameToIdResolver;
|
||||
import net.minecraft.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -31,13 +32,11 @@ 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;
|
||||
|
||||
public static final String PROFILE_CACHE_FILENAME = "mojang_profile_cache.json";
|
||||
private static final GameProfileCache PROFILE_CACHE;
|
||||
private static final CachedUserNameToIdResolver PROFILE_CACHE;
|
||||
|
||||
private static LoadingCache<UUID, Optional<Property>> SKIN_CACHE;
|
||||
|
||||
@@ -51,13 +50,13 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
|
||||
PROFILE_CACHE = new GameProfileCache(new GameProfileRepository() {
|
||||
PROFILE_CACHE = new CachedUserNameToIdResolver(new GameProfileRepository() {
|
||||
@Override
|
||||
public void findProfilesByNames(String[] names, ProfileLookupCallback callback) {
|
||||
for (var name : names) {
|
||||
try {
|
||||
var profile = MojangSkinProvider.getProfile(name);
|
||||
callback.onProfileLookupSucceeded(profile);
|
||||
callback.onProfileLookupSucceeded(profile.name(), profile.id());
|
||||
} catch (IOException e) {
|
||||
throw new TransparentException(e);
|
||||
}
|
||||
@@ -65,10 +64,10 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<GameProfile> findProfileByName(String name) {
|
||||
public Optional<NameAndId> findProfileByName(String name) {
|
||||
try {
|
||||
var profile = MojangSkinProvider.getProfile(name);
|
||||
return Optional.of(profile);
|
||||
return Optional.of(new NameAndId(profile.id(), profile.name()));
|
||||
} catch (IOException e) {
|
||||
throw new TransparentException(e);
|
||||
}
|
||||
@@ -95,7 +94,7 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
}
|
||||
|
||||
public static SkinProviderContext skinProviderContextFromProfile(GameProfile gameProfile) {
|
||||
return new SkinProviderContext(MojangSkinProvider.PROVIDER_NAME, gameProfile.getName(), null);
|
||||
return new SkinProviderContext(MojangSkinProvider.PROVIDER_NAME, gameProfile.name(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -118,7 +117,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().getId()));
|
||||
return Result.success(SKIN_CACHE.get(cachedProfile.get().id()));
|
||||
} catch (UncheckedExecutionException e) {
|
||||
return Result.error((Exception) e.getCause());
|
||||
} catch (Exception e) {
|
||||
@@ -133,7 +132,7 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
return Optional.ofNullable(textures);
|
||||
}
|
||||
|
||||
private static GameProfile getProfile(final String name) throws IOException {
|
||||
private static NameAndId getProfile(final String name) throws IOException {
|
||||
var request = HttpRequest.newBuilder()
|
||||
.uri(MojangSkinProvider.SERVICES_SERVER_URI
|
||||
.resolve("/minecraft/profile/lookup/name/")
|
||||
@@ -148,7 +147,7 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
if (response.statusCode() != 200)
|
||||
throw new IllegalArgumentException("no profile with name " + name);
|
||||
|
||||
return JsonUtils.fromJson(response.body(), GameProfile.class);
|
||||
return JsonUtils.fromJson(response.body(), NameAndId.class);
|
||||
}
|
||||
|
||||
private static GameProfile getProfileWithProperties(UUID uuid) throws IOException {
|
||||
@@ -166,6 +165,6 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
if (response.statusCode() != 200)
|
||||
throw new IllegalArgumentException("no profile with uuid " + uuid);
|
||||
|
||||
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).toProfile();
|
||||
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).profile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ 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;
|
||||
@@ -22,7 +21,6 @@ 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,12 +1,13 @@
|
||||
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.lionarius.skinrestorer.mixin.TrackedEntityAccessorInvoker;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.*;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
@@ -97,21 +98,26 @@ public final class PlayerUtils {
|
||||
}
|
||||
|
||||
public static GameProfile cloneGameProfile(GameProfile profile) {
|
||||
var newProfile = new GameProfile(profile.getId(), profile.getName());
|
||||
newProfile.getProperties().putAll(profile.getProperties());
|
||||
var newProfile = new GameProfile(profile.id(), profile.name());
|
||||
newProfile.properties().putAll(profile.properties());
|
||||
|
||||
return newProfile;
|
||||
}
|
||||
|
||||
public static Property getPlayerSkin(GameProfile profile) {
|
||||
return Iterables.getFirst(profile.getProperties().get(TEXTURES_KEY), null);
|
||||
return Iterables.getFirst(profile.properties().get(TEXTURES_KEY), null);
|
||||
}
|
||||
|
||||
public static void applyRestoredSkin(GameProfile profile, Property skin) {
|
||||
profile.getProperties().removeAll(TEXTURES_KEY);
|
||||
public static GameProfile applyRestoredSkin(GameProfile profile, Property skin) {
|
||||
var propertiesMap = profile.properties();
|
||||
|
||||
if (skin != null)
|
||||
profile.getProperties().put(TEXTURES_KEY, skin);
|
||||
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));
|
||||
}
|
||||
|
||||
public static boolean areSkinPropertiesEquals(Property x, Property y) {
|
||||
@@ -135,7 +141,7 @@ public final class PlayerUtils {
|
||||
|
||||
public static GameProfile toProfile(MinecraftProfilePropertiesResponse response) {
|
||||
final GameProfile profile = new GameProfile(response.id(), response.name());
|
||||
profile.getProperties().putAll(response.properties());
|
||||
profile.properties().putAll(response.properties());
|
||||
return profile;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
public net.minecraft.server.players.GameProfileCache$GameProfileInfo
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
accessWidener v2 named
|
||||
|
||||
accessible class net/minecraft/server/players/GameProfileCache$GameProfileInfo
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
"PlayerListMixin",
|
||||
"ServerLoginPacketListenerImplMixin",
|
||||
"TrackedEntityAccessorInvoker",
|
||||
"SkullBlockEntityMixin",
|
||||
"GameProfileCacheAccessor"
|
||||
"PlayerAccessor"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
Reference in New Issue
Block a user