Solved Get all configuration sections in an YAML file?

Discussion in 'Plugin Development' started by Assist, Feb 9, 2014.

Thread Status:
Not open for further replies.
  1. Hey. I'm using the CrackShot API in one of my plugins, and from what I can tell, there is no method that returns all the weapons. I tried making my own by accessing the defaultWeapons file and getting all the sections in it, but there seems to be none. Here is a part of my code
    Code:java
    1. private static String getRandomWeapon() {
    2. HashSet <String> weaponList = new HashSet <String>();
    3.  
    4. File f = new File("plugins" + File.separator + "CrackShot" + File.separator + "weapons", "defaultWeapons");
    5. FileConfiguration c = YamlConfiguration.loadConfiguration(f);
    6.  
    7. for (String key : c.getKeys(false)) {
    8. weaponList.add(key);
    9. }
    10.  
    11. return (String) weaponList.toArray()[r.nextInt(weaponList.size())];
    12. }
    I tried adding debug messages to it, and the file isn't null, but it seems to be empty, or then I'm just not using it correctly.

    The question here is; how would I go about looping through all the sections in the file, if it's formatted like this:
    Code:
    section1:
        # stuff
    section2:
        # more stuff
    I would like to add section1 and section2 to my HashSet.

    Thanks in advance.

    Edit: Also, I can assure you that the file isn't empty. Here's a snippet of the default weapons that come with the plugin:
    Code:
    Gauss:
        Item_Information:
            Item_Name: "&eGauss Shotgun"
            Item_Type: 417
            Item_Lore: "&eAdvanced pump-action shotgun.|&eFires metal slugs that penetrate|&eall targets within 40 blocks.|&eDeals 200% damage to Zombies."
            Sounds_Acquired: BAT_TAKEOFF-1-1-0
        Shooting:
            Cancel_Left_Click_Block_Damage: true
            Cancel_Right_Click_Interactions: true
            Projectile_Amount: 1
            Projectile_Type: energy
            Projectile_Subtype: 40-1-NONE-0
            Projectile_Damage: 12
            Sounds_Shoot: WITHER_SHOOT-1-2-0,EXPLODE-1-2-0
        Reload:
            Enable: true
            Reload_Amount: 8
            Reload_Bullets_Individually: true
            Reload_Duration: 10
            Sounds_Reloading: IRONGOLEM_THROW-1-2-0
        Firearm_Action:
            Type: pump
            Open_Duration: 12
            Close_Duration: 3
            Sound_Open: PISTON_EXTEND-1-2-0
            Sound_Close: PISTON_EXTEND-1-2-0
        Abilities:
            Reset_Hit_Cooldown: true
            Super_Effective: ZOMBIE-2
        Particles:
            Enable: true
            Particle_Player_Shoot: BLOCK_BREAK-57
        Hit_Events:
            Enable: true
            Sounds_Shooter: SHOOT_ARROW-1-2-0
     
    Carbine:
        Item_Information:
            Item_Name: "&eCarbine"
            Item_Type: 417
            Item_Lore: "&eDeals crits with a 10% chance.|&eSwitch to the grenade launcher|&ewith right click. Fired grenades|&earm themselves in 0.25 seconds."
            Attachments:
                Type: main
                Info: "M320"
                Toggle_Delay: 5
                Sounds_Toggle: NOTE_STICKS-1-2-0
            Sounds_Acquired: BAT_TAKEOFF-1-1-0
        Shooting:
            Cancel_Left_Click_Block_Damage: true
            Cancel_Right_Click_Interactions: true
            Delay_Between_Shots: 3
            Recoil_Amount: 1
            Projectile_Amount: 1
            Projectile_Type: snowball
            Projectile_Speed: 40
            Projectile_Damage: 4
            Bullet_Spread: 0.5
            Sounds_Shoot: BLAZE_HIT-1-2-0,ZOMBIE_WOOD-1-2-0
        Sneak:
            Enable: true
            No_Recoil: true
            Bullet_Spread: 0.4
        Reload:
            Enable: true
            Reload_Amount: 8
            Reload_Duration: 30
            Sounds_Reloading: SKELETON_IDLE-1-0-0,FIRE_IGNITE-1-1-14,DOOR_OPEN-1-2-16,FIRE_IGNITE-1-1-26,HURT_FLESH-1-0-27,DOOR_CLOSE-1-2-28
        Firearm_Action:
            Type: slide
            Close_Duration: 8
            Sound_Close: CLICK-1-1-0
        Abilities:
            Reset_Hit_Cooldown: true
        Particles:
            Enable: true
            Particle_Impact_Anything: BLOCK_BREAK-80
            Particle_Critical: BLOCK_BREAK-55
        Hit_Events:
            Enable: true
            Sounds_Shooter: SHOOT_ARROW-1-2-0
        Critical_Hits:
            Enable: true
            Bonus_Damage: 2
            Chance: 10
            Sounds_Shooter: ORB_PICKUP-1-2-0
     
  2. I apologize for this early bump, but I'm off to school and hoping to get an answer to this question.

    Thanks in advance.

    Edit:
    Show Spoiler
    [​IMG]

    So it seems like I forgot to add ".yml" to the end of the file name...
     
Thread Status:
Not open for further replies.

Share This Page