Skip to content

Commit

Permalink
1.20.2 should be working
Browse files Browse the repository at this point in the history
  • Loading branch information
retrooper committed Sep 27, 2023
1 parent 9ecadae commit 4d27d6e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -68,7 +68,7 @@ public void onPacketPlaySend(PacketPlaySendEvent event) {
}
}
});
});*/
PacketEvents.get().init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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() + ".";
Expand All @@ -182,25 +184,36 @@ 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");
CLOSE_WINDOW = Class.forName(COMMON_PREFIX + "CloseWindow");
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");
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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() + ".";
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 4d27d6e

Please sign in to comment.