Using permission nodes throughout your plugins
In some cases you may want to check if a player has a specific permission from within your code. With the addition of a universal permission system within Bukkit, this couldn't have been easier. Looking at the Bukkit API docs, we can 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 similar to the one 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 items "); }
This block of code is unnecessary within our plugin because Bukkit can automatically handle player permissions for commands. To see a proper...