2020-09-07 13:29:44 +02:00
|
|
|
package io.gitlab.jfronny.dynres;
|
|
|
|
|
2021-11-10 17:18:47 +01:00
|
|
|
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
|
|
|
|
2021-11-10 17:18:47 +01: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 = "";
|
2020-09-24 22:45:20 +02:00
|
|
|
|
|
|
|
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-24 22:45:20 +02:00
|
|
|
}
|
|
|
|
}
|
2020-09-07 13:29:44 +02:00
|
|
|
|
2020-09-07 15:03:15 +02:00
|
|
|
@Override
|
2021-11-10 17:18:47 +01:00
|
|
|
public void register(WebServer api) {
|
2022-03-01 15:02:48 +01:00
|
|
|
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER && packFile != null) {
|
2020-09-07 15:45:04 +02:00
|
|
|
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 17:22:06 +02:00
|
|
|
}
|
|
|
|
}
|
2020-09-07 13:29:44 +02:00
|
|
|
}
|
|
|
|
}
|