Help with config.yml

Discussion in 'Plugin Development' started by Jackson12, May 19, 2015.

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

    Jackson12

    Hey, I'm having trouble making my config.yml. I am currently working on a plugin for staff recommendations. This is how i want my config.yml to look like, but i don't know how to do it. I also want it to where you can add as many names as you want just like that and to where they show up on separate lines in chat when you type a command.
    Code:
    Staff:
        - StaffName
        - StaffName
        - StaffName
        - StaffName
    
     
  2. Offline

    techboy291

    You're wanting a string list, which you can set in the config like you would anything else. You can get it with getConfig().getStringList("Staff") in your case, assuming you're in your plugin's main class. Give the wiki page above a read if you haven't already.
     
  3. Offline

    Jackson12

    Ok, Thanks ill give it a try

    It didn't work, or i'm just not typing it in the config right. Can you please show me how i should type it in the config after i insert the code you gave me.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  4. Offline

    nverdier

    Just saying, if you have a list like that, each new line starting with a '-' should have that same indentation as the 'Staff:', in this case no indentation.
     
  5. Offline

    Jackson12

    It did not work, Here is my main class....

    Code:
    package StaffRecommendation;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Staff extends JavaPlugin{
     
        public void onEnable() {
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
        public void onDisable() {
            saveConfig();
        }
     
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player player = (Player) sender;
            if(sender.hasPermission("recommended.staff"));
            if(commandLabel.equalsIgnoreCase("Staff")){
                player.sendMessage(ChatColor.GREEN + ">>>" + ChatColor.BLUE + ">>" + ChatColor.RED + ">" + ChatColor.DARK_AQUA + "  Staff List  " + ChatColor.RED + "<" + ChatColor.BLUE + "<<" + ChatColor.GREEN + "<<<\n" + getConfig().getStringList("Staff"));
            }
         
            return false;
        }
    }
    
    Here is my config.yml

    Code:
    Staff:
    - zjblow
    - jackson
     
    Last edited: May 19, 2015
  6. Offline

    Konato_K

    @nverdier Just for the record, this is not entirely truth, I'm not totally aware of how identation needs to be done in YML in lists, but I have done this as valid YML
    Code:
    something:
      - something else
      - and another here
      - potato
     
  7. Offline

    nverdier

    Ah, nevermind then ;3 I know for sure that they all have to be on the same level, though.
     
  8. Offline

    Jackson12

    I got it to work, But i had to use a different line of code:
    Code:
    for (String line : getConfig().getStringList("Staff")) {
                player.sendMessage(line);
            }
     
    Last edited: May 20, 2015
Thread Status:
Not open for further replies.

Share This Page