Skip to content
Ben Davies edited this page Mar 20, 2020 · 3 revisions

Plugins

So what are plugins?

  • They extend server functionality
  • Add Commands
  • Much more.

Getting Started

Requirements

  • Java IDE (IntelliJ, Eclipse, Netbeans)
  • Gradle 6 or higher
  • Some Java knowledge

Intellij

Create your project

Create a Empty gradle project in intellij image

Set your artifactId and groupId image

Click finish

Setup your build.gradle

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.

Create your TestApplication class

image

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

Create Your Plugin Class

image

Command Decorator

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"
}

Command Middleware

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

Example

Please see CorePlugin for a working example

Testing

Please run

./gradlew runBabblebot

or run from gradle window in IntelliJ