diff --git a/1_20/1_20_6/src/main/java/me/earth/mc_runtime_test/McGameTestRunner.java b/1_20/1_20_6/src/main/java/me/earth/mc_runtime_test/McGameTestRunner.java index 1cce3fd..1f7fb5d 100644 --- a/1_20/1_20_6/src/main/java/me/earth/mc_runtime_test/McGameTestRunner.java +++ b/1_20/1_20_6/src/main/java/me/earth/mc_runtime_test/McGameTestRunner.java @@ -5,6 +5,7 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.player.Player; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import java.util.Collection; @@ -27,7 +28,7 @@ public class McGameTestRunner { * @param playerUUID the uuid of the player. * @param server the server to run the tests on. */ - public static MultipleTestTracker runGameTests(UUID playerUUID, MinecraftServer server) throws ExecutionException, InterruptedException, TimeoutException { + public static @Nullable MultipleTestTracker runGameTests(UUID playerUUID, MinecraftServer server) throws ExecutionException, InterruptedException, TimeoutException { return server.submit(() -> { Player player = Objects.requireNonNull(server.getPlayerList().getPlayer(playerUUID)); ServerLevel level = (ServerLevel) player.level(); @@ -37,6 +38,8 @@ public static MultipleTestTracker runGameTests(UUID playerUUID, MinecraftServer if (testFunctions.size() < McRuntimeTest.MIN_GAME_TESTS_TO_FIND) { LOGGER.error("Failed to find the minimum amount of gametests, expected " + McRuntimeTest.MIN_GAME_TESTS_TO_FIND + ", but found " + testFunctions.size()); throw new IllegalStateException("Failed to find the minimum amount of gametests, expected " + McRuntimeTest.MIN_GAME_TESTS_TO_FIND + ", but found " + testFunctions.size()); + } else if (testFunctions.isEmpty()) { + return null; } GameTestRegistry.forgetFailedTests(); diff --git a/1_20/1_20_6/src/main/java/me/earth/mc_runtime_test/mixin/MixinMinecraft.java b/1_20/1_20_6/src/main/java/me/earth/mc_runtime_test/mixin/MixinMinecraft.java index 74b9689..6e0bba3 100644 --- a/1_20/1_20_6/src/main/java/me/earth/mc_runtime_test/mixin/MixinMinecraft.java +++ b/1_20/1_20_6/src/main/java/me/earth/mc_runtime_test/mixin/MixinMinecraft.java @@ -90,6 +90,11 @@ private void tickHook(CallbackInfo ci) throws ExecutionException, InterruptedExc if (McRuntimeTest.RUN_GAME_TESTS) { LOGGER.info("Running game tests..."); mcRuntimeTest$testTracker = McGameTestRunner.runGameTests(player.getUUID(), Objects.requireNonNull(singleplayerServer)); + if (mcRuntimeTest$testTracker == null) { + mcRuntimeTest$testTracker = new MultipleTestTracker(); + LOGGER.info("No tests found, Successfully finished."); + mcRuntime$stop(); + } } else { LOGGER.info("Successfully finished."); mcRuntime$stop(); @@ -120,8 +125,8 @@ private void tickHook(CallbackInfo ci) throws ExecutionException, InterruptedExc private void mcRuntime$stop() { IntegratedServer server = singleplayerServer; if (server != null) { - this.disconnect(); server.halt(true); + this.disconnect(); } running = false; diff --git a/1_21/src/main/java/me/earth/mc_runtime_test/McGameTestRunner.java b/1_21/src/main/java/me/earth/mc_runtime_test/McGameTestRunner.java index 1cce3fd..1f7fb5d 100644 --- a/1_21/src/main/java/me/earth/mc_runtime_test/McGameTestRunner.java +++ b/1_21/src/main/java/me/earth/mc_runtime_test/McGameTestRunner.java @@ -5,6 +5,7 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.player.Player; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import java.util.Collection; @@ -27,7 +28,7 @@ public class McGameTestRunner { * @param playerUUID the uuid of the player. * @param server the server to run the tests on. */ - public static MultipleTestTracker runGameTests(UUID playerUUID, MinecraftServer server) throws ExecutionException, InterruptedException, TimeoutException { + public static @Nullable MultipleTestTracker runGameTests(UUID playerUUID, MinecraftServer server) throws ExecutionException, InterruptedException, TimeoutException { return server.submit(() -> { Player player = Objects.requireNonNull(server.getPlayerList().getPlayer(playerUUID)); ServerLevel level = (ServerLevel) player.level(); @@ -37,6 +38,8 @@ public static MultipleTestTracker runGameTests(UUID playerUUID, MinecraftServer if (testFunctions.size() < McRuntimeTest.MIN_GAME_TESTS_TO_FIND) { LOGGER.error("Failed to find the minimum amount of gametests, expected " + McRuntimeTest.MIN_GAME_TESTS_TO_FIND + ", but found " + testFunctions.size()); throw new IllegalStateException("Failed to find the minimum amount of gametests, expected " + McRuntimeTest.MIN_GAME_TESTS_TO_FIND + ", but found " + testFunctions.size()); + } else if (testFunctions.isEmpty()) { + return null; } GameTestRegistry.forgetFailedTests(); diff --git a/1_21/src/main/java/me/earth/mc_runtime_test/mixin/MixinMinecraft.java b/1_21/src/main/java/me/earth/mc_runtime_test/mixin/MixinMinecraft.java index f20757e..08afacc 100644 --- a/1_21/src/main/java/me/earth/mc_runtime_test/mixin/MixinMinecraft.java +++ b/1_21/src/main/java/me/earth/mc_runtime_test/mixin/MixinMinecraft.java @@ -91,6 +91,11 @@ private void tickHook(CallbackInfo ci) throws ExecutionException, InterruptedExc if (McRuntimeTest.RUN_GAME_TESTS) { LOGGER.info("Running game tests..."); mcRuntimeTest$testTracker = McGameTestRunner.runGameTests(player.getUUID(), Objects.requireNonNull(singleplayerServer)); + if (mcRuntimeTest$testTracker == null) { + mcRuntimeTest$testTracker = new MultipleTestTracker(); + LOGGER.info("No tests found, Successfully finished."); + mcRuntime$stop(); + } } else { LOGGER.info("Successfully finished."); mcRuntime$stop(); @@ -121,8 +126,8 @@ private void tickHook(CallbackInfo ci) throws ExecutionException, InterruptedExc private void mcRuntime$stop() { IntegratedServer server = singleplayerServer; if (server != null) { - disconnect(); server.halt(true); + disconnect(); } running = false;