-
Notifications
You must be signed in to change notification settings - Fork 1
Creating A Plugin
Ben Davies edited this page Mar 20, 2020
·
3 revisions
- They extend server functionality
- Add Commands
- Much more.
- Java IDE (IntelliJ, Eclipse, Netbeans)
- Gradle 6 or higher
- Some Java knowledge
Create a Empty gradle project in intellij

Set your artifactId and groupId

Click finish
plugins {
id 'java-library'
}
group 'net.bdavies.test'
version '1.0.0'
repositories {
mavenCentral()
jcenter()
maven {
url "https://dl.bintray.com/bendavies99/Babblebot-Server"
}
}
configurations {
agent {
extendsFrom implementation
canBeResolved true
}
}
dependencies {
implementation 'co.uk.bjdavies:babblebot-server-api:1.2.7'
implementation 'co.uk.bjdavies:babblebot-server-server:1.2.7'
agent 'co.uk.bjdavies:babblebot-server-agent:1.2.7'
implementation 'org.javassist:javassist:3.26.0-GA'
}
task runBabblebot(type: JavaExec) {
dependsOn build
//Your main application class
main = 'net.bdavies.test.TestApp'
classpath = sourceSets.main.runtimeClasspath
jvmArgs '-javaagent:' + project.configurations.agent.find { it.name.startsWith("babblebot-server-agent") }
group 'babblebot'
}
Be sure to sync your dependencies.

This is just boilerplate code for testing your plugin, you do not need to include it in the final JAR.

Basic
/*
Creates a basic command no paramaters or multiple aliases
*/
@Command(description = "Test")
public String test() {
return "String"
}Advanced
/*
Creates an advanced command
*/
@Command(aliases = {"ban", "remove"},
description = "This will ban a user for period of time",
usage = "(ban | remove) -for=time(s,m,h) (e.g. -for=10s)",
requiredParams = { "for" })
public String test() {
return "String"
}This is what gets ran before the command is executed it determines if the command will execute or not.
An example of this is in the core plugin where if the user decides to ignore a channel it will be determined in the middleware if the bot should respond.
@Override
public void onBoot() {
log.info("Booting Core Plugin");
commandDispatcher.registerGlobalMiddleware(context ->
Ignore.where("channelId", context.getMessage().getChannelId().asString()).doesntExist()
|| context.getCommandName().equals("listen"));
}Code taken from CorePlugin.java
Please see CorePlugin for a working example
Please run
./gradlew runBabblebotor run from gradle window in IntelliJ