Creating Bukkit Plugins

Download Report

Transcript Creating Bukkit Plugins






Do you have Java JDK installed?
Do you have the latest bukkit jar file
installed?
Do you have Minecraft installed?
Do you have the github files installed?
Do you have the bukkit server files?



How to build a Bukkit plugin
How to find information about the API an
Java
How to make cheats and react to the game



A plugin for Bukkit is a jar file
A jar file is a zip file. Inside the structure of
the file corresponds to what Bukkit expects
It needs compiled Java code and a plugin.yml
file
javac -Xlint -classpath ../../craftbukkit.jar
Hello.java




Create the bin folder
Inside the bin folder, create Hello folder
Move Hello.class into this folder
Copy plugin .yml into bin
jar -cvf Hello.jar -C bin .

Copy Hello.jar and put it in plugins folder



Start bukkit
Start Minecraft
Type /hello bob



Now we are going to learn how to write
cheats
Cheats are Commands
A command is an order that you can type into
Minecraft via / command arguments

For a command to work you need
 The description of the command in the plugin.yml
 The code in your java file


This is a configuration file
It tells Bukkit
 the name of our module,
 its main class – the start up class
 what commands exist within your plugin



The onCommand event
Check for our command
Then call the method that executes the
command
Look at the code and try the different spells
How would you make your own?

Through the Bukkit API
Application
Programming
Interface


The API is like a dictionary to tell the
computer what to do
Each package is like a chapter in the
dictionary
The API is organized as a map of idea
What categories do we have?
 World
 Player
 Blocks
 Events



Think of what you would like to do
I want to change the whether!
Think of what category does it fall into
 Is it a player?
 A block?
 A World event?



Look at the packages. Click them
Look at what classes are within the package
Click on something like looks correct




Find out to what package it belongs so you
can import it correctly
In the method list, look for what you want to
do
Use the search function to find possible
methods
Remember that Java uses get() and set() as a
convention for changing values



Good libraries are consistent
If you found something related to Pigs under
entities, then other beings, like chickens,
should be under entities
The more you use the documentation, the
better you will get at finding what you need
Search following this convention
bukkit api <what you want to find out>
bukkit api player’s hunger


Seek out bukkit.org result and minecraft
forums results
Watch out for outdated information. Keep an
eye for bukkit versions and the dates




Build the Hydra plugin
Install it
Summon zombies through the “rise”
command
Fight it until you defeat it

Events are things that happen in the game
 Hitting a block
 Eating
 Waking up
 If-then code

If the event happens, then do this




We need an event listener
We need to use the annotation
We need to write the event function
You need to find the right event in the
documentation



Idea: when you kill a zombie, two will spawn!
Events: when a Zombie dies
Look in the API




I need them to respawn only when I kill them
Find the damage event
Set a variable
Modify our original event handler

Making changes by hand is boring. So I built
some scripts to automate the boring parts
away



Use it as ./new.sh <name>
It will create a template for a new plugin
You need to change every word that says
CHANGEME

It will compile, move the files, create a jar,
and move the jar to the plugin folder





Build tools
IDE for development
More Java
Bukkit services
Saving data