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