From b79591faac5f076780733d696d2679e2f3cae6b4 Mon Sep 17 00:00:00 2001
From: Phillipp Glanz <6745190+TheMeinerLP@users.noreply.github.com>
Date: Tue, 15 Oct 2024 20:33:20 +0200
Subject: [PATCH] Fix custom player provider usage for junit (#81)
* Add possibility for custom player provider
* Improve documentation for custom player provider method at test connection
---
.../net/minestom/testing/TestConnection.java | 44 +++++++++++++++++++
.../minestom/testing/TestConnectionImpl.java | 12 +++--
2 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/testing/src/main/java/net/minestom/testing/TestConnection.java b/testing/src/main/java/net/minestom/testing/TestConnection.java
index c25b74be0e6..a2c37dea7fa 100644
--- a/testing/src/main/java/net/minestom/testing/TestConnection.java
+++ b/testing/src/main/java/net/minestom/testing/TestConnection.java
@@ -3,16 +3,60 @@
import net.minestom.server.coordinate.Pos;
import net.minestom.server.entity.Player;
import net.minestom.server.instance.Instance;
+import net.minestom.server.network.PlayerProvider;
import net.minestom.server.network.packet.server.ServerPacket;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture;
+/**
+ * Represents a connection to a test server.
+ */
public interface TestConnection {
+
+ /**
+ * Sets the custom player provider for this test connection.
+ *
+ * For a successful test you need to override the sendChunk method in the player implementation.
+ * Example:
+ *
{@code + * public class CustomGamePlayerImpl extends Player { + * public CustomGamePlayerImpl(UUID uuid, String username, PlayerConnection playerConnection) { + * super(uuid, username, playerConnection); + * } + * @Override + * public void sendChunk(Chunk chunk) { + * sendPacket(chunk.getFullDataPacket()); + * } + * } + * }+ * @param provider the custom player provider + */ + void setCustomPlayerProvider(@NotNull PlayerProvider provider); + + /** + * Connects a player to the server. + * + * @param instance the instance to spawn the player in + * @param pos the position to spawn the player at + * @return a future that completes when the player is connected + */ @NotNull CompletableFuture<@NotNull Player> connect(@NotNull Instance instance, @NotNull Pos pos); + /** + * Tracks incoming packets of a specific type. + * + * @param type the packet type to track + * @param