Players not recieving permissions when assigning?

Discussion in 'Plugin Development' started by IkeVoodoo, Oct 19, 2020.

  1. Offline

    IkeVoodoo

    Hello! i am trying to make a simple permission manager, and i ran into an issue:

    when assigning a permission to a player it dosent register, the player yet does not have the permission, i am doing:

    PermissionAttachment attach = player.addAttachment(Main.getInstance());
    permissionAttachments.put(player.getUniqueId(), attach);
    attach.setPermission("chat.staff", true);

    why isen't that working? or am i missing something?
     
  2. Offline

    Strahan

    Are you storing that attach object anywhere? Otherwise, once whatever method you are creating it in terminates, the object will be discarded.
     
  3. Offline

    IkeVoodoo

    Yes, i am storing in a HashMap<UUID, PermissionAttachment> permissionAttachments = new HashMap<>();

    I have seen many guides using it, and figured it had to be stored (unless returned then stored)

    should i do p.recalculatePermissions(); ?
     
    Last edited: Oct 19, 2020
  4. Offline

    Strahan

    Ah yea, now that I re-read your post I see you putting it in the map. Hmmmm. That should work. Actually, I was just testing it because I wasn't sure if it will work seeing as how you aren't getting it from the map in that code and realized that I was wrong; the map is superfluous. I always thought the attachment had to persist, but apparently I was in err. I tested it with:
    Code:
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
      Player p = (Player)sender;
      switch (label.toLowerCase()) {
      case "cmd1":
        PermissionAttachment attach = p.addAttachment(this);
        attach.setPermission(args[0], true);
        break;
      
      case "cmd2":
        p.sendMessage("You do " + (p.hasPermission(args[0])?"":"not ") + "have the permission " + args[0]);
        break;
      }
      return true;
    }
    ...and it worked fine. Learn something every day lol. I did /cmd2 blah and it said I did not have perm blah. Then I did /cmd1 blah then /cmd2 blah again and it said I did. Even persisted across a /restart.

    Sooooo, yea, no idea, sorry. That works fine for me so it should be working.
     
  5. Offline

    IkeVoodoo

    Thanks for your help, i will try do that in a command (i made myself an handler for this, i don't know if that is the problem)
     

Share This Page