mirror of
https://e.coding.net/circlecloud/YumCore.git
synced 2024-11-24 02:08:48 +00:00
fix: 1.18.1#133 not compatible
This commit is contained in:
parent
1d1303b31c
commit
bdd54705bb
@ -1,18 +1,8 @@
|
|||||||
package pw.yumc.YumCore.config;
|
package pw.yumc.YumCore.config;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import com.google.common.io.Files;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
@ -20,19 +10,20 @@ import org.yaml.snakeyaml.DumperOptions;
|
|||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
import org.yaml.snakeyaml.error.YAMLException;
|
import org.yaml.snakeyaml.error.YAMLException;
|
||||||
import org.yaml.snakeyaml.representer.Representer;
|
import org.yaml.snakeyaml.representer.Representer;
|
||||||
|
|
||||||
import com.google.common.io.Files;
|
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.bukkit.P;
|
import pw.yumc.YumCore.bukkit.P;
|
||||||
import pw.yumc.YumCore.config.yaml.BukkitConstructor;
|
import pw.yumc.YumCore.config.yaml.BukkitConstructor;
|
||||||
import pw.yumc.YumCore.config.yaml.BukkitRepresenter;
|
import pw.yumc.YumCore.config.yaml.BukkitRepresenter;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 抽象配置文件
|
* 抽象配置文件
|
||||||
*
|
*
|
||||||
* @since 2016年3月12日 下午4:46:45
|
|
||||||
* @author 喵♂呜
|
* @author 喵♂呜
|
||||||
|
* @since 2016年3月12日 下午4:46:45
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractConfig extends YamlConfiguration {
|
public abstract class AbstractConfig extends YamlConfiguration {
|
||||||
private static String CONTENT_NOT_BE_NULL = "内容不能为 null";
|
private static String CONTENT_NOT_BE_NULL = "内容不能为 null";
|
||||||
@ -103,6 +94,72 @@ public abstract class AbstractConfig extends YamlConfiguration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void convertMapsToSections(Map<?, ?> input, ConfigurationSection section) {
|
||||||
|
for (Map.Entry<?, ?> entry : input.entrySet()) {
|
||||||
|
String key = entry.getKey().toString();
|
||||||
|
Object value = entry.getValue();
|
||||||
|
|
||||||
|
if (value instanceof Map) {
|
||||||
|
convertMapsToSections((Map<?, ?>) value, section.createSection(key));
|
||||||
|
} else {
|
||||||
|
section.set(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String parseHeader(String input) {
|
||||||
|
String[] lines = input.split("\r?\n", -1);
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
boolean readingHeader = true;
|
||||||
|
boolean foundHeader = false;
|
||||||
|
|
||||||
|
for (int i = 0; (i < lines.length) && (readingHeader); i++) {
|
||||||
|
String line = lines[i];
|
||||||
|
|
||||||
|
if (line.startsWith(COMMENT_PREFIX)) {
|
||||||
|
if (i > 0) {
|
||||||
|
result.append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.length() > COMMENT_PREFIX.length()) {
|
||||||
|
result.append(line.substring(COMMENT_PREFIX.length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
foundHeader = true;
|
||||||
|
} else if ((foundHeader) && (line.length() == 0)) {
|
||||||
|
result.append("\n");
|
||||||
|
} else if (foundHeader) {
|
||||||
|
readingHeader = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String buildHeader() {
|
||||||
|
String header = options().header();
|
||||||
|
if (header == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
String[] lines = header.split("\r?\n", -1);
|
||||||
|
boolean startedHeader = false;
|
||||||
|
|
||||||
|
for (int i = lines.length - 1; i >= 0; i--) {
|
||||||
|
builder.insert(0, "\n");
|
||||||
|
|
||||||
|
if ((startedHeader) || (lines[i].length() != 0)) {
|
||||||
|
builder.insert(0, lines[i]);
|
||||||
|
builder.insert(0, COMMENT_PREFIX);
|
||||||
|
startedHeader = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(File file) throws IOException {
|
public void save(File file) throws IOException {
|
||||||
Validate.notNull(file, FILE_NOT_BE_NULL);
|
Validate.notNull(file, FILE_NOT_BE_NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user