Thread Status:
Not open for further replies.
  1. Introduction
    Hey guys, drew6017 back here again today giving you a tutorial on how to make your first plugin for bukkit! In this tutorial we will be covering some of the basics. This tutorial requires no past knowledge in coding although it is recommended.


    Setting Up Your Workspace
    This tutorial is going to show you how to make plugins using maven which is a java tool for developing server plugins. To get started, we are going to need to set up our interactive development environment or IDE. For maven development, I would suggest Eclipse Luna which is what I am going to be using in this tutorial. Although you could use other IDEs such as Netbeans or Jetbrains which you could find with a quick google search. Netbeans comes along with the Java JDK which I would recommend installing as well. This is normally required, but Eclipse comes with a Java EE compiler that does not require JDK so you should be fine if you don’t want to go to the trouble of installing the JDK. Once you have downloaded Eclipse, extract the zip to your desktop. Inside the folder you will find an Application(.exe) named eclipse.exe. Run this application. It should take longer to start up the first time you run it. Eclipse will prompt you to select a workspace. When it does, you can either leave it as the default or set your own. After this, eclipse should be set up, and you are ready to start coding!

    Setting Up A Test Server
    Before we start actually coding the plugin, we are going to need a way to test our plugins to make sure they don't have any bugs before releasing them. I use a Spigot server to test my plugins for bukkit so I can market them as being compatible with Spigot and Bukkit. We will be setting up a spigot server for this tutorial. Now, you are going to have to download BuildTools. When run BuildTools gives you everything you could ever need for bukkit/spigot/craftbukkit plugin coding including the server jars. You just need to make a new folder on your computer and place the BuildTools jar inside. After this, you need to run the jar using a shell script which can be made by creating a file in notepad with the .sh file extension. Inside the Shell Script you need to paste this code:
    Code:
    JAVA_HOME="C:/Program Files/Java/jdk1.7.0_71/" java -jar BuildTools.jar
    If you are running any other OS than MAC, you are going to have to install Git. This is to run the shell script we just made. After running BuildTools and allowing it to finish download all of the required files, you need go to the directory that you placed the BuildTools jar in. In this folder you are going to have to go to Spigot\Spigot-Server\target. Here you will find a server named spigot-[MC version]-[build version]-[version type].jar. This is your server jar. Copy this jar to another directory. This will be your server directory. Now, create a file named whatEverYouWant.bat. Right click on the file and paste the following code. This is some simple code that I wrote for the purpose of this tutorial.
    Code:
    @ECHO off
    "C:\Program Files\Java\jre7\bin\java.exe" -Xmx1024M -Xms1024M -XX:MaxPermSize=256M -jar spigot-1.8-R0.1-SNAPSHOT.jar
    PAUSE
    (You could use this code to run BuildTools if you do not want to install Git, even though I recommend you should install Git) You are going to have to change the "C:\Program Files\Java\jre7\bin\java.exe" to the path of your java.exe. This will be different depending on the version of java you have installed and the operating bit of your system. For instance, if you have a 32 or 64 bit computer. There are 1024 megabytes in one gigabyte. Multiply this number by however many gigabytes of ram you want to give to your server. This number can not exceed the amount of ram your system has or you will get an error. After excepting some agreements thanks to Eula, your server will create some files and directory's. One of these directory's will be your plugins folder. This is where you will put your finished plugins after compiling them.

    Creating a Project
    To create your first plugin, you are going to need to create a project in eclipse. Right click the long tab on the left side of your screen and hover over New then click Project

    [​IMG]

    After clicking Project you will be prompt to select a project type. You will need to select Maven Project.

    [​IMG]
    Click next and check the box that says Create a simple project (skip archetype selection)

    [​IMG]
    Click next again and you are going to need to fill out the following fields with whatever you want.

    [​IMG]
    Click Finish and you have created a new project! Now we are going to have to edit our pom.xml. To do this, copy and paste the following code into your pom.xml inside the <project> tags that were created by default.

    Code:
         <build>
          <plugins>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <configuration>
                      <source>1.7</source>
                      <target>1.7</target>
                  </configuration>
              </plugin>
          </plugins>
       </build>
    
          <repositories>
           <repository>
               <id>bukkit-repo</id>
               <url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
           </repository>
       </repositories>
    
          <dependencies>
           <dependency>
               <groupId>org.bukkit</groupId>
               <artifactId>bukkit</artifactId>
               <version>1.8-R0.1-SNAPSHOT</version>
               <type>jar</type>
               <scope>provided</scope>
           </dependency>
       </dependencies>
    The finished pom.xml should look something like this.
    [​IMG]
    The Basics
    To start the plugin we are going to need to create a package and class. Right click on the directory inside your expanded project named src/main/java. Go to New>Package. Under name, I would name this yourCodingName.pluginName.main. This is so if someone else creates a plugin and names a class the same as yours, the server wont break and only load one of your plugins. This can happen because plugins are treated as library's for the server jar. Right click on the package you just created and go to New>Class. Name the class whatever you want and create it. After the class has been created, you are going to need to make your class extend JavaPlugin. After this, create two methods. onEnable and onDisable. These methods will be called when your class is enabled by the server. We are just going to make them print a message into the console for the sake of simplicity. Your class should look like this so far.
    [​IMG]
    For our plugin to be considered a plugin, we are going to need whats called a plugin.yml. This is what defines your plugin and lets your server know it from just a random jar on your computer. To create the plugin.yml, you are going to need to find the directory under your project named src/main/resources. Right click on this and select New>File. Enter the name of the file to be plugin.yml. WARNING: This file has to be named plugin.yml. Your plugin.yml should look something like this.
    [​IMG]
    Thats it! Your plugin can now be recognized as a plugin and loaded by bukkit/spigot to print in a message when the server starts. To compile the plugin, right click on your Project and go to Run As>Maven Install
    [​IMG]
    After doing this, go to your workspace>ProjectName>target. Inside this folder is your jar! All you have to do is drag this jar to the plugins folder for your server.
    About Me
    I am a java coder from good ole Mississippi who knows a little bit of almost every language out there. Batch, shell script, python, html, ect... You name it, I probably have coded it before. I started out coding java GUI applications, but always wanted to get into some form of game design. The best way for me to start doing that was not by creating a whole new game, but editing an existing one. This is how I got into coding bukkit. I written several plugins. Out of all the plugins I have coded, my favorite one by far is FireworkBuilder which you can check out by clicking that hyperlink. Out of all the java GUI applications I have coded, my favorite is J.A.R.V.I.S which was a recreation of the Jarvis seen off of the movie Iron Man. I created it for a school project and according to the classes reaction when it was able to tell me the weather, play music, etc. I think I did a pretty good job. Thanks for reading this tutorial, hope it helped you get started coding!
    Want To Learn More
    Check out some of my other tutorials!
    1. Data Storage
     
    #1
    Last edited: Apr 18, 2015
    • Useful Useful x 13
    • Like Like x 9
    • Creative Creative x 1
  2. 043A7

    043A7 Well-Known Member

    Messages:
    1,811
    Nice tutorial!

    Btw, if you don't like doing work and you want to be a pirate, getspigot.org is your website! Yarrrr
     
    #2
    • Like Like x 2
  3. Ashley Tonkin

    Ashley Tonkin New Member

    Messages:
    2
    This is great :)

    Are you going to be doing some more ?
    I'm only asking as i would like to get into Java programming more for Minecraft. as im a Web Programmer myself in PHP and HTML plus others, Java is OOP and im only starting to get into OOP with PHP so im slowly learning.
     
    #3
  4. I could. Maybe something like data storage for plugins?
     
    #4
  5. Ashley Tonkin

    Ashley Tonkin New Member

    Messages:
    2
    Yeah that would be awesome just some more basic stuff then i guess go slowly into more advanced plugins
     
    #5
  6. Is is an awesome guide. It really helped me out.

    +1
     
    #6
  7. Jacko

    Jacko Well-Known Member

    Messages:
    4,978
    [ERROR] The build could not read 1 project -> [Help 1]
    [ERROR]
    [ERROR] The project [unknown-group-id]:[unknown-artifact-id]:[unknown-version] (C:\Users\Neww\Desktop\Failing at making a minecraft plugin\Healer\pom.xml) has 4 errors
    [ERROR] Malformed POM C:\Users\Neww\Desktop\Failing at making a minecraft plugin\Healer\pom.xml: Expected root element 'project' but found 'build' (position: START_TAG seen <build>... @1:12) @ C:\Users\Neww\Desktop\Failing at making a minecraft plugin\Healer\pom.xml, line 1, column 12 -> [Help 2]
    [ERROR] 'groupId' is missing. @ line 1, column 12
    [ERROR] 'artifactId' is missing. @ line 1, column 12
    [ERROR] 'version' is missing. @ line 1, column 12
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
    [ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/ModelParseException

    ^when i try to compile it
     
    #7
  8. You cant just paste what I have in for the pom. You have to add it between the project brackets like this.
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>drew6017.projection</groupId>
        <artifactId>Projection</artifactId>
        <version>0.0.1</version>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        <dependencies>
            <dependency>
                <groupId>drew6017.spigot</groupId>
                <artifactId>Spigot</artifactId>
                <version>1.8.4</version>
                <type>jar</type>
                <scope>provided</scope>
            </dependency>
        </dependencies>
    </project>
     
    #8
  9. Ondre

    Ondre Well-Known Member

    Ondre
    MVP+
    Bougie
    GUILDMASTER
    Messages:
    1,004
    This is definitely a great tutorial for new beginners! Nice job. +1
     
    #9
  10. Myythe

    Myythe Member

    Aoxx
    Messages:
    80
    I know a thing or two about java and Bukkit. Not that difficult, but it sure isn't easy figuring out for yourself.
     
    #10
  11. joellie50

    joellie50 Well-Known Member

    joellie50
    MVP+
    Messages:
    2,035
    "Gives creative rating"
    Fantastic.
     
    #11
  12. Thanks man this was really helpful now i have particles for my server thx <3 !
     
    #12
  13. BemLo

    BemLo New Member

    BemLo
    VIP
    Messages:
    1
    NICE!
     
    #13
  14. Mike

    Mike Well-Known Member

    mikeNsadie
    MVP+
    Messages:
    3,697
    Just saying, I already made a guide for it but great tutorial either way man!
     
    #14
  15.  
    #15
  16. Mike

    Mike Well-Known Member

    mikeNsadie
    MVP+
    Messages:
    3,697
    [QUOTE="PhantomMickey, post: 7522204, member: 803356"][/QUOTE]Hm, pretty sure you did something wrong. Try to look at the error and figure it out, that the way i learn to do it. :)
     
    #16
  17. TechnoFloss

    TechnoFloss New Member

    iEatFloss
    MVP+
    Messages:
    2
    I got this error when running the Debug Configuration:
    Code:
    Failed to connect to remote VM. Connection refused.
    Connection refused (Connection refused)
    How can I fix this?
    Overall, great tutorial though!
     
    #17
  18. hi
     
    #18
  19. Please do not necro (post on) old threads, if you're having an issue it would be better to make a new post as any information here is likely to be outdated.
     
    #19
Thread Status:
Not open for further replies.

Share This Page