Search in sources :

Example 1 with OkaeriValidator

use of eu.okaeri.configs.validator.okaeri.OkaeriValidator in project FunnyGuilds by FunnyGuilds.

the class ConfigurationFactory method createTablistConfiguration.

public TablistConfiguration createTablistConfiguration(File tablistConfigurationFile) {
    return ConfigManager.create(TablistConfiguration.class, (it) -> {
        it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesCommons());
        it.withSerdesPack(registry -> {
            registry.register(new NumberRangeTransformer());
            registry.register(new TablistPageSerializer());
            registry.register(new SkinTextureSerializer());
        });
        it.withBindFile(tablistConfigurationFile);
        it.saveDefaults();
        it.load(true);
        it.migrate(new T0001_Update_player_list_animated());
    });
}
Also used : YamlBukkitConfigurer(eu.okaeri.configs.yaml.bukkit.YamlBukkitConfigurer) T0001_Update_player_list_animated(net.dzikoysk.funnyguilds.config.migration.T0001_Update_player_list_animated) SkinTextureSerializer(net.dzikoysk.funnyguilds.config.serdes.SkinTextureSerializer) SerdesCommons(eu.okaeri.configs.serdes.commons.SerdesCommons) NumberRangeTransformer(net.dzikoysk.funnyguilds.config.serdes.NumberRangeTransformer) TablistPageSerializer(net.dzikoysk.funnyguilds.config.tablist.TablistPageSerializer) OkaeriValidator(eu.okaeri.configs.validator.okaeri.OkaeriValidator)

Example 2 with OkaeriValidator

use of eu.okaeri.configs.validator.okaeri.OkaeriValidator in project FunnyGuilds by FunnyGuilds.

the class ConfigurationFactory method createPluginConfiguration.

public PluginConfiguration createPluginConfiguration(File pluginConfigurationFile) {
    return ConfigManager.create(PluginConfiguration.class, (it) -> {
        it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesCommons());
        it.withSerdesPack(registry -> {
            registry.register(new RawStringTransformer());
            registry.register(new MaterialTransformer());
            registry.register(new ItemStackTransformer());
            registry.register(new EntityTypeTransformer());
            registry.register(new FunnyTimeTransformer());
            registry.register(new RangeFormattingTransformer());
            registry.register(new VectorSerializer());
        });
        it.withBindFile(pluginConfigurationFile);
        it.withLogger(FunnyGuilds.getInstance().getLogger());
        it.saveDefaults();
        it.load(true);
        it.migrate(new P0001_Fix_freecam_compensation_key_case(), new P0002_Migrate_old_heart_configuration(), new P0003_Migrate_old_tnt_protection_configuration(), new P0004_Migrate_tablist_into_separate_file(), new P0005_Fix_heart_configuration_centery_key());
    });
}
Also used : ItemStackTransformer(net.dzikoysk.funnyguilds.config.serdes.ItemStackTransformer) SerdesCommons(eu.okaeri.configs.serdes.commons.SerdesCommons) P0004_Migrate_tablist_into_separate_file(net.dzikoysk.funnyguilds.config.migration.P0004_Migrate_tablist_into_separate_file) FunnyTimeTransformer(net.dzikoysk.funnyguilds.config.serdes.FunnyTimeTransformer) RawStringTransformer(net.dzikoysk.funnyguilds.config.serdes.RawStringTransformer) YamlBukkitConfigurer(eu.okaeri.configs.yaml.bukkit.YamlBukkitConfigurer) P0001_Fix_freecam_compensation_key_case(net.dzikoysk.funnyguilds.config.migration.P0001_Fix_freecam_compensation_key_case) P0003_Migrate_old_tnt_protection_configuration(net.dzikoysk.funnyguilds.config.migration.P0003_Migrate_old_tnt_protection_configuration) EntityTypeTransformer(net.dzikoysk.funnyguilds.config.serdes.EntityTypeTransformer) RangeFormattingTransformer(net.dzikoysk.funnyguilds.config.serdes.RangeFormattingTransformer) VectorSerializer(net.dzikoysk.funnyguilds.config.serdes.VectorSerializer) P0002_Migrate_old_heart_configuration(net.dzikoysk.funnyguilds.config.migration.P0002_Migrate_old_heart_configuration) MaterialTransformer(net.dzikoysk.funnyguilds.config.serdes.MaterialTransformer) P0005_Fix_heart_configuration_centery_key(net.dzikoysk.funnyguilds.config.migration.P0005_Fix_heart_configuration_centery_key) OkaeriValidator(eu.okaeri.configs.validator.okaeri.OkaeriValidator)

Example 3 with OkaeriValidator

use of eu.okaeri.configs.validator.okaeri.OkaeriValidator in project okaeri-platform by OkaeriPoland.

the class ConfigurationComponentResolver method make.

@Override
@SuppressWarnings("unchecked")
public Object make(@NonNull ComponentCreator creator, @NonNull BeanManifest manifest, @NonNull Injector injector) {
    if (!OkaeriConfig.class.isAssignableFrom(manifest.getType())) {
        throw new IllegalArgumentException("Component of @Configuration on type requires class to be a OkaeriConfig: " + manifest);
    }
    long start = System.currentTimeMillis();
    Class<? extends OkaeriConfig> configType = (Class<? extends OkaeriConfig>) manifest.getType();
    Messages messages = configType.getAnnotation(Messages.class);
    if (messages != null) {
        throw new IllegalArgumentException("Cannot register @Messages with raw OkaeriConfig type, use LocaleConfig: " + configType);
    }
    Configuration configuration = configType.getAnnotation(Configuration.class);
    String path = configuration.path();
    boolean defaultNotNull = configuration.defaultNotNull();
    Class<? extends Configurer> provider = configuration.provider();
    try {
        Configurer configurer = (provider == Configuration.DEFAULT.class) ? this.defaultConfigurerProvider.get() : injector.createInstance(provider);
        OkaeriSerdesPack[] serdesPacks = Stream.concat(Stream.of(this.defaultConfigurerSerdes), Arrays.stream(configuration.serdes())).map(injector::createInstance).distinct().toArray(OkaeriSerdesPack[]::new);
        String extension = configurer.getExtensions().isEmpty() ? "bin" : configurer.getExtensions().get(0);
        String resolvedPath = path.replace("{ext}", extension);
        OkaeriConfig config = ConfigManager.create(configType, (it) -> {
            it.withBindFile(new File(this.dataFolder, resolvedPath));
            it.withConfigurer(new OkaeriValidator(configurer, defaultNotNull), serdesPacks);
            it.saveDefaults();
            it.load(true);
        });
        long took = System.currentTimeMillis() - start;
        creator.log(ComponentHelper.buildComponentMessage().type("Loaded configuration").name(configType.getSimpleName()).took(took).meta("path", path).meta("provider", provider.getSimpleName()).build());
        creator.increaseStatistics("configs", 1);
        return config;
    } catch (Exception exception) {
        throw new RuntimeException("Configuration load failure", exception);
    }
}
Also used : Messages(eu.okaeri.platform.core.annotation.Messages) Configuration(eu.okaeri.platform.core.annotation.Configuration) OkaeriConfig(eu.okaeri.configs.OkaeriConfig) OkaeriSerdesPack(eu.okaeri.configs.serdes.OkaeriSerdesPack) Configurer(eu.okaeri.configs.configurer.Configurer) OkaeriValidator(eu.okaeri.configs.validator.okaeri.OkaeriValidator) File(java.io.File)

Aggregations

OkaeriValidator (eu.okaeri.configs.validator.okaeri.OkaeriValidator)3 SerdesCommons (eu.okaeri.configs.serdes.commons.SerdesCommons)2 YamlBukkitConfigurer (eu.okaeri.configs.yaml.bukkit.YamlBukkitConfigurer)2 OkaeriConfig (eu.okaeri.configs.OkaeriConfig)1 Configurer (eu.okaeri.configs.configurer.Configurer)1 OkaeriSerdesPack (eu.okaeri.configs.serdes.OkaeriSerdesPack)1 Configuration (eu.okaeri.platform.core.annotation.Configuration)1 Messages (eu.okaeri.platform.core.annotation.Messages)1 File (java.io.File)1 P0001_Fix_freecam_compensation_key_case (net.dzikoysk.funnyguilds.config.migration.P0001_Fix_freecam_compensation_key_case)1 P0002_Migrate_old_heart_configuration (net.dzikoysk.funnyguilds.config.migration.P0002_Migrate_old_heart_configuration)1 P0003_Migrate_old_tnt_protection_configuration (net.dzikoysk.funnyguilds.config.migration.P0003_Migrate_old_tnt_protection_configuration)1 P0004_Migrate_tablist_into_separate_file (net.dzikoysk.funnyguilds.config.migration.P0004_Migrate_tablist_into_separate_file)1 P0005_Fix_heart_configuration_centery_key (net.dzikoysk.funnyguilds.config.migration.P0005_Fix_heart_configuration_centery_key)1 T0001_Update_player_list_animated (net.dzikoysk.funnyguilds.config.migration.T0001_Update_player_list_animated)1 EntityTypeTransformer (net.dzikoysk.funnyguilds.config.serdes.EntityTypeTransformer)1 FunnyTimeTransformer (net.dzikoysk.funnyguilds.config.serdes.FunnyTimeTransformer)1 ItemStackTransformer (net.dzikoysk.funnyguilds.config.serdes.ItemStackTransformer)1 MaterialTransformer (net.dzikoysk.funnyguilds.config.serdes.MaterialTransformer)1 NumberRangeTransformer (net.dzikoysk.funnyguilds.config.serdes.NumberRangeTransformer)1