-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathConfigImpl.java
39 lines (32 loc) · 1.01 KB
/
ConfigImpl.java
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
package me.earth.headlessmc.config;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import me.earth.headlessmc.api.config.Config;
import me.earth.headlessmc.api.config.Property;
import java.util.Properties;
import java.util.function.Supplier;
@RequiredArgsConstructor
public class ConfigImpl implements Config {
private final Properties properties;
@Getter
private final String name;
@Getter
private final int id;
public static Config empty() {
return new ConfigImpl(new Properties(), "empty", -1);
}
@Override
public <T> T getValue(Property<T> property, Supplier<T> defaultValue) {
String value = System.getProperty(property.getName());
if (value == null) {
value = (String) properties.get(property.getName());
if (value == null) {
return defaultValue.get();
}
}
T result = property.parse(value);
return result == null
? defaultValue.get()
: result;
}
}