Solved Getting a list of strings from a config?

Discussion in 'Plugin Development' started by dan14941, May 4, 2014.

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

    dan14941

    Im trying to make a list that displays the staff from a config here is the code that i snot working:
    Code:
            if(commandLabel.equalsIgnoreCase("staff"))
            {
    for(String st : config.getStringList("Staff.ranks"))
                {
                    player.sendMessage(ChatColor.YELLOW + st + ": ");
                    if(config.getStringList("Staff." + st) == null)
                    {
                        player.sendMessage(ChatColor.RED + "None Set!");
                    }
                    else
                    {
                        for(int i = 0; i <= config.getStringList("Staff." + st).size(); i++)
                        {
                            player.sendMessage(ChatColor.GREEN + config.getString("Staff." + str));
                        }
     
                    }
                    player.sendMessage(s);
                }
    it just says under the rank: null

    here is my config file:
    Code:
    # Add your custom ranks below!
    Staff:
      ranks:
      - admin
      - moderator
      - co-owner
      owner:
        name: Default
      admin:
      - sdhshduih
      - 2
      - 3
      - 4
     
  2. Offline

    IkBenHarm

    dan14941

    you could do it by this:

    Code:
                else if(args.length == 1 && args[0].equalsIgnoreCase("List")){
                 
                    if(!p.hasPermission("team.list") || !p.hasPermission("team.*")){
                        p.sendMessage(ChatColor.AQUA + "[team]  -  You do not have permission!");
                        return true;
                    }
                     
                    List<String> l = new ArrayList<>();
                     
                    for(Team k : TeamManager.getManager().getAllTeans()){
                        l.add(k.getName());
                    }
                     
                    if(l.isEmpty()){
                        p.sendMessage(ChatColor.AQUA + "[team]  -  There are no Teams!");
                    }
                     
                    else{
                        p.sendMessage(ChatColor.AQUA + "[team]  -  All Teams: " + l);
                    }
                }
    and then replace
    TeamManager.getManager().getAllTeams() with your list.

    Should help you i think

    * this is piece from my own plugin, so do not copy and paste directly :p *
     
  3. Offline

    dan14941

    IkBenHarm is there no simple way of doing it?
     
  4. Offline

    IkBenHarm

    dan14941
    this is pretty simple :p
    What do you not understand? Ill try to explain
     
  5. Offline

    dan14941

    IkBenHarm i mean in like 3 or 4 lines of text
     
  6. Offline

    IkBenHarm

    dan14941
    you could remove the if is empty check, you could remove the permission etc.
    But why would that make a big difference?
     
  7. Offline

    dan14941

    IkBenHarm wait nvm i was looking at the code like: "Wow what the hell, did he do?" but i understand it
    its late and ima bit stupid lol
     
  8. Offline

    IkBenHarm

    dan14941
    haha okay, glad i coould help
     
Thread Status:
Not open for further replies.

Share This Page