mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-26 11:07:53 +01:00
Add login callback
This commit is contained in:
parent
6340a10331
commit
c24bf3d13d
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user