https://github.com/tetoe-mc/configx
A fabric API library for plugins to load & save configurations
https://github.com/tetoe-mc/configx
fabric fabric-mc minecraft minecraft-library server-plugin-library
Last synced: 22 days ago
JSON representation
A fabric API library for plugins to load & save configurations
- Host: GitHub
- URL: https://github.com/tetoe-mc/configx
- Owner: tetoe-mc
- License: cc0-1.0
- Created: 2025-01-27T02:47:20.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-03T02:11:25.000Z (over 1 year ago)
- Last Synced: 2025-04-06T03:28:06.093Z (about 1 year ago)
- Topics: fabric, fabric-mc, minecraft, minecraft-library, server-plugin-library
- Language: Java
- Homepage: https://curseforge.com/minecraft/mc-mods/config-x
- Size: 103 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Config X
[](https://github.com/NriotHrreion)
[](./LICENSE)
[](https://github.com/tetoe-mc/configx/stargazers)
[](https://github.com/tetoe-mc/configx/actions/workflows/build.yml)
## Description
This is a fabric API library for plugins to load & save configurations.
## Installation
1. Add the following to your build script:
```gradle
repositories {
maven {
url = uri("https://repo.codemc.io/repository/tetoe-mc")
}
}
dependencies {
// Approach #1: Ensure Config X is always available by including it within your own jar
include(modImplementation("space.nocp:configx:2.0.5"))
// Approach #2: Depend on Config X, but require that users install it themselves
modImplementation "space.nocp:configx:2.0.5"
}
```
2. Refresh your project.
## Usage
Remember to import the package before starting.
```java
import space.nocp.configx.api.*;
```
#### Register a configuration
Before registering a configuration, you need to write a class describing the configuration object and prepare a default configuration. Here, let's call the class `ConfigType`.
```java
// ...
Configuration config = ConfigManager.get().register("my-config", defaultConfig, ConfigType.class);
```
#### Get a configuration
After registering your configuration, you can use `config()` method to get the configuration at anywhere in your project.
```java
Configuration config = ConfigManager.get().config("my-config");
```
#### Get & set the configuration object
```java
Configuration config = ...;
ConfigType configObj = config.get();
configObj.myValue = "Hello World";
config.set(configObj);
config.save(); // Remember to save the config after setting it
```
#### Load the configuration from the file system manually
Usually, the configuration is always up-to-date with the one storing in the file system. But sometimes, you may want to refresh it manually.
```java
Configuration config = ...;
config.load();
```
#### Get the info of the configuration
```java
Configuration config = ...;
String id = config.id; // my-config
config.getFileName(); // my-config.json
config.getPath().toString(); // C:/path/to/config/my-config.json
```
#### Use custom Gson to parse JSON
Config X stores your configuration in the JSON format. When you stores objects that requires custom serializers and deserializers, you need to build your own Gson to achieve this.
Before registering your configuration, you need to prepare your Gson in advance. Here, let's assume we already have a custom Gson object called `myGson`.
Just simply add the Gson object as a parameter after all the parameters in `register()` method, and the parsing operations will be done with the provided Gson.
```java
// ...
Configuration config = ConfigManager.get().register("my-config", defaultConfig, ConfigType.class, myGson);
```
For more information about custom serializer and deserializer in Gson, see the article: [Building a Personalized Serializer and Deserializer using Java Gson Library](https://medium.com/@alexandre.therrien3/personalized-serializer-and-deserializer-using-java-gson-library-c079de3974d4)
## Build from source
```cmd
git clone https://github.com/tetoe-mc/configx.git
cd configx
./gradlew build
```
Then you can get the jar file in the build folder.
## LICENSE
[CC0 1.0](./LICENSE)