|
32 | 32 | import com.comphenix.protocol.events.PacketEvent; |
33 | 33 | import com.comphenix.protocol.utility.MinecraftReflection; |
34 | 34 | import com.comphenix.protocol.utility.MinecraftVersion; |
35 | | -import com.comphenix.protocol.wrappers.CustomPacketPayloadWrapper; |
36 | 35 | import com.comphenix.protocol.wrappers.EnumWrappers; |
37 | | -import com.comphenix.protocol.wrappers.MinecraftKey; |
38 | 36 | import com.comphenix.protocol.wrappers.Pair; |
39 | 37 | import com.comphenix.protocol.wrappers.PlayerInfoData; |
40 | 38 | import com.comphenix.protocol.wrappers.WrappedChatComponent; |
|
64 | 62 | import com.google.common.collect.Lists; |
65 | 63 | import io.leangen.geantyref.GenericTypeReflector; |
66 | 64 | import io.leangen.geantyref.TypeFactory; |
67 | | -import io.netty.buffer.ByteBuf; |
68 | | -import io.netty.buffer.Unpooled; |
69 | 65 | import java.lang.reflect.ParameterizedType; |
70 | 66 | import java.lang.reflect.Type; |
71 | 67 | import java.util.AbstractMap; |
@@ -209,6 +205,9 @@ final class ProtocolLibPacketAdapter implements PlatformPacketAdapter<World, Pla |
209 | 205 | .build(); |
210 | 206 | } |
211 | 207 |
|
| 208 | + // MonotonicNonNull, lazily initialized |
| 209 | + private Platform<World, Player, ItemStack, Plugin> platform; |
| 210 | + |
212 | 211 | private static @Nullable WrappedWatchableObject createWatchableObject( |
213 | 212 | int index, |
214 | 213 | @NotNull Type type, |
@@ -494,36 +493,8 @@ final class ProtocolLibPacketAdapter implements PlatformPacketAdapter<World, Pla |
494 | 493 | byte[] payload |
495 | 494 | ) { |
496 | 495 | return (player, npc) -> { |
497 | | - // CustomPayload (https://wiki.vg/Protocol#Custom_Payload) |
498 | | - PacketContainer container = new PacketContainer(PacketType.Play.Server.CUSTOM_PAYLOAD); |
499 | | - |
500 | | - if (MinecraftVersion.AQUATIC_UPDATE.atOrAbove()) { |
501 | | - // mc 1.13: channel id is now in the format of a resource location |
502 | | - String[] parts = channelId.split(":", 2); |
503 | | - MinecraftKey key = parts.length == 1 ? new MinecraftKey(channelId) : new MinecraftKey(parts[0], parts[1]); |
504 | | - |
505 | | - if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { |
506 | | - // mc 1.20.2: custom payload info is in a wrapper object |
507 | | - CustomPacketPayloadWrapper payloadWrapper = new CustomPacketPayloadWrapper(payload, key); |
508 | | - container.getCustomPacketPayloads().write(0, payloadWrapper); |
509 | | - } else { |
510 | | - // pre 1.20.2: payload key is a plain field |
511 | | - container.getMinecraftKeys().write(0, key); |
512 | | - } |
513 | | - } else { |
514 | | - // mc 1.8: channel id is a string |
515 | | - container.getStrings().write(0, channelId); |
516 | | - } |
517 | | - |
518 | | - if (!MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { |
519 | | - // pre 1.20.2: payload data is a ByteBuf field |
520 | | - ByteBuf buffer = Unpooled.copiedBuffer(payload); |
521 | | - Object wrappedSerializableBuffer = MinecraftReflection.getPacketDataSerializer(buffer); |
522 | | - container.getModifier().withType(ByteBuf.class).write(0, wrappedSerializableBuffer); |
523 | | - } |
524 | | - |
525 | | - // send the packet without notifying any bound packet listeners |
526 | | - PROTOCOL_MANAGER.sendServerPacket(player, container, false); |
| 496 | + Plugin plugin = this.platform.extension(); |
| 497 | + player.sendPluginMessage(plugin, channelId, payload); |
527 | 498 | }; |
528 | 499 | } |
529 | 500 |
|
|
0 commit comments