From 4d27d6e96739be2aa69d81770bc345d09d537fb1 Mon Sep 17 00:00:00 2001 From: retrooper Date: Wed, 27 Sep 2023 17:11:31 +0200 Subject: [PATCH] 1.20.2 should be working --- .../packetevents/PacketEventsPlugin.java | 4 +- .../packettype/PacketTypeClasses.java | 42 +++++++++++++++---- .../utils/player/ClientVersion.java | 6 +-- .../utils/server/ServerVersion.java | 2 +- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/main/java/io/github/retrooper/packetevents/PacketEventsPlugin.java b/src/main/java/io/github/retrooper/packetevents/PacketEventsPlugin.java index 0467082b1a..aa9589114e 100644 --- a/src/main/java/io/github/retrooper/packetevents/PacketEventsPlugin.java +++ b/src/main/java/io/github/retrooper/packetevents/PacketEventsPlugin.java @@ -45,7 +45,7 @@ public void onLoad() { @Override public void onEnable() { - PacketEvents.get().getEventManager().registerListener(new PacketListenerAbstract() { + /*PacketEvents.get().getEventManager().registerListener(new PacketListenerAbstract() { @Override public void onPacketPlayReceive(PacketPlayReceiveEvent event) { if (event.getPacketId() == PacketType.Play.Client.USE_ENTITY) { @@ -68,7 +68,7 @@ public void onPacketPlaySend(PacketPlaySendEvent event) { } } - }); + });*/ PacketEvents.get().init(); } diff --git a/src/main/java/io/github/retrooper/packetevents/packettype/PacketTypeClasses.java b/src/main/java/io/github/retrooper/packetevents/packettype/PacketTypeClasses.java index 0c3200e4ef..739e2969e7 100644 --- a/src/main/java/io/github/retrooper/packetevents/packettype/PacketTypeClasses.java +++ b/src/main/java/io/github/retrooper/packetevents/packettype/PacketTypeClasses.java @@ -137,8 +137,7 @@ public static void load() { public static class Play { public static class Client { - private static String COMMON_PREFIX; - private static String PREFIX; + private static String COMMON_PREFIX, PREFIX, PREFIX_COMMON_STATES; public static Class FLYING, POSITION, POSITION_LOOK, LOOK, GROUND, CLIENT_COMMAND, TRANSACTION, BLOCK_DIG, ENTITY_ACTION, USE_ENTITY, WINDOW_CLICK, STEER_VEHICLE, CUSTOM_PAYLOAD, ARM_ANIMATION, @@ -157,6 +156,9 @@ public static class Client { public static void load() { if (PacketEvents.get().getServerUtils().getVersion().isNewerThanOrEquals(ServerVersion.v_1_17)) { PREFIX = "net.minecraft.network.protocol.game."; + if (PacketEvents.get().getServerUtils().getVersion().isNewerThanOrEquals(ServerVersion.v_1_20_2)) { + PREFIX_COMMON_STATES = "net.minecraft.network.protocol.common."; + } } else { PREFIX = ServerVersion.getNMSDirectory() + "."; @@ -182,17 +184,25 @@ public static void load() { TRANSACTION = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Transaction"); //This packet was added in 1.17 protocol PONG = Reflection.getClassByNameWithoutException(PREFIX + "ServerboundPongPacket"); + if (PONG == null) { + PONG = Reflection.getClassByNameWithoutException(PREFIX_COMMON_STATES + "ServerboundPongPacket"); + } + SETTINGS = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Settings"); + if (SETTINGS == null) { + SETTINGS = Reflection.getClassByNameWithoutException(PREFIX_COMMON_STATES + "ServerboundClientInformationPacket"); + } try { - SETTINGS = Class.forName(COMMON_PREFIX + "Settings"); ENCHANT_ITEM = Class.forName(COMMON_PREFIX + "EnchantItem"); - CLIENT_COMMAND = Class.forName(COMMON_PREFIX + "ClientCommand"); BLOCK_DIG = Class.forName(COMMON_PREFIX + "BlockDig"); ENTITY_ACTION = Class.forName(COMMON_PREFIX + "EntityAction"); USE_ENTITY = Class.forName(COMMON_PREFIX + "UseEntity"); WINDOW_CLICK = Class.forName(COMMON_PREFIX + "WindowClick"); STEER_VEHICLE = Class.forName(COMMON_PREFIX + "SteerVehicle"); - CUSTOM_PAYLOAD = Class.forName(COMMON_PREFIX + "CustomPayload"); + CUSTOM_PAYLOAD = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "CustomPayload"); + if (CUSTOM_PAYLOAD == null) { + CUSTOM_PAYLOAD = Reflection.getClassByNameWithoutException(PREFIX_COMMON_STATES + "ServerboundCustomPayloadPacket"); + } ARM_ANIMATION = Class.forName(COMMON_PREFIX + "ArmAnimation"); ABILITIES = Class.forName(COMMON_PREFIX + "Abilities"); HELD_ITEM_SLOT = Class.forName(COMMON_PREFIX + "HeldItemSlot"); @@ -200,7 +210,10 @@ public static void load() { TAB_COMPLETE = Class.forName(COMMON_PREFIX + "TabComplete"); CHAT = Class.forName(COMMON_PREFIX + "Chat"); SET_CREATIVE_SLOT = Class.forName(COMMON_PREFIX + "SetCreativeSlot"); - KEEP_ALIVE = Class.forName(COMMON_PREFIX + "KeepAlive"); + KEEP_ALIVE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "KeepAlive"); + if (KEEP_ALIVE == null) { + KEEP_ALIVE = Reflection.getClassByNameWithoutException(PREFIX_COMMON_STATES + "ServerboundKeepAlivePacket"); + } UPDATE_SIGN = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "UpdateSign"); TELEPORT_ACCEPT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "TeleportAccept"); @@ -241,7 +254,7 @@ public static void load() { } public static class Server { - private static String COMMON_PREFIX, PREFIX; + private static String COMMON_PREFIX, PREFIX, PREFIX_COMMON_STATES; public static Class SPAWN_ENTITY, SPAWN_ENTITY_EXPERIENCE_ORB, SPAWN_ENTITY_WEATHER, SPAWN_ENTITY_LIVING, SPAWN_ENTITY_PAINTING, SPAWN_ENTITY_SPAWN, ANIMATION, STATISTIC, BLOCK_BREAK, BLOCK_BREAK_ANIMATION, TILE_ENTITY_DATA, BLOCK_ACTION, @@ -276,6 +289,9 @@ public static class Server { public static void load() { if (PacketEvents.get().getServerUtils().getVersion().isNewerThanOrEquals(ServerVersion.v_1_17)) { PREFIX = "net.minecraft.network.protocol.game."; + if (PacketEvents.get().getServerUtils().getVersion().isNewerThanOrEquals(ServerVersion.v_1_20_2)) { + PREFIX_COMMON_STATES = "net.minecraft.network.protocol.common."; + } } else { PREFIX = ServerVersion.getNMSDirectory() + "."; @@ -310,14 +326,23 @@ public static void load() { SET_SLOT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "SetSlot"); SET_COOLDOWN = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "SetCooldown"); CUSTOM_PAYLOAD = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "CustomPayload"); + if (CUSTOM_PAYLOAD == null) { + CUSTOM_PAYLOAD = Reflection.getClassByNameWithoutException(PREFIX_COMMON_STATES + "ClientboundCustomPayloadPacket"); + } CUSTOM_SOUND_EFFECT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "CustomSoundEffect"); KICK_DISCONNECT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "KickDisconnect"); + if (KICK_DISCONNECT == null) { + KICK_DISCONNECT = Reflection.getClassByNameWithoutException(PREFIX_COMMON_STATES + "ClientboundDisconnectPacket"); + } ENTITY_STATUS = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "EntityStatus"); EXPLOSION = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Explosion"); UNLOAD_CHUNK = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "UnloadChunk"); GAME_STATE_CHANGE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "GameStateChange"); OPEN_WINDOW_HORSE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "OpenWindowHorse"); KEEP_ALIVE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "KeepAlive"); + if (KEEP_ALIVE == null) { + KEEP_ALIVE = Reflection.getClassByNameWithoutException(PREFIX_COMMON_STATES + "ClientboundKeepAlivePacket"); + } MAP_CHUNK = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "MapChunk"); WORLD_EVENT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "WorldEvent"); WORLD_PARTICLES = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "WorldParticles"); @@ -388,6 +413,9 @@ public static void load() { //These packets were added in 1.17 PING = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundPingPacket"); + if (PING == null) { + PING = Reflection.getClassByNameWithoutException(PREFIX_COMMON_STATES + "ClientboundPingPacket"); + } ADD_VIBRATION_SIGNAL = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundAddVibrationSignalPacket"); CLEAR_TITLES = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundClearTitlesPacket"); INITIALIZE_BORDER = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundInitializeBorderPacket"); diff --git a/src/main/java/io/github/retrooper/packetevents/utils/player/ClientVersion.java b/src/main/java/io/github/retrooper/packetevents/utils/player/ClientVersion.java index 996e44e6b4..bdbbf3a57d 100644 --- a/src/main/java/io/github/retrooper/packetevents/utils/player/ClientVersion.java +++ b/src/main/java/io/github/retrooper/packetevents/utils/player/ClientVersion.java @@ -95,12 +95,12 @@ public enum ClientVersion { v_1_18_2(758), v_1_19(759), v_1_19_1(760), v_1_19_3(761), v_1_19_4(762), - v_1_20(763), + v_1_20(763), v_1_20_2(764), //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.protocolVersion + 1), + HIGHER_THAN_SUPPORTED_VERSIONS(v_1_20_2.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. @@ -121,7 +121,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}; + 575, 578, 735, 736, 751, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764}; private int protocolVersion; ClientVersion(int protocolVersion) { diff --git a/src/main/java/io/github/retrooper/packetevents/utils/server/ServerVersion.java b/src/main/java/io/github/retrooper/packetevents/utils/server/ServerVersion.java index b5e8cc473b..0bc98bce63 100644 --- a/src/main/java/io/github/retrooper/packetevents/utils/server/ServerVersion.java +++ b/src/main/java/io/github/retrooper/packetevents/utils/server/ServerVersion.java @@ -47,7 +47,7 @@ public enum ServerVersion { //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 - v_1_20(763), v_1_20_1(763), + v_1_20(763), v_1_20_1(763), v_1_20_2(764), ERROR(-1); private static final String NMS_VERSION_SUFFIX = Bukkit.getServer().getClass().getPackage().getName()