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>
|
<groupId>net.t2code</groupId>
|
||||||
<artifactId>T2CodeLib</artifactId>
|
<artifactId>T2CodeLib</artifactId>
|
||||||
<version>16.7_dev-2</version>
|
<version>16.7_dev-3</version>
|
||||||
<!--version>VERSION_snapshot-0</version-->
|
<!--version>VERSION_snapshot-0</version-->
|
||||||
<!--version>VERSION_beta-0</version-->
|
<!--version>VERSION_beta-0</version-->
|
||||||
<!--version>VERSION_dev-0</version-->
|
<!--version>VERSION_dev-0</version-->
|
||||||
|
@ -20,7 +20,8 @@ public class T2CBconfigWriter {
|
|||||||
|
|
||||||
|
|
||||||
public static void createConfig(File configFile, T2CconfigItem[] values, String... header) {
|
public static void createConfig(File configFile, T2CconfigItem[] values, String... header) {
|
||||||
if (!configFile.exists()) {
|
boolean exist = configFile.exists();
|
||||||
|
if (!exist) {
|
||||||
configFile.getParentFile().mkdirs();
|
configFile.getParentFile().mkdirs();
|
||||||
try {
|
try {
|
||||||
configFile.createNewFile();
|
configFile.createNewFile();
|
||||||
@ -38,11 +39,14 @@ public class T2CBconfigWriter {
|
|||||||
Map<String, List<String>> comments = new LinkedHashMap<>();
|
Map<String, List<String>> comments = new LinkedHashMap<>();
|
||||||
|
|
||||||
for(T2CconfigItem item : values){
|
for(T2CconfigItem item : values){
|
||||||
|
if (item.getForceSet() || !exist) {
|
||||||
if(!config.contains(item.getPath())){
|
if(!config.contains(item.getPath())){
|
||||||
config.set(item.getPath(), item.getValue());
|
config.set(item.getPath(), item.getValue());
|
||||||
}
|
}
|
||||||
comments.put(item.getPath(), item.getComments());
|
comments.put(item.getPath(), item.getComments());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
saveConfigWithComments(configFile, comments, header);
|
saveConfigWithComments(configFile, comments, header);
|
||||||
readConfig(config,values);
|
readConfig(config,values);
|
||||||
}
|
}
|
||||||
@ -93,7 +97,21 @@ public class T2CBconfigWriter {
|
|||||||
addSection((Configuration) value, comments, builder, fullKey, indentLevel + 1);
|
addSection((Configuration) value, comments, builder, fullKey, indentLevel + 1);
|
||||||
} else {
|
} else {
|
||||||
// Add value with proper indentation
|
// 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);
|
config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
Map<String, List<String>> comments = new LinkedHashMap<>();
|
Map<String, List<String>> comments = new LinkedHashMap<>();
|
||||||
|
|
||||||
for (T2CconfigItem value : values) {
|
for (T2CconfigItem item : values) {
|
||||||
if ((value.getForceSet() && exist) || (!exist && !value.getForceSet())) {
|
if (item.getForceSet() || !exist) {
|
||||||
config.addDefault(value.getPath(), value.getValue());
|
config.addDefault(item.getPath(), item.getValue());
|
||||||
comments.put(value.getPath(), value.getComments());
|
comments.put(item.getPath(), item.getComments());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +93,19 @@ public class T2CconfigWriter {
|
|||||||
addSection((ConfigurationSection) value, comments, builder, fullKey, indentLevel + 1);
|
addSection((ConfigurationSection) value, comments, builder, fullKey, indentLevel + 1);
|
||||||
} else {
|
} else {
|
||||||
// Add value with proper indentation
|
// 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.SPIGOT.system.T2CodeLibMain;
|
||||||
import net.t2code.t2codelib.T2CconfigItem;
|
import net.t2code.t2codelib.T2CconfigItem;
|
||||||
import net.t2code.t2codelib.Util;
|
import net.t2code.t2codelib.Util;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -44,14 +46,6 @@ public class T2CLibConfig {
|
|||||||
|
|
||||||
space_command("command", null, true,""),
|
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]",
|
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>'."),
|
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 class T2CVconfigWriter {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void createConfig(Logger logger, File configFile, T2CconfigItem[] manager, String... header) throws IOException {
|
public static void createConfig(Logger logger, File configFile, T2CconfigItem[] manager, String... header) throws IOException {
|
||||||
|
boolean exist = configFile.exists();
|
||||||
if (!configFile.exists()) {
|
if (!exist) {
|
||||||
configFile.getParentFile().mkdirs();
|
configFile.getParentFile().mkdirs();
|
||||||
try {
|
try {
|
||||||
configFile.createNewFile();
|
configFile.createNewFile();
|
||||||
@ -34,10 +32,13 @@ public class T2CVconfigWriter {
|
|||||||
if (config == null) {
|
if (config == null) {
|
||||||
config = new LinkedHashMap<>();
|
config = new LinkedHashMap<>();
|
||||||
}
|
}
|
||||||
for(T2CconfigItem value : manager){
|
for (T2CconfigItem item : manager) {
|
||||||
readValue(config,value.getPath(), value);
|
if (item.getForceSet() || !exist) {
|
||||||
addValue(config, value.getPath(), value.getValue());
|
readValue(config, item.getPath(), item);
|
||||||
comments.put(value.getPath(), value.getComments());
|
addValue(config, item.getPath(), item.getValue());
|
||||||
|
comments.put(item.getPath(), item.getComments());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
saveConfigWithComments(configFile, comments, config, header);
|
saveConfigWithComments(configFile, comments, config, header);
|
||||||
}
|
}
|
||||||
@ -128,7 +129,6 @@ public class T2CVconfigWriter {
|
|||||||
builder.append(indent).append("# ").append(c).append("\n");
|
builder.append(indent).append("# ").append(c).append("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the value is a section (nested map)
|
// Check if the value is a section (nested map)
|
||||||
if (value instanceof Map) {
|
if (value instanceof Map) {
|
||||||
// Correctly add the section
|
// Correctly add the section
|
||||||
@ -136,7 +136,20 @@ public class T2CVconfigWriter {
|
|||||||
addSection((Map<String, Object>) value, comments, builder, fullKey, indentLevel + 1);
|
addSection((Map<String, Object>) value, comments, builder, fullKey, indentLevel + 1);
|
||||||
} else {
|
} else {
|
||||||
// Add value with proper indentation
|
// 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