From 40788a0cd6936a3e0e2e710e1ec790d9aaffc5b4 Mon Sep 17 00:00:00 2001 From: tahmid-23 <60953955+tahmid-23@users.noreply.github.com> Date: Sat, 15 Jul 2023 00:49:50 -0400 Subject: [PATCH] rewrite messaging to use one channel per packet --- core/build.gradle.kts | 1 + .../core}/packet/BinaryDataReader.java | 2 +- .../core}/packet/BinaryDataWriter.java | 7 +- .../core/packet/MinestomPacketUtils.java | 15 ++++ messaging/build.gradle.kts | 5 ++ .../phantazm/messaging/MessageChannels.java | 26 ------- .../org/phantazm/messaging/packet/Packet.java | 10 +-- .../messaging/packet/PacketHandler.java | 57 -------------- .../MapDataVersionQueryPacket.java | 11 ++- .../MapDataVersionResponsePacket.java | 11 ++- .../{c2s => server}/RoundStartPacket.java | 8 +- .../serialization/PacketSerializer.java | 69 ----------------- .../serialization/PacketSerializers.java | 43 ----------- server/build.gradle.kts | 1 - .../org/phantazm/server/MessagingFeature.java | 75 ------------------- .../org/phantazm/server/PhantazmServer.java | 1 - .../org/phantazm/server/ZombiesFeature.java | 10 +-- .../org/phantazm/velocity/PhantazmPlugin.java | 22 +++--- .../MaliciousPluginMessageBlocker.java | 15 ++-- .../listener/ProxyMessagingHandler.java | 47 +++++------- .../packet/ByteArrayInputDataReader.java | 5 ++ .../packet/ByteArrayOutputDataWriter.java | 5 ++ .../velocity/packet/VelocityPacketUtils.java | 24 ++++++ zombies-mapeditor/build.gradle.kts | 2 +- .../mapeditor/client/MapeditorClient.java | 72 +++++------------- .../client/packet/FabricPacketUtils.java | 39 ++++++++++ .../MapDataVersionResponsePacketWrapper.java | 31 ++++++++ .../packet/PacketByteBufDataWriter.java | 9 +++ .../client/packet/PhantazmPacket.java | 31 -------- zombies-timer/build.gradle.kts | 3 +- .../autosplits/ZombiesAutoSplitsClient.java | 28 +------ .../messaging/PhantazmMessagingHandler.java | 40 ---------- .../autosplits/packet/FabricPacketUtils.java | 39 ++++++++++ .../packet/PacketByteBufDataWriter.java | 9 +++ .../autosplits/packet/PhantazmPacket.java | 31 -------- .../packet/RoundStartPacketWrapper.java | 31 ++++++++ .../java/org/phantazm/zombies/map/Round.java | 13 ++-- .../map/objects/BasicMapObjectsSource.java | 9 +-- .../zombies/scene/ZombiesSceneProvider.java | 7 +- 39 files changed, 308 insertions(+), 556 deletions(-) rename {server/src/main/java/org/phantazm/server => core/src/main/java/org/phantazm/core}/packet/BinaryDataReader.java (96%) rename {server/src/main/java/org/phantazm/server => core/src/main/java/org/phantazm/core}/packet/BinaryDataWriter.java (76%) create mode 100644 core/src/main/java/org/phantazm/core/packet/MinestomPacketUtils.java delete mode 100644 messaging/src/main/java/org/phantazm/messaging/MessageChannels.java delete mode 100644 messaging/src/main/java/org/phantazm/messaging/packet/PacketHandler.java rename messaging/src/main/java/org/phantazm/messaging/packet/{c2p => player}/MapDataVersionQueryPacket.java (73%) rename messaging/src/main/java/org/phantazm/messaging/packet/{c2p => proxy}/MapDataVersionResponsePacket.java (76%) rename messaging/src/main/java/org/phantazm/messaging/packet/{c2s => server}/RoundStartPacket.java (70%) delete mode 100644 messaging/src/main/java/org/phantazm/messaging/serialization/PacketSerializer.java delete mode 100644 messaging/src/main/java/org/phantazm/messaging/serialization/PacketSerializers.java delete mode 100644 server/src/main/java/org/phantazm/server/MessagingFeature.java create mode 100644 velocity/src/main/java/org/phantazm/velocity/packet/VelocityPacketUtils.java create mode 100644 zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/packet/FabricPacketUtils.java create mode 100644 zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/packet/MapDataVersionResponsePacketWrapper.java delete mode 100644 zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/packet/PhantazmPacket.java delete mode 100644 zombies-timer/src/main/java/org/phantazm/zombies/autosplits/messaging/PhantazmMessagingHandler.java create mode 100644 zombies-timer/src/main/java/org/phantazm/zombies/autosplits/packet/FabricPacketUtils.java delete mode 100644 zombies-timer/src/main/java/org/phantazm/zombies/autosplits/packet/PhantazmPacket.java create mode 100644 zombies-timer/src/main/java/org/phantazm/zombies/autosplits/packet/RoundStartPacketWrapper.java diff --git a/core/build.gradle.kts b/core/build.gradle.kts index d4506a242..03247f58b 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -4,6 +4,7 @@ plugins { dependencies { api(projects.phantazmCommons) + api(projects.phantazmMessaging) api(libs.ethylene.core) api(libs.ethylene.mapper) api(libs.commons.lang3) diff --git a/server/src/main/java/org/phantazm/server/packet/BinaryDataReader.java b/core/src/main/java/org/phantazm/core/packet/BinaryDataReader.java similarity index 96% rename from server/src/main/java/org/phantazm/server/packet/BinaryDataReader.java rename to core/src/main/java/org/phantazm/core/packet/BinaryDataReader.java index 048db64a5..d45641bf8 100644 --- a/server/src/main/java/org/phantazm/server/packet/BinaryDataReader.java +++ b/core/src/main/java/org/phantazm/core/packet/BinaryDataReader.java @@ -1,4 +1,4 @@ -package org.phantazm.server.packet; +package org.phantazm.core.packet; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; diff --git a/server/src/main/java/org/phantazm/server/packet/BinaryDataWriter.java b/core/src/main/java/org/phantazm/core/packet/BinaryDataWriter.java similarity index 76% rename from server/src/main/java/org/phantazm/server/packet/BinaryDataWriter.java rename to core/src/main/java/org/phantazm/core/packet/BinaryDataWriter.java index ceee74737..46b667b0d 100644 --- a/server/src/main/java/org/phantazm/server/packet/BinaryDataWriter.java +++ b/core/src/main/java/org/phantazm/core/packet/BinaryDataWriter.java @@ -1,5 +1,6 @@ -package org.phantazm.server.packet; +package org.phantazm.core.packet; +import net.minestom.server.network.NetworkBuffer; import net.minestom.server.utils.binary.BinaryWriter; import org.jetbrains.annotations.NotNull; import org.phantazm.messaging.serialization.DataReader; @@ -23,6 +24,10 @@ public BinaryDataWriter(@NotNull BinaryWriter binaryWriter) { this.binaryWriter = Objects.requireNonNull(binaryWriter, "binaryWriter"); } + public static @NotNull BinaryDataWriter fromNetworkBuffer(@NotNull NetworkBuffer networkBuffer) { + return new BinaryDataWriter(new BinaryWriter(Objects.requireNonNull(networkBuffer, "networkBuffer"))); + } + @Override public void writeByte(byte data) { binaryWriter.writeByte(data); diff --git a/core/src/main/java/org/phantazm/core/packet/MinestomPacketUtils.java b/core/src/main/java/org/phantazm/core/packet/MinestomPacketUtils.java new file mode 100644 index 000000000..3aec8f816 --- /dev/null +++ b/core/src/main/java/org/phantazm/core/packet/MinestomPacketUtils.java @@ -0,0 +1,15 @@ +package org.phantazm.core.packet; + +import net.minestom.server.network.NetworkBuffer; +import org.jetbrains.annotations.NotNull; +import org.phantazm.messaging.packet.Packet; + +public class MinestomPacketUtils { + + public static byte @NotNull[] serialize(@NotNull Packet packet) { + return NetworkBuffer.makeArray(buffer -> { + packet.write(BinaryDataWriter.fromNetworkBuffer(buffer)); + }); + } + +} diff --git a/messaging/build.gradle.kts b/messaging/build.gradle.kts index 58f6acbb1..2aad065d7 100644 --- a/messaging/build.gradle.kts +++ b/messaging/build.gradle.kts @@ -1,3 +1,8 @@ plugins { id("phantazm.java-library-conventions") } + +dependencies { + implementation(projects.phantazmCommons) + api(libs.adventure.key) +} diff --git a/messaging/src/main/java/org/phantazm/messaging/MessageChannels.java b/messaging/src/main/java/org/phantazm/messaging/MessageChannels.java deleted file mode 100644 index 68304566e..000000000 --- a/messaging/src/main/java/org/phantazm/messaging/MessageChannels.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.phantazm.messaging; - -/** - * Contains shared message channel ID values. - * Message channels should use the 1.13+ namespaced key format. These constants represent the key's value. - */ -public final class MessageChannels { - - - /** - * The message channel between the proxy and a server. - */ - public static final String PROXY_TO_SERVER = "proxy2server"; - - /** - * The message channel between the client and a server. - */ - public static final String CLIENT_TO_SERVER = "client2server"; - - public static final String CLIENT_TO_PROXY = "client2proxy"; - - private MessageChannels() { - throw new UnsupportedOperationException(); - } - -} diff --git a/messaging/src/main/java/org/phantazm/messaging/packet/Packet.java b/messaging/src/main/java/org/phantazm/messaging/packet/Packet.java index 510116eac..cdeaa3ebd 100644 --- a/messaging/src/main/java/org/phantazm/messaging/packet/Packet.java +++ b/messaging/src/main/java/org/phantazm/messaging/packet/Packet.java @@ -1,5 +1,6 @@ package org.phantazm.messaging.packet; +import net.kyori.adventure.key.Key; import org.jetbrains.annotations.NotNull; import org.phantazm.messaging.serialization.DataWriter; @@ -8,14 +9,7 @@ */ public interface Packet { - /** - * Gets the ID of the packet. This should be unique for a single messaging channel. - * For example, all the packets in the proxy plugin messaging channel should be unique. - * However, they can share IDs with packets on other channels. - * - * @return The ID of the packet - */ - byte getId(); + @NotNull Key getId(); /** * Writes the packet to a {@link DataWriter}. diff --git a/messaging/src/main/java/org/phantazm/messaging/packet/PacketHandler.java b/messaging/src/main/java/org/phantazm/messaging/packet/PacketHandler.java deleted file mode 100644 index 48250f55b..000000000 --- a/messaging/src/main/java/org/phantazm/messaging/packet/PacketHandler.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.phantazm.messaging.packet; - -import org.jetbrains.annotations.NotNull; -import org.phantazm.messaging.serialization.PacketSerializer; - -import java.util.Objects; - -/** - * A wrapper around a {@link PacketSerializer} that simplifies binary data reading and writing. - * - * @param The type of output that packets will be sent to - */ -public abstract class PacketHandler { - - private final PacketSerializer packetSerializer; - - public PacketHandler(@NotNull PacketSerializer packetSerializer) { - this.packetSerializer = Objects.requireNonNull(packetSerializer, "packetSerializer"); - } - - /** - * Handles incoming binary data. - * - * @param outputReceiver The output receiver for any packets that will be sent as a result of receiving this data - * @param data The data that was sent - */ - public void handleData(@NotNull TOutputReceiver outputReceiver, byte @NotNull [] data) { - packetSerializer.deserializePacket(data).ifPresent(packet -> handlePacket(outputReceiver, packet)); - } - - /** - * Handles an incoming packet. - * - * @param outputReceiver The output receiver for any packets that will be sent as a result of receiving this packet - * @param packet The packet that was sent - */ - protected abstract void handlePacket(@NotNull TOutputReceiver outputReceiver, @NotNull Packet packet); - - /** - * Sends binary data to a receiver. - * - * @param outputReceiver The binary data receiver - * @param data The binary data to send - */ - protected abstract void sendToReceiver(@NotNull TOutputReceiver outputReceiver, byte @NotNull [] data); - - /** - * Sends an outgoing packet to the output receiver. - * - * @param outputReceiver The output receiver - * @param packet The packet to send - */ - public void output(@NotNull TOutputReceiver outputReceiver, @NotNull Packet packet) { - sendToReceiver(outputReceiver, packetSerializer.serializePacket(packet)); - } - -} diff --git a/messaging/src/main/java/org/phantazm/messaging/packet/c2p/MapDataVersionQueryPacket.java b/messaging/src/main/java/org/phantazm/messaging/packet/player/MapDataVersionQueryPacket.java similarity index 73% rename from messaging/src/main/java/org/phantazm/messaging/packet/c2p/MapDataVersionQueryPacket.java rename to messaging/src/main/java/org/phantazm/messaging/packet/player/MapDataVersionQueryPacket.java index 09d6e5568..0ed19070f 100644 --- a/messaging/src/main/java/org/phantazm/messaging/packet/c2p/MapDataVersionQueryPacket.java +++ b/messaging/src/main/java/org/phantazm/messaging/packet/player/MapDataVersionQueryPacket.java @@ -1,6 +1,8 @@ -package org.phantazm.messaging.packet.c2p; +package org.phantazm.messaging.packet.player; +import net.kyori.adventure.key.Key; import org.jetbrains.annotations.NotNull; +import org.phantazm.commons.Namespaces; import org.phantazm.messaging.packet.Packet; import org.phantazm.messaging.serialization.DataReader; import org.phantazm.messaging.serialization.DataWriter; @@ -12,10 +14,7 @@ */ public record MapDataVersionQueryPacket() implements Packet { - /** - * The ID of the {@link MapDataVersionQueryPacket}. - */ - public static final byte ID = 0; + public static final Key ID = Key.key(Namespaces.PHANTAZM, "client/mapdata_version_query"); public static @NotNull MapDataVersionQueryPacket read(@NotNull DataReader reader) { Objects.requireNonNull(reader, "reader"); @@ -23,7 +22,7 @@ public record MapDataVersionQueryPacket() implements Packet { } @Override - public byte getId() { + public @NotNull Key getId() { return ID; } diff --git a/messaging/src/main/java/org/phantazm/messaging/packet/c2p/MapDataVersionResponsePacket.java b/messaging/src/main/java/org/phantazm/messaging/packet/proxy/MapDataVersionResponsePacket.java similarity index 76% rename from messaging/src/main/java/org/phantazm/messaging/packet/c2p/MapDataVersionResponsePacket.java rename to messaging/src/main/java/org/phantazm/messaging/packet/proxy/MapDataVersionResponsePacket.java index 3df95f373..4f518c26e 100644 --- a/messaging/src/main/java/org/phantazm/messaging/packet/c2p/MapDataVersionResponsePacket.java +++ b/messaging/src/main/java/org/phantazm/messaging/packet/proxy/MapDataVersionResponsePacket.java @@ -1,6 +1,8 @@ -package org.phantazm.messaging.packet.c2p; +package org.phantazm.messaging.packet.proxy; +import net.kyori.adventure.key.Key; import org.jetbrains.annotations.NotNull; +import org.phantazm.commons.Namespaces; import org.phantazm.messaging.packet.Packet; import org.phantazm.messaging.serialization.DataReader; import org.phantazm.messaging.serialization.DataWriter; @@ -14,10 +16,7 @@ */ public record MapDataVersionResponsePacket(int version) implements Packet { - /** - * The ID of the {@link MapDataVersionResponsePacket}. - */ - public static final byte ID = 1; + public static final Key ID = Key.key(Namespaces.PHANTAZM, "proxy/mapdata_version_response"); public static @NotNull MapDataVersionResponsePacket read(@NotNull DataReader reader) { Objects.requireNonNull(reader, "reader"); @@ -25,7 +24,7 @@ public record MapDataVersionResponsePacket(int version) implements Packet { } @Override - public byte getId() { + public @NotNull Key getId() { return ID; } diff --git a/messaging/src/main/java/org/phantazm/messaging/packet/c2s/RoundStartPacket.java b/messaging/src/main/java/org/phantazm/messaging/packet/server/RoundStartPacket.java similarity index 70% rename from messaging/src/main/java/org/phantazm/messaging/packet/c2s/RoundStartPacket.java rename to messaging/src/main/java/org/phantazm/messaging/packet/server/RoundStartPacket.java index 9ed2553c8..9fdcb2d06 100644 --- a/messaging/src/main/java/org/phantazm/messaging/packet/c2s/RoundStartPacket.java +++ b/messaging/src/main/java/org/phantazm/messaging/packet/server/RoundStartPacket.java @@ -1,6 +1,8 @@ -package org.phantazm.messaging.packet.c2s; +package org.phantazm.messaging.packet.server; +import net.kyori.adventure.key.Key; import org.jetbrains.annotations.NotNull; +import org.phantazm.commons.Namespaces; import org.phantazm.messaging.packet.Packet; import org.phantazm.messaging.serialization.DataReader; import org.phantazm.messaging.serialization.DataWriter; @@ -9,7 +11,7 @@ public record RoundStartPacket() implements Packet { - public static final byte ID = 0; + public static final Key ID = Key.key(Namespaces.PHANTAZM, "server/round_start"); public static @NotNull RoundStartPacket read(@NotNull DataReader reader) { Objects.requireNonNull(reader, "reader"); @@ -17,7 +19,7 @@ public record RoundStartPacket() implements Packet { } @Override - public byte getId() { + public @NotNull Key getId() { return ID; } diff --git a/messaging/src/main/java/org/phantazm/messaging/serialization/PacketSerializer.java b/messaging/src/main/java/org/phantazm/messaging/serialization/PacketSerializer.java deleted file mode 100644 index 9b095f8d5..000000000 --- a/messaging/src/main/java/org/phantazm/messaging/serialization/PacketSerializer.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.phantazm.messaging.serialization; - -import org.jetbrains.annotations.NotNull; -import org.phantazm.messaging.packet.Packet; - -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.function.Function; -import java.util.function.Supplier; - -/** - * Converts packets from byte arrays to {@link Packet}s and vice versa. - */ -public class PacketSerializer { - - private final Map> packetDeserializerMap; - - private final Supplier writerCreator; - - private final Function readerCreator; - - /** - * Creates a {@link PacketSerializer}. - * - * @param packetDeserializerMap A {@link Map} of byte packet IDs to {@link Packet} creators from a {@link DataReader} - * @param writerCreator A creator for serialization {@link DataWriter}s - * @param readerCreator A creator for deserialization {@link DataReader}s - */ - public PacketSerializer(@NotNull Map> packetDeserializerMap, - @NotNull Supplier writerCreator, @NotNull Function readerCreator) { - this.packetDeserializerMap = Objects.requireNonNull(packetDeserializerMap, "packetDeserializerMap"); - this.writerCreator = Objects.requireNonNull(writerCreator, "writerCreator"); - this.readerCreator = Objects.requireNonNull(readerCreator, "readerCreator"); - } - - /** - * Serializes a packet into a byte array. - * - * @param packet The packet to serialize - * @return The byte array representation of the packet - */ - public byte[] serializePacket(@NotNull Packet packet) { - DataWriter dataWriter = writerCreator.get(); - dataWriter.writeByte(packet.getId()); - packet.write(dataWriter); - - return dataWriter.toByteArray(); - } - - /** - * Deserializes a packet from a byte array. - * - * @param bytes The byte array representation of the packet - * @return An {@link Optional} of the deserialized packet which is empty if deserialization fails - */ - public @NotNull Optional deserializePacket(byte @NotNull [] bytes) { - DataReader dataReader = readerCreator.apply(bytes); - byte id = dataReader.readByte(); - - Function deserializer = packetDeserializerMap.get(id); - if (deserializer == null) { - return Optional.empty(); - } - - return Optional.of(deserializer.apply(dataReader)); - } - -} diff --git a/messaging/src/main/java/org/phantazm/messaging/serialization/PacketSerializers.java b/messaging/src/main/java/org/phantazm/messaging/serialization/PacketSerializers.java deleted file mode 100644 index e1a24a449..000000000 --- a/messaging/src/main/java/org/phantazm/messaging/serialization/PacketSerializers.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.phantazm.messaging.serialization; - -import org.jetbrains.annotations.NotNull; -import org.phantazm.messaging.packet.Packet; -import org.phantazm.messaging.packet.c2p.MapDataVersionQueryPacket; -import org.phantazm.messaging.packet.c2p.MapDataVersionResponsePacket; -import org.phantazm.messaging.packet.c2s.RoundStartPacket; - -import java.util.Map; -import java.util.function.Function; -import java.util.function.Supplier; - -/** - * Creates common {@link PacketSerializer}s. - */ -public final class PacketSerializers { - - private static final Map> clientToServerDeserializers; - - private static final Map> clientToProxyDeserializers; - - static { - clientToServerDeserializers = Map.of(RoundStartPacket.ID, RoundStartPacket::read); - clientToProxyDeserializers = - Map.of(MapDataVersionQueryPacket.ID, MapDataVersionQueryPacket::read, MapDataVersionResponsePacket.ID, - MapDataVersionResponsePacket::read); - } - - private PacketSerializers() { - throw new UnsupportedOperationException(); - } - - public static @NotNull PacketSerializer clientToServerSerializer(@NotNull Supplier writerCreator, - @NotNull Function readerCreator) { - return new PacketSerializer(clientToServerDeserializers, writerCreator, readerCreator); - } - - public static @NotNull PacketSerializer clientToProxySerializer(@NotNull Supplier writerCreator, - @NotNull Function readerCreator) { - return new PacketSerializer(clientToProxyDeserializers, writerCreator, readerCreator); - } - -} diff --git a/server/build.gradle.kts b/server/build.gradle.kts index 9dc7998f7..e3f3d9156 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -11,7 +11,6 @@ repositories { dependencies { implementation(projects.phantazmCore) - implementation(projects.phantazmMessaging) implementation(projects.phantazmMob) implementation(projects.phantazmZombiesMapdata) implementation(projects.phantazmZombies) diff --git a/server/src/main/java/org/phantazm/server/MessagingFeature.java b/server/src/main/java/org/phantazm/server/MessagingFeature.java deleted file mode 100644 index d42ff26bc..000000000 --- a/server/src/main/java/org/phantazm/server/MessagingFeature.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.phantazm.server; - -import net.kyori.adventure.key.Key; -import net.minestom.server.entity.Player; -import net.minestom.server.event.Event; -import net.minestom.server.event.EventNode; -import net.minestom.server.event.player.PlayerPluginMessageEvent; -import net.minestom.server.utils.binary.BinaryReader; -import net.minestom.server.utils.binary.BinaryWriter; -import org.jetbrains.annotations.NotNull; -import org.phantazm.commons.Namespaces; -import org.phantazm.messaging.MessageChannels; -import org.phantazm.messaging.packet.Packet; -import org.phantazm.messaging.packet.PacketHandler; -import org.phantazm.messaging.serialization.PacketSerializer; -import org.phantazm.messaging.serialization.PacketSerializers; -import org.phantazm.server.packet.BinaryDataReader; -import org.phantazm.server.packet.BinaryDataWriter; - -import java.util.Map; - -/** - * Main entrypoint for plugin messaging. This is used to communicate with the proxy and players. - */ -public final class MessagingFeature { - - private static PacketHandler clientToServerHandler; - - private MessagingFeature() { - throw new UnsupportedOperationException(); - } - - static void initialize(@NotNull EventNode global) { - PacketSerializer clientToServer = - PacketSerializers.clientToServerSerializer(() -> new BinaryDataWriter(new BinaryWriter()), - data -> new BinaryDataReader(new BinaryReader(data))); - Key clientToServerIdentifier = Key.key(Namespaces.PHANTAZM, MessageChannels.CLIENT_TO_SERVER); - clientToServerHandler = new PacketHandler<>(clientToServer) { - @Override - protected void handlePacket(@NotNull Player player, @NotNull Packet packet) { - - } - - @Override - protected void sendToReceiver(@NotNull Player player, byte @NotNull [] data) { - player.sendPluginMessage(clientToServerIdentifier.toString(), data); - } - }; - Map> packetHandlers = - Map.of(MessageChannels.CLIENT_TO_SERVER, clientToServerHandler); - - global.addListener(PlayerPluginMessageEvent.class, event -> { - String identifier = event.getIdentifier(); - if (!identifier.contains(":")) { - return; - } - - String[] split = identifier.split(":"); - if (split.length != 2 || !split[0].equals(Namespaces.PHANTAZM)) { - return; - } - - PacketHandler packetHandler = packetHandlers.get(split[1]); - if (packetHandler == null) { - return; - } - - packetHandler.handleData(event.getPlayer(), event.getMessage()); - }); - } - - public static @NotNull PacketHandler getClientToServerHandler() { - return FeatureUtils.check(clientToServerHandler); - } -} diff --git a/server/src/main/java/org/phantazm/server/PhantazmServer.java b/server/src/main/java/org/phantazm/server/PhantazmServer.java index dbbab1024..d0a1ba59d 100644 --- a/server/src/main/java/org/phantazm/server/PhantazmServer.java +++ b/server/src/main/java/org/phantazm/server/PhantazmServer.java @@ -244,7 +244,6 @@ private static void initializeFeatures(KeyParser keyParser, EventNode glo LobbyFeature.initialize(global, viewProvider, lobbiesConfig, contextManager); ChatFeature.initialize(global, viewProvider, chatConfig, PartyFeature.getPartyHolder().uuidToGuild(), MinecraftServer.getCommandManager()); - MessagingFeature.initialize(global); CommandFeature.initialize(MinecraftServer.getCommandManager(), routerStore, viewProvider, LobbyFeature.getFallback()); diff --git a/server/src/main/java/org/phantazm/server/ZombiesFeature.java b/server/src/main/java/org/phantazm/server/ZombiesFeature.java index 66d946b5a..6b59a63df 100644 --- a/server/src/main/java/org/phantazm/server/ZombiesFeature.java +++ b/server/src/main/java/org/phantazm/server/ZombiesFeature.java @@ -180,12 +180,10 @@ static void initialize(@NotNull EventNode globalEventNode, @NotNull Conte return new InstanceClientBlockHandler(instance, dimensionType.getMinY(), dimensionType.getHeight()); }, globalEventNode), contextManager, keyParser, mobNoPushTeam, corpseTeam, database, - MessagingFeature.getClientToServerHandler(), ZombiesFeature.powerups(), - new BasicZombiesPlayerSource(database, viewProvider, - EquipmentFeature::createEquipmentCreator, MobFeature.getModels(), contextManager, - keyParser), - mapDependencyProvider -> contextManager.makeContext(entry.getValue().corpse()) - .provide(mapDependencyProvider), songLoader); + ZombiesFeature.powerups(), new BasicZombiesPlayerSource(database, viewProvider, + EquipmentFeature::createEquipmentCreator, MobFeature.getModels(), contextManager, + keyParser), mapDependencyProvider -> contextManager.makeContext(entry.getValue().corpse()) + .provide(mapDependencyProvider), songLoader); providers.put(entry.getKey(), provider); } diff --git a/velocity/src/main/java/org/phantazm/velocity/PhantazmPlugin.java b/velocity/src/main/java/org/phantazm/velocity/PhantazmPlugin.java index 48ecc4fa2..130b8b5b1 100644 --- a/velocity/src/main/java/org/phantazm/velocity/PhantazmPlugin.java +++ b/velocity/src/main/java/org/phantazm/velocity/PhantazmPlugin.java @@ -1,18 +1,19 @@ package org.phantazm.velocity; import com.google.inject.Inject; +import com.velocitypowered.api.event.EventManager; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.proxy.ProxyServer; -import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; -import org.phantazm.commons.Namespaces; -import org.phantazm.messaging.MessageChannels; +import org.phantazm.messaging.packet.player.MapDataVersionQueryPacket; import org.phantazm.velocity.listener.MaliciousPluginMessageBlocker; import org.phantazm.velocity.listener.ProtocolVersionForwarder; import org.phantazm.velocity.listener.ProxyMessagingHandler; +import java.util.Collections; + /** * A velocity plugin used to communicate information to the Phantazm server. */ @@ -39,15 +40,12 @@ public PhantazmPlugin(ProxyServer server) { */ @Subscribe public void onInitialize(ProxyInitializeEvent event) { - ChannelIdentifier proxyToServer = - MinecraftChannelIdentifier.create(Namespaces.PHANTAZM, MessageChannels.PROXY_TO_SERVER); - ChannelIdentifier clientToProxy = MinecraftChannelIdentifier.create(Namespaces.PHANTAZM, - MessageChannels.CLIENT_TO_PROXY); - server.getChannelRegistrar().register(proxyToServer); - server.getChannelRegistrar().register(clientToProxy); - server.getEventManager().register(this, new MaliciousPluginMessageBlocker(proxyToServer)); - server.getEventManager().register(this, new ProtocolVersionForwarder()); - server.getEventManager().register(this, new ProxyMessagingHandler(clientToProxy)); + server.getChannelRegistrar().register(MinecraftChannelIdentifier.from(MapDataVersionQueryPacket.ID)); + + EventManager eventManager = server.getEventManager(); + eventManager.register(this, new MaliciousPluginMessageBlocker(Collections.emptySet())); + eventManager.register(this, new ProtocolVersionForwarder()); + eventManager.register(this, ProxyMessagingHandler.createDefault()); } } diff --git a/velocity/src/main/java/org/phantazm/velocity/listener/MaliciousPluginMessageBlocker.java b/velocity/src/main/java/org/phantazm/velocity/listener/MaliciousPluginMessageBlocker.java index 370d81704..d78e292aa 100644 --- a/velocity/src/main/java/org/phantazm/velocity/listener/MaliciousPluginMessageBlocker.java +++ b/velocity/src/main/java/org/phantazm/velocity/listener/MaliciousPluginMessageBlocker.java @@ -9,21 +9,17 @@ import org.jetbrains.annotations.NotNull; import java.util.Objects; +import java.util.Set; /** * Blocks malicious plugin messages from players that go through the plugin's proxy channel. */ public class MaliciousPluginMessageBlocker { - private final ChannelIdentifier proxyIdentifier; + private final Set blockedIdentifiers; - /** - * Creates a {@link MaliciousPluginMessageBlocker}. - * - * @param channelIdentifier The {@link ChannelIdentifier} for the plugin's proxy2server channel - */ - public MaliciousPluginMessageBlocker(@NotNull ChannelIdentifier channelIdentifier) { - this.proxyIdentifier = Objects.requireNonNull(channelIdentifier, "channelIdentifier"); + public MaliciousPluginMessageBlocker(@NotNull Set blockedIdentifiers) { + this.blockedIdentifiers = Objects.requireNonNull(blockedIdentifiers, "blockedIdentifiers"); } /** @@ -33,8 +29,7 @@ public MaliciousPluginMessageBlocker(@NotNull ChannelIdentifier channelIdentifie */ @Subscribe public void onPlayerMessage(PluginMessageEvent event) { - if (event.getIdentifier().getId().equals(proxyIdentifier.getId()) && - event.getSource() instanceof Player player) { + if (blockedIdentifiers.contains(event.getIdentifier()) && event.getSource() instanceof Player player) { event.setResult(PluginMessageEvent.ForwardResult.handled()); player.disconnect(Component.text("Malicious plugin message.", NamedTextColor.RED)); } diff --git a/velocity/src/main/java/org/phantazm/velocity/listener/ProxyMessagingHandler.java b/velocity/src/main/java/org/phantazm/velocity/listener/ProxyMessagingHandler.java index 12c3910ef..1110e10e3 100644 --- a/velocity/src/main/java/org/phantazm/velocity/listener/ProxyMessagingHandler.java +++ b/velocity/src/main/java/org/phantazm/velocity/listener/ProxyMessagingHandler.java @@ -1,56 +1,45 @@ package org.phantazm.velocity.listener; -import com.google.common.io.ByteStreams; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.connection.PluginMessageEvent; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.messages.ChannelIdentifier; +import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import org.jetbrains.annotations.NotNull; -import org.phantazm.messaging.packet.Packet; -import org.phantazm.messaging.packet.PacketHandler; -import org.phantazm.messaging.packet.c2p.MapDataVersionQueryPacket; -import org.phantazm.messaging.packet.c2p.MapDataVersionResponsePacket; -import org.phantazm.messaging.serialization.PacketSerializer; -import org.phantazm.messaging.serialization.PacketSerializers; -import org.phantazm.velocity.packet.ByteArrayInputDataReader; -import org.phantazm.velocity.packet.ByteArrayOutputDataWriter; +import org.phantazm.messaging.packet.player.MapDataVersionQueryPacket; +import org.phantazm.messaging.packet.proxy.MapDataVersionResponsePacket; +import org.phantazm.velocity.packet.VelocityPacketUtils; import org.phantazm.zombies.map.MapSettingsInfo; import java.util.Map; +import java.util.Objects; +import java.util.function.BiConsumer; /** * Handles all messaging that involves the proxy */ public class ProxyMessagingHandler { - private final Map> packetHandlers; + private final Map> packetHandlers; /** * Creates a new {@link ProxyMessagingHandler}. - * @param clientToProxyIdentifier The identifier for the channel between the client and the proxy */ - @SuppressWarnings("UnstableApiUsage") - public ProxyMessagingHandler(@NotNull ChannelIdentifier clientToProxyIdentifier) { - PacketSerializer clientToProxy = PacketSerializers.clientToProxySerializer( - () -> new ByteArrayOutputDataWriter(ByteStreams.newDataOutput()), - data -> new ByteArrayInputDataReader(ByteStreams.newDataInput(data))); - packetHandlers = Map.of(clientToProxyIdentifier, new PacketHandler<>(clientToProxy) { - @Override - protected void handlePacket(@NotNull Player player, @NotNull Packet packet) { - if (packet instanceof MapDataVersionQueryPacket) { - output(player, new MapDataVersionResponsePacket(MapSettingsInfo.MAP_DATA_VERSION)); - } - } + public ProxyMessagingHandler(@NotNull Map> packetHandlers) { + this.packetHandlers = Objects.requireNonNull(packetHandlers, "packetHandlers"); + } - @Override - protected void sendToReceiver(@NotNull Player player, byte @NotNull [] data) { - player.sendPluginMessage(clientToProxyIdentifier, data); - } + public static @NotNull ProxyMessagingHandler createDefault() { + Map> packetHandlers = Map.of(MinecraftChannelIdentifier.from(MapDataVersionQueryPacket.ID), (player, data) -> { + VelocityPacketUtils.sendPacket(player, new MapDataVersionResponsePacket(MapSettingsInfo.MAP_DATA_VERSION)); }); + + return new ProxyMessagingHandler(packetHandlers); } /** * Handles a {@link PluginMessageEvent}. + * * @param event The event */ @Subscribe @@ -59,9 +48,9 @@ public void onPluginMessage(PluginMessageEvent event) { return; } - PacketHandler packetHandler = packetHandlers.get(event.getIdentifier()); + BiConsumer packetHandler = packetHandlers.get(event.getIdentifier()); if (packetHandler != null) { - packetHandler.handleData(player, event.getData()); + packetHandler.accept(player, event.getData()); event.setResult(PluginMessageEvent.ForwardResult.handled()); } } diff --git a/velocity/src/main/java/org/phantazm/velocity/packet/ByteArrayInputDataReader.java b/velocity/src/main/java/org/phantazm/velocity/packet/ByteArrayInputDataReader.java index a292070f2..4da5d1323 100644 --- a/velocity/src/main/java/org/phantazm/velocity/packet/ByteArrayInputDataReader.java +++ b/velocity/src/main/java/org/phantazm/velocity/packet/ByteArrayInputDataReader.java @@ -1,6 +1,7 @@ package org.phantazm.velocity.packet; import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteStreams; import org.jetbrains.annotations.NotNull; import org.phantazm.messaging.serialization.DataReader; @@ -22,6 +23,10 @@ public ByteArrayInputDataReader(@NotNull ByteArrayDataInput input) { this.input = Objects.requireNonNull(input, "input"); } + public ByteArrayInputDataReader(byte @NotNull[] bytes) { + this(ByteStreams.newDataInput(bytes)); + } + @Override public byte readByte() { return input.readByte(); diff --git a/velocity/src/main/java/org/phantazm/velocity/packet/ByteArrayOutputDataWriter.java b/velocity/src/main/java/org/phantazm/velocity/packet/ByteArrayOutputDataWriter.java index f70856d84..57126adb4 100644 --- a/velocity/src/main/java/org/phantazm/velocity/packet/ByteArrayOutputDataWriter.java +++ b/velocity/src/main/java/org/phantazm/velocity/packet/ByteArrayOutputDataWriter.java @@ -1,6 +1,7 @@ package org.phantazm.velocity.packet; import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; import org.jetbrains.annotations.NotNull; import org.phantazm.messaging.serialization.DataWriter; @@ -22,6 +23,10 @@ public ByteArrayOutputDataWriter(@NotNull ByteArrayDataOutput output) { this.output = Objects.requireNonNull(output, "output"); } + public ByteArrayOutputDataWriter() { + this(ByteStreams.newDataOutput()); + } + @Override public void writeByte(byte data) { output.writeByte(data); diff --git a/velocity/src/main/java/org/phantazm/velocity/packet/VelocityPacketUtils.java b/velocity/src/main/java/org/phantazm/velocity/packet/VelocityPacketUtils.java new file mode 100644 index 000000000..62f864c15 --- /dev/null +++ b/velocity/src/main/java/org/phantazm/velocity/packet/VelocityPacketUtils.java @@ -0,0 +1,24 @@ +package org.phantazm.velocity.packet; + +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; +import org.jetbrains.annotations.NotNull; +import org.phantazm.messaging.packet.Packet; +import org.phantazm.messaging.packet.proxy.MapDataVersionResponsePacket; +import org.phantazm.messaging.serialization.DataWriter; +import org.phantazm.zombies.map.MapSettingsInfo; + +public class VelocityPacketUtils { + + public static byte @NotNull[] serialize(@NotNull Packet packet) { + DataWriter dataWriter = new ByteArrayOutputDataWriter(); + packet.write(dataWriter); + return dataWriter.toByteArray(); + } + + public static void sendPacket(@NotNull Player player, @NotNull Packet packet) { + byte[] data = VelocityPacketUtils.serialize(new MapDataVersionResponsePacket(MapSettingsInfo.MAP_DATA_VERSION)); + player.sendPluginMessage(MinecraftChannelIdentifier.from(packet.getId()), data); + } + +} diff --git a/zombies-mapeditor/build.gradle.kts b/zombies-mapeditor/build.gradle.kts index ce15174bc..f6e4603f9 100644 --- a/zombies-mapeditor/build.gradle.kts +++ b/zombies-mapeditor/build.gradle.kts @@ -6,7 +6,7 @@ plugins { alias(libs.plugins.fabric.loom) } -version = "1.3.0+1.19.4" +version = "1.4.0+1.19.4" base { archivesName.set("phantazm-zombies-mapeditor") diff --git a/zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/MapeditorClient.java b/zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/MapeditorClient.java index c95e87462..647e2a454 100644 --- a/zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/MapeditorClient.java +++ b/zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/MapeditorClient.java @@ -3,7 +3,6 @@ import com.github.steanky.ethylene.codec.yaml.YamlCodec; import com.github.steanky.ethylene.core.ConfigCodec; import io.github.cottonmc.cotton.gui.client.CottonClientScreen; -import io.netty.buffer.Unpooled; import me.x150.renderer.event.RenderEvents; import me.x150.renderer.render.Renderer3d; import net.fabricmc.api.ClientModInitializer; @@ -13,8 +12,6 @@ import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.event.player.UseBlockCallback; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; -import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.loader.api.FabricLoader; import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Keyed; @@ -24,27 +21,17 @@ import net.minecraft.client.option.KeyBinding; import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.network.PacketByteBuf; import net.minecraft.text.Text; import net.minecraft.util.Formatting; -import net.minecraft.util.Identifier; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.HitResult; import org.jetbrains.annotations.NotNull; import org.lwjgl.glfw.GLFW; -import org.phantazm.commons.Namespaces; -import org.phantazm.messaging.MessageChannels; -import org.phantazm.messaging.packet.Packet; -import org.phantazm.messaging.packet.PacketHandler; -import org.phantazm.messaging.packet.c2p.MapDataVersionQueryPacket; -import org.phantazm.messaging.packet.c2p.MapDataVersionResponsePacket; -import org.phantazm.messaging.serialization.PacketSerializer; -import org.phantazm.messaging.serialization.PacketSerializers; +import org.phantazm.messaging.packet.player.MapDataVersionQueryPacket; import org.phantazm.zombies.map.FileSystemMapLoader; import org.phantazm.zombies.map.MapSettingsInfo; -import org.phantazm.zombies.mapeditor.client.packet.PacketByteBufDataReader; -import org.phantazm.zombies.mapeditor.client.packet.PacketByteBufDataWriter; -import org.phantazm.zombies.mapeditor.client.packet.PhantazmPacket; +import org.phantazm.zombies.mapeditor.client.packet.FabricPacketUtils; +import org.phantazm.zombies.mapeditor.client.packet.MapDataVersionResponsePacketWrapper; import org.phantazm.zombies.mapeditor.client.render.ObjectRenderer; import org.phantazm.zombies.mapeditor.client.ui.MainGui; import org.phantazm.zombies.mapeditor.client.ui.NewObjectGui; @@ -89,45 +76,22 @@ public void onInitializeClient() { new KeyBinding(TranslationKeys.KEY_MAPEDITOR_CREATE, InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_N, TranslationKeys.CATEGORY_MAPEDITOR_ALL)); - PacketSerializer clientToProxy = PacketSerializers.clientToProxySerializer( - () -> new PacketByteBufDataWriter(PacketByteBufs.create()), - data -> new PacketByteBufDataReader(new PacketByteBuf(Unpooled.wrappedBuffer(data)))); - Identifier clientToProxyIdentifier = Identifier.of(Namespaces.PHANTAZM, MessageChannels.CLIENT_TO_PROXY); - if (clientToProxyIdentifier != null) { - PacketHandler clientToProxyHandler = new PacketHandler<>(clientToProxy) { - @Override - protected void handlePacket(@NotNull PacketSender packetSender, @NotNull Packet packet) { - if (packet instanceof MapDataVersionResponsePacket responsePacket) { - ClientPlayerEntity player = MinecraftClient.getInstance().player; - - if (player != null) { - Text message; - if (responsePacket.version() == MapSettingsInfo.MAP_DATA_VERSION) { - message = Text.translatable(TranslationKeys.CHAT_MAPEDITOR_MAPDATA_VERSION_SYNC_SYNCED) - .formatted(Formatting.GREEN); - } - else { - message = Text.translatable(TranslationKeys.CHAT_MAPEDITOR_MAPDATA_VERSION_SYNC_NOT_SYNCED) - .formatted(Formatting.RED); - } - player.sendMessage(message); - } + ClientPlayConnectionEvents.JOIN.register(((handler, sender, client) -> { + FabricPacketUtils.sendPacket(sender, new MapDataVersionQueryPacket()); + })); + ClientPlayNetworking.registerGlobalReceiver(MapDataVersionResponsePacketWrapper.TYPE, + (packet, player, responseSender) -> { + Text message; + if (packet.packet().version() == MapSettingsInfo.MAP_DATA_VERSION) { + message = Text.translatable(TranslationKeys.CHAT_MAPEDITOR_MAPDATA_VERSION_SYNC_SYNCED) + .formatted(Formatting.GREEN); } - } - - @Override - protected void sendToReceiver(@NotNull PacketSender packetSender, byte @NotNull [] data) { - packetSender.sendPacket(clientToProxyIdentifier, new PacketByteBuf(Unpooled.wrappedBuffer(data))); - } - }; - ClientPlayConnectionEvents.JOIN.register(((handler, sender, client) -> { - clientToProxyHandler.output(sender, new MapDataVersionQueryPacket()); - })); - ClientPlayNetworking.registerGlobalReceiver(PhantazmPacket.TYPE, ((packet, player, responseSender) -> { - clientToProxyHandler.handleData(responseSender, packet.data()); - })); - } - + else { + message = Text.translatable(TranslationKeys.CHAT_MAPEDITOR_MAPDATA_VERSION_SYNC_NOT_SYNCED) + .formatted(Formatting.RED); + } + player.sendMessage(message); + }); ClientTickEvents.END_CLIENT_TICK.register(new ClientTickEvents.EndTick() { private BlockHitResult lastBlockLook; diff --git a/zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/packet/FabricPacketUtils.java b/zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/packet/FabricPacketUtils.java new file mode 100644 index 000000000..c87abb8b9 --- /dev/null +++ b/zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/packet/FabricPacketUtils.java @@ -0,0 +1,39 @@ +package org.phantazm.zombies.mapeditor.client.packet; + +import net.fabricmc.fabric.api.networking.v1.FabricPacket; +import net.fabricmc.fabric.api.networking.v1.PacketSender; +import net.fabricmc.fabric.api.networking.v1.PacketType; +import net.kyori.adventure.key.Key; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.NotNull; +import org.phantazm.messaging.packet.Packet; +import org.phantazm.messaging.serialization.DataReader; + +import java.util.function.Function; + +public class FabricPacketUtils { + + private FabricPacketUtils() { + throw new UnsupportedOperationException(); + } + + private static Identifier identifierFromKey(Key key) { + return Identifier.of(key.namespace(), key.value()); + } + + public static void sendPacket(@NotNull PacketSender sender, @NotNull Packet packet) { + PacketByteBufDataWriter dataWriter = new PacketByteBufDataWriter(); + packet.write(dataWriter); + sender.sendPacket(identifierFromKey(packet.getId()), dataWriter.getBuf()); + } + + public static @NotNull PacketType createPacketType(@NotNull Key key, + @NotNull Function innerCreator, + @NotNull Function wrapperCreator) { + return PacketType.create(identifierFromKey(key), buf -> { + TInnerPacket innerPacket = innerCreator.apply(new PacketByteBufDataReader(buf)); + return wrapperCreator.apply(innerPacket); + }); + } + +} diff --git a/zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/packet/MapDataVersionResponsePacketWrapper.java b/zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/packet/MapDataVersionResponsePacketWrapper.java new file mode 100644 index 000000000..08211f7f7 --- /dev/null +++ b/zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/packet/MapDataVersionResponsePacketWrapper.java @@ -0,0 +1,31 @@ +package org.phantazm.zombies.mapeditor.client.packet; + +import net.fabricmc.fabric.api.networking.v1.FabricPacket; +import net.fabricmc.fabric.api.networking.v1.PacketType; +import net.minecraft.network.PacketByteBuf; +import org.jetbrains.annotations.NotNull; +import org.phantazm.messaging.packet.proxy.MapDataVersionResponsePacket; + +import java.util.Objects; + +public record MapDataVersionResponsePacketWrapper(@NotNull MapDataVersionResponsePacket packet) implements FabricPacket { + + public static final PacketType TYPE = + FabricPacketUtils.createPacketType(MapDataVersionResponsePacket.ID, MapDataVersionResponsePacket::read, + MapDataVersionResponsePacketWrapper::new); + + public MapDataVersionResponsePacketWrapper { + Objects.requireNonNull(packet, "packet"); + } + + @Override + public void write(PacketByteBuf buf) { + packet.write(new PacketByteBufDataWriter()); + } + + @Override + public PacketType getType() { + return TYPE; + } + +} diff --git a/zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/packet/PacketByteBufDataWriter.java b/zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/packet/PacketByteBufDataWriter.java index 5e91e6291..13900a299 100644 --- a/zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/packet/PacketByteBufDataWriter.java +++ b/zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/packet/PacketByteBufDataWriter.java @@ -1,5 +1,6 @@ package org.phantazm.zombies.mapeditor.client.packet; +import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.minecraft.network.PacketByteBuf; import org.jetbrains.annotations.NotNull; import org.phantazm.messaging.serialization.DataWriter; @@ -22,6 +23,10 @@ public PacketByteBufDataWriter(@NotNull PacketByteBuf packetByteBuf) { this.packetByteBuf = Objects.requireNonNull(packetByteBuf, "packetByteBuf"); } + public PacketByteBufDataWriter() { + this(PacketByteBufs.create()); + } + @Override public void writeByte(byte data) { packetByteBuf.writeByte(data); @@ -36,4 +41,8 @@ public void writeInt(int data) { public byte @NotNull [] toByteArray() { return packetByteBuf.array(); } + + public @NotNull PacketByteBuf getBuf() { + return packetByteBuf; + } } diff --git a/zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/packet/PhantazmPacket.java b/zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/packet/PhantazmPacket.java deleted file mode 100644 index 1e6b64cd0..000000000 --- a/zombies-mapeditor/src/main/java/org/phantazm/zombies/mapeditor/client/packet/PhantazmPacket.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.phantazm.zombies.mapeditor.client.packet; - -import net.fabricmc.fabric.api.networking.v1.FabricPacket; -import net.fabricmc.fabric.api.networking.v1.PacketType; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.util.Identifier; -import org.jetbrains.annotations.NotNull; -import org.phantazm.commons.Namespaces; -import org.phantazm.messaging.MessageChannels; - -public record PhantazmPacket(byte @NotNull [] data) implements FabricPacket { - - public static final PacketType TYPE = - PacketType.create(new Identifier(Namespaces.PHANTAZM, MessageChannels.CLIENT_TO_SERVER), - PhantazmPacket::new); - - public PhantazmPacket(PacketByteBuf buf) { - this(buf.getWrittenBytes()); - } - - @Override - public void write(PacketByteBuf buf) { - buf.writeBytes(data); - } - - @Override - public PacketType getType() { - return TYPE; - } - -} diff --git a/zombies-timer/build.gradle.kts b/zombies-timer/build.gradle.kts index dfb9eac8a..2660c0729 100644 --- a/zombies-timer/build.gradle.kts +++ b/zombies-timer/build.gradle.kts @@ -6,7 +6,7 @@ plugins { alias(libs.plugins.fabric.loom) } -version = "0.1.0+1.20.1" +version = "0.2.0+1.20.1" base { archivesName.set("zombies-autosplits") @@ -37,6 +37,7 @@ dependencies { include(projects.phantazmCommons) include(projects.phantazmMessaging) + include(libs.adventure.key) include(libs.ethylene.core) include(libs.ethylene.yaml) include(libs.toolkit.collection) diff --git a/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/ZombiesAutoSplitsClient.java b/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/ZombiesAutoSplitsClient.java index ed83354ac..5946c6144 100644 --- a/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/ZombiesAutoSplitsClient.java +++ b/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/ZombiesAutoSplitsClient.java @@ -7,37 +7,25 @@ import com.github.steanky.ethylene.core.loader.ConfigLoader; import com.github.steanky.ethylene.core.loader.SyncFileConfigLoader; import com.github.steanky.ethylene.core.processor.ConfigProcessor; -import io.netty.buffer.Unpooled; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; -import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; import net.minecraft.client.option.KeyBinding; -import net.minecraft.network.PacketByteBuf; import org.jetbrains.annotations.NotNull; import org.lwjgl.glfw.GLFW; -import org.phantazm.messaging.packet.PacketHandler; -import org.phantazm.messaging.serialization.DataReader; -import org.phantazm.messaging.serialization.DataWriter; -import org.phantazm.messaging.serialization.PacketSerializer; -import org.phantazm.messaging.serialization.PacketSerializers; import org.phantazm.zombies.autosplits.config.ZombiesAutoSplitsConfig; import org.phantazm.zombies.autosplits.config.ZombiesAutoSplitsConfigProcessor; import org.phantazm.zombies.autosplits.event.ClientSoundCallback; -import org.phantazm.zombies.autosplits.messaging.PhantazmMessagingHandler; -import org.phantazm.zombies.autosplits.packet.PacketByteBufDataReader; -import org.phantazm.zombies.autosplits.packet.PacketByteBufDataWriter; -import org.phantazm.zombies.autosplits.packet.PhantazmPacket; +import org.phantazm.zombies.autosplits.packet.RoundStartPacketWrapper; import org.phantazm.zombies.autosplits.render.RenderTimeHandler; import org.phantazm.zombies.autosplits.sound.AutoSplitSoundInterceptor; -import org.phantazm.zombies.autosplits.splitter.CompositeSplitter; import org.phantazm.zombies.autosplits.splitter.AutoSplitSplitter; +import org.phantazm.zombies.autosplits.splitter.CompositeSplitter; import org.phantazm.zombies.autosplits.splitter.internal.InternalSplitter; import org.phantazm.zombies.autosplits.splitter.socket.LiveSplitSocketSplitter; import org.phantazm.zombies.autosplits.tick.KeyInputHandler; @@ -49,8 +37,6 @@ import java.nio.file.Path; import java.util.Collection; import java.util.concurrent.*; -import java.util.function.Function; -import java.util.function.Supplier; public class ZombiesAutoSplitsClient implements ClientModInitializer { @@ -199,14 +185,8 @@ private void initKeyBindings() { } private void initPackets() { - Supplier writerCreator = () -> new PacketByteBufDataWriter(PacketByteBufs.create()); - Function readerCreator = - data -> new PacketByteBufDataReader(new PacketByteBuf(Unpooled.wrappedBuffer(data))); - PacketSerializer packetSerializer = PacketSerializers.clientToServerSerializer(writerCreator, readerCreator); - PacketHandler clientToServerHandler = - new PhantazmMessagingHandler(packetSerializer, PhantazmPacket.TYPE.getId(), compositeSplitter); - ClientPlayNetworking.registerGlobalReceiver(PhantazmPacket.TYPE, (packet, player, responseSender) -> { - clientToServerHandler.handleData(responseSender, packet.data()); + ClientPlayNetworking.registerGlobalReceiver(RoundStartPacketWrapper.TYPE, (packet, player, responseSender) -> { + compositeSplitter.split(); }); } diff --git a/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/messaging/PhantazmMessagingHandler.java b/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/messaging/PhantazmMessagingHandler.java deleted file mode 100644 index 8ebbd75a9..000000000 --- a/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/messaging/PhantazmMessagingHandler.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.phantazm.zombies.autosplits.messaging; - -import io.netty.buffer.Unpooled; -import net.fabricmc.fabric.api.networking.v1.PacketSender; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.util.Identifier; -import org.jetbrains.annotations.NotNull; -import org.phantazm.messaging.packet.Packet; -import org.phantazm.messaging.packet.PacketHandler; -import org.phantazm.messaging.packet.c2s.RoundStartPacket; -import org.phantazm.messaging.serialization.PacketSerializer; -import org.phantazm.zombies.autosplits.splitter.CompositeSplitter; - -import java.util.Objects; - -public class PhantazmMessagingHandler extends PacketHandler { - - private final CompositeSplitter compositeSplitter; - - private final Identifier identifier; - - public PhantazmMessagingHandler(@NotNull PacketSerializer packetSerializer, @NotNull Identifier identifier, - @NotNull CompositeSplitter compositeSplitter) { - super(packetSerializer); - this.identifier = Objects.requireNonNull(identifier, "identifier"); - this.compositeSplitter = Objects.requireNonNull(compositeSplitter, "compositeSplitter"); - } - - @Override - protected void handlePacket(@NotNull PacketSender packetSender, @NotNull Packet packet) { - if (packet instanceof RoundStartPacket) { - compositeSplitter.split(); - } - } - - @Override - protected void sendToReceiver(@NotNull PacketSender packetSender, byte @NotNull [] data) { - packetSender.sendPacket(identifier, new PacketByteBuf(Unpooled.wrappedBuffer(data))); - } -} diff --git a/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/packet/FabricPacketUtils.java b/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/packet/FabricPacketUtils.java new file mode 100644 index 000000000..dabe1f8f7 --- /dev/null +++ b/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/packet/FabricPacketUtils.java @@ -0,0 +1,39 @@ +package org.phantazm.zombies.autosplits.packet; + +import net.fabricmc.fabric.api.networking.v1.FabricPacket; +import net.fabricmc.fabric.api.networking.v1.PacketSender; +import net.fabricmc.fabric.api.networking.v1.PacketType; +import net.kyori.adventure.key.Key; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.NotNull; +import org.phantazm.messaging.packet.Packet; +import org.phantazm.messaging.serialization.DataReader; + +import java.util.function.Function; + +public class FabricPacketUtils { + + private FabricPacketUtils() { + throw new UnsupportedOperationException(); + } + + private static Identifier identifierFromKey(Key key) { + return Identifier.of(key.namespace(), key.value()); + } + + public static void sendPacket(@NotNull PacketSender sender, @NotNull Packet packet) { + PacketByteBufDataWriter dataWriter = new PacketByteBufDataWriter(); + packet.write(dataWriter); + sender.sendPacket(identifierFromKey(packet.getId()), dataWriter.getBuf()); + } + + public static @NotNull PacketType createPacketType(@NotNull Key key, + @NotNull Function innerCreator, + @NotNull Function wrapperCreator) { + return PacketType.create(identifierFromKey(key), buf -> { + TInnerPacket innerPacket = innerCreator.apply(new PacketByteBufDataReader(buf)); + return wrapperCreator.apply(innerPacket); + }); + } + +} diff --git a/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/packet/PacketByteBufDataWriter.java b/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/packet/PacketByteBufDataWriter.java index e20bc8094..5e7ecc4f5 100644 --- a/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/packet/PacketByteBufDataWriter.java +++ b/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/packet/PacketByteBufDataWriter.java @@ -1,5 +1,6 @@ package org.phantazm.zombies.autosplits.packet; +import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.minecraft.network.PacketByteBuf; import org.jetbrains.annotations.NotNull; import org.phantazm.messaging.serialization.DataWriter; @@ -22,6 +23,10 @@ public PacketByteBufDataWriter(@NotNull PacketByteBuf packetByteBuf) { this.packetByteBuf = Objects.requireNonNull(packetByteBuf, "packetByteBuf"); } + public PacketByteBufDataWriter() { + this(PacketByteBufs.create()); + } + @Override public void writeByte(byte data) { packetByteBuf.writeByte(data); @@ -36,4 +41,8 @@ public void writeInt(int data) { public byte @NotNull [] toByteArray() { return packetByteBuf.array(); } + + public @NotNull PacketByteBuf getBuf() { + return packetByteBuf; + } } diff --git a/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/packet/PhantazmPacket.java b/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/packet/PhantazmPacket.java deleted file mode 100644 index 4eaf12491..000000000 --- a/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/packet/PhantazmPacket.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.phantazm.zombies.autosplits.packet; - -import net.fabricmc.fabric.api.networking.v1.FabricPacket; -import net.fabricmc.fabric.api.networking.v1.PacketType; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.util.Identifier; -import org.jetbrains.annotations.NotNull; -import org.phantazm.commons.Namespaces; -import org.phantazm.messaging.MessageChannels; - -public record PhantazmPacket(byte @NotNull [] data) implements FabricPacket { - - public static final PacketType TYPE = - PacketType.create(new Identifier(Namespaces.PHANTAZM, MessageChannels.CLIENT_TO_SERVER), - PhantazmPacket::new); - - public PhantazmPacket(PacketByteBuf buf) { - this(buf.getWrittenBytes()); - } - - @Override - public void write(PacketByteBuf buf) { - buf.writeBytes(data); - } - - @Override - public PacketType getType() { - return TYPE; - } - -} diff --git a/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/packet/RoundStartPacketWrapper.java b/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/packet/RoundStartPacketWrapper.java new file mode 100644 index 000000000..4fa955f1c --- /dev/null +++ b/zombies-timer/src/main/java/org/phantazm/zombies/autosplits/packet/RoundStartPacketWrapper.java @@ -0,0 +1,31 @@ +package org.phantazm.zombies.autosplits.packet; + +import net.fabricmc.fabric.api.networking.v1.FabricPacket; +import net.fabricmc.fabric.api.networking.v1.PacketType; +import net.minecraft.network.PacketByteBuf; +import org.jetbrains.annotations.NotNull; +import org.phantazm.messaging.packet.server.RoundStartPacket; + +import java.util.Objects; + +public record RoundStartPacketWrapper(@NotNull RoundStartPacket packet) implements FabricPacket { + + public static final PacketType TYPE = + FabricPacketUtils.createPacketType(RoundStartPacket.ID, RoundStartPacket::read, + RoundStartPacketWrapper::new); + + public RoundStartPacketWrapper { + Objects.requireNonNull(packet, "packet"); + } + + @Override + public void write(PacketByteBuf buf) { + packet.write(new PacketByteBufDataWriter()); + } + + @Override + public PacketType getType() { + return TYPE; + } + +} diff --git a/zombies/src/main/java/org/phantazm/zombies/map/Round.java b/zombies/src/main/java/org/phantazm/zombies/map/Round.java index 2265f5347..32b845624 100644 --- a/zombies/src/main/java/org/phantazm/zombies/map/Round.java +++ b/zombies/src/main/java/org/phantazm/zombies/map/Round.java @@ -1,12 +1,11 @@ package org.phantazm.zombies.map; import net.minestom.server.MinecraftServer; -import net.minestom.server.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Unmodifiable; import org.phantazm.commons.Tickable; -import org.phantazm.messaging.packet.PacketHandler; -import org.phantazm.messaging.packet.c2s.RoundStartPacket; +import org.phantazm.core.packet.MinestomPacketUtils; +import org.phantazm.messaging.packet.server.RoundStartPacket; import org.phantazm.mob.PhantazmMob; import org.phantazm.zombies.map.action.Action; import org.phantazm.zombies.player.ZombiesPlayer; @@ -27,7 +26,6 @@ public class Round implements Tickable { private final List spawnpoints; private final Map spawnedMobs; private final Collection zombiesPlayers; - private final PacketHandler packetHandler; private boolean isActive; private long waveStartTime; @@ -42,8 +40,7 @@ public class Round implements Tickable { */ public Round(@NotNull RoundInfo roundInfo, @NotNull List waves, @NotNull List> startActions, @NotNull List> endActions, @NotNull SpawnDistributor spawnDistributor, - @NotNull List spawnpoints, @NotNull Collection zombiesPlayers, - @NotNull PacketHandler packetHandler) { + @NotNull List spawnpoints, @NotNull Collection zombiesPlayers) { List waveInfo = roundInfo.waves(); if (waveInfo.isEmpty()) { LOGGER.warn("Round {} has no waves", roundInfo); @@ -58,7 +55,6 @@ public Round(@NotNull RoundInfo roundInfo, @NotNull List waves, @NotNull L this.spawnedMobs = new HashMap<>(); this.spawnpoints = Objects.requireNonNull(spawnpoints, "spawnpoints"); this.zombiesPlayers = Objects.requireNonNull(zombiesPlayers, "zombiesPlayers"); - this.packetHandler = Objects.requireNonNull(packetHandler, "packetHandler"); } public @NotNull RoundInfo getRoundInfo() { @@ -108,7 +104,8 @@ public void startRound(long time) { int prevBestRound = zombiesPlayer.module().getStats().getBestRound(); zombiesPlayer.module().getStats().setBestRound(Math.max(prevBestRound, roundInfo.round())); zombiesPlayer.getPlayer().ifPresent(player -> { - packetHandler.output(player, new RoundStartPacket()); + byte[] data = MinestomPacketUtils.serialize(new RoundStartPacket()); + player.sendPluginMessage(RoundStartPacket.ID.asString(), data); }); } diff --git a/zombies/src/main/java/org/phantazm/zombies/map/objects/BasicMapObjectsSource.java b/zombies/src/main/java/org/phantazm/zombies/map/objects/BasicMapObjectsSource.java index 05512a601..e0544dd94 100644 --- a/zombies/src/main/java/org/phantazm/zombies/map/objects/BasicMapObjectsSource.java +++ b/zombies/src/main/java/org/phantazm/zombies/map/objects/BasicMapObjectsSource.java @@ -14,7 +14,6 @@ import net.kyori.adventure.key.Key; import net.minestom.server.coordinate.Point; import net.minestom.server.coordinate.Pos; -import net.minestom.server.entity.Player; import net.minestom.server.event.Event; import net.minestom.server.event.EventNode; import net.minestom.server.instance.Instance; @@ -32,7 +31,6 @@ import org.phantazm.core.sound.SongLoader; import org.phantazm.core.sound.SongPlayer; import org.phantazm.core.tracker.BoundedTracker; -import org.phantazm.messaging.packet.PacketHandler; import org.phantazm.mob.MobModel; import org.phantazm.mob.MobStore; import org.phantazm.mob.PhantazmMob; @@ -72,19 +70,16 @@ public class BasicMapObjectsSource implements MapObjects.Source { private final Map mobModels; private final ClientBlockHandlerSource clientBlockHandlerSource; private final KeyParser keyParser; - private final PacketHandler packetHandler; public BasicMapObjectsSource(@NotNull MapInfo mapInfo, @NotNull ContextManager contextManager, @NotNull MobSpawnerSource mobSpawnerSource, @NotNull Map mobModels, - @NotNull ClientBlockHandlerSource clientBlockHandlerSource, @NotNull KeyParser keyParser, - @NotNull PacketHandler packetHandler) { + @NotNull ClientBlockHandlerSource clientBlockHandlerSource, @NotNull KeyParser keyParser) { this.mapInfo = Objects.requireNonNull(mapInfo, "mapInfo"); this.contextManager = Objects.requireNonNull(contextManager, "contextManager"); this.mobSpawnerSource = Objects.requireNonNull(mobSpawnerSource, "mobSpawnerSource"); this.mobModels = Objects.requireNonNull(mobModels, "mobModels"); this.clientBlockHandlerSource = Objects.requireNonNull(clientBlockHandlerSource, "clientBlockHandlerSource"); this.keyParser = Objects.requireNonNull(keyParser, "keyParser"); - this.packetHandler = Objects.requireNonNull(packetHandler, "packetHandler"); } @Override @@ -269,7 +264,7 @@ private List buildRounds(List roundInfoList, List } rounds.add(new Round(roundInfo, waves, startActions, endActions, spawnDistributor, spawnpoints, - zombiesPlayers.values(), packetHandler)); + zombiesPlayers.values())); } return rounds; diff --git a/zombies/src/main/java/org/phantazm/zombies/scene/ZombiesSceneProvider.java b/zombies/src/main/java/org/phantazm/zombies/scene/ZombiesSceneProvider.java index bca6b137b..3a765e9c4 100644 --- a/zombies/src/main/java/org/phantazm/zombies/scene/ZombiesSceneProvider.java +++ b/zombies/src/main/java/org/phantazm/zombies/scene/ZombiesSceneProvider.java @@ -11,7 +11,6 @@ import it.unimi.dsi.fastutil.longs.LongList; import net.kyori.adventure.key.Key; import net.minestom.server.coordinate.Pos; -import net.minestom.server.entity.Player; import net.minestom.server.event.Event; import net.minestom.server.event.EventNode; import net.minestom.server.event.entity.EntityDamageEvent; @@ -36,7 +35,6 @@ import org.phantazm.core.time.AnalogTickFormatter; import org.phantazm.core.time.PrecisionSecondTickFormatter; import org.phantazm.core.tracker.BoundedTracker; -import org.phantazm.messaging.packet.PacketHandler; import org.phantazm.mob.MobModel; import org.phantazm.mob.MobStore; import org.phantazm.mob.trigger.EventTrigger; @@ -96,8 +94,7 @@ public ZombiesSceneProvider(@NotNull Executor executor, int maximumScenes, @NotNull EventNode rootNode, @NotNull MobSpawnerSource mobSpawnerSource, @NotNull Map mobModels, @NotNull ClientBlockHandlerSource clientBlockHandlerSource, @NotNull ContextManager contextManager, @NotNull KeyParser keyParser, @NotNull Team mobNoPushTeam, - @NotNull Team corpseTeam, @NotNull ZombiesDatabase database, @NotNull PacketHandler packetHandler, - @NotNull Map powerups, @NotNull ZombiesPlayer.Source zombiesPlayerSource, + @NotNull Team corpseTeam, @NotNull ZombiesDatabase database, @NotNull Map powerups, @NotNull ZombiesPlayer.Source zombiesPlayerSource, @NotNull CorpseCreator.Source corpseCreatorSource, @NotNull SongLoader songLoader) { super(executor, maximumScenes); this.instanceSpaceFunction = Objects.requireNonNull(instanceSpaceFunction, "instanceSpaceFunction"); @@ -115,7 +112,7 @@ public ZombiesSceneProvider(@NotNull Executor executor, int maximumScenes, this.corpseTeam = Objects.requireNonNull(corpseTeam, "corpseTeam"); this.mapObjectSource = new BasicMapObjectsSource(mapInfo, contextManager, mobSpawnerSource, mobModels, - clientBlockHandlerSource, keyParser, packetHandler); + clientBlockHandlerSource, keyParser); this.zombiesPlayerSource = Objects.requireNonNull(zombiesPlayerSource, "zombiesPlayerSource"); this.powerupHandlerSource = new BasicPowerupHandlerSource(powerups, contextManager, settingsInfo.powerupPickupRadius());