If you’ve ever watched Dream, a well-known Minecraft YouTuber, you’ve probably noticed that a lot of his videos feature challenges in the game. He and his friends take on these challenges in an effort to win the game in peculiar situations. These might include bizarre occurrences like raids or frequently spawning bee swarms. This is all made possible using Minecraft server plugins.
Setting up your development environment
You need the Java Development Kit, not the Runtime Environment. Download the Java SE JDK from Oracle’s site. Make sure you get the JDK, not the JRE, and make sure you have the correct one for your operating system. Java.com only has JREs, you have to go to Oracle’s site for the JDK. Linux users can try installing the java-8-openjdk
package.
Please be aware that OS X no longer comes with Java by default. However, the version it installs is outdated (Java 6), and Bukkit/Spigot development requires at least Java 7, so you will need to download the more recent Java even if you already have the system Java. It will automatically install if you try to run something that requires Java.
Download and Build Spigot
Even if you never run Spigot, you must link against it in order to compile plugins, so you must have a local copy on your computer.
Download BuildTools.jar from https://hub.spigotmc.org/jenkins/job/BuildTools/
Place it in an otherwise empty directory. Open a terminal window or command prompt and go to the directory where you put the file. Run the following command to build it:
This will probably take a while. Ideally, you’ll receive a file called Spigot-1. 14. 2. jar in the same directory with BuildTools. jar (if Spigot has been updated since I posted this, the version number in the filename may differ) You’ll require it later when creating the project in Eclipse, so keep track of where this directory is.
Plugin development is done with a Java IDE. If you already use a favorite Java IDE, I’m sure you can make it work, but if not, I strongly suggest Eclipse, and my instructions will be built around it.
You can get Eclipse here: http://www.eclipse.org/downloads/
Eclipse is already packaged for the majority of Linux distributions, and you can likely install it using your package manager. Your mileage may vary in getting it to work. Because updating plugins can sometimes break how the packager packaged the main app and because plugins occasionally require a more recent version of Eclipse (Ubuntu ships with an older version), I use a copy of Eclipse that I downloaded from the eclipse website. org rather than the one Ubuntu ships.
Go to Eclipse’s preferences, click the triangle next to “Java,” and look for the “Installed JREs” section if you have more than one version of Java installed (OS X users, this probably applies to you). Ensure that the one you just installed is highlighted and listed there. If not, click Add, choose Directory from the right-hand menu, select the location where you installed the Java JDK, and look for the “jre” directory there. On OS X, Oracle’s installer will install inside /Library/Java/VirtualMachines/. Examples:
Install a YAML editor plugin to Eclipse
The YAML-formatted file you create instructs Spigot how to interact with your plugin. Despite being essentially just a text file, as shipped, Eclipse cannot edit YAML files. There are several plugins that will teach it how, though.
Visit Help – Several plugins are available that can accomplish this; choose one you like and install it.
UPDATE 2019/07/13: YEdit, which I previously recommended here (it was the only one at the time I wrote this), is no longer available on the Eclipse Marketplace. There are currently a number of alternatives, and they should all function.
Creating your first project in Eclipse
- Choose File -> New -> Java Project
- Enter the name of your plugin
- Choose Next (not Finish)
- Click the Libraries tab.
- Click Add External JARs…
- Select the shaded Spigot-API JAR file from the Spigot directory you built earlier. Within the directory with BuildTools. The API file will be located in Spigot/Spigot-API/target and likely have the name spigot-api-1. 14. 2-R0-SNAPSHOT-shaded. jar.
- Toggle the triangle to the left of spigot-api
- Choose Javadoc Location
- Click Edit…
- In Javadoc location path, enter: https://hub. spigotmc. org/javadocs/spigot/ . This will enable Spigot API objects and methods to be automatically completed by Eclipse’s autocomplete.
- Click OK
- Click Finish
- Choose File -> New -> Package
- Enter the name of your package. Typically, this has a reversed domain name structure. It should begin with a personal identification, have the project name at the end in all lowercase letters, and finish with that. Minecraft itself is net. minecraft. server for example, Spigot is org. spigotmc, and the Bukkit plugin API is org. bukkit. plugin. I’ll use tld. example. myplugin in the examples.
- Click Finish
Create the Main class
- Choose File -> New -> Class
- Enter the class name that Spigot will load when it loads the plugin. You can give this any name you like (we’ll talk about instructing Spigot where to find it later), but for the sake of simplicity, I’ll use the term “Main” in the examples.
- Next to Superclass, click Browse…
- Type JavaPlugin into the search bar and select the only result that appears (org bukkit. plugin. java).
- Click OK
- Click Finish
You should now see code that resembles this when it automatically opens in the editor:
You need to implement two of the functions that the API defines. These are onEnable and onDisable, and they are called when your plugin is turned on or off, respectively. They are not required to do anything, but if you need to distribute or dispose of any resources, those are the places to do it. Add those two functions to your Main. java file, so that it looks like this:
Create the plugin.yml file
- Choose File -> New -> File
- Select the top-level folder of your project (the project name)
- for the File name enter
plugin.yml
- Click Finish
It should open in the editor. If it doesn’t, you probably neglected to install YEdit at the beginning of this tutorial.
This file will be in YAML format, and describes to Spigot how to interact with the plugin. The top of the file leads off with some basic information about the plugin, and is then followed by a description of the commands which are made available by the plugin.
The package and class name of the class that Spigot loads when it loads the plugin’s jar file must be listed in the “main:” line. The commands /plugins and /help display the user the human readable terms “version,” “author,” and “description.”
Each command you execute should have a line in the “commands:” block. When users use a command that is not listed here, Spigot won’t send it to you.
The “description” and “usage” sections of each command’s block are displayed to the user when they use the /help command. Which permission allows access to the command is specified in the “permission” line. Users who attempt to use it without authorization will see “permission-message” instead. The name of the plugin should come first, followed by a dot, and then any random permission name. Additionally, you can use a core permission or another plugin’s permission. For instance, you could specify “mw” as a requirement if your plugin adds more features to MultiWorld. admin” permission or so forth. If you want it accessible to all users, you can omit this line.
Create your build script
You must create a JAR file (Java ARchive) in order to install the plugin in Spigot. You may employ File – It will be simpler for you in the long run to configure Eclipse to create it automatically. In order for Eclipse to do that, we will be creating a build script in this step that defines the contents of the JAR file.
- Go to File -> New -> File
- Choose the top-level folder (the name of your project)
- For File name enter build.xml
- Click Finish
It should open in the editor.
Paste in the following:
You should replace “MyPlugin” at the top with the name of your project. Additionally, WordPress inserts a space between For the file to be valid, that space must be removed.
Tell Eclipse to use your build script
- Click the project name with the right mouse button (control-click or two fingers on a Mac) and select Properties.
- Choose Builders on the left side.
- Click New…
- Choose Ant Builder and click OK
- Set the name to
Make JAR
- For Buildfile, enter ${project_loc}/build. xml (literally, including the $ and the braces).
- Click the Refresh tab
- Checkmark Refresh resources upon completion
- Choose The project containing the selected resources
- Switch to the Targets tab.
- Next to “Auto Build” and “During a ‘clean,” select Set Targets…, and then simply click the OK button on the dialog that appears.
- Click OK to close out of the Edit Configuration window.
- Click OK to close out of the Properties window.
You should now have a functioning project, and whenever you make changes to anything in it, the plugin’s jar file in the target directory will be rebuilt automatically. It should always be current with your code if you’ve been saving your changes.
You now have a working plugin file that does nothing but has the necessary framework if you followed the instructions up to this point.
Oh, one more thing.
The plugin. A command description was included in the yml file as a simple example of how to put that in the plugin. yml file. I’d be remiss if I didn’t also provide you with a sample of the code that would be used to execute that command. That goes in Main. java by adding an onCommand() handler function. Your final Main. java would look like this:
UPDATED 2016/05/06: Still works in 1. 9, so updated references accordingly. Step 6 of the project creation process was fixed to use the shaded version of the API file. Many thanks to those who pointed it out in the comments.
UPDATED 2017/02/21: Although I haven’t had a chance to test it recently, several commenters have stated that this still functions in 1 11. x, so I’ve updated the references accordingly.
UPDATED 2019/07/13: Likewise. I haven’t tried it, but others claim it still functions in 1 14. x in the comments, so updating the title and references. A note about YEdit being removed from the Eclipse Marketplace has also been added.
Updated on 2019-07-22: It appears that WordPress finally broke the syntax highlighter plugin I’ve been using for the past four years. I’ve since replaced it with a Gutenberg-compatible one and made an attempt to fix the formatting of the code. Build. In particular, xml was completely broken; it needs to be fixed right away.
Find me on TwitterMe:
Minecraft Plugin Tutorial (in Kotlin) | Project Setup
FAQ
What coding language do Minecraft plugins use?
The coding language that Minecraft uses is Java. If you utilize a computer frequently, you might be familiar with this name.
How do I start coding Minecraft plugins?
ProcedureIn the Package Explorer View, right-click the project. Select New > Class. Give the class a name, enter RPUserPlugin for the Superclass, and make sure the Inherited abstract methods check box is selected when the New Java Class window appears. Your plug-in class must implement the following methods:
How to make plugins in Java?
Install Java in Step 1 of Making a Minecraft Server With Plugins For Minecraft to work you need to have Java installed. Step 2: Downloading the Server. Step 3: Preparing the Server. Step 4: Letting People Join Your Server. Step 5: Installing Mods. Step 6: Update the Server. 1 Person Made This Project! . 40 Comments.