Help with YAML

Discussion in 'Plugin Development' started by Windwaker, May 26, 2011.

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

    Windwaker

    Well I'm not exactly sure how to make a config with YAML.... So far I have...

    Code:
    public class Sunscreen extends JavaPlugin{
        static String mainDirectory = "plugins/Sunscreen";
        File file = new File(mainDirectory + File.separator + "config.yml");
        private static final Logger log = Logger.getLogger("Minecraft");
        private final ssEntityListener entityListener = new ssEntityListener (this);
        public void onEnable(){
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.CREATURE_SPAWN, entityListener,
                    Event.Priority.Normal, this);
            pm.registerEvent(Event.Type.ENTITY_COMBUST, entityListener,
                    Event.Priority.Normal, this);
            log.info("Sunscreen Enabled. Sun-Screening Mobs...");
    
        }
        public void onDisable() {
            log.info("Suncreen Disabled, aww.");
    
        }
        public Configuration load(){
    
            try {
                Configuration config = new Configuration(file);
                config.load();
                return config;
    
            } catch (Exception e) {
                e.printStackTrace();
            }
    
            new File(mainDirectory).mkdir();
    
            if(!file.exists()){
                try {
                    file.createNewFile();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            } else {
    
            }
            return null;
    
        }
        public void write(String root, Object x){
            Configuration config = load();
            config.setProperty(root, x);
            config.save();
    
        }
        public String read(String root){
            Configuration config = load();
            return config.getString(root);
    
        }
    }
    What goes under the }else{ ?
     
  2. Offline

    DreadKyller

    first off, why are you making the file after one possible return and after a trying clause, it just doesn't make sense to me to keep going on the code like that, I personally think the is(!file.exists()) blah should go before trying to make a config file with it
     
Thread Status:
Not open for further replies.

Share This Page