Minecraft Plugins 1: HelloMinecraft

Planning
Step 1
Planning
Step 2
Here is a demonstration of the plugin we are going to be making in this lesson:

You will be able to type the command /hello to print the message "Hello!" in blue font.
Right-clicking on a chicken will result in the message "Hello my name is Bob the Chicken!"

Step 3
Fill in your plugin.java file with the following code.

The "onEnable" method will be called (activated) when the server is started. This plugin will simply print "Server Started!" to the console when we start the server.

Step 4
Make sure you click the save button at the bottom!
Step 5
Fill in the plugin.yml file with the following:

The plugin.yml file contains basic information about the plugin including the name, version, and path to the main java class that contains the content of the plugin.

Step 6
Remember to save!
Step 7
When you are finished, click the button at the top that says "Compile"
Check Your Work
Step 8
When the compiling is complete, you should see this on the right side of your screen.

If you have errors in your code, ask an instructor to help you address them.

Step 9
When your code has compiled successfully, click the button at the top that says "Deploy"
Step 10
If it asks if you are sure, click "OK"
Check Your Work
Step 11
If it has been deployed to your server successfully, you should see this message at the top of your page.
Check Your Work
Step 12
When you start your server you should see "Server Started!" in the console right after the plugin is enabled!
Step 13
Return to your plugin.java file and add the following method as shown:

This method will allow the player to type "/hello" in-game and have it print the message "Hello!" in blue text!

The "onCommand" method is called when a command is entered either in-game or in the server's console. We will take a closer look at what is happening here in the next step.

Information
Step 14
Take a moment to read about the four parameters taken by the onCommand method.
Step 15
Add these lines to plugin.yml

IMPORTANT: Line 5 is "SPACE SPACE hello:" and Line 6 is "SPACE SPACE SPACE SPACE description...."

Step 16
Remember to save your files constantly!
Step 17
Click the button that says "Compile"
Check Your Work
Step 18
When your code is finished compiling, you probably have some errors!

We are getting these errors because we need to import the tools from bukkit that we are using in this plugin.

Step 19
Add these lines of import code to your plugin.java file.
Step 20
Click "Compile" and make sure you don't have any other errors in your code.
Step 21
Once your plugin code has compiled, deploy it to your server.
Step 22
Open Minecraft and connect to your server.
Step 23
When you are connected to the server, type "/RELOAD"
Step 24
Then type "/hello"
Check Your Work
Step 25
You should see "Hello!" printed in blue!
Step 26
Try to type the "hello" command into the console and you will see that this causes a lot of errors!
Step 27
Make the changes you see in the red box to your plugin.java file.

This code will check to see if the sender of the command is a player in-game or a user typing the command into the console.

If the sender is a player, it will do the standard blue "Hello!" message.

If the sender is not a player, it will print "Hello from the console!" in the console.

Check Your Work
Step 28
Type "hello" into your server's console to test. You should see "Hello from the console!" printed in the console log.
Step 29
Now let's add the code for the message that is displayed when we right-click on a chicken.

When the player interacts (right-click) with something, it will check to see if the entity interacted with is a chicken. If it is, it will send the player the message "Hello my name is Bob the Chicken!"

Step 30
Save your file, compile your code, and then deploy your updated plugin!

NOTE: If you have errors when you click "Compile" try to fix the errors or ask an instructor for help!

Step 31
In-game, type "/reload" to reload the updated plugin on your server.
Check Your Work
Step 32
You should now be able to right-click on chickens and see a message!

Congratulations, you just finished your first Minecraft plugin!

Challenge
Step 33
CHALLENGE: Add a new command "/goodbye" that displays "Goodbye!" in red, and make a different animal say something!
Planning
Step 34
In the next lesson we will make the chickens explode when they are hit by arrows!

Try one of these lessons next:

Minecraft Plugins 1: HelloMinecraft Info

Account

MVCode

Created By

aaron

Access Level

public

For Teachers and Schools

Teach coding to your students with MVCode Teach

MVCode offers an integrated product designed to teach coding to students.

Learn more about MVCode Teach