Help with Setting Permissions Individually

Discussion in 'Plugin Development' started by IAmUltimateHammer, Jun 21, 2019.

Thread Status:
Not open for further replies.
  1. Hello, I am currently working on a custom factions/teams plugin and I am running into some issues with applying permissions to players. I want to apply a default permission ("prefix.newarrival") when players first join that changes their display name, etc. Then, when players join a faction, say with the command /faction join red, I want the default permission to be removed, and the red faction permission to be applied ("prefix.red").

    I followed, to the best of my ability, the instructions on the following link:

    https://bukkit.gamepedia.com/Developing_a_permissions_plugin

    but I was only able to add any number of the permissions to the players on the PlayerJoinEvent.

    Code:
    public HashMap<UUID, PermissionAttachment> playerPermissions = new HashMap<>();
    Code:
    public void setupPermissions(Player player) {
            PermissionAttachment attachment = player.addAttachment(this);
            this.playerPermissions.put(player.getUniqueId(), attachment);
            permissionsSetter(player.getUniqueId());
        }
    
        public void permissionsSetter(UUID uuid) {
            PermissionAttachment attachment = this.playerPermissions.get(uuid);
           
            attachment.setPermission("prefix.newarrival", true);
           
            }
    And here is my PlayerJoinEvent code in a separate class:
    Code:
    @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            Player player = e.getPlayer();
            String playerName = player.getName();
            plugin.setupPermissions(player);
           
            //Chat Name Alterations Per Faction Membership\\
            String newArrivalPrefix = "" + ChatColor.DARK_GREEN + "[" + ChatColor.GREEN + playerName + ChatColor.DARK_GREEN + "]" + ChatColor.RESET + "";
            String redPrefix = "" + ChatColor.DARK_RED + "[" + ChatColor.RED + playerName + ChatColor.DARK_RED + "]" + ChatColor.RESET + "";
            String bluePrefix = "" + ChatColor.DARK_BLUE + "[" + ChatColor.BLUE + playerName + ChatColor.DARK_BLUE + "]" + ChatColor.RESET + "";
            String barbarianPrefix = "" + ChatColor.BLACK + "[" + ChatColor.DARK_GRAY + playerName + ChatColor.BLACK + "]" + ChatColor.RESET + "";
           
            if(player.hasPermission("prefix.newarrival")) {
                player.setDisplayName(newArrivalPrefix);
            }else if(player.hasPermission("prefix.red")) {
                player.setDisplayName(redPrefix);
            }else if(player.hasPermission("prefix.blue")) {
                player.setDisplayName(bluePrefix);
            }else if(player.hasPermission("prefix.barbarian")) {
                player.setDisplayName(barbarianPrefix);
            }
           
           
        }
    To clearly define my issue, I cannot seem to figure out how to reference the "attachment" variable, in the "permissionsSetter(UUID uuid)" method, in other places such as onCommand, in order to set and unset permissions from players following commands they input.

    Any help is appreciated. Thank you in advance!
     
Thread Status:
Not open for further replies.

Share This Page