package me.shedaniel.math.api; import net.fabricmc.api.EnvType; import net.fabricmc.loader.api.FabricLoader; import java.util.Optional; import java.util.concurrent.Callable; import java.util.function.Supplier; public class Executor { private Executor() {} public static void run(Supplier runnableSupplier) { runnableSupplier.get().run(); } public static void runIf(Supplier predicate, Supplier runnableSupplier) { if (predicate.get()) runnableSupplier.get().run(); } public static void runIfEnv(EnvType env, Supplier runnableSupplier) { if (FabricLoader.getInstance().getEnvironmentType() == env) runnableSupplier.get().run(); } public static T call(Supplier> runnableSupplier) { try { return runnableSupplier.get().call(); } catch (Exception e) { throw new RuntimeException(e); } } public static Optional callIf(Supplier predicate, Supplier> runnableSupplier) { if (predicate.get()) try { return Optional.of(runnableSupplier.get().call()); } catch (Exception e) { throw new RuntimeException(e); } return Optional.empty(); } public static Optional callIfEnv(EnvType env, Supplier> runnableSupplier) { if (FabricLoader.getInstance().getEnvironmentType() == env) try { return Optional.of(runnableSupplier.get().call()); } catch (Exception e) { throw new RuntimeException(e); } return Optional.empty(); } }