From 7f2cea976276ef14030964eea6c91ebee9f39204 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 12 Apr 2020 02:13:15 +0800 Subject: Adds warning screen Signed-off-by: shedaniel --- .../me/shedaniel/rei/RoughlyEnoughItemsState.java | 72 +++++++++++++++++++--- 1 file changed, 62 insertions(+), 10 deletions(-) (limited to 'src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java') diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java index a6c71f6cb..0a67d6f75 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java @@ -26,6 +26,8 @@ package me.shedaniel.rei; import net.fabricmc.api.EnvType; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.util.Pair; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.ApiStatus; import java.util.ArrayList; @@ -37,24 +39,74 @@ import java.util.Set; public class RoughlyEnoughItemsState { private RoughlyEnoughItemsState() {} - private static List> failedToLoad = new ArrayList<>(); - private static Set failedToLoadSet = new LinkedHashSet<>(); + public static final Logger LOGGER = LogManager.getFormatterLogger("REI"); - public static void failedToLoad(String reason) { + private static List> errors = new ArrayList<>(); + private static List> warnings = new ArrayList<>(); + private static Set errorSet = new LinkedHashSet<>(); + private static Set warningSet = new LinkedHashSet<>(); + private static List continueCallbacks = new ArrayList<>(); + + public static void error(String reason) { if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER || FabricLoader.getInstance().isDevelopmentEnvironment()) throw new RuntimeException(reason); - if (RoughlyEnoughItemsState.failedToLoadSet.add(reason + " " + null)) - RoughlyEnoughItemsState.failedToLoad.add(new Pair<>(reason, null)); + if (RoughlyEnoughItemsState.errorSet.add(reason + " " + null)) { + RoughlyEnoughItemsState.errors.add(new Pair<>(reason, null)); + LOGGER.error(reason); + } } - public static void failedToLoad(String reason, String link) { + public static void error(String reason, String link) { if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER || FabricLoader.getInstance().isDevelopmentEnvironment()) throw new RuntimeException(reason + " " + link); - if (RoughlyEnoughItemsState.failedToLoadSet.add(reason + " " + link)) - RoughlyEnoughItemsState.failedToLoad.add(new Pair<>(reason, link)); + if (RoughlyEnoughItemsState.errorSet.add(reason + " " + link)) { + RoughlyEnoughItemsState.errors.add(new Pair<>(reason, link)); + LOGGER.error(reason + " " + link); + } + } + + public static void warn(String reason) { + if (RoughlyEnoughItemsState.warningSet.add(reason + " " + null)) { + RoughlyEnoughItemsState.warnings.add(new Pair<>(reason, null)); + LOGGER.warn(reason); + } + } + + public static void warn(String reason, String link) { + if (RoughlyEnoughItemsState.warningSet.add(reason + " " + link)) { + RoughlyEnoughItemsState.warnings.add(new Pair<>(reason, link)); + LOGGER.warn(reason + " " + link); + } + } + + @SuppressWarnings({"Convert2MethodRef", "FunctionalExpressionCanBeFolded"}) + public static void onContinue(Runnable runnable) { + continueCallbacks.add(runnable); + } + + public static List> getErrors() { + return errors; + } + + public static List> getWarnings() { + return warnings; + } + + public static void clear() { + errors.clear(); + errorSet.clear(); + warnings.clear(); + warningSet.clear(); } - public static List> getFailedToLoad() { - return failedToLoad; + public static void continues() { + for (Runnable callback : continueCallbacks) { + try { + callback.run(); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } + } + continueCallbacks.clear(); } } -- cgit