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
|
@ -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,39 +13,36 @@
|
|||
# GENERAL #
|
||||
###########
|
||||
|
||||
common:
|
||||
storage:
|
||||
# SQL database's address
|
||||
# Accepted values: valid IP address (e.g. localhost, 127.0.0.1)
|
||||
address: "localhost"
|
||||
# SQL database's username.
|
||||
# Accepted values: any string
|
||||
username: ""
|
||||
# SQL database's password.
|
||||
# Accepted values: any string
|
||||
password: ""
|
||||
# SQL database's address
|
||||
# Accepted values: valid IP address (e.g. localhost, 127.0.0.1)
|
||||
address: "localhost"
|
||||
# SQL database's username.
|
||||
# Accepted values: any string
|
||||
username: ""
|
||||
# SQL database's password.
|
||||
# Accepted values: any string
|
||||
password: ""
|
||||
|
||||
#################
|
||||
# BUKKIT/SPIGOT #
|
||||
#################
|
||||
|
||||
bukkit:
|
||||
# Nicko's messages prefix.
|
||||
# Accepted values: any string
|
||||
prefix: "§8[§6Nicko§8] "
|
||||
# Nicko's messages prefix.
|
||||
# Accepted values: any string
|
||||
prefix: "§8[§6Nicko§8] "
|
||||
|
||||
# Indicates wherever the data will be stored
|
||||
# locally through a .json file or a (My)SQL database.
|
||||
# Accepted values: false (Disabled), true (Enabled)
|
||||
local: true
|
||||
# Indicates wherever the data will be stored
|
||||
# locally through a .json file or a (My)SQL database.
|
||||
# Accepted values: false (Disabled), true (Enabled)
|
||||
local: true
|
||||
|
||||
# Enables Bungeecord support, switching
|
||||
# servers will transfer player's disguise.
|
||||
# Accepted values: false (Disabled), true (Enabled)
|
||||
bungeecord: false
|
||||
# Enables Bungeecord support, switching
|
||||
# servers will transfer player's disguise.
|
||||
# Accepted values: false (Disabled), true (Enabled)
|
||||
bungeecord: false
|
||||
|
||||
# Nicko will copy the English locale as "lang.yml"
|
||||
# and will use the translations in that file when "Server Custom"
|
||||
# is selected as the player's locale.
|
||||
# Accepted values: false (Disabled), true (Enabled)
|
||||
customLocale: false
|
||||
# Nicko will copy the English locale as "lang.yml"
|
||||
# and will use the translations in that file when "Server Custom"
|
||||
# is selected as the player's locale.
|
||||
# Accepted values: false (Disabled), true (Enabled)
|
||||
customLocale: false
|
Loading…
Add table
Add a link
Reference in a new issue