How to make a spigot plugin!

Installing Prerequisites 

How to install Java


When we create a plugin we need the Java SE JDK. This is the development kit for Java. You can find the download here, make sure you install the correct version for your operating system.

How to install Eclipse


Eclipse is a Java IDE, we will be using eclipse to develop and build our plugins. You can find the download here

Once you have downloaded eclipse, 
how to install eclipse

select the first option, Eclipse IDE for Java Developers, to install our needed IDE.

How to download the Spigot Development Package (Build Tools)


We will also need the spigot package to be able to develop a plugin.

We will download the latest successful build, here. Put this file inside a folder somewhere accessible, I will put this on my desktop.

  1. Open the terminal by searching CMD inside the windows menu.
  2. Inside the terminal using cd, navigate to the folder you put the BuildTools.jar file in.
    • cd ~YOUR PATH~
  3. Run the command `java -jar BuildTools.jar`
  4. This will probably open an installer for GIT, just be patient it might take awhile.

Lets create the actual plugin!

Open up eclipse. This will ask for a workspace folder, I recommend using the default folder.

Creating the project

  1. Press File - New - Java Project
  2. In the Project Name, type in the name of your project, I will just be using Test Plugin.
  3. Keep everything else the same and click next.
  4. Click the Libraries tab, and then Add External JARs
  5. Navigate to where you saved the BuildTools.jar file, then navigate to Spigot/Spigot-API/target
  6. Select the file called Spigot-api-%VERSION%-R0.1-SNAPSHOT-shaded.jar
  7. Toggle the dropdown next to the file you just imported
  8. In the Javadoc location type https://hub.spigotmc.org/javadocs/spigot/
  9. Click Finish

Creating a Package

  1. Press File - New - Package
  2. In the source folder, select Browse, then navigate to the project you just created, then src.
  3. Type in the name of your package. Packages are usually structured like com.name.plugin. But this is usually done when you have a website at name.com. I will just use me.Noordo.testplugin.
  4. Click Finish

Creating the main class

  1. Press File - New - Class
  2. In the name, type in Main
  3. Click on Browse next to the Superclass, and search for JavaPlugin. Select the one from org.bukkit.plugin.java.
  4. Click Finish

Lets get coding!

We will first add two classes for when the plugin is loaded, and when it is unloaded, and we will use the getServer().getConsoleSender() to reference our console. We can then use this to send a message to the console when the plugin is loaded, we can also use ChatColor.RED to make the text Red! 
package me.noordo.testplugin;  
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.java.JavaPlugin;

import net.md_5.bungee.api.ChatColor;  

public class Main extends JavaPlugin {
	
      @Override
      public void onEnable() {
      	ConsoleCommandSender console = getServer().getConsoleSender();
		console.sendMessage(ChatColor.RED + "Plugin works!");
      }
      
      @Override  
      public void onDisable() {
      
      }  
}  

Creating the plugin.yml

We need a plugin.yml to tell the server about our plugin. This includes what commands we have, who the author is. what the name is and what the description is.
  1. Press File - New - File
  2. Select the src folder
  3. In the name type in plugin.yml
  4. This should open an external file editor, but if you wish to use eclipse double click on the plugin.yml and select OK. This should open the marketplace where you can download Yaml Editor.
  5. Type in the following, replace me.noordo.testplugin to what you called your package earlier, you can replace everything else to suit your needs.
 main: me.noordo.testplugin.Main  
 name: TestPlugin  
 version: 1.0  
 author: Noordo  
 description: A Test Plugin
We will put commands in here in a later tutorial.

Building the plugin!

  1. Right click on the project we created earlier, mine is called Test Plugin.
  2. Select Export
  3. Dropdown Java
  4. Select Jar File and click Next
  5. Make sure your plugin is selected
  6. Click Browse and navigate to where you want to save the file, and type the name as well
  7. Select Finish

Woohoo, we finished! You can now drop this plugin into your own server. If you start the server you should be able to see 'Plugin Works!' in the console

Comments

Popular posts from this blog

RTX 2080 Benchmarks