YAML Problems [SOLVED]

Discussion in 'Plugin Development' started by rominos2, Jul 12, 2011.

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

    rominos2

    Hi I would like to modify my plugins properties to Yaml files but I don't find out what I want

    I set a yaml config file

    Seasons:
    Season0:0
    Season1:1
    Properties:
    Active:true
    Log:false

    I know every properties in the properties part so I can load them all
    But in the Seasons part, users have to create their own nodes and I don't know how to access to this created nodes like Season0 and Season1

    When I call getKeys(), it only return Properties
    How can I do ?
     
  2. Offline

    krinsdeath

    Create a users key, and then check the user's name in the properties as you need to poll the information:

    Code:
    public void onSomeEvent(SomeEvent event) {
      config.getInt("Seasons." + event.getPlayer().getName() + ".Season0", 0);
    }
    
    Code:
    Seasons:
      rominos2:
        Season0: 0
        Season1: 1
      Notch:
        Season0: 0
        Season1: 0
      krinsdeath:
        Season0: 1
        Season1: 0
    Properties:
      Active: true
      Log: false
    
     
  3. Offline

    rominos2

    And ???
    How can I list all the players ?
    Only listing is interesting me
     
  4. Offline

    krinsdeath

    In the case I demonstrated, you'd use:

    Code:
    List<String> keys = config.getKeys("Seasons");
    
    Which would return a list containing rominos2, Notch, and krinsdeath.
     
  5. Offline

    rominos2

    I tried and i return me null ^^
     
  6. Offline

    krinsdeath

    Can I get a peek at the source, including the YAML file you're trying to read from? (use CODE tags, please)
     
  7. Offline

    rominos2

    there it is
    Code:
    Seasons:
        Wet Season:
            Percentages:
                Thunder: 10
                Sun: 20
                Rain: 70
            SeasonLenght: 5
            SpecialDays:
                Last Day of Wet Season: 4
                Mid Wet Season: 2
                First Day of Wet Season: 0
        Dry Season:
            Percentages:
                Thunder: 5
                Sun: 80
                Rain: 15
            WeatherLenght: 0.5
            SeasonLenght: 10
            SpecialDays:
                Last Day of Dry Season: 9
                First Day of Dry Season: 0
    Properties:
        LogInfo: true
        Messages:
            SpecialDayMessage: It's <name>.
            ColorList:
                WHITE: §f
                BLUE: §9
                LIGHT_PURPLE: §d
                GOLD: §6
                GREEN: §a
                AQUA: §b
                DARK_AQUA: §3
                DARK_GREEN: §2
                DARK_GRAY: §8
                DARK_RED: §4
                YELLOW: §e
                DARK_BLUE: §1
                BLACK: §0
                DARK_PURPLE: §5
                RED: §c
                GRAY: §7
            SeasonsMessage: You're in <name> for another <number> days.
            ChangeMessage: Seasons changes to <name>.
            Color: $b
        Active: true
        Regen:
            Snow: true
        TimeResolution: 0.1
    
    And the Source
    Code:
    public void loadSeasons() {
            this.plugin.getLogger().info("----- BEGINNING OF TEST -----");
            this.plugin.getLogger().info(""+this.getKeys("Seasons").size());
            this.plugin.getLogger().info("----- END OF TEST -----");
        }//loadSeasons
    
    It has an NullPointerException between the beginning anfd the end ^^
     
  8. Offline

    krinsdeath

    You're trying to reference a method that doesn't exist. I'm assuming the keyword 'this' refers to your plugin. You need to create a variable of type Configuration and load your plugin's YAML into it.

    Code:
    public class MyPlugin extends JavaPlugin {
      public Plugin plugin;
      public Configuration config;
      @Override
      public void onEnable() {
        plugin = this;
        config = this.getConfiguration();
        loadSeasons();
      }
    
      public void loadSeasons() {
        plugin.getLogger().info("---- test begin ----");
        for (String key : config.getKeys("Seasons")) {
          plugin.getLogger().info(key);
        }
        plugin.getLogger().info("---- test end ----");
      }
    }
    
     
  9. Offline

    rominos2

    In fact "this" refers to the class that extends Configuration
    It's not the same class that the plugin
     
  10. Offline

    krinsdeath

    There's no need to extend bukkit's Configuration class. It has all of the methods you'll ever need to access the information in [your] YAML.

    Without knowing how you instantiate the Configuration in your extended class, and how your plugin deals with the extended configuration, I can't really say what the problem is. :(

    more info required
     
  11. Offline

    rominos2

    Ok I'll see it tommorow without extending the Configuration
    Thanks for that help

    In fact it doesn't change anything
    But I find something

    When I create the default Config with setProperty("Seasons. ....)
    It find the seasons in the getKeys("Seasons")
    But when I reload so when I don't set the nodes it doesn't find them

    Is there something I had to do and I forget
    Do you want the whole class ?

    EDIT : HA finnaly I find the point I didn't call load()
    Thanks for the sources of your plugins ^^

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 17, 2016
Thread Status:
Not open for further replies.

Share This Page