Restore AUTH_SERVER_URL functionality

This commit is contained in:
fullwall 2024-08-19 11:50:15 +08:00
parent 412f67c4ef
commit 5ffd6e40dc
2 changed files with 36 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package net.citizensnpcs.nms.v1_20_R4.util; package net.citizensnpcs.nms.v1_20_R4.util;
import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandle;
import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -58,8 +59,13 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.GameProfileRepository; import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.HttpAuthenticationService;
import com.mojang.authlib.minecraft.MinecraftSessionService; import com.mojang.authlib.minecraft.MinecraftSessionService;
import com.mojang.authlib.minecraft.client.MinecraftClient;
import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.Property;
import com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService;
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
import com.mojang.util.UndashedUuid;
import net.citizensnpcs.Settings.Setting; import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.CitizensAPI;
@ -556,7 +562,15 @@ public class NMSImpl implements NMSBridge {
if (Bukkit.isPrimaryThread()) if (Bukkit.isPrimaryThread())
throw new IllegalStateException("NMS.fillProfileProperties cannot be invoked from the main thread."); throw new IllegalStateException("NMS.fillProfileProperties cannot be invoked from the main thread.");
MinecraftSessionService sessionService = ((CraftServer) Bukkit.getServer()).getServer().getSessionService(); MinecraftSessionService sessionService = ((CraftServer) Bukkit.getServer()).getServer().getSessionService();
return sessionService.fetchProfile(profile.getId(), requireSecure).profile(); if (!(sessionService instanceof YggdrasilMinecraftSessionService))
return sessionService.fetchProfile(profile.getId(), requireSecure).profile();
URL url = HttpAuthenticationService
.constantURL(getAuthServerBaseUrl() + "profile/" + UndashedUuid.toString(profile.getId()));
url = HttpAuthenticationService.concatenateURL(url, "unsigned=" + !requireSecure);
MinecraftClient client = (MinecraftClient) MINECRAFT_CLIENT.invoke(sessionService);
MinecraftProfilePropertiesResponse response = client.get(url, MinecraftProfilePropertiesResponse.class);
return response.toProfile();
} }
public String getAuthServerBaseUrl() { public String getAuthServerBaseUrl() {
@ -2558,6 +2572,7 @@ public class NMSImpl implements NMSBridge {
PlayerAdvancements.class); PlayerAdvancements.class);
private static final MethodHandle ARMADILLO_SCUTE_TIME = NMS.getSetter(Armadillo.class, "cj"); private static final MethodHandle ARMADILLO_SCUTE_TIME = NMS.getSetter(Armadillo.class, "cj");
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP = NMS.getFirstGetter(AttributeSupplier.class, Map.class); private static final MethodHandle ATTRIBUTE_PROVIDER_MAP = NMS.getFirstGetter(AttributeSupplier.class, Map.class);
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP_SETTER = NMS.getFirstFinalSetter(AttributeSupplier.class, private static final MethodHandle ATTRIBUTE_PROVIDER_MAP_SETTER = NMS.getFirstFinalSetter(AttributeSupplier.class,
Map.class); Map.class);
@ -2607,6 +2622,8 @@ public class NMSImpl implements NMSBridge {
private static EntityDataAccessor<Float> INTERACTION_WIDTH = null; private static EntityDataAccessor<Float> INTERACTION_WIDTH = null;
private static final MethodHandle JUMP_FIELD = NMS.getGetter(LivingEntity.class, "bn"); private static final MethodHandle JUMP_FIELD = NMS.getGetter(LivingEntity.class, "bn");
private static final MethodHandle LOOK_CONTROL_SETTER = NMS.getFirstSetter(Mob.class, LookControl.class); private static final MethodHandle LOOK_CONTROL_SETTER = NMS.getFirstSetter(Mob.class, LookControl.class);
private static final MethodHandle MINECRAFT_CLIENT = NMS.getFirstGetter(YggdrasilMinecraftSessionService.class,
MinecraftClient.class);
private static final MethodHandle MOVE_CONTROLLER_OPERATION = NMS.getSetter(MoveControl.class, "k"); private static final MethodHandle MOVE_CONTROLLER_OPERATION = NMS.getSetter(MoveControl.class, "k");
private static final MethodHandle NAVIGATION_CREATE_PATHFINDER = NMS private static final MethodHandle NAVIGATION_CREATE_PATHFINDER = NMS
.getFirstMethodHandleWithReturnType(PathNavigation.class, true, PathFinder.class, int.class); .getFirstMethodHandleWithReturnType(PathNavigation.class, true, PathFinder.class, int.class);

View File

@ -1,6 +1,7 @@
package net.citizensnpcs.nms.v1_21_R1.util; package net.citizensnpcs.nms.v1_21_R1.util;
import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandle;
import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -58,8 +59,13 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.GameProfileRepository; import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.HttpAuthenticationService;
import com.mojang.authlib.minecraft.MinecraftSessionService; import com.mojang.authlib.minecraft.MinecraftSessionService;
import com.mojang.authlib.minecraft.client.MinecraftClient;
import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.Property;
import com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService;
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
import com.mojang.util.UndashedUuid;
import net.citizensnpcs.Settings.Setting; import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.CitizensAPI;
@ -535,7 +541,15 @@ public class NMSImpl implements NMSBridge {
if (Bukkit.isPrimaryThread()) if (Bukkit.isPrimaryThread())
throw new IllegalStateException("NMS.fillProfileProperties cannot be invoked from the main thread."); throw new IllegalStateException("NMS.fillProfileProperties cannot be invoked from the main thread.");
MinecraftSessionService sessionService = ((CraftServer) Bukkit.getServer()).getServer().getSessionService(); MinecraftSessionService sessionService = ((CraftServer) Bukkit.getServer()).getServer().getSessionService();
return sessionService.fetchProfile(profile.getId(), requireSecure).profile(); if (!(sessionService instanceof YggdrasilMinecraftSessionService))
return sessionService.fetchProfile(profile.getId(), requireSecure).profile();
URL url = HttpAuthenticationService
.constantURL(getAuthServerBaseUrl() + "profile/" + UndashedUuid.toString(profile.getId()));
url = HttpAuthenticationService.concatenateURL(url, "unsigned=" + !requireSecure);
MinecraftClient client = (MinecraftClient) MINECRAFT_CLIENT.invoke(sessionService);
MinecraftProfilePropertiesResponse response = client.get(url, MinecraftProfilePropertiesResponse.class);
return response.toProfile();
} }
public String getAuthServerBaseUrl() { public String getAuthServerBaseUrl() {
@ -2541,6 +2555,7 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle ARMADILLO_SCUTE_TIME = NMS.getSetter(Armadillo.class, "cn"); private static final MethodHandle ARMADILLO_SCUTE_TIME = NMS.getSetter(Armadillo.class, "cn");
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP = NMS.getFirstGetter(AttributeSupplier.class, Map.class); private static final MethodHandle ATTRIBUTE_PROVIDER_MAP = NMS.getFirstGetter(AttributeSupplier.class, Map.class);
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP_SETTER = NMS.getFirstFinalSetter(AttributeSupplier.class, private static final MethodHandle ATTRIBUTE_PROVIDER_MAP_SETTER = NMS.getFirstFinalSetter(AttributeSupplier.class,
Map.class); Map.class);
private static final MethodHandle ATTRIBUTE_SUPPLIER = NMS.getFirstGetter(AttributeMap.class, private static final MethodHandle ATTRIBUTE_SUPPLIER = NMS.getFirstGetter(AttributeMap.class,
@ -2587,6 +2602,8 @@ public class NMSImpl implements NMSBridge {
private static EntityDataAccessor<Float> INTERACTION_WIDTH = null; private static EntityDataAccessor<Float> INTERACTION_WIDTH = null;
private static final MethodHandle JUMP_FIELD = NMS.getGetter(LivingEntity.class, "bn"); private static final MethodHandle JUMP_FIELD = NMS.getGetter(LivingEntity.class, "bn");
private static final MethodHandle LOOK_CONTROL_SETTER = NMS.getFirstSetter(Mob.class, LookControl.class); private static final MethodHandle LOOK_CONTROL_SETTER = NMS.getFirstSetter(Mob.class, LookControl.class);
private static final MethodHandle MINECRAFT_CLIENT = NMS.getFirstGetter(YggdrasilMinecraftSessionService.class,
MinecraftClient.class);
private static final MethodHandle MOVE_CONTROLLER_OPERATION = NMS.getSetter(MoveControl.class, "k"); private static final MethodHandle MOVE_CONTROLLER_OPERATION = NMS.getSetter(MoveControl.class, "k");
private static final MethodHandle NAVIGATION_CREATE_PATHFINDER = NMS private static final MethodHandle NAVIGATION_CREATE_PATHFINDER = NMS
.getFirstMethodHandleWithReturnType(PathNavigation.class, true, PathFinder.class, int.class); .getFirstMethodHandleWithReturnType(PathNavigation.class, true, PathFinder.class, int.class);