Chapter 7. The Bukkit Event System
At this point, we know how to create a plugin that runs a code when a command is executed. This is very useful in many situations. However, sometimes we would rather not be required to type in a command. We prefer if the code could be automatically triggered to execute. The trigger could be a specific event that occurs on the server, such as a block being broken, a creeper exploding, or a player sending a message in chat. The Bukkit event system allows a developer to listen for an event and automatically run a block of code based on that event. Using the Bukkit event system you can automate your server, which means less work for you to maintain the server in the future. In this chapter we'll cover the following topics:
Choosing an event
Registering an event listener
Listening for an event
Canceling an event
Communicating between events
Modifying an event as it occurs
Creating more plugins on your own