Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mefrreex/configuration
Library for working with configs based on Sponge Configurate
https://github.com/mefrreex/configuration
Last synced: about 1 month ago
JSON representation
Library for working with configs based on Sponge Configurate
- Host: GitHub
- URL: https://github.com/mefrreex/configuration
- Owner: MEFRREEX
- Created: 2024-05-02T23:40:43.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-05-30T21:00:17.000Z (7 months ago)
- Last Synced: 2024-05-30T23:34:29.240Z (7 months ago)
- Language: Java
- Homepage:
- Size: 50.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Configuration
A library for working with configuration files based on Sponge Configurate.## 📖 Overview
**Configuration** is a flexible Java library for managing various types of configuration files, such as YAML, JSON, and HOCON. This library simplifies the process of creating, modifying, and reading configuration files with a clear and intuitive API.### ✨ Features
- **Multiple Formats Support**: Easily switch between YAML, JSON, and HOCON formats.
- **Dynamic Configuration Handling**: Set, modify, and retrieve values from configurations with a clean syntax.
- **Auto-Detection**: Automatically detects the file format based on the extension.## 🛠Code Examples
### Creating a Configuration
```java
Config config = json ?
new JsonConfig(new File("config.json")) :
new YamlConfig(new File("config.yml"));
```### Setting Values in the Config
```java
// Getting the node we need and setting its value
config.node("string").setValue("Test string");
config.nodes("values.list").setValue(List.of(1, 2, 3));
config.nodes("values.map").setValue(Map.of("key", "Value"));// Saving the config
config.save();
```### Getting Values from the Config
```java
// Getting node values
String string = config.nodes("string").asString();
List listValues = config.nodes("values.list").asList();
Map mapValues = config.nodes("values.map").asMap();// Getting node or default value
String withDefaultValue = config.nodes("value").asString("Default Value");System.out.println(string + ", " + listValues + ", " + mapValues + ", " + withDefaultValue);
// Check if there is a node named non-existing-node
if (config.nodes("non-existing-node").isNull()) {
System.out.println("Node non-existing-node not found!");
}
```### Alternative Configuration Creation
```java
// Config types: YAML, JSON, HOCON, or DETECT (to auto-detect format by file name)
Config config = ConfigType.DETECT.createOf(new File("config.json"));
```## 🔌 Installation
### Maven
Add the following repository and dependency to your `pom.xml`:
```xml
jitpack.io
https://jitpack.io
com.github.MEFRREEX
Configuration
1.0.0```
### Gradle
Add the following repository and dependency to your `build.gradle`:
```groovy
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}dependencies {
implementation 'com.github.MEFRREEX:Configuration:1.0.0'
}
```---
[Switch to Russian](README_ru.md)