Fix bug in Configuration inialization and Configuration#load(String content) that was passing content as file path on 1.21 implementation.
This commit is contained in:
parent
632993678e
commit
6ef06b1c4d
3 changed files with 11 additions and 6 deletions
|
|
@ -17,6 +17,7 @@ public class Configuration implements org.adrianvictor.lib.configuration.provide
|
|||
@Override
|
||||
public void load(File file) {
|
||||
config = new org.bukkit.util.config.Configuration(file);
|
||||
config.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ public class File implements FileProvider {
|
|||
java.io.File file = new java.io.File(plugin.getDataFolder(), resourcePath);
|
||||
|
||||
if (!file.exists() || replace) {
|
||||
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
InputStream in = plugin.getClass().getResourceAsStream("/" + resourcePath);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
public class Configuration implements org.adrianvictor.lib.configuration.provider.ConfigurationProvider {
|
||||
|
|
@ -24,11 +28,12 @@ public class Configuration implements org.adrianvictor.lib.configuration.provide
|
|||
|
||||
@Override
|
||||
public void load(String contents) throws IOException, org.adrianvictor.lib.configuration.exception.InvalidConfigurationException {
|
||||
try {
|
||||
config.load(contents);
|
||||
} catch (InvalidConfigurationException e) {
|
||||
throw new org.adrianvictor.lib.configuration.exception.InvalidConfigurationException(e.getMessage());
|
||||
}
|
||||
String timestamp = LocalDateTime.now()
|
||||
.format(DateTimeFormatter.ofPattern("HH-mm-dd-MM-yyyy"));
|
||||
Path temp = Files.createTempFile("tlib-configprovider-tmp-%s".formatted(timestamp), ".yml");
|
||||
Files.writeString(temp, contents);
|
||||
File file = temp.toFile();
|
||||
load(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue