| Total Complexity | 8 |
| Total Lines | 53 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package net.labymod.serverapi.bukkit; |
||
| 13 | public class BukkitLabyModConfig extends LabyModConfig { |
||
| 14 | |||
| 15 | private FileConfiguration fileConfiguration; |
||
| 16 | |||
| 17 | public BukkitLabyModConfig( File file ) { |
||
| 18 | super( file ); |
||
| 19 | |||
| 20 | // Creating the file if it doesn't exist |
||
| 21 | if ( !file.exists() ) |
||
| 22 | try { |
||
| 23 | file.createNewFile(); |
||
|
|
|||
| 24 | } catch ( IOException e ) { |
||
| 25 | e.printStackTrace(); |
||
| 26 | } |
||
| 27 | |||
| 28 | // Loading the config |
||
| 29 | this.fileConfiguration = YamlConfiguration.loadConfiguration( file ); |
||
| 30 | |||
| 31 | // Initializing the config |
||
| 32 | init( file ); |
||
| 33 | } |
||
| 34 | |||
| 35 | @Override |
||
| 36 | public void init( File file ) { |
||
| 37 | // Applying options to the config |
||
| 38 | fileConfiguration.options().copyDefaults( true ); |
||
| 39 | |||
| 40 | // Adding the defaults |
||
| 41 | addDefaults(); |
||
| 42 | |||
| 43 | // Saving the config after adding the defaults |
||
| 44 | saveConfig(); |
||
| 45 | |||
| 46 | // Loading the values |
||
| 47 | loadValues(); |
||
| 48 | } |
||
| 49 | |||
| 50 | @Override |
||
| 51 | public Object getValue( String key ) { |
||
| 52 | return fileConfiguration.get( key ); |
||
| 53 | } |
||
| 54 | |||
| 55 | @Override |
||
| 56 | public void addDefault( String key, Object value ) { |
||
| 57 | fileConfiguration.addDefault( key, value ); |
||
| 58 | } |
||
| 59 | |||
| 60 | @Override |
||
| 61 | public void saveConfig() { |
||
| 62 | try { |
||
| 63 | fileConfiguration.save( file ); |
||
| 64 | } catch ( IOException e ) { |
||
| 65 | e.printStackTrace(); |
||
| 66 | } |
||
| 69 |