This is a small guide on developing a Spigot plugin. There are other guides online, however some of these guides are outdated and do not clearly direct you on how to setup your environment properly (for example, how you add the API to your project has now changed).
This guide is updated as of 19/06/2024.
- Install Java
- Install and Compile Build Tools
- Setup Server
- Integrated Development Environment
- Develop a Plugin
You need the Java Development Kit (JDK) which includes the Java Runtime Environment (JRE) to develop Spigot plugins using Java.
The version that Spigot supports as of 18/06/2024 is Java version 21/22 which can be downloaded from https://adoptium.net/temurin/releases/. Select the options that apply to you and select JDK as the Package Type and it will give you a download to install.
SpigotMC has developed a tool to make it easy to compile your Spigot builds called BuildTools. This tool will download the required source files, patch it and compile it for you. You can download the Spigot Build Tools from https://hub.spigotmc.org/jenkins/job/BuildTools/.
Note: You may need to install the Git
tool to use the Build Tools, you can download it from https://www.git-scm.com/downloads.
When you open the tool you must select the version of the server you want to target and a location to store all of the build artifacts (jar files) before selecting Compile
. This process may take a while so be patient.
We are going to need a server to test the plugins on.
- Create a folder for your Minecraft server.
- Copy the
spigot.jar
from the build tools directory into your server folder. - Create a batch file called
start.bat
which will be used for starting the server with the following content:
@echo off
java -Xms2G -Xmx4G -XX:+UseG1GC -jar spigot.jar nogui
pause
Replace -Xms2G
(minimum heap size) and Xmx4G
(maximum heap size) with the memory size (RAM) that you would prefer.
4. Run the start.bat
file to setup the initial server files.
5. Agree to the eula.txt
file which has been generated by opening it and replacing the value false
with true
.
6. Start the server again by running start.bat
.
7. You should now have a running Spigot server.
You need an Integrated Development Environment (IDE) to develop the plugins in, you can use powerful editors like Visual Studio Code (VSCode), however using an IDE build specifically for Java will give you a much better experience.
My recommendation is to use IntelliJ IDEA which is created by JetBrains who have tons of experience developing language specific IDE's like PyCharm (Python IDE) and Rider (C#/.NET IDE).
You can download IntelliJ IDEA from https://www.jetbrains.com/idea/download/. Make sure you download the Community Edition of IntelliJ and not the Ultimate edition as it is the commercial version of the software which runs under a trial period. The community edition is the free and open source version of IntelliJ IDEA.
After you have installed the IDE you need to create a new project.
- Create a project by clicking the
New Project
button. - Give the project a name (this is your plugin name).
- Select the JDK you want to target (in this case, the JDK you downloaded and installed earlier).
- Leave the rest of the settings as default and click the
Create
button - Right click your project and select
Open Module Settings
. - Select the
Libraries
tab. - Click the
+
icon to open the file browser. - Navigate to your server directory you setup earlier.
- Select the
./bundler/libraries/spigot-api-version.jar
file and clickOk
. - You are now ready to develop a Spigot plugin.
- Right click the
src
directory and create a package matching the naming schemetld.domain.subdomain
. This name should be unique, an example of following this scheme iscom.anchydev.testplugin
. This is where all your code for your plugin will live. - Move the
Main
class file that was automatically generated into this directory. - Click the
Main
class file to edit it and implement the following code:
package com.anchydev.TestPlugin;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
@Override
public void onEnable() {
Bukkit.getLogger().info("Hello from " + this.getName() + "!");
}
}
- Create a
plugin.yml
in thesrc
directory with the following contents:
name: NameOfYourPlugin
version: 1.0
author: YourName
main: com.anchydev.TestPlugin.Main
api-version: 1.20.4
Before you build an artifact you must setup your artifact profile first:
- Right click your project and select
Open Module Settings
. - Select the
Artifacts
tab. - Click the
+
icon to add a new artifact type. - Select
JAR
>From modules with dependencies
. - Leave everything blank and press
OK
. - In the right panel click the
+
icon for adding a copy of a file. - Select
File
and add theplugin.yml
file you created in thesrc
directory earlier. - Set a build output path where your
jar
file will be compiled to. - Close the project settings.
You are now ready to build an artifact (jar) of your plugin.
- Open the
Build
menu at the top of the screen (it may be in the hamburger menu) and clickBuild Artifacts
. - Copy the
jar
file from the output you chose earlier into your serversplugins
directory.
Now that you have compiled and built an artifact of your plugin, you need to test it.
- Restart the Spigot server.
- Wait for the server to start-up.
- Observe the "Hello from PluginName!" message in the server console.
You have successfully created your first plugin! To develop it further you only need follow the 2nd Part of the Build Artifact section of this guide.