40 lines
1.4 KiB
Java
40 lines
1.4 KiB
Java
package io.gitlab.jfronny.dynres;
|
|
|
|
import io.gitlab.jfronny.libjf.web.api.WebInit;
|
|
import io.gitlab.jfronny.libjf.web.api.WebServer;
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.loader.api.FabricLoader;
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import java.io.IOException;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
|
|
public class DynRes implements WebInit {
|
|
public static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger("DynRes");
|
|
public static Path resFile;
|
|
public static String resourceLink = "";
|
|
|
|
static {
|
|
resFile = FabricLoader.getInstance().getGameDir().resolve(Cfg.resourcesFile);
|
|
if (!Files.exists(resFile)) {
|
|
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) {
|
|
LOGGER.error("The resource file specified in your config could not be found. YOU MUST SPECIFY A RESOURCE PACK FOR IT TO BE SERVED!");
|
|
}
|
|
resFile = null;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void register(WebServer api) {
|
|
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER && resFile != null) {
|
|
try {
|
|
resourceLink = api.registerFile("/resources.zip", resFile, !Cfg.hashResources);
|
|
LOGGER.info("Initialized DynRes at " + resourceLink);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|