UserCacheMixin.java (1392B)
1 package cz.bain.plugins.goauth.mixin; 2 3 import com.mojang.authlib.GameProfile; 4 import com.mojang.authlib.GameProfileRepository; 5 import cz.bain.plugins.goauth.Goauth; 6 import net.minecraft.entity.player.PlayerEntity; 7 import net.minecraft.util.UserCache; 8 import org.spongepowered.asm.mixin.Mixin; 9 import org.spongepowered.asm.mixin.Shadow; 10 import org.spongepowered.asm.mixin.injection.At; 11 import org.spongepowered.asm.mixin.injection.Inject; 12 import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 13 14 import java.util.Optional; 15 16 @Mixin(UserCache.class) 17 public abstract class UserCacheMixin { 18 19 @Shadow 20 private static boolean shouldUseRemote() { 21 return false; 22 } 23 24 /** 25 * Override UUIDs when server is in offline mode 26 */ 27 @Inject(at = @At(value = "RETURN"), method = "findProfileByName", cancellable = true) 28 private static void findProfileByNameInject(GameProfileRepository repository, String name, CallbackInfoReturnable<Optional<GameProfile>> cir) { 29 if (!shouldUseRemote() && cir.getReturnValue().isPresent()) { 30 GameProfile profile = cir.getReturnValue().get(); 31 Goauth.LOGGER.info("changin uuid"); 32 cir.setReturnValue(Optional.of( 33 new GameProfile(PlayerEntity.getUuidFromProfile(new GameProfile(null, profile.getName())), profile.getName()) 34 )); 35 } 36 } 37 }