Help with permissions!

Discussion in 'Plugin Development' started by SofaKin, Oct 7, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    SofaKin

  2. Offline

    Skionz

    Player#hasPermission(String);
     
  3. Offline

    SofaKin

    I know how to add permissions but I don't know where to put it.
     
  4. Offline

    teej107

  5. Offline

    Peter25715

    Hey SofaKin,
    In order you wanna learn how to add the permissions, Here's the way you do it.
    First you have to add the permissions in the class then in the Plugin.yml...

    1) CLASS;

    Code:java
    1. if (cmd.getName().equalsIgnoreCase("squishykick")) {
    2. if (sender.hasPermission("PermissionName")) {
    3.  
    4. //code here..
    5.  
    6. if (args.length == 1) {
    7. sender.sendMessage(ChatColor.RED + "Please specify a player!");
    8. return true;
    9. }
    10. Player target = Bukkit.getServer().getPlayer(args[0]);
    11. if (target == null) {
    12. sender.sendMessage(ChatColor.RED + "Could not find player " + args [0] + "!");
    13. return true;
    14. }
    15. target.kickPlayer(ChatColor.RED + "You have been kicked!");
    16. Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + "Player " + target.getName() + " has been kicked by " + sender.getName() + "!");
    17. }
    18. else if (cmd.getName().equalsIgnoreCase("squishyban")) {
    19. if (args.length == 1) {
    20. sender.sendMessage(ChatColor.RED + "Please specify a player!");
    21. return true;
    22. }
    23. Player target = Bukkit.getServer().getPlayer(args[0]);
    24. if (target == null) {
    25. sender.sendMessage(ChatColor.RED + "Could not find player " + args [0] + "!");
    26. return true;
    27. }
    28. target.kickPlayer(ChatColor.RED + "You have been banned!");
    29. target.setBanned(true);
    30. Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + "Player " + target.getName() + " has been banned by " + sender.getName() + "!");
    31. }else{
    32. sender.sendMessage("You dont have perms.. etc.");
    33. }
    34. return true;
    35. //You should know the rest here..
    36. }


    So the if (sender.hasPermission("PermHere") {
    means; If the sender of the command has the permissions to for the specified permission that you put then... Do the written code,

    2) Plugin.yml..

    Code:
    main: PackageName.ClassName
    name: PluginName
    version: 1.0
    description: description
     
    commands:
        commandname:
            usage: /<command>
            description: description
        commandNameAgain:
            #Usage Again..
            #Description Again..
            #You should know the rest, Btw this # thing is comment so it will not effect on code..
           
    permissions:
        permissionName:
            description: description..
           
        #if you have 2 or 3 or even 100 permissions or commands you should put them here.
          
    Hope I helped, Please reply if u got any error.
     
  6. Offline

    SofaKin

    Do I do the same thing for squishyban? Also, is putting permissions in the plugin.yml required?
     
  7. Offline

    Monkey_Swag

    SofaKin you have to make a permission check for every command. Unless you want any player on the server using the command. And yes, writing the permissions in your plugin.yml is necessary
     
  8. Offline

    teej107

    Monkey_Swag
    You can also register permissions dynamically but you shouldn't do that if you have a set amount of permissions. Which you do.
     
  9. Offline

    ToPoEdiTs

Thread Status:
Not open for further replies.

Share This Page