ModernBukkit icon

ModernBukkit -----

A modern API to code spigot plugins.



This documentation is not well formated for a better version visit https://github.com/Keksnet/ModernBukkit/blob/master/README.md

[h1]ModernBukkit[/h1]
An annotation based plugin framework for bukkit.

Why should I use ModernBukkit?

ModernBukkit helps you to achieve your goals with less code
and makes your code cleaner and easier to understand.
Furthermore it is actively developed and supported.


Code comparison

Commands

Code without using ModernBukkit

Code (Text):
public class HelloWorldCommand implements CommandExecutor {

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if(args.length >= 1) {
            if(args[0].equals("arg1")) {
                if(sender.hasPermission("system.test.arg1")) {
                    sender.sendMessage("Hello, " + sender.getName());
                }else {
                    sender.sendMessage("§cYou do not have the permission system.test.arg1");
                }
                return false;
            }
        }
        if(sender.hasPermission("system.test")) {
            sender.sendMessage("Hello, World!");
        }else {
            sender.sendMessage("§cYou do not have the permission system.test");
        }
        return false;
    }
}

Code using ModernBukkit

With this code we are getting tabcompletion too.
Code (Text):
import de.neo.modernbukkit.command.Command;
import de.neo.modernbukkit.command.Subcommand;
import de.neo.modernbukkit.command.TabCompletion;
import org.bukkit.command.CommandSender;

public class TestCommand {

    @Command(command = "test", permission = "system.test")
    @TabCompletion(format = "$subCommand $players dummy")
    public void test(CommandSender sender, String[] args) {
        sender.sendMessage("Hello, world!");
    }

    @Subcommand(rootCommand = "test", subCommand = "arg1", permission = "system.test.arg1", position = 1)
    public void testArg1(CommandSender sender, String[] args) {
        sender.sendMessage("Hello, " + sender.getName());
    }

}

Getting started

You have to set ModernBukkit as a dependency in maven or gradle.

Example for Maven

Repository:
Code (Text):
<repository>
    <id>keinsurvival-repo</id>
    <url>https://repo.nononitas.eu/ui/native/keinsurvival-public</url>
</repository>
Dependency:
Code (Text):
<dependency>
    <groupId>de.neo</groupId>
    <artifactId>ModernBukkit</artifactId>
    <version>VERSION</version>
    <scope>provided</scope>
</dependency>

Example for Gradle (groovy)

Repository:
Code (Text):
maven {
    name 'keinsurvival-repo'
    url 'https://repo.nononitas.eu/artifactory/keinsurvival-public'
}
Dependency:
Code (Text):
compileOnly 'de.neo:ModernBukkit:VERSION'

Example for Gradle (kotlin)

Repository:
Code (Text):
maven("https://repo.nononitas.eu/artifactory/keinsurvival-public")
Dependency:
Code (Text):
compileOnly("de.neo:ModernBukkit:VERSION")

Using ModernBukkit

To use the benefits of ModernBukkit you have to extend
`[code single]ModernJavaPlugin[/code][code single] instead of [/code][code single]JavaPlugin[/code]`. You
also have to override `[code single]onStart()[/code][code single] instead of [/code][code single]onEnable()[/code]`.
When you override `[code single]onEnable()[/code]` your plugin may not work.

Code (Text):
public class TestMain extends ModernJavaPlugin {
    @Override
    public void onStart() {
        // Your code goes here...
    }
}

Commands with ModernBukkit

Registering commands

If you want to register commands using ModernBukkit you have to create a command class.
To do so you only need to create a new class. In this class you can create a method
with one of the following signatures.

Code (Text):
public class TestCommand {
    public void sig1(CommandSender sender, String[] args) {} // short signature

    public void sig2(CommandSender sender, Command cmd, String label, String[] args) {} // long signature
}
Now you need to mark the method as a command. You can do this by simply use the
`[code single]@Command[/code][code single] annotation. The [/code][code single]@Command[/code]` annotation needs a few parameters so that
it can set the command up.

`[code single]@Command(String command, String permission, String[] aliases)[/code]`
- command - the name of the command.
- permission - the permission required to execute the command.
- aliases - all aliases that this command should have.

The method is executed when the command was executed.

The following code registers the command `[code single]/test[/code]` and you need the permission
`[code single]system.test[/code]` to use the command.

Code (Text):
public class TestCommand {
    @Command(command = "test", permission = "system.test")
    public void test(CommandSender sender, String[] args) {
        sender.sendMessage("Hello, world!");
    }
}

Registering subcommands

You can also register subcommands using ModernBukkit. You need the same setup as
for a normal command. You just need to use the `[code single]@Subcommand[/code]` annotation instead of
the `[code single]@Command[/code][code single] annotations. The [/code][code single]@Subcommand[/code]` annotation has the following
parameters.

`[code single]@Subcommand(String rootCommand, String subCommand, String permission, int position)[/code]`
- rootCommand - the name of the parentcommand.
- subCommand - the name of the subcommand.
- permission - the permission required to execute the command.
- position - the position of the subcommand. Not implemented yet. Default: 1

The following code registers the subcommand `[code single]/test arg1[/code]` and you need the permission
`[code single]system.test.arg1[/code]` to use the command.

Code (Text):
public class TestCommand {
    @Command(command = "test", permission = "system.test")
    public void test(CommandSender sender, String[] args) {
        sender.sendMessage("Hello, world!");
    }

    @Subcommand(rootCommand = "test", subCommand = "arg1", permission = "system.test.arg1", position = 1)
    public void testArg1(CommandSender sender, String[] args) {
        sender.sendMessage("Hello, " + sender.getName());
    }

}

Using ``[code single]@TabCompletion[/code]``

The default tab completion is not always good enough. When you want to improve the
tab completion. You only need to put the `[code single]@TabCompletion[/code]` annotation on the command
method. The `[code single]@TabCompletion[/code]` annotation takes the format as the only parameter.

The format works as follows. You provide one string. The string has a value for each
argument index separated by spaces. The following values are possible:

| Placeholder | Description |
|------------------|----------------------------------------------------------------|
| $players | Adds a list of all players to the tab complete. |

All placeholders that are invalid are visible as plain text.

Code (Text):
public class TestCommand {

    @Command(command = "test", permission = "system.test")
    @TabCompletion(format = "$subCommand $players dummy")
    public void test(CommandSender sender, String[] args) {
        sender.sendMessage("Hello, world!");
    }

    @Subcommand(rootCommand = "test", subCommand = "arg1", permission = "system.test.arg1", position = 1)
    public void testArg1(CommandSender sender, String[] args) {
        sender.sendMessage("Hello, " + sender.getName());
    }

}

Custom TabCompleter

If the tab completer provided by ModernBukkit is not good enough you can register
your own tab completer using the `[code single]@TabCompleter[/code]` annotation.

`[code single]@TabCompleter(command)[/code]`
- command - the name of the command this tab completer is for.

Code (Text):
public class TestCommand {

    @Command(command = "test", permission = "system.test")
    @TabCompletion(format = "$subCommand $players dummy")
    public void test(CommandSender sender, String[] args) {
        sender.sendMessage("Hello, world!");
    }

    @Subcommand(rootCommand = "test", subCommand = "arg1", permission = "system.test.arg1", position = 1)
    public void testArg1(CommandSender sender, String[] args) {
        sender.sendMessage("Hello, " + sender.getName());
    }

    @TabCompleter(command = "test")
    public List<String> completeTest(CommandSender sender, String[] args) {
        ArrayList<String> completions = new ArrayList<>();
        if(args.length == 1) {
        completions.add("arg1");
        }
        return completions;
    }

}
That are the basics for ModernBukkit. I hope you have fun.

Support

You can get support on the following platforms.

Discord (german)

SpigotMC
Resource Information
Author:
----------
Total Downloads: 36
First Release: Oct 19, 2021
Last Update: Oct 19, 2021
Category: ---------------
All-Time Rating:
0 ratings
Find more info at github.com...
Version -----
Released: --------------------
Downloads: ------
Version Rating:
----------------------
-- ratings