A library that automatically generates and manages configuration files based on classes.

Related tags

Spring Boot sc-cfg
Overview

sc-cfg

SC-CFG is a simple, yet powerful library that automatically generate configuration files based on your classes. Compatible with Java 8+ and Kotlin, anyone can use it and start enjoying the commodities right now.

You won't have to worry about reloading your configuration anymore, SC-CFG handles everything for you, automatically.

Add the library as dependency

Modules

First, pick what platform modules you're going to use, currently there are:

  • bukkit for Spigot 1.8+ and Java 8+
  • bungee for BungeeCord
  • kotlin for Kotlin extensions on any platform

Second, pick the serializers you're going to use according to the file type you want your configs have.

  • hocon (.conf)
  • json (.json)
  • yaml (.yml)

Then add them to your favorite build tool.

Gradle

repositories {
    maven { url = 'https://jitpack.io' }
}

dependencies {
    // replace 'bukkit' with artifact name
    implementation("com.github.secretx33.sc-cfg:bukkit:main-SNAPSHOT")
}

Maven

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.github.secretx33.sc-cfg</groupId>
        <!-- Replace 'bukkit' with the artifact name -->
        <artifactId>bukkit</artifactId>
        <version>main-SNAPSHOT</version>
    </dependency>
</dependencies>

Usage

Annotate your config class

Using SC-CFG is as simple as annotating your config class with @Configuration. Both public and private fields are supported, final or not, in both the own class and parents.

import com.github.secretx33.sccfg.api.annotation.Configuration;

// you just have to annotate the class
@Configuration
public class MyConfig {
    
    public int someValue = 0;
    private final String someString = "rock";
}

Which is serialized to MyConfig.yml, automatically.

someValue: 0
someString: rock

Get the instance of the config class

To get the singleton instance of the class through the Config class, do as follows.

public class MyPlugin extends JavaPlugin {
    @Override
    public void onEnable() {
        // get the instance of your config
        MyConfig config = Config.getConfig(MyConfig.class);
    }
}

Register an instance of the config class

If your config class cannot have a no args constructor for some reason, like when it needs some dependency injected on it, you can handle the instantiation of the config, registering it later, when is convenient for you.

import com.github.secretx33.sccfg.Config;

public class MyPlugin extends JavaPlugin {
    @Override
    public void onEnable() {
        MyConfigOne config = new MyConfig(this); // config that require some dependency injected
        Config.registerConfig(config); // you can register any config whenever is convenient
        // Config.registerConfigs(...); // and even multiple configs at once
    }
}

Features

Automatic reload

Configs are already reload automatically whenever there's some modification on the file, you don't have to do anything extra.

Save config

You can save config current values to the disk with a single method call.

public class MyPlugin extends JavaPlugin {

    @Override
    public void onEnable() {
        MyConfig config = Config.getConfig(MyConfig.class);
        
        // save your config by using
        Config.saveConfig(config);
        // or
        Config.saveConfig(MyConfig.class);
    }
}

Multiple file types

The default file type for configurations is YAML, but we do support multiple file type (check all supported types here).

To switch between then is as easy as changing one option on your @Configuration annotation (and add the respective serializer for that type).

import com.github.secretx33.sccfg.api.*;

// switch your config to hocon
@Configuration(type = FileType.HOCON)
public class MyConfig {
    // ...
}

Header and comments

It's now possible to add a header to the file by setting header property of your @Configuration annotation, and also comments directly to properties by annotating them with @Comment (or @NamedPath).

OBS.: Json does not support comments by nature, so any comments on this FileType will be ignored.

import com.github.secretx33.sccfg.api.*;

@Configuration(header = {
    "I am the first line of the header",
    "and I am the second one",
})
public class MyConfig {
    
    @Comment("this value is awesome")
    public int someValue = 0;
    
    @Comment({"but this one...", "this one ROCKS!"})
    private final String someString = "rock";
}

And our MyConfig.yml will looks like this.

# I am the first line of the header
# and I am the second one

# this value is awesome
someValue: 0
# but this one...
# this one ROCKS!
someString: rock

And much, much more... Please check our wiki for a complete list of sc-cfg features with usage examples.

Kotlin

Please check our wiki for detailed usages of Kotlin extension functions, but there's a brief list of them.

import com.github.secretx33.sccfg.*

// get the singleton instance of MyConfig
val config = getConfig<MyConfig>()
val lazyConfig = lazyConfig<MyConfig>()

// register a config instance manually initiated
val anotherConfig = AnotherConfig(someDependency)
registerConfig(anotherConfig)

// persist the config to the disk
saveConfig(config)
// or
saveConfig<MyConfig>()

// save default values to the disk, optionally overriding the file if exists
saveDefaults(config, reloadAfterwards = true, overrideIfExists = false)

Bugs or suggestions

Please report all bugs or post suggestions on the Issue section.

License

Read file LICENSE.

You might also like...

Generates a Proguard mapping file for use in obfuscating your Java projects.

Reaper Generates a Proguard mapping file for use in obfuscating your Java projects. Features Automatically checks for duplicate names. Interactive, in

Dec 29, 2022

Resconstruct is a java library to infer missing information vectors of java classes.

Reconstruct Resconstruct is a java library to infer missing information vectors of java classes. Features Phantom classes Inheritance solving Dummy fi

Nov 17, 2022

A Velocity proxy plugin for Minecraft server discovery in k8s. All discovered servers are automatically added to the Velocity proxy.

kryo-server-discovery This plugin connects minecraft servers to a velocity proxy within Kubernetes. The service account in the namespace which the pro

Sep 13, 2022

A minecraft plugin to automatically use a totem of undying from your inventory

A minecraft plugin to automatically use a totem of undying from your inventory

AutoTotem Spigot Download https://www.spigotmc.org/resources/autototem.99443/ Automatically use totems of undying from your inventory without needing

May 5, 2022

This project is an Android Studio plugin version of BlackObfuscator, it supports obfuscating code automatically. More information about this project are in BlackObfuscator.

DEX控制流混淆插件版 · BlackObfuscator-ASPlugin English Version 本项目为 BlackObfuscator 的Android Studio插件版,支持打包自动化混淆。功能及介绍方面请查看 BlackObfuscator 源项目 注意事项 首要注意:Blac

Dec 31, 2022

An API Library that provides the functionality to access, manage and store device topologies found in JSON files using Java and Maven Framework

An API Library that provides the functionality to access, manage and store device topologies found in JSON files using Java and Maven Framework

Topology API 📙 About An API library which provides the functionality to access, manage and store device topologies. 📝 Description Read a topology fr

Aug 4, 2022

Z2Laser - a simple Java-based tool to convert Z movements in your G-Code files to Laser on or off commands

Z2Laser - a simple Java-based tool to convert Z movements in your G-Code files to Laser on or off commands

Feb 20, 2022

A list of direct references to classes and interfaces in the Java Language Specification (3d Ed.)

A list of direct references to classes and interfaces in the Java Language Specification (3d Ed.) and a program to compute the indirectly required classes and interfaces

Jun 3, 2022

The Apache Commons CSV library provides a simple interface for reading and writing CSV files of various types.

Apache Commons CSV The Apache Commons CSV library provides a simple interface for reading and writing CSV files of various types. Documentation More i

Dec 26, 2022
Comments
  • java.lang.NoClassDefFoundError: com/github/secretx33/sccfg/Config

    java.lang.NoClassDefFoundError: com/github/secretx33/sccfg/Config

    I built your framework into a library .jar with all its dependencies satisfied but I'm getting this error java.lang.NoClassDefFoundError: com/github/secretx33/sccfg/Config the error is found at at me.nixeee.magictools.MagicTools.onEnable(MagicTools.java:19) but the enable looks like this PrivateVaultStorage storageconfig = Config.getConfig(PrivateVaultStorage.class); Config.registerConfig(storageconfig);

    Any idea what is going on with this class not found error?

    opened by Yuzi1221 2
  • Added support for header and comments

    Added support for header and comments

    Features

    • Added official support for BungeeCord!
    • Added support for file headers through a new property on the Configuration annotation.
    • Added support for comments through the new @Comment annotation.
    • Added @NamedPath, a powerful annotation that combines @Name, @Path, @Comment in a single thing.

    Changes

    • MemorySectionAdapter now uses recursion to serialize/deserialize MemorySection, which made it much more powerful because it now fully supports nested configuration section entries.
    • Improved javadocs.

    Fixes

    • Fixed issue with Kotlin extension saveDefaults.
    opened by SecretX33 0
  • Fixed bug with Map serialization, added alias for value of Configuration annotation

    Fixed bug with Map serialization, added alias for value of Configuration annotation

    Changes

    • Added name as alias for value property of @Configuration.
    • Added note about thread safeness of getConfig, registerConfig, and registerConfigs methods to make clear what kind of thread safeness they offer.

    Bug Fixes

    • The values from the config class instance were being replaced by the serializable equivalent of their values, so a Map<String, ItemStack[]> would get replaced by a Map<String, List<String>> or something like that, which caused the AbstractSerializer#setValueOnField method to throw IllegalArgumentException. Map<String, ItemStack[]> is one of the types which triggered that issue.
    opened by SecretX33 0
ReleaseFab is a Java client application which automatically generates Release Notes for any project.

ReleaseFab is a Java client application which atomatically generates Release Notes for any project. The information can be gathered from multiple different sources including the source code itself, the Git repository and an Application Lifecycle Management System of your choice.

comlet Verteilte Systeme GmbH 7 Jun 10, 2022
Auto-Unit-Test-Case-Generator automatically generates high-level code-coverage JUnit test suites for Java, widely used within the ANT Group.

中文README传送门 What is Auto-Unit-Test-Case-Generator Auto-Unit-Test-Case-Generator generates JUnit test suites for Java class just as its name. During te

TRaaS 108 Dec 22, 2022
Manages server status and gives log of status information. front end - angular js, backend- sbring boot, DB-MySQL

ServerManagerApplication / | | / | | ( ___ _ __ __ __ ___ _ __ | \ / | __ _ _ __ __ _ __ _ ___ _ __ __ \ / _ \ | '| \ \ / / / _ \ | '| | |/| | / | | '

null 1 Jan 6, 2022
This is a Maven plugin designed to help developers automatizing the creation of code classes from YML files based on AsyncApi and OpenAPI.

SCS MultiApi Maven Plugin This is a Maven plugin designed to help developers automatizing the creation of code classes from YML files based on AsyncAp

Corunet 0 Dec 20, 2022
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)

OpenAPI Generator Master (5.4.x): 6.0.x (6.0.x): ⭐ ⭐ ⭐ If you would like to contribute, please refer to guidelines and a list of open tasks. ⭐ ⭐ ⭐ ‼️

OpenAPI Tools 14.8k Dec 30, 2022
Apollo is a reliable configuration management system suitable for microservice configuration management scenarios.

English | 中文 Apollo - A reliable configuration management system Apollo is a reliable configuration management system. It can centrally manage the con

Apollo 27.6k Jan 5, 2023
YetAnotherConfigLib (yacl) is just that. A builder-based configuration library for Minecraft.

YetAnotherConfigLib Yet Another Config Lib, like, what were you expecting? Why does this mod even exist? This mod was made to fill a hole in this area

Xander 36 Dec 29, 2022
Generates and keeps up-to-date your Spring Boot applications' Let's Encrypt or other ACME compliant SSL certificates.

Generates and keeps up-to-date your Spring Boot applications' Let's Encrypt or other ACME compliant SSL certificates. Pure Java in a single file of library code. An automated embedded alternative to Certbot and docker-sidecars. No JVM restart is needed on certificate update.

Valentyn Berezin 12 Nov 18, 2022
JAXB-based Java library for Word docx, Powerpoint pptx, and Excel xlsx files

README What is docx4j? docx4j is an open source (Apache v2) library for creating, editing, and saving OpenXML "packages", including docx, pptx, and xs

Jason Harrop 1.9k Jan 2, 2023
Buried Barrels is a simple vanilla+ mod that generates hidden barrels throughout the world.

Buried Barrels is a simple vanilla+ mod that generates hidden barrels throughout the world. Special maps leading to these treasures can be found on mo

Aurel 2 Apr 7, 2022