diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a87d264 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +# +# https://help.github.com/articles/dealing-with-line-endings/ +# +# Linux start script should use lf +/gradlew text eol=lf + +# These are Windows script files and should use crlf +*.bat text eol=crlf + +# Binary files should be left untouched +*.jar binary diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..fd778f0 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,21 @@ +version: 2 +updates: + - package-ecosystem: "gradle" + directory: "/" + schedule: + interval: "weekly" + + commit-message: + prefix: "deps" + + open-pull-requests-limit: 25 + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + + commit-message: + prefix: "ci" + + open-pull-requests-limit: 25 \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..6125b8d --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,39 @@ +name: CI + +on: + + push: + branches: [ "**" ] + + pull_request: { } + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v7 + + - name: Set up JDK 21 + uses: actions/setup-java@v6 + with: + java-version: '21' + distribution: 'temurin' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v6 + + - name: Grant execute permission + run: chmod +x gradlew + + - name: Build + run: ./gradlew build + + - name: Upload artifacts + uses: actions/upload-artifact@v7 + with: + name: functionalConfiguration-artifacts + path: | + */build/libs/*.jar + if-no-files-found: error \ No newline at end of file diff --git a/.gitignore b/.gitignore index cfca2ea..9e4b940 100644 --- a/.gitignore +++ b/.gitignore @@ -1,29 +1,21 @@ -# Build Folders # -bin/ -build/ -target/ -gen/ -libraries_runtime/ -libraries_shade/ -build_libraries/ -logs/ +# MacOS DS_Store files +.DS_Store -# Gradle +# Gradle cache folder .gradle -.gradletasknamecache - # Eclipse Files # -*.project -*.classpath -*.prefs -*.factorypath -.apt_generated/ -.externalToolBuilders/ - -# Netbeans -.nb-gradle/ +# Gradle build folder +build # IntelliJ -.idea/ +out/ +.idea *.iml +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +# Common working directory +run diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index ab1f416..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Ignored default folder with query files -/queries/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 88df1b1..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/discord.xml b/.idea/discord.xml deleted file mode 100644 index 104c42f..0000000 --- a/.idea/discord.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index aa00ffa..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,7 +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 b9fb53b..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index 828a0d8..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 0297330..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 03d251c..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index c3e3123..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..d03d53b --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,128 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +https://discord.gg/2syNtcKcgR. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. \ No newline at end of file diff --git a/FunctionalConfiguration.iml b/FunctionalConfiguration.iml deleted file mode 100644 index 3cf00db..0000000 --- a/FunctionalConfiguration.iml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - PAPER - - 1 - - - - \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c5fc639 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 g4vrk + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..20193a7 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,162 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import org.gradle.api.tasks.bundling.Jar +import org.gradle.kotlin.dsl.invoke +import org.gradle.kotlin.dsl.withType +import util.VersionUtility +import xyz.jpenilla.runpaper.task.RunServer + +plugins { + id("java-library") + alias(libs.plugins.run.paper) + alias(libs.plugins.shadow) +} + +version = VersionUtility.version(project, version.toString()) + +allprojects { + + repositories { + + mavenCentral() + + maven { + name = "papermc-repo" + url = uri("https://repo.papermc.io/repository/maven-public/") + } + + } + +} + +subprojects { + + apply(plugin = "java-library") + apply(plugin = "maven-publish") + apply(plugin = "com.gradleup.shadow") + + group = rootProject.group + version = rootProject.version + description = rootProject.description + + dependencies { + + compileOnly(rootProject.libs.lombok) + annotationProcessor(rootProject.libs.lombok) + + } + + plugins.withType { + + dependencies { + "testImplementation"( + platform(rootProject.libs.junit.bom) + ) + + "testImplementation"( + rootProject.libs.junit.jupiter + ) + + "testRuntimeOnly"( + rootProject.libs.junit.platform.launcher + ) + } + + tasks.withType().configureEach { + useJUnitPlatform() + } + } + + extensions.configure { + + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + + withSourcesJar() + + } + + + tasks { + + withType().configureEach { + + options.encoding = "UTF-8" + + } + + withType().configureEach { + minecraftVersion(libs.versions.minecraft.get()) + jvmArgs("-Xms2G", "-Xmx2G", "-Dcom.mojang.eula.agree=true") + } + + withType().configureEach { + archiveFileName.set( + "${rootProject.name}-${project.name}-${rootProject.version}.jar" + ) + + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + + mergeServiceFiles() + } + + named("build") { + + dependsOn(named("shadowJar")) + + } + + } + + + extensions.configure { + + publications { + + create("maven") { + + groupId = System.getenv("GROUP") ?: project.group.toString() + artifactId = project.name + version = System.getenv("VERSION") ?: project.version.toString() + + artifact(tasks.named("shadowJar")) { + classifier = "" + } + artifact(tasks.named("sourcesJar")) + + pom { + name.set("${rootProject.name}-${project.name}") + description.set(provider { project.description }) + } + + } + + } + + } + +} + + +tasks { + + named("jar") { + + enabled = false + + } + + clean { + + dependsOn(subprojects.map { "${it.path}:clean" }) + + } + + build { + + dependsOn(subprojects.map { "${it.path}:build" }) + + } + +} + +defaultTasks("clean", "build") diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..8f77993 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,11 @@ +plugins { + `kotlin-dsl` +} + +repositories { + + gradlePluginPortal() + + mavenCentral() + +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/util/VersionUtility.kt b/buildSrc/src/main/kotlin/util/VersionUtility.kt new file mode 100644 index 0000000..5750161 --- /dev/null +++ b/buildSrc/src/main/kotlin/util/VersionUtility.kt @@ -0,0 +1,92 @@ +package util + +import org.gradle.api.Project + +object VersionUtility { + + private const val DEFAULT_BRANCH = "local" + private const val UNKNOWN_COMMIT = "unknown" + private const val MAIN_BRANCH = "master" + private const val SHORT_COMMIT_LENGTH = 7 + + fun branch(project: Project): String { + val environmentBranch = System.getenv("GIT_BRANCH") + + if (!environmentBranch.isNullOrBlank()) { + return sanitize(environmentBranch) + } + + val branch = execute( + project, + "git", + "branch", + "--show-current" + ) + + return branch + .takeIf { it.isNotBlank() } + ?.let(::sanitize) + ?: DEFAULT_BRANCH + } + + fun commitHash(project: Project): String { + val environmentCommit = System.getenv("GIT_COMMIT") + + if (!environmentCommit.isNullOrBlank()) { + return environmentCommit.take(SHORT_COMMIT_LENGTH) + } + + return execute( + project, + "git", + "rev-parse", + "--short", + "HEAD" + ).ifBlank { + UNKNOWN_COMMIT + } + } + + fun version( + project: Project, + baseVersion: String + ): String { + val branch = branch(project) + val commit = commitHash(project) + + return buildString { + append(baseVersion) + + if (branch != MAIN_BRANCH) { + append('-') + append(branch) + } + + append('-') + append(commit) + } + } + + private fun execute( + project: Project, + vararg command: String + ): String { + return runCatching { + project.providers.exec { + commandLine(command.toList()) + isIgnoreExitValue = true + } + .standardOutput + .asText + .get() + .trim() + }.getOrDefault("") + } + + private fun sanitize(value: String): String { + return value.replace( + Regex("[^a-zA-Z0-9._-]"), + "-" + ) + } +} \ No newline at end of file diff --git a/common/build.gradle.kts b/common/build.gradle.kts new file mode 100644 index 0000000..7e40f21 --- /dev/null +++ b/common/build.gradle.kts @@ -0,0 +1,6 @@ +dependencies { + + compileOnly(libs.paper.api) + compileOnly(libs.configurate.yaml) + +} \ No newline at end of file diff --git a/common/src/main/java/com/g4vrk/config/Config.java b/common/src/main/java/com/g4vrk/config/Config.java new file mode 100644 index 0000000..4521bc4 --- /dev/null +++ b/common/src/main/java/com/g4vrk/config/Config.java @@ -0,0 +1,17 @@ +package com.g4vrk.config; + +import org.jetbrains.annotations.NotNull; +import org.spongepowered.configurate.ConfigurationNode; + +import java.io.IOException; + +public interface Config { + + @NotNull ConfigurationNode root(); + + @NotNull ConfigurationNode node(final @NotNull Object... path); + + void load() throws IOException; + void save() throws IOException; + +} diff --git a/src/main/java/com/g4vrk/functionalConfiguration/NamedConfigEntry.java b/common/src/main/java/com/g4vrk/config/NamedConfigEntry.java similarity index 78% rename from src/main/java/com/g4vrk/functionalConfiguration/NamedConfigEntry.java rename to common/src/main/java/com/g4vrk/config/NamedConfigEntry.java index 0b85852..f8007c3 100644 --- a/src/main/java/com/g4vrk/functionalConfiguration/NamedConfigEntry.java +++ b/common/src/main/java/com/g4vrk/config/NamedConfigEntry.java @@ -1,4 +1,4 @@ -package com.g4vrk.functionalConfiguration; +package com.g4vrk.config; import org.jetbrains.annotations.NotNull; diff --git a/common/src/main/java/com/g4vrk/config/YamlConfig.java b/common/src/main/java/com/g4vrk/config/YamlConfig.java new file mode 100644 index 0000000..580f67e --- /dev/null +++ b/common/src/main/java/com/g4vrk/config/YamlConfig.java @@ -0,0 +1,41 @@ +package com.g4vrk.config; + +import org.jetbrains.annotations.NotNull; +import org.spongepowered.configurate.ConfigurationNode; +import org.spongepowered.configurate.yaml.YamlConfigurationLoader; + +import java.io.IOException; + +public class YamlConfig implements Config { + + private final YamlConfigurationLoader loader; + + private ConfigurationNode root; + + public YamlConfig( + @NotNull YamlConfigurationLoader loader + ) { + this.loader = loader; + } + + @Override + public @NotNull ConfigurationNode root() { + return root; + } + + @Override + public @NotNull ConfigurationNode node(@NotNull Object... path) { + return root.node(path); + } + + @Override + public void load() throws IOException { + this.root = loader.load(); + } + + @Override + public void save() throws IOException { + loader.save(root); + } + +} diff --git a/src/main/java/com/g4vrk/functionalConfiguration/loader/AbstractConfigLoader.java b/common/src/main/java/com/g4vrk/config/loader/AbstractConfigLoader.java similarity index 77% rename from src/main/java/com/g4vrk/functionalConfiguration/loader/AbstractConfigLoader.java rename to common/src/main/java/com/g4vrk/config/loader/AbstractConfigLoader.java index d1afcb1..9c68b31 100644 --- a/src/main/java/com/g4vrk/functionalConfiguration/loader/AbstractConfigLoader.java +++ b/common/src/main/java/com/g4vrk/config/loader/AbstractConfigLoader.java @@ -1,9 +1,10 @@ -package com.g4vrk.functionalConfiguration.loader; +package com.g4vrk.config.loader; -import com.g4vrk.functionalConfiguration.Config; +import com.g4vrk.config.Config; import org.jetbrains.annotations.NotNull; import org.spongepowered.configurate.yaml.YamlConfigurationLoader; +import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; @@ -11,16 +12,19 @@ public abstract class AbstractConfigLoader implements ConfigLoader { @Override - public @NotNull C from(@NotNull Path path) { + public @NotNull C from(@NotNull Path path) throws IOException { + final YamlConfigurationLoader loader = YamlConfigurationLoader.builder() .path(path) .build(); return from(loader); + } @Override - public @NotNull Iterable from(@NotNull Iterable paths) { + public @NotNull Iterable from(@NotNull Iterable paths) throws IOException { + final List list = new ArrayList<>(); for (final Path path : paths) { @@ -30,5 +34,6 @@ public abstract class AbstractConfigLoader implements ConfigLo return list; } - protected abstract @NotNull C from(@NotNull YamlConfigurationLoader loader); + protected abstract @NotNull C from(@NotNull YamlConfigurationLoader loader) throws IOException; + } diff --git a/common/src/main/java/com/g4vrk/config/loader/ConfigLoader.java b/common/src/main/java/com/g4vrk/config/loader/ConfigLoader.java new file mode 100644 index 0000000..816e131 --- /dev/null +++ b/common/src/main/java/com/g4vrk/config/loader/ConfigLoader.java @@ -0,0 +1,15 @@ +package com.g4vrk.config.loader; + +import com.g4vrk.config.Config; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.nio.file.Path; + +public interface ConfigLoader { + + @NotNull C from(final @NotNull Path path) throws IOException; + + @NotNull Iterable from(final @NotNull Iterable paths) throws IOException; + +} diff --git a/common/src/main/java/com/g4vrk/config/loader/YamlConfigLoader.java b/common/src/main/java/com/g4vrk/config/loader/YamlConfigLoader.java new file mode 100644 index 0000000..7325c33 --- /dev/null +++ b/common/src/main/java/com/g4vrk/config/loader/YamlConfigLoader.java @@ -0,0 +1,33 @@ +package com.g4vrk.config.loader; + +import com.g4vrk.config.YamlConfig; +import org.jetbrains.annotations.NotNull; +import org.spongepowered.configurate.yaml.YamlConfigurationLoader; + +import java.io.IOException; + +public class YamlConfigLoader extends AbstractConfigLoader { + + private final boolean load; + + public YamlConfigLoader() { + this(true); + } + + public YamlConfigLoader( + boolean load + ) { + this.load = load; + } + + @Override + protected @NotNull YamlConfig from(@NotNull YamlConfigurationLoader loader) throws IOException { + + final YamlConfig yamlConfig = new YamlConfig(loader); + + if (this.load) yamlConfig.load(); + + return yamlConfig; + + } +} diff --git a/common/src/main/java/com/g4vrk/config/loader/mapped/MappedConfigLoader.java b/common/src/main/java/com/g4vrk/config/loader/mapped/MappedConfigLoader.java new file mode 100644 index 0000000..ad66921 --- /dev/null +++ b/common/src/main/java/com/g4vrk/config/loader/mapped/MappedConfigLoader.java @@ -0,0 +1,16 @@ +package com.g4vrk.config.loader.mapped; + +import com.g4vrk.config.Config; +import com.g4vrk.config.NamedConfigEntry; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.io.IOException; + +public interface MappedConfigLoader { + + @NotNull NamedConfigEntry from(final @NotNull File file) throws IOException; + + @NotNull Iterable> from(final @NotNull Iterable files) throws IOException; + +} diff --git a/src/main/java/com/g4vrk/functionalConfiguration/loader/mapped/SimpleMappedConfigLoader.java b/common/src/main/java/com/g4vrk/config/loader/mapped/SimpleMappedConfigLoader.java similarity index 69% rename from src/main/java/com/g4vrk/functionalConfiguration/loader/mapped/SimpleMappedConfigLoader.java rename to common/src/main/java/com/g4vrk/config/loader/mapped/SimpleMappedConfigLoader.java index 60158e1..bb70fce 100644 --- a/src/main/java/com/g4vrk/functionalConfiguration/loader/mapped/SimpleMappedConfigLoader.java +++ b/common/src/main/java/com/g4vrk/config/loader/mapped/SimpleMappedConfigLoader.java @@ -1,12 +1,13 @@ -package com.g4vrk.functionalConfiguration.loader.mapped; +package com.g4vrk.config.loader.mapped; -import com.g4vrk.functionalConfiguration.Config; -import com.g4vrk.functionalConfiguration.NamedConfigEntry; -import com.g4vrk.functionalConfiguration.loader.ConfigLoader; -import com.g4vrk.functionalConfiguration.loader.mapped.namer.FileNamer; +import com.g4vrk.config.Config; +import com.g4vrk.config.NamedConfigEntry; +import com.g4vrk.config.loader.ConfigLoader; +import com.g4vrk.config.loader.mapped.namer.FileNamer; import org.jetbrains.annotations.NotNull; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -24,7 +25,7 @@ public SimpleMappedConfigLoader( } @Override - public @NotNull NamedConfigEntry from(@NotNull File file) { + public @NotNull NamedConfigEntry from(@NotNull File file) throws IOException { final C config = loader.from(file.toPath()); final String name = namer.nameFor(file); @@ -32,10 +33,12 @@ public SimpleMappedConfigLoader( } @Override - public @NotNull Iterable> from(@NotNull Iterable files) { + public @NotNull Iterable> from(@NotNull Iterable files) throws IOException { final List> entries = new ArrayList<>(); - files.forEach(file -> entries.add(from(file))); + for (File file : files) { + entries.add(from(file)); + } return entries; } diff --git a/src/main/java/com/g4vrk/functionalConfiguration/loader/mapped/namer/FileNamer.java b/common/src/main/java/com/g4vrk/config/loader/mapped/namer/FileNamer.java similarity index 51% rename from src/main/java/com/g4vrk/functionalConfiguration/loader/mapped/namer/FileNamer.java rename to common/src/main/java/com/g4vrk/config/loader/mapped/namer/FileNamer.java index 4f81154..1249083 100644 --- a/src/main/java/com/g4vrk/functionalConfiguration/loader/mapped/namer/FileNamer.java +++ b/common/src/main/java/com/g4vrk/config/loader/mapped/namer/FileNamer.java @@ -1,4 +1,4 @@ -package com.g4vrk.functionalConfiguration.loader.mapped.namer; +package com.g4vrk.config.loader.mapped.namer; import org.jetbrains.annotations.NotNull; @@ -6,5 +6,7 @@ @FunctionalInterface public interface FileNamer { - @NotNull String nameFor(@NotNull File file); + + @NotNull String nameFor(final @NotNull File file); + } diff --git a/src/main/java/com/g4vrk/functionalConfiguration/loader/mapped/namer/PrimaryFileNamer.java b/common/src/main/java/com/g4vrk/config/loader/mapped/namer/PrimaryFileNamer.java similarity index 58% rename from src/main/java/com/g4vrk/functionalConfiguration/loader/mapped/namer/PrimaryFileNamer.java rename to common/src/main/java/com/g4vrk/config/loader/mapped/namer/PrimaryFileNamer.java index 41720d8..16b3e96 100644 --- a/src/main/java/com/g4vrk/functionalConfiguration/loader/mapped/namer/PrimaryFileNamer.java +++ b/common/src/main/java/com/g4vrk/config/loader/mapped/namer/PrimaryFileNamer.java @@ -1,12 +1,19 @@ -package com.g4vrk.functionalConfiguration.loader.mapped.namer; +package com.g4vrk.config.loader.mapped.namer; import org.jetbrains.annotations.NotNull; import java.io.File; public class PrimaryFileNamer implements FileNamer { + + public static final PrimaryFileNamer INSTANCE = new PrimaryFileNamer(); + + private PrimaryFileNamer() { + } + @Override public @NotNull String nameFor(@NotNull File file) { return file.getName(); } + } diff --git a/common/src/main/java/com/g4vrk/config/manager/ConfigManager.java b/common/src/main/java/com/g4vrk/config/manager/ConfigManager.java new file mode 100644 index 0000000..a132d51 --- /dev/null +++ b/common/src/main/java/com/g4vrk/config/manager/ConfigManager.java @@ -0,0 +1,49 @@ +package com.g4vrk.config.manager; + +import com.g4vrk.config.Config; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.IOException; +import java.util.Collection; +import java.util.Map; +import java.util.Optional; + +public interface ConfigManager extends Iterable { + + void register( + @NotNull String key, + @NotNull C config + ); + + void registerAll( + @NotNull Map configs + ); + + @Nullable C remove( + @NotNull String key + ); + + boolean contains( + @NotNull String key + ); + + @NotNull Optional find( + @NotNull String key + ); + + @Nullable C findOrNull( + @NotNull String key + ); + + @NotNull Collection values(); + + void loadAll() throws IOException; + + void saveAll() throws IOException; + + default void reloadAll() throws IOException { + loadAll(); + } + +} diff --git a/src/main/java/com/g4vrk/functionalConfiguration/manager/SimpleConfigManager.java b/common/src/main/java/com/g4vrk/config/manager/SimpleConfigManager.java similarity index 53% rename from src/main/java/com/g4vrk/functionalConfiguration/manager/SimpleConfigManager.java rename to common/src/main/java/com/g4vrk/config/manager/SimpleConfigManager.java index 8e9c95e..15ec360 100644 --- a/src/main/java/com/g4vrk/functionalConfiguration/manager/SimpleConfigManager.java +++ b/common/src/main/java/com/g4vrk/config/manager/SimpleConfigManager.java @@ -1,8 +1,8 @@ -package com.g4vrk.functionalConfiguration.manager; +package com.g4vrk.config.manager; -import com.g4vrk.functionalConfiguration.Config; -import com.g4vrk.functionalConfiguration.NamedConfigEntry; +import com.g4vrk.config.Config; import org.jetbrains.annotations.NotNull; +import org.jspecify.annotations.Nullable; import java.io.IOException; import java.util.Collection; @@ -18,59 +18,77 @@ public class SimpleConfigManager implements ConfigManager { @Override public void register( - @NotNull NamedConfigEntry namedConfigEntry + @NotNull String key, + @NotNull C config ) { - this.configs.put(namedConfigEntry.name(), namedConfigEntry.config()); + + this.configs.put(key, config); + } @Override - public void registerAll(@NotNull Iterable> namedConfigEntries) { - namedConfigEntries.forEach(this::register); + public void registerAll( + @NotNull Map configs + ) { + + this.configs.putAll(configs); + } @Override - public void unregister( - @NotNull String name - ) { - this.configs.remove(name); + public @Nullable C remove(@NotNull String key) { + + return this.configs.remove(key); + } @Override - public boolean hasConfig( - @NotNull String name - ) { - return this.configs.containsKey(name); + public boolean contains(@NotNull String key) { + + return this.configs.containsKey(key); + } @Override - public @NotNull Optional getConfig( - @NotNull String name - ) { - return Optional.ofNullable(this.configs.get(name)); + public @NotNull Optional find(@NotNull String key) { + return Optional.ofNullable(this.findOrNull(key)); } @Override - public @NotNull Collection getAll() { + public @Nullable C findOrNull(@NotNull String key) { + return this.configs.get(key); + } + + @Override + public @NotNull Collection values() { return Collections.unmodifiableCollection(this.configs.values()); } @Override public void loadAll() throws IOException { + for (final C config : this.configs.values()) { + config.load(); + } + } @Override public void saveAll() throws IOException { + for (final C config : this.configs.values()) { + config.save(); + } + } @Override public @NotNull Iterator iterator() { - return getAll().iterator(); + return values().iterator(); } } \ No newline at end of file diff --git a/common/src/main/java/com/g4vrk/config/manager/YamlConfigManager.java b/common/src/main/java/com/g4vrk/config/manager/YamlConfigManager.java new file mode 100644 index 0000000..4a991dc --- /dev/null +++ b/common/src/main/java/com/g4vrk/config/manager/YamlConfigManager.java @@ -0,0 +1,6 @@ +package com.g4vrk.config.manager; + +import com.g4vrk.config.YamlConfig; + +public class YamlConfigManager extends SimpleConfigManager { +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..f87e33b --- /dev/null +++ b/gradle.properties @@ -0,0 +1,5 @@ +group=com.g4vrk +version=1.1.0 +org.gradle.configuration-cache=true +org.gradle.parallel=true +org.gradle.caching=true diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..d997cfc Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..c42672d --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..0262dcb --- /dev/null +++ b/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/b631911858264c0b6e4d6603d677ff5218766cee/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..c4bdd3a --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,93 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 0000000..262dad6 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,6 @@ +jdk: + - openjdk17 +before_install: + - chmod +x gradlew +install: + - ./gradlew clean build publishToMavenLocal \ No newline at end of file diff --git a/libs.versions.toml b/libs.versions.toml new file mode 100644 index 0000000..8d4a8a9 --- /dev/null +++ b/libs.versions.toml @@ -0,0 +1,30 @@ +[versions] + +paper-api = "1.18.2-R0.1-SNAPSHOT" + +minecraft = "1.18.2" + +lombok = "1.18.48" + +shadow = "9.6.1" +run-task = "3.0.2" + +configurate = "4.2.0" + +junit = "6.1.3" +junit-platform = "6.1.3" + +[libraries] +paper-api = { module = "io.papermc.paper:paper-api", version.ref = "paper-api" } + +lombok = { module = "org.projectlombok:lombok", version.ref = "lombok" } + +configurate-yaml = { module = "org.spongepowered:configurate-yaml", version.ref = "configurate" } + +junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" } +junit-jupiter = { module = "org.junit.jupiter:junit-jupiter" } +junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junit-platform" } + +[plugins] +shadow = { id = "com.gradleup.shadow", version.ref = "shadow" } +run-paper = { id = "xyz.jpenilla.run-paper", version.ref = "run-task" } diff --git a/pom.xml b/pom.xml deleted file mode 100644 index bf0770d..0000000 --- a/pom.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - 4.0.0 - - com.g4vrk - FunctionalConfiguration - 1.0.0 - jar - - FunctionalConfiguration - - - 17 - UTF-8 - - - - clean package - - - org.apache.maven.plugins - maven-compiler-plugin - 3.13.0 - - ${java.version} - ${java.version} - - - - org.apache.maven.plugins - maven-shade-plugin - 3.5.3 - - - package - - shade - - - - - - - - src/main/resources - true - - - - - - - - - - org.projectlombok - lombok - 1.18.42 - provided - - - - org.spongepowered - configurate-yaml - 4.2.0 - provided - - - - - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..26375bb --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,19 @@ +rootProject.name = "FunctionalConfiguration" + +include( + "common", +) + +dependencyResolutionManagement { + + versionCatalogs { + + create("libs") { + + from(files("libs.versions.toml")) + + } + + } + +} \ No newline at end of file diff --git a/src/main/java/com/g4vrk/functionalConfiguration/Config.java b/src/main/java/com/g4vrk/functionalConfiguration/Config.java deleted file mode 100644 index e65953d..0000000 --- a/src/main/java/com/g4vrk/functionalConfiguration/Config.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.g4vrk.functionalConfiguration; - -import org.jetbrains.annotations.NotNull; -import org.spongepowered.configurate.ConfigurationNode; - -import java.io.BufferedReader; -import java.io.IOException; - -public interface Config { - - @NotNull ConfigurationNode getRoot(); - - @NotNull ConfigurationNode node(@NotNull Object... path); - - void load() throws IOException; - void save() throws IOException; - - void applyDefaults(@NotNull BufferedReader reader) throws IOException; - -} diff --git a/src/main/java/com/g4vrk/functionalConfiguration/YamlConfig.java b/src/main/java/com/g4vrk/functionalConfiguration/YamlConfig.java deleted file mode 100644 index ca02f46..0000000 --- a/src/main/java/com/g4vrk/functionalConfiguration/YamlConfig.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.g4vrk.functionalConfiguration; - -import org.jetbrains.annotations.NotNull; -import org.spongepowered.configurate.ConfigurationNode; -import org.spongepowered.configurate.serialize.SerializationException; -import org.spongepowered.configurate.yaml.YamlConfigurationLoader; - -import java.io.BufferedReader; -import java.io.IOException; - -public class YamlConfig implements Config { - - private final YamlConfigurationLoader loader; - - private ConfigurationNode root; - - public YamlConfig( - @NotNull YamlConfigurationLoader loader - ) { - this.loader = loader; - } - - @Override - public @NotNull ConfigurationNode getRoot() { - return root; - } - - @Override - public @NotNull ConfigurationNode node(@NotNull Object... path) { - return root.node(path); - } - - @Override - public void load() throws IOException { - this.root = loader.load(); - } - - @Override - public void save() throws IOException { - loader.save(root); - } - - @Override - public void applyDefaults(final @NotNull BufferedReader reader) throws IOException { - final ConfigurationNode defaults = YamlConfigurationLoader.builder() - .source(() -> reader) - .build() - .load(); - - merge(this.root, defaults); - } - - private void merge( - final @NotNull ConfigurationNode target, - final @NotNull ConfigurationNode defaults - ) { - defaults.childrenMap().forEach((key, defChild) -> { - final ConfigurationNode targetChild = target.node(key); - - if (targetChild.virtual()) { - try { - target.node(key).set(defChild.raw()); - } catch (SerializationException ignored) { - } - } else { - merge(targetChild, defChild); - } - }); - } -} diff --git a/src/main/java/com/g4vrk/functionalConfiguration/loader/ConfigLoader.java b/src/main/java/com/g4vrk/functionalConfiguration/loader/ConfigLoader.java deleted file mode 100644 index 360668a..0000000 --- a/src/main/java/com/g4vrk/functionalConfiguration/loader/ConfigLoader.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.g4vrk.functionalConfiguration.loader; - -import com.g4vrk.functionalConfiguration.Config; -import org.jetbrains.annotations.NotNull; - -import java.nio.file.Path; - -public interface ConfigLoader { - - @NotNull C from(@NotNull Path path); - - @NotNull Iterable from(@NotNull Iterable paths); - -} diff --git a/src/main/java/com/g4vrk/functionalConfiguration/loader/YamlConfigLoader.java b/src/main/java/com/g4vrk/functionalConfiguration/loader/YamlConfigLoader.java deleted file mode 100644 index f748188..0000000 --- a/src/main/java/com/g4vrk/functionalConfiguration/loader/YamlConfigLoader.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.g4vrk.functionalConfiguration.loader; - -import com.g4vrk.functionalConfiguration.YamlConfig; -import org.jetbrains.annotations.NotNull; -import org.spongepowered.configurate.yaml.YamlConfigurationLoader; - -public class YamlConfigLoader extends AbstractConfigLoader { - @Override - protected @NotNull YamlConfig from(@NotNull YamlConfigurationLoader loader) { - return new YamlConfig(loader); - } -} diff --git a/src/main/java/com/g4vrk/functionalConfiguration/loader/mapped/MappedConfigLoader.java b/src/main/java/com/g4vrk/functionalConfiguration/loader/mapped/MappedConfigLoader.java deleted file mode 100644 index b99e83b..0000000 --- a/src/main/java/com/g4vrk/functionalConfiguration/loader/mapped/MappedConfigLoader.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.g4vrk.functionalConfiguration.loader.mapped; - -import com.g4vrk.functionalConfiguration.Config; -import com.g4vrk.functionalConfiguration.NamedConfigEntry; -import org.jetbrains.annotations.NotNull; - -import java.io.File; - -public interface MappedConfigLoader { - - @NotNull NamedConfigEntry from(@NotNull File file); - - @NotNull Iterable> from(@NotNull Iterable files); - -} diff --git a/src/main/java/com/g4vrk/functionalConfiguration/manager/ConfigManager.java b/src/main/java/com/g4vrk/functionalConfiguration/manager/ConfigManager.java deleted file mode 100644 index a6de4c5..0000000 --- a/src/main/java/com/g4vrk/functionalConfiguration/manager/ConfigManager.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.g4vrk.functionalConfiguration.manager; - -import com.g4vrk.functionalConfiguration.Config; -import com.g4vrk.functionalConfiguration.NamedConfigEntry; -import org.jetbrains.annotations.NotNull; - -import java.io.IOException; -import java.util.Collection; -import java.util.Iterator; -import java.util.Optional; - -public interface ConfigManager extends Iterable { - - void register( - @NotNull NamedConfigEntry namedConfigEntry - ); - - void registerAll( - @NotNull Iterable> namedConfigEntries - ); - - void unregister( - @NotNull String name - ); - - boolean hasConfig( - @NotNull String name - ); - - @NotNull Optional getConfig( - @NotNull String name - ); - - @NotNull Collection getAll(); - - void loadAll() throws IOException; - - void saveAll() throws IOException; - - default void reloadAll() throws IOException { - this.loadAll(); - } - -} diff --git a/src/main/java/com/g4vrk/functionalConfiguration/manager/YamlConfigManager.java b/src/main/java/com/g4vrk/functionalConfiguration/manager/YamlConfigManager.java deleted file mode 100644 index 38e78d0..0000000 --- a/src/main/java/com/g4vrk/functionalConfiguration/manager/YamlConfigManager.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.g4vrk.functionalConfiguration.manager; - -import com.g4vrk.functionalConfiguration.YamlConfig; - -public class YamlConfigManager extends SimpleConfigManager { -}