Update Permissions and Prefix and Suffix without reloading whole server

Discussion in 'Plugin Development' started by ZP18, Jun 15, 2015.

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


    Hi, I am working on a plugin that will have a permissions feature, when I change the rank of a player however (/ranks ZP4RKER Admin) the permissions and prefix and suffix don't update until the plugin is reloaded. I have a Permissions.reload() function but it doesn't update the perms for some reason. Here is my reload() function:

    public static final void reload() {
            for(Player player : Bukkit.getOnlinePlayers()) {
                String rank = players.getString("players." + player.getName() + ".rank");
                List<String> perms = (List<String>) ranks.getList("ranks." + rank + ".permissions");
                for(String perm : perms) {
                    PermissionAttachment attach = player.addAttachment(plugin);
                    if(perm.contains("*")) {
                        for(String Perm : wildPerm(perm)) {
                            attach.setPermission(Perm, true);
                    } else {
                        attach.setPermission(perm, true);
            plugin.getLogger().info("Permissions reloaded!");
    Also here is my onPlayerJoin code:
    public class JoinEvent implements Listener {
        private ConfigManager manager;
        private Config players;
        private Config ranks;
        private Config uuids;
        public JoinEvent(bPlugin plugin) {
            manager = new ConfigManager(plugin);
            players = manager.getNewConfig("playerdata.yml");
            ranks = manager.getNewConfig("Permissions/ranks.yml");
            uuids = manager.getNewConfig("uuids.yml");
        public void onPlayerJoin(PlayerJoinEvent e) {
            Player player = e.getPlayer();
            booleanfirstTime = false;
            uuids.set(player.getUniqueId().toString(), player.getName());
            if(players.get("players." + player.getName() + ".rank") == null) {
                players.set("players." + player.getName() + ".rank", "Default");
                firstTime = true;
            String rank = players.getString("players." + player.getName() + ".rank");
            String prefix = ranks.getString("ranks." + rank + ".prefix");
            if(firstTime) {
                e.setJoinMessage(prefix + player.getDisplayName() + CC.YELLOW + " has joined the server for the first time!");
            } else {
                e.setJoinMessage(prefix + player.getDisplayName() + CC.YELLOW + " has joined the server!");
    I would like to update the perms and suffix without reloading the plugin, thanks for any help!
    Last edited by a moderator: Jun 16, 2015
  2. @ZP18 I'm guessing "players" is a config reference? If you change the file, the changes are not reflected in the configuration memory until you load it from the file again.
  3. Offline


    @AdamQpzm Yes the players is a config reference, so are you saying I should make a function similar to this:
    2. public static void reloadConfig() {
    3. players = manager.getNewConfig();
    4. }
  4. Offline


    If you're adding attachments, would it not make sense to remove any attachments that are left behind before adding new ones again?
  5. Offline


    I fixed the Prefix problem but not the Perms problem. @RingOfStorms where would I remove the attachment and how do I remove it?
Thread Status:
Not open for further replies.

Share This Page