Commands
25 minCreate player commands with arguments and permissions.
Creating Commands
Commands let players interact with your plugin via chat.
Basic Command
public class HelloCommand extends AbstractPlayerCommand { public HelloCommand() {
super("hello");
}
@Override
public void execute(ServerPlayer player, Arguments args) {
player.sendMessage(Component.text("Hello, " + player.getName() + "!"));
}
}
Registering Commands
@Override
public void setup() {
getServer().getCommandManager()
.register(new HelloCommand());
}Command Arguments
public class TeleportCommand extends AbstractPlayerCommand { public TeleportCommand() {
super("tp");
// Define arguments
addArgument(new DoubleArgument("x"));
addArgument(new DoubleArgument("y"));
addArgument(new DoubleArgument("z"));
}
@Override
public void execute(ServerPlayer player, Arguments args) {
double x = args.get("x", Double.class);
double y = args.get("y", Double.class);
double z = args.get("z", Double.class);
// Teleport using Teleport component
Ref<EntityStore> ref = player.getEntityRef();
ref.add(Teleport.getComponentType(),
new Teleport(new Vector3d(x, y, z)));
player.sendMessage(Component.text("Teleported!"));
}
}
Available Argument Types
StringArgument- textIntegerArgument- whole numbersDoubleArgument- decimal numbersPlayerArgument- online playerBooleanArgument- true/false