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

Using permission nodes throughout your plugins


In some cases, you may want to check whether a player has a specific permission from within your code. With the addition of a universal permission system within Bukkit, this is very easy, regardless of the permission plugin that you are using. Looking at the Bukkit API documentation, you will see that the Player object contains a hasPermission method, which returns a Boolean response. The method requires a string value, which is the permission node that is being checked. We can place this method in an if statement, as shown in the following code:

if (player.hasPermission("enchanter.enchant")) {
  //Add a level 10 Knockback enchantment
  Enchantment enchant = Enchantment.KNOCKBACK;
  hand.addUnsafeEnchantment(enchant, 10);
  player.sendMessage("Your item has been enchanted!");
} else {
  player.sendMessage("You do not have permission to enchant");
}

This block of code is unnecessary for the plugin because Bukkit can automatically handle player...