Sueta

SimpleJSONConfig – Smart JSON/YAML Configs & Data Stores for

1.4.2

serialization, configuration, library, gson, json, yaml

·Plugin

SimpleJSONConfig
Smart JSON/YAML configuration & data storage library for your Bukkit/Spigot/Paper plugins
Create, manage and share configs with zero boilerplate!

✨ Main Features

  • Create JSON or YAML configuration files for your plugins
  • Persist your data in flat files using Data Stores
  • Easily serialize your objects with a custom Serializer
  • Shared adapters for cross-plugin functionality (SharedGsonBuilder)
  • Add comments directly in your config with @comment annotation
  • Autowire configs into static fields using @Autowired
  • Share your configurations between plugins
  • Specify custom configuration directory
  • Built-in support for most crucial Bukkit/Spigot types:
    • ItemStack
    • Location
    • World
    • Block
    • And more...
  • Interfaces and superclasses support
  • Reload specific config or all at once
  • LRU cache for faster Data Store access
  • Automatic config file updates when fields change in your class

Quick Start

1. Register SimpleJSONConfig in your plugin

public class Main extends JavaPlugin {

    @Override
    public void onEnable() {
        // Default directory: YourPlugin/configuration/
        SimpleJSONConfig.INSTANCE.register(this);
       
        // Use YAML instead of JSON
        SimpleJSONConfig.INSTANCE.register(this, StoreType.YAML);
       
        // Specify custom directory
        SimpleJSONConfig.INSTANCE.register(this, new File("default/config/directory"));
    }
}

2. Create your config class

@Getter
@Configuration("config") // or config.json / path/to/config
@SuppressWarnings("FieldMayBeFinal") // no final modifiers yet
public class MyConfig extends Config {

    private String joinMessage = "Default join message";

    private List<ItemStack> startingEquipment = new ArrayList<>(
        Collections.singletonList(new ItemStack(Material.DIRT))
    );

    @Comment("This comment will appear in the config file too")
    private YourType something;
}

3. Access your config

// Option 1: Get directly
private MyConfig config = Config.getConfig(MyConfig.class);

// Option 2: Autowire into static field
@Autowired
private static MyConfig config;

Data Stores
Persist any object that implements Identifiable with just an annotation!

@Stored(value = "directory", storeType = StoreType.JSON)
public class MyClass implements Identifiable<UUID> {

    private final UUID id;
    private int count;

    @Override
    public UUID getId() {
        return id;
    }
}

Access it through a Service:

private static Service<UUID, MyClass> service = Service.getService(MyClass.class);

public void foo() {
    MyClass obj = new MyClass(UUID.randomUUID());
    service.save(obj); // serialize to file
    MyClass loaded = service.getById(obj.getId());
    List<MyClass> matching = service.getMatching(c -> c.getCount() > 10);
    service.delete(obj);
}

⚙️ Additional Features

  • Exclude fields from serialization with transient modifier
  • Serialize any object with the built-in Serializer
  • Reload configs at runtime
  • Enable LRU cache for Data Stores
  • Customize Gson with your own type adapters via SharedGsonBuilder
  • InterfaceAdapter support for complex polymorphic types

Maven & Gradle

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

<dependencies>
    <dependency>
        <groupId>com.github.2DevsStudio</groupId>
        <artifactId>SimpleJSONConfig</artifactId>
        <version>1.4.1</version>
        <scope>compile</scope>
        <!-- Or provided if you want cross-plugin config sharing -->
    </dependency>
</dependencies>
Gradle
repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'com.github.2DevsStudio:SimpleJSONConfig:1.4.1'
    // or compileOnly for cross-plugin config sharing
}

Why use SimpleJSONConfig?
Because writing config handling by hand is boring.
With SimpleJSONConfig you can:

  • Stop manually parsing JSON/YAML
  • Stop worrying about missing or outdated config fields
  • Share configurations between plugins easily
  • Store your data in a clean and type-safe way

Get it now on GitHub!
➡ GitHub Repository ⬅

Make your plugin development faster, cleaner, and more enjoyable with SimpleJSONConfig!

Similar projects

Plugin →