diff --git a/platform/fabric/src/testmod/java/lol/bai/badpackets/test/fabric/FabricBadPacketTest.java b/platform/fabric/src/testmod/java/lol/bai/badpackets/test/fabric/FabricBadPacketTest.java index fcfe820..afe3672 100644 --- a/platform/fabric/src/testmod/java/lol/bai/badpackets/test/fabric/FabricBadPacketTest.java +++ b/platform/fabric/src/testmod/java/lol/bai/badpackets/test/fabric/FabricBadPacketTest.java @@ -11,7 +11,7 @@ public class FabricBadPacketTest implements ModInitializer { @Override public void onInitialize() { - BadPacketTest.server(); + BadPacketTest.common(); // TODO // ServerConfigurationConnectionEvents.CONFIGURE.register((handler, server) -> { diff --git a/src/main/java/lol/bai/badpackets/api/PacketReadyCallback.java b/src/main/java/lol/bai/badpackets/api/PacketReadyCallback.java new file mode 100644 index 0000000..f65d55c --- /dev/null +++ b/src/main/java/lol/bai/badpackets/api/PacketReadyCallback.java @@ -0,0 +1,8 @@ +package lol.bai.badpackets.api; + +@FunctionalInterface +public interface PacketReadyCallback { + + void onReady(C context); + +} diff --git a/src/main/java/lol/bai/badpackets/api/PacketReceiver.java b/src/main/java/lol/bai/badpackets/api/PacketReceiver.java new file mode 100644 index 0000000..23c34bd --- /dev/null +++ b/src/main/java/lol/bai/badpackets/api/PacketReceiver.java @@ -0,0 +1,8 @@ +package lol.bai.badpackets.api; + +@FunctionalInterface +public interface PacketReceiver { + + void receive(C context, P payload); + +} diff --git a/src/main/java/lol/bai/badpackets/api/PacketSender.java b/src/main/java/lol/bai/badpackets/api/PacketSender.java index 82f132a..d2bf5e3 100644 --- a/src/main/java/lol/bai/badpackets/api/PacketSender.java +++ b/src/main/java/lol/bai/badpackets/api/PacketSender.java @@ -1,9 +1,8 @@ package lol.bai.badpackets.api; -import lol.bai.badpackets.api.play.ClientPlayPacketReadyCallback; +import lol.bai.badpackets.api.play.ClientPlayContext; import lol.bai.badpackets.api.play.PlayPackets; -import lol.bai.badpackets.api.play.ServerPlayPacketReadyCallback; -import lol.bai.badpackets.api.play.ServerPlayPacketReceiver; +import lol.bai.badpackets.api.play.ServerPlayContext; import lol.bai.badpackets.impl.handler.ClientPlayPacketHandler; import lol.bai.badpackets.impl.handler.ServerPlayPacketHandler; import lol.bai.badpackets.impl.marker.ApiSide; @@ -25,11 +24,11 @@ public interface PacketSender { *

* Only available when on game. * - * @see PlayPackets#registerServerChannel(ResourceLocation, ServerPlayPacketReceiver) - * @see PlayPackets#registerServerChannel(CustomPacketPayload.Type, StreamCodec, ServerPlayPacketReceiver) + * @see PlayPackets#registerServerChannel(ResourceLocation) + * @see PlayPackets#registerServerChannel(CustomPacketPayload.Type, StreamCodec) */ @ApiSide.ClientOnly - static PacketSender c2s() { + static ClientPlayContext c2s() { return ClientPlayPacketHandler.get(); } @@ -41,8 +40,7 @@ static PacketSender c2s() { * @see PlayPackets#registerClientChannel(ResourceLocation) * @see PlayPackets#registerClientChannel(CustomPacketPayload.Type, StreamCodec) */ - @ApiSide.ServerOnly - static PacketSender s2c(ServerPlayer player) { + static ServerPlayContext s2c(ServerPlayer player) { return ServerPlayPacketHandler.get(player); } @@ -51,8 +49,8 @@ static PacketSender s2c(ServerPlayer player) { *

* Note: Only works for Bad Packets channels. * - * @see PlayPackets#registerClientReadyCallback(ClientPlayPacketReadyCallback) - * @see PlayPackets#registerServerReadyCallback(ServerPlayPacketReadyCallback) + * @see PlayPackets#registerClientReadyCallback(PacketReadyCallback) + * @see PlayPackets#registerServerReadyCallback(PacketReadyCallback) */ boolean canSend(ResourceLocation id); @@ -61,8 +59,8 @@ static PacketSender s2c(ServerPlayer player) { *

* Note: Only works for Bad Packets channels. * - * @see PlayPackets#registerClientReadyCallback(ClientPlayPacketReadyCallback) - * @see PlayPackets#registerServerReadyCallback(ServerPlayPacketReadyCallback) + * @see PlayPackets#registerClientReadyCallback(PacketReadyCallback) + * @see PlayPackets#registerServerReadyCallback(PacketReadyCallback) */ default boolean canSend(CustomPacketPayload.Type type) { return canSend(type.id()); diff --git a/src/main/java/lol/bai/badpackets/api/config/ClientConfigConnectionContext.java b/src/main/java/lol/bai/badpackets/api/config/ClientConfigContext.java similarity index 90% rename from src/main/java/lol/bai/badpackets/api/config/ClientConfigConnectionContext.java rename to src/main/java/lol/bai/badpackets/api/config/ClientConfigContext.java index 0c22405..4772c17 100644 --- a/src/main/java/lol/bai/badpackets/api/config/ClientConfigConnectionContext.java +++ b/src/main/java/lol/bai/badpackets/api/config/ClientConfigContext.java @@ -9,7 +9,7 @@ @ApiSide.ClientOnly @ApiStatus.NonExtendable -public interface ClientConfigConnectionContext extends PacketSender { +public interface ClientConfigContext extends PacketSender { Minecraft client(); diff --git a/src/main/java/lol/bai/badpackets/api/config/ClientConfigPacketReadyCallback.java b/src/main/java/lol/bai/badpackets/api/config/ClientConfigPacketReadyCallback.java deleted file mode 100644 index bb26302..0000000 --- a/src/main/java/lol/bai/badpackets/api/config/ClientConfigPacketReadyCallback.java +++ /dev/null @@ -1,11 +0,0 @@ -package lol.bai.badpackets.api.config; - -import lol.bai.badpackets.impl.marker.ApiSide; - -@ApiSide.ClientOnly -@FunctionalInterface -public interface ClientConfigPacketReadyCallback { - - void onConfig(ClientConfigConnectionContext context); - -} diff --git a/src/main/java/lol/bai/badpackets/api/config/ClientConfigPacketReceiver.java b/src/main/java/lol/bai/badpackets/api/config/ClientConfigPacketReceiver.java deleted file mode 100644 index f9aba39..0000000 --- a/src/main/java/lol/bai/badpackets/api/config/ClientConfigPacketReceiver.java +++ /dev/null @@ -1,18 +0,0 @@ -package lol.bai.badpackets.api.config; - -import lol.bai.badpackets.impl.marker.ApiSide; -import net.minecraft.resources.ResourceLocation; - -@ApiSide.ClientOnly -@FunctionalInterface -public interface ClientConfigPacketReceiver

{ - - /** - * Server-to-client packet receiver. - *

- * Can only reliably send packet when in a - * {@linkplain ConfigPackets#registerTask(ResourceLocation, ConfigTaskExecutor) task}. - */ - void receive(ClientConfigConnectionContext context, P payload); - -} diff --git a/src/main/java/lol/bai/badpackets/api/config/ConfigPackets.java b/src/main/java/lol/bai/badpackets/api/config/ConfigPackets.java index 9b07db6..ab85993 100644 --- a/src/main/java/lol/bai/badpackets/api/config/ConfigPackets.java +++ b/src/main/java/lol/bai/badpackets/api/config/ConfigPackets.java @@ -1,5 +1,7 @@ package lol.bai.badpackets.api.config; +import lol.bai.badpackets.api.PacketReadyCallback; +import lol.bai.badpackets.api.PacketReceiver; import lol.bai.badpackets.api.PacketSender; import lol.bai.badpackets.impl.handler.ServerConfigPacketHandler; import lol.bai.badpackets.impl.marker.ApiSide; @@ -33,37 +35,61 @@ public static void registerTask(ResourceLocation id, ConfigTaskExecutor executor ServerConfigPacketHandler.registerTask(id, executor); } + /** + * Register a client-to-server packet channel. + *

+ * This method needs to be called on all sides. + *

+ * Register the receiver on server side with {@link #registerServerReceiver(ResourceLocation, PacketReceiver)} + * + * @param id the packet id + */ + public static void registerServerChannel(ResourceLocation id) { + ChannelRegistry.CONFIG_C2S.registerCodec(id, UntypedPayload.codec(id)); + } + + /** + * Register a client-to-server packet channel. + *

+ * This method needs to be called on all sides. + *

+ * Register the receiver on server side with {@link #registerServerReceiver(CustomPacketPayload.Type, PacketReceiver)} + * + * @param type the {@linkplain CustomPacketPayload#type() packet type} + * @param codec the payload codec + */ + public static

void registerServerChannel(CustomPacketPayload.Type

type, StreamCodec codec) { + ChannelRegistry.CONFIG_C2S.registerCodec(type.id(), codec); + } + /** * Register a client-to-server packet receiver. *

+ * The channel needs to be {@linkplain #registerServerChannel(ResourceLocation) registered} first. + *

* Raw packet receiver is run on Netty event-loop. Read the buffer on it and run - * the operation on {@linkplain MinecraftServer#execute(Runnable) server thread}. + * the operation on {@linkplain MinecraftServer#execute(Runnable) client thread}. * * @param id the packet id * @param receiver the receiver - * - * @see ServerConfigPacketReceiver#receive */ - public static void registerServerChannel(ResourceLocation id, ServerConfigPacketReceiver receiver) { - ChannelRegistry.CONFIG_C2S.registerCodec(id, UntypedPayload.codec(id)); + public static void registerServerReceiver(ResourceLocation id, PacketReceiver receiver) { ChannelRegistry.CONFIG_C2S.registerReceiver(id, (context, payload) -> receiver.receive(context, ((UntypedPayload) payload).buffer())); } /** * Register a client-to-server packet receiver. *

+ * The channel needs to be {@linkplain #registerServerChannel(CustomPacketPayload.Type, StreamCodec) registered} first. + *

* Typed packet receiver is run on the main server thread. * * @param type the {@linkplain CustomPacketPayload#type() packet type} - * @param codec the payload codec * @param receiver the receiver - * - * @see ServerConfigPacketReceiver#receive */ @SuppressWarnings("unchecked") - public static

void registerServerChannel(CustomPacketPayload.Type

type, StreamCodec codec, ServerConfigPacketReceiver

receiver) { - ChannelRegistry.CONFIG_C2S.registerCodec(type.id(), codec); - ChannelRegistry.CONFIG_C2S.registerReceiver(type.id(), (ServerConfigPacketReceiver) receiver); + public static

void registerServerReceiver(CustomPacketPayload.Type

type, PacketReceiver receiver) { + ChannelRegistry.CONFIG_C2S.registerReceiver(type.id(), (PacketReceiver) receiver); } /** @@ -73,17 +99,16 @@ public static

void registerServerChannel(CustomP *

* Not a general-purpose player join callback, use platform specific API for that. */ - @ApiSide.ServerOnly - public static void registerServerReadyCallback(ServerConfigPacketReadyCallback callback) { + public static void registerServerReadyCallback(PacketReadyCallback callback) { CallbackRegistry.SERVER_READY_CONFIG.add(callback); } /** - * Register a server-to-client packet receiver. + * Register a server-to-client packet channel. *

* This method needs to be called on all sides. *

- * Register the receiver on client side with {@link #registerClientReceiver(ResourceLocation, ClientConfigPacketReceiver)} + * Register the receiver on client side with {@link #registerClientReceiver(ResourceLocation, PacketReceiver)} * * @param id the packet id */ @@ -92,11 +117,11 @@ public static void registerClientChannel(ResourceLocation id) { } /** - * Register a server-to-client packet receiver. + * Register a server-to-client packet channel. *

* This method needs to be called on all sides. *

- * Register the receiver on client side with {@link #registerClientReceiver(CustomPacketPayload.Type, ClientConfigPacketReceiver)} + * Register the receiver on client side with {@link #registerClientReceiver(CustomPacketPayload.Type, PacketReceiver)} * * @param type the {@linkplain CustomPacketPayload#type() packet type} * @param codec the payload codec @@ -115,12 +140,9 @@ public static

void registerClientChannel(CustomP * * @param id the packet id * @param receiver the receiver - * - * @see ClientConfigPacketReceiver#receive - * @see #disconnect */ @ApiSide.ClientOnly - public static void registerClientReceiver(ResourceLocation id, ClientConfigPacketReceiver receiver) { + public static void registerClientReceiver(ResourceLocation id, PacketReceiver receiver) { ChannelRegistry.CONFIG_S2C.registerReceiver(id, (context, payload) -> receiver.receive(context, ((UntypedPayload) payload).buffer())); } @@ -133,14 +155,11 @@ public static void registerClientReceiver(ResourceLocation id, ClientConfigPacke * * @param type the {@linkplain CustomPacketPayload#type() packet type} * @param receiver the receiver - * - * @see ClientConfigPacketReceiver#receive - * @see #disconnect */ @ApiSide.ClientOnly @SuppressWarnings("unchecked") - public static

void registerClientReceiver(CustomPacketPayload.Type

type, ClientConfigPacketReceiver

receiver) { - ChannelRegistry.CONFIG_S2C.registerReceiver(type.id(), (ClientConfigPacketReceiver) receiver); + public static

void registerClientReceiver(CustomPacketPayload.Type

type, PacketReceiver receiver) { + ChannelRegistry.CONFIG_S2C.registerReceiver(type.id(), (PacketReceiver) receiver); } /** @@ -153,7 +172,7 @@ public static

void registerClientReceiver(Custom * @see #disconnect */ @ApiSide.ClientOnly - public static void registerClientReadyCallback(ClientConfigPacketReadyCallback callback) { + public static void registerClientReadyCallback(PacketReadyCallback callback) { CallbackRegistry.CLIENT_READY_CONFIG.add(callback); } @@ -161,7 +180,7 @@ public static void registerClientReadyCallback(ClientConfigPacketReadyCallback c * Helper method to disconnect client-to-server connection. * * @param handler the handler instance - * @param reason the disconnection reason + * @param reason the disconnection reason */ @ApiSide.ClientOnly public static void disconnect(ClientConfigurationPacketListenerImpl handler, Component reason) { diff --git a/src/main/java/lol/bai/badpackets/api/config/ConfigTaskExecutor.java b/src/main/java/lol/bai/badpackets/api/config/ConfigTaskExecutor.java index a1076c6..64620c1 100644 --- a/src/main/java/lol/bai/badpackets/api/config/ConfigTaskExecutor.java +++ b/src/main/java/lol/bai/badpackets/api/config/ConfigTaskExecutor.java @@ -1,6 +1,5 @@ package lol.bai.badpackets.api.config; -import lol.bai.badpackets.api.PacketSender; import net.minecraft.resources.ResourceLocation; @FunctionalInterface @@ -9,13 +8,13 @@ public interface ConfigTaskExecutor { /** * Return whether the task is run or not. *

- * Make use of {@link PacketSender#canSend(ResourceLocation)} to check whether the client can process the task, + * Make use of {@link ServerConfigContext#canSend(ResourceLocation)} to check whether the client can process the task, * and return {@code false} otherwise. *

* Once the client received the task packet, it should send a response packet to the server. - * After the server received the response packet, it should call {@link ServerConfigConnectionContext#finishTask(ResourceLocation)} + * After the server received the response packet, it should call {@link ServerConfigContext#finishTask(ResourceLocation)} * to allow the client to join the server. */ - boolean runTask(ServerConfigConnectionContext context); + boolean runTask(ServerConfigContext context); } diff --git a/src/main/java/lol/bai/badpackets/api/config/ServerConfigConnectionContext.java b/src/main/java/lol/bai/badpackets/api/config/ServerConfigContext.java similarity index 86% rename from src/main/java/lol/bai/badpackets/api/config/ServerConfigConnectionContext.java rename to src/main/java/lol/bai/badpackets/api/config/ServerConfigContext.java index b18b6bf..54aade7 100644 --- a/src/main/java/lol/bai/badpackets/api/config/ServerConfigConnectionContext.java +++ b/src/main/java/lol/bai/badpackets/api/config/ServerConfigContext.java @@ -7,7 +7,7 @@ import org.jetbrains.annotations.ApiStatus; @ApiStatus.NonExtendable -public interface ServerConfigConnectionContext extends PacketSender { +public interface ServerConfigContext extends PacketSender { MinecraftServer server(); diff --git a/src/main/java/lol/bai/badpackets/api/config/ServerConfigPacketReadyCallback.java b/src/main/java/lol/bai/badpackets/api/config/ServerConfigPacketReadyCallback.java deleted file mode 100644 index 7b7b4df..0000000 --- a/src/main/java/lol/bai/badpackets/api/config/ServerConfigPacketReadyCallback.java +++ /dev/null @@ -1,11 +0,0 @@ -package lol.bai.badpackets.api.config; - -import lol.bai.badpackets.impl.marker.ApiSide; - -@ApiSide.ServerOnly -@FunctionalInterface -public interface ServerConfigPacketReadyCallback { - - void onConfig(ServerConfigConnectionContext context); - -} diff --git a/src/main/java/lol/bai/badpackets/api/config/ServerConfigPacketReceiver.java b/src/main/java/lol/bai/badpackets/api/config/ServerConfigPacketReceiver.java deleted file mode 100644 index 21de61f..0000000 --- a/src/main/java/lol/bai/badpackets/api/config/ServerConfigPacketReceiver.java +++ /dev/null @@ -1,16 +0,0 @@ -package lol.bai.badpackets.api.config; - -import net.minecraft.resources.ResourceLocation; - -@FunctionalInterface -public interface ServerConfigPacketReceiver

{ - - /** - * Client-to-server packet receiver. - *

- * Can only reliably send packet when in a - * {@linkplain ConfigPackets#registerTask(ResourceLocation, ConfigTaskExecutor) task}. - */ - void receive(ServerConfigConnectionContext context, P payload); - -} diff --git a/src/main/java/lol/bai/badpackets/api/play/ClientPlayConnectionContext.java b/src/main/java/lol/bai/badpackets/api/play/ClientPlayContext.java similarity index 84% rename from src/main/java/lol/bai/badpackets/api/play/ClientPlayConnectionContext.java rename to src/main/java/lol/bai/badpackets/api/play/ClientPlayContext.java index c365aac..13e4fe7 100644 --- a/src/main/java/lol/bai/badpackets/api/play/ClientPlayConnectionContext.java +++ b/src/main/java/lol/bai/badpackets/api/play/ClientPlayContext.java @@ -8,7 +8,7 @@ @ApiSide.ClientOnly @ApiStatus.NonExtendable -public interface ClientPlayConnectionContext extends PacketSender { +public interface ClientPlayContext extends PacketSender { Minecraft client(); diff --git a/src/main/java/lol/bai/badpackets/api/play/ClientPlayPacketReadyCallback.java b/src/main/java/lol/bai/badpackets/api/play/ClientPlayPacketReadyCallback.java deleted file mode 100644 index 70497bc..0000000 --- a/src/main/java/lol/bai/badpackets/api/play/ClientPlayPacketReadyCallback.java +++ /dev/null @@ -1,11 +0,0 @@ -package lol.bai.badpackets.api.play; - -import lol.bai.badpackets.impl.marker.ApiSide; - -@ApiSide.ClientOnly -@FunctionalInterface -public interface ClientPlayPacketReadyCallback { - - void onReady(ClientPlayConnectionContext context); - -} diff --git a/src/main/java/lol/bai/badpackets/api/play/ClientPlayPacketReceiver.java b/src/main/java/lol/bai/badpackets/api/play/ClientPlayPacketReceiver.java deleted file mode 100644 index 52a92eb..0000000 --- a/src/main/java/lol/bai/badpackets/api/play/ClientPlayPacketReceiver.java +++ /dev/null @@ -1,11 +0,0 @@ -package lol.bai.badpackets.api.play; - -import lol.bai.badpackets.impl.marker.ApiSide; - -@ApiSide.ClientOnly -@FunctionalInterface -public interface ClientPlayPacketReceiver

{ - - void receive(ClientPlayConnectionContext context, P payload); - -} diff --git a/src/main/java/lol/bai/badpackets/api/play/PlayPackets.java b/src/main/java/lol/bai/badpackets/api/play/PlayPackets.java index 84292ba..1c155d6 100644 --- a/src/main/java/lol/bai/badpackets/api/play/PlayPackets.java +++ b/src/main/java/lol/bai/badpackets/api/play/PlayPackets.java @@ -1,5 +1,7 @@ package lol.bai.badpackets.api.play; +import lol.bai.badpackets.api.PacketReadyCallback; +import lol.bai.badpackets.api.PacketReceiver; import lol.bai.badpackets.api.PacketSender; import lol.bai.badpackets.impl.marker.ApiSide; import lol.bai.badpackets.impl.payload.UntypedPayload; @@ -21,30 +23,58 @@ public final class PlayPackets { /** * Register a client-to-server packet channel. *

+ * This method needs to be called on all sides. + *

+ * Register the receiver on server side with {@link #registerServerReceiver(ResourceLocation, PacketReceiver)} + * + * @param id the packet id + */ + public static void registerServerChannel(ResourceLocation id) { + ChannelRegistry.PLAY_C2S.registerCodec(id, UntypedPayload.codec(id)); + } + + /** + * Register a client-to-server packet channel. + *

+ * This method needs to be called on all sides. + *

+ * Register the receiver on server side with {@link #registerServerReceiver(CustomPacketPayload.Type, PacketReceiver)} + * + * @param type the {@linkplain CustomPacketPayload#type() packet type} + * @param codec the payload codec + */ + public static

void registerServerChannel(CustomPacketPayload.Type

type, StreamCodec codec) { + ChannelRegistry.PLAY_C2S.registerCodec(type.id(), codec); + } + + /** + * Register a server-to-client packet receiver. + *

+ * The channel needs to be {@linkplain #registerServerChannel(ResourceLocation) registered} first. + *

* Raw packet receiver is run on Netty event-loop. Read the buffer on it and run * the operation on {@linkplain MinecraftServer#execute(Runnable) server thread}. * * @param id the packet id * @param receiver the receiver */ - public static void registerServerChannel(ResourceLocation id, ServerPlayPacketReceiver receiver) { - ChannelRegistry.PLAY_C2S.registerCodec(id, UntypedPayload.codec(id)); + public static void registerServerReceiver(ResourceLocation id, PacketReceiver receiver) { ChannelRegistry.PLAY_C2S.registerReceiver(id, (context, payload) -> receiver.receive(context, ((UntypedPayload) payload).buffer())); } /** - * Register a client-to-server packet channel. + * Register a client-to-server packet receiver. + *

+ * The channel needs to be {@linkplain #registerServerChannel(CustomPacketPayload.Type, StreamCodec) registered} first. *

* Typed packet receiver is run on the main server thread. * * @param type the {@linkplain CustomPacketPayload#type() packet type} - * @param codec the payload codec * @param receiver the receiver */ @SuppressWarnings("unchecked") - public static

void registerServerChannel(CustomPacketPayload.Type

type, StreamCodec codec, ServerPlayPacketReceiver

receiver) { - ChannelRegistry.PLAY_C2S.registerCodec(type.id(), codec); - ChannelRegistry.PLAY_C2S.registerReceiver(type.id(), (ServerPlayPacketReceiver) receiver); + public static

void registerServerReceiver(CustomPacketPayload.Type

type, PacketReceiver receiver) { + ChannelRegistry.PLAY_C2S.registerReceiver(type.id(), (PacketReceiver) receiver); } /** @@ -54,7 +84,7 @@ public static

void registerServerChannel(CustomP *

* Not a general-purpose player join callback, use platform specific API for that. */ - public static void registerServerReadyCallback(ServerPlayPacketReadyCallback callback) { + public static void registerServerReadyCallback(PacketReadyCallback callback) { CallbackRegistry.SERVER_PLAY.add(callback); } @@ -63,7 +93,7 @@ public static void registerServerReadyCallback(ServerPlayPacketReadyCallback cal *

* This method needs to be called on all sides. *

- * Register the receiver on client side with {@link #registerClientReceiver(ResourceLocation, ClientPlayPacketReceiver)} + * Register the receiver on client side with {@link #registerClientReceiver(ResourceLocation, PacketReceiver)} * * @param id the packet id */ @@ -76,7 +106,7 @@ public static void registerClientChannel(ResourceLocation id) { *

* This method needs to be called on all sides. *

- * Register the receiver on client side with {@link #registerClientReceiver(CustomPacketPayload.Type, ClientPlayPacketReceiver)} + * Register the receiver on client side with {@link #registerClientReceiver(CustomPacketPayload.Type, PacketReceiver)} * * @param type the {@linkplain CustomPacketPayload#type() packet type} * @param codec the payload codec @@ -97,7 +127,7 @@ public static

void registerClientChannel(CustomP * @param receiver the receiver */ @ApiSide.ClientOnly - public static void registerClientReceiver(ResourceLocation id, ClientPlayPacketReceiver receiver) { + public static void registerClientReceiver(ResourceLocation id, PacketReceiver receiver) { ChannelRegistry.PLAY_S2C.registerReceiver(id, (context, payload) -> receiver.receive(context, ((UntypedPayload) payload).buffer())); } @@ -113,8 +143,8 @@ public static void registerClientReceiver(ResourceLocation id, ClientPlayPacketR */ @ApiSide.ClientOnly @SuppressWarnings("unchecked") - public static

void registerClientReceiver(CustomPacketPayload.Type

type, ClientPlayPacketReceiver

receiver) { - ChannelRegistry.PLAY_S2C.registerReceiver(type.id(), (ClientPlayPacketReceiver) receiver); + public static

void registerClientReceiver(CustomPacketPayload.Type

type, PacketReceiver receiver) { + ChannelRegistry.PLAY_S2C.registerReceiver(type.id(), (PacketReceiver) receiver); } /** @@ -125,7 +155,7 @@ public static

void registerClientReceiver(Custom * Not a general-purpose player join callback, use platform specific API for that. */ @ApiSide.ClientOnly - public static void registerClientReadyCallback(ClientPlayPacketReadyCallback callback) { + public static void registerClientReadyCallback(PacketReadyCallback callback) { CallbackRegistry.CLIENT_PLAY.add(callback); } diff --git a/src/main/java/lol/bai/badpackets/api/play/ServerPlayConnectionContext.java b/src/main/java/lol/bai/badpackets/api/play/ServerPlayContext.java similarity index 86% rename from src/main/java/lol/bai/badpackets/api/play/ServerPlayConnectionContext.java rename to src/main/java/lol/bai/badpackets/api/play/ServerPlayContext.java index 77267ed..a9de0bc 100644 --- a/src/main/java/lol/bai/badpackets/api/play/ServerPlayConnectionContext.java +++ b/src/main/java/lol/bai/badpackets/api/play/ServerPlayContext.java @@ -7,7 +7,7 @@ import org.jetbrains.annotations.ApiStatus; @ApiStatus.NonExtendable -public interface ServerPlayConnectionContext extends PacketSender { +public interface ServerPlayContext extends PacketSender { MinecraftServer server(); diff --git a/src/main/java/lol/bai/badpackets/api/play/ServerPlayPacketReadyCallback.java b/src/main/java/lol/bai/badpackets/api/play/ServerPlayPacketReadyCallback.java deleted file mode 100644 index 578e7c7..0000000 --- a/src/main/java/lol/bai/badpackets/api/play/ServerPlayPacketReadyCallback.java +++ /dev/null @@ -1,8 +0,0 @@ -package lol.bai.badpackets.api.play; - -@FunctionalInterface -public interface ServerPlayPacketReadyCallback { - - void onReady(ServerPlayConnectionContext context); - -} diff --git a/src/main/java/lol/bai/badpackets/api/play/ServerPlayPacketReceiver.java b/src/main/java/lol/bai/badpackets/api/play/ServerPlayPacketReceiver.java deleted file mode 100644 index c5afc3f..0000000 --- a/src/main/java/lol/bai/badpackets/api/play/ServerPlayPacketReceiver.java +++ /dev/null @@ -1,8 +0,0 @@ -package lol.bai.badpackets.api.play; - -@FunctionalInterface -public interface ServerPlayPacketReceiver

{ - - void receive(ServerPlayConnectionContext context, P payload); - -} diff --git a/src/main/java/lol/bai/badpackets/impl/handler/AbstractPacketHandler.java b/src/main/java/lol/bai/badpackets/impl/handler/AbstractPacketHandler.java index aa6b756..3ed71d0 100644 --- a/src/main/java/lol/bai/badpackets/impl/handler/AbstractPacketHandler.java +++ b/src/main/java/lol/bai/badpackets/impl/handler/AbstractPacketHandler.java @@ -11,6 +11,7 @@ import java.util.stream.Collectors; import io.netty.buffer.Unpooled; +import lol.bai.badpackets.api.PacketReceiver; import lol.bai.badpackets.api.PacketSender; import lol.bai.badpackets.impl.Constants; import lol.bai.badpackets.impl.payload.UntypedPayload; @@ -27,9 +28,9 @@ import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.Nullable; -public abstract class AbstractPacketHandler implements PacketSender { +public abstract class AbstractPacketHandler implements PacketSender { - protected final ChannelRegistry registry; + protected final ChannelRegistry registry; protected final Logger logger; private final Function> packetFactory; @@ -40,7 +41,7 @@ public abstract class AbstractPacketHandler implem private boolean initialized = false; - protected AbstractPacketHandler(String desc, ChannelRegistry registry, Function> packetFactory, BlockableEventLoop eventLoop, Connection connection) { + protected AbstractPacketHandler(String desc, ChannelRegistry registry, Function> packetFactory, BlockableEventLoop eventLoop, Connection connection) { this.logger = LogManager.getLogger(desc); this.registry = registry; this.packetFactory = packetFactory; @@ -81,7 +82,7 @@ public boolean receive(CustomPacketPayload payload) { if (registry.has(id)) { try { - R receiver = registry.get(id); + PacketReceiver receiver = registry.get(id); if (payload instanceof UntypedPayload || eventLoop.isSameThread()) { receiveUnsafe(receiver, payload); @@ -100,7 +101,7 @@ public boolean receive(CustomPacketPayload payload) { protected abstract void onInitialChannelSyncPacketReceived(); - protected abstract void receiveUnsafe(R receiver, CustomPacketPayload payload); + protected abstract void receiveUnsafe(PacketReceiver receiver, CustomPacketPayload payload); public void sendInitialChannelSyncPacket() { if (!initialized) { diff --git a/src/main/java/lol/bai/badpackets/impl/handler/ClientConfigPacketHandler.java b/src/main/java/lol/bai/badpackets/impl/handler/ClientConfigPacketHandler.java index 7681831..a45c2b7 100644 --- a/src/main/java/lol/bai/badpackets/impl/handler/ClientConfigPacketHandler.java +++ b/src/main/java/lol/bai/badpackets/impl/handler/ClientConfigPacketHandler.java @@ -3,9 +3,8 @@ import java.util.Set; import java.util.function.Consumer; -import lol.bai.badpackets.api.config.ClientConfigConnectionContext; -import lol.bai.badpackets.api.config.ClientConfigPacketReadyCallback; -import lol.bai.badpackets.api.config.ClientConfigPacketReceiver; +import lol.bai.badpackets.api.PacketReceiver; +import lol.bai.badpackets.api.config.ClientConfigContext; import lol.bai.badpackets.api.config.ConfigPackets; import lol.bai.badpackets.impl.platform.PlatformProxy; import lol.bai.badpackets.impl.registry.CallbackRegistry; @@ -20,7 +19,7 @@ import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; -public class ClientConfigPacketHandler extends AbstractPacketHandler, FriendlyByteBuf> implements ClientConfigConnectionContext { +public class ClientConfigPacketHandler extends AbstractPacketHandler implements ClientConfigContext { private final Minecraft client; private final ClientConfigurationPacketListenerImpl listener; @@ -39,15 +38,15 @@ protected Packet createVanillaRegisterPacket(Set channels, @Override protected void onInitialChannelSyncPacketReceived() { - for (ClientConfigPacketReadyCallback callback : CallbackRegistry.CLIENT_READY_CONFIG) { - callback.onConfig(this); + for (var callback : CallbackRegistry.CLIENT_READY_CONFIG) { + callback.onReady(this); } sendInitialChannelSyncPacket(); } @Override - protected void receiveUnsafe(ClientConfigPacketReceiver receiver, CustomPacketPayload payload) { + protected void receiveUnsafe(PacketReceiver receiver, CustomPacketPayload payload) { receiver.receive(this, payload); } diff --git a/src/main/java/lol/bai/badpackets/impl/handler/ClientPlayPacketHandler.java b/src/main/java/lol/bai/badpackets/impl/handler/ClientPlayPacketHandler.java index 1e3ce49..67d8e5f 100644 --- a/src/main/java/lol/bai/badpackets/impl/handler/ClientPlayPacketHandler.java +++ b/src/main/java/lol/bai/badpackets/impl/handler/ClientPlayPacketHandler.java @@ -3,9 +3,8 @@ import java.util.Set; import java.util.function.Consumer; -import lol.bai.badpackets.api.play.ClientPlayConnectionContext; -import lol.bai.badpackets.api.play.ClientPlayPacketReadyCallback; -import lol.bai.badpackets.api.play.ClientPlayPacketReceiver; +import lol.bai.badpackets.api.PacketReceiver; +import lol.bai.badpackets.api.play.ClientPlayContext; import lol.bai.badpackets.impl.platform.PlatformProxy; import lol.bai.badpackets.impl.registry.CallbackRegistry; import lol.bai.badpackets.impl.registry.ChannelRegistry; @@ -17,7 +16,7 @@ import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; -public class ClientPlayPacketHandler extends AbstractPacketHandler, RegistryFriendlyByteBuf> implements ClientPlayConnectionContext { +public class ClientPlayPacketHandler extends AbstractPacketHandler implements ClientPlayContext { private final Minecraft client; private final ClientPacketListener listener; @@ -46,13 +45,13 @@ protected Packet createVanillaRegisterPacket(Set channels, @Override protected void onInitialChannelSyncPacketReceived() { sendInitialChannelSyncPacket(); - for (ClientPlayPacketReadyCallback callback : CallbackRegistry.CLIENT_PLAY) { + for (var callback : CallbackRegistry.CLIENT_PLAY) { callback.onReady(this); } } @Override - protected void receiveUnsafe(ClientPlayPacketReceiver receiver, CustomPacketPayload payload) { + protected void receiveUnsafe(PacketReceiver receiver, CustomPacketPayload payload) { receiver.receive(this, payload); } diff --git a/src/main/java/lol/bai/badpackets/impl/handler/ServerConfigPacketHandler.java b/src/main/java/lol/bai/badpackets/impl/handler/ServerConfigPacketHandler.java index 1920930..d0e9dc5 100644 --- a/src/main/java/lol/bai/badpackets/impl/handler/ServerConfigPacketHandler.java +++ b/src/main/java/lol/bai/badpackets/impl/handler/ServerConfigPacketHandler.java @@ -5,10 +5,9 @@ import java.util.Set; import java.util.function.Consumer; +import lol.bai.badpackets.api.PacketReceiver; import lol.bai.badpackets.api.config.ConfigTaskExecutor; -import lol.bai.badpackets.api.config.ServerConfigConnectionContext; -import lol.bai.badpackets.api.config.ServerConfigPacketReadyCallback; -import lol.bai.badpackets.api.config.ServerConfigPacketReceiver; +import lol.bai.badpackets.api.config.ServerConfigContext; import lol.bai.badpackets.impl.Constants; import lol.bai.badpackets.impl.platform.PlatformProxy; import lol.bai.badpackets.impl.registry.CallbackRegistry; @@ -25,7 +24,7 @@ import net.minecraft.server.network.ServerConfigurationPacketListenerImpl; import org.jetbrains.annotations.NotNull; -public class ServerConfigPacketHandler extends AbstractPacketHandler, FriendlyByteBuf> implements ServerConfigConnectionContext { +public class ServerConfigPacketHandler extends AbstractPacketHandler implements ServerConfigContext { public static final Map CUSTOM_TASKS = new HashMap<>(); @@ -54,15 +53,15 @@ protected Packet createVanillaRegisterPacket(Set channels, @Override protected void onInitialChannelSyncPacketReceived() { - for (ServerConfigPacketReadyCallback callback : CallbackRegistry.SERVER_READY_CONFIG) { - callback.onConfig(this); + for (var callback : CallbackRegistry.SERVER_READY_CONFIG) { + callback.onReady(this); } ((TaskFinisher) listener).badpackets_finishTask(CallbackTask.TYPE); } @Override - protected void receiveUnsafe(ServerConfigPacketReceiver receiver, CustomPacketPayload payload) { + protected void receiveUnsafe(PacketReceiver receiver, CustomPacketPayload payload) { receiver.receive(this, payload); } diff --git a/src/main/java/lol/bai/badpackets/impl/handler/ServerPlayPacketHandler.java b/src/main/java/lol/bai/badpackets/impl/handler/ServerPlayPacketHandler.java index 2386a91..0966b33 100644 --- a/src/main/java/lol/bai/badpackets/impl/handler/ServerPlayPacketHandler.java +++ b/src/main/java/lol/bai/badpackets/impl/handler/ServerPlayPacketHandler.java @@ -3,9 +3,8 @@ import java.util.Set; import java.util.function.Consumer; -import lol.bai.badpackets.api.play.ServerPlayConnectionContext; -import lol.bai.badpackets.api.play.ServerPlayPacketReadyCallback; -import lol.bai.badpackets.api.play.ServerPlayPacketReceiver; +import lol.bai.badpackets.api.PacketReceiver; +import lol.bai.badpackets.api.play.ServerPlayContext; import lol.bai.badpackets.impl.platform.PlatformProxy; import lol.bai.badpackets.impl.registry.CallbackRegistry; import lol.bai.badpackets.impl.registry.ChannelRegistry; @@ -19,7 +18,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerGamePacketListenerImpl; -public class ServerPlayPacketHandler extends AbstractPacketHandler, RegistryFriendlyByteBuf> implements ServerPlayConnectionContext { +public class ServerPlayPacketHandler extends AbstractPacketHandler implements ServerPlayContext { private final MinecraftServer server; private final ServerGamePacketListenerImpl handler; @@ -41,13 +40,13 @@ protected Packet createVanillaRegisterPacket(Set channels, @Override protected void onInitialChannelSyncPacketReceived() { - for (ServerPlayPacketReadyCallback callback : CallbackRegistry.SERVER_PLAY) { + for (var callback : CallbackRegistry.SERVER_PLAY) { callback.onReady(this); } } @Override - protected void receiveUnsafe(ServerPlayPacketReceiver receiver, CustomPacketPayload payload) { + protected void receiveUnsafe(PacketReceiver receiver, CustomPacketPayload payload) { receiver.receive(this, payload); } diff --git a/src/main/java/lol/bai/badpackets/impl/marker/ApiSide.java b/src/main/java/lol/bai/badpackets/impl/marker/ApiSide.java index e9c6e5c..95a7f17 100644 --- a/src/main/java/lol/bai/badpackets/impl/marker/ApiSide.java +++ b/src/main/java/lol/bai/badpackets/impl/marker/ApiSide.java @@ -17,15 +17,4 @@ public class ApiSide { } - /** - * Anything that has this annotation means that it function only available on the logical server. - *

- * Marker only annotation, doesn't actually restrict access on runtime. - */ - @Documented - @Retention(RetentionPolicy.CLASS) - public @interface ServerOnly { - - } - } diff --git a/src/main/java/lol/bai/badpackets/impl/registry/CallbackRegistry.java b/src/main/java/lol/bai/badpackets/impl/registry/CallbackRegistry.java index 24bc937..b1bc6e9 100644 --- a/src/main/java/lol/bai/badpackets/impl/registry/CallbackRegistry.java +++ b/src/main/java/lol/bai/badpackets/impl/registry/CallbackRegistry.java @@ -2,17 +2,18 @@ import java.util.ArrayList; -import lol.bai.badpackets.api.config.ClientConfigPacketReadyCallback; -import lol.bai.badpackets.api.config.ServerConfigPacketReadyCallback; -import lol.bai.badpackets.api.play.ClientPlayPacketReadyCallback; -import lol.bai.badpackets.api.play.ServerPlayPacketReadyCallback; +import lol.bai.badpackets.api.PacketReadyCallback; +import lol.bai.badpackets.api.config.ClientConfigContext; +import lol.bai.badpackets.api.config.ServerConfigContext; +import lol.bai.badpackets.api.play.ClientPlayContext; +import lol.bai.badpackets.api.play.ServerPlayContext; public class CallbackRegistry { - public static final ArrayList CLIENT_READY_CONFIG = new ArrayList<>(); - public static final ArrayList SERVER_READY_CONFIG = new ArrayList<>(); + public static final ArrayList> CLIENT_READY_CONFIG = new ArrayList<>(); + public static final ArrayList> SERVER_READY_CONFIG = new ArrayList<>(); - public static final ArrayList CLIENT_PLAY = new ArrayList<>(); - public static final ArrayList SERVER_PLAY = new ArrayList<>(); + public static final ArrayList> CLIENT_PLAY = new ArrayList<>(); + public static final ArrayList> SERVER_PLAY = new ArrayList<>(); } diff --git a/src/main/java/lol/bai/badpackets/impl/registry/ChannelRegistry.java b/src/main/java/lol/bai/badpackets/impl/registry/ChannelRegistry.java index 746e617..8a5005f 100644 --- a/src/main/java/lol/bai/badpackets/impl/registry/ChannelRegistry.java +++ b/src/main/java/lol/bai/badpackets/impl/registry/ChannelRegistry.java @@ -7,10 +7,11 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantReadWriteLock; -import lol.bai.badpackets.api.config.ClientConfigPacketReceiver; -import lol.bai.badpackets.api.config.ServerConfigPacketReceiver; -import lol.bai.badpackets.api.play.ClientPlayPacketReceiver; -import lol.bai.badpackets.api.play.ServerPlayPacketReceiver; +import lol.bai.badpackets.api.PacketReceiver; +import lol.bai.badpackets.api.config.ClientConfigContext; +import lol.bai.badpackets.api.config.ServerConfigContext; +import lol.bai.badpackets.api.play.ClientPlayContext; +import lol.bai.badpackets.api.play.ServerPlayContext; import lol.bai.badpackets.impl.Constants; import lol.bai.badpackets.impl.handler.AbstractPacketHandler; import lol.bai.badpackets.impl.payload.UntypedPayload; @@ -21,24 +22,24 @@ import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.Nullable; -public class ChannelRegistry implements ChannelCodecFinder { +public class ChannelRegistry implements ChannelCodecFinder { private static final Set RESERVED_CHANNELS = Set.of( Constants.CHANNEL_SYNC, Constants.MC_REGISTER_CHANNEL, Constants.MC_UNREGISTER_CHANNEL); - public static final ChannelRegistry> CONFIG_S2C = new ChannelRegistry<>(RESERVED_CHANNELS); - public static final ChannelRegistry> CONFIG_C2S = new ChannelRegistry<>(RESERVED_CHANNELS); + public static final ChannelRegistry CONFIG_S2C = new ChannelRegistry<>(RESERVED_CHANNELS); + public static final ChannelRegistry CONFIG_C2S = new ChannelRegistry<>(RESERVED_CHANNELS); - public static final ChannelRegistry> PLAY_S2C = new ChannelRegistry<>(RESERVED_CHANNELS); - public static final ChannelRegistry> PLAY_C2S = new ChannelRegistry<>(RESERVED_CHANNELS); + public static final ChannelRegistry PLAY_S2C = new ChannelRegistry<>(RESERVED_CHANNELS); + public static final ChannelRegistry PLAY_C2S = new ChannelRegistry<>(RESERVED_CHANNELS); private final Set reservedChannels; private final Map> codecs = new HashMap<>(); - private final Map receivers = new HashMap<>(); - private final Set> handlers = new HashSet<>(); + private final Map> receivers = new HashMap<>(); + private final Set> handlers = new HashSet<>(); private final ReentrantReadWriteLock locks = new ReentrantReadWriteLock(); @@ -63,7 +64,7 @@ public

void registerCodec(ResourceLocation id, S } } - public void registerReceiver(ResourceLocation id, R receiver) { + public void registerReceiver(ResourceLocation id, PacketReceiver receiver) { Lock lock = locks.writeLock(); lock.lock(); @@ -73,7 +74,7 @@ public void registerReceiver(ResourceLocation id, R receiver) { } receivers.put(id, receiver); - for (AbstractPacketHandler handler : handlers) { + for (AbstractPacketHandler handler : handlers) { handler.onRegister(id); } } finally { @@ -92,7 +93,7 @@ public boolean has(ResourceLocation id) { } } - public R get(ResourceLocation id) { + public PacketReceiver get(ResourceLocation id) { Lock lock = locks.readLock(); lock.lock(); @@ -127,7 +128,7 @@ public Set getChannels() { } } - public void addHandler(AbstractPacketHandler handler) { + public void addHandler(AbstractPacketHandler handler) { Lock lock = locks.writeLock(); lock.lock(); @@ -138,7 +139,7 @@ public void addHandler(AbstractPacketHandler handler) { } } - public void removeHandler(AbstractPacketHandler handler) { + public void removeHandler(AbstractPacketHandler handler) { Lock lock = locks.writeLock(); lock.lock(); diff --git a/src/testmod/java/lol/bai/badpackets/test/BadPacketTest.java b/src/testmod/java/lol/bai/badpackets/test/BadPacketTest.java index 7b09b3b..c5fea3f 100644 --- a/src/testmod/java/lol/bai/badpackets/test/BadPacketTest.java +++ b/src/testmod/java/lol/bai/badpackets/test/BadPacketTest.java @@ -23,9 +23,12 @@ public class BadPacketTest { public static final Logger LOGGER = LoggerFactory.getLogger(BadPacketTest.class); - public static void server() { + public static void common() { // TASK -------------------------------------------------------------------------------------------------------- + ConfigPackets.registerServerChannel(TestTaskPayload.TYPE, TestTaskPayload.CODEC); + ConfigPackets.registerClientChannel(TestTaskPayload.TYPE, TestTaskPayload.CODEC); + ConfigPackets.registerTask(CONFIG_TASK, context -> { if (context.canSend(TestTaskPayload.TYPE)) { context.send(new TestTaskPayload(TestTaskPayload.Stage.QUESTION_1)); @@ -35,7 +38,7 @@ public static void server() { return false; }); - ConfigPackets.registerServerChannel(TestTaskPayload.TYPE, TestTaskPayload.CODEC, (context, payload) -> { + ConfigPackets.registerServerReceiver(TestTaskPayload.TYPE, (context, payload) -> { LOGGER.info("[config task] client -> server " + payload.stage().name()); switch (payload.stage()) { @@ -46,14 +49,17 @@ public static void server() { } }); - ConfigPackets.registerClientChannel(TestTaskPayload.TYPE, TestTaskPayload.CODEC); - // CONFIG ------------------------------------------------------------------------------------------------------ - ConfigPackets.registerServerChannel(CONFIG_C2S, (context, buf) -> + ConfigPackets.registerServerChannel(CONFIG_C2S); + ConfigPackets.registerClientChannel(CONFIG_S2C); + ConfigPackets.registerServerChannel(TestConfigPayload.TYPE, TestConfigPayload.CODEC); + ConfigPackets.registerClientChannel(TestConfigPayload.TYPE, TestConfigPayload.CODEC); + + ConfigPackets.registerServerReceiver(CONFIG_C2S, (context, buf) -> LOGGER.info(buf.readUtf())); - ConfigPackets.registerServerChannel(TestConfigPayload.TYPE, TestConfigPayload.CODEC, (context, payload) -> + ConfigPackets.registerServerReceiver(TestConfigPayload.TYPE, (context, payload) -> LOGGER.info(payload.msg())); ConfigPackets.registerServerReadyCallback(context -> { @@ -67,15 +73,17 @@ public static void server() { context.send(new TestConfigPayload("[config typed] server -> client")); }); - ConfigPackets.registerClientChannel(CONFIG_S2C); - ConfigPackets.registerClientChannel(TestConfigPayload.TYPE, TestConfigPayload.CODEC); - // PLAY -------------------------------------------------------------------------------------------------------- - PlayPackets.registerServerChannel(PLAY_C2S, (context, buf) -> + PlayPackets.registerServerChannel(PLAY_C2S); + PlayPackets.registerClientChannel(PLAY_S2C); + PlayPackets.registerServerChannel(TestPlayPayload.TYPE, TestPlayPayload.CODEC); + PlayPackets.registerClientChannel(TestPlayPayload.TYPE, TestPlayPayload.CODEC); + + PlayPackets.registerServerReceiver(PLAY_C2S, (context, buf) -> LOGGER.info(buf.readUtf())); - PlayPackets.registerServerChannel(TestPlayPayload.TYPE, TestPlayPayload.CODEC, (context, payload) -> + PlayPackets.registerServerReceiver(TestPlayPayload.TYPE, (context, payload) -> LOGGER.info(payload.msg())); PlayPackets.registerServerReadyCallback(context -> { @@ -89,8 +97,6 @@ public static void server() { context.send(new TestPlayPayload("[play typed] server -> client")); }); - PlayPackets.registerClientChannel(PLAY_S2C); - PlayPackets.registerClientChannel(TestPlayPayload.TYPE, TestPlayPayload.CODEC); } public static void client() {