Create Your First Plugin¶
Welcome to Allay! Allay provides a powerful plugin system so that you can write plugin in many languages, such as Java, JavaScript, Scala and Kotlin. In this section, we will guide you to create your first plugin in Java.
Prerequisites¶
To develop your first plugin, you will have to install the following prerequisites:
Creating a New Project¶
We have plugin template that you can use to create your project quickly:
And because you are going to write your plugin in java, we choose the JavaPluginTemplate
to create a new project:
- Click on the green
Use this template
button and chooseCreate a new repository
on the repository page. - Enter the repository name and description. The name should be in camel-case, in this case, we will use
MyPlugin
as the name. - Click on the green
Create repository
button.
Wait a moment for the repository to be created, and you will be redirected to the repo page of your new project. Then we can clone the repository to our local machine.
Edit the Project Information¶
After cloning the repository, open the project in IDEA, and we need to change some information:
- Rename package name from
org.allaymc.javaplugintemplate
toyour.group.name.myplugin
. - Rename
src/main/java/your/group/name/myplugin/JavaPluginTemplate.java
tosrc/main/java/your/group/name/myplugin/MyPlugin.java
, there are also some places that you need to change inside the class. Please make sure that this class (the main class) has a default constructor. - Find
build.gradle.kts
file, changegroup
toyour.group.myplugin
, also don't forget to changedescription
. - Find
settings.gradle.kts
file, changerootProject.name
toMyPlugin
. - Find
src/main/resources/plugin.json
file: - Change
entrance
toyour.group.name.myplugin.MyPlugin
. - Change
name
toMyPlugin
. - Change
authors
to["yourname"]
- Reload gradle
Build and Install Your Plugin¶
To build your plugin into a jar file, you need to run the following command:
And this command will produce a file named MyPlugin-1.0.0-shaded.jar
in the build/libs
directory.
Copying this file to the plugins
directory of your Allay server, and start the server
to check if your plugin loads and operates as expected.