• Stars
    star
    177
  • Rank 215,985 (Top 5 %)
  • Language
    Java
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Utility for using Minecraft's 1.13 'brigadier' library in Bukkit plugins.

commodore Javadocs Maven Central

commodore is a utility for using Minecraft's 1.13 brigadier library in Bukkit plugins. It allows you to easily register command completion data for your plugin's commands.

If you have questions, feel free to ask in Discord.

Example


Approaches to registering completion data

commodore supports:

  • Registering completions using brigadier's LiteralCommandNode builder API
  • Registering completions using commodore's .commodore file format

For example, implementing completions for Minecraft's /time command:

Using brigadier's LiteralCommandNode builder API

LiteralCommandNode<?> timeCommand = LiteralArgumentBuilder.literal("time")
        .then(LiteralArgumentBuilder.literal("set")
                .then(LiteralArgumentBuilder.literal("day"))
                .then(LiteralArgumentBuilder.literal("noon"))
                .then(LiteralArgumentBuilder.literal("night"))
                .then(LiteralArgumentBuilder.literal("midnight"))
                .then(RequiredArgumentBuilder.argument("time", IntegerArgumentType.integer())))
        .then(LiteralArgumentBuilder.literal("add")
                .then(RequiredArgumentBuilder.argument("time", IntegerArgumentType.integer())))
        .then(LiteralArgumentBuilder.literal("query")
                .then(LiteralArgumentBuilder.literal("daytime"))
                .then(LiteralArgumentBuilder.literal("gametime"))
                .then(LiteralArgumentBuilder.literal("day"))
        ).build();

commodore.register(bukkitCommand, timeCommand);

Using commodore's .commodore file format

time {
  set {
    day;
    noon;
    night;
    midnight;
    time brigadier:integer;
  }
  add {
    time brigadier:integer;
  }
  query {
    daytime;
    gametime;
    day;
  }
}
// assuming the file above is stored as "time.commodore" in the plugin jar
LiteralCommandNode<?> timeCommand = CommodoreFileFormat.parse(plugin.getResource("time.commodore"));
commodore.register(bukkitCommand, timeCommand);

Using the .commodore file format is recommended. In my opinion it is much easier to read/understand/update than the Node Builder API provided by brigadier.

Another example of a .commodore file can be found here, for the LuckPerms plugin commands. The corresponding code used to register the completions is here.

Usage

This guide assumes your plugin is built using Maven or Gradle though.

1) Configure your build script to shade commodore into your plugin jar

Maven

You need to add (or merge) the following sections into your pom.xml file.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <artifactSet>
                            <includes>
                                <include>me.lucko:commodore</include>
                            </includes>
                        </artifactSet>
                        <relocations>
                            <relocation>
                                <pattern>me.lucko.commodore</pattern>
                                <!-- vvv Replace with the package of your plugin vvv -->
                                <shadedPattern>com.yourdomain.yourplugin.commodore</shadedPattern>
                            </relocation>
                        </relocations>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>me.lucko</groupId>
        <artifactId>commodore</artifactId>
        <!-- vvv Replace with the latest commodore version vvv -->
        <version>{version}</version>
        <scope>compile</scope>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>minecraft-repo</id>
        <url>https://libraries.minecraft.net/</url>
    </repository>
</repositories>
Gradle

You need to add (or merge) the following sections into your build.gradle file.

plugins {
  id 'com.github.johnrengelman.shadow' version '6.1.0'
}

repositories {
  mavenCentral()
  maven { url 'https://libraries.minecraft.net/' }
}

dependencies {
  /* vvv Replace with the latest commodore version vvv */
  implementation 'me.lucko:commodore:{version}'
}

shadowJar {
  dependencies {
    exclude(dependency('com.mojang:brigadier'))
  }
  
  /* vvv Replace with the package of your plugin vvv */
  relocate 'me.lucko.commodore', 'com.yourdomain.yourplugin.commodore'
}

Replace {version} with the latest version: latest version

2) Setup commodore in your plugin

package me.lucko.example;

import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;

import me.lucko.commodore.Commodore;
import me.lucko.commodore.CommodoreProvider;

import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;

public class TestPlugin extends JavaPlugin {

    @Override
    public void onEnable() {

        // register your command executor as normal.
        PluginCommand command = getCommand("mycommand");
        command.setExecutor(new MyCommandExecutor());

        // check if brigadier is supported
        if (CommodoreProvider.isSupported()) {
            
            // get a commodore instance
            Commodore commodore = CommodoreProvider.getCommodore(this);

            // register your completions.
            registerCompletions(commodore, command);
        }
    }
    
    // You will need to put this method inside another class to prevent classloading
    // errors when your plugin loads on pre 1.13 versions.
    private static void registerCompletions(Commodore commodore, PluginCommand command) {
        commodore.register(command, LiteralArgumentBuilder.literal("mycommand")
                .then(RequiredArgumentBuilder.argument("some-argument", StringArgumentType.string()))
                .then(RequiredArgumentBuilder.argument("some-other-argument", BoolArgumentType.bool()))
        );
    }
}

The com.mojang.brigadier packages will be automatically imported into your classpath when you add the commodore dependency, but they should not be shaded into your plugins jar file.

More Repositories

1

spark

A performance profiler for Minecraft clients, servers, and proxies.
Java
1,027
star
2

helper

A collection of utilities and extended APIs to support the rapid and easy development of Bukkit plugins.
Java
456
star
3

paste

paste is a simple web app for writing & sharing code.
TypeScript
221
star
4

BungeeGuard

A plugin-based security/firewall solution for BungeeCord and Velocity proxies.
Java
211
star
5

bytebin

Fast & lightweight content storage web service.
Java
102
star
6

jar-relocator

A Java program to relocate classes within a jar archive using ASM.
Java
90
star
7

spark-viewer

Web frontend for spark.
TypeScript
77
star
8

fabric-permissions-api

A simple permissions API for Fabric
Java
52
star
9

minecraft-command-permissions-fabric

Registers vanilla Minecraft commands in Fabric Permission API with structure "minecraft.command.<command>"
Java
45
star
10

shadow

An annotation based API for Java reflection.
Java
26
star
11

bytesocks

Fast & lightweight WebSocket server with channels.
Java
21
star
12

infra

Config for the self-hosted infrastructure and services used by my open source projects
Roff
19
star
13

VaultChatFormatter

Java
16
star
14

shadow-bukkit

Extra annotations for use with shadow and Bukkit
Java
13
star
15

ScriptController

Extended API for Java's Scripting Engine framework
Java
12
star
16

gChat

A simple global chat plugin for BungeeCord.
Java
11
star
17

TinyVault

A minimal Vault plugin
Java
11
star
18

tapir

Java
10
star
19

commodore-file

The commodore file format
Java
7
star
20

LuckPermsUI

Desktop client for LuckPerms.
Java
7
star
21

paste-netcat

Upload content to pastes.dev using netcat
Go
6
star
22

synapse

Java
5
star
23

spark2json

Convert raw spark profiler data to JSON
JavaScript
5
star
24

bytesocks-java-client

A Java client for bytesocks
Java
5
star
25

spark-docs

Documentation for spark.
TypeScript
5
star
26

configurate-toml

Java
5
star
27

spark-mappings

Deobfuscation mappings data for spark-web
JavaScript
4
star
28

ConditionalPerms

Define permissions that only apply when conditions are met
Java
4
star
29

FindLag

Java
3
star
30

adventure-platform

Java
3
star
31

adventure

Java
3
star
32

SidebarManager

A simple scoreboard manager
Java
2
star
33

LogUploader

Java
2
star
34

NetworkAnalytics

Java
2
star
35

PunishmentGui

GUI based punishments with automatically scaled responses
Java
2
star
36

lucko.github.io

Personal website
JavaScript
2
star
37

servercmd

Adds /server on the backend server
Java
1
star
38

helper-dev

Misc utilities to aid with Minecraft in-game content design
Java
1
star
39

WelcomeTutorial

Java
1
star
40

synapse-plugins

Java
1
star
41

CommandBlocker

Java
1
star
42

mod-publish

Some handy scripts to automatically publish of some of my Minecraft mods to CurseForge and Modrinth
TypeScript
1
star
43

spark-infopoints

spark info points are extra snippets of information about well-known/notable call frames
JavaScript
1
star