Issues (29)

serverapi/bungee/BungeecordLabyModConfig.java (4 issues)

1
package net.labymod.serverapi.bungee;
2
3
import net.labymod.serverapi.LabyModConfig;
4
import net.md_5.bungee.config.Configuration;
5
import net.md_5.bungee.config.ConfigurationProvider;
6
import net.md_5.bungee.config.YamlConfiguration;
7
8
import java.io.File;
9
import java.io.IOException;
10
11
/**
12
 * Class created by qlow | Jan
13
 */
14
public class BungeecordLabyModConfig extends LabyModConfig {
15
16
    private Configuration configuration;
17
18
    public BungeecordLabyModConfig( File file ) {
19
        super( file );
20
21
        // Creating the file if it doesn't exist
22
        if ( !file.exists() )
23
            try {
24
                file.createNewFile();
0 ignored issues
show
Do something with the "boolean" value returned by "createNewFile".
Loading history...
25
            } catch ( IOException e ) {
26
                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...
27
            }
28
29
        // Initializing the config
30
        init( file );
31
    }
32
33
    @Override
34
    public void init( File file ) {
35
        // Loading the config
36
        try {
37
            this.configuration = ConfigurationProvider.getProvider( YamlConfiguration.class ).load( file );
38
        } catch ( IOException e ) {
39
            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...
40
        }
41
42
        // Adding the defaults
43
        addDefaults();
44
45
        // Saving the config after adding the defaults
46
        saveConfig();
47
48
        // Loading the values
49
        loadValues();
50
    }
51
52
    @Override
53
    public Object getValue( String key ) {
54
        return configuration.get( key );
55
    }
56
57
    @Override
58
    public void addDefault( String key, Object value ) {
59
        if ( !configuration.contains( key ) )
60
            configuration.set( key, value );
61
    }
62
63
    @Override
64
    public void saveConfig() {
65
        try {
66
            ConfigurationProvider.getProvider( YamlConfiguration.class ).save( configuration, file );
67
        } catch ( IOException e ) {
68
            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...
69
        }
70
    }
71
}
72