@jsprismarine/brigadier
    TypeScript icon, indicating that this package has built-in type declarations

    0.2.0-rc.1 • Public • Published

    @jsprismarine/brigadier

    This is a nodejs version of Mojang's Brigadier library. Originally developed by remtori.

    Brigadier is a command parser & dispatcher, designed and developed for Minecraft: Java Edition and now freely available for use elsewhere under the MIT license.

    Installation

    npm install @jsprismarine/brigadier --save
    

    Usage

    Dispatch a command

    const { CommandDispatcher, literal, argument, string, Suggestions } = require("node-brigadier")
    
    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"
    		]
    	}
    }
    
    const dispatcher = new CommandDispatcher();
    
    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", /*String*/ 3))
    					return 0;
    				})
    			)
    		)
    	)
    )
    
    const parsedCommand = dispatcher.parse("fill 3 4 5 10 11 12 air", {})
    try {
    	dispatcher.execute(parsedCommand);
    } catch (ex) {
    	console.error(ex.getMessage());
    }
    
    // Console
    // BlockPos { x: 3, y: 4, z: 5 }
    // BlockPos { x: 10, y: 11, z: 12 }
    // air

    Install

    npm i @jsprismarine/brigadier

    DownloadsWeekly Downloads

    551

    Version

    0.2.0-rc.1

    License

    MIT

    Unpacked Size

    445 kB

    Total Files

    208

    Last publish

    Collaborators

    • filiphsandstrom
    • herryyt