How to Code Minecraft Plugins!
How To Code a Minecraft Plugin
After many years of waiting, today I can officially announce that Minecraft Plugin Development has come to replit! With this tutorial you will understand all you need to know on how to create the basic boilerplate for a standard Java edition plugin for the Spigot API.
This guide is geared towards creating a plugin on repl.it but will also work for IDEs such as Intelij IDEA and Eclipse (I recommend Intelij out of the two)
For any assistance feel free to leave a reply or join my Discord server discord.gg/zfgVqZv
Minecraft Java plugin development can be done for a variety of different APIs such as CraftBukkit, Spigot, PaperMC, Bungeecord, etc.
A Minecraft plugin is essentially a library built on these APIs that will allow you to interact with the API to create custom gamemodes, administration utilities, and much more!
Plugins are typically cross compatible with the main APIs but if you use methods specific to PaperMC it will not run as intended on CraftBukkit or Spigot servers, so be careful if cross-compatibility is a concern for you.
In this tutorial we will be building our plugin on the Spigot API using Maven as our build tool (Gradle is not available on repl.it as far as i’m aware).
Create a new Java repl and then go to the terminal/console.
Type the following commands in this order:
After that, you should begin to see Maven (a java build tool) spit messages in console. Leave it for a minute until it asks you to start inputting information for your project.
The first message you see should be along the lines of
For this, choose the latest version, for example if I was given this:
I would enter
8 into the console.
After this you will see a message asking you to input your
groupID. For this, if you have a domain then enter
tld.yourdomain, for example I own the domain astolfo.tech so I would enter
tech.astolfo. If you don’t have a domain then use
After this it will ask you for your artifactID, this is basically the name of your project. So, just enter what you’d like to call your plugin without any spaces or special characters. Example:
Once you’ve entered your artifactID it will ask for your plugin version, just put
1.0-SNAPSHOT to start with. It doesn’t really matter what goes here but in the end it will be the prefix of your compiled jarfile.
Once that’s done it will ask for what you’d like the package to be named. In this case enter your groupID+artifactID, for example:
When that’s over it will ask you to confirm, enter
Y, and then you should see this:
You should see a folder in your files with the name of your artifactID, click it and open the
Delete what’s currently in your pom.xml and paste the following:
Make sure to replace the values i’ve marked with your own values or your plugin will fail to compile!
Once you’ve modified the pom.xml file, navigate to
src/main and create a folder called
resources and then go inside that folder and create a file called
We will setup this file later!
After that go to
src/main/java/groupID/artifactID and delete
Create a new file called
YourPluginName.java and inside of it paste the following:
Replace the value for
package on line 1 and the name of the class to the appropriate values.
After this, go back to your plugin.yml file and paste the following:
Here’s an example of a working plugin.yml file:
Setting Up Your Repl
Now that we’ve sorted all that out, create a
.replit file in your project root and paste in the following:
Remember! Replace the marked value with your own
This will automatically compile your code whenever you click the run button!
Creating a Command
Now that we’ve sorted out all the basics, let’s begin creating our first command!
To start, go to your
plugin.yml file and add this to the bottom of the file:
Replace COMMANDNAME with what you want the player to type in game, for example a command called
tutorial will be run when you type
/tutorial in game. For a full list of command properties read this documentation
After that navigate to
src/main/java/groupID/artifactID and create a new folder called
classes and inside that folder create a folder called
Inside the commands folder create a new file called
Inside that file paste in the following boilerplate:
In this command I will show you how to send a basic message to the player. For more information on various that can be called on the player interface consult this documentation.
Inside our onCommand method (above the return true) we will define the Player as the command executor. To do this we will create a new Player variable called "p" by casting the "sender" variable like this.
Player p = (Player) sender;
Next, to send the message we need to use the
Player#sendMessage() method like this:
Our code should look like this now:
If your code looks like mine then that means you’re on the right track!
Now, how do we let the plugin know we want this class to be responsible for the command we created in our plugin.yml?
Simple! Head over to your plugin’s main class (YourPluginName.java) and import the class for your command by writing
After that, add the following line inside the
And that’s all there is to it! You can run the repl and use your compiled jarfile (located in
src/target on your server to test it out!
Creating a Listener
Commands are great and all but what if you want to do an action when an event occurs? (Ex. When a player hits an entity) Well, that’s where listeners come into play!
Go to your classes folder and create a folder called "listeners" and inside it create a new file called
Inside this file paste in the following boilerplate:
Remember! Replace the marked values with your own
Let’s create a new event handler which will prevent players from dropping items. To do this, create a new method with the player drop event as a parameter like this:
WARNING! Ensure you remember to put @EventHandler above the method or it will not work!
Inside our new method let’s get the player who dropped the item using the
e#getPlayer() method and send him a message like this
Now, let’s cancel the event so the player can’t drop the item using the
Our method should look like this now.
If this is the case, we can move onto actually registering the listener.
Navigate to your main class again, import your listener class and inside your
onEnable() method add a new line with the following:
That’s all there is to creating a listener. More events can be found on the Spigot API documentation
Compiling your Plugin
Now that we’ve finished, press the run button and it should compile your plugin and put the .jar file for you to download in
If the build fails and throws an error, either check my working repl project repl.it/@agent9002/Tutorial-Plugin and see what you’ve done differently. Or, if you’re too confused then feel free to contact me.
Need Tech Support?
If you need any assistance feel free to leave a reply or join my Discord server discord.gg/zfgVqZv
@amasad if you're talking about his recent post on repl share then that would definitely work as it uses PaperMC as it's jarfile (good choice @Scoder12 ;3). The problem though, is that it's running on a 1.16.1 version (the poor performance version), but with server config optimisations this could turn out real nicely.
for the commands folder, do we create files actually called YourCommandName.java, or do we call it something else. Also, i tried to name it /help or something, and you cannot have a file with / in the name. ty btw for all of the help
heyyyyyyyyyy how do you find the two ID folders. i got nothing. stuff keeps saying GO TO ARTIFACTID or smthn i dont have anything like that. :CCCCCCCCCCCCCCCCC
where is the project root folder? im not sure xD this like my 3rd time with java not including lessons
I have no idea how this works. Hover on my username. So to make it actually working minecraft, you would need some way to show the results right?
Can you help me? When I enter the first two lines and run it, this is what it says:
javac -classpath .:/run_dir/junit-4.12.jar:target/dependency/
- -d . Main.java
Main.java:1: error: class, interface or enum expected
compiler exit status 1
I do not know why. makes me think they know what I'm doing. I'm also new here.
Having an issue where I am unable to run it. I went through the tutorial but I seem to be missing something.
Oh yeah minecraft, forgot about that game. Haven't played since 2012. I guess I outgrew it.
WOW! But nxt time can u make a python plugin
Java is the industry standard for Minecraft plugins, if you have any interest in doing them then I recommend you just learn Java because attempting to do it in Python is not only going to result in a plugin with worse performance but it’s also going to be a lot harder to make since you’ll be going in blind. If you can find a good plugin API for Python though, I wouldn’t mind helping you. @FluidGaming
@agent9002 I dissagree. Despite it being one of the easiest and most popular languages in the world, it is still too slow, as it does not use a compiler and it being dynamically typed. There is a reason the original version of Minecraft is not written in Java. I mean, if he made a C# or C++ plugin, then it would be at a good speed.
Definitely not, the server also has to use a client based in Java. So if you're writing this in C#/C++ it would have to translate the Java code to C#/C++ and vice versa which is just going to be slow. This is why projects that attempt to do this with different languages typically fail to support a large amount of players and lack a large number of the in-game events. Good speed isn't something that would be achieved here. With efficient coding constructs you shouldn't run into any issues with speed with MC Plugin Development. @viraatvv
What are you on about? The actual server client from Mojang is written in Java, it's not a matter of plugin developers being incompetent, the actual client is based on Java. Think of it as asking a mod developer to rewrite the entire base game of Minecraft in C#/++ with Java server compatibility. And even then, there's already so many existing frameworks and libraries made in Java for CraftBukkit and it's forks, it would just be too much of a hassle. It's not an "easy switch". @viraatvv