Skip to main content
Version: Minecraft 26.2

dev.polymodloader.api.command

Generated

This page is generated from the source's Javadoc by ./gradlew apiReference. Do not edit it; fix the source comment and generate it again.

TypeKindDescription
ArgumentCommandclassA typed value in a command.
CommandActionfunctional interfaceWhat a command does.
CommandArgumentTypeinterfaceWhat a command argument accepts; each maps to one of the game's argument parsers, so clients complete and validate them natively.
CommandArgumentType.BlockPosTyperecordBlock coordinates, absolute or relative (~ ~1 ~); read with CommandContext.getBlockPos(String).
CommandArgumentType.BooleanTyperecordtrue or false; read with CommandContext.getBoolean(String).
CommandArgumentType.DecimalTyperecordDecimal number in [min, max]; read with CommandContext.getDouble(String).
CommandArgumentType.IntegerTyperecordWhole number in [min, max]; read with CommandContext.getInteger(String).
CommandArgumentType.PlayerTyperecordOne online player by name or selector; read with CommandContext.getPlayer(String).
CommandArgumentType.TextKindenumHow much text a TextType consumes.
CommandArgumentType.TextTyperecordText: one word, a quotable string, or the rest of the line; read with CommandContext.getString(String).
CommandContextinterfaceParsed arguments and the source of a running command.
CommandFailureclassThrown by a CommandAction to fail with a message shown to the command source in red.
CommandNodeabstract classOne word of a command: a fixed LiteralCommand or a typed ArgumentCommand.
CommandRegistrarinterfaceRegisters server commands.
CommandSourceinterfaceWho or what ran a command: a player, the console, a command block, or a function.
LiteralCommandclassA 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.

ParameterTypeDescription
contextCommandContext—

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].

ParameterTypeDescription
minint—
maxint—

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).

ComponentTypeDescription

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).

ComponentTypeDescription

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).

ComponentTypeDescription
mindouble—
maxdouble—

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).

ComponentTypeDescription
minint—
maxint—

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).

ComponentTypeDescription

Supertypes: CommandArgumentType

CommandArgumentType.TextKind​

enum · Since 0.1.0-alpha.4 or earlier

public static enum TextKind

How much text a TextType consumes.

ConstantDescription
WORDLetters, digits, and _ - . +.
QUOTABLEA word, or text in double quotes.
GREEDYEverything 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).

ComponentTypeDescription
kindCommandArgumentType.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.

ParameterTypeDescription
nameString—

Returns int

getDouble(String)​

double getDouble(String name)

Since 0.1.0-alpha.4 or earlier

Value of a CommandArgumentType.decimal() argument.

ParameterTypeDescription
nameString—

Returns double

getBoolean(String)​

boolean getBoolean(String name)

Since 0.1.0-alpha.4 or earlier

Value of a CommandArgumentType.bool() argument.

ParameterTypeDescription
nameString—

Returns boolean

getString(String)​

String getString(String name)

Since 0.1.0-alpha.4 or earlier

Value of a text argument.

ParameterTypeDescription
nameString—

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.

ParameterTypeDescription
nameString—

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.

ParameterTypeDescription
nameString—

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.

ParameterTypeDescription
messageString—

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.

ParameterTypeDescription
nameString—

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).

ParameterTypeDescription
nameString—
typeCommandArgumentType—

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.

ParameterTypeDescription
childCommandNode<?>—

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.

ParameterTypeDescription
actionCommandAction—

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.

ParameterTypeDescription
levelint—

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.

ParameterTypeDescription
nodePermissionNode—

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.

ParameterTypeDescription
commandLiteralCommand—

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.

ParameterTypeDescription
textString—

sendFailure(String)​

void sendFailure(String text)

Since 0.1.0-alpha.4 or earlier

Sends an error message (shown in red to players).

ParameterTypeDescription
textString—

hasPermission(int)​

boolean hasPermission(int level)

Since 0.1.0-alpha.4 or earlier

Whether the source has at least permission level (0–4).

ParameterTypeDescription
levelint—

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.

ParameterTypeDescription
nodePermissionNode—

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

Buy me a coffee