use of gg.moonflower.pollen.api.config.PollinatedConfigType in project pollen by MoonflowerTeam.
the class ConfigCommand method register.
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean dedicated) {
// Disable showing serverconfig on a dedicated server because the files won't exist
dispatcher.register(Commands.literal("config").then(Commands.literal("showfile").then(Commands.argument("mod", StringArgumentType.word()).suggests(PollenSuggestionProviders.MOD_IDS).then(Commands.argument("type", dedicated ? EnumArgument.enumValues(PollinatedConfigType.COMMON, PollinatedConfigType.CLIENT) : EnumArgument.enumValues(PollinatedConfigType.values())).executes(ctx -> {
String modId = StringArgumentType.getString(ctx, "mod");
PollinatedConfigType type = EnumArgument.getEnum(PollinatedConfigType.class, ctx, "type");
String configFileName = getConfigFileName(modId, type);
if (configFileName != null) {
File f = new File(configFileName);
ctx.getSource().sendSuccess(new TranslatableComponent("commands." + Pollen.MOD_ID + ".config.success", modId, type, new TextComponent(f.getName()).withStyle(ChatFormatting.UNDERLINE).withStyle((style) -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, f.getAbsolutePath())))), false);
return Command.SINGLE_SUCCESS;
} else {
ctx.getSource().sendFailure(new TranslatableComponent("commands." + Pollen.MOD_ID + ".config.fail", modId, type));
return 0;
}
})))));
}
use of gg.moonflower.pollen.api.config.PollinatedConfigType in project pollen by MoonflowerTeam.
the class ConfigManagerImpl method register.
public static <T> T register(String modId, PollinatedConfigType type, String fileName, Function<PollinatedConfigBuilder, T> consumer) {
ModLoadingContext context = ModLoadingContext.get();
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
Pair<T, ForgeConfigSpec> pair = new PollinatedConfigBuilderImpl(new ForgeConfigSpec.Builder()).configure(consumer);
ModConfig config = new ModConfig(convert(type), pair.getRight(), context.getActiveContainer(), fileName);
context.getActiveContainer().addConfig(config);
if (registeredEvents.add(modId)) {
bus.<ModConfig.Loading>addListener(event -> {
ModConfig modConfig = event.getConfig();
get(modConfig.getModId(), convert(modConfig.getType())).ifPresent(c -> {
ConfigEvent.LOADING.invoker().configChanged(c);
});
});
bus.<ModConfig.Reloading>addListener(event -> {
ModConfig modConfig = event.getConfig();
get(modConfig.getModId(), convert(modConfig.getType())).ifPresent(c -> {
ConfigEvent.RELOADING.invoker().configChanged(c);
});
});
}
CONFIGS.computeIfAbsent(modId, __ -> new EnumMap<>(PollinatedConfigType.class)).put(type, new PollinatedModConfigImpl(config));
return pair.getLeft();
}
Aggregations