Repository navigation
Expand file tree
/
Copy pathTestSimple.java
More file actions
55 lines (45 loc) · 2.08 KB
/
Copy pathTestSimple.java
File metadata and controls
55 lines (45 loc) · 2.08 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
import cn.elytra.nightconfig.Configuration;
import com.electronwill.nightconfig.core.EnumGetMethod;
import net.neoforged.neoforge.common.ModConfigSpec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.file.Paths;
import java.time.format.TextStyle;
import java.util.List;
import static cn.elytra.nightconfig.internal.Utils.newArrayListOf;
public class TestSimple {
private static final Logger log = LoggerFactory.getLogger(TestSimple.class);
@SuppressWarnings({"ConditionalBreakInInfiniteLoop", "BusyWait"})
public static void main(String[] args) throws InterruptedException {
ModConfigSpec.Builder b = new ModConfigSpec.Builder();
ModConfigSpec.BooleanValue foo = b
.comment("The FOO flag")
.translation("config.foo.key")
.define("foo", true);
ModConfigSpec.ConfigValue<Integer> bar = b
.comment("The BAR magic code")
.define("bar", 42);
ModConfigSpec.ConfigValue<List<? extends String>> baz = b
.comment("The BAZ list of String")
.defineList("baz", newArrayListOf("Hello", "Bonjour"), String::new, String.class::isInstance);
b.comment("This is a NESTED section?!").push("nest");
ModConfigSpec.EnumValue<TextStyle> nestedEnum = b
.comment("Some random enum?")
.defineEnum("enum", TextStyle.FULL, EnumGetMethod.ORDINAL_OR_NAME);
ModConfigSpec.IntValue nestedInt = b
.comment("Yet another Integer")
.defineInRange("int", 1, -1, 114514);
b.pop();
ModConfigSpec spec = b.build();
Configuration.openConfig(spec, Paths.get("config", "1.toml"));
log.info("FOO {} BAR {} BAZ {} N_ENUM {} N_INT {}", foo.get(), bar.get(), String.join(",", baz.get()), nestedEnum.get().name(), nestedInt.get());
while (true) {
Thread.sleep(1000);
log.info("BAR now: {}", bar.get());
if (bar.get() == 1024) {
break;
}
}
Configuration.unloadConfig(spec);
}
}