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 Type
    Method
    Description
    <T extends @Nullable Object, E extends Throwable>
    T
    computeOnServer(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.
    void
    runCommand(String command)
    Runs a command on the server.
    <E extends Throwable>
    void
    runOnServer(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.
    int
    waitFor(Predicate<net.minecraft.server.MinecraftServer> predicate)
    Waits for a predicate to be true.
    int
    waitFor(Predicate<net.minecraft.server.MinecraftServer> predicate, int timeout)
    Waits for a predicate to be true.
  • Method Details

    • runCommand

      void runCommand(String command)
      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 return
      E - 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

      int waitFor(Predicate<net.minecraft.server.MinecraftServer> predicate)
      Waits for a predicate to be true. Fails if the predicate is not satisfied after ClientGameTestContext.DEFAULT_TIMEOUT ticks.
      Parameters:
      predicate - The predicate to check
      Returns:
      The number of ticks waited
    • waitFor

      int waitFor(Predicate<net.minecraft.server.MinecraftServer> predicate, int timeout)
      Waits for a predicate to be true. Fails if the predicate is not satisfied after timeout ticks. If timeout is ClientGameTestContext.NO_TIMEOUT, there is no timeout.
      Parameters:
      predicate - The predicate to check
      timeout - The number of ticks before timing out
      Returns:
      The number of ticks waited