Annotation/Reflection Based Command API that just does what you want it to do without any problems.
- Maven
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository
<dependency>
<groupId>com.github.therealdamt</groupId>
<artifactId>commandapi</artifactId>
<version>1.4.0</version>
</dependency>
- Gradle
repositories {
...
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.therealdamt:commandapi:1.4.0'
}
- Example main class
public class Main extends JavaPlugin {
@Override
public void onEnable() { // You also have the default tab completer, and the default help service, new DefaultTabCompleter();
new CommandHandler(this).bind(ItemStack.class, new ItemStackProvider())
.register(new FlyCommand(), new ItemStackCommand()).helpService(new HelpService())
.tabComplete(new TabCompleter()).registerCommands();
}
}
- Example command class
public class ItemStackCommand {
@Command(value = "kekw", async = true, usage = "/kekw itemStack", description = "Just makes an itemstack lol")
@Permission(permission = "kekw.kekew", message = "no perm noob")
public void itemStackCommand(@Sender Player player, @Name("itemStack") ItemStack itemStack) {
player.getInventory().addItem(itemStack);
player.sendMessage(ChatColor.GREEN + "Gave ya your itemstack!");
}
}
- Example provider
public class ItemStackProvider implements CommandProvider<ItemStack> {
@Override
public ItemStack provide(String s) throws CommandProviderNullException {
Material material = Material.getMaterial(s.toUpperCase());
if (material == null)
throw new CommandProviderNullException(ChatColor.RED + "It seems like you did not provide a valid material.");
return new ItemStack(material);
}
}
- Example Help Service
public class HelpService implements HelpCommandService {
@Override
public List<String> get(Command command, List<Command> subCommands) {
return subCommands
.stream()
.map(command1 -> command.getUsage() + ", ")
.collect(Collectors.toList());
}
}
- Example Tab Completer
public class TabCompleter implements TabComplete {
@Override
public List<String> get(Command command, List<Command> subCommands, String[] args) {
return subCommands
.stream()
.map(subCommand -> subCommand.getName() + "\n")
.collect(Collectors.toList());
}
}
You have full rights to use this command api within your projects, but if possible to include credits that'd be amazing!
Discord: bingbongwaseem