How to create a Minecraft plugin

You often play Minecraft, the now iconic sandbox videogame designed by Markus “Notch” Persson, and you’ve also created your own server, which you would now like to expand with new features. In particular, you’ve heard that it’s possible to program plugins, but you don’t know where to start. No problem: you’ve come to the right place!

In fact, in this guide, I will explain in detail how to create a plugin for Minecraft giving you a concrete example of what is possible and explaining how, usually, players use the latter. I assure you that this is a less complex procedure than you imagine.

What do you say? Are you ready to customize your Minecraft server? I think you can’t wait to see your code in action. Come on then, all you have to do is simply follow the quick instructions that you can find below. That said, there is nothing left for me to do, except wish you good reading and have fun!

Index

  • Preliminary information
  • Create a server and download the necessary programs
  • How to create a Minecraft plugin

Preliminary information

Before going into the details of the procedure on how to create a plugin for Minecraft, I think it may interest you to know more about this possibility.

Well, plugins are used in Mojang’s title to expand the possibilities offered by Spigot, modified APIs (i.e. software libraries) that allow you to create Minecraft servers with customized functions, much richer and more flexible than the official ones. All this takes place using the Java programming language, therefore, as you have already guessed, the changes you are going to make will only be feasible on the Java version for PC of Minecraft.

Of course, the changes you can make on the server depend on your imagination and programming skills. If you want concrete examples of what developers from all over the world have created, I recommend that you take a look at the Spigot plugins page.

As you can see on the page I mentioned above, there really is everything. There are those who have created custom wings and those who have introduced volcanic eruptions in the title of Mojang. In short, learning how to program plugins for Minecraft servers can be particularly interesting.

Before starting with the instructions, however, it is good to underline two aspects: in this tutorial I will carry out a practical example related to a Spigot server, but on Minecraft there are various types of virtual rooms, as you can read in this page (in English). However, I will focus on the type of server in question, as the most used, but if you are an enthusiast you may want to take a look at the other available solutions as well.

For the rest, as already mentioned above, to create a plugin for a Spigot server it is necessary to program in Java. In this guide I will simply explain how to make your first working plugin in a short time, taking advantage of the rudiments of this programming language.

In fact, it would be impossible to explain to you how to program in Java in an advanced way in a single tutorial. It takes months, if not years, of study to actually learn a programming language. That’s why, if you want to deepen the subject, I suggest you consult my tutorials on how to start programminghow to program in Java and how to learn Java, in which I have recommended many resources suitable for this purpose.

Create a server and download the necessary programs

Having made all the premises of the case, it is time to take action by setting up a Spigot server for Minecraft in localhost (therefore on your computer) and downloading the right programs to create a plugin. To give you some concrete examples, I will examine the creation of a Spigot server on Windows.

Well, the first thing you need to do is install Git and OpenJDK 8, two software intended for programming necessary to create a virtual room of this type. To do this, connect to the official Git site and press the Download button. Then open the Git- [version] .exe file obtained and press the Next (12 times)Install and Next buttons in succession to complete the installation.

Then, connected to the OpenJDK site, check the OpenJDK 8 box and press the Latest release button. This will download the OpenJDK- [version] .msi file to your PC. Then open the latter, click on the Next button, check the box linked to the license terms and press in succession on the NextNextInstallYes and Finish.

Small note: Spigot developers would recommend using Java SE Runtime Environment 8, downloadable via the official portal, instead of OpenJDK8. However, in that case to start the download you need to register an Oracle account and the procedure also requires information such as the name of the company you work for and the telephone number of the office, so I preferred to suggest an easier way.

That said, once you have installed the aforementioned programs, you need to compile the server file via BuildTools.java : file that you can download by simply clicking hereOnce the download is complete, open Git Bash, which is part of the program you previously installed, and move the BuildTools.java file to your desktop. Then go back to Git Bash, type the command and press Enter on your keyboard.cd desktop

At this point, type the command java -jar BuildTools.javaand press Enter. Perfect, you will see the progress of the creation of the jar file of your Spigot server. You may have to wait a few minutes, as there are also several downloads to make to get everything up and running.

In any case, once the procedure is finished, if everything has been done correctly, you should see that some files have appeared on the desktop and that in the Git Bash window there is the word Success.

At this point, you can close the Git Bash window and start the spigot- [version] .jar file on the desktop. If everything has been done correctly, the Minecraft server window should appear on the screen. If not, try opening the eula.txt file that you find on the desktop and change the value false to true.

Perfect, now your server is up. To verify that it is working, just start Minecraft in the latest version available, press the Multiplayer button, then the Direct Access key, type localhost and press the Enter server button.

If everything has been done correctly, you will see that your character will enter the server and that the nickname you have chosen for the Mojang title will appear in the Minecraft server window. Congratulations, you now have a working Spigot server!

For more information on the changes that can be made by default to the virtual room and for further details on the installation phase, also for other versions and platforms, I invite you to consult the Spigot website (in English).

Now that you have seen that the virtual room works, you can log out and close both the game and the Minecraft server window.

However, you need one more program before you can start creating your plugin: a integrated development environment (IDE). Put simply, it is a program that allows you to write and compile Java code.

There are several programs of this type, as you can read in my guide dedicated to the subject. Anyway, I recommend IntelliJ IDEA which is relatively simple to use. To download it, just connect to its official website and press the DOWNLOAD button twice.

Once the download is complete, open the idealC- [version] .exe file obtained and press in succession on NextNextNext and Install, then check the Run IntelliJ IDEA box and click on Finish, to complete the setup.

How to create a Minecraft plugin

After having created a Spigot server and installed all the necessary programs, the “highlight” has arrived, that is, the creation of the plugin.

If you followed the instructions I gave you in the previous chapter, you already have the Intellij IDEA window on your screen. Then click on the Skip Remaining and Set Defaults button and click on the New Project option. Then, select the Java item on the top left and press the Next button twice.

At this point, give the project a name (eg PluginAranzulla) and click on the Finish button. You can safely press Close, in case some “tutorial” windows appear on the screen.

Then, click on the File item at the top left and click on Project structure. Move, therefore, to the Libraries tab, press the + icon, click on the Java item, select the server jar file and press on OK.

Perfect, you have now successfully imported all relevant libraries. Once this is done, close the libraries window, expand the project folder on the left, right-click on the src folder and select the New> Package items from the menu that is proposed to you, then assigning the name you prefer (eg Aranzulla) .

Then, right-click on the package you just created, which is on the left, and select the New> Java Class items from the menu that is proposed to you. So give the name you want (eg PluginAranzulla) and press OK.

Perfect, now it’s time to write the code. The first thing to do is to import JavaPlugin: to do this, insert the line at the top of the file import org.bukkit.plugin.java.JavaPlugin, closing with a semicolon.

Then press Enter to create some line of space and start creating your own class, writing, for example public class PluginAranzulla extends JavaPlugin. Put simply, you are creating a class that extends that JavaPlugin, used by developers to create plugins for Minecraft.

Obviously, you have to close everything with curly brackets. In case JavaPlugin is not recognized, try to re-import the server jar file in the way I showed you earlier.

Next, right-click on the src folder and select the New> File items from the menu that opens, giving it the name plugin.yml. Here you have to enter all the basic information related to the plugin, from its name to the main class, passing through the version, the description and the commands. In this case, it’s all very simple: just use the variables namemainversiondescription and commands followed by: and enter their “value”.

In particular, in name, you must type the name of the plugin (do not insert spaces for any reason), in main the name of the class you created previously (preceded by the name of the package and without extension), in version enter the version that you think is more correct (eg. 0.0.1 if it is a preliminary phase, 1.0.0 if you think it is “finished”) and in description, you must enter the description of the plugin (eg Plugin created through Salvatore Aranzulla’s tutorial).

Finally, in commands, it is necessary to insert, after the colon, the name of the command you want to use (e.g. website) followed by: and having inside the parameters description (description) and usage (method with which the user can use the command, eg / website).

Perfect, now you have the “space” in which to make your changes. I’ll give you a very simple example from which you can then start building more advanced plugins. More specifically, I will explain how to create a plugin that will allow the user to get the URL of the server creator‘s official site by simply using the / website command within the Minecraft server.

To bring this plugin to life, go back inside the java file you created earlier and add two more imports, namely import org.bukkit.command.Commandand import org.bukkit.command.CommandSender. The latter are used to use the tools designed to “receive” the user’s commands.

After that, you need to override the onEnable () and onDisable () methods within the plugin class. To do this, just use a @Overridebefore the creation of the public void methods. I advise you to use indentation with the tab key to make the code more “readable”. I remind you that you can write comments to the code via// , what is written in those lines will be ignored during compilation: it only serves you to remind you what that code is for.

In this specific plugin we will not use these methods, but the structure is usually this and therefore it was right to explain it to you. The method we will use instead for this example is the onCommand one, designed to “respond” to user commands. Here we give as input, that is the variables in brackets, CommandSender, that is the user who sends the command, and Command, that is the command itself. You also need to add a String and a String [] in order to adequately perform the ‘ Override.

Inside the onCommand method there must be what happens when the user sends a certain type of command. In this case, I have decided that the command the user should use to get the website URL is simply / website. For this reason, it is necessary to check the input sent by the user. I have already explained to you that it is contained in the Command type , which I have “instantiated” through the variable called command.

To check, we use an if, or an “if”. The code in this case is the following: if (comando.getName().equalsIgnoreCase(“sitoweb”)) { utente.sendMessage(“Il mio sito è [www.aranzulla.it](http://www.aranzulla.it/)”); }. In other words, I take the command with the getName () method, I look, regardless of case, if the command is really “website” through the equalsIgnoreCase method and if so I send a message containing the URL of my site to the user via the sendMessage method.

At this point, you have successfully finished programming the plugin that returns the website URL to the user when the user uses the / website command. Now comes the build part, which will create your plugin .jar file.

To proceed, click on the File item at the top left, click on Project Structure, move to the Artifacts tab, press the + button and select the items JAR> From modules with dependencies. Then press OK, remove, using the  icon, the word Extracted file spigot [version] .jar and press the Apply button first and then the OK button.

At this point, click on the Build item at the top and press the Build Artifacts option. Then, click on the Build item, wait a few seconds and the system will inform you that the compilation has been completed. You will see the red out folder appear at the top left.

Therefore, expand its content, expand the artifacts folder as well and you will see the .jar file of your plugin appear. Now, right click on it and select the Show in Explorer option.

This will open the File Explorer path with your plugin .jar file. Now, you need to move the file in question that you have generated into your server’s plugins folder. If you followed my instructions, you should find it on your desktop.

Next, start the server jar file and wait for the Minecraft server window to appear and load. Once done, type stop at the server console and press Enter. After that, restart the server jar file again. In this way, you should see the writing linked to your plugin appear: it means that it has been installed.

Now you just have to start Minecraft, press first on the Multiplayer button and then on the Direct Access button, enter the server address (eg localhost) and press Enter.

In this way, you will correctly enter your virtual room. To check the plugin operation, just press the T button on the keyboard, type the command /sitoweb and press the Enter server button. If the message with the site URL appears on the screen, everything has been done correctly.

Furthermore, you can also see the list of active plugins on the server using the command /plugins. In short, you have successfully created your first plugin for a Minecraft Spigot server. Now you just have to indulge yourself with the Java code to create your own personalized experiences within the Mojang title.

Since you are a fan of Minecraft, I suggest you also take a look at the page of my site dedicated to the game in question, where you can find countless tutorials related to the Mojang title.

 

Leave a Reply

Your email address will not be published.