Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencyResolutionManagement {

versionCatalogs {
create("libs") {
version("minestom", "2025.10.05-1.21.8")
version("minestom", "2025.10.11-1.21.10")
version("junit", "6.0.0")
version("junit.platform", "6.0.0")

Expand Down
30 changes: 19 additions & 11 deletions src/main/java/net/minestom/testing/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
import net.minestom.server.entity.Player;
import net.minestom.server.event.Event;
import net.minestom.server.event.EventFilter;
import net.minestom.server.instance.IChunkLoader;
import net.minestom.server.instance.ChunkLoader;
import net.minestom.server.instance.Instance;
import net.minestom.server.instance.block.Block;
import net.minestom.server.network.player.GameProfile;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.time.Duration;
Expand Down Expand Up @@ -86,7 +85,7 @@ default TestConnection createConnection() {
* @param <H> the handler type
* @return the {@link Collector} instance to use
*/
<E extends Event, H> Collector<E> trackEvent(Class<E> eventType, EventFilter<? super E, H> filter, @NotNull H actor);
<E extends Event, H> Collector<E> trackEvent(Class<E> eventType, EventFilter<? super E, H> filter, H actor);

/**
* Listen for a specific event type in the test environment.
Expand All @@ -111,7 +110,7 @@ default void tick() {
* @param timeout the maximum duration to wait for the condition to be met, or null for no timeout
* @return true if the condition was met, false if the timeout was reached
*/
default boolean tickWhile(@NotNull BooleanSupplier condition, @Nullable Duration timeout) {
default boolean tickWhile(BooleanSupplier condition, @Nullable Duration timeout) {
var ticker = process().ticker();
final long start = System.nanoTime();
while (condition.getAsBoolean()) {
Expand All @@ -131,7 +130,7 @@ default boolean tickWhile(@NotNull BooleanSupplier condition, @Nullable Duration
* @param pos the position to spawn the player at
* @return the created player
*/
default @NotNull Player createPlayer(@NotNull Instance instance, @NotNull Pos pos) {
default Player createPlayer(Instance instance, Pos pos) {
return createConnection().connect(instance, pos);
}

Expand All @@ -141,7 +140,7 @@ default boolean tickWhile(@NotNull BooleanSupplier condition, @Nullable Duration
* @param instance the instance to spawn the player in
* @return the created player
*/
default @NotNull Player createPlayer(@NotNull Instance instance) {
default Player createPlayer(Instance instance) {
return createPlayer(instance, Pos.ZERO);
}

Expand All @@ -150,7 +149,7 @@ default boolean tickWhile(@NotNull BooleanSupplier condition, @Nullable Duration
*
* @return the created instance
*/
default @NotNull Instance createFlatInstance() {
default Instance createFlatInstance() {
return createFlatInstance(null);
}

Expand All @@ -160,18 +159,27 @@ default boolean tickWhile(@NotNull BooleanSupplier condition, @Nullable Duration
* @param chunkLoader the chunk loader to use for the instance
* @return the created instance
*/
default @NotNull Instance createFlatInstance(@Nullable IChunkLoader chunkLoader) {
default Instance createFlatInstance(@Nullable ChunkLoader chunkLoader) {
var instance = process().instance().createInstanceContainer(chunkLoader);
instance.setGenerator(unit -> unit.modifier().fillHeight(0, 40, Block.STONE));
return instance;
}

/**
* Creates a new {@link Instance} which is empty and can be used in the test environment.
* @param chunkLoader the chunk loader to use for the instance
* @return the created instance
*/
default Instance createEmptyInstance(ChunkLoader chunkLoader) {
return process().instance().createInstanceContainer(chunkLoader);
}

/**
* Creates a new {@link Instance} which is empty and can be used in the test environment.
*
* @return the created instance
*/
default @NotNull Instance createEmptyInstance() {
default Instance createEmptyInstance() {
return process().instance().createInstanceContainer();
}

Expand All @@ -181,7 +189,7 @@ default boolean tickWhile(@NotNull BooleanSupplier condition, @Nullable Duration
*
* @param instance the instance to destroy
*/
default void destroyInstance(@NotNull Instance instance) {
default void destroyInstance(Instance instance) {
destroyInstance(instance, false);
}

Expand All @@ -191,7 +199,7 @@ default void destroyInstance(@NotNull Instance instance) {
* @param instance the instance to destroy
* @param cleanUpPlayers whether to remove players from the instance
*/
default void destroyInstance(@NotNull Instance instance, boolean cleanUpPlayers) {
default void destroyInstance(Instance instance, boolean cleanUpPlayers) {
if (cleanUpPlayers && !instance.getPlayers().isEmpty()) {
instance.getPlayers().forEach(Player::remove);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/minestom/testing/TestConnectionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.concurrent.atomic.AtomicBoolean;

final class TestConnectionImpl implements TestConnection {

private final ServerProcess process;
private final GameProfile gameProfile;
private final PlayerConnectionImpl playerConnection = new PlayerConnectionImpl();
Expand Down Expand Up @@ -59,7 +58,8 @@ public Player connect(Instance instance, Pos pos) {
future.complete(player);
});
future.join();
playerConnection.setConnectionState(ConnectionState.PLAY);
playerConnection.setClientState(ConnectionState.PLAY);
playerConnection.setServerState(ConnectionState.PLAY);
process.connection().updateWaitingPlayers();
return player;
}
Expand All @@ -84,7 +84,7 @@ public void sendPacket(SendablePacket packet) {

private ServerPacket extractPacket(final SendablePacket packet) {
if (!(packet instanceof ServerPacket serverPacket))
return SendablePacket.extractServerPacket(getConnectionState(), packet);
return SendablePacket.extractServerPacket(getServerState(), packet);

final Player player = getPlayer();
if (player == null) return serverPacket;
Expand Down
Loading