0.4.3 • Published 2 days ago

@jsprismarine/brigadier v0.4.3

Weekly downloads
105
License
MIT
Repository
github
Last release
2 days ago

@jsprismarine/brigadier

License Join the Discord Server npm

@jsprismarine/brigadier is a Node.js version of Mojang's Brigadier library. It is a command parser & dispatcher, originally designed and developed for Minecraft: Java Edition and now freely available for use elsewhere under the MIT license.

This project was originally developed by remtori as node-brigadier.

Prerequisites

Before you begin, ensure you have met the following requirements:

  • You have installed the latest version of Node.js and a package manager like npm, pnpm or bun.

Installation

To install JSPrismarine/brigadier, use the following command:

npm install @jsprismarine/brigadier --save

Usage

Dispatch a command

import { CommandDispatcher, literal, argument, string, Suggestions } from '@jsprismarine/brigadier';

// Define a BlockPos class
class BlockPos {
    constructor(x = 0, y = 0, z = 0) {
        this.x = x;
        this.y = y;
        this.z = z;
    }
    parse(reader) {
        this.x = reader.readInt();
        reader.skip();
        this.y = reader.readInt();
        reader.skip();
        this.z = reader.readInt();
        return this;
    }
    listSuggestions(context, builder) {
        return Suggestions.empty();
    }
    getExamples() {
        return ['1 2 3'];
    }
}

// Create a new CommandDispatcher
const dispatcher = new CommandDispatcher();

// Register a command
dispatcher.register(
    literal('fill').then(
        argument('pos1', new BlockPos()).then(
            argument('pos2', new BlockPos()).then(
                argument('block', string()).executes((context) => {
                    console.log(context.getArgument('pos1', BlockPos));
                    console.log(context.getArgument('pos2', BlockPos));
                    console.log(context.getArgument('block', 3));
                    return 0;
                })
            )
        )
    )
);

// Parse a command
const parsedCommand = dispatcher.parse('fill 3 4 5 10 11 12 air', {});

// Execute the command
try {
    dispatcher.execute(parsedCommand);
} catch (error) {
    console.error(error.getMessage());
}
0.4.3

11 days ago

0.4.2

11 days ago

0.4.1

17 days ago

0.4.0

20 days ago

0.3.0

25 days ago

0.2.1

25 days ago

0.2.0-rc.1

3 years ago

0.1.0

3 years ago