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