package io.gitlab.jfronny.libjf.config.impl.ui; import io.gitlab.jfronny.libjf.config.api.v1.ui.ConfigScreenFactory; import net.fabricmc.loader.api.FabricLoader; import java.util.Comparator; import java.util.List; public class ConfigScreenFactoryDiscovery { private static ConfigScreenFactory discovered1 = null; private static io.gitlab.jfronny.libjf.config.api.v2.ui.ConfigScreenFactory discovered2 = null; @Deprecated public static ConfigScreenFactory getConfigured() { if (discovered1 == null) { List entrypoints = getEntrypoints(); discovered1 = entrypoints .stream() .filter(it -> it instanceof io.gitlab.jfronny.libjf.config.api.v2.ui.ConfigScreenFactory) .map(it -> (io.gitlab.jfronny.libjf.config.api.v2.ui.ConfigScreenFactory) it) .max(Comparator.comparing(io.gitlab.jfronny.libjf.config.api.v2.ui.ConfigScreenFactory::getPriority)) .map(ConfigScreenFactory2To1::new) .orElseGet(() -> entrypoints .stream() .filter(it -> it instanceof ConfigScreenFactory) .map(it -> (ConfigScreenFactory) it) .max(Comparator.comparing(ConfigScreenFactory::getPriority)) .orElseGet(() -> new ConfigScreenFactory2To1(new PlaceholderScreenFactory()))); } return discovered1; } public static io.gitlab.jfronny.libjf.config.api.v2.ui.ConfigScreenFactory getConfigured2() { if (discovered2 == null) { List entrypoints = getEntrypoints(); discovered2 = entrypoints .stream() .filter(it -> it instanceof io.gitlab.jfronny.libjf.config.api.v2.ui.ConfigScreenFactory) .map(it -> (io.gitlab.jfronny.libjf.config.api.v2.ui.ConfigScreenFactory) it) .max(Comparator.comparing(io.gitlab.jfronny.libjf.config.api.v2.ui.ConfigScreenFactory::getPriority)) .orElseGet(() -> entrypoints .stream() .filter(it -> it instanceof ConfigScreenFactory) .map(it -> (ConfigScreenFactory) it) .map(ConfigScreenFactory1To2::new) .max(Comparator.comparing(io.gitlab.jfronny.libjf.config.api.v2.ui.ConfigScreenFactory::getPriority)) .orElseGet(PlaceholderScreenFactory::new)); } return discovered2; } private static List getEntrypoints() { return FabricLoader.getInstance().getEntrypoints("libjf:config_screen", Object.class); } }