promotional bannermobile promotional banner
premium banner
A simpler way to use Hytale config codecs

Description

CodecLib

CodecLib is a lightweight Hytale config library that automates the creation of BuilderCodec using reflection. It allows you to create complex configuration files and data structures using simple POJOs (Plain Old Java Objects), without manually defining every field and codec.


🚀 Usage

1. Basic Configuration

Create a class with the fields you want to serialize. You can initialize them to set default values.

/**
 * RULES:
 * 1. Fields MUST NOT be final, static or transient.
 * 2. Fields MUST start with an uppercase letter (Hytale Config convention).
 * 3. Be sure that the custom class you use are annotated with @Configuration as well.
 */
@Configuration
public class MyConfig {

    private String ExampleField = "defaultValue";

    @FieldName("DifferentName") //Inside config.json this field will be named "DifferentName"
    private String exampleFieldButWithDifferentName = "defaultValue2";

    @SkipConfigField //This will skip the field for serialization
    private String thisFieldWillNotExist = "defaultValue3";

    private int ExampleIntField = 42;
}

2. Generating the Codec

Use the CodecFactory to generate the codec and load your config.

// ... inside your plugin ...

public CodecLibPlugin(@Nonnull JavaPluginInit init) {
    super(init);
    instance = this;
    //Optionally, you can register your own codecs for your types
    CodecFactory.registerCustomCodec(Path.class, Codec.PATH);
    //Just use CodecFactory.createClassCodec(YourClass.class) as Codec
    CONFIG = withConfig("yourcustomconfig", CodecFactory.createClassCodec(ExampleConfig.class));
}

@Override
protected void setup() {
    CONFIG.save();//You can save normally like this
    assert Objects.equals(CONFIG.get().getExampleField(), "defaultValue");
    assert Objects.equals(CONFIG.get().getExampleIntField(), 42);
    assert Objects.equals(CONFIG.get().getExampleFieldButWithDifferentName(), "defaultValue2");
}

3. Nested Objects

You can put objects inside other objects. CodecLib will recursively generate codecs for them.

@Configuration
public class DatabaseConfig {
    public String Host = "localhost";
    public int Port = 3306;
}
@Configuration
public class MainConfig {
    public String PluginName = "MyPlugin";

    // This will be automatically handled!
    public DatabaseConfig Database = new DatabaseConfig();
}

📦 Installation

Replace with your actual JitPack/Maven instructions if hosted, otherwise shade or copy the library.

Gradle (Groovy)

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

dependencies {
    implementation 'com.github.Emibergo02:CodecLib:main-SNAPSHOT'
}
//It is suggested to relocate the package in your project
shadowJar {
    relocate 'dev.unnm3d.codeclib', 'your.package.name.codeclib'
}

✅ Supported Types

The library automatically resolves codecs for the following types:

  • String, Boolean, Integer, Double, Long, Float, Byte, Short
  • UUID, Instant
  • String[], int[], double[], long[], float[]
  • Any other Class (via recursion)
  • More are coming, stay tuned

📋 Requirements

  • Java 25+
  • Hytale Server API (for BuilderCodec, Codec, etc.)