Getting configuration section help.

Discussion in 'Spigot Plugin Development' started by JacksonHogan, May 14, 2016.

  1. I'm trying to loop through the config section "Arenas" to get the arena names.
    This is what my code looks like:

    Code (Java):
    public static Arena loadArenas(){
            for(String key : Skywars.config.getConfig().getConfigurationSection("Arenas").getKeys(false)){
                String world = Skywars.config.getConfig().getString(key + ".world");
                double lobbyx = Skywars.config.getConfig().getDouble(key + ".lobbyx");
                double lobbyy = Skywars.config.getConfig().getDouble(key + ".lobbyy");
                double lobbyz = Skywars.config.getConfig().getDouble(key + ".lobbyz");
                int lobbypitch = Skywars.config.getConfig().getInt(key + ".lobbypitch");
                int lobbyyaw = Skywars.config.getConfig().getInt(key + ".lobbyyaw");
                Location lobbyLoc = new Location(Bukkit.getWorld(world), lobbyx, lobbyy, lobbyz, lobbypitch, lobbyyaw);
                double endx = Skywars.config.getConfig().getDouble(key + ".endx");
                double endy = Skywars.config.getConfig().getDouble(key + ".endy");
                double endz = Skywars.config.getConfig().getDouble(key + ".endz");
                int endpitch = Skywars.config.getConfig().getInt(key + ".endpitch");
                int endyaw = Skywars.config.getConfig().getInt(key + ".endyaw");
                Location endLoc = new Location(Bukkit.getWorld(world), endx, endy, endz, endpitch, endyaw);
                int maxPlayers = Skywars.config.getConfig().getInt(key + ".maxPlayers");
                Arena a = new Arena(key, Bukkit.getWorld(world), lobbyLoc, endLoc, maxPlayers);
            return null;
    My Config:
    Code (Text):
        world: Builder
        lobbyx: 1027.7809245268475
        lobbyy: 17.0
        lobbyz: -284.755069447873
        lobbypitch: 35.79868
        lobbyyaw: 17.398888
        endx: 1027.7809245268475
        endy: 17.0
        endz: -284.755069447873
        endpitch: 35.79868
        endyaw: 17.398888
        maxPlayers: 1
            world: Builder
            x: 1027.7636260170016
            y: 17.0
            z: -274.3899634274507
            pitch: 14.554382
            yaw: 51.06911
    EDIT: Its not loading the arenas.... I don't get an error or anything.
    #1 JacksonHogan, May 14, 2016
    Last edited: May 14, 2016
  2. Whats the problem...
  3. Its not loading the arenas.... I don't get an error or anything.
  4. Do you call the method?
    Why does the method signature return an Arena if you don't use it as such, just make it void
  5. Yes, I do call it in the onEnable method:
    Code (Text):
    public void onEnable(){
            plugin = this;
            messages = new Config(this, "Messages.yml");
            config = new Config(this, "Config.yml");
            chest = new Config(this, "Chests.yml");
  6. I use SQLite mostly now, and haven't messed with the Config for a while, but I will point something out.

    Code (Text):
    for(String key : Skywars.config.getConfig().getConfigurationSection("Arenas").getKeys(false)){
    You are looking for keys AND values (obviously because you have String key), yet you set getKeys to false? What if you set that to true so you could get both the keys and the values, considering the String key will most probably return the values considering the system is not getting the keys but rather the values.
  7. Store the ConfigurationSection in a variable and use that. If you really want to however, just add "Arenas" + before key. Example:
    Code (Text):

    ConfigurationSection arenaSec = Skywars.config.getConfig().getConfigurationSection("Arenas");
    for (String key : arenaSec.getKeys(false)) {
        String world = arenaSec.getString(key + ".world");
  8. For the key thing it's not loading simply because they're null, the key returns "sw1" not "arenas.sw1" so in the for loop do something like key = "arenas." + key; instead so you're getting the full key not just the key of the section. I hope I explained that well.