Skip to content

Real-MTR/CommandAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CommandAPI


Credits: @Zowpy

A light-weight yet powerful CommandAPI created by Zowpy and maintained by MTR

Simple Commands Example

public class BroadcastCommand {

    @Command(name = "broadcast")
    public void broadcast(@Sender ConsoleCommandSender sender, @Combined String text) {
        Bukkit.broadcastMessage(text);
    }
}

Commands & Subcommands Example

public class NiceCommand {
    
    @Command(name = "nice")
    public void idk(@Sender CommandSender sender) {
        sender.sendMessage("NICE");
    }

    @Command(name = "nice damn")
    public void idk2(@Sender CommandSender sender) {
        sender.sendMessage("NICE damnnnnn");
    }
}

Registeration

public class BroadcastPlugin extends JavaPlugin {

    @Override
    public void onEnable() {
        CommandAPI commandAPI = new CommandAPI();
        commandAPI.beginCommandRegister()
                .register(new BroadcastCommand())
                .endRegister();
    }
}

Providers

Every argument/parameter needs its own provider

There are built-in providers which are all the primitive types and the bukkit player

You can create your own provider

Creating a Provider

public class UUIDProvider implements Provider<UUID> {
    
    @Override
    public UUID provide(String s) throws CommandExitException {
        try {
            return UUID.fromString(s);
        } catch (Exception e) {
            throw new CommandExitException(ChatColor.RED + "Not a valid uuid");
        }
    }
}

The paramater in the provide method is the argument given

The message given in the CommandExitException's constructor is sent to the command sender when the exception is thrown

How to get the dependency?

  • Maven
<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>com.github.Real-MTR</groupId>
        <artifactId>CommandAPI</artifactId>
        <version>VERSION</version>
    </dependency>
</dependencies>
  • Gradle
repositories {
    mavenCentral()
    
    maven { 
        url 'https://jitpack.io'
    }
}

dependencies {
    implementation 'com.github.Real-MTR:CommandAPI:VERSION'
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages