forked from sorceress/EasyAuth
Stat migration changes
This commit is contained in:
parent
2b582c004e
commit
d16e46e046
|
@ -40,6 +40,7 @@ public class MixinPlayerAdvancementTracker {
|
||||||
@Inject(method = "load(Lnet/minecraft/server/ServerAdvancementLoader;)V", at = @At("TAIL"))
|
@Inject(method = "load(Lnet/minecraft/server/ServerAdvancementLoader;)V", at = @At("TAIL"))
|
||||||
private void endMigratingOfflineAdvancements(ServerAdvancementLoader advancementLoader, CallbackInfo ci) {
|
private void endMigratingOfflineAdvancements(ServerAdvancementLoader advancementLoader, CallbackInfo ci) {
|
||||||
if(config.main.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) this.owner).isUsingMojangAccount()) {
|
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");
|
this.advancementFile = new File(this.advancementFile.getParent(), owner.getUuid() + ".json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package org.samo_lego.simpleauth.mixin;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.network.ClientConnection;
|
import net.minecraft.network.ClientConnection;
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.PlayerManager;
|
import net.minecraft.server.PlayerManager;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.stat.ServerStatHandler;
|
import net.minecraft.stat.ServerStatHandler;
|
||||||
|
@ -11,12 +10,9 @@ import net.minecraft.text.LiteralText;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import org.samo_lego.simpleauth.event.AuthEventHandler;
|
import org.samo_lego.simpleauth.event.AuthEventHandler;
|
||||||
import org.samo_lego.simpleauth.utils.PlayerAuth;
|
import org.samo_lego.simpleauth.utils.PlayerAuth;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
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.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
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.CallbackInfo;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||||
|
@ -30,8 +26,6 @@ import static org.samo_lego.simpleauth.SimpleAuth.config;
|
||||||
@Mixin(PlayerManager.class)
|
@Mixin(PlayerManager.class)
|
||||||
public abstract class MixinPlayerManager {
|
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"))
|
@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) {
|
private void onPlayerConnect(ClientConnection clientConnection, ServerPlayerEntity serverPlayerEntity, CallbackInfo ci) {
|
||||||
AuthEventHandler.onPlayerJoin(serverPlayerEntity);
|
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(
|
@Inject(
|
||||||
method = "createStatHandler(Lnet/minecraft/entity/player/PlayerEntity;)Lnet/minecraft/stat/ServerStatHandler;",
|
method = "createStatHandler(Lnet/minecraft/entity/player/PlayerEntity;)Lnet/minecraft/stat/ServerStatHandler;",
|
||||||
at = @At(
|
at = @At(
|
||||||
|
@ -82,6 +60,10 @@ public abstract class MixinPlayerManager {
|
||||||
private void migrateOfflineStats(PlayerEntity player, CallbackInfoReturnable<ServerStatHandler> cir, UUID uUID, ServerStatHandler serverStatHandler, File serverStatsDir, File playerStatFile) {
|
private void migrateOfflineStats(PlayerEntity player, CallbackInfoReturnable<ServerStatHandler> cir, UUID uUID, ServerStatHandler serverStatHandler, File serverStatsDir, File playerStatFile) {
|
||||||
File onlineFile = new File(serverStatsDir, uUID + ".json");
|
File onlineFile = new File(serverStatsDir, uUID + ".json");
|
||||||
if(config.main.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) player).isUsingMojangAccount() && !onlineFile.exists()) {
|
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);
|
((ServerStatHandlerAccessor) serverStatHandler).setFile(onlineFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue