Start coding with Spigot

Nov 15, 2015
Start coding with Spigot
  • Welcome! Prepare yourself for start coding
    ================
    Thank you for reading this wiki. Prepare yourself and your computer for start coding with Spigot, for create magic.

    Requirements:

    • An IDE (like Eclipse)
    • Time
    • Space in the disk.
    Some basic terms that you need to know:
    • IDE: Integrated Development Environment;
    • API: Application Program Interface; the bridge between some other program and your program.
    • Library: Required for plugins.
    • Java: One of many programming languages. Minecraft (server + client) run on Java
    -First steps-
    Things that need to be done before we start.

    Install the Eclipse IDE in your computer. Here is a video (not mine) teaching you how to install Eclipse:

    Well, I will simulate the Eclipse IDE with a picture but dont worry, is the same thing.

    1) Open Eclipse and create a new project:
      • Set the project name to what ever you wish.
      • Select Add External JARs under the Libraries tab. In the JAR Selection dialogue box, select the spigot-api jar file.* Select Finish (See image)
    2) Add a new package to your Eclipse project:
    Right click on src and click on New > Package. You may use any namespace convention you wish, just be consistent. (Help image)

    3) Create a new class:
    Right click on the newly created package and select New > Class. Give it any name; since this is a blank plugin, I gave it the same name as the project. (Help image). Inside the editor, the newly created Java class will open. The code should look somewhat like this:
    Code (Text):
    package com.meeku.tutorialplugin;

    public class SpigotBlankPlugin {

    }
    4) Modify the class declaration:
    You must extend the class to JavaPlugin. This makes your class inherit all fields and methods of the JavaPlugin class. Now your code will look like this:
    Code (Java):
    package com.meeku.tutorialplugin;

    public class SpigotBlankPlugin extends JavaPlugin{

    }
    5) Put these methods.
    The JavaPlugin class has some abstract methods which must be implemented by your plugin. The methods are onEnable and onDisable.

    Code (Text):
    [CODE]package com.meeku.tutorialplugin;

    public class SpigotBlankPlugin extends JavaPlugin{

        // When plugin is first enabled
        @Override
        public void onEnable() {
        }
        // When plugin is disabled
        @Override
        public void onDisable() {

        }

    }

    5) Create a plugin.yml file
    The plugin.yml file indicates what commands are in your plugin, what is the name of your plugin. who is the author of your plugin, where is the main class of your plugin and some other information. This file must be included in your plugin.
    Code (Text):
    name: MyPlugin
    main: com.meeku.tutorialplugin.SpigotBlankPlugin
    version: 1.0
    commands:
    6) Export your first plugin as a jar
    Right click on the project name, select Export. In the consequential dialogue box, select JAR file (. Click Next. You can uncheck the classpath and project includes and change the export destination to your plugins folder.

    7) Hour to test!
    Run your server (with your plugin iside the "plugins" folder).
    [​IMG]

    And you're done! Your plugin is ready to show his magic.
    Y
    Thanks to the Spigot Community for creating the images (Link to the post) and some text. I created this wiki basing on the wiki of the Spigot Community. I maked the instruction simplier.
    Regards,
    MrPlug

    Credits:

    Useful links:

    SPECIAL - SPECIAL - SPECIAL - SPECIAL - SPECIAL
  • Loading...
  • Loading...