Skip to content

Save variables to files and load their value by object mapper

License

Notifications You must be signed in to change notification settings

CKATEPTb-minecraft/Varflex

 
 

Repository files navigation

Varflex


Save variables to files and load their value by object mapper. It is useful for people with basic understanding of java, gradle, workflow and is designed for lazy people

License Sonatype Nexus (Snapshots) Publish Discord


Versioning

We use Semantic Versioning 2.0.0 to manage our releases.

Features

  • Easy to use
  • Automatic serialize
  • Automatic deserialize
  • Comment support
  • Yaml support
  • Xml support
  • Json support
    • Hocon support
    • Gson support
    • Jackson support
  • Documented

Download

Download from our repository or depend via Gradle:

repositories {
    maven("https://repo.animecraft.fun/repository/maven-snapshots/")
}

dependencies {
    implementation("dev.ckateptb.minecraft:Varflex:<version>")
}

How To

  • Import the dependency as shown above
  • Add Varflex as a dependency to your plugin.yml
name: ...
version: ...
main: ...
depend: [ Varflex ]
authors: ...
description: ...
  • Create you config class with fields that should be saved (extends GsonConfig/HoconConfig/JacksonConfig/XmlConfig/YamlConfig)
import dev.ckateptb.common.tableclothconfig.hocon.HoconConfig;
import lombok.Getter;
import lombok.Setter;
import org.spongepowered.configurate.objectmapping.meta.Comment;
import org.spongepowered.configurate.objectmapping.meta.Matches;
import org.spongepowered.configurate.objectmapping.meta.Setting;

import java.io.File;
import java.nio.file.Paths;
import java.util.List;

@Getter // Lombok's annotation. Generate Getters for all field
@Setter // Lombok's annotation. Generate Setters for all field
public class HoconExampleConfig extends HoconConfig {
    // Create field and set default value
    @Setting("example.custom.key") // Path for key separated by dot
    private List<String> list = List.of("Hello", "programmer", "world!");
    @Comment(value = "Wow, its comment", override = true)
    private boolean isDev = true;
    @Matches("^H") // Regex for matching
    private String helloWorldString = "Hello World";

    @Override
    public File getFile() { // File location (will be auto-created)
        return Paths.get("config", "config.conf").toFile();
    }
}
# Example auto-generated config file
example.custom.key=[
    "Hello",
    "programmer",
    "world!"
]
hello-world-string="Hello World"
# Wow, its comment
is-dev=true
  • Initialize configuration class
public class MyPlugin extends JavaPlugin {
    public void onEnable() {
        HoconExampleConfig config = new HoconExampleConfig(); // Create new instance
        config.load(); // Load saved config file if present
        config.save(); // Save changes to config file if changes present
    }
}
  • Nothing more, easy to do.

About

Save variables to files and load their value by object mapper

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%