Solved YAML Config

Discussion in 'Plugin Development' started by khave, Aug 3, 2014.

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

    khave

    Code:
    #------------------------------------------------------------------------
    #To enable and disable things write true or false (Only for Scheduler
    #and PlayerMovement)
    #
    #Schematic is the schematic file you want loaded. DO NOT ADD EXTENSION.
    #
    #Scheduler is wether or not to use a scheduler for pasting the schematic.
    #Good for laggy servers with many players.
    #
    #SchedulerTime is the time for the scheduler to update (in ticks).
    #20 Ticks = 1 second.
    #
    #PlayerMovement is wether or not to update the schematic everytime you
    #move. Creates a smooth transaction, but may be laggy
    #------------------------------------------------------------------------
    #
    WELoader:
      Schematic: sus1
      Scheduler: false
      SchedulerTime: 5
      PlayerMovement: true
    This is my config, but when I try to get some values from the config nothing happens.

    This is how I get my values:
    Code:
    getConfig().getInt("WELoader.SchedulerTime");
    The config saves on reload, so theres nothing wrong there.
     
  2. What is your full class, because I think it has to do with something in your OnEnable method
     
  3. Offline

    khave

    It's a confusing class (Haven't made it look prettuh yet :3), so I'm just posting the essentials:

    Code:java
    1. public void loadConfiguration() {
    2. saveDefaultConfig();
    3. //this.saveConfig();
    4. this.getConfig().options().copyDefaults(true);
    5. }
    6.  
    7.  
    8. @Override
    9. public void onDisable(){
    10. saveDefaultConfig();
    11. }
    12.  
    13.  
    14. @Override
    15. public void onEnable() {
    16. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    17. loadConfiguration();
    18. }
     
  4. You can remove the copy defaults in the load config and what will be printed out when you use System.out.println('how you get the integer');
     
  5. Offline

    pookeythekid

    khave In your loadConfiguration() method, this.getConfig().options().copyDefaults(true); is unnecessary. saveDefaultConfig(); copies your config perfectly, word for word. The getConfig().options...(blah blah) does not save your config comments correctly (that is, the comments that are not in the header). This has nothing to do with your config keys, but it's a nice thing to know if you want to comment your config without putting it all in the header.

    Otherwise, I think a full ("prettuh") class would help for others to debug.
     
  6. Offline

    khave




    I removed the unnecessary code and came up with this:

    Code:java
    1. @Override
    2. public void onDisable(){
    3. saveDefaultConfig();
    4. }
    5.  
    6.  
    7. @Override
    8. public void onEnable() {
    9. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    10. saveDefaultConfig();
    11. }


    This is what I use in my onCommand:
    Code:java
    1. if(!getConfig().getBoolean("WELoader.Scheduler")){
    2. return true;
    3. }


    I tried posting the value of WELoader.Scheduler and it came out null, so clearly it can't recognize my path D;

    EDIT:
    Sorry I tried messing with it and found out you guys helped me correctly and it was my other code which was not working xP. Thanks for the help guys!
     
  7. Offline

    pookeythekid

Thread Status:
Not open for further replies.

Share This Page