Skip to content
This repository has been archived by the owner on Oct 29, 2023. It is now read-only.

Creating your first plugin

Alexander edited this page Jun 26, 2017 · 9 revisions

Make sure you have checked out the Setting up your workspace article before making a plugin.

Setting up the project

  1. Before setting up the project to be directed at plugin making, create a Gradle project. If you don't know how to do that, please check out the Creating a Gradle project article.

  2. Open the build.gradle file in the project's root directory.

  3. Change whatever version identifier is located after sourceCompatibility to 1.8.

  4. Add maven { url "https://jitpack.io" } to the bottom of the repositories block. This allows us to use GitHub repositories as dependencies.

  5. Add compile 'com.github.Wingman:wingman:VERSION' to the top of the dependencies block, where VERSION is to be replaced by the latest Wingman release version found here. You can also opt-in to use com.github.Wingman:wingman:-SNAPSHOT if you want your plugin to always use the latest API.

Creating the plugin

  1. Navigate to the Gradle directory src\main\java, and create a new package called com.<your GitHub name>.myplugin, then create a class named MyPlugin inside that package.

  2. Annotate it with the Plugin class, like so:

@Plugin(
        id = "MyPlugin",
        name = "My Plugin",
        version = "1.0.0",
        description = ""
)
public class MyPlugin {
}
  1. For this tutorial, set the id value to "MyPlugin", the name value to "My Plugin", the version value to "1.0.0" and leave the description empty. Keep in mind however that the client dislikes having multiple plugins loaded with the same ID, so make sure to release your plugin with a unique ID. This can be done by adding a random string of characters to the end of the ID.

  2. Create a new public void method named anything, preferably activate, and annotate it with Plugin.Activate.

@Plugin(
        id = "MyPlugin",
        name = "My Plugin",
        version = "1.0.0",
        description = ""
)
public class MyPlugin {

    @Plugin.Activate
    public void activate() {
        System.out.println("Hi there!");
    }
}

Running/debugging the plugin

Using IntelliJ IDEA:

  1. Open the Run/Debug Configurations screen.

  1. Add a new Application configuration.

  1. Set the Wingman Main class as the entry point (press the button next to the Main class input box, press Project at the top and navigate to the class).

  1. Set the configuration module to MyPlugin_main.

  1. Run or debug the project.

  1. Wingman should launch and after a while activate your new plugin.

INFO MyPlugin - Hi there! should appear in the console box.

Archiving the plugin

Using IntelliJ IDEA:

  1. Press the Gradle button on the right-hand side of the IDE interface.

  2. Open Tasks, build, and double-click the build task.

  1. Your plugin is now archived in a .jar file. By default it'll be named MyPlugin-1.0-SNAPSHOT.jar and be located in build\libs. You can now distribute that plugin archive to a mate if you want, telling them to install it by following the instructions here.

Using the console:

  1. Open a console window, Command Prompt or cmd.exe on Windows.

  2. Navigate to your plugin's root directory using the cd command.

  3. Type gradlew build to use Gradle to build the project.

  4. Your plugin is now archived in a .jar file. By default it'll be named MyPlugin-1.0-SNAPSHOT.jar and be located in build\libs. You can now distribute that plugin archive to a mate if you want, telling them to install it by following the instructions here.

Outro

You've created your first plugin!

You can now continue by checking out other plugin related wiki articles and tutorials.