From b921bc5c2cace3af26a6e5b0a98eb9dd9adf97ae Mon Sep 17 00:00:00 2001 From: RuscalWorld Date: Fri, 6 Aug 2021 17:03:40 +0300 Subject: [PATCH] Forcibly disable TPS and MSPT metrics if spark mod is not installed --- .../ru/ruscalworld/fabricexporter/FabricExporter.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/ru/ruscalworld/fabricexporter/FabricExporter.java b/src/main/java/ru/ruscalworld/fabricexporter/FabricExporter.java index 92348db..70007e2 100644 --- a/src/main/java/ru/ruscalworld/fabricexporter/FabricExporter.java +++ b/src/main/java/ru/ruscalworld/fabricexporter/FabricExporter.java @@ -3,14 +3,18 @@ package ru.ruscalworld.fabricexporter; import io.prometheus.client.exporter.HTTPServer; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; +import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.api.ModContainer; import net.minecraft.server.MinecraftServer; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import ru.ruscalworld.fabricexporter.config.MainConfig; import java.io.IOException; +import java.util.Optional; public class FabricExporter implements ModInitializer { + private static final Logger logger = LogManager.getLogger(); private static FabricExporter instance; private MinecraftServer server; @@ -29,6 +33,13 @@ public class FabricExporter implements ModInitializer { e.printStackTrace(); } + Optional spark = FabricLoader.getInstance().getModContainer("spark"); + if (!spark.isPresent() && config.shouldUseSpark()) { + config.setShouldUseSpark(false); + logger.warn("Spark mod is not installed, but \"use-spark\" property is enabled! TPS and MSPT metrics will be disabled."); + logger.warn("To fix this, you should either set \"use-spark\" in exporter.properties to false or install Spark mod (https://spark.lucko.me)."); + } + MetricRegistry metricRegistry = new MetricRegistry(this); metricRegistry.registerDefault(); this.setMetricRegistry(metricRegistry);