In This EpisodeWe are going to start working on permissions, and how you can prevent players from using their commands unless they have the correct permissions. We are going to add permissions to our "/hello" command and our "/tellme" command. Bukkit Development Skills (this episode): - Adding permissions to our commands - Making parent permissions for other permissions Step 1So we are going to start off in the plugin.yml file, so we can specify all our permissions in there. Here is our previous plugin.yml from episode 2 (Tutorial2) name: Tutorial2 Now we are going to add the permissions. In case you don't know already, permissions are normally made like this: <plugin name>.<command>.<optional stuff>.<optional stuff> This is not required. This is just the way most people make it to keep all permissions together. Like when they're making parent permissions, they usually do <name>.<command>.*, which gives them full permissions for all features of their command. You can have your permissions any way you want, it is just recommended this way (they usually have atleast 1 dot). name: Tutorial3 As you can see above, we created a new section in the plugin.yml called "permissions". Under this, we created our 2 permissions: tutorial3.hello (for our /hello), and tutorial3.tellme (for /tellme). Under that, you will notice some things: default > either true, false, or op. If true, it gives all players the permission by default. If op, it gives only ops the permission, unless the permission is given to other users. If false, no one has the permission by default, and you have to give it to the player to use (including ops) description > The description of the permission (optional) Plugin.yml Help: http://wiki.bukkit.org/Plugin_YAML The link above gives you A TON of more information about every aspect of the Plugin.yml file. Step 2Now that we added the permissions to the plugin.yml file, we can add them to our code. Here is our previous code for /hello: if (cmd.getName().equalsIgnoreCase("hello")){ Now we are going to insert our permission check right underneath the check for the command. I will explain it below: if (cmd.getName().equalsIgnoreCase("hello")){ Okay, so right up there, we are checking: if the CommandSender named sender DOES NOT (as in the "!") have the permission: "tutorial3.hello", then run the following. We said (as "the following") to send the sender a message saying "Oh No! You do not have permission to run this." Then we returned it. Step 3Now lets do the same thing with /tellme: if (cmd.getName().equalsIgnoreCase("tellme")){ There we go! Step 4Now we will work on parent permissions: (plugin.yml): permissions: Basically, what we did up there is we created a new permission called "tutorial3.*". We made this permission give access to all our commands (/hello and /tellme). We added the "children" of the permission, making the permission itself a parent. After the permission (under the children), you can have "true" or "false" true > yes, this permission is a child to tutorial3.* false > no, even though the permission is listed, it is not a child to tutorial3.* The permissions (children) will work by themselves as well as working with tutorial3.* Step 5Export the Jar File and run your server! You're done! The EndYou learned how to make permissions! Next Episode is coming soon! Did I make any problems? Comment below! (I hope I didn't) Have any suggestions for future episodes (want to learn something else)? Comment below! Wanna talk? Comment below! FINAL CODE (Tutorial3.java): http://pastebin.com/R7MKaJ8q
0 Comments
Leave a Reply. |
|