* Added version constants for 1.20.5 & 1.20.6
* Updated minecraft internals to adapt to 1.20.5/1.20.6 (tested on paper experimental builds) * Adapt to further breaking changes introduced by paper * Updated custom payload wrapper for 1.20.5/1.20.6
This commit is contained in:
1 parent
8d4d89f049
commit
95952588f1
7 files changed
+90
-39
No files matched your search
@@ -26,6 +26,7 @@ import io.github.retrooper.packetevents.packettype.PacketType;
|
||||
import io.github.retrooper.packetevents.packetwrappers.play.in.custompayload.WrappedPacketInCustomPayload;
|
||||
import io.github.retrooper.packetevents.packetwrappers.play.out.entity.WrappedPacketOutEntity;
|
||||
import io.github.retrooper.packetevents.packetwrappers.play.out.entityeffect.WrappedPacketOutEntityEffect;
|
||||
import io.github.retrooper.packetevents.packetwrappers.play.out.entityvelocity.WrappedPacketOutEntityVelocity;
|
||||
import io.github.retrooper.packetevents.packetwrappers.play.out.setslot.WrappedPacketOutSetSlot;
|
||||
import io.github.retrooper.packetevents.settings.PacketEventsSettings;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
@@ -87,6 +88,9 @@ public class PacketEventsPlugin extends JavaPlugin {
|
||||
eff.setEffectId(eff.getEffectId());
|
||||
System.out.println("eff: " + eff.getEffectId() + ", ampl: " + eff.getAmplifier() + ", dur:" + eff.getDuration());
|
||||
}
|
||||
else if (event.getPacketId() == PacketType.Play.Server.ENTITY_VELOCITY) {
|
||||
WrappedPacketOutEntityVelocity ev = new WrappedPacketOutEntityVelocity(event.getNMSPacket());
|
||||
}
|
||||
}
|
||||
});*/
|
||||
PacketEvents.get().init();
|
||||
|
||||
+1
@@ -26,6 +26,7 @@ import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
public class PlayerChannelHandlerModern extends ChannelDuplexHandler {
|
||||
/**
|
||||
|
||||
@@ -48,7 +48,7 @@ public class PacketTypeClasses {
|
||||
PREFIX = "net.minecraft.network.protocol.status.";
|
||||
}
|
||||
else {
|
||||
PREFIX = ServerVersion.getNMSDirectory() + ".";
|
||||
PREFIX = ServerVersion.getNMSDirectory();
|
||||
}
|
||||
Client.START = Reflection.getClassByNameWithoutException(PREFIX + "PacketStatusInStart");
|
||||
Client.PING = Reflection.getClassByNameWithoutException(PREFIX + "PacketStatusInPing");
|
||||
@@ -64,7 +64,7 @@ public class PacketTypeClasses {
|
||||
PREFIX = "net.minecraft.network.protocol.status.";
|
||||
}
|
||||
else {
|
||||
PREFIX = ServerVersion.getNMSDirectory() + ".";
|
||||
PREFIX = ServerVersion.getNMSDirectory();
|
||||
}
|
||||
Server.PONG = Reflection.getClassByNameWithoutException(PREFIX + "PacketStatusOutPong");
|
||||
Server.SERVER_INFO = Reflection.getClassByNameWithoutException(PREFIX + "PacketStatusOutServerInfo");
|
||||
@@ -82,7 +82,7 @@ public class PacketTypeClasses {
|
||||
PREFIX = "net.minecraft.network.protocol.handshake.";
|
||||
}
|
||||
else {
|
||||
PREFIX = ServerVersion.getNMSDirectory() + ".";
|
||||
PREFIX = ServerVersion.getNMSDirectory();
|
||||
}
|
||||
Handshaking.Client.SET_PROTOCOL = Reflection.getClassByNameWithoutException(PREFIX + "PacketHandshakingInSetProtocol");
|
||||
}
|
||||
@@ -99,7 +99,7 @@ public class PacketTypeClasses {
|
||||
PREFIX = "net.minecraft.network.protocol.login.";
|
||||
}
|
||||
else {
|
||||
PREFIX = ServerVersion.getNMSDirectory() + ".";
|
||||
PREFIX = ServerVersion.getNMSDirectory();
|
||||
}
|
||||
//In and Out custom payload login packets have been here since 1.13
|
||||
if (PacketEvents.get().getServerUtils().getVersion().isNewerThanOrEquals(ServerVersion.v_1_13)) {
|
||||
@@ -119,7 +119,7 @@ public class PacketTypeClasses {
|
||||
PREFIX = "net.minecraft.network.protocol.login.";
|
||||
}
|
||||
else {
|
||||
PREFIX = ServerVersion.getNMSDirectory() + ".";
|
||||
PREFIX = ServerVersion.getNMSDirectory();
|
||||
}
|
||||
//In and Out custom payload login packets have been here since 1.13
|
||||
if (PacketEvents.get().getServerUtils().getVersion().isNewerThanOrEquals(ServerVersion.v_1_13)) {
|
||||
@@ -161,7 +161,7 @@ public class PacketTypeClasses {
|
||||
}
|
||||
}
|
||||
else {
|
||||
PREFIX = ServerVersion.getNMSDirectory() + ".";
|
||||
PREFIX = ServerVersion.getNMSDirectory();
|
||||
}
|
||||
COMMON_PREFIX = PREFIX + "PacketPlayIn";
|
||||
FLYING = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Flying");
|
||||
@@ -294,7 +294,7 @@ public class PacketTypeClasses {
|
||||
}
|
||||
}
|
||||
else {
|
||||
PREFIX = ServerVersion.getNMSDirectory() + ".";
|
||||
PREFIX = ServerVersion.getNMSDirectory();
|
||||
}
|
||||
COMMON_PREFIX = PREFIX + "PacketPlayOut";
|
||||
SPAWN_ENTITY = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "SpawnEntity");
|
||||
|
||||
+24
-11
@@ -31,9 +31,10 @@ import java.lang.reflect.Method;
|
||||
|
||||
public final class WrappedPacketInCustomPayload extends WrappedPacket {
|
||||
private static boolean strPresent, byteArrayPresent, customPacketPayloadPresent;
|
||||
private static Class<?> CUSTOM_PACKET_PAYLOAD;
|
||||
private static Class<?> CUSTOM_PACKET_PAYLOAD, BRAND_PAYLOAD;
|
||||
private static Method CUSTOM_PACKET_PAYLOAD_MINECRAFT_KEY, CUSTOM_PACKET_PAYLOAD_PACKETDATASERIALIZER;
|
||||
private static byte isVersion_1_17 = -1;
|
||||
private static boolean isVersion_1_20_5;
|
||||
|
||||
public WrappedPacketInCustomPayload(NMSPacket packet) {
|
||||
super(packet);
|
||||
@@ -49,6 +50,10 @@ public final class WrappedPacketInCustomPayload extends WrappedPacket {
|
||||
CUSTOM_PACKET_PAYLOAD_MINECRAFT_KEY = Reflection.getMethod(CUSTOM_PACKET_PAYLOAD, NMSUtils.minecraftKeyClass, 0);
|
||||
CUSTOM_PACKET_PAYLOAD_PACKETDATASERIALIZER = Reflection.getMethod(CUSTOM_PACKET_PAYLOAD, 0, NMSUtils.packetDataSerializerClass);
|
||||
}
|
||||
isVersion_1_20_5 = version.isNewerThanOrEquals(ServerVersion.v_1_20_5);
|
||||
if (isVersion_1_20_5) {
|
||||
BRAND_PAYLOAD = NMSUtils.getNMClassWithoutException("network.protocol.common.custom.BrandPayload");
|
||||
}
|
||||
}
|
||||
|
||||
private Object getModernPayloadObject() {
|
||||
@@ -58,17 +63,25 @@ public final class WrappedPacketInCustomPayload extends WrappedPacket {
|
||||
public String getChannelName() {
|
||||
if (customPacketPayloadPresent) {
|
||||
Object payload = getModernPayloadObject();
|
||||
try {
|
||||
if (isVersion_1_17 == -1) {
|
||||
isVersion_1_17 = (byte) (version.isNewerThanOrEquals(ServerVersion.v_1_17) ? 1 : 0);
|
||||
if (isVersion_1_20_5) {
|
||||
if (BRAND_PAYLOAD.isInstance(payload)) {
|
||||
WrappedPacket reflectBrandPayload = new WrappedPacket(new NMSPacket(payload));
|
||||
return reflectBrandPayload.readString(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
if (isVersion_1_17 == -1) {
|
||||
isVersion_1_17 = (byte) (version.isNewerThanOrEquals(ServerVersion.v_1_17) ? 1 : 0);
|
||||
}
|
||||
int namespaceIndex = isVersion_1_17 == 1 ? 2 : 0;
|
||||
int keyIndex = isVersion_1_17 == 1 ? 3 : 1;
|
||||
Object minecraftKey = CUSTOM_PACKET_PAYLOAD_MINECRAFT_KEY.invoke(payload);
|
||||
WrappedPacket minecraftKeyWrapper = new WrappedPacket(new NMSPacket(minecraftKey));
|
||||
return minecraftKeyWrapper.readString(namespaceIndex) + ":" + minecraftKeyWrapper.readString(keyIndex);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
int namespaceIndex = isVersion_1_17 == 1 ? 2 : 0;
|
||||
int keyIndex = isVersion_1_17 == 1 ? 3 : 1;
|
||||
Object minecraftKey = CUSTOM_PACKET_PAYLOAD_MINECRAFT_KEY.invoke(payload);
|
||||
WrappedPacket minecraftKeyWrapper = new WrappedPacket(new NMSPacket(minecraftKey));
|
||||
return minecraftKeyWrapper.readString(namespaceIndex) + ":" + minecraftKeyWrapper.readString(keyIndex);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
} else if (strPresent) {
|
||||
|
||||
@@ -45,8 +45,6 @@ import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public final class NMSUtils {
|
||||
public static final String NMS_DIR = ServerVersion.getNMSDirectory() + ".";
|
||||
public static final String OBC_DIR = ServerVersion.getOBCDirectory() + ".";
|
||||
private static final ThreadLocal<Random> randomThreadLocal = ThreadLocal.withInitial(Random::new);
|
||||
public static boolean legacyNettyImportMode;
|
||||
public static ServerVersion version;
|
||||
@@ -186,6 +184,9 @@ public final class NMSUtils {
|
||||
dataWatcherClass = getNMSClassWithoutException("DataWatcher");
|
||||
if (dataWatcherClass == null) {
|
||||
dataWatcherClass = getNMClassWithoutException("network.syncher.DataWatcher");
|
||||
if (dataWatcherClass == null) {
|
||||
dataWatcherClass = getNMClassWithoutException("network.syncher.SynchedEntityData");
|
||||
}
|
||||
}
|
||||
nmsItemClass = getNMSClassWithoutException("Item");
|
||||
if (nmsItemClass == null) {
|
||||
@@ -226,6 +227,9 @@ public final class NMSUtils {
|
||||
iChatBaseComponentClass = NMSUtils.getNMSClassWithoutException("IChatBaseComponent");
|
||||
if (iChatBaseComponentClass == null) {
|
||||
iChatBaseComponentClass = getNMClassWithoutException("network.chat.IChatBaseComponent");
|
||||
if (iChatBaseComponentClass == null) {
|
||||
iChatBaseComponentClass = getNMClassWithoutException("network.chat.Component");
|
||||
}
|
||||
}
|
||||
|
||||
tileEntityCommandClass = NMSUtils.getNMSClassWithoutException("TileEntityCommand");
|
||||
@@ -281,7 +285,11 @@ public final class NMSUtils {
|
||||
}
|
||||
|
||||
if (dataWatcherClass != null) {
|
||||
dataWatcherConstructor = dataWatcherClass.getConstructor(nmsEntityClass);
|
||||
try {
|
||||
dataWatcherConstructor = dataWatcherClass.getConstructor(nmsEntityClass);
|
||||
} catch (Exception ex) {
|
||||
dataWatcherConstructor = dataWatcherClass.getDeclaredConstructors()[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (nmsItemStackClass != null && iMaterialClass != null) {
|
||||
@@ -324,6 +332,9 @@ public final class NMSUtils {
|
||||
} catch (ClassNotFoundException e) {
|
||||
//That is fine, it is probably a subclass
|
||||
chatSerializerClass = SubclassUtil.getSubClass(iChatBaseComponentClass, "ChatSerializer");
|
||||
if (chatSerializerClass == null) {
|
||||
chatSerializerClass = SubclassUtil.getSubClass(iChatBaseComponentClass, "Serializer");
|
||||
}
|
||||
}
|
||||
craftMagicNumbersClass = NMSUtils.getOBCClass("util.CraftMagicNumbers");
|
||||
|
||||
@@ -376,7 +387,7 @@ public final class NMSUtils {
|
||||
|
||||
if (registryMaterials != null) {
|
||||
getRegistryId = Reflection.getMethod(registryMaterials, int.class, 0, 1);
|
||||
getRegistryById = Reflection.getMethod(registryMaterials, Optional.class, true,0, int.class);
|
||||
getRegistryById = Reflection.getMethod(registryMaterials, Optional.class, true, 0, int.class);
|
||||
}
|
||||
|
||||
worldSettingsClass = NMSUtils.getNMSClassWithoutException("WorldSettings");
|
||||
@@ -405,8 +416,13 @@ public final class NMSUtils {
|
||||
public static Object getMinecraftServerInstance(Server server) {
|
||||
if (minecraftServer == null) {
|
||||
try {
|
||||
minecraftServer = Reflection.getField(craftServerClass, minecraftServerClass, 0)
|
||||
.get(server);
|
||||
Field f = Reflection.getField(craftServerClass, minecraftServerClass, 0);
|
||||
if (f == null) {
|
||||
//1.20.5 way
|
||||
minecraftServer = Reflection.getField(minecraftServerClass, minecraftServerClass, 0).get(null);
|
||||
} else {
|
||||
minecraftServer = f.get(server);
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -433,7 +449,7 @@ public final class NMSUtils {
|
||||
}
|
||||
|
||||
public static Class<?> getNMSClass(String name) throws ClassNotFoundException {
|
||||
return Class.forName(NMS_DIR + name);
|
||||
return Class.forName(ServerVersion.getNMSDirectory() + name);
|
||||
}
|
||||
|
||||
public static Class<?> getNMClass(String name) throws ClassNotFoundException {
|
||||
@@ -457,7 +473,7 @@ public final class NMSUtils {
|
||||
}
|
||||
|
||||
public static Class<? extends Enum<?>> getNMSEnumClass(String name) throws ClassNotFoundException {
|
||||
return (Class<? extends Enum<?>>) Class.forName(NMS_DIR + name);
|
||||
return (Class<? extends Enum<?>>) Class.forName(ServerVersion.getNMSDirectory() + name);
|
||||
}
|
||||
|
||||
public static Class<? extends Enum<?>> getNMSEnumClassWithoutException(String name) {
|
||||
@@ -478,7 +494,7 @@ public final class NMSUtils {
|
||||
}
|
||||
|
||||
public static Class<?> getOBCClass(String name) throws ClassNotFoundException {
|
||||
return Class.forName(OBC_DIR + name);
|
||||
return Class.forName(ServerVersion.getOBCDirectory() + name);
|
||||
}
|
||||
|
||||
public static Class<?> getNettyClass(String name) throws ClassNotFoundException {
|
||||
@@ -539,7 +555,7 @@ public final class NMSUtils {
|
||||
Class<?> entityPlayerClass = entityPlayer != null ? entityPlayer.getClass() : null;
|
||||
String className = entityPlayer != null ? ClassUtil.getClassSimpleName(entityPlayerClass) : "";
|
||||
if (entityPlayer == null
|
||||
|| className.contains("Fake")) {
|
||||
|| className.contains("Fake")) {
|
||||
return null;
|
||||
}
|
||||
//If we need to get the superclass, we get it
|
||||
@@ -576,8 +592,7 @@ public final class NMSUtils {
|
||||
playerConnection = wrapper.read(0, playerConnectionClass);
|
||||
wrapper = new WrappedPacket(new NMSPacket(playerConnection), playerConnectionClass);
|
||||
return wrapper.readObject(0, networkManagerClass);
|
||||
}
|
||||
catch (Exception ex3) {
|
||||
} catch (Exception ex3) {
|
||||
//Print the original exception!
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@@ -786,7 +801,12 @@ public final class NMSUtils {
|
||||
|
||||
public static Object generateDataWatcher(Object nmsEntity) {
|
||||
try {
|
||||
return dataWatcherConstructor.newInstance(nmsEntity);
|
||||
if (dataWatcherConstructor.getParameterCount() == 2) {
|
||||
return dataWatcherConstructor.newInstance(nmsEntity, null);
|
||||
}
|
||||
else {
|
||||
return dataWatcherConstructor.newInstance(nmsEntity);
|
||||
}
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -96,14 +96,15 @@ public enum ClientVersion {
|
||||
|
||||
v_1_19(759), v_1_19_1(760), v_1_19_3(761), v_1_19_4(762),
|
||||
/**
|
||||
* 1.20.3 and 1.20.4 have the same protocol version
|
||||
* 1.20.3 and 1.20.4 have the same protocol version.
|
||||
* 1.20.5 and 1.20.6 have the same protocol version.
|
||||
*/
|
||||
v_1_20(763), v_1_20_2(764), v_1_20_3(765),
|
||||
v_1_20(763), v_1_20_2(764), v_1_20_3(765), v_1_20_5(766),
|
||||
//TODO Update(checkpoint for things to look out for when updating)
|
||||
|
||||
LOWER_THAN_SUPPORTED_VERSIONS(v_1_7_10.protocolVersion - 1),
|
||||
//TODO Update(checkpoint for things to look out for when updating)
|
||||
HIGHER_THAN_SUPPORTED_VERSIONS(v_1_20_3.protocolVersion + 1),
|
||||
HIGHER_THAN_SUPPORTED_VERSIONS(v_1_20_5.protocolVersion + 1),
|
||||
/**
|
||||
* Pre releases just aren't supported, we would end up with so many enum constants.
|
||||
* This constant assures you they are on a pre-release.
|
||||
@@ -124,7 +125,7 @@ public enum ClientVersion {
|
||||
//TODO Update(checkpoint for things to look out for when updating)
|
||||
private static final int[] CLIENT_VERSIONS = new int[]{5, 47, 107, 108, 109, 110, 210, 315, 316, 335, 338,
|
||||
340, 393, 401, 404, 477, 480, 485, 490, 498, 573,
|
||||
575, 578, 735, 736, 751, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765};
|
||||
575, 578, 735, 736, 751, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766};
|
||||
private int protocolVersion;
|
||||
|
||||
ClientVersion(int protocolVersion) {
|
||||
|
||||
@@ -44,14 +44,26 @@ public enum ServerVersion {
|
||||
v_1_16(735), v_1_16_1(736), v_1_16_2(751), v_1_16_3(753), v_1_16_4(754), v_1_16_5(754),
|
||||
v_1_17(755), v_1_17_1(756),
|
||||
v_1_18(757), v_1_18_1(757), v_1_18_2(758),
|
||||
//TODO Update (checkpoint)
|
||||
v_1_19(759), v_1_19_1(760), v_1_19_2(760), v_1_19_3(761), v_1_19_4(762),
|
||||
//Same protocol version for 1.20 and 1.20.1. Same protocol version for 1.20.3 and 1.20.4.
|
||||
v_1_20(763), v_1_20_1(763), v_1_20_2(764), v_1_20_3(765), v_1_20_4(765),
|
||||
//Same protocol version for 1.20.5 and 1.20.6.
|
||||
v_1_20(763), v_1_20_1(763), v_1_20_2(764), v_1_20_3(765), v_1_20_4(765), v_1_20_5(766), v_1_20_6(766),
|
||||
//TODO Update (checkpoint)
|
||||
ERROR(-1);
|
||||
|
||||
private static final String NMS_VERSION_SUFFIX = Bukkit.getServer().getClass().getPackage().getName()
|
||||
.replace(".", ",").split(",")[3];
|
||||
private static final String NMS_VERSION_SUFFIX;
|
||||
|
||||
static {
|
||||
String temp;
|
||||
try {
|
||||
temp = Bukkit.getServer().getClass().getPackage().getName()
|
||||
.replace(".", ",").split(",")[3] + ".";
|
||||
}
|
||||
catch (Exception ex) {
|
||||
temp = "";
|
||||
}
|
||||
NMS_VERSION_SUFFIX = temp;
|
||||
}
|
||||
private static final ServerVersion[] VALUES = values();
|
||||
public static ServerVersion[] reversedValues = new ServerVersion[VALUES.length];
|
||||
private static ServerVersion cachedVersion;
|
||||
|
||||
Reference in new issue
Block a user