From be61f70c8ac0eb0a720406e01c26ec6f03a9ff2f Mon Sep 17 00:00:00 2001 From: Sollace Date: Sun, 29 Sep 2024 19:22:26 +0100 Subject: [PATCH] Update code for the Handled<> class to use the new interface and deprecated the old methods as we have no way of updating them without breaking old code --- src/main/java/com/sollace/fabwork/api/packets/Handled.java | 6 ++---- .../java/com/sollace/fabwork/api/packets/HandledPacket.java | 2 ++ src/main/java/com/sollace/fabwork/api/packets/Packet.java | 2 ++ .../com/sollace/fabwork/api/packets/SimpleNetworking.java | 2 ++ .../java/com/sollace/fabwork/impl/packets/ReceiverImpl.java | 4 ++-- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sollace/fabwork/api/packets/Handled.java b/src/main/java/com/sollace/fabwork/api/packets/Handled.java index cf03dd6..8411692 100644 --- a/src/main/java/com/sollace/fabwork/api/packets/Handled.java +++ b/src/main/java/com/sollace/fabwork/api/packets/Handled.java @@ -11,9 +11,8 @@ * or if the packet class they're creating extends a pre-established * packet from the base game. *

- * Recommended approach is to use {@link HandledPacket} and override handle(sender) for server-bound - * packets and use {@link Packet} together with the receiver API - * to handle client-bound packets as this allows for better separation of client-specific code. + * Recommended approach is to use {@link Handled} and override handle(sender) for server-bound + * packets and use the receiver API to handle client-bound packets as this allows for better separation of client-specific code. * * @author Sollace */ @@ -24,7 +23,6 @@ public interface Handled { * Implementors may optionally override this method, * or register handlers using the receiver(). *

- * * @param sender The player who initially sent this packet. */ diff --git a/src/main/java/com/sollace/fabwork/api/packets/HandledPacket.java b/src/main/java/com/sollace/fabwork/api/packets/HandledPacket.java index 048a4ee..ddf61b0 100644 --- a/src/main/java/com/sollace/fabwork/api/packets/HandledPacket.java +++ b/src/main/java/com/sollace/fabwork/api/packets/HandledPacket.java @@ -16,6 +16,8 @@ * to handle client-bound packets as this allows for better separation of client-specific code. * * @author Sollace + * @deprecated The packet interface will be retired in 1.22. Use Handled instead. */ +@Deprecated public interface HandledPacket extends Packet, Handled { } \ No newline at end of file diff --git a/src/main/java/com/sollace/fabwork/api/packets/Packet.java b/src/main/java/com/sollace/fabwork/api/packets/Packet.java index 71b6fa8..a1cb5b9 100644 --- a/src/main/java/com/sollace/fabwork/api/packets/Packet.java +++ b/src/main/java/com/sollace/fabwork/api/packets/Packet.java @@ -11,7 +11,9 @@ * to handle client-bound packets as this allows for better separation of client-specific code. * * @author Sollace + * @deprecated The packet interface will be retired in 1.22. Use Handled instead. */ +@Deprecated public interface Packet { /** * Writes this packet to the supplied buffer prior to transmission. diff --git a/src/main/java/com/sollace/fabwork/api/packets/SimpleNetworking.java b/src/main/java/com/sollace/fabwork/api/packets/SimpleNetworking.java index 00c7a1c..5d72557 100644 --- a/src/main/java/com/sollace/fabwork/api/packets/SimpleNetworking.java +++ b/src/main/java/com/sollace/fabwork/api/packets/SimpleNetworking.java @@ -41,6 +41,7 @@ public interface SimpleNetworking { * * @return A registered PacketType */ + @Deprecated static C2SPacketType clientToServer(Identifier id, Function factory) { return clientToServer(id, PacketCodec.of(Packet::toBuffer, factory::apply)); } @@ -72,6 +73,7 @@ static C2SPacketType clientToServer(Identifier id, PacketCodec S2CPacketType serverToClient(Identifier id, Function factory) { return serverToClient(id, PacketCodec.of(Packet::toBuffer, factory::apply)); } diff --git a/src/main/java/com/sollace/fabwork/impl/packets/ReceiverImpl.java b/src/main/java/com/sollace/fabwork/impl/packets/ReceiverImpl.java index 84dc84a..15d01a7 100644 --- a/src/main/java/com/sollace/fabwork/impl/packets/ReceiverImpl.java +++ b/src/main/java/com/sollace/fabwork/impl/packets/ReceiverImpl.java @@ -39,9 +39,9 @@ public void addTemporaryListener(BiPredicate callback) { void onReceive(Sender sender, P packet) { persistentListeners.fire(sender, packet); listeners.fire(sender, packet); - if (packet instanceof HandledPacket) { + if (packet instanceof Handled handler) { try { - ((HandledPacket)packet).handle(sender); + handler.handle(sender); } catch (Exception e) { LOGGER.error("Exception whilst handling packet callback for handled packet " + id, e); }