16.7_dev-3 repo release
ConfigWriter - add List & "" to String - fix forceSet
This commit is contained in:
parent
2f168197fe
commit
e9a43889cb
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>net.t2code</groupId>
|
||||
<artifactId>T2CodeLib</artifactId>
|
||||
<version>16.7_dev-2</version>
|
||||
<version>16.7_dev-3</version>
|
||||
<!--version>VERSION_snapshot-0</version-->
|
||||
<!--version>VERSION_beta-0</version-->
|
||||
<!--version>VERSION_dev-0</version-->
|
||||
|
@ -20,7 +20,8 @@ public class T2CBconfigWriter {
|
||||
|
||||
|
||||
public static void createConfig(File configFile, T2CconfigItem[] values, String... header) {
|
||||
if (!configFile.exists()) {
|
||||
boolean exist = configFile.exists();
|
||||
if (!exist) {
|
||||
configFile.getParentFile().mkdirs();
|
||||
try {
|
||||
configFile.createNewFile();
|
||||
@ -38,10 +39,13 @@ public class T2CBconfigWriter {
|
||||
Map<String, List<String>> comments = new LinkedHashMap<>();
|
||||
|
||||
for(T2CconfigItem item : values){
|
||||
if(!config.contains(item.getPath())){
|
||||
config.set(item.getPath(), item.getValue());
|
||||
if (item.getForceSet() || !exist) {
|
||||
if(!config.contains(item.getPath())){
|
||||
config.set(item.getPath(), item.getValue());
|
||||
}
|
||||
comments.put(item.getPath(), item.getComments());
|
||||
}
|
||||
comments.put(item.getPath(), item.getComments());
|
||||
|
||||
}
|
||||
saveConfigWithComments(configFile, comments, header);
|
||||
readConfig(config,values);
|
||||
@ -93,7 +97,21 @@ public class T2CBconfigWriter {
|
||||
addSection((Configuration) value, comments, builder, fullKey, indentLevel + 1);
|
||||
} else {
|
||||
// Add value with proper indentation
|
||||
builder.append(indent).append(key).append(": ").append(value).append("\n");
|
||||
// builder.append(indent).append(key).append(": ").append(value).append("\n");
|
||||
if (value instanceof List) {
|
||||
builder.append(indent).append(key).append(": ").append("\n");
|
||||
List<Object> zw = (List<Object>) value;
|
||||
for (Object s : zw) {
|
||||
if (s instanceof String) {
|
||||
builder.append(indent).append("- \"").append(s).append("\"\n");
|
||||
} else builder.append(indent).append("- ").append(s).append("\n");
|
||||
}
|
||||
} else {
|
||||
if (value instanceof String) {
|
||||
builder.append(indent).append(key).append(": \"").append(value).append("\"\n");
|
||||
} else builder.append(indent).append(key).append(": ").append(value).append("\n");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,10 +34,10 @@ public class T2CconfigWriter {
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
Map<String, List<String>> comments = new LinkedHashMap<>();
|
||||
|
||||
for (T2CconfigItem value : values) {
|
||||
if ((value.getForceSet() && exist) || (!exist && !value.getForceSet())) {
|
||||
config.addDefault(value.getPath(), value.getValue());
|
||||
comments.put(value.getPath(), value.getComments());
|
||||
for (T2CconfigItem item : values) {
|
||||
if (item.getForceSet() || !exist) {
|
||||
config.addDefault(item.getPath(), item.getValue());
|
||||
comments.put(item.getPath(), item.getComments());
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,7 +93,19 @@ public class T2CconfigWriter {
|
||||
addSection((ConfigurationSection) value, comments, builder, fullKey, indentLevel + 1);
|
||||
} else {
|
||||
// Add value with proper indentation
|
||||
builder.append(indent).append(key).append(": ").append(value).append("\n");
|
||||
if (value instanceof List) {
|
||||
builder.append(indent).append(key).append(": ").append("\n");
|
||||
List<Object> zw = (List<Object>) value;
|
||||
for (Object s : zw) {
|
||||
if (s instanceof String) {
|
||||
builder.append(indent).append("- \"").append(s).append("\"\n");
|
||||
} else builder.append(indent).append("- ").append(s).append("\n");
|
||||
}
|
||||
} else {
|
||||
if (value instanceof String) {
|
||||
builder.append(indent).append(key).append(": \"").append(value).append("\"\n");
|
||||
} else builder.append(indent).append(key).append(": ").append(value).append("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ import net.t2code.t2codelib.SPIGOT.api.yaml.T2CconfigWriter;
|
||||
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
||||
import net.t2code.t2codelib.T2CconfigItem;
|
||||
import net.t2code.t2codelib.Util;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -44,14 +46,6 @@ public class T2CLibConfig {
|
||||
|
||||
space_command("command", null, true,""),
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
test("opWhitelist.whitelist", null, true,"Test"),
|
||||
testp1n("opWhitelist.whitelist.player1.name", "PlayerName", false,"Test"),
|
||||
testp1u("opWhitelist.whitelist.player1.uuid", "00000000000000000000000000000000", false,"Test"),
|
||||
|
||||
commandPermToggleCommand("command.permToggle.permissionSetCommand", "lp user [player] permission set [perm] [value]",
|
||||
true,"This option specifies which command is to be used for the T2CodeLib command '/t2code permtoggle <player> <permission>'."),
|
||||
;
|
||||
|
@ -1,24 +0,0 @@
|
||||
// This class was created by JaTiTV.
|
||||
|
||||
package net.t2code.t2codelib.SPIGOT.system.config.config;
|
||||
|
||||
import net.t2code.t2codelib.T2CconfigItem;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class test {
|
||||
|
||||
/**
|
||||
public void test(){
|
||||
ConfigurationSection test = (ConfigurationSection) T2CLibConfig.VALUES.test.getValue();
|
||||
for (String key : test.getConfigurationSection("").getKeys(false)) {
|
||||
String name = test.getString(key + ".Playername");//value.pathPlayerName.replace("KEY", key));
|
||||
PlayerObject playerObject = new PlayerObject(
|
||||
name,
|
||||
test.getString(key + ".UUID")//value.pathPlayerUuid.replace("KEY", key)).replace("-", ""));
|
||||
PlayerCache.getOpHashMap().put(name, playerObject);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
@ -14,11 +14,9 @@ import java.util.Map;
|
||||
|
||||
public class T2CVconfigWriter {
|
||||
|
||||
|
||||
|
||||
public static void createConfig(Logger logger, File configFile, T2CconfigItem[] manager, String... header) throws IOException {
|
||||
|
||||
if (!configFile.exists()) {
|
||||
boolean exist = configFile.exists();
|
||||
if (!exist) {
|
||||
configFile.getParentFile().mkdirs();
|
||||
try {
|
||||
configFile.createNewFile();
|
||||
@ -29,78 +27,81 @@ public class T2CVconfigWriter {
|
||||
}
|
||||
|
||||
Yaml yaml = new Yaml();
|
||||
Map<String,Object> config = yaml.load(Files.newInputStream(configFile.toPath()));
|
||||
Map<String, Object> config = yaml.load(Files.newInputStream(configFile.toPath()));
|
||||
Map<String, List<String>> comments = new LinkedHashMap<>();
|
||||
if(config == null){
|
||||
if (config == null) {
|
||||
config = new LinkedHashMap<>();
|
||||
}
|
||||
for(T2CconfigItem value : manager){
|
||||
readValue(config,value.getPath(), value);
|
||||
addValue(config, value.getPath(), value.getValue());
|
||||
comments.put(value.getPath(), value.getComments());
|
||||
for (T2CconfigItem item : manager) {
|
||||
if (item.getForceSet() || !exist) {
|
||||
readValue(config, item.getPath(), item);
|
||||
addValue(config, item.getPath(), item.getValue());
|
||||
comments.put(item.getPath(), item.getComments());
|
||||
}
|
||||
|
||||
}
|
||||
saveConfigWithComments(configFile, comments,config, header);
|
||||
saveConfigWithComments(configFile, comments, config, header);
|
||||
}
|
||||
|
||||
private static void readValue(Map<String, Object> config, String path, T2CconfigItem value) {
|
||||
if(path.contains(".")){
|
||||
if (path.contains(".")) {
|
||||
String[] pathsplit = path.split("\\.");
|
||||
String key = pathsplit[0];
|
||||
if(config.containsKey(key)){
|
||||
if (config.containsKey(key)) {
|
||||
StringBuilder zw = new StringBuilder();
|
||||
for(int i=1; i<pathsplit.length;i++){
|
||||
for (int i = 1; i < pathsplit.length; i++) {
|
||||
zw.append(pathsplit[i]);
|
||||
if(i!= (pathsplit.length-1)){
|
||||
if (i != (pathsplit.length - 1)) {
|
||||
zw.append(".");
|
||||
}
|
||||
}
|
||||
readValue((Map<String, Object>) config.get(key),zw.toString(), value);
|
||||
readValue((Map<String, Object>) config.get(key), zw.toString(), value);
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
Object vl = config.get(path);
|
||||
if(vl != null){
|
||||
if (vl != null) {
|
||||
value.setValue(vl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void addValue(Map<String, Object> config, String path, Object value) {
|
||||
if(path.contains(".")){
|
||||
if (path.contains(".")) {
|
||||
String[] pathsplit = path.split("\\.");
|
||||
String key = pathsplit[0];
|
||||
if(config.containsKey(key)){
|
||||
if (config.containsKey(key)) {
|
||||
StringBuilder zw = new StringBuilder();
|
||||
for(int i=1; i<pathsplit.length;i++){
|
||||
for (int i = 1; i < pathsplit.length; i++) {
|
||||
zw.append(pathsplit[i]);
|
||||
if(i!= (pathsplit.length-1)){
|
||||
if (i != (pathsplit.length - 1)) {
|
||||
zw.append(".");
|
||||
}
|
||||
}
|
||||
addValue((Map<String, Object>) config.get(key),zw.toString(),value);
|
||||
}else{
|
||||
addValue((Map<String, Object>) config.get(key), zw.toString(), value);
|
||||
} else {
|
||||
Map<String, Object> newMap = new LinkedHashMap<>();
|
||||
StringBuilder zw = new StringBuilder();
|
||||
for(int i=1; i<pathsplit.length;i++){
|
||||
for (int i = 1; i < pathsplit.length; i++) {
|
||||
zw.append(pathsplit[i]);
|
||||
if(i!= (pathsplit.length-1)){
|
||||
if (i != (pathsplit.length - 1)) {
|
||||
zw.append(".");
|
||||
}
|
||||
}
|
||||
addValue(newMap,zw.toString(),value);
|
||||
addValue(newMap, zw.toString(), value);
|
||||
config.put(key, newMap);
|
||||
}
|
||||
}else{
|
||||
if(!config.containsKey(path)){
|
||||
} else {
|
||||
if (!config.containsKey(path)) {
|
||||
config.put(path, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void saveConfigWithComments(File file, Map<String, List<String>> comments, Map<String,Object> config, String... headers) {
|
||||
private static void saveConfigWithComments(File file, Map<String, List<String>> comments, Map<String, Object> config, String... headers) {
|
||||
try {
|
||||
StringBuilder configContent = new StringBuilder();
|
||||
for(String h : headers){
|
||||
for (String h : headers) {
|
||||
configContent.append(h).append("\n");
|
||||
}
|
||||
configContent.append("\n");
|
||||
@ -113,7 +114,7 @@ public class T2CVconfigWriter {
|
||||
}
|
||||
}
|
||||
|
||||
private static void addSection(Map<String,Object> config, Map<String, List<String>> comments, StringBuilder builder, String prefix, int indentLevel) {
|
||||
private static void addSection(Map<String, Object> config, Map<String, List<String>> comments, StringBuilder builder, String prefix, int indentLevel) {
|
||||
String indent = " ".repeat(indentLevel);
|
||||
|
||||
|
||||
@ -124,11 +125,10 @@ public class T2CVconfigWriter {
|
||||
// Add comment if it exists for this key
|
||||
List<String> commentList = comments.get(fullKey);
|
||||
if (commentList != null) {
|
||||
for(String c : commentList){
|
||||
for (String c : commentList) {
|
||||
builder.append(indent).append("# ").append(c).append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the value is a section (nested map)
|
||||
if (value instanceof Map) {
|
||||
// Correctly add the section
|
||||
@ -136,7 +136,20 @@ public class T2CVconfigWriter {
|
||||
addSection((Map<String, Object>) value, comments, builder, fullKey, indentLevel + 1);
|
||||
} else {
|
||||
// Add value with proper indentation
|
||||
builder.append(indent).append(key.getKey()).append(": ").append(value).append("\n");
|
||||
// builder.append(indent).append(key.getKey()).append(": ").append(value).append("\n");
|
||||
if (value instanceof List) {
|
||||
builder.append(indent).append(key).append(": ").append("\n");
|
||||
List<Object> zw = (List<Object>) value;
|
||||
for (Object s : zw) {
|
||||
if (s instanceof String) {
|
||||
builder.append(indent).append("- \"").append(s).append("\"\n");
|
||||
} else builder.append(indent).append("- ").append(s).append("\n");
|
||||
}
|
||||
} else {
|
||||
if (value instanceof String) {
|
||||
builder.append(indent).append(key).append(": \"").append(value).append("\"\n");
|
||||
} else builder.append(indent).append(key).append(": ").append(value).append("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user