Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
5d05cec
Initial standalone commit
Thatsmusic99 Jun 14, 2021
ace01ce
Added tests
Thatsmusic99 Jun 14, 2021
865c386
Added interfaces
Thatsmusic99 Jun 23, 2021
8e78ce3
Bumped version
Thatsmusic99 Jul 2, 2021
1413261
Deprecated CMFile altogether
Thatsmusic99 Jul 3, 2021
aedaa77
Added ConfigSection implementation
Thatsmusic99 Jul 3, 2021
a666d48
Added MemorySection implementation
Thatsmusic99 Jul 3, 2021
32934e1
Added CommentWriter
Thatsmusic99 Jul 3, 2021
de7d954
Replaced ConfigTests with a test of AT's
Thatsmusic99 Jul 3, 2021
ef00ed6
Renamed InternalConfigFile to ConfigFile
Thatsmusic99 Jul 3, 2021
44d4706
get rid of this, this sucks
Thatsmusic99 Jul 3, 2021
d327dbd
Add any pending comments to the parent section rather than actual option
Thatsmusic99 Jul 3, 2021
f624b1d
Fixed addComment(String, String) only working for sections, not actua…
Thatsmusic99 Jul 3, 2021
6767d0a
Added ConfigSection#addComments(String, String...)
Thatsmusic99 Jul 3, 2021
1712bf9
Throw IllegalStateException when trying to make a section where an op…
Thatsmusic99 Jul 3, 2021
e727a0f
Remove duplicating code in moveTo method
Thatsmusic99 Jul 3, 2021
c78812c
Add TODO for future release
Thatsmusic99 Jul 3, 2021
36ff653
oh yeah bump the version
Thatsmusic99 Jul 3, 2021
f9b2d2e
Fixed ConfigFile#reload
Thatsmusic99 Jul 4, 2021
85d5a28
Fixed comments not always getting fetched and placed properly
Thatsmusic99 Jul 4, 2021
ac0e7ae
Fixed option paths not being determined correctly
Thatsmusic99 Jul 4, 2021
23148e8
Fixed ConfigSection#makeSectionLenient(String) not working properly
Thatsmusic99 Jul 4, 2021
e07cd79
Generify the maps here
Thatsmusic99 Jul 4, 2021
20c69e6
Remove the option if the value specified is null
Thatsmusic99 Jul 4, 2021
de63db3
Moved API and Bukkit stuff into separate modules
Thatsmusic99 Jul 4, 2021
d95b4de
Added tests
Thatsmusic99 Jul 4, 2021
8d40c80
Ignore all .yml files generated by tests
Thatsmusic99 Jul 4, 2021
c181aec
add a warning to own the libs
Thatsmusic99 Jul 4, 2021
ed3eaab
Fixed dependency/imports that come from Bukkit
Thatsmusic99 Jul 4, 2021
c4a2d05
Fixed null options being added
Thatsmusic99 Jul 13, 2021
70a291b
Fixed NPE + problems when using getList on an array
Thatsmusic99 Jul 13, 2021
03ff1a6
Also prevent null sections being added
Thatsmusic99 Jul 13, 2021
41395ed
Fixed moveTo not setting options to null
Thatsmusic99 Jul 13, 2021
19b91b7
If the section is null, don't try to re-add a section
Thatsmusic99 Jul 13, 2021
1256afd
Fixed ConfigFile#reload re-adding sections made via addExample
Thatsmusic99 Jul 13, 2021
bca2f54
Make ConfigFile#getExamples a hashset (better contains TO)
Thatsmusic99 Jul 13, 2021
b231064
Make some methods private
Thatsmusic99 Jul 13, 2021
61ef128
Added some javadocs
Thatsmusic99 Jul 13, 2021
38de42a
Bumped version
Thatsmusic99 Jul 13, 2021
331d754
Fixed custom options added to lenient sections not saving if they wer…
Thatsmusic99 Jul 13, 2021
ecadafe
Force writing to file using the UTF-8 charset
Thatsmusic99 Jul 17, 2021
3266c82
Fixed error in Bukkit pom
Thatsmusic99 Jul 17, 2021
f949276
Add the override annotation where needed
Thatsmusic99 Jul 18, 2021
1fdfaf5
Add getPath as a method to the MemorySection interface
Thatsmusic99 Jul 18, 2021
853aeb9
Added forceExample and createExampleSection
Thatsmusic99 Jul 18, 2021
4bdc95d
Implemented the Title API with full documentation
Thatsmusic99 Jul 18, 2021
78e874f
Slight code cutdown
Thatsmusic99 Jul 18, 2021
de8c226
Add internal method getKey
Thatsmusic99 Jul 18, 2021
f3fc9b1
Added makeSectionLenient to ConfigSection interface
Thatsmusic99 Jul 18, 2021
a4053f8
Tweaked annotations
Thatsmusic99 Jul 18, 2021
9aa7831
Added null checks to the API implementations
Thatsmusic99 Jul 18, 2021
2c52ca7
Code cleanup/rearranging
Thatsmusic99 Jul 18, 2021
f12e645
Added some documentation
Thatsmusic99 Jul 18, 2021
127c019
Bumped version to v2.0.0-BETA-1
Thatsmusic99 Jul 18, 2021
566f295
are you kidding me
Thatsmusic99 Jul 18, 2021
e34e865
Extended AT tests for Title API
Thatsmusic99 Jul 18, 2021
b70d4a0
Fixed #moveTo and #moveToNew not working properly
Thatsmusic99 Aug 9, 2021
d14ab7f
Completed documentation for MemorySection
Thatsmusic99 Aug 9, 2021
8591844
Bumped version
Thatsmusic99 Aug 9, 2021
1c3bd8a
Fixed moveTo and reload regenerating stuff we don't want
Thatsmusic99 Aug 9, 2021
bdd2a4a
gaaaah
Thatsmusic99 Aug 11, 2021
1864683
Close that damned file reader
Thatsmusic99 Aug 11, 2021
b6af520
Re-add options where required
Thatsmusic99 Aug 11, 2021
ce8cf11
Make saveToString public
Thatsmusic99 Sep 4, 2021
c71b565
Add ConfigFile#getFile
Thatsmusic99 Sep 4, 2021
aa15c0b
Fix the NPE nuke when someone sets a key to null
Thatsmusic99 Oct 14, 2021
5f3afdd
Fixed using set on a non-existent section doing something... uhh... s…
Thatsmusic99 Nov 21, 2021
52d3af4
Semi-hotfix: add useExisting parameter to most getters
Thatsmusic99 Nov 21, 2021
2006b5f
Add the useExisting parameter to contains
Thatsmusic99 Nov 21, 2021
34ef7be
it has had to happen AGAIN
Thatsmusic99 Nov 23, 2021
8e9536c
Stop adding sections that AREN'T NEEDED
Thatsmusic99 Nov 23, 2021
7c6ce6f
lmao whoops i'm such a caprisun :nail_care:
Thatsmusic99 Nov 23, 2021
4301308
I will kill a THOUSAND children before i kill the economy
Thatsmusic99 Nov 29, 2021
b5b74e0
Close the reader in all cases - constructor and loading now throws IO…
Thatsmusic99 Dec 7, 2021
8ffa2a0
Nothing was seen
Thatsmusic99 Dec 9, 2021
eba029d
oh come on
Thatsmusic99 Dec 9, 2021
4ccdb2e
Loggers are the way forward!
Thatsmusic99 Jan 1, 2022
3e463a3
Fix bad code, of course
Thatsmusic99 Mar 26, 2022
6e871a4
OH YEAH UH BUMP THIS PLS
Thatsmusic99 Mar 26, 2022
85de53a
Fix contains adding sections when it, stupidly, shouldn't
Thatsmusic99 Mar 26, 2022
5f8d849
Remove existing values after the config is saved
Thatsmusic99 Mar 26, 2022
fecc591
Get rid of loader options
Thatsmusic99 Mar 29, 2022
5de89f7
Get rid of loader options
Thatsmusic99 Feb 19, 2023
475a1fc
Use comment and section objects
Thatsmusic99 Feb 19, 2023
fd3cbdf
Implement Map
Thatsmusic99 Feb 19, 2023
44271d8
so many changes in this file omg
Thatsmusic99 Feb 19, 2023
42fb32c
bump version
Thatsmusic99 Feb 19, 2023
379a172
modify tests
Thatsmusic99 Feb 19, 2023
3a9ff7c
feat: add option handlers
Thatsmusic99 Feb 21, 2023
8331868
dev: bump version
Thatsmusic99 Feb 23, 2023
2cf34aa
fix: comments being re-added
Thatsmusic99 Feb 23, 2023
d47bba0
fix: SnakeYAML being outdated
Thatsmusic99 Jun 7, 2023
0a74f80
chore(version): bump
Thatsmusic99 Jun 7, 2023
10950b5
Remove existing values after the config is saved
Thatsmusic99 Mar 26, 2022
a331e30
Get rid of loader options
Thatsmusic99 Mar 29, 2022
cee793f
Get rid of loader options
Thatsmusic99 Feb 19, 2023
25519c1
Use comment and section objects
Thatsmusic99 Feb 19, 2023
2e0faa6
Implement Map
Thatsmusic99 Feb 19, 2023
ceb9ff1
so many changes in this file omg
Thatsmusic99 Feb 19, 2023
dbce0d5
bump version
Thatsmusic99 Feb 19, 2023
e4ba8b5
modify tests
Thatsmusic99 Feb 19, 2023
e327adf
feat: add option handlers
Thatsmusic99 Feb 21, 2023
2161b9f
dev: bump version
Thatsmusic99 Feb 23, 2023
04489fb
fix: comments being re-added
Thatsmusic99 Feb 23, 2023
29bf050
chore(version): bump
Thatsmusic99 Jun 7, 2023
a1f1417
Merge remote-tracking branch 'origin/standalone-impl' into standalone…
Thatsmusic99 Jun 8, 2023
c515fcb
feat: add example annotations
Thatsmusic99 Jun 8, 2023
0f5fb2a
fix: reloading duplicating comments
Thatsmusic99 Jun 9, 2023
a35c4c3
fix: this too
Thatsmusic99 Jun 9, 2023
d297950
fix: several API issues such as self-deleting sections and examples
Thatsmusic99 Jun 9, 2023
7267d2f
fix: non-extended file handling overriding config content
Thatsmusic99 Jun 9, 2023
6bfaab8
chore(version): bump
Thatsmusic99 Jun 9, 2023
c7dd28e
fix: error when deleting files and reloading
Thatsmusic99 Jun 17, 2023
19ba091
fix: put lenient sections in the right place
Thatsmusic99 Jun 17, 2023
47056d8
fix: don't bring back old sections after a reload
Thatsmusic99 Jun 17, 2023
054a6fd
chore(version): bump
Thatsmusic99 Jun 17, 2023
0f1aa4a
fix: create a new file when using loadConfig
Thatsmusic99 Jun 17, 2023
5b04db0
fix: examples being forced when the parent section does not exist, bu…
Thatsmusic99 Jun 28, 2023
d9e7214
chore(version): bump to v2.0.0-BETA-9
Thatsmusic99 Jun 28, 2023
3c12d1a
fix: sections not being marked as, well, sections
Thatsmusic99 Jul 2, 2023
75e5f74
Update API pom
Thatsmusic99 Aug 2, 2023
5b9a37f
Update it here too
Thatsmusic99 Aug 2, 2023
cec628e
And this too
Thatsmusic99 Aug 2, 2023
5e3d9c7
And this too
Thatsmusic99 Aug 2, 2023
5211f45
On this fine day I thank SnakeYAML and Spigot for being so wonderful …
Thatsmusic99 Aug 2, 2023
2a5bc15
Merge pull request #7 from Errored-Innovations/Thatsmusic99-patch-1
Thatsmusic99 Aug 2, 2023
cfa23de
I’m editing on mobile have mercy for the love of god
Thatsmusic99 Aug 2, 2023
c4a1b91
fix: LoaderOptions in the wrong spot
Thatsmusic99 Aug 3, 2023
0d6c52f
feat: add permitted classes for tag inspection
Thatsmusic99 Aug 11, 2023
1c79b68
chore(version): bump to v2.0.0-rc.1
Thatsmusic99 Aug 11, 2023
816f328
fix: pending comments (and sections) being handled incorrectly
Thatsmusic99 Jan 3, 2024
bb69324
chore(version): bump to v2.0.0-rc.2
Thatsmusic99 Jan 3, 2024
51bcbe2
chore(deps): bump annotations to 24.0.1
Thatsmusic99 Jan 3, 2024
e34c38e
chore(deps): bump junit to 4.13.2
Thatsmusic99 Jan 3, 2024
d3e3294
feat: add ability to check options before being processed by the config
Thatsmusic99 Dec 23, 2024
4070ca9
chore(version): bump to v2.0.0-rc.3
Thatsmusic99 Dec 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
target/
ConfigurationMaster.iml
ConfigurationMaster.iml
*.yml
30 changes: 30 additions & 0 deletions API/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ConfigurationMaster</artifactId>
<groupId>com.github.thatsmusic99</groupId>
<version>v2.0.0-rc.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>ConfigurationMaster-API</artifactId>
<version>v2.0.0-rc.3</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

<dependencies>

<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.thatsmusic99.configurationmaster.annotations;

import java.lang.annotation.*;

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(Examples.class)
public @interface Example {

String key();

String value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.thatsmusic99.configurationmaster.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Examples {
Example[] value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.github.thatsmusic99.configurationmaster.annotations;


import io.github.thatsmusic99.configurationmaster.annotations.handlers.DefaultOptionHandler;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Option {

String path() default "";

String comment() default "";

String section() default "";

boolean lenient() default false;

Class<? extends OptionHandler> optionHandler() default DefaultOptionHandler.class;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.github.thatsmusic99.configurationmaster.annotations;

import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public interface OptionHandler {

Object get(
@NotNull ConfigFile file,
@NotNull String name
);

void set(
@NotNull ConfigFile file,
@NotNull String name,
@NotNull Object value
);

void addDefault(
@NotNull ConfigFile file,
@NotNull String name,
@NotNull Object value,
@Nullable String section,
@Nullable String comment
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.thatsmusic99.configurationmaster.annotations.handlers;

import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
import org.jetbrains.annotations.NotNull;

public class BooleanOptionHandler extends DefaultOptionHandler {

@Override
public Object get(@NotNull ConfigFile file, @NotNull String name) {
return file.getBoolean(name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.thatsmusic99.configurationmaster.annotations.handlers;

import io.github.thatsmusic99.configurationmaster.annotations.OptionHandler;
import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class DefaultOptionHandler implements OptionHandler {


@Override
public Object get(@NotNull ConfigFile file, @NotNull String name) {
return file.get(name);
}

@Override
public void set(@NotNull ConfigFile file, @NotNull String name, @NotNull Object value) {
file.set(name, value);
}

@Override
public void addDefault(@NotNull ConfigFile file, @NotNull String name, @NotNull Object value, @Nullable String section, @Nullable String comment) {
file.addDefault(name, value, section, comment);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.thatsmusic99.configurationmaster.annotations.handlers;

import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
import org.jetbrains.annotations.NotNull;

public class FloatOptionHandler extends DefaultOptionHandler {

@Override
public Object get(@NotNull ConfigFile file, @NotNull String name) {
return file.getFloat(name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.thatsmusic99.configurationmaster.annotations.handlers;

import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
import org.jetbrains.annotations.NotNull;

public class IntegerOptionHandler extends DefaultOptionHandler {

@Override
public Object get(@NotNull ConfigFile file, @NotNull String name) {
return file.getInteger(name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.thatsmusic99.configurationmaster.annotations.handlers;

import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
import org.jetbrains.annotations.NotNull;

public class LongOptionHandler extends DefaultOptionHandler {

@Override
public Object get(@NotNull ConfigFile file, @NotNull String name) {
return file.getLong(name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.thatsmusic99.configurationmaster.annotations.handlers;

import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
import org.jetbrains.annotations.NotNull;

public class StringOptionHandler extends DefaultOptionHandler {

@Override
public Object get(@NotNull ConfigFile file, @NotNull String name) {
return file.getString(name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package io.github.thatsmusic99.configurationmaster.api;

import io.github.thatsmusic99.configurationmaster.api.comments.Comment;
import io.github.thatsmusic99.configurationmaster.api.comments.Section;

import java.util.ArrayList;
import java.util.List;

class CommentWriter {

private final ConfigFile config;
// The currently written lines of the file.
private List<String> currentLines;

protected CommentWriter(ConfigFile config) {
this.config = config;
this.currentLines = new ArrayList<>();
}

/**
* Initiates the comment writing process.
*/
protected void writeComments(List<String> currentLines) {
this.currentLines = currentLines;

// For each comment to be made...
for (String path : config.getComments().keySet()) {
// Write the comment at the specified path
writeComment(path, path.split("\\."), 0, 0);
}

// However, if there's any comments left, write them in.
for (Comment comment : config.getPendingComments()) {

String str = comment.getComment();
if (str.isEmpty()) {
currentLines.add("");
continue;
}
currentLines.add("");
String[] rawComment = str.split("\n");
for (String commentPart : rawComment) {
if (commentPart.isEmpty()) {
currentLines.add("");
continue;
}

// If we have a comment section here, use that instead
if (comment instanceof Section) {
String section = commentPart.split(": ")[1];
StringBuilder length = new StringBuilder();
length.append("###");
for (int j = 0; j < section.length(); j++) {
length.append("#");
}
length.append("###");
currentLines.add(length.toString());
currentLines.add("# " + section + " #");
currentLines.add(length.toString());
} else {
currentLines.add("# " + commentPart);
}
}
}
}

/**
* Method used to write a specified comment.
*
* @param path The path the comment must be written at.
* @param divisions The number of sections the part can be split up into.
* @param iteration How far we're down the pathway (in terms of different sections).
* @param startingLine The line we're starting from.
*/
private void writeComment(String path, String[] divisions, int iteration, int startingLine) {
StringBuilder indent = new StringBuilder();
for (int j = 0; j < iteration; j++) indent.append(" ");

// Go through each line in the file
for (int i = startingLine; i < currentLines.size(); i++) {
String line = currentLines.get(i);

// If the line doesn't have an equal or larger indent, then the line could not be found.
if (!line.startsWith(indent.toString())) return;

// If it's already a comment, leave it be.
if (line.startsWith("#")) continue;

// If it's not an option (e.g. option: or 'option':), continue
if (!(line.startsWith(indent + divisions[iteration] + ":") ||
line.startsWith(indent + "'" + divisions[iteration] + "':"))) continue;

// Increment the iteration
iteration += 1;

// If the
if (iteration != divisions.length) {
writeComment(path, divisions, iteration, i + 1);
continue;
}

// Get the current line we're on
int currentLine = i;

//
List<Comment> comments = config.getComments().get(path);
if (comments == null || comments.isEmpty()) continue;

for (Comment comment : comments) {

// Add an empty line before a single-
if (iteration == 1) {
currentLines.add(currentLine, "");
currentLine++;
}

if (comment == null || comment.getComment().isEmpty()) {
currentLines.add(currentLine, "");
} else {

String commentStr = comment.getComment();
String[] commentParts = commentStr.split("\n");

if (comment instanceof Section) {

// Get the maximum length
int max = 0;
for (String commentPart : commentParts) {
max = Math.max(commentPart.length(), max);
}

// Build the
StringBuilder length = new StringBuilder();
length.append("###");
for (int j = 0; j < max; j++) {
length.append("#");
}
length.append("###");
currentLines.add(currentLine, length.toString());
currentLine++;
for (String commentPart : commentParts) {
currentLines.add(currentLine, "# " + commentPart + " #");
currentLine++;
}
currentLines.add(currentLine, length.toString());
currentLine++;
continue;
}

for (String commentPart : commentParts) {
currentLines.add(currentLine, indent + "# " + commentPart);
currentLine++;
}
}
}
break;
}
}

protected List<String> getLines() {
return currentLines;
}
}
Loading