From 45fcc9ef7d2728e3c444d654941e1d0b2b2eadbf Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 12 Feb 2023 21:14:10 +0100 Subject: [PATCH] Rename Protocol generics to be clearer --- .../api/protocol/AbstractProtocol.java | 58 +++++++++---------- .../viaversion/api/protocol/Protocol.java | 49 ++++++++-------- .../packet/mapping/PacketTypeMapping.java | 4 -- .../packet/provider/PacketTypesProvider.java | 9 +++ 4 files changed, 62 insertions(+), 58 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java index 67dc53958..e62090149 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java @@ -52,18 +52,18 @@ import org.checkerframework.checker.nullness.qual.Nullable; /** * Abstract protocol class to handle packet transformation between two protocol versions. * - * @param unmapped clientbound packet type - * @param mapped clientbound packet type - * @param mapped serverbound packet type - * @param unmapped serverbound packet type + * @param unmapped clientbound packet type + * @param mapped clientbound packet type + * @param mapped serverbound packet type + * @param unmapped serverbound packet type */ -public abstract class AbstractProtocol implements Protocol { - protected final Class unmappedClientboundPacketType; - protected final Class mappedClientboundPacketType; - protected final Class mappedServerboundPacketType; - protected final Class unmappedServerboundPacketType; - private final PacketTypesProvider packetTypesProvider; +public abstract class AbstractProtocol implements Protocol { + protected final Class unmappedClientboundPacketType; + protected final Class mappedClientboundPacketType; + protected final Class mappedServerboundPacketType; + protected final Class unmappedServerboundPacketType; + private final PacketTypesProvider packetTypesProvider; private final PacketMappings serverboundMappings = PacketMappings.arrayMappings(); private final PacketMappings clientboundMappings = PacketMappings.arrayMappings(); private final Map, Object> storedObjects = new HashMap<>(); @@ -76,8 +76,8 @@ public abstract class AbstractProtocol unmappedClientboundPacketType, @Nullable Class mappedClientboundPacketType, - @Nullable Class mappedServerboundPacketType, @Nullable Class unmappedServerboundPacketType) { + protected AbstractProtocol(@Nullable Class unmappedClientboundPacketType, @Nullable Class mappedClientboundPacketType, + @Nullable Class mappedServerboundPacketType, @Nullable Class unmappedServerboundPacketType) { this.unmappedClientboundPacketType = unmappedClientboundPacketType; this.mappedClientboundPacketType = mappedClientboundPacketType; this.mappedServerboundPacketType = mappedServerboundPacketType; @@ -162,7 +162,7 @@ public abstract class AbstractProtocol createPacketTypesProvider() { + protected PacketTypesProvider createPacketTypesProvider() { return new SimplePacketTypesProvider<>( packetTypeMap(unmappedClientboundPacketType), packetTypeMap(mappedClientboundPacketType), @@ -217,36 +217,36 @@ public abstract class AbstractProtocol mappedPacketTypes = packetTypesProvider.mappedClientboundPacketTypes().get(packetType.state()); - C2 mappedPacketType = mappedPacketType(packetType, mappedPacketTypes, unmappedClientboundPacketType, mappedClientboundPacketType); + public void registerClientbound(CU packetType, @Nullable PacketHandler handler) { + PacketTypeMap mappedPacketTypes = packetTypesProvider.mappedClientboundPacketTypes().get(packetType.state()); + CM mappedPacketType = mappedPacketType(packetType, mappedPacketTypes, unmappedClientboundPacketType, mappedClientboundPacketType); registerClientbound(packetType, mappedPacketType, handler); } @Override - public void registerClientbound(C1 packetType, @Nullable C2 mappedPacketType, @Nullable PacketHandler handler, boolean override) { + public void registerClientbound(CU packetType, @Nullable CM mappedPacketType, @Nullable PacketHandler handler, boolean override) { register(clientboundMappings, packetType, mappedPacketType, unmappedClientboundPacketType, mappedClientboundPacketType, handler, override); } @Override - public void cancelClientbound(C1 packetType) { + public void cancelClientbound(CU packetType) { registerClientbound(packetType, null, PacketWrapper::cancel); } @Override - public void registerServerbound(S2 packetType, @Nullable PacketHandler handler) { - PacketTypeMap mappedPacketTypes = packetTypesProvider.mappedServerboundPacketTypes().get(packetType.state()); - S1 mappedPacketType = mappedPacketType(packetType, mappedPacketTypes, unmappedServerboundPacketType, mappedServerboundPacketType); + public void registerServerbound(SU packetType, @Nullable PacketHandler handler) { + PacketTypeMap mappedPacketTypes = packetTypesProvider.mappedServerboundPacketTypes().get(packetType.state()); + SM mappedPacketType = mappedPacketType(packetType, mappedPacketTypes, unmappedServerboundPacketType, mappedServerboundPacketType); registerServerbound(packetType, mappedPacketType, handler); } @Override - public void registerServerbound(S2 packetType, @Nullable S1 mappedPacketType, @Nullable PacketHandler handler, boolean override) { + public void registerServerbound(SU packetType, @Nullable SM mappedPacketType, @Nullable PacketHandler handler, boolean override) { register(serverboundMappings, packetType, mappedPacketType, unmappedServerboundPacketType, mappedServerboundPacketType, handler, override); } @Override - public void cancelServerbound(S2 packetType) { + public void cancelServerbound(SU packetType) { registerServerbound(packetType, null, PacketWrapper::cancel); } @@ -350,13 +350,13 @@ public abstract class AbstractProtocol map = packetTypesProvider.unmappedClientboundPacketTypes().get(state); + private @Nullable CU unmappedClientboundPacketType(final State state, final int packetId) { + PacketTypeMap map = packetTypesProvider.unmappedClientboundPacketTypes().get(state); return map != null ? map.typeById(packetId) : null; } - private @Nullable S2 unmappedServerboundPacketType(final State state, final int packetId) { - PacketTypeMap map = packetTypesProvider.unmappedServerboundPacketTypes().get(state); + private @Nullable SU unmappedServerboundPacketType(final State state, final int packetId) { + PacketTypeMap map = packetTypesProvider.unmappedServerboundPacketTypes().get(state); return map != null ? map.typeById(packetId) : null; } @@ -387,7 +387,7 @@ public abstract class AbstractProtocol packetTypesProvider() { + public PacketTypesProvider packetTypesProvider() { return packetTypesProvider; } diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/Protocol.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/Protocol.java index 78e5dc4d6..de493719a 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/Protocol.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/Protocol.java @@ -40,13 +40,13 @@ import org.checkerframework.checker.nullness.qual.Nullable; * Abstract protocol class handling packet transformation between two protocol versions. * Clientbound and serverbount packet types can be set to enforce correct usage of them. * - * @param unmapped ("old") clientbound packet types - * @param mapped ("new") clientbound packet types - * @param mapped ("old") serverbound packet types - * @param unmapped ("new") serverbound packet types - * @see SimpleProtocol for a helper class if you do not want to define any of the types above + * @param unmapped clientbound packet types + * @param mapped clientbound packet types + * @param mapped serverbound packet types + * @param unmapped serverbound packet types + * @see SimpleProtocol for a helper class if you do not need to define any of the types above */ -public interface Protocol { +public interface Protocol { default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId) { registerServerbound(state, unmappedPacketId, mappedPacketId, (PacketHandler) null); @@ -100,7 +100,7 @@ public interface Protocol unmapped clientbound packet type + * @param mapped clientbound packet type + * @param mapped serverbound packet type + * @param unmapped serverbound packet type + * @see SimplePacketTypesProvider + */ public interface PacketTypesProvider { /**