Redo sessions service to support authlib update in older versions

This commit is contained in:
libraryaddict 2024-01-03 06:29:11 +13:00
parent c7d8e44169
commit 33cb700aa1
13 changed files with 52 additions and 54 deletions

View File

@ -262,10 +262,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
return new float[]{dimensions.width, nmsEntity.getEyeHeight()};
}
public WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) {
DedicatedServer minecraftServer = getMinecraftServer();
MinecraftSessionService sessionService = minecraftServer.getSessionService();
return WrappedGameProfile.fromHandle(sessionService.fillProfileProperties((GameProfile) gameProfile.getHandle(), true));
public MinecraftSessionService getMinecraftSessionService() {
return getMinecraftServer().getSessionService();
}
public Float getSoundModifier(Object entity) {

View File

@ -262,10 +262,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
return new float[]{dimensions.width, nmsEntity.getEyeHeight()};
}
public WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) {
DedicatedServer minecraftServer = getMinecraftServer();
MinecraftSessionService sessionService = minecraftServer.getSessionService();
return WrappedGameProfile.fromHandle(sessionService.fillProfileProperties((GameProfile) gameProfile.getHandle(), true));
public MinecraftSessionService getMinecraftSessionService() {
return getMinecraftServer().getSessionService();
}
public Float getSoundModifier(Object entity) {

View File

@ -20,7 +20,6 @@ import me.libraryaddict.disguise.utilities.reflection.ReflectionManagerAbstract;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.Vector3f;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
import net.minecraft.network.syncher.EntityDataAccessor;
@ -263,10 +262,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
return new float[]{dimensions.width, nmsEntity.getEyeHeight()};
}
public WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) {
DedicatedServer minecraftServer = getMinecraftServer();
MinecraftSessionService sessionService = minecraftServer.getSessionService();
return WrappedGameProfile.fromHandle(sessionService.fillProfileProperties((GameProfile) gameProfile.getHandle(), true));
public MinecraftSessionService getMinecraftSessionService() {
return getMinecraftServer().getSessionService();
}
public Float getSoundModifier(Object entity) {

View File

@ -269,10 +269,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
return new float[]{dimensions.width, nmsEntity.getEyeHeight()};
}
public WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) {
DedicatedServer minecraftServer = getMinecraftServer();
MinecraftSessionService sessionService = minecraftServer.getSessionService();
return WrappedGameProfile.fromHandle(sessionService.fillProfileProperties((GameProfile) gameProfile.getHandle(), true));
public MinecraftSessionService getMinecraftSessionService() {
return getMinecraftServer().getSessionService();
}
public Float getSoundModifier(Object entity) {

View File

@ -319,10 +319,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
return new float[]{dimensions.width, nmsEntity.getEyeHeight()};
}
public WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) {
DedicatedServer minecraftServer = getMinecraftServer();
MinecraftSessionService sessionService = minecraftServer.getSessionService();
return WrappedGameProfile.fromHandle(sessionService.fillProfileProperties((GameProfile) gameProfile.getHandle(), true));
public MinecraftSessionService getMinecraftSessionService() {
return getMinecraftServer().getSessionService();
}
public Float getSoundModifier(Object entity) {

View File

@ -314,10 +314,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
return new float[]{dimensions.width, nmsEntity.getEyeHeight()};
}
public WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) {
DedicatedServer minecraftServer = getMinecraftServer();
MinecraftSessionService sessionService = minecraftServer.getSessionService();
return WrappedGameProfile.fromHandle(sessionService.fillProfileProperties((GameProfile) gameProfile.getHandle(), true));
public MinecraftSessionService getMinecraftSessionService() {
return getMinecraftServer().getSessionService();
}
public Float getSoundModifier(Object entity) {

View File

@ -315,10 +315,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
return new float[]{dimensions.width, nmsEntity.getEyeHeight()};
}
public WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) {
DedicatedServer minecraftServer = getMinecraftServer();
MinecraftSessionService sessionService = minecraftServer.getSessionService();
return WrappedGameProfile.fromHandle(sessionService.fillProfileProperties((GameProfile) gameProfile.getHandle(), true));
public MinecraftSessionService getMinecraftSessionService() {
return getMinecraftServer().getSessionService();
}
public Float getSoundModifier(Object entity) {

View File

@ -318,10 +318,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
return new float[]{dimensions.width, nmsEntity.getEyeHeight()};
}
public WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) {
DedicatedServer minecraftServer = getMinecraftServer();
MinecraftSessionService sessionService = minecraftServer.getSessionService();
return WrappedGameProfile.fromHandle(sessionService.fetchProfile(gameProfile.getUUID(), true).profile());
public MinecraftSessionService getMinecraftSessionService() {
return getMinecraftServer().getSessionService();
}
public Float getSoundModifier(Object entity) {

View File

@ -319,10 +319,8 @@ public class ReflectionManager implements ReflectionManagerAbstract {
return new float[]{dimensions.width, nmsEntity.getEyeHeight()};
}
public WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) {
DedicatedServer minecraftServer = getMinecraftServer();
MinecraftSessionService sessionService = minecraftServer.getSessionService();
return WrappedGameProfile.fromHandle(sessionService.fetchProfile(gameProfile.getUUID(), true).profile());
public MinecraftSessionService getMinecraftSessionService() {
return getMinecraftServer().getSessionService();
}
public Float getSoundModifier(Object entity) {

View File

@ -277,7 +277,7 @@
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>3.5.41</version>
<version>5.0.51</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -3,16 +3,17 @@ package me.libraryaddict.disguise.utilities.reflection;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.ProfileLookupCallback;
import lombok.Getter;
@Getter
public class LibsProfileLookupCaller implements ProfileLookupCallback {
private WrappedGameProfile gameProfile;
public WrappedGameProfile getGameProfile() {
return gameProfile;
@Override
public void onProfileLookupFailed(String s, Exception e) {
}
@Override
@Deprecated
public void onProfileLookupFailed(GameProfile gameProfile, Exception arg1) {
}

View File

@ -17,6 +17,7 @@ import com.comphenix.protocol.wrappers.WrappedParticle;
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import com.comphenix.protocol.wrappers.nbt.NbtWrapper;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftSessionService;
import lombok.Getter;
import lombok.SneakyThrows;
import me.libraryaddict.disguise.DisguiseConfig;
@ -194,6 +195,7 @@ public class ReflectionManager {
private static Field trackedPlayers;
private static Method clearEntityTracker;
private static Method addEntityTracker;
private static Method fillProfileProperties;
public static void init() {
try {
@ -369,6 +371,15 @@ public class ReflectionManager {
entitiesField = getNmsField("EntityTracker", "trackedEntities");
ihmGet = getNmsMethod("IntHashMap", "get", int.class);
}
for (Method m : MinecraftSessionService.class.getMethods()) {
if (!m.getName().equals("fillProfileProperties")) {
continue;
}
fillProfileProperties = m;
break;
}
}
public static boolean hasInvul(Entity entity) {
@ -1259,22 +1270,26 @@ public class ReflectionManager {
}
public static WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) {
if (nmsReflection != null) {
return nmsReflection.getSkullBlob(gameProfile);
}
try {
Object minecraftServer = getMinecraftServer();
MinecraftSessionService service = null;
for (Method method : getNmsClass("MinecraftServer").getMethods()) {
if (method.getReturnType().getSimpleName().equals("MinecraftSessionService")) {
Object session = method.invoke(minecraftServer);
if (nmsReflection != null) {
service = nmsReflection.getMinecraftSessionService();
} else {
Object minecraftServer = getMinecraftServer();
return WrappedGameProfile.fromHandle(
session.getClass().getDeclaredMethod("fillProfileProperties", gameProfile.getHandleType(), boolean.class)
.invoke(session, gameProfile.getHandle(), true));
for (Method method : getNmsClass("MinecraftServer").getMethods()) {
if (method.getReturnType().getSimpleName().equals("MinecraftSessionService")) {
service = (MinecraftSessionService) method.invoke(minecraftServer);
}
}
}
if (fillProfileProperties == null) {
return WrappedGameProfile.fromHandle(service.fetchProfile(gameProfile.getUUID(), true).profile());
}
return WrappedGameProfile.fromHandle(fillProfileProperties.invoke(service, gameProfile.getHandle(), true));
} catch (Exception ex) {
ex.printStackTrace();
}

View File

@ -6,6 +6,7 @@ import com.comphenix.protocol.wrappers.EnumWrappers;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.mojang.authlib.ProfileLookupCallback;
import com.mojang.authlib.minecraft.MinecraftSessionService;
import org.bukkit.Art;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
@ -82,7 +83,7 @@ public interface ReflectionManagerAbstract {
float[] getSize(Entity entity);
WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile);
MinecraftSessionService getMinecraftSessionService();
Float getSoundModifier(Object entity);