Issues (29)

labymod/serverapi/bukkit/BukkitLabyModConfig.java (3 issues)

1
package net.labymod.serverapi.bukkit;
2
3
import net.labymod.serverapi.LabyModConfig;
4
import org.bukkit.configuration.file.FileConfiguration;
5
import org.bukkit.configuration.file.YamlConfiguration;
6
7
import java.io.File;
8
import java.io.IOException;
9
10
/**
11
 * Class created by qlow | Jan
12
 */
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();
0 ignored issues
show
Do something with the "boolean" value returned by "createNewFile".
Loading history...
24
            } catch ( IOException e ) {
25
                e.printStackTrace();
0 ignored issues
show
Throwable.printStackTrace writes to the console which might not be available at runtime. Using a logger is preferred.
Loading history...
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();
0 ignored issues
show
Throwable.printStackTrace writes to the console which might not be available at runtime. Using a logger is preferred.
Loading history...
66
        }
67
    }
68
}
69