YAML node: What type ?

Discussion in 'Plugin Development' started by Europia79, May 2, 2014.

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

    Europia79

    I'm trying to access a node in a YML file... but I don't know what type it is just by looking at it... So I don't know what getter to look for in API.

    Here's the yaml file:
    Code:
    arenas:
      b2:
        locations:
          '1': Battlecraft,211.2465228678722,74.0,-940.3882217694892,-267.55667,3.6000125
          '0': Battlecraft,160.33054850156566,74.0,-942.7268442438761,-88.60673,-0.8999724
        type: BombArena
        spawns:
          '1':
            time: 1 300 0
            spawn: HARD_CLAY 1
            loc: Battlecraft,185.6336732547647,74.0,-941.8442307513332,-177.5567,2.1000018
        waitRoomLocations:
          '1': Battlecraft,187.10000444808097,74.0,-950.2985274819425,-185.65675,-1.8000057
          '0': Battlecraft,184.09688872870893,74.0,-950.5107243057915,-172.60669,-1.3500059
        params: {}
        bases:
          '1': Battlecraft,161.0,74.0,-942.0,0.0,0.0
          '2': Battlecraft,210.0,74.0,-942.0,0.0,0.0
    brokenArenas: {}
    
    Specifically, I'm trying to get and set the node: "arenas.b2.spawns.1.spawn"

    which is the general node of "arenas.{name}.spawns.{index}.spawn"

    Code:
    spawn: HARD_CLAY 1
    I've tried getString() hoping it would work without there being single quotes or double quotes.

    Code:java
    1. private void setBombSpawn(String x) {
    2. // PATH = "arenas.{arena}.spawns.{index}.spawn"
    3. String value = x + " 1";
    4. String BombBlockString = this.BombBlock.name();
    5. this.debug.log("updating arenas.yml with " + x);
    6. ConfigurationSection arenas = this.arenasYml.getConfigurationSection("arenas");
    7. this.debug.log("" + arenas.getKeys(false).toString());
    8. for (String arena : arenas.getKeys(false)) {
    9. this.debug.log("" + arena.toString());
    10. ConfigurationSection spawns = this.arenasYml.getConfigurationSection("arenas." + arena);
    11. this.debug.log("" + spawns.getKeys(false).toString());
    12. for (String n : spawns.getKeys(false)) {
    13. String path = "arenas." + arena + ".spawns." + n + ".spawn";
    14. String old = this.arenasYml.getItemStack(path).toString();
    15. if (!old.startsWith(BombBlockString)) {
    16. this.debug.log("BombArena arenas.yml has an item/mob spawn that is NOT a Bomb! " + old);
    17. continue;
    18. }
    19. getLogger().info("" + path + " has been changed from " + old + " to " + value);
    20. this.arenasYml.set(path, value);
    21. }
    22. }
    23. this.arenasYml.saveConfig();
    24. }


    Here's the error (pretty obvious because I'm using the wrong getter)
    NPE in server.log and debugging info (open)

    Code:
    [BattleArena] Enabling BattleArena v3.9.6.7
    [BattleArena] enabling!
    [BattleArena] Essentials detected. God mode handling activated
    [BattleArena] WorldEdit detected.
    [BattleArena] WorldGuard detected. WorldGuard regions can now be used
    [BattleArena] Warning currency was empty, using name from config.yml
    [BattleArena] found economy plugin Vault. [Default]
    [BattleArena] no additional Arena modules
    [BattleArena] registering classes: assault, support, recon, engineer, Vector, Dragonuv, Barrett, Fal, 552, AKS-75X, UMP-45X, FAMAS-X, stg77, P90X
    [BattleArena] enabled!
    [INFO] [BombArena] Enabling BombArena v172140502-0104
    [INFO] [BombArena] Loading config.yml
    [INFO] [BombArena] updating arenas.yml with LOG
    [INFO] [BombArena] [b2]
    [INFO] [BombArena] b2
    [INFO] [BombArena] [locations, type, spawns, waitRoomLocations, params, bases]
    2014-05-02 01:09:30 [Server thread][ERROR] Error occurred while enabling BombArena v172140502-0104 (Is it up to date?)
    java.lang.NullPointerException
        at mc.euro.demolition.BombPlugin.setBombSpawn(BombPlugin.java:14) ~[?:?]
        at mc.euro.demolition.BombPlugin.loadDefaultConfig(BombPlugin.java:109) ~[?:?]
        at mc.euro.demolition.BombPlugin.onEnable(BombPlugin.java:86) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:250) ~[craftbukkit172.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:350) [craftbukkit172.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:389) [craftbukkit172.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugin(CraftServer.java:439) [craftbukkit172.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.enablePlugins(CraftServer.java:375) [craftbukkit172.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.m(MinecraftServer.java:342) [craftbukkit172.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.g(MinecraftServer.java:319) [craftbukkit172.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.a(MinecraftServer.java:275) [craftbukkit172.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.java:175) [craftbukkit172.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:424) [craftbukkit172.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit172.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    [Server thread][INFO] Server permissions file permissions.yml is empty, ignoring it
    2014-05-02 01:09:31 [Server thread][INFO] Done (2.189s)! For help, type "help" or "?"


    So I tried getString() first, then I tried getItemStack(). Is it a vector ? Or a custom type ?

    It looks like I have two options: write my own getter() or find one in the BattleArena API:

    http://ci.battleplugins.com/job/BattleArena/javadoc/
     
  2. Offline

    Superckl1

    Europia79

    What you see is a serialized class. You will have to look through the BattleCraft source to see exactly what class it is and how they unserialize it.
     
    Europia79 likes this.
  3. Offline

    Europia79

  4. Offline

    Europia79

    https://github.com/alkarinv/BattleA.../arena/executors/ArenaEditorExecutor.java#L61

    Help! This method (lines 61-80) is what originally adds the section "arenas.{arenaName}.spawns.{index}.spawn" node with the value "spawn: HARD_CLAY 1"

    But I've examined all those classes, and still cannot figure out how to
    1. get the node (in order to check the contents)
    2. change the value of the node (if necessary)

    If anyone is knowledgeable about Serializing & De-Serializing configuration nodes, I would appreciate the help! Thanks!
     
Thread Status:
Not open for further replies.

Share This Page