DynRes/src/main/java/io/gitlab/jfronny/dynres/DynRes.java

39 lines
1.4 KiB
Java
Raw Normal View History

2020-09-07 13:29:44 +02:00
package io.gitlab.jfronny.dynres;
2024-04-25 19:46:53 +02:00
import io.gitlab.jfronny.commons.logger.SystemLoggerPlus;
2023-09-22 20:59:35 +02:00
import io.gitlab.jfronny.libjf.web.api.v1.*;
2020-09-07 13:29:44 +02:00
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
2020-09-23 20:22:36 +02:00
import java.io.IOException;
2021-11-30 20:53:13 +01:00
import java.nio.file.Files;
import java.nio.file.Path;
2020-09-07 13:29:44 +02:00
2023-09-22 20:59:35 +02:00
public class DynRes implements WebEntrypoint {
2024-04-25 19:46:53 +02:00
public static final SystemLoggerPlus LOGGER = SystemLoggerPlus.forName("DynRes");
2022-03-01 15:02:48 +01:00
public static Path packFile;
public static String packUrl = "";
static {
2022-03-01 15:02:48 +01:00
packFile = FabricLoader.getInstance().getGameDir().resolve(Cfg.resourcesFile);
if (!Files.exists(packFile)) {
2021-11-30 20:53:13 +01:00
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) {
2022-01-05 12:26:20 +01:00
LOGGER.error("The resource file specified in your config could not be found. YOU MUST SPECIFY A RESOURCE PACK FOR IT TO BE SERVED!");
2021-11-30 20:53:13 +01:00
}
2022-03-01 15:02:48 +01:00
packFile = null;
}
}
2020-09-07 13:29:44 +02:00
2020-09-07 15:03:15 +02:00
@Override
public void register(WebServer api) {
2022-03-01 15:02:48 +01:00
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER && packFile != null) {
try {
2023-09-22 20:59:35 +02:00
packUrl = api.registerFile(PathSegment.of("resources.zip"), packFile, !Cfg.hashResources);
2024-04-25 19:46:53 +02:00
LOGGER.info("Initialized DynRes at {0}", packUrl);
2020-09-23 20:22:36 +02:00
} catch (IOException e) {
2024-04-25 19:46:53 +02:00
LOGGER.error("Could not register DynRes resource pack", e);
}
}
2020-09-07 13:29:44 +02:00
}
}