dev.polymodloader.api.command
This page is generated from the source's Javadoc by ./gradlew apiReference. Do not edit it; fix the source comment and generate it again.
| Type | Kind | Description |
|---|---|---|
ArgumentCommand | class | A typed value in a command. |
CommandAction | functional interface | What a command does. |
CommandArgumentType | interface | What a command argument accepts; each maps to one of the game's argument parsers, so clients complete and validate them natively. |
CommandArgumentType.BlockPosType | record | Block coordinates, absolute or relative (~ ~1 ~); read with CommandContext.getBlockPos(String). |
CommandArgumentType.BooleanType | record | true or false; read with CommandContext.getBoolean(String). |
CommandArgumentType.DecimalType | record | Decimal number in [min, max]; read with CommandContext.getDouble(String). |
CommandArgumentType.IntegerType | record | Whole number in [min, max]; read with CommandContext.getInteger(String). |
CommandArgumentType.PlayerType | record | One online player by name or selector; read with CommandContext.getPlayer(String). |
CommandArgumentType.TextKind | enum | How much text a TextType consumes. |
CommandArgumentType.TextType | record | Text: one word, a quotable string, or the rest of the line; read with CommandContext.getString(String). |
CommandContext | interface | Parsed arguments and the source of a running command. |
CommandFailure | class | Thrown by a CommandAction to fail with a message shown to the command source in red. |
CommandNode | abstract class | One word of a command: a fixed LiteralCommand or a typed ArgumentCommand. |
CommandRegistrar | interface | Registers server commands. |
CommandSource | interface | Who or what ran a command: a player, the console, a command block, or a function. |
LiteralCommand | class | A fixed word in a command. |
ArgumentCommand
class · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public final class ArgumentCommand extends CommandNode<ArgumentCommand>
A typed value in a command. Create with CommandNode.argument(String, CommandArgumentType).
Supertypes: CommandNode
type()
public CommandArgumentType type()
Since 0.1.0-alpha.4 or earlier
What the argument accepts.
Returns CommandArgumentType
CommandAction
functional interface · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public interface CommandAction
What a command does. Runs on the server thread.
run(CommandContext)
int run(CommandContext context) throws CommandFailure
Since 0.1.0-alpha.4 or earlier
Runs the command.
| Parameter | Type | Description |
|---|---|---|
context | CommandContext | — |
Returns int — the command's result value (used by /execute store); 1 conventionally means success
Throws CommandFailure — to show an error message to the source and report failure
CommandArgumentType
interface · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public sealed interface CommandArgumentType
What a command argument accepts; each maps to one of the game's argument parsers, so clients complete and validate them natively.
integer()
static CommandArgumentType integer()
Since 0.1.0-alpha.4 or earlier
Any whole number.
Returns CommandArgumentType
integer(int, int)
static CommandArgumentType integer(int min, int max)
Since 0.1.0-alpha.4 or earlier
A whole number in [min, max].
| Parameter | Type | Description |
|---|---|---|
min | int | — |
max | int | — |
Returns CommandArgumentType
decimal()
static CommandArgumentType decimal()
Since 0.1.0-alpha.4 or earlier
Any decimal number.
Returns CommandArgumentType
bool()
static CommandArgumentType bool()
Since 0.1.0-alpha.4 or earlier
true or false.
Returns CommandArgumentType
word()
static CommandArgumentType word()
Since 0.1.0-alpha.4 or earlier
A single word.
Returns CommandArgumentType
string()
static CommandArgumentType string()
Since 0.1.0-alpha.4 or earlier
A word or quoted text.
Returns CommandArgumentType
greedyString()
static CommandArgumentType greedyString()
Since 0.1.0-alpha.4 or earlier
The rest of the command line.
Returns CommandArgumentType
blockPos()
static CommandArgumentType blockPos()
Since 0.1.0-alpha.4 or earlier
Block coordinates.
Returns CommandArgumentType
player()
static CommandArgumentType player()
Since 0.1.0-alpha.4 or earlier
One online player.
Returns CommandArgumentType
CommandArgumentType.BlockPosType
record · Since 0.1.0-alpha.4 or earlier
public static record BlockPosType() implements CommandArgumentType
Block coordinates, absolute or relative (~ ~1 ~); read with CommandContext.getBlockPos(String).
| Component | Type | Description |
|---|
Supertypes: CommandArgumentType
CommandArgumentType.BooleanType
record · Since 0.1.0-alpha.4 or earlier
public static record BooleanType() implements CommandArgumentType
true or false; read with CommandContext.getBoolean(String).
| Component | Type | Description |
|---|
Supertypes: CommandArgumentType
CommandArgumentType.DecimalType
record · Since 0.1.0-alpha.4 or earlier
public static record DecimalType(double min, double max) implements CommandArgumentType
Decimal number in [min, max]; read with CommandContext.getDouble(String).
| Component | Type | Description |
|---|---|---|
min | double | — |
max | double | — |
Supertypes: CommandArgumentType
CommandArgumentType.IntegerType
record · Since 0.1.0-alpha.4 or earlier
public static record IntegerType(int min, int max) implements CommandArgumentType
Whole number in [min, max]; read with CommandContext.getInteger(String).
| Component | Type | Description |
|---|---|---|
min | int | — |
max | int | — |
Supertypes: CommandArgumentType
CommandArgumentType.PlayerType
record · Since 0.1.0-alpha.4 or earlier
public static record PlayerType() implements CommandArgumentType
One online player by name or selector; read with CommandContext.getPlayer(String).
| Component | Type | Description |
|---|
Supertypes: CommandArgumentType
CommandArgumentType.TextKind
enum · Since 0.1.0-alpha.4 or earlier
public static enum TextKind
How much text a TextType consumes.
| Constant | Description |
|---|---|
WORD | Letters, digits, and _ - . +. |
QUOTABLE | A word, or text in double quotes. |
GREEDY | Everything until the end of the command. |
CommandArgumentType.TextType
record · Since 0.1.0-alpha.4 or earlier
public static record TextType(CommandArgumentType.TextKind kind) implements CommandArgumentType
Text: one word, a quotable string, or the rest of the line; read with CommandContext.getString(String).
| Component | Type | Description |
|---|---|---|
kind | CommandArgumentType.TextKind | — |
Supertypes: CommandArgumentType
CommandContext
interface · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public interface CommandContext
Parsed arguments and the source of a running command. Valid only during the action. Reading an argument that is not on the executed path, or with the wrong type, throws IllegalArgumentException.
source()
CommandSource source()
Since 0.1.0-alpha.4 or earlier
Who ran the command.
Returns CommandSource
getInteger(String)
int getInteger(String name)
Since 0.1.0-alpha.4 or earlier
Value of an CommandArgumentType.integer() argument.
| Parameter | Type | Description |
|---|---|---|
name | String | — |
Returns int
getDouble(String)
double getDouble(String name)
Since 0.1.0-alpha.4 or earlier
Value of a CommandArgumentType.decimal() argument.
| Parameter | Type | Description |
|---|---|---|
name | String | — |
Returns double
getBoolean(String)
boolean getBoolean(String name)
Since 0.1.0-alpha.4 or earlier
Value of a CommandArgumentType.bool() argument.
| Parameter | Type | Description |
|---|---|---|
name | String | — |
Returns boolean
getString(String)
String getString(String name)
Since 0.1.0-alpha.4 or earlier
Value of a text argument.
| Parameter | Type | Description |
|---|---|---|
name | String | — |
Returns String
getBlockPos(String)
BlockPos getBlockPos(String name) throws CommandFailure
Since 0.1.0-alpha.4 or earlier
Value of a CommandArgumentType.blockPos() argument, resolved against the source.
| Parameter | Type | Description |
|---|---|---|
name | String | — |
Returns BlockPos
Throws CommandFailure — when the position is not loaded
getPlayer(String)
PlayerView getPlayer(String name) throws CommandFailure
Since 0.1.0-alpha.4 or earlier
Value of a CommandArgumentType.player() argument.
| Parameter | Type | Description |
|---|---|---|
name | String | — |
Returns PlayerView
Throws CommandFailure — when no single online player matches
CommandFailure
class · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public final class CommandFailure extends Exception
Thrown by a CommandAction to fail with a message shown to the command source in red.
CommandFailure(String)
public CommandFailure(String message)
Since 0.1.0-alpha.4 or earlier
Creates a failure with the message shown to the user.
| Parameter | Type | Description |
|---|---|---|
message | String | — |
CommandNode
abstract class · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public abstract sealed class CommandNode<N extends CommandNode<N>>
One word of a command: a fixed LiteralCommand or a typed ArgumentCommand. Nodes form a tree; a node with an action can end the command.
literal(String)
public static LiteralCommand literal(String name)
Since 0.1.0-alpha.4 or earlier
A fixed word, for example /hello.
| Parameter | Type | Description |
|---|---|---|
name | String | — |
Returns LiteralCommand
argument(String, CommandArgumentType)
public static ArgumentCommand argument(String name, CommandArgumentType type)
Since 0.1.0-alpha.4 or earlier
A typed value; read it in actions with context.get*(name).
| Parameter | Type | Description |
|---|---|---|
name | String | — |
type | CommandArgumentType | — |
Returns ArgumentCommand
then(CommandNode<?>)
public N then(CommandNode<?> child)
Since 0.1.0-alpha.4 or earlier
Adds a child that may follow this node.
| Parameter | Type | Description |
|---|---|---|
child | CommandNode<?> | — |
Returns N
executes(CommandAction)
public N executes(CommandAction action)
Since 0.1.0-alpha.4 or earlier
Lets the command end at this node and run action.
| Parameter | Type | Description |
|---|---|---|
action | CommandAction | — |
Returns N
requiresPermission(int)
public N requiresPermission(int level)
Since 0.1.0-alpha.4 or earlier
Only sources with at least this permission level can see and run this node: 0 everyone, 2 game masters (command blocks, operators), 4 server owners.
| Parameter | Type | Description |
|---|---|---|
level | int | — |
Returns N
requiresPermission(PermissionNode)
public N requiresPermission(PermissionNode node)
Since 0.1.0-alpha.4 or earlier
Only sources that have node can see and run this node.
| Parameter | Type | Description |
|---|---|---|
node | PermissionNode | — |
Returns N
permissionNode()
public Optional<PermissionNode> permissionNode()
Since 0.1.0-alpha.4 or earlier
The required named permission, if any (checked in addition to the level).
Returns Optional<PermissionNode>
name()
public String name()
Since 0.1.0-alpha.4 or earlier
The word or argument name.
Returns String
children()
public List<CommandNode<?>> children()
Since 0.1.0-alpha.4 or earlier
Child nodes in registration order.
Returns List<CommandNode<?>>
action()
public Optional<CommandAction> action()
Since 0.1.0-alpha.4 or earlier
The action run when the command ends here.
Returns Optional<CommandAction>
permissionLevel()
public int permissionLevel()
Since 0.1.0-alpha.4 or earlier
Required permission level, 0–4.
Returns int
CommandRegistrar
interface · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public interface CommandRegistrar
Registers server commands. Poly Mod Loader adds them every time the server builds its command tree (server start and /reload), on every server kind, including single player.
When: inside common entrypoints. Registering a name that another mod or the game already uses merges the trees as the game does; Poly Mod Loader logs POLY-COMMAND-001 when two mods register the same top-level name.
register(LiteralCommand)
void register(LiteralCommand command)
Since 0.1.0-alpha.4 or earlier
Registers a top-level command. Do not change command or its children afterwards.
| Parameter | Type | Description |
|---|---|---|
command | LiteralCommand | — |
Throws IllegalStateException — after registration closed (POLY-COMMAND-002)
CommandSource
interface · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public interface CommandSource
Who or what ran a command: a player, the console, a command block, or a function.
name()
String name()
Since 0.1.0-alpha.4 or earlier
Display name, for example a player name or Server.
Returns String
sendMessage(String)
void sendMessage(String text)
Since 0.1.0-alpha.4 or earlier
Sends feedback text to the source.
| Parameter | Type | Description |
|---|---|---|
text | String | — |
sendFailure(String)
void sendFailure(String text)
Since 0.1.0-alpha.4 or earlier
Sends an error message (shown in red to players).
| Parameter | Type | Description |
|---|---|---|
text | String | — |
hasPermission(int)
boolean hasPermission(int level)
Since 0.1.0-alpha.4 or earlier
Whether the source has at least permission level (0–4).
| Parameter | Type | Description |
|---|---|---|
level | int | — |
Returns boolean
hasPermission(PermissionNode)
boolean hasPermission(PermissionNode node)
Since 0.1.0-alpha.4 or earlier
Whether the source has the permission: for players as PlayerView.hasPermission; for the console, command blocks, and functions by the node's default level.
| Parameter | Type | Description |
|---|---|---|
node | PermissionNode | — |
Returns boolean
player()
Optional<PlayerView> player()
Since 0.1.0-alpha.4 or earlier
The player who ran the command, if a player did.
Returns Optional<PlayerView>
world()
WorldView world()
Since 0.1.0-alpha.4 or earlier
The world the command runs in.
Returns WorldView
blockPos()
BlockPos blockPos()
Since 0.1.0-alpha.4 or earlier
The block position the command runs at.
Returns BlockPos
LiteralCommand
class · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public final class LiteralCommand extends CommandNode<LiteralCommand>
A fixed word in a command. Create with CommandNode.literal(String).
Supertypes: CommandNode