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, ...

Get Building Minecraft Server Modifications - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.