Interface TestServerContext
- All Known Subinterfaces:
TestDedicatedServerContext
@NonExtendable
public interface TestServerContext
Context for a client gametest containing various helpful functions while a server (integrated or dedicated) is
running.
Unless otherwise specified, methods in this class can only be called on the client gametest thread.
-
Method Summary
Modifier and TypeMethodDescriptioncomputeOnServer(org.apache.commons.lang3.function.FailableFunction<net.minecraft.server.MinecraftServer, T, E> function) Runs the given function on the server thread, and returns the result.voidrunCommand(String command) Runs a command on the server.<E extends Throwable>
voidrunOnServer(org.apache.commons.lang3.function.FailableConsumer<net.minecraft.server.MinecraftServer, E> action) Runs the given action on the server thread, and waits for it to complete.intWaits for a predicate to be true.intWaits for a predicate to be true.
-
Method Details
-
runCommand
Runs a command on the server.- Parameters:
command- The command to run
-
runOnServer
<E extends Throwable> void runOnServer(org.apache.commons.lang3.function.FailableConsumer<net.minecraft.server.MinecraftServer, E> action) throws E Runs the given action on the server thread, and waits for it to complete. If already on the server thread, this action is run directly.This method can be called from the client gametest thread and the server thread.
- Type Parameters:
E- The type of the checked exception that the action throws- Parameters:
action- The action to run on the server thread- Throws:
E- When the action throws an exception
-
computeOnServer
<T extends @Nullable Object, E extends Throwable> T computeOnServer(org.apache.commons.lang3.function.FailableFunction<net.minecraft.server.MinecraftServer, T, E> function) throws E Runs the given function on the server thread, and returns the result. If already on the server thread, the function is run directly.This method can be called from the client gametest thread and the server thread.
- Type Parameters:
T- The type of the value to returnE- The type of the checked exception that the function throws- Parameters:
function- The function to run on the server thread- Returns:
- The result of the function
- Throws:
E- When the function throws an exception
-
waitFor
Waits for a predicate to be true. Fails if the predicate is not satisfied afterClientGameTestContext.DEFAULT_TIMEOUTticks.- Parameters:
predicate- The predicate to check- Returns:
- The number of ticks waited
-
waitFor
Waits for a predicate to be true. Fails if the predicate is not satisfied aftertimeoutticks. IftimeoutisClientGameTestContext.NO_TIMEOUT, there is no timeout.- Parameters:
predicate- The predicate to checktimeout- The number of ticks before timing out- Returns:
- The number of ticks waited
-