- 1,645 views • 2 today
- 13
- 3
- 18
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, String[] 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.
[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, String[] 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/ "
Its now: " 1. Download Eclipse IDE. You can find it here: www.eclipse.org/downloads/ "
1992228
6


Have something to say?
good job on this, though! :)
www.youtube.com/watch?v=FsWnSm3N7FA