From d16e46e0465f145e4c4fa6ba0239ba425e1dc37d Mon Sep 17 00:00:00 2001 From: samo_lego <34912839+samolego@users.noreply.github.com> Date: Tue, 9 Mar 2021 22:43:45 +0100 Subject: [PATCH 1/3] Stat migration changes --- .../mixin/MixinPlayerAdvancementTracker.java | 1 + .../simpleauth/mixin/MixinPlayerManager.java | 26 +++---------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerAdvancementTracker.java b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerAdvancementTracker.java index a141c4a..2265db9 100644 --- a/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerAdvancementTracker.java +++ b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerAdvancementTracker.java @@ -40,6 +40,7 @@ public class MixinPlayerAdvancementTracker { @Inject(method = "load(Lnet/minecraft/server/ServerAdvancementLoader;)V", at = @At("TAIL")) private void endMigratingOfflineAdvancements(ServerAdvancementLoader advancementLoader, CallbackInfo ci) { if(config.main.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) this.owner).isUsingMojangAccount()) { + // Changes the file name to use online UUID this.advancementFile = new File(this.advancementFile.getParent(), owner.getUuid() + ".json"); } } diff --git a/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerManager.java b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerManager.java index 9c0dda9..9617aa4 100644 --- a/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerManager.java +++ b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerManager.java @@ -3,7 +3,6 @@ package org.samo_lego.simpleauth.mixin; import com.mojang.authlib.GameProfile; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.ClientConnection; -import net.minecraft.server.MinecraftServer; import net.minecraft.server.PlayerManager; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.stat.ServerStatHandler; @@ -11,12 +10,9 @@ import net.minecraft.text.LiteralText; import net.minecraft.text.Text; import org.samo_lego.simpleauth.event.AuthEventHandler; import org.samo_lego.simpleauth.utils.PlayerAuth; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @@ -30,8 +26,6 @@ import static org.samo_lego.simpleauth.SimpleAuth.config; @Mixin(PlayerManager.class) public abstract class MixinPlayerManager { - @Shadow @Final private MinecraftServer server; - @Inject(method = "onPlayerConnect(Lnet/minecraft/network/ClientConnection;Lnet/minecraft/server/network/ServerPlayerEntity;)V", at = @At("RETURN")) private void onPlayerConnect(ClientConnection clientConnection, ServerPlayerEntity serverPlayerEntity, CallbackInfo ci) { AuthEventHandler.onPlayerJoin(serverPlayerEntity); @@ -55,22 +49,6 @@ public abstract class MixinPlayerManager { } } - @ModifyVariable( - method = "createStatHandler(Lnet/minecraft/entity/player/PlayerEntity;)Lnet/minecraft/stat/ServerStatHandler;", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/entity/player/PlayerEntity;getName()Lnet/minecraft/text/Text;" - ), - ordinal = 1 - ) - private File migrateOfflineStats(File file, PlayerEntity player) { - if(config.main.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) player).isUsingMojangAccount()) { - String playername = player.getGameProfile().getName(); - file = new File(file.getParent(), PlayerEntity.getOfflinePlayerUuid(playername) + ".json"); - } - return file; - } - @Inject( method = "createStatHandler(Lnet/minecraft/entity/player/PlayerEntity;)Lnet/minecraft/stat/ServerStatHandler;", at = @At( @@ -82,6 +60,10 @@ public abstract class MixinPlayerManager { private void migrateOfflineStats(PlayerEntity player, CallbackInfoReturnable cir, UUID uUID, ServerStatHandler serverStatHandler, File serverStatsDir, File playerStatFile) { File onlineFile = new File(serverStatsDir, uUID + ".json"); if(config.main.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) player).isUsingMojangAccount() && !onlineFile.exists()) { + String playername = player.getGameProfile().getName(); + File offlineFile = new File(onlineFile.getParent(), PlayerEntity.getOfflinePlayerUuid(playername) + ".json"); + offlineFile.renameTo(onlineFile); + ((ServerStatHandlerAccessor) serverStatHandler).setFile(onlineFile); } } From 3203fb75e1a4be9b773a8924c1d23bdee0ef6a9d Mon Sep 17 00:00:00 2001 From: samolego <34912839+samolego@users.noreply.github.com> Date: Wed, 10 Mar 2021 22:15:33 +0100 Subject: [PATCH 2/3] Fixes #56 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index d05a9f2..cfdc981 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ forge_version=36.0.4 architectury_version=1.5.101 # Mod Properties -mod_version = 1.7.5 +mod_version = 1.7.6 maven_group = org.samo_lego archives_base_name = simpleauth From 1fa5016bfc01fccce47740547499f66fb24caea5 Mon Sep 17 00:00:00 2001 From: samolego <34912839+samolego@users.noreply.github.com> Date: Wed, 10 Mar 2021 22:18:13 +0100 Subject: [PATCH 3/3] Version bump --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index cfdc981..0cc7dbb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ forge_version=36.0.4 architectury_version=1.5.101 # Mod Properties -mod_version = 1.7.6 +mod_version = 1.7.7 maven_group = org.samo_lego archives_base_name = simpleauth