Skip to content

Latest commit

History

56 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

BotModuleAPI

SpongyBot's public module API

Build Status

Maven

Repository:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
...
</repositories>

Dependency:

<dependencies>
<dependency>
<groupId>com.github.Sponges</groupId>
<artifactId>BotModuleAPI</artifactId>
<version>x</version>
</dependency>
...
</dependencies>

The version x should be replaced with the latest built commit. You can find these on the project commits page (https://github.com/SpongyBot/ModuleAPI/commits/master) or on JitPack (https://jitpack.io/#Sponges/BotModuleAPI).

Example: <version>41bae81a4d</version>

Usage

Simple module:

publicclassEssentialsextendsModule { // the main class should extend ModulepublicEssentials() {
super("Essentials", "1.0-SNAPSHOT"); // module name & version
}
@OverridepublicvoidonEnable() {
// in here goes all the code that should run when the module is enabled
}
@OverridepublicvoidonDisable() {
/// in here is the code that should run when the module is disabled
}
}

Command:

publicclassMyCommandextendsCommand {
publicMyCommand() {
super("my command description", "mycommand", "mc", "mycmd");
// description of the command, command name, command aliases
}
@OverridepublicvoidonCommand(CommandRequestcommandRequest, String[] strings) {
commandRequest.reply("Hi, this is a reply to your command!");
}
}

Registering the command:

@OverridepublicvoidonEnable() {
CommandManagermanager = getCommandManager();
MyCommandmyCommand = newMyCommand();
manager.register(myCommand);
}

Events:

Listening to an event:

EventManagermanager = getEventManager();
manager.register(SomeEvent.class, event -> {
// your code goes here 
});

Creating your own event:

publicclassMyEventextendsEvent {
publicMyEvent() {
super(true); // true if the event is cancellable
}
}

Firing an event:

Eventevent = newMyEvent(); // dummy event for demonstrationEventManagermanager = getEventManager();
manager.post(event); // fires the event on the same thread (in sync)manager.postAsync(event); // fires the event on a new thread (async) - REQUIRED FOR EVENT CANCELLING

Documentation

Will add javadocs at some point.

Ensure all modules are safe for a multi-threaded environment.

License

Module API code is licensed under the MIT license. Full text included in the LICENSE file.

About

GenieBot's public module API

Resources

Stars

3 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages