Trying my own configManager

Discussion in 'Plugin Development' started by MrGeneralQ, Jul 28, 2016.

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

    MrGeneralQ

    So I am trying to create my own ConfigManger and I'm almost there.
    Except that I am stuck on one part.

    It is bit hard to explain but the code comments should explain what I'm trying:

    My Config class is still empty because I don't know how to start.


    My Main class:

    Code:
    package me.mrgeneralq.takeout;
    
    
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    import commands.Takeout;
    
    public class Main extends JavaPlugin{
    
       
    ConfigManager manager = new ConfigManager(this);
    
       
       
        public void onEnable(){
       
           
           
            // I want vvvvvv this SO I can access my config
        Config myConfig = manager.createConfig("data.yml");
       
        //So I can use for example of of these things
       
        // MyConfig.saveConfig();
       
       
       
       
            getCommand("takeout").setExecutor(new Takeout());
        }
       
       
       
       
    }
    





    My ConfigManager Class:

    Code:
    package me.mrgeneralq.takeout;
    import java.io.File;
    import java.io.IOException;
    
    import org.bukkit.configuration.file.YamlConfiguration;
    
    public class ConfigManager {
       
       
       
        private Main main;
    
        public ConfigManager(Main main){
            this.main = main;
        }
       
    
       
        public void createConfig(String configName){
           
            File newConfig = new File(main.getDataFolder(), configName);
            YamlConfiguration loadConfig = YamlConfiguration.loadConfiguration(newConfig);
           
           
            try {
                loadConfig.save(newConfig);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
           
           
        }
       
       
       
       
       
       
       
       
       
    }
    

    Can someone help me? Thank you :)
     
  2. Offline

    ArsenArsen

    You need a Map<String, YamlConfiguration> to store that. I have done this before so you can look onto my GitHub.
     
  3. Offline

    MrGeneralQ

    Can you provide a url to me?
     
  4. Offline

    mine-care

  5. Offline

    MrGeneralQ

    Thanks for all the replies but I still don't get on how to make that Config varName = ConfigManager.createConfig("data.yml");

    I just need to know on how I can get the BOLD part working
     
  6. Offline

    ArsenArsen

    Use a YamlConfiguration instead of Config and return that.
     
  7. Offline

    MrGeneralQ

    but ConfigManager doesn't return anything.
     
  8. Offline

    I Al Istannen

    @MrGeneralQ
    Then add a "return loadConfig;" statement at the end of the createConfig method ;)
     
  9. Offline

    Oxyorum

    @MrGeneralQ Set the return type of yout createConfig method to YamlConfiguration, then do what
    @I Al Istannen is saying. Problem solved.
     
  10. Offline

    MrGeneralQ

    I will give this a try. But for now I am doing stuff with custom classes. This thread is not closed yet :)
     
  11. Offline

    mine-care

    @MrGeneralQ Don't forget to tahg us ;) Otherwise we wont respond :p Tahg by clicking the tahg button at the botom right of our posts.
     
  12. Offline

    MrGeneralQ

    taggy tag tag :p
     
    mine-care likes this.
  13. Offline

    HeartandSoul

    I do a similar thing. It works, but its way to simple, and it prints the info in console, not IG.

    I'd have to think about this
     
Thread Status:
Not open for further replies.

Share This Page