Provides reusable and maintainable Spigot components. Stable releases can be found below, hosted on Maven Central.
BCommons is hosted on maven's central repository, below are examples of how to include BCommons into your project:
<dependency>
<groupId>me.bradleysteele</groupId>
<artifactId>commons</artifactId>
<version>VERSION</version>
</dependency>implementation 'me.bradleysteele:commons:VERSION'
The JavaPlugin is extended by the BPlugin
class and handles pre and post processing of loading, enabling and disabling. An example of how to use the BPlugin class
can be found below.
publicclassExamplePluginextendsBPlugin {
@Overridepublicvoidenable() {
this.register(
WorkerExample.class, CmdExample.class
);
}
}All Registrable classes must be enabled through BPlugin#register. Singletons must have a static get() or getInstance() method returning an instance of the class being registered, otherwise a new instance will be created and registered. Some examples of built-in registrables can be found below.
The BCommand
registrable provides simple methods for easily creating command executors. It is important to note when using the BCommand class, you do not
have to register commands in your plugin.yml.
publicclassCmdExampleextendsBCommand {
publicCmdExample() {
// Note: the "main" command executor must be in this list too.this.setAliases("example", "exmpl", "test", "tst");
// The information when shown when typing '/minecraft:help /example'.this.setDescription("Some information about the command.");
// Default: false, allows the command to be ran by the console.this.setAllowConsole(true);
this.setPermission("example.permission.node");
this.setPermissionDenyMessage("&cYou do not have permission.");
}
// The method executed when the command is ran. Note that this is not fired // if cancelled by the PlayerCommandPreprocessEvent.@Overridepublicvoidexecute(CommandSendersender, String[] args) {
sender.sendMessage("Hello!");
}
}The BWorker registrable should be used for event handling and running repeating tasks.
publicclassWorkerExampleextendsBWorker {
privatebooleancanFly;
publicWorkerExample() {
// Initial delaythis.setDelay(20);
// Every second (20 ticks)this.setPeriod(20);
// Asynchronousthis.setSync(false); }
@Overridepublicvoidrun() {
canFly = ThreadLocalRandom.current().nextBoolean();
}
@EventHandlerpublicvoidonToggleFlight(PlayerToggleFlightEventevent) {
event.setCancelled(event.isFlying() && !canFly);
}
}