Blogs Tutorial

Bukkit Plugin Tutorial 3: Getting the commands right.

  • 1.2k views 0 today
  • 8
  • 6
  • 1
evilguy4000
Lvl 33Artisan Modder
33
Hello dear PMC'ers,
Its evilguy4000 again with another bukkit plugin tutorial. Today I'm going to learn you something about making commands for your plugin. This is rather simple, but you still need to keep your head with all the coding e are going to do today.

Things you will need:

1) Eclipse with the Java Project of last Lesson.
2) An idea of a command you want.
3) Some Paper and a pencil. (optional, but I highly suggest it.)

Let's get started:

So we are going to get started with making a scheme of all the commands we are going to make today. I'll give you an example of one off the schemes I made for the plugin I'm working on these weeks.

qLaZyIpng

Now you can make succh a paper like I did or you can think of your own manner. I do this and I keep them stored in my file cabinet so I keep track of all my Plugins. You can always ask me for help with these.

1) Making the method where we declare our commands. Because it are commands it will be a public Boolean method. We are going to give this method the name onCommand. Then we are going to declare all the things we are going to need and that are (CommandSender s, Command cmd, String label, String[] args). It will look something like this now.

ZoiVSdwpng

You see now that it gives an error message even with my code and that's because we didn't add a return statement. We'll do that by adding return true; in the method. Now it looks something like this.

noxAMJpng

2) Now that this is done we can start with making our very first command. For this tutorial I'm going to make the command print a line that says the Plugin works. To do this we will need an IF statement. If statements will only preform the given action if the conditions between the brackets are fulfilled. And with this plugin the command will be /Test. So the code between the brackets will check if the text of the command is Test. So The code will be. cmd.getName().equalsIgnoreCase("Test"). One important thing to remember is that all this code needs to come before the return statement. If you have done that correctly your code will look something like this.

AnDQhcXpng

3) Now we will make it so that the command prints out It works. This all needs to be done inside of the if statement. To say it in a short way that message needs to be send to the CommandSender so we are going to start with s. and then we need to send a message to him and there is nothing more easy. So you get s.sendMessage() and between the brackets comes the message between quotation Marks. So you will get something like this.

XahzBNpng

4) You can also change the color of that text by adding chatcollors. I'm going to make the text Red so it's more visible and you need to type ChatColor.RED + "It Works!" So your code would look something like this. Ofcourse you can also make it any color you want.

eyglpng

5) And that's all that needs to be done to the programming of the commands. If you want other actions to be done you can find out by searching and trying or you can even ask me. This are the basics of the commands and now for the plugin to work we need to add this command to the plugin.yml file. I'm just going to give you the code for in the file because I still have problems with that file, I hate it :3.

name: PMC_Tutorial
main: me.evilguy4000.PMC_Tutorial.PMC_Tutorial
version: 0.0.1
commands:
Test:
description: prints out a line.

In your plugin.yml File it would look something like this.

XJQuqipng

6) Now we are going to export our first plugin so we can use it on our server. Of course this is really simple. Before you can really export the file you need to refresh your Java project this is done by right clicking your project and click refresh. Otherwise you will get an error.

suTlEdcpng

7) Now you need to Right click your Project and you need to click export.

mOrYtxpng

8) Now a screen will open and you need to selcet the folder Java and then you need to select Jar file and Click next.

cthrhpmpng

9) Now you all you need to do is select the name and the place where your Jar needs to go, that can all be done with help of the Browse button and I hope you all know how to do that. and if that's finished you are ready to go. all you need to do is place the jar file in the plugins folder of your craftbukkit server and you start up the server and you are ready to go.

Wcvrrkpng

This was my third tutorial about Bukkit plugins and today we covered the commands. I'm going to keep saying that if there are problems or if you want to know something just ask me I'll help with pleasure.

Greetings,
evilguy4000.

More like this

  Have something to say?

OnlyIn5DYT
10/21/2013 10:52 pm
Level 39 : Artisan Architect
nice
1

Welcome