Migrating stats
This commit is contained in:
parent
b0fe67669c
commit
1582b2dcac
|
@ -30,16 +30,16 @@ public class MixinPlayerAdvancementTracker {
|
||||||
|
|
||||||
@Inject(method = "load(Lnet/minecraft/server/ServerAdvancementLoader;)V", at = @At("HEAD"))
|
@Inject(method = "load(Lnet/minecraft/server/ServerAdvancementLoader;)V", at = @At("HEAD"))
|
||||||
private void startMigratingOfflineAdvancements(ServerAdvancementLoader advancementLoader, CallbackInfo ci) {
|
private void startMigratingOfflineAdvancements(ServerAdvancementLoader advancementLoader, CallbackInfo ci) {
|
||||||
if(config.experimental.premiumAutologin && ((PlayerAuth) this.owner).isUsingMojangAccount() && !this.advancementFile.isFile()) {
|
if(config.experimental.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) this.owner).isUsingMojangAccount() && !this.advancementFile.isFile()) {
|
||||||
// Migrate
|
// Migrate
|
||||||
String playername = owner.getGameProfile().getName().toLowerCase();
|
String playername = owner.getGameProfile().getName();
|
||||||
this.advancementFile = new File(this.advancementFile.getParent(), PlayerEntity.getOfflinePlayerUuid(playername).toString() + ".json");
|
this.advancementFile = new File(this.advancementFile.getParent(), PlayerEntity.getOfflinePlayerUuid(playername).toString() + ".json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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.experimental.premiumAutologin && ((PlayerAuth) this.owner).isUsingMojangAccount()) {
|
if(config.experimental.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) this.owner).isUsingMojangAccount()) {
|
||||||
this.advancementFile = new File(this.advancementFile.getParent(), owner.getUuid() + ".json");
|
this.advancementFile = new File(this.advancementFile.getParent(), owner.getUuid() + ".json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,39 @@
|
||||||
package org.samo_lego.simpleauth.mixin;
|
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.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.text.LiteralText;
|
import net.minecraft.text.LiteralText;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import org.samo_lego.simpleauth.event.entity.player.PlayerJoinServerCallback;
|
import org.samo_lego.simpleauth.event.entity.player.PlayerJoinServerCallback;
|
||||||
import org.samo_lego.simpleauth.event.entity.player.PlayerLeaveServerCallback;
|
import org.samo_lego.simpleauth.event.entity.player.PlayerLeaveServerCallback;
|
||||||
import org.samo_lego.simpleauth.event.entity.player.PrePlayerJoinCallback;
|
import org.samo_lego.simpleauth.event.entity.player.PrePlayerJoinCallback;
|
||||||
|
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 java.io.File;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
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) {
|
||||||
PlayerJoinServerCallback.EVENT.invoker().onPlayerJoin(serverPlayerEntity);
|
PlayerJoinServerCallback.EVENT.invoker().onPlayerJoin(serverPlayerEntity);
|
||||||
|
@ -42,4 +56,39 @@ public abstract class MixinPlayerManager {
|
||||||
cir.setReturnValue(returnText);
|
cir.setReturnValue(returnText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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.experimental.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(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"
|
||||||
|
),
|
||||||
|
locals = LocalCapture.CAPTURE_FAILHARD
|
||||||
|
)
|
||||||
|
private void migrateOfflineStats(PlayerEntity player, CallbackInfoReturnable<ServerStatHandler> cir, UUID uUID, ServerStatHandler serverStatHandler, File serverStatsDir, File playerStatFile) {
|
||||||
|
File onlineFile = new File(serverStatsDir, uUID + ".json");
|
||||||
|
if(config.experimental.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) player).isUsingMojangAccount() && !onlineFile.exists()) {
|
||||||
|
((ServerStatHandlerAccessor) serverStatHandler).setFile(onlineFile);
|
||||||
|
System.out.println("File: " + ((ServerStatHandlerAccessor) serverStatHandler).getFile().getName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
System.out.println("Nope: " + ((ServerStatHandlerAccessor) serverStatHandler).getFile().getName());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package org.samo_lego.simpleauth.mixin;
|
||||||
|
|
||||||
|
import net.minecraft.stat.ServerStatHandler;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
@Mixin(ServerStatHandler.class)
|
||||||
|
public interface ServerStatHandlerAccessor {
|
||||||
|
|
||||||
|
@Accessor("file")
|
||||||
|
File getFile();
|
||||||
|
|
||||||
|
@Accessor("file")
|
||||||
|
void setFile(File file);
|
||||||
|
}
|
|
@ -11,7 +11,8 @@
|
||||||
"MixinServerPlayerEntity",
|
"MixinServerPlayerEntity",
|
||||||
"MixinServerPlayNetworkHandler",
|
"MixinServerPlayNetworkHandler",
|
||||||
"MixinSlot",
|
"MixinSlot",
|
||||||
"MixinWorldSaveHandler"
|
"MixinWorldSaveHandler",
|
||||||
|
"ServerStatHandlerAccessor"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|
Loading…
Reference in New Issue