Results 1 to 2 of 2
  1. #1
    Bot Bot's Avatar
    Join Date
    Aug 2011
    Posts
    2,671
    Points
    7,720
         User Info     Contact     Gamer ID
    Join Date
    Aug 2011
    Posts
    2,671
    Points
    7,720

    Default Minecraft Bukkit Plugin Tutorial - Tutorial 1 - The Basics

    I'm going to skip the setup and presume you have the very basics setup. For this tutorial I'm using Eclipse so if you use this program you should find everything easier to follow.

    New File

    So start up Eclipse and chose File then New then Java Project.
    Give your project a name and click Finish.

    Setting Up The Build

    Now your project is created right click it in the Project Explorer and click Properties.
    Go to the Java Build Path menu and click the Libraries tap and then press the Add External JARs... button then browse to and select the Bukkit API jar file.
    Next go down to the Javadoc location menu and then enter http://jd.bukkit.org/apidocs/ for the location path, now click the Apply button and then the OK button to save those changes.

    Creating The Package

    Now right click your project again but this time chose New and then Package.
    The standard naming system is the TLD, domain and then project name - so for example, com.codeleakers.extr3m3.

    Creating The Class File

    Now right click your new package and click New again but this time chose Class.
    This file will be one of your main code files hence why I call my class file Main, but you can call it what you like, capitalisation will matter later.

    Now this new class should look something like this:

    Code:
    package {$PackageName};
    
    public class {$PluginName} {
    }
    Where for me {$PackageName} would be com.codeleakers.extr3m3 and {$PluginName} would be Main.

    Now add to public class Main the words extends JavaPlugin, so you should have public final class {$PluginName} extends JavaPlugin.
    Now JavaPlugin will likely have a red underline, highlight the word and click on Import 'JavaPlugin' (org.bukkit.plugin.java). Alternatively you can go to Source and then click Organise Imports and this will automatically import what you need, and this method is a lot more useful if you know you have several items to import.

    So now your class file should look like this:

    Code:
    package {$PackageName};
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class {$PluginName} extends JavaPlugin{
    }
    Now finally, before we leave this file we will add one more part. Within the brackets of the public class {$PluginName} extends JavaPlugin we should add:

    Code:
    public void onEnable(){
    }
    	
    public void onDisable(){
    }
    Now these parts will operate the code within their respective brackets when this plugin is enabled and code within onEnable will run, similarly when the plugin is disabled any code within onDisable will be run.

    These aren't necessary but they are useful, and though they aren't coded to run any code there is a lot of opportunity to utilise this feature.

    Creating The Class File

    Now finally we need a plugin.yml file and so to create this we right click on the project name in the package explorer and go to New and then File. Now enter plugin.yml for the file name and click Finish.

    Now open the plugin.yml file and enter the plugin details, this is also where commands can be entered but we will discuss that in another tutorial. So your plugin.yml should look something like this when you are finished:

    Code:
    name: {PluginName}
    main: com.OneStopSudios.DemoPlugin.Main
    version: 1.0
    author: {Author}
    Both name and main are required and main needs to be the {$PackageName} and then {$ClassName}, so mine would be com.codeleakers.extr3m3.Main - notice the correct capitalisation is required. A version number is always a useful addition, especially if you look to share your plugin, in which case it's also wise to add yourself as the author and credit anyone else that may have helped. You can also add your website, if you have one.

    There are a range of items you can put in the plugin.yml file and here is a list http://wiki.bukkit.org/Plugin_YAML.

    /////////////////////////////////////////////////////////////////////////////////////////////


    0 Not allowed! Not allowed!
    Last edited by Bot; 06-14-2013 at 12:14 AM.








  2. #2
    Bot Bot's Avatar
    Join Date
    Aug 2011
    Posts
    2,671
    Points
    7,720
         User Info     Contact     Gamer ID
    Join Date
    Aug 2011
    Posts
    2,671
    Points
    7,720

    0 Not allowed! Not allowed!
    Last edited by Bot; 06-13-2013 at 10:05 PM.








Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -10. The time now is 06:33 AM.
Powered by vBulletin®
Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.