Solved Need Help with Permissions

Discussion in 'Plugin Development' started by MrGamingLion66, Dec 19, 2016.

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

    MrGamingLion66

    Hey everyone, on my friend's server he wanted me to make ranks for him. So, I create the permission bellow for the owner rank.

    Code:
    public static Permission owner = new Permission("owner");
    My problem is that I don't know how to give this permission to certain players and that I don't know how to stop ops from auto receiving it. Can anyone help?
     
  2. Offline

    Orange Tabby

    Last edited: Dec 19, 2016
  3. Offline

    MrGamingLion66

    @Orange Tabby
    I just read through the tutorial you sent me and I found some parts a little confusing so, I would like to ask a few clarifying questions.

    So I would make an attachment like so:
    Code:
    PermissionAttachment ownerAttachment = player.addAttachment(plugin);
    Then I would assign my permission to the attachment:
    Code:
    attachment.setPermission("owner", true);
    Then I would create a hashmap:
    Code:
    public static HashMap<UUID, Permission> ranks = new HashMap<UUID, Permission>();
    Then I add the player and their attachment:
    Code:
    ranks.put(p.getUUID(), ownerAttachment);
    This is what I got from the tutorial. Is there anything else I need to add or anything I'm doing wrong?
     
    mythbusterma likes this.
  4. Offline

    mythbusterma

    @MrGamingLion66

    Definitely remove the "static" keyword there, but you're on the right track.
     
    MrGamingLion66 likes this.
  5. Offline

    MrGamingLion66

    @mythbusterma @Orange Tabby
    Okay, I'm have trouble creating the plugin variable, this is what I've used in the past but I don't think it is working right now.

    Code:
    public static CrimsonCentralMain plugin;
     
  6. Offline

    CreeperFace0777

    Make sure you make a constuctor class for your class file so it obtains the plugin var once the class has been called. And once again the static modifier isn't necissary
     
  7. Offline

    MrGamingLion66

    @CreeperFace0777
    Thanks that worked! Sorry about the static modifiers I put them there so that I can access them across multiple classes. However, I have a new problem now. I'm trying to create a command so I can set someone to the owner rank. However, I'm having problems with the arguments.

    Code:
    if(cmd.getName().equalsIgnoreCase("ccr"))
            {
                if(args.length == 0)
                {
                    player.sendMessage("Not enough arguments!");
                }else if(args.length == 1){
                    player.sendMessage("Not enough arguments!");
                }else if(args.length == 2){
                    player.sendMessage("Not enough arguments!");
                }else if(args.length == 3){
                    Bukkit.broadcastMessage("test");
                    String s = args[1];
                    String pl = args[2];
                    String permission = args[3];
                    Bukkit.broadcastMessage("test");
                   
                    if(s != null && s.equals("set"))
                    {
                        if(Bukkit.getPlayer(pl) != null)
                        {
                            Player plr = Bukkit.getPlayer(pl);
                            if(pr == "Owner")
                            {
                                PermissionAttachment ownerAttachment = plr.addAttachment(this);
                                ownerAttachment.setPermission(Ranks.owner, true);
                                ranks.put(plr.getUniqueId(), ownerAttachment);
                            }
                        }
                    }
                }
            }
    It says: java.lang.ArrayIndexOutOfBoundsException: 3
    Can anyone help?
     
  8. Offline

    Zombie_Striker

    @MrGamingLion66
    You are reaching an index that does not exist. You have to remember this length is not the same as index. If the length is 3, that means there are 3 objects in the array, but the last index is 2. The first index is equal to 0 instead of 1, so every time you access an arg, subtract one from the number,

    Example, change this
    to
     
  9. Offline

    MrGamingLion66

    @Zombie_Striker
    Thanks for the reminder! It works great now. Thanks to everyone else for their help!
     
Thread Status:
Not open for further replies.

Share This Page