Getting a list of arenas from config

Discussion in 'Plugin Help/Development/Requests' started by MCPVPCoder, Feb 17, 2015.

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

    MCPVPCoder

    Hello. I am having issues getting a list of arenas from my "arenas.yml" file. It saves them correctly and such, but when I try to load them by getStringList(....) it does not work.

    Arenas.yml
    Code:
    Arenas:
      '1':
        Spawn:
          X: -20.51898431238692
          Y: 4.0
          Z: -3.534145837262486
          World: world
      '2':
        Spawn:
          X: -12.4425497847055
          Y: 4.0
          Z: 0.513421916749869
          World: world
      '3':
        Spawn:
          X: -12.222858275141215
          Y: 4.0
          Z: -6.603315924513339
          World: world
    
    Log
    Code:
    [21:26:52] [Server thread/ERROR]: Error occurred while enabling SkyWars vb0.1.4 (Is it up to date?)
    java.lang.NumberFormatException: For input string: "MemorySection[path='Arenas', root='YamlConfiguration']"
        at java.lang.NumberFormatException.forInputString(Unknown Source) ~[?:1.8.0_31]
        at java.lang.Integer.parseInt(Unknown Source) ~[?:1.8.0_31]
        at java.lang.Integer.valueOf(Unknown Source) ~[?:1.8.0_31]
        at com.REMOVED.skywars.ArenaManager.loadArenas(ArenaManager.java:79) ~[?:?]
        at com.REMOVED.skywars.SkyWars.onEnable(SkyWars.java:72) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-59b08be-c13376d]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:335) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-59b08be-c13376d]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-59b08be-c13376d]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:355) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-59b08be-c13376d]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:315) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-59b08be-c13376d]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(CraftServer.java:744) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-59b08be-c13376d]
        at org.bukkit.Bukkit.reload(Bukkit.java:534) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-59b08be-c13376d]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-59b08be-c13376d]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-59b08be-c13376d]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:645) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-59b08be-c13376d]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchServerCommand(CraftServer.java:631) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-59b08be-c13376d]
        at net.minecraft.server.v1_8_R1.DedicatedServer.aM(DedicatedServer.java:353) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-59b08be-c13376d]
        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:317) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-59b08be-c13376d]
        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:623) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-59b08be-c13376d]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:526) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-59b08be-c13376d]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]
    [21:26:52] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [21:26:52] [Server thread/INFO]: CONSOLE: [0;32;1mReload complete.[m
    
    Load Method
    Code:
            List<String> arenaStrings = this.plugin.arenasConf.getStringList("Arenas");
     
  2. Offline

    Qwertyness_

    The getStringList(String) method only works with this kind of list:
    Code:
    Arenas:
    - '1'
    - '2'
    Instead, you have to do something like this:
    Code:
    for (String key : configuration.getConfigurationSection("Arenas").getKeys(false)) {
      //Arena creation code where key = the arena section name.
      //Example:
      ConfigurationSection arenaSection = configuration.getConfigurationSection("Arenas." + key);
      int x = arenaSection.getInt("Spawn.X")
     
    }
     
    MCPVPCoder likes this.
  3. Offline

    MCPVPCoder

    Thank you so much!
     
Thread Status:
Not open for further replies.

Share This Page