Skip to content

Commit

Permalink
Merge pull request #98 from Machine-Maker/fix/craftbukkit-chat-1.19.1
Browse files Browse the repository at this point in the history
fix: CraftBukkit Chat facet for 1.19.1
  • Loading branch information
kashike authored Jul 30, 2022
2 parents 9d6c831 + 1f456a2 commit 92962c2
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import org.jetbrains.annotations.Nullable;

import static java.lang.invoke.MethodHandles.dropArguments;
import static java.lang.invoke.MethodHandles.insertArguments;
import static java.lang.invoke.MethodType.methodType;
import static net.kyori.adventure.platform.bukkit.BukkitComponentSerializer.gson;
import static net.kyori.adventure.platform.bukkit.BukkitComponentSerializer.legacy;
Expand Down Expand Up @@ -248,8 +249,12 @@ public Object createMessage(final @NotNull V viewer, final @NotNull Component me
findMcClassName("network.protocol.game.ClientboundChatPacket"),
findMcClassName("network.protocol.game.ClientboundSystemChatPacket")
);
// ClientboundSystemChatPacket constructor changed for 1.19
chatPacketConstructor = findConstructor(chatPacketClass, CLASS_CHAT_COMPONENT, int.class);
// ClientboundSystemChatPacket constructor changed for 1.19.1
chatPacketConstructor = findConstructor(chatPacketClass, CLASS_CHAT_COMPONENT, boolean.class);
if (chatPacketConstructor == null) {
// ClientboundSystemChatPacket constructor changed for 1.19
chatPacketConstructor = findConstructor(chatPacketClass, CLASS_CHAT_COMPONENT, int.class);
}
if (chatPacketConstructor == null) {
// ClientboundChatPacket constructor changed for 1.16
chatPacketConstructor = findConstructor(chatPacketClass, CLASS_CHAT_COMPONENT);
Expand All @@ -260,8 +265,14 @@ public Object createMessage(final @NotNull V viewer, final @NotNull Component me
}
} else {
if (MESSAGE_TYPE_CHAT == Integer.valueOf(0)) {
// for 1.19, create a function that drops the last UUID argument while keeping the integer message type argument
chatPacketConstructor = dropArguments(chatPacketConstructor, 2, UUID.class);
if (chatPacketConstructor.type().parameterType(1).equals(boolean.class)) {
// 1.19.1
chatPacketConstructor = insertArguments(chatPacketConstructor, 1, Boolean.FALSE);
chatPacketConstructor = dropArguments(chatPacketConstructor, 1, Integer.class, UUID.class);
} else {
// for 1.19, create a function that drops the last UUID argument while keeping the integer message type argument
chatPacketConstructor = dropArguments(chatPacketConstructor, 2, UUID.class);
}
} else {
// Create a function that ignores the message type and sender id arguments to call the underlying one-argument constructor
chatPacketConstructor = dropArguments(chatPacketConstructor, 1, CLASS_MESSAGE_TYPE == null ? Object.class : CLASS_MESSAGE_TYPE, UUID.class);
Expand Down

0 comments on commit 92962c2

Please sign in to comment.