feat: switch to jackson for YAML config parsing
This commit is contained in:
parent
bf09e24c4b
commit
bf46564e46
5 changed files with 71 additions and 34 deletions
|
@ -35,6 +35,8 @@
|
|||
<include>net.wesjd:anvilgui</include>
|
||||
<include>de.studiocode.invui:*</include>
|
||||
<include>com.github.jsixface:*</include>
|
||||
<include>com.fasterxml.jackson.dataformat</include>
|
||||
<include>com.fasterxml.jackson.core</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
|
@ -50,6 +52,14 @@
|
|||
<pattern>com.github.jsixface</pattern>
|
||||
<shadedPattern>net.artelnatif.libs.yaml</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.fasterxml.jackson.dataformat</pattern>
|
||||
<shadedPattern>net.artelnatif.libs.jackson.yaml</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.fasterxml.jackson.core</pattern>
|
||||
<shadedPattern>net.artelnatif.libs.jackson.core</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<minimizeJar>false</minimizeJar>
|
||||
</configuration>
|
||||
|
|
|
@ -111,6 +111,18 @@
|
|||
<artifactId>yamlconfig</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>2.14.0-rc1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
<version>2.14.0-rc1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -136,6 +148,8 @@
|
|||
<include>net.wesjd:anvilgui</include>
|
||||
<include>de.studiocode.invui:*</include>
|
||||
<include>com.github.jsixface:*</include>
|
||||
<include>com.fasterxml.jackson.dataformat</include>
|
||||
<include>com.fasterxml.jackson.core</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
|
@ -151,6 +165,14 @@
|
|||
<pattern>com.github.jsixface</pattern>
|
||||
<shadedPattern>net.artelnatif.libs.yaml</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.fasterxml.jackson.dataformat</pattern>
|
||||
<shadedPattern>net.artelnatif.libs.jackson.yaml</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.fasterxml.jackson.core</pattern>
|
||||
<shadedPattern>net.artelnatif.libs.jackson.core</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<!-- Prevents breaking AnvilGUI's VersionWrapper. -->
|
||||
<minimizeJar>false</minimizeJar>
|
||||
|
|
|
@ -7,4 +7,8 @@ public record Configuration(
|
|||
String prefix,
|
||||
Boolean local,
|
||||
Boolean bungeecord,
|
||||
Boolean customLocale) { }
|
||||
Boolean customLocale) {
|
||||
public Configuration() {
|
||||
this("", "", "", "", false, false, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package net.artelnatif.nicko.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||
import net.artelnatif.nicko.Nicko;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
|
@ -9,7 +10,7 @@ import java.nio.file.StandardCopyOption;
|
|||
|
||||
public class ConfigurationManager {
|
||||
private final Nicko nicko;
|
||||
private final Yaml yaml = new Yaml();
|
||||
private final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
|
||||
private final File directory;
|
||||
private final File file;
|
||||
|
||||
|
@ -21,17 +22,20 @@ public class ConfigurationManager {
|
|||
|
||||
public void save(Configuration configuration) throws IOException {
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
|
||||
yaml.dump(configuration, writer);
|
||||
mapper.writeValue(writer, configuration);
|
||||
writer.flush();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveDefaultConfig() {
|
||||
if (!file.exists()) {
|
||||
System.out.println("FILE DOES NOT EXISTS");
|
||||
try {
|
||||
final InputStream input = ConfigurationManager.class.getResourceAsStream("config.yml");
|
||||
final InputStream input = getClass().getResourceAsStream("/config.yml");
|
||||
if (input != null) {
|
||||
nicko.getLogger().info("Saved default configuration as config.yml");
|
||||
Files.createDirectories(file.getParentFile().toPath());
|
||||
Files.createFile(file.toPath());
|
||||
Files.copy(input, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -42,7 +46,7 @@ public class ConfigurationManager {
|
|||
|
||||
public Configuration load() throws IOException {
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||
return yaml.loadAs(reader, Configuration.class);
|
||||
return mapper.readValue(reader, Configuration.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
# GENERAL #
|
||||
###########
|
||||
|
||||
common:
|
||||
storage:
|
||||
# SQL database's address
|
||||
# Accepted values: valid IP address (e.g. localhost, 127.0.0.1)
|
||||
address: "localhost"
|
||||
|
@ -29,7 +27,6 @@ common:
|
|||
# BUKKIT/SPIGOT #
|
||||
#################
|
||||
|
||||
bukkit:
|
||||
# Nicko's messages prefix.
|
||||
# Accepted values: any string
|
||||
prefix: "§8[§6Nicko§8] "
|
||||
|
|
Loading…
Reference in a new issue