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

41 lines
1.4 KiB
Java
Raw Normal View History

2020-09-07 13:29:44 +02:00
package io.gitlab.jfronny.dynres;
import io.gitlab.jfronny.libjf.web.api.WebInit;
import io.gitlab.jfronny.libjf.web.api.WebServer;
2020-09-07 13:29:44 +02:00
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
2022-03-01 15:02:48 +01:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
2020-09-07 13:29:44 +02:00
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
public class DynRes implements WebInit {
2022-03-01 15:02:48 +01:00
public static final Logger LOGGER = LoggerFactory.getLogger("DynRes");
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 {
2022-03-01 15:02:48 +01:00
packUrl = api.registerFile("/resources.zip", packFile, !Cfg.hashResources);
LOGGER.info("Initialized DynRes at " + packUrl);
2020-09-23 20:22:36 +02:00
} catch (IOException e) {
e.printStackTrace();
}
}
2020-09-07 13:29:44 +02:00
}
}