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());
});
}
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());
});
}
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);
}
}
Aggregations