Skip to content

Latest commit

 

History

History
44 lines (34 loc) · 898 Bytes

README.md

File metadata and controls

44 lines (34 loc) · 898 Bytes

bukkit-object

Setup

repositories {
    mavenCentral()
}

dependencies {
    implementation 'io.typst:bukkit-object:1.0.2'
}

Usage

import java.io.File;

class MyPlugin extends JavaPlugin {
    private final BukkitObjectMapper mapper = new BukkitObjectMapper();
    private MyData myData = MyData.empty;

    @Override
    public void onEnable() {
        // load
        YamlConfiguration config = YamlConfiguration.loadConfiguration(getConfigFile());
        myData = mapper.decode(config.getValues(false), MyData.class).getOrThrow();
    }

    @Override
    public void onDisable() {
        // save
        YamlConfiguration config = new YamlConfiguration();
        mapper.encode(myData).getOrThrow().forEach(config::set);
        config.save(file);
    }

    public File getConfigFile() {
        return new File(getDataFolder(), "config.yml");
    }
}