Resource [Tutorial] How To Make a Plugin

Discussion in 'Spigot Plugin Development' started by M7MDMCGamer, Apr 28, 2017.

  1. this simple tutorials will give you some basics, we will make a plugin that when type /hi it say to you hello in green
    NOTE: if you don't know java learn it by this good tutorial

    First Thing Download:

    JDK for compile plugin:
    Windows 64Bit exe file 198MB
    Windows 32Bit exe file 191MB
    Linux 64Bit tar.gz file 175MB
    Linux 32Bit tar.gz file 179MB
    Mac OS X dmg file 226MB
    Eclipse for typing plugin:
    Windows 64Bit zip file 161MB
    Windows 32Bit zip file 161MB
    Linux 64Bit tar.gz file 160MB
    Linux 32Bit tar.gz file 160MB
    Mac OS X tar.gz file 160MB
    And download spigot.jar

    after setup jdk open eclipse

    right click and click on "New Java Project"

    Screenshot_1.png
    name it anything then click next Screenshot_2.png click on "Libraries" tab and click on "add External jars" and go to your spigot.jar then click finish
    Screenshot_3.png
    right click on small triangle next your project name
    Screenshot_4.png
    right click on "src" click on new then click on Package
    Screenshot_5.png
    name the package me. and after the . type your minecraft name example if your minecraft name is steve you will type me.steve and remove the tick from "Create a package-info.java" then click finish
    Screenshot_6.png
    right click on your package and click new then click on class
    Screenshot_7.png
    name it anything then click finish
    Screenshot_8.png
    here we will start coding
    first we need extend spigot.jar
    Code (Text):

    package me.m7mdmcgamer;

    public class Main extends JavaPlugin {

    }
     
    is JavaPlugin is underlined with red ? dont worry its normal because you didnt import it pres ctrl+shift+O in same time

    there is a method called onEnable you can type in it any code you want it run when plugin is enabled and there is onDisable like onEnable but when plugin disabled
    we want when plugin enabled plugin say in console "Plugin Has Been Enabled" and when disabled "Plugin Has Been Disabled"

    first lets type on enable and on disable methods
    Code (Text):

    package me.m7mdmcgamer;

    public class Main extends JavaPlugin {

    public void onEnable(){
       //here code you want run when plugin enabled
    }
    public void onDisable(){
       //here code you want run when plugin disabled
    }

    }
     

    now we will add the command

    we need a method called onCommand lets add it
    Code (Text):

    package me.m7mdmcgamer;

    public class Main extends JavaPlugin {

    public void onEnable(){
       //here code you want run when plugin enabled

    }
    public void onDisable(){
       //here code you want run when plugin disabled
       
    }
    public boolean onCommand(CommandSender sender,Command cmd,String label,String[] args){

    }
    }
     
    now we need to add the command
    Code (Text):

    package me.m7mdmcgamer;

    public class Main extends JavaPlugin {

    public void onEnable(){
       //here code you want run when plugin enabled

    }
    public void onDisable(){
       //here code you want run when plugin disabled

    }
    public boolean onCommand(CommandSender sender,Command cmd,String label,String[] args){
       if(cmd.getName().equalsIgnoreCase("hi")){
     
        return true;
       }
    }
    }
     
    our command is hi you can make it anything you want
    now we made the command but it will not work because we didnt type what to do when command used
    Code (Text):

    package me.m7mdmcgamer;

    public class Main extends JavaPlugin {

    public void onEnable(){
       //here code you want run when plugin enabled

    }
    public void onDisable(){
       //here code you want run when plugin disabled

    }
    public boolean onCommand(CommandSender sender,Command cmd,String label,String[] args){
       if(cmd.getName().equalsIgnoreCase("hi")){

         sender.sendMessage(ChatColor.GREEN + "Hello!");
         return true;
       }
    return true;
    }

    }
     
    sender is the person that typed the command
    and you can repeat this for more commands
    Code (Text):

       if(cmd.getName().equalsIgnoreCase("hi")){

         sender.sendMessage(ChatColor.GREEN + "Hello!");
         return true;
       }
     
    "hi" is the command name you can make it anything
    "hello" is the message that will be sent it can be anything
    now we made the command but we need to do 1 thing now

    right click on project name click on new then click on file
    Screenshot_9.png
    then name it "plugin.yml" then click finish
    add in it
    Code (Text):

    name: PluginName
    main: me.m7mdmcgamer.Main
    version: 1.0
    commands:
        hi:
          description: hello
     
    main: is your main class path

    then export it and put it in your plugins folder in server
     
    #1 M7MDMCGamer, Apr 28, 2017
    Last edited: Apr 28, 2017
    • Funny Funny x 1
  2. Try using code blocks to make it more readable!
    Code (Text):
    package me.m7mdmcgamer;

    public class Main extends JavaPlugin {

        public void onEnable(){
             //here code you want run when plugin enabled
        }

        public void onDisable(){
             //here code you want run when plugin disabled
        }

    }
     
  3. There are already other well written guides on how to make basic plugins.
     
    • Agree Agree x 2
  4. Helpful! But you could have shown what to write in the plugin.yml. Also, you could have explained a bit more what you do at every step instead of just writing one sentence saying only what it will do, for example, you could have given an example of what to write at onEnable.

    Also as @JasperJH mentioned, you could have used code blocks to make it easier to read.
     
  5. Should you not teach people to use the @Override annotation and your plugin.yml is messed up, this may be because of formatting not being in a code-block.

    Other than that, you should also add something about learning to use the Javadocs, Also it's good you used the ChatColor enum.

    You were able to tell people about how to make a plugin, but you did not explain why it works or describe what you have done. This means that readers will copy and not learn well.
     
  6. "typing plugin", it's called an IDE.
     
  7. *Slams head against the wall*
    TheNewBoston? Really?
    The code you spoonfed doesn't even do that.

    Overall, the tutorial is useless even if we ignore the terrible way you speak. Not trying to be mean.
     
    • Agree Agree x 3