diff --git a/.gitignore b/.gitignore
index a1c2a23..7dc0dd2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,5 +19,11 @@
*.tar.gz
*.rar
+# Compiler Files #
+build/
+.idea/
+.gradle/
+Configurations.iml
+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
diff --git a/.gradle/7.3.3/checksums/checksums.lock b/.gradle/7.3.3/checksums/checksums.lock
deleted file mode 100644
index f083086..0000000
Binary files a/.gradle/7.3.3/checksums/checksums.lock and /dev/null differ
diff --git a/.gradle/7.3.3/checksums/md5-checksums.bin b/.gradle/7.3.3/checksums/md5-checksums.bin
deleted file mode 100644
index 9a73814..0000000
Binary files a/.gradle/7.3.3/checksums/md5-checksums.bin and /dev/null differ
diff --git a/.gradle/7.3.3/checksums/sha1-checksums.bin b/.gradle/7.3.3/checksums/sha1-checksums.bin
deleted file mode 100644
index 57749d8..0000000
Binary files a/.gradle/7.3.3/checksums/sha1-checksums.bin and /dev/null differ
diff --git a/.gradle/7.3.3/dependencies-accessors/dependencies-accessors.lock b/.gradle/7.3.3/dependencies-accessors/dependencies-accessors.lock
deleted file mode 100644
index b030339..0000000
Binary files a/.gradle/7.3.3/dependencies-accessors/dependencies-accessors.lock and /dev/null differ
diff --git a/.gradle/7.3.3/dependencies-accessors/gc.properties b/.gradle/7.3.3/dependencies-accessors/gc.properties
deleted file mode 100644
index e69de29..0000000
diff --git a/.gradle/7.3.3/executionHistory/executionHistory.bin b/.gradle/7.3.3/executionHistory/executionHistory.bin
deleted file mode 100644
index 8ee3401..0000000
Binary files a/.gradle/7.3.3/executionHistory/executionHistory.bin and /dev/null differ
diff --git a/.gradle/7.3.3/executionHistory/executionHistory.lock b/.gradle/7.3.3/executionHistory/executionHistory.lock
deleted file mode 100644
index 26f37a3..0000000
Binary files a/.gradle/7.3.3/executionHistory/executionHistory.lock and /dev/null differ
diff --git a/.gradle/7.3.3/fileChanges/last-build.bin b/.gradle/7.3.3/fileChanges/last-build.bin
deleted file mode 100644
index f76dd23..0000000
Binary files a/.gradle/7.3.3/fileChanges/last-build.bin and /dev/null differ
diff --git a/.gradle/7.3.3/fileHashes/fileHashes.bin b/.gradle/7.3.3/fileHashes/fileHashes.bin
deleted file mode 100644
index d5f2db4..0000000
Binary files a/.gradle/7.3.3/fileHashes/fileHashes.bin and /dev/null differ
diff --git a/.gradle/7.3.3/fileHashes/fileHashes.lock b/.gradle/7.3.3/fileHashes/fileHashes.lock
deleted file mode 100644
index 12a7cfb..0000000
Binary files a/.gradle/7.3.3/fileHashes/fileHashes.lock and /dev/null differ
diff --git a/.gradle/7.3.3/gc.properties b/.gradle/7.3.3/gc.properties
deleted file mode 100644
index e69de29..0000000
diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock
deleted file mode 100644
index 7e329a8..0000000
Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and /dev/null differ
diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties
deleted file mode 100644
index fa3655c..0000000
--- a/.gradle/buildOutputCleanup/cache.properties
+++ /dev/null
@@ -1,2 +0,0 @@
-#Fri Feb 11 20:42:21 CST 2022
-gradle.version=7.3.3
diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin
deleted file mode 100644
index 234192e..0000000
Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and /dev/null differ
diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe
deleted file mode 100644
index e28ba3e..0000000
Binary files a/.gradle/file-system.probe and /dev/null differ
diff --git a/.gradle/vcs-1/gc.properties b/.gradle/vcs-1/gc.properties
deleted file mode 100644
index e69de29..0000000
diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index 26d3352..0000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
deleted file mode 100644
index b589d56..0000000
--- a/.idea/compiler.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
deleted file mode 100644
index 611e7c8..0000000
--- a/.idea/gradle.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
deleted file mode 100644
index 7ae5ed7..0000000
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
deleted file mode 100644
index 8633eb9..0000000
--- a/.idea/jarRepositories.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index d93202f..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/Configurations.main.iml b/.idea/modules/Configurations.main.iml
deleted file mode 100644
index f5de878..0000000
--- a/.idea/modules/Configurations.main.iml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
- PAPER
- ADVENTURE
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
deleted file mode 100644
index e96534f..0000000
--- a/.idea/uiDesigner.xml
+++ /dev/null
@@ -1,124 +0,0 @@
-
-
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 94a25f7..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Configurations.iml b/Configurations.iml
deleted file mode 100644
index d6ebd48..0000000
--- a/Configurations.iml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/main/java/io/github/simplexdev/configurations/ConfigFactory.java b/src/main/java/io/github/simplexdev/configurations/ConfigFactory.java
index b5084ce..97d37e5 100644
--- a/src/main/java/io/github/simplexdev/configurations/ConfigFactory.java
+++ b/src/main/java/io/github/simplexdev/configurations/ConfigFactory.java
@@ -4,8 +4,8 @@ import io.github.simplexdev.configurations.api.INode;
import io.github.simplexdev.configurations.api.ISection;
public class ConfigFactory {
- public ISection createNewSection(String name) {
- ISection section = new Section(name);
+ public Section createNewSection(String name) {
+ Section section = new Section(name);
Configurations.availableSections.add(section);
return section;
}
diff --git a/src/main/java/io/github/simplexdev/configurations/Group.java b/src/main/java/io/github/simplexdev/configurations/Group.java
index 346c624..746c19b 100644
--- a/src/main/java/io/github/simplexdev/configurations/Group.java
+++ b/src/main/java/io/github/simplexdev/configurations/Group.java
@@ -45,7 +45,7 @@ public class Group implements IGroup {
* @param name The name of this group.
*/
public Group(@NotNull IGroup group, @NotNull String name) {
- this.section = group.getSection();
+ this.section = group.getParentSection();
this.group = group;
this.name = name;
}
@@ -103,6 +103,7 @@ public class Group implements IGroup {
* @param name The name of the nested group
* @return The nested group.
*/
+ @Override
public @Nullable IGroup getNestedGroup(String name) {
for (IGroup nested : nestedGroups) {
if (nested.getName().equalsIgnoreCase(name)) {
@@ -112,6 +113,16 @@ public class Group implements IGroup {
return null;
}
+ @Override
+ public boolean hasNest() {
+ return nestedGroups.isEmpty();
+ }
+
+ @Override
+ public List getNest() {
+ return nestedGroups;
+ }
+
/**
* Gets the parent section associated with this group.
* This will get the parent section regardless of nesting because sections are singular.
@@ -119,7 +130,7 @@ public class Group implements IGroup {
* @return The parent section of this group.
*/
@Override
- public @NotNull ISection getSection() {
+ public @NotNull ISection getParentSection() {
return section;
}
@@ -154,11 +165,23 @@ public class Group implements IGroup {
@Override
public String serialize() {
- return getName();
+ // Will indent the group in relation to the amount of parent groups there are.
+ if (getParentGroup() != null) {
+ int x = 0; // Origin
+ IGroup parent = getParentGroup();
+ while (parent.getParentGroup() != null) {
+ parent = parent.getParentGroup();
+ x++;
+ }
+ x += 1; // Consider parent section as 0
+ x *= 2; // Double indent
+ return getParentSection().indent(x) + getName() + ": ";
+ }
+ return getParentSection().indent(2) + getName() + ": "; // Parent section has no indentation and this is not a nested group.
}
@Override
public IGroup deserialize(String serializedInput) {
- return getSection().getGroup(serializedInput);
+ return getParentSection().getGroup(serializedInput);
}
}
diff --git a/src/main/java/io/github/simplexdev/configurations/Section.java b/src/main/java/io/github/simplexdev/configurations/Section.java
index 473537b..854151e 100644
--- a/src/main/java/io/github/simplexdev/configurations/Section.java
+++ b/src/main/java/io/github/simplexdev/configurations/Section.java
@@ -50,6 +50,12 @@ public class Section implements ISection {
for (IGroup group : groupList) {
if (group.getName().equalsIgnoreCase(name)) {
return group;
+ } else if (group.hasNest()) {
+ for (IGroup nested : group.getNest()) {
+ if (nested.getName().equalsIgnoreCase(name)) {
+ return nested;
+ }
+ }
}
}
return null;
@@ -61,7 +67,7 @@ public class Section implements ISection {
@Override
public String serialize() {
- return getName();
+ return getName() + ": " + newLine();
}
@Override
@@ -73,4 +79,20 @@ public class Section implements ISection {
}
return null;
}
+
+ @Override
+ public String indent(int level) {
+ StringBuilder sb = new StringBuilder();
+ int x = 0;
+ while (x < level) {
+ sb.append("\\ ");
+ x++;
+ }
+ return sb.toString();
+ }
+
+ @Override
+ public String newLine() {
+ return "\n";
+ }
}
diff --git a/src/main/java/io/github/simplexdev/configurations/api/IGroup.java b/src/main/java/io/github/simplexdev/configurations/api/IGroup.java
index 66f640a..8673f95 100644
--- a/src/main/java/io/github/simplexdev/configurations/api/IGroup.java
+++ b/src/main/java/io/github/simplexdev/configurations/api/IGroup.java
@@ -4,8 +4,9 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
+import java.util.List;
-public interface IGroup extends Serializable {
+public interface IGroup extends Serialize {
IGroup createNestedGroup(IGroup group, String name, INode>... nodes);
String getName();
@@ -19,6 +20,12 @@ public interface IGroup extends Serializable {
@Nullable
IGroup getParentGroup();
+ @Nullable IGroup getNestedGroup(String name);
+
+ boolean hasNest();
+
+ List getNest();
+
/**
* Gets the parent section associated to this group.
* Groups cannot exist outside a parent section.
@@ -27,7 +34,7 @@ public interface IGroup extends Serializable {
* @return The parent section of this group.
*/
@NotNull
- ISection getSection();
+ ISection getParentSection();
/**
* @return The nodes contained within this group.
diff --git a/src/main/java/io/github/simplexdev/configurations/api/INode.java b/src/main/java/io/github/simplexdev/configurations/api/INode.java
index d6ac004..d3b3996 100644
--- a/src/main/java/io/github/simplexdev/configurations/api/INode.java
+++ b/src/main/java/io/github/simplexdev/configurations/api/INode.java
@@ -1,6 +1,6 @@
package io.github.simplexdev.configurations.api;
-public interface INode extends Serializable {
+public interface INode extends Serialize {
/**
* @return The name of the configuration entry.
*/
diff --git a/src/main/java/io/github/simplexdev/configurations/api/ISection.java b/src/main/java/io/github/simplexdev/configurations/api/ISection.java
index f6a614a..d155c29 100644
--- a/src/main/java/io/github/simplexdev/configurations/api/ISection.java
+++ b/src/main/java/io/github/simplexdev/configurations/api/ISection.java
@@ -4,7 +4,9 @@ import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-public interface ISection extends Serializable {
+import java.io.Serializable;
+
+public interface ISection extends Serializable, Serialize {
@NotNull
String getName();
@@ -16,4 +18,8 @@ public interface ISection extends Serializable {
@Nullable
IGroup getGroup(String name);
+
+ String indent(int level);
+
+ String newLine();
}
diff --git a/src/main/java/io/github/simplexdev/configurations/api/Serializable.java b/src/main/java/io/github/simplexdev/configurations/api/Serialize.java
similarity index 77%
rename from src/main/java/io/github/simplexdev/configurations/api/Serializable.java
rename to src/main/java/io/github/simplexdev/configurations/api/Serialize.java
index 01dcd05..06d21ac 100644
--- a/src/main/java/io/github/simplexdev/configurations/api/Serializable.java
+++ b/src/main/java/io/github/simplexdev/configurations/api/Serialize.java
@@ -1,6 +1,6 @@
package io.github.simplexdev.configurations.api;
-public interface Serializable {
+public interface Serialize {
String serialize();
T deserialize(String serializedInput);
diff --git a/src/main/java/io/github/simplexdev/configurations/api/Yaml.java b/src/main/java/io/github/simplexdev/configurations/api/Yaml.java
index d7d1cef..adda41c 100644
--- a/src/main/java/io/github/simplexdev/configurations/api/Yaml.java
+++ b/src/main/java/io/github/simplexdev/configurations/api/Yaml.java
@@ -1,39 +1,56 @@
package io.github.simplexdev.configurations.api;
+import io.github.simplexdev.configurations.ConfigFactory;
import io.github.simplexdev.configurations.Configurations;
import io.github.simplexdev.configurations.Utils;
import org.bukkit.plugin.Plugin;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
+import java.util.function.Supplier;
@SuppressWarnings("ALL")
-public abstract class Yaml {
+public abstract class Yaml extends org.yaml.snakeyaml.Yaml {
private final Plugin plugin;
private final File dataFolder;
private final File configFile;
private final Utils utils;
+ private final ConfigFactory factory;
+ private final String fileName;
- private final Map> groupsPerSection = new HashMap<>();
- private final Map>> nodesPerGroup = new HashMap<>();
+ private final Map> groupsInSection = new HashMap<>();
+ private final Map>> nodesInGroup = new HashMap<>();
- public Yaml(Plugin plugin, String fileName, boolean copyResource) {
+ public Yaml(@NotNull Plugin plugin, @Nullable String subDirectory, @NotNull String fileName, @NotNull boolean copyResource) {
+ super();
this.plugin = plugin;
this.utils = new Utils();
+ this.factory = new ConfigFactory();
+ this.fileName = fileName;
File dataFolder = plugin.getDataFolder();
if (!dataFolder.exists()) dataFolder.mkdir();
+ if (subDirectory != null) {
+ File subDir = new File(dataFolder, subDirectory);
+ }
+
this.dataFolder = dataFolder;
File file = new File(dataFolder, fileName);
- try {
- file.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
+ if (!file.exists()) {
+ try {
+ file.createNewFile();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
if (copyResource) {
plugin.saveResource(fileName, true);
@@ -41,6 +58,33 @@ public abstract class Yaml {
this.configFile = file;
}
+ public Yaml(Plugin plugin, String fileName) {
+ this(plugin, null, fileName, false);
+ }
+
+ public Yaml(Plugin plugin) {
+ this(plugin, null, "config.yml", false);
+ }
+
+ public Yaml(Plugin plugin, boolean copyResource) {
+ this(plugin, null, "config.yml", true);
+ }
+
+ public void load() {
+ try {
+ super.load(new BufferedReader(new FileReader(configFile)));
+ } catch (IOException ex) {
+ plugin.getLogger().severe(ex.getMessage());
+ }
+ }
+
+ public void save(boolean saveResource) {
+ if (saveResource) {
+ plugin.saveResource(fileName, true);
+ }
+ }
+
+ @Nullable
public ISection getSection(String name) {
for (ISection section : Configurations.availableSections) {
if (section.getName().equalsIgnoreCase(name)) {
@@ -49,4 +93,8 @@ public abstract class Yaml {
}
return null;
}
+
+ public final ConfigFactory getFactory() {
+ return factory;
+ }
}