summaryrefslogtreecommitdiffstats
path: root/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java
blob: 591afe3fa4f457c6b9930c4fcd1accfdcff0a7e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.anjocaido.groupmanager;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.logging.Level;

import org.anjocaido.groupmanager.utils.Tasks;
import org.bukkit.configuration.file.YamlConfiguration;

/**
 *
 * @author gabrielcouto
 */
public class GMConfiguration {

    private GroupManager plugin;
    private File configFile;
    private YamlConfiguration GMconfig;
    
    public GMConfiguration(GroupManager plugin) {
        this.plugin = plugin;
        load();
    }

    public void load() {
        if (!plugin.getDataFolder().exists()) {
            plugin.getDataFolder().mkdirs();
        }
        configFile = new File(plugin.getDataFolder(), "config.yml");

        if (!configFile.exists()) {
            try {
                Tasks.copy(plugin.getResourceAsStream("config.yml"), configFile);
            } catch (IOException ex) {
                GroupManager.logger.log(Level.SEVERE, null, ex);
            }
        }

        GMconfig = new YamlConfiguration();
        
        try {
        	GMconfig.load(configFile);
        } catch (Exception ex) {
            throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + configFile.getPath(), ex);
        }
        
        // Setup defaults
        adjustLoggerLevel();
        plugin.setValidateOnlinePlayer(isToggleValidate());
    }
    
    public boolean isOpOverride() {
    	return GMconfig.getBoolean("settings.config.opOverrides", true);
    }
    public boolean isBukkitPermsOverride() {
    	return GMconfig.getBoolean("settings.config.bukkit_perms_override", false);
    }
    public boolean isToggleValidate() {
    	return GMconfig.getBoolean("settings.config.validate_toggle", true);
    }

	public Map<String, Object> getMirrorsMap() {   
    	// Try to fetch the old mirror path first		
		if (GMconfig.isConfigurationSection("settings.permission.world.mirror"))
			return (Map<String, Object>) GMconfig.getConfigurationSection("settings.permission.world.mirror").getValues(false);
		else
			return (Map<String, Object>) GMconfig.getConfigurationSection("settings.mirrors").getValues(false);
		
    }

    public Integer getSaveInterval() {   	
    	return GMconfig.getInt("settings.data.save.minutes", 10);
    }
    
    public Integer getBackupDuration() {   	
    	return GMconfig.getInt("settings.data.save.hours", 24);
    }

    public void adjustLoggerLevel() {
    	
    	try {
            GroupManager.logger.setLevel(Level.parse(GMconfig.getString("settings.logging.level", "INFO")));
            return;
        } catch (Exception e) {
        }
    	
    	GroupManager.logger.setLevel(Level.INFO);
    }
}