Minecraft Blogs / Tutorial

Plugin tutorial 1.7.9!!

  • 367 views, 1 today
  • 1
  • 1
  • 1
Nickolous15's Avatar Nickolous15
Level 4 : Apprentice Miner
1
Hi, my name is Nick and I will teach how to code your own plugins!! Why should you read this: this will let you code your own plugins that is Essential for a popular server. Why choose this tutorial: I will be going over almost everything from bukkit in code and expance it the best I can. This blog will be a work in progress and I will work on it whenever I can. Let's get started!!!

Ok befoer we begin we must download 3 things (all are free :D )
Eclipse
Bukkit Developement Build
Java JDK (Just the JDK)

******Importent: most code is case-sensitive
*****after 2 slashes "//" the words on that line will not be read as code and the compuder will skip over, you do not need to type them.

Once you download them, launch eclipse the next part of the tutorial will be in "step form".
step 1: right click go to new-> then Java Project name it anything you like.
step 2: right click the project on the left hand side and click properdies at the bottem.
step 3: click Java build path and click libraries.
step 4: click add external JARS and open the Bukkit developement build.
This step added all the data of minecraft and servers and is the most important step. ^^^
step 5: click src and click new Class, in the package text box, write me.<your name>.Main and for the Class name write MainClass and click finnish.


Once you have compleated all of this, we can start coding!

To start after is Says "public class MainClass" write extends JavaPlugin. An error will apear (dont worry it will go away in a second). Next hover your mouse over the "JavaPlugin" and then Click import JavaPlugin. The error should be gone :D. Now we will write our onEnable and on Disable methods, which happen when the server starts and stop so go ahead and type:

@Override
public void onEnable(){
//everything in these 2 brackets will happen when the server starts
}

@Override
public void onDisable(){
//everything in these 2 brackets will happen when the server stops
}


Now that you have that what do you want to do when the server starts? Let's tell the owner that is has been enabled. to do this. We will add:  this.getLogger().info("Tutorial has been enabled!"); between the onEnable brackets{ } and this.getLogger().info("Tutorial has been disabled!"); between the onDisble brackets { } So now what do we need? Commands of corse! This method is long so for a shortcut click command + space (sorry don't know for a mac) and look for the onCommand method. it should look something like this:


@Override
public boolean onCommand(CommandSender sender, Command command,
String label, String[] args) {
// TODO Auto-generated method stub
return super.onCommand(sender, command, label, args);
}

We do not want the method to be this it will not work so change it to:

public boolean onCommand(CommandSender sender, Command command,
String label, String[] args) {

return false;
}

now that it looks like that, lets add a command however I woild just like to tell you what this all means:
CommandSender sender" this is the sender of the command, this is ether the player or the consol.
"Command command" this is the command itself however you do not use this too much.
"String label" this is used in every command because it is the name of the command this does not include the "/" before it. In java(the coding language we are using), "String" is letters while int is a number. **This is only the first word of the command the next words are the String[] args.
"String[] args" we will not be using this in this part, but we will later. This is the words that come after the first word in the command. however never have a command with spaces because it will not work without using these.

Ok I hope I explane that well I know this is a lot of imformation but this is all important. To add a comand we need to see if the command name matches the command name we want.
To to this, add:    


if(label.equalsIgnoreCase("givemepickaxe")){

}



if() statements are one of the most used lines in Java. This is saying if everything in the parentheses after the "if" is true, then  everything in the brackets { } after the "if" statement will be read and processed.

label.equalsIgnoreCase("givemepickaxe")

This means that if the command name(label) equals while ignoring caps(so a player could type /giVeMePICKaxe and it would still work)  the if() statement is true and the code inside will be read.

So what do we want to do? Give the player a picaxe of corse :D. So how do we do this? first we need to know what the player is, which is the sender. so write:


Player player = (Player) sender;


This means that A Player that we are calling "player" is a Player, that is the sender (from the onCommand() methode). xD 
no now we can do so many things to the player anything from sending them a message to banning them :) but for now we will send them a message and give them a diamond pic. To do this lets make an Itemstack for a diamond pic and send them a message.


ItemStack diamondpic = new ItemStack(Material.DIAMOND_PICKAXE);
player.getInventory().addItem(diamondpic);
player.sendMessage(ChatColor.GOLD+"Have a pickaxe!");


Alomost done :)

now for the plugin YML so click on you Java plugin folder rightclick and make a new file and name it plugin.yml

Everything in here is self explanatory accept for the "main:" part so just add everything below 

name:<the plugin name> Tutorial
main<this is you main class so first it is you package name then .MainClass> com.nickolous.main.MainClass
version: 1.0
description: >
                  The PMC tutorial on plugin making!
commands:
   givemepickaxe:
      description: gives the player a diamond pickaxe.


Thats it your done!!!!
To export it, right click the java project,and click export.
Add it to your plugin folder and your done!
Thanks for reading, more tutorials to come, if this helps you subscibe or give me diamond :)
See you in the next tutorial! I learned from the BCBroz's youtube channel, my brother who's a compuder scientist, and a few of my friends.

Next tutorial is out(CLICK ME :D)
CreditThe BCBroz Youtube Channel
Tags

Create an account or sign in to comment.

Nickolous15
06/09/2014 8:38 pm
Level 4 : Apprentice Miner
Nickolous15's Avatar
feel free to post any questions here
1
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome