-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigHandler.java
More file actions
119 lines (100 loc) · 4.21 KB
/
ConfigHandler.java
File metadata and controls
119 lines (100 loc) · 4.21 KB
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
package simplexity.adminhax.config;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import simplexity.adminhax.AdminHax;
import java.util.HashSet;
import java.util.List;
import java.util.logging.Logger;
public class ConfigHandler {
private static ConfigHandler instance;
private final Logger logger = AdminHax.getInstance().getLogger();
private ConfigHandler() {
}
public static ConfigHandler getInstance() {
if (instance == null) instance = new ConfigHandler();
return instance;
}
private float maxWalkSpeed, minWalkSpeed, maxFlySpeed, minFlySpeed;
private boolean sessionPersistentFlight, worldChangePersistentFlight, respawnPersistentFlight,
gamemodeChangePersistentFlight, respectBindingCurse;
private int maxRenameCharacters;
private static final HashSet<Material> disabledHatItems = new HashSet<>();
public void reloadConfigValues() {
AdminHax.getInstance().reloadConfig();
FileConfiguration config = AdminHax.getInstance().getConfig();
maxWalkSpeed = checkFloat(10, "speed.walk.max", config);
minWalkSpeed = checkFloat(-10, "speed.walk.min", config);
maxFlySpeed = checkFloat(10, "speed.fly.max", config);
minFlySpeed = checkFloat(-10, "speed.fly.min", config);
sessionPersistentFlight = config.getBoolean("flight.persistent.session", true);
worldChangePersistentFlight = config.getBoolean("flight.persistent.world-change", true);
respawnPersistentFlight = config.getBoolean("flight.persistent.respawn", true);
gamemodeChangePersistentFlight = config.getBoolean("flight.persistent.gamemode-change", true);
maxRenameCharacters = config.getInt("rename.max-characters", 50);
respectBindingCurse = config.getBoolean("hat.respect-curse-of-binding", true);
List<String> disabledItems = config.getStringList("hat.disabled-items");
disabledHatItems.clear();
if (!disabledItems.isEmpty()) {
for (String disabledItem : disabledItems) {
Material itemType = Material.getMaterial(disabledItem);
if (itemType == null) {
logger.info(disabledItem + " is not a valid material, please check your syntax");
continue;
}
disabledHatItems.add(itemType);
}
}
}
private float checkFloat(float defaultValue, String configPath, FileConfiguration config) {
String configString = config.getString(configPath);
if (configString == null) {
logger.warning("Value at " + configPath + " is null, please configure this value. Setting to default value.");
return defaultValue;
}
float configFloat;
try {
configFloat = Float.parseFloat(configString);
} catch (NumberFormatException e) {
logger.warning("Value at " + configPath + " is not a number, please configure this value. Setting to default value.");
return defaultValue;
}
if (configFloat > 10.0 || configFloat < -10.0) {
logger.warning("Value for " + configPath + " is out of range (-10.0 to 10.0). Setting to default value");
return defaultValue;
}
return configFloat;
}
public float getMaxWalkSpeed() {
return maxWalkSpeed;
}
public float getMinWalkSpeed() {
return minWalkSpeed;
}
public float getMaxFlySpeed() {
return maxFlySpeed;
}
public float getMinFlySpeed() {
return minFlySpeed;
}
public boolean isSessionPersistentFlight() {
return sessionPersistentFlight;
}
public boolean isWorldChangePersistentFlight() {
return worldChangePersistentFlight;
}
public boolean isRespawnPersistentFlight() {
return respawnPersistentFlight;
}
public boolean isGamemodeChangePersistentFlight() {
return gamemodeChangePersistentFlight;
}
public int getMaxRenameCharacters() {
return maxRenameCharacters;
}
public boolean shouldRespectBindingCurse() {
return respectBindingCurse;
}
public HashSet<Material> getDisabledHatItems(){
return disabledHatItems;
}
}