Add login callback

This commit is contained in:
themode 2022-01-23 09:12:30 +01:00
parent 6340a10331
commit c24bf3d13d
2 changed files with 9 additions and 3 deletions

View File

@ -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<Player> loginCallback);
default @NotNull CompletableFuture<@NotNull Player> connect(@NotNull Instance instance, @NotNull Pos pos) {
return connect(instance, pos, (player) -> {
});
}
<T extends ServerPacket> @NotNull PacketTracker<T> trackIncoming(@NotNull Class<T> type);
default @NotNull PacketTracker<ServerPacket> trackIncoming(){
default @NotNull PacketTracker<ServerPacket> trackIncoming() {
return trackIncoming(ServerPacket.class);
}

View File

@ -36,7 +36,7 @@ final class TestConnectionImpl implements TestConnection {
}
@Override
public @NotNull CompletableFuture<Player> connect(@NotNull Instance instance, @NotNull Pos pos) {
public @NotNull CompletableFuture<Player> connect(@NotNull Instance instance, @NotNull Pos pos, @NotNull Consumer<Player> loginCallback) {
AtomicReference<EventListener<PlayerLoginEvent>> 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);