All right welcome back to a brand new video series in this whole tutorial series I’m going to be teaching you all how to code Minecraft plugins we will be using the spigot API to uh program all of our plugins so I’m really excited because I’ve always wanted to do a series on this So some prerequisites make sure you won have Java installed okay I have Java 17 installed on my computer but make sure you install Java first before you even attempt to do this two make sure you have an IDE set up I’m going to be using IntelliJ for this whole tutorial series IntelliJ is a very popular very widely used IDE and it’s very easy to use so I expect you all to have it installed and use that to follow along you could use Eclipse but I would not recommend it because IntelliJ is uh is really popular in pretty much The industry uses IntelliJ these days okay so the first thing that I’ll do is I’ll just go ahead and set up a spigot server very quickly so you can see that right here on my desktop I have the spigot 1.19 0.2 uh dot jar file I’m gonna move this Inside my documents folder so what I’ll do is I’ll make a new folder called spigot server inside my documents folder I’m going to go ahead and move uh the spigot 1.19 file so uh we want to move this from the desktop okay because it’s currently in the Desktop and I’m going to move it inside the documents slash spigot server folder I’m going to see the into the spigot server folder and then we should see that we have this jar file so I’m gonna load up this jar file so I’m going to run the jar file by typing Java python Jar spigot okay and this is just going to run the jar file and then we do need to agree to the EULA in order for us to continue initializing the server so let me go ahead and just do that real quick should take not too long so I’m just running through this uh Server setup just so you all are on the same page okay so I’m going to run the server and our server should be running okay so pretty much you’ll see that the rest of the folder will generate some additional files after you agree to the EULA one thing that I will mention is Make sure you have the plugins folder created inside the spigot server by default it will automatically create this folder for you but if you don’t have it just make sure you create it okay because we’re going to go ahead and put our jar files of the build plugin That we create inside this plugins folder and then our spigot server will be able to load the plugin so let’s just close this out because we don’t really need this anymore and let me just minimize this and so we’re going to go ahead into IntelliJ and we’re going to create our project For our plugin so I have until you opened up IntelliJ is free okay if you use the Community Edition so I’m going to go ahead and just click on new project and then we can see over here we have a new project and I’m going to name my Project I’ll just call this um spigot plugged in tutorial and the location of this will be inside the documents folder and the language is obviously going to be Java the build system we will be using Maven although if you choose to use Gradle you can but I’m going to be Using Maven so I expect you all to follow along with Maven and I also forgot to mention is that make sure you also do have Maven installed as well you can see that for the jdk version I’m using version 17. okay and for advanced settings uh the Group ID I’m going to leave that alone so just go ahead and just click create okay and we have our project set up so now what we need to do next is we need to go ahead and actually download the jar files uh for our plugin or for our plugin Project right now um You can actually just manually download the jar files or what’s easier is you can actually just uh copy and paste the XML okay so I’ll actually leave a link in the description to this URL and you’re basically going to need to just copy This XML over here so this will automatically download the spigot API for your project so I’m just going to copy this and you’re going to paste this inside your palm.xml file okay so right over here just like that okay now um you might see like this as red and what that means is That spigot the the jar files were not downloaded now obviously over here it’s not showing it as red because I think it’s using a cached version but in order to actually download it what you can do is just click on this little icon over here load Maven changes and what that’ll Do is it’ll automatically just uh well not automatically but it’ll manually download the dependencies so I’ll just do that okay and it’ll take like you know a couple seconds for it to finish downloading but once it’s done it should no longer be red okay so as you can see That we do have our dependencies downloaded so we are good to go so what we’re going to do now is we’re going to go ahead and create our plugin so to get started with coding it we need to go inside our source main Java folder we’re going to right click click on new Or hover over new and then select Java class and then we’re just going to call this class whatever you want and I’ll just call this my plugin and then what you want to do is you want to go ahead and extend the Java plugin class and this is going to come from the Org.bucket.plugin.java package so this is from the spigot API uh you know dependency that we had downloaded okay and now what we want to do is we want to go ahead and override two methods we’re going to override the on disable and uh on enable method now um to get This tab just hit Ctrl o okay on your keyboard and then you’ll get it so for now we’ll just work with these two methods and then later on in other tutorials I’ll show you how you can do things such as handle commands Okay so just go ahead and Override these two methods and what I’ll do is for the on enable method inside here I’m going to go ahead and log a message to the output so I’ll reference this Dot get logger and then we’ll log a message so for the level I’m going to use the level enum Which comes from java.uto.logging and I’ll just uh do this I’ll set it to info and then for the message I’ll just say uh my plugin successfully loaded okay and now that we’re uh logging this to our console we’ll go ahead and go into resources the folder resources because the next Thing that we’ll need to do is we’ll need to create the plugin dot yml file that’s very important okay because it tells spigot all the information about your plugin so over the restore over our resources folder inside Main right click hover over new create a new file by clicking on file And just name it plugin not yml and then what you want to do is you want to specify three properties the first property is going to be the name of the plugin so I’ll just call this my plugin the second property is going to be the Version which you can you know put this as whatever version you want I’ll just press 1.0 and then the third property is going to be Main and this is going to be the uh the class for your plugin in our case the class of our plugin is my Plugin one thing that I will also mention is that our our plugin is not inside a package so in our case we would actually just leave it as my plugin like this okay so what I’ll do now is I’ll close this okay so just remember that Main is just the class of your plugin okay this is the main file of the plugin okay that’s pretty much all it is to it um okay so now what we can do is we can actually package our plugin so we’re going to go over to the right hand side I’ll click On Maven and expand this part over here and then you want to go ahead and click on lifecycle expand this and you want to click on package and what this will do is it will package your whole project and then you’ll see it’s going to build everything and there should be a new Target folder that is created and you’re going to see that it created this jar file for us okay so you can actually just take this jar file and move it inside your server folder now I’ll show you how we can actually change the output directory later on but For now let’s just take this and move it into the server folder so what I’ll do is I’ll open up a new terminal so I’m inside my documents folder you can do this inside your file explorer manually but I’ll just use the terminal I’ll see the inside spigot plugin tutorial because That’s my project right I’m going to see the inside the target folder and you can see that I have that jar file over here I’m going to move this inside the documents folder inside the spigot server directory inside plugins okay or actually wait whoops it’s supposed to be MV spigot Plug-in tutorial 1.0 snapshot.jar so we’re moving the jar file into the documents folder whoops documents maybe server and then plugins like that again you can manually do this inside your file explorer okay so I just moved it so the file is no longer in the Target folder if I see The into plugins I should now see this jar file okay so now uh since our server is already running I can just type reload and this should reload the entire server and you can see that right over here that it says my plugin successfully loaded and this text is coming from Right over here this log over here so that means our plugin has successfully loaded all right so now I’m going to go ahead and show you how you can change the output directory so that way when you compile your Minecraft plugin instead of having to move it manually to The plugins folder it’ll automatically compile it to that folder so a quick shout out to Cody Simpson because he actually made a video uh showing you how to do this and this is actually the same exact article that he Linked In His tutorial so shout out to Cody Simpson But I’ll also leave a link in the description to this stack Overflow page so you can actually copy this this XML into your palm to XML files that’s all you have to do okay um you could actually just copy this um right over here go into your palm.xml file and right over here Just simply paste that over here okay and then if you don’t have this plugin downloaded this version text will be red so I already have I already have it downloaded so you so it’s using the cached version but just go ahead and make sure you click on load Maven Changes just so that it will actually download the dependency so it will no longer be read anymore which means that you have the dependency downloaded okay so what you’re going to do next is you’re going to change the output directory over here so I’m just going to Delete that and I’m on Windows right now so I’m going to specify my file path so it’s going to be C colon backslash and then users backslash Anson backslash and then documents and then spigot server because that’s where my spigot server is and then backslash plugins and I’m going to save And I’m going to exit this now inside my terminal you’re going to see that I don’t have anything in my folder right now so we’re going to go ahead and go to Maven we’re going to go ahead and just package everything and you’re going to see that um It’s no longer going to build that jar file into our Target folder if we look at our Powershell if I type LS you’re going to see that the jar file is now over here okay so what I can do is I can always just um run the spigot jar Okay and what I can do is I can just specify no GUI so that way it doesn’t run a GUI so that means that it won’t open up the uh the extra uh interface it will just it will just have everything in the console over here But if you prefer that as well you can also do that but everything works fine in this console okay so you can see that our plugin has been loaded and if I want to make changes to my plugin let’s just do this dot get logger you actually don’t even need to reference This you can just call get logger okay and then you can just do log level dot info a like plugin and then let’s go ahead and repackage everything okay and then what we will do is inside the console we’ll just type reload and you’re going to see that it says hey My plugin so every single time to make a change we package it again and then you can see it says hey my plugin so that’s how you can compile into the uh the plugins folder so again shout out to Cody Simpson uh I did see His video on that so shout out to him um but yeah that’s pretty much it for this whole tutorial so that’s pretty much it when it comes to developing your very first Minecraft plugin with spigot so in the next tutorial I’ll show you how to do other stuff such as handling Commands so thanks for watching and I’ll see you all in the next episode peace out Video Information
This video, titled ‘Minecraft Plugin Tutorial – Creating Your Plugin with Spigot’, was uploaded by Anson the Developer on 2022-08-13 13:00:28. It has garnered 7792 views and 128 likes. The duration of the video is 00:14:42 or 882 seconds.
Link to Stack Overflow Post on Changing Output Directory: https://stackoverflow.com/questions/4757426/maven-specify-the-outputdirectory-only-for-packaging-a-jar
Get Spigot Dependencies for pom.xml file: https://www.spigotmc.org/wiki/spigot-maven/
Support the Channel:
Become a Member: https://www.youtube.com/ansonthedeveloper/join Become a Patreon: http://patreon.com/stuyy Buy me a Coffee: http://ko-fi.com/anson Donate on Streamlabs: https://streamlabs.com/ansondevacademy/tip Donate on PayPal: https://paypal.me/ansonfoong
Connect with me:
Twitter: https://twitter.com/ansonthedev Discord: https://discord.gg/Gd5fAEJDQD GitHub: http://github.com/stuyy Twitch: http://twitch.tv/stuy