16.7_dev-3 repo release

ConfigWriter
- add List & "" to String
- fix forceSet
This commit is contained in:
JaTiTV 2024-07-03 00:01:02 +02:00
parent 2f168197fe
commit e9a43889cb
6 changed files with 91 additions and 78 deletions

View File

@ -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-->

View File

@ -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,11 +39,14 @@ public class T2CBconfigWriter {
Map<String, List<String>> comments = new LinkedHashMap<>();
for(T2CconfigItem item : values){
if (item.getForceSet() || !exist) {
if(!config.contains(item.getPath())){
config.set(item.getPath(), item.getValue());
}
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");
}
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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>'."),
;

View File

@ -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);
}
}
*/
}

View File

@ -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();
@ -34,10 +32,13 @@ public class T2CVconfigWriter {
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);
}
@ -128,7 +129,6 @@ public class T2CVconfigWriter {
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");
}
}
}
}