Book Image

Building Minecraft Server Modifications - Second Edition

By : Cody M. Sommer
4 (1)
Book Image

Building Minecraft Server Modifications - Second Edition

4 (1)
By: Cody M. Sommer

Overview of this book

Minecraft is a sandbox game that allows you to play it in any way you want. Coupled with a multiplayer server powered by Spigot, you can customize the game even more! Using the Bukkit API, anyone interested in learning how to program can control their Minecraft world by developing server plugins. This book is a great introduction to software development through the wonderful world of Minecraft. We start by instructing you through how to set up your home PC for Minecraft server development. This includes an IDE complete with the required libraries as well as a Spigot server to test on. You will be guided through writing code for several different plugins. Each chapter teaches you new skills to create plugins of increasing complexity, and each plugin adds a new concept of the Bukkit API By the end of the book, you will have all the knowledge you need about the API to successfully create any type of plugin. You can then practice and build your Java skills through developing more mods for their server.
Table of Contents (17 chapters)
Building Minecraft Server Modifications Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a BukkitRunnable class


We will start by creating the AlwaysDay plugin. The code that we will write for this plugin will be put inside the onEnable method. The first step to creating a scheduled task is to create a BukkitRunnable class. This class will comprise very few lines of code. Therefore, it is not necessary to create a whole new Java file for it. For this reason, we will create a class within the onEnable method. This can be done using the following line of code:

BukkitRunnable runnable = new BukkitRunnable();

Normally, this code would be valid since you are constructing a new instance of a class. However, BukkitRunnable is an abstract class, which means that it cannot be instantiated. The purpose of an abstract class is to provide some base code that other classes can extend and build on top of. An example of this is the JavaPlugin class. For each plugin that you created, you started with a class that extends JavaPlugin. This allows you to override methods, such as onEnable...