Anvil
Building blocksEnvironmentsActions

Overview

Find running process handles, execute commands, call agents, and restart or kill servers or proxies.

Use ScenarioContext.processes() to inspect the current server and proxy processes in a running scenario. It is available inside an injected JUnit context or the context returned by ScenarioEngine.start().

Find a process

This fragment assumes anvil is an open ScenarioContext from the proxy environment:

var processes = anvil.processes();
var proxy = processes.proxy("proxy");
var lobby = processes.server("lobby");
System.out.println(proxy.address());
System.out.println(lobby.files().read("server.properties"));

Names are the ones declared in the scenario. Lookups return current handles; typed lookups also check whether the named process has the expected role.

OperationResult
get(name)Any declared server or proxy
server(name) / proxy(name)A process of the specified role
all()Immutable snapshot of processes in launch order
servers() / proxies()Immutable snapshot filtered by role
restart(name)Replacement process after readiness
kill(name)Stopped process, ended without its shutdown sequence

Every handle exposes name(), address(), files(), state(), and console().

Read and change a process's files

files() reaches the process's workspace wherever its workbench keeps it. Paths are relative to the workspace and separated by /; a path that leaves the workspace is refused. Its methods throw IOException.

import me.whereareiam.anvil.api.process.ProcessFiles;
ProcessFiles files = lobby.files();
String properties = files.read("server.properties");
files.write("plugins/Example/config.yml", "enabled: false\n");
List<String> plugins = files.list("plugins");
files.delete("plugins/Example");

Restarts keep the files: every generation of a process shares one workspace. location() describes where the workspace is for diagnostics, such as its path on the local machine. Use capability(Type.class) for installed process behavior, including capabilities backed by agents. After a restart, request a fresh lookup or use the returned replacement handle. An earlier snapshot continues to contain the earlier handles.

Own the lifecycle through the scenario

Anvil prepares declared assets and dependencies before configuring platforms. It starts servers before proxies, waits for process and agent readiness, and runs the setup hook before returning the context. Closing the context releases players and stops processes in reverse order.

Independent preparation and process startup may run concurrently within the configured limits. A ready process says nothing about whether your plugin action succeeded: establish that with the appropriate player, server, or console assertion.

Choose an action

Choose the operation your test needs to perform against an existing server or proxy:

  • Running console commands shows bounded log observations.
  • Dispatching commands runs a command as the console and reports whether the platform accepted it.
  • Interacting through agents explains typed capabilities and native work inside a server or proxy.
  • Watching players on a process waits until a player is on a server and reads what a server or proxy knows about it.
  • Moving players between worlds lists a server's worlds, creates, loads, unloads and deletes worlds on Paper and Spigot, waits for the server to load one, finds the world a player is in, moves it to another one and waits for the server to report the move.
  • Waiting for ticks waits for a server's ticks or until a condition holds instead of sleeping, and sets how fast the server runs them, up to as fast as it can as /tick sprint does.
  • Restarting processes covers workspace preservation and explicit player reconnection.
  • Killing processes ends a server or proxy as if it had crashed, without its shutdown.
  • Cleanup diagnostics explains lifecycle failures and retention.

On this page