summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
blob: efae5d2aa2cfc11d6eb868acccff3dee92a763b9 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package net.tylermurphy.hideAndSeek.configuration;

import java.util.Map;
import java.util.Map.Entry;

import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.util.Vector;

import net.tylermurphy.hideAndSeek.Main;

public class Config {
	
	public static String 
		messagePrefix,
		errorPrefix,
		tauntPrefix,
		worldborderPrefix,
		abortPrefix,
		gameoverPrefix,
		warningPrefix,
		spawnWorld,
		exitWorld,
		lobbyWorld;
	
	public static Vector
		spawnPosition,
		lobbyPosition,
		exitPosition,
		worldborderPosition;
	
	public static boolean 
		nametagsVisible,
		permissionsRequired,
		announceMessagesToNonPlayers,
		worldborderEnabled;
	
	public static int 
		minPlayers,
		worldborderSize,
		worldborderDelay,
		currentWorldborderSize,
		gameLength,
		saveMinX,
		saveMinZ,
		saveMaxX,
		saveMaxZ;
	
	public static FileConfiguration getConfig() {
		return Main.plugin.getConfig();
	}
	
	public static void saveConfig() {
		Main.plugin.saveConfig();
	}
	
	public static void loadConfig() {
		
		Main.plugin.reloadConfig();
		
		//Spawn
		spawnPosition = new Vector(
				getConfig().getDouble("spawns.game.x"), 
				Math.max(0,Math.min(255,getConfig().getDouble("spawns.game.y"))),
				getConfig().getDouble("spawns.game.z")
			);
		spawnWorld = getConfig().getString("spawns.game.world");
		
		///Lobby
		lobbyPosition = new Vector(
				getConfig().getDouble("spawns.lobby.x"), 
				Math.max(0,Math.min(255,getConfig().getDouble("spawns.lobby.y"))),
				getConfig().getDouble("spawns.lobby.z")
			);
		lobbyWorld = getConfig().getString("spawns.lobby.world");
		
		announceMessagesToNonPlayers = getConfig().getBoolean("announceMessagesToNonPlayers");
		
		exitPosition = new Vector(
				getConfig().getDouble("spawns.exit.x"), 
				Math.max(0,Math.min(255,getConfig().getDouble("spawns.exit.y"))),
				getConfig().getDouble("spawns.exit.z")
			);
		exitWorld = getConfig().getString("spawns.exit.world");
		
		//World border
		worldborderPosition = new Vector(
				getConfig().getInt("worldBorder.x"), 
				0, 
				getConfig().getInt("worldBorder.z")
			);
		worldborderSize = Math.max(100,getConfig().getInt("worldBorder.size"));
		worldborderDelay = Math.max(1,getConfig().getInt("worldBorder.delay"));
		worldborderEnabled = getConfig().getBoolean("worldBorder.enabled");
		
		//Prefix
		char SYMBOLE = '\u00A7';
		String SYMBOLE_STRING = new String(new char[] {SYMBOLE});
		
		messagePrefix = getConfig().getString("prefix.default").replace("&", SYMBOLE_STRING);
		errorPrefix = getConfig().getString("prefix.error").replace("&", SYMBOLE_STRING);
		tauntPrefix = getConfig().getString("prefix.taunt").replace("&", SYMBOLE_STRING);
		worldborderPrefix = getConfig().getString("prefix.border").replace("&", SYMBOLE_STRING);
		abortPrefix = getConfig().getString("prefix.abort").replace("&", SYMBOLE_STRING);
		gameoverPrefix = getConfig().getString("prefix.gameover").replace("&", SYMBOLE_STRING);
		warningPrefix = getConfig().getString("prefix.warning").replace("&", SYMBOLE_STRING);
		
		//Map Bounds
		saveMinX = getConfig().getInt("bounds.min.x");
		saveMinZ = getConfig().getInt("bounds.min.z");
		saveMaxX = getConfig().getInt("bounds.max.x");
		saveMaxZ = getConfig().getInt("bounds.max.z");
		
		//Other
		nametagsVisible = getConfig().getBoolean("nametagsVisible");
		permissionsRequired = getConfig().getBoolean("permissionsRequired");
		minPlayers = Math.max(2,getConfig().getInt("minPlayers"));
		gameLength = getConfig().getInt("gameLength");
		
		getConfig().options().copyDefaults(true);
		saveConfig();
		
	}
	
	public static void addToSection(String sectionName, Map<String,Object> values) {
		ConfigurationSection section = getConfig().getConfigurationSection(sectionName);
		if(section == null) section = getConfig().createSection(sectionName);
		Map<String,Object> sectionValues = section.getValues(true);
		for(Entry<String, Object> entry : values.entrySet()) {
			sectionValues.put(entry.getKey(), entry.getValue());
		}
		getConfig().createSection(sectionName, sectionValues);
		saveConfig();
	}
	
	public static void addToConfig(String path, Object value) {
		getConfig().set(path, value);
	}
	
}