Minecraft Blogs

Creating Bukkit plugins part 3 - Multiple commands + Events

  • 3
  • 1
  • 3
avatar gabe4356
Level 51 : Grandmaster Blob
Ok, so in part 3, I will show you how to add more than one command, and add Events. I will show you how I did my thor plugin basicly, I used the event to call down lightning when the player right clicks with the thor hammer (a diamond axe) and they receive a thor hammer when they type /thor. Shall we get started?

So lets continue from where we left off in the last tutorial, where we added the command. Lets add another command
DO NOT EVER EVER add (and I mean ever) another onCommand meathod, just do this:
Code - New Command

That is what the code should look like now. All you have to do to add another command is just add this below the previous command and the previous }
Adding another command

That tests if the player typed the command "Alist" as well as if they typed the command above, if you add another on Comand method, it won't work. And you have to have the '{' bracket below the first command, or else it won't work. it closes the previous '{'

Now that you know how to add more than one command ,lets move on to adding and registering an event.

To add the event, paste this above you onCommand method

Code - Event

That calls an event of lightning striking down when the player right clicks with a diamond axe, it also plays the sound of an enderdragon getting hit when he uses it. It also damages the player (player.damage(5);) when they use the Diamond axe. the Player player = event.getPlayer(); gets the player who used the diamond axe, then executes the red of the event. Now right now, that will not do anything, we still need to register it in the onCommand method, so now you paste this under the onCommand meathod

Code - Register event
Now, there will be an error, to fix the error, he have to implent listener, so at the top, do this: If we do not implent the listener, then the plugin will not know when to register the event, or how to call the event, so now we implent the listener:
Code - implenting listener
You have to put that right after "public class YourClassNameHere extends java plugin"
So now it should look like this:
Code: Implenting Listener

Final Code:

Final Code

Now you can have fun changing the event to what-ever, and whatnot. Please do not copy my Thor Plugin and re-post it.

If you have any questions, or suggestions, either PM me, or comment them.
 Click me to go to part 4!

1 Update Logs

Update #1 : 09/02/2014 3:56:45 pmSep 2nd, 2014

.Made everything a bit more clear

09/02/2014 3:55 pm
Level 25 : Expert Mountaineer
You have to be very broad when talking about plugin creation because as to newcomers most teachers fail to explain why for most things.  Assume you were a young chap and wanted to learn with little to no experience in plugin creation (the majority of minecrafters).  You wouldn't know what an event is and why would you use one and what "implementing listener" is and why we need it.  Good luck though and sorry but how do you reply lol < nvm on my phone I see now
09/02/2014 3:45 pm
Level 25 : Expert Mountaineer
This could be quite useful, though you should explain each set of codes more clearly so I know everything we're doing and why.  Otherwise all I'm learning is that I can remember how to copy.
09/02/2014 3:51 pm
Level 51 : Grandmaster Blob
Ok, I tried to make it clear, but I will edit it and try to make it more clear I suppose, what exactly do you think is not clear?
Planet Minecraft Logo


© 2010 - 2020