Promote in a group ladder

Discussion in 'Plugin Development' started by TitaniuMark, Jan 20, 2019.

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

    TitaniuMark

    Currently I am trying to create a Permission plugin but... i have a problem:
    I don't realize how to make the "Group Ladder" aka [Inheritance] promote command...

    This is the code that create the "inheritance" config:
    Code:
    public class Inheritor implements CommandExecutor {
       
        private File hre;
        private FileConfiguration cfg;
        private RipHudRanks plugin;
        private File_Players players;
       
        public Inheritor(RipHudRanks plugin){
            this.plugin = plugin;
            this.hre = new File("plugins/RipHudRanks", "InheritanceList.yml");
            this.cfg = YamlConfiguration.loadConfiguration(this.hre);
           
            if (!this.hre.exists()){
                try{
                    this.cfg.save(this.hre);
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
        }
        public File getGroup(){
            return this.hre;
        }
        public FileConfiguration getCfg(){
            return this.cfg;
        }
        public void saveCfg(){
            try{
                this.cfg.save(this.hre);
            }catch (IOException e){
                e.printStackTrace();
            }
        }
    
        @Override
        public boolean onCommand(CommandSender cs, Command cmd, String label, String[] arg) {
            if (cmd.getName().equalsIgnoreCase("inherit")){
                List<String> inh = getCfg().getStringList("Inherit." + arg[0]);
                inh.add(arg[1]);
                getCfg().set("Inheritor." + arg[0], inh);
                saveCfg();
                cs.sendMessage("Now, the group: " + arg[1] + " is inherited to group: " + arg[0]);
            }
               
           
            return true;
        }
    
    }
    Now.. I have a total of 3 configs:
    player.yml *
    - It store players with their
    - Groups
    - Permissions (separately from the group defined perms)

    groups.yml
    - It store groups with
    - Perms
    - Variables

    InheritanceList.yml *
    - It store groups that inherits another groups
    so.. if i type /i staff admin
    the group admin will be an object on the ladder "staff"
    /* the group "def" was inserted there first */
    It will look like that:
    Code:
    Inheritor:
       staff:
            - admin
            - def
    
    Now... I have a player called "Elite" assigned to group "def" ,
    How do i replace the [players.yml > Elite > Groups > "def"] with the next group in the list "staff"?
     
  2. @TitaniuMark

    If I read your question, it looks like you want to modify the config of player 'Elite'. Is that really what you want to do?
     
  3. Offline

    TitaniuMark

    Yes ... I want to modify the config of player 'Elite" relyed to the "staff" ladder on Inheritance config....
     
  4. @TitaniuMark

    Ah, now I realize what you are trying to do and why.
    I think you can load the list of the ranks with something like
    Code:
    cfg.getConfigurationSection("Inheritance").getStringList("staff");
    Then use the indexOf method of that string list with the current rank. If it is 0, player already has max rank. If not, the new rank should be list.get(index - 1);

    Then change the value in your players config and save your players config.
     
Thread Status:
Not open for further replies.

Share This Page