Exploring the Bukkit API

Now that you are familiar with the Bukkit API documentation, I advise you to look through it on your own. You will find interesting methods; many of these methods will spark ideas for cool plugins that you may want to make. Note that there may be additional links to view more methods for an object. For example, a Player is a type of LivingEntity. Therefore, you can call a LivingEntity method on a Player object. This inheritance is shown after the method summary, as shown in the following screenshot:

Exploring the Bukkit API

If you are ever going to try and think up an idea for a plugin, browsing through the API documentation will surely give you some ideas. I suggest reading the class pages, listed as follows, as they will be the classes that you will frequently use in your future plugins:

Class

Package

Description

World

org.bukkit

A world on the server

Player

org.bukkit.entity

A person who is playing on the server

Entity

org.bukkit.entity

A player, mob, item, projectile, vehicle, and so on

Block

org.bukkit.block

A specific block in the world, such as a dirt block or a chest

Inventory

org.bukkit.inventory

The inventory of a player, chest, furnace, and so on

ItemStack

org.bukkit.inventory

An item that is in an inventory, which includes how many items are present

Location

org.bukkit

The location of an entity or a block

Material

org.bukkit

The type of a block or item, such as DIRT, STONE, or DIAMOND_SWORD

Bukkit

org.bukkit

Contains many useful methods that can be called from anywhere in your code

Now that you understand how to read the Bukkit Java documentation, you can find answers to the various questions that you may have. For example, what if you want to find out which methods you would call to get the Block that is at x:20 y:64 z:14 in the world that is named "world"?

First, you will need to retrieve the correct World object. The initial place that you may check is the Bukkit class, as listed in the previous table. You may check there because you can call these methods from anywhere in your code. Another option is to view the uses of the World class. This can be done by clicking on the Use link at the top of the World page. There, you can see all the methods that return a World object as well as methods that accept a World object as a parameter. To aid in searching through a page, remember that you can use Ctrl + F. Searching for name will lead you to the Bukkit.getWorld method, which takes the name of the world as a parameter and returns the actual World object.

Once you have the World object, you will want to find a method that will give you the Block at a specific location. You could navigate to the World page and use Ctrl + F to search for block, location, x, y, or z. If none of these help you find a useful method, then you can always view the uses of Block in a way that is similar to how we viewed the uses of World. Either way, you will find the World.getBlockAt method, which can be called on the World object that you discovered in the previous step.

The following are a few additional challenges to guide you while exploring the Bukkit API on your own and becoming familiar with it:

  • Which method would you call to check what time it is in a world?
  • Which methods would you call to send a message to the player whose name is Steve?
  • Which methods would you call to check whether the material of a block is flammable?
  • Which method would you call to check whether a player has diamonds in their inventory?
  • Which methods would you call to check whether a player is holding an item that is edible?
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.220.120