Blogs Tutorial

[Plugin tutorial] [BASICS]

  • 1,645 views • 2 today
  • 13
  • 3
  • 18
SugarrCraft
Level 34 : Artisan Modder
38
Hey! Its sugar, and I'll be showing you how to create your first plugin!
[I have spent a lot of time on this, and diamonds are always appreciated.]

[What you need]

1. Download Eclipse IDE. You can find it here: www.eclipse.org/downloads/

2. Download the latest version of bukkit. You can find it here: www.dl.bukkit.org/

[Setting it up]

1. I assume you set up eclipse already.

2. Create a new project. [CTRL + N]

3. Choose java project.

4. Name it whatever.. I'll be naming it MyFirstPlugin

5. Now right click the java project.

6. Go select Build Path > Configure Build Path

7. Go to libraries.

8. Then click 'add external jars'.

9. Go to your downloads, or wherever your craftbukkit is.

10. Now, click on 'src' and add a package.

[VERY IMPORTANT] 11. Now do new > package. For your package name it me.yourname.pluginNAME [ caps don't matter]

12. Add a new class. Name it whatever, I just use main as the name. [THAT RYHMES?!]

[Coding!]

Wooh! You didn't quit yet! Well, now for the fun part.

Now your class should look a bit like:

package '
name'

public class Main {

}

Now you will add extends JavaPlugin .

Hover your mouse over the 'JavaPlugin' and import it.

[PRO TIP]: ONLY IMPORT BUKKIT !

Now, add

public final Logger logger = Logger.getLogger("Minecraft");


[EXPLANATION] Ever saw a console log? How it says [Plugin] is now enabled! and such? Well, this is basically allowing you to do that for your plugin.

Okay. Now things are getting more complex.

Now, go down about 1, or 3 lines. Add
public void onEnable() {
logger.info("PLUGIN IS NOW ENABLED");
}

public void onDisable() {
logger.info("PLUGIN IS NOW DISABLED ");
}

[EXPLANATION]
The logger.info(""); is from what we added before. The public final. This displays [PLUGIN IS NOW ENABLED] or vice versa, to the console.

Okay. Now adding commands.

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

return false();
}

To be honest, If you know java, you know what this does..

Okay! Now adding the commands!
public boolean onCommand(CommandSender sender, Command command, String commandlabel, String[] args) {
if(sender instanceof Player)
{
Player player = (Player)sender;

}
}
return false;
}
}
[EXPLANATION]
Okay! Now this will add /hello to the server. It also checks if the sender is a player. If its the console you'll get a error. You may need to import all of that.

Now, we want to send them a message when they type /hello.


public boolean onCommand(CommandSender sender, Command command, String commandlabel, S
tring[] args) {
if(commandlabel.equalsIgnoreCase("hello")){
if(sender instanceof Player)
{
Player player = (Player)sender;
player.sendMessage(ChatColor.GOLD + "Hello!")
}
}
return false;
}
}

Okay! Good job. Now, the sendMessage is sending the player a message. It also is adding gold.

Else statement.

public boolean onCommand(CommandSender sender, Command command, String commandlabel, String[] args) {
if(commandlabel.equalsIgnoreCase("hello")){
if(sender instanceof Player)
{
Player player = (Player)sender;
player.sendMessage(ChatColor.GOLD + "Hello!");

}
}
}
return false;
}
}


Now it should work. Next time I update this Ill tell you how to export this plugin.

1 Update Logs

Update #1 : by SugarrCraft 03/16/2013 9:44:35 pmMarch 17, 2013 @ 1:44 am UTC

Fixed " 1. Download eclipse. You can find it here: www.eclipse.org/downloads/ "
Its now: " 1. Download Eclipse IDE. You can find it here: www.eclipse.org/downloads/ "

  Have something to say?

gabe4356
07/27/2014 8:00 pm
Level 53 : Grandmaster Blob
Either I missed it (which I don't think so) or you forgot about the Plugin.yml
1
supersant15
03/19/2013 7:31 pm
Level 8 : Apprentice Warrior
your awesome sugar
1
suger
03/17/2013 8:16 am
Level 4 : Apprentice Miner
Cool Diamond nice work :]
1
SugarrCraft
03/17/2013 8:36 am
Level 34 : Artisan Modder
Thanks! but.. your name..
1
suger
03/17/2013 11:12 am
Level 4 : Apprentice Miner
Ya Sweet
1
goreae
03/17/2013 5:48 am
Level 21 : Expert Farmer
actually, this section is only for released mods, not tutorials. I would just go ahead and copy/paste this post into a new blog post.

good job on this, though! :)
1
SugarrCraft
03/17/2013 7:55 am
Level 34 : Artisan Modder
Oh! Ill go change it to a blog now.. Thank you!
1
browniepownder2
03/17/2013 12:16 am
Level 1 : New Miner
I SAW THIS ON YOUTUBE WOW YOU FUCKIN STOLE THIS, DELETE OR GET BANNED, ADMINS HERES LINK FOR PROOF HE STOLE THIS

www.youtube.com/watch?v=FsWnSm3N7FA
1
goreae
03/17/2013 5:45 am
Level 21 : Expert Farmer
just go away. Seriously. Nobody is going to subscribe to your idiotic channel because you claimed someone stole something. get a life, asshat.
1
SugarrCraft
03/17/2013 7:56 am
Level 34 : Artisan Modder
Thanks! The video was inappropriate, also.
1

Welcome