Migrating advancements (#23)
This commit is contained in:
parent
b297ae6cbe
commit
0e369bf99f
|
@ -0,0 +1,47 @@
|
|||
package org.samo_lego.simpleauth.mixin;
|
||||
|
||||
import net.minecraft.advancement.PlayerAdvancementTracker;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.ServerAdvancementLoader;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import org.samo_lego.simpleauth.utils.PlayerAuth;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
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.callback.CallbackInfo;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.samo_lego.simpleauth.SimpleAuth.config;
|
||||
|
||||
@Mixin(PlayerAdvancementTracker.class)
|
||||
public class MixinPlayerAdvancementTracker {
|
||||
|
||||
@Mutable
|
||||
@Shadow
|
||||
@Final
|
||||
private File advancementFile;
|
||||
|
||||
@Shadow
|
||||
private ServerPlayerEntity owner;
|
||||
|
||||
@Inject(method = "load(Lnet/minecraft/server/ServerAdvancementLoader;)V", at = @At("HEAD"))
|
||||
private void startMigratingOfflineAdvancements(ServerAdvancementLoader advancementLoader, CallbackInfo ci) {
|
||||
System.out.println(this.advancementFile.isFile());
|
||||
if(config.experimental.premiumAutologin && ((PlayerAuth) this.owner).isUsingMojangAccount() && !this.advancementFile.isFile()) {
|
||||
// Migrate
|
||||
String playername = owner.getGameProfile().getName().toLowerCase();
|
||||
this.advancementFile = new File(this.advancementFile.getParent(), PlayerEntity.getOfflinePlayerUuid(playername).toString() + ".json");
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "load(Lnet/minecraft/server/ServerAdvancementLoader;)V", at = @At("TAIL"))
|
||||
private void endMigratingOfflineAdvancements(ServerAdvancementLoader advancementLoader, CallbackInfo ci) {
|
||||
if(config.experimental.premiumAutologin && ((PlayerAuth) this.owner).isUsingMojangAccount()) {
|
||||
this.advancementFile = new File(this.advancementFile.getParent(), owner.getUuid() + ".json");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,7 +30,6 @@ public abstract class MixinPlayerManager {
|
|||
PlayerLeaveServerCallback.EVENT.invoker().onPlayerLeave(serverPlayerEntity);
|
||||
}
|
||||
|
||||
// Method for kicking player for
|
||||
@Inject(method = "checkCanJoin(Ljava/net/SocketAddress;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/text/Text;", at = @At("HEAD"), cancellable = true)
|
||||
private void checkCanJoin(SocketAddress socketAddress, GameProfile profile, CallbackInfoReturnable<Text> cir) {
|
||||
// Getting the player that is trying to join the server
|
||||
|
|
|
@ -192,8 +192,23 @@ public class AuthConfig {
|
|||
* Whether players who have a valid session should skip the authentication process.
|
||||
* You have to set online-mode to true in server.properties!
|
||||
* (cracked players will still be able to enter, but they'll need to login)
|
||||
*
|
||||
* This protects premium usernames from being stolen, since cracked players
|
||||
* with name that is found in Mojang database, are kicked.
|
||||
*/
|
||||
public boolean premiumAutologin = false;
|
||||
/**
|
||||
* Whether to modify player uuids to offline style.
|
||||
* Note: this should be used only if you had your server
|
||||
* running in offline mode and you made the switch to use
|
||||
* AuthConfig#premiumAutoLogin AND your players already
|
||||
* have e.g. villager discounts, which are based on uuid.
|
||||
* Other things (advancements, playerdata) are migrated
|
||||
* automatically, so think before enabling this. In case
|
||||
* an online-mode player changes username, they'll loose all
|
||||
* their stuff, unless you migrate it manually.
|
||||
*/
|
||||
public boolean forceoOfflineUuids = false;
|
||||
}
|
||||
|
||||
public MainConfig main = new MainConfig();
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [],
|
||||
"server": [
|
||||
"MixinPlayerAdvancementTracker",
|
||||
"MixinPlayerEntity",
|
||||
"MixinPlayerManager",
|
||||
"MixinServerLoginNetworkHandler",
|
||||
|
|
Loading…
Reference in New Issue