Sueta

CommandsAPI

2.0.1

Create Commands Easily With Annotations and Without plugin.yml

·Plugin

CommandsAPI

First of all, what the **** is it? Well, let me me answer that, would ya?
CommandsAPI is a way to easily register commands without the need of a plugin.yml or anything weird as that! We Use annotations. Seems complicated. I know. believe me it's not.

Example:
upload_2017-4-29_22-20-26.png
if you want to learn how to use this API, continue reading this thread.

First of all, quick tutorial about using annotations

What is annotations? annotations are a way to give more information about a method, a class, a constructor and more. How? very simple.
Simply put a @AnnotationName before your desired object.
In our case, The annotation is @command, and the target ( desired object is a method ). You can also give additional information about that object inside the annotation, As the following:
upload_2017-4-29_22-20-40.png

Downloading And Installing The API

Download the API jar from this resource, or from the main github repo.

Or use Maven

How to install the API in eclipse and intellij idea:

Spoiler

If you are on Eclipse add the API to the build path, and make sure it's getting exported with it

If you are on intellij Idea, Add it as a dependency in the project structure, then export it in the artifact.

Registering the class

First step, and believe me this is the hardest one ( :p ), You need to register the class. You need to repeat the following to each class you use this API.

Implement CommandListener on the class. ( as the following )
upload_2017-4-29_22-22-4.png

Then Register that Class in your onEnable method ( or any code that runs )
If your desired class is your main class you can write this:
upload_2017-4-29_22-21-22.png
Any other class:
upload_2017-4-29_22-21-54.png

@CommandClass

@CommandClass is an annotation, that annotation targets Classes, not methods.

@CommandClass would be written before the class starts:
upload_2017-4-29_23-36-30.png

The @CommandClass contains some default values.

Name

The command name can be imported from multiple things.
Command name -> CommandClass name -> Method name

if there is a name in the @command annotation, that would override everything else.

If there isn't, and there is a default name for the entire class ( aka CommandClass ), then it would use that name.

And finally, if both Command annotation and CommandClass annotation name value is empty, it would use the name of the method.

+ You can use multiple names by spaceing them out. for example, /essentials and /ess would be @Command(name = "essentials ess")

Permission

By changing the permission value in @command annotation ( or @CommandClass annotation for default permission ) You enable permissions for the command.
If the player doesn't meet the permissions, the command won't run and he would get an error.

+ You can use multiple permission by spacing them out. for example, pizza.admin and pasta.admin would be @Command(permission = "pizza.admin pasta.admin")

Arguments

Wow. This is a complicated one. Let's start.

The player command must have the exact same arguments like your @command arguments. With the exception of a wildcard, a wildcard ( symbol = '*' ) would be ignored, meaning the player can enter whatever he wants in the slot. When you use wildcard because all of the other args are static, and never change, The API would only supply you with the wilcarded arguments. Complicated? Let's an example:
upload_2017-4-29_23-28-14.png
If the player enters "pex group Owner user add Erezbiox1"
The API would give the method only "Owner" and "Erezbiox1"
Because all of the other arguments are the same each time.

Parameters

The parameters of the method can be anything you want, in what order you want. ( almost )

It can be only CommandSender, only String[], both in any order or nothing.

Instead of CommandSender you can put Player, then only player would be able to run the command, any not players ( console for example ) will get an error.

Errors

If there is a player requirment and the sender isn't a player, or the sender doesn't have enough permissions, or the sender didn't sent the right arguments, all of those reasons would send the player an error message.
that message is configurable.

if the @command doesn't say a exact error, the API would use the @CommandClass one. If the @CommandClass didn't give one either, the API would use the default error message.

If the message equals to "default", then the message will be the API's default message

If the message equals to "none", then there will be no message.

The possible errors are:
permissionError, argumentsError and playerError.

Side-note

- The build that you see is a untested experimental build. But it does work ( as far as I've tested )
- It's almost 1 AM in my place and I woke up early today, plus I ain't no native english, so forgive any spelling or grammar mistake.
- As some of you know, this API is a part of a bigger unfinished API. BioAPI. I published this build because I know BioAPI ain't coming soon.
- The code is a mess. I know, I didn't had the time to make it better, and I just threw features on it.
- It is open-source.
- Please show your support and star my github repo, would ya?
- Sorry for the thread design :\ if you want to make this better contact me!

Videos and guides

Currently Empty! if you published a video that used this API or explained it, please contact me so I can add you! :)

That's it guys! if you like it, please consider donating? Would ya? ;)

Similar projects

Plugin →