A cross-platform wrapper library for making Brigadier commands
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Go to file
William 1817d12b5f
fix: fix fabric mixins
5 months ago
.github feat: make x-plat command registering possible 5 months ago
bukkit deps: bump space.arim.morepaperlib:morepaperlib from 0.4.3 to 0.4.4 (#4) 5 months ago
common feat: fixup paper custom argument types 5 months ago
example-plugin feat: add argument example to testbase 5 months ago
fabric-1.20.1 fix: fix fabric mixins 5 months ago
fabric-1.20.6 fix: fix fabric mixins 5 months ago
gradle/wrapper refactor: redo layout, registration structure 6 months ago
images build: add CI, README, banner, metadata 6 months ago
paper feat: register namespace-backed aliases on legacy paper 5 months ago
velocity refactor: fixup custom argument support on Fabric 5 months ago
.gitignore refactor: redo layout, registration structure 6 months ago
HEADER refactor: redo layout, registration structure 6 months ago
LICENSE Initial commit 7 months ago
README.md feat: add way of supplying custom commanduser impls 5 months ago
build.gradle fix: version/description on Fabric mods 5 months ago
gradle.properties fix: fix fabric mixins 5 months ago
gradlew fix: make gradlew executable 5 months ago
gradlew.bat refactor: redo layout, registration structure 6 months ago
settings.gradle feat: bukkit support, x-plat sub-commands 5 months ago

README.md

Claim Operations Library


Uniform is cross-platform wrapper for making Brigadier commands, based on BrigadierWrapper by Tofaa2, which itself was inspired by EmortalMC's command-system.

Uniform currently targets the following platforms:

Platform Artifact Minecraft Java
Common uniform-common - >17
Bukkit uniform-bukkit >1.17.1 >17
Paper uniform-paper >1.17.1 >21
Velocity uniform-velocity >3.3.0 >17
Fabric 1.20.1 uniform-fabric =1.20.1 >17
Fabric 1.20.6 uniform-fabric =1.20.6 >21

  • Fabric: Please note Uniform on Fabric requires adventure-platform-fabric and the Fabric API as dependencies. To target Fabric, use uniform-fabric as the artifact and <uniform_version>+<minecraft_version> as the version (e.g. net.william278.uniform:uniform-fabric:1.0+1.20.1).
  • Sponge: Support for Sponge 8 is also planned in a future version.

Setup

Uniform is available on Maven. You can browse the Javadocs here.

Gradle setup instructions

First, add the Maven repository to your build.gradle file:

repositories {
    maven { url "https://repo.william278.net/releases" }
}

Then, add the dependency itself. Replace VERSION with the latest release version. (e.g., 1.0) and PLATFORM with the platform you are targeting (e.g., paper). If you want to target pre-release "snapshot" versions (not recommended), you should use the /snapshots repository instead.

dependencies {
    implementation "net.william278.uniform:uniform-PLATFORM:VERSION"
}

Using Maven/something else? There's instructions on how to include Uniform on the repo browser.

Basic use

Uniform lets you create commands either natively per-platform, or cross-platform (by compiling against uniform-common in a common module, then implementing uniform-PLATFORM in each platform, getting the platform specific Uniform manager instance and registering your commands).

Check example-plugin for a full example of a cross-platform command being registered on Paper.

Platform-specific commands

Extend the platform-specific PlatformCommand class and add your Brigadier syntax.

public class ExampleCommand extends PaperCommand {
    public ExampleCommand() {
        super("example", "platform-specific");
        command.setDefaultExecutor((context) -> {
            context.getSource().getBukkitSender().sendMessage("Hello, world!");
        });
        addSyntax((context) -> {
            context.getSource().getBukkitSender().sendMessage("Woah!!!!");
            String arg = context.getArgument("message", String.class);
            context.getSource().getBukkitSender()
                .sendMessage(MiniMessage.miniMessage().deserialize(arg));
        }, stringArg("message"));
    }
}

Cross-platform commands

Target uniform-common and extend the Command class. You'll want to use BaseCommand#getUser to get a platform-agnostic User from which you can acquire the adventure Audience to send messages to.

public class ExampleCrossPlatCommand extends Command {
    public ExampleCrossPlatCommand() {
        super("example", "cross-platform");
    }

    @Override
    public <S> void provide(@NotNull BaseCommand<S> command) {
        // What gets executed when no args are passed. 
        // For tidiness, feel free to delegate this stuff to methods!
        command.setDefaultExecutor((context) -> {
            // Use command.getUser(context.getSource()) to get the user
            final Audience user = command.getUser(context.getSource()).getAudience();
            user.sendMessage(Component.text("Hello, world!"));
        });

        // Add syntax to the command
        command.addSyntax((context) -> {
            final Audience user = command.getUser(ctx.getSource()).getAudience();
            user.sendMessage(Component.text("Woah!!!!"));
            String arg = context.getArgument("message", String.class);
            user.sendMessage(MiniMessage.miniMessage().deserialize(arg));
        }, stringArg("message"));

        // Sub-commands, too
        command.addSubCommand("subcommand", (sub) -> {
            sub.setDefaultExecutor((context) -> {
                final Audience user = sub.getUser(context.getSource()).getAudience();
                user.sendMessage(Component.text("Subcommand executed!"));
            });
        });
    }
}

Registering

Then, register the command with the platform-specific Uniform instance (e.g. FabricUniform.getInstance(), PaperUniform.getInstance(), etc...)

Building

To build Uniform, run clean build in the root directory. The output JARs will be in target/.

License

Uniform is licensed under GPL v3 as it derives from BrigadierWrapper. See LICENSE for more information.