From c24bf3d13d919e69d6f8128aeb852e42a27f1ec1 Mon Sep 17 00:00:00 2001 From: themode Date: Sun, 23 Jan 2022 09:12:30 +0100 Subject: [PATCH] Add login callback --- .../java/net/minestom/server/api/TestConnection.java | 9 +++++++-- .../java/net/minestom/server/api/TestConnectionImpl.java | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/test/java/net/minestom/server/api/TestConnection.java b/src/test/java/net/minestom/server/api/TestConnection.java index 969e36d85..02859cd22 100644 --- a/src/test/java/net/minestom/server/api/TestConnection.java +++ b/src/test/java/net/minestom/server/api/TestConnection.java @@ -11,11 +11,16 @@ import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; public interface TestConnection { - @NotNull CompletableFuture<@NotNull Player> connect(@NotNull Instance instance, @NotNull Pos pos); + @NotNull CompletableFuture<@NotNull Player> connect(@NotNull Instance instance, @NotNull Pos pos, @NotNull Consumer loginCallback); + + default @NotNull CompletableFuture<@NotNull Player> connect(@NotNull Instance instance, @NotNull Pos pos) { + return connect(instance, pos, (player) -> { + }); + } @NotNull PacketTracker trackIncoming(@NotNull Class type); - default @NotNull PacketTracker trackIncoming(){ + default @NotNull PacketTracker trackIncoming() { return trackIncoming(ServerPacket.class); } diff --git a/src/test/java/net/minestom/server/api/TestConnectionImpl.java b/src/test/java/net/minestom/server/api/TestConnectionImpl.java index 9faacf13c..fae6364df 100644 --- a/src/test/java/net/minestom/server/api/TestConnectionImpl.java +++ b/src/test/java/net/minestom/server/api/TestConnectionImpl.java @@ -36,7 +36,7 @@ final class TestConnectionImpl implements TestConnection { } @Override - public @NotNull CompletableFuture connect(@NotNull Instance instance, @NotNull Pos pos) { + public @NotNull CompletableFuture connect(@NotNull Instance instance, @NotNull Pos pos, @NotNull Consumer loginCallback) { AtomicReference> listenerRef = new AtomicReference<>(); var listener = EventListener.builder(PlayerLoginEvent.class) .handler(event -> { @@ -44,6 +44,7 @@ final class TestConnectionImpl implements TestConnection { event.setSpawningInstance(instance); event.getPlayer().setRespawnPoint(pos); process.eventHandler().removeListener(listenerRef.get()); + loginCallback.accept(event.getPlayer()); } }).build(); listenerRef.set(listener);