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

45 lines
1.8 KiB
Java
Raw Normal View History

2020-09-07 13:29:44 +02:00
package io.gitlab.jfronny.dynres.mixin;
2021-06-02 13:31:04 +02:00
import io.gitlab.jfronny.dynres.Cfg;
2020-09-07 13:29:44 +02:00
import io.gitlab.jfronny.dynres.DynRes;
import io.gitlab.jfronny.libjf.web.api.WebServer;
import io.gitlab.jfronny.libjf.web.impl.util.WebPaths;
2020-09-07 13:29:44 +02:00
import net.minecraft.server.dedicated.ServerPropertiesHandler;
2020-09-07 15:03:15 +02:00
import org.apache.commons.codec.digest.DigestUtils;
2021-06-02 13:31:04 +02:00
import org.spongepowered.asm.mixin.Final;
2020-09-07 13:29:44 +02:00
import org.spongepowered.asm.mixin.Mixin;
2021-06-02 13:31:04 +02:00
import org.spongepowered.asm.mixin.Mutable;
2020-09-07 13:29:44 +02:00
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
2020-09-07 15:03:15 +02:00
import java.io.IOException;
2021-11-30 20:53:13 +01:00
import java.io.InputStream;
import java.nio.file.Files;
2020-09-07 13:29:44 +02:00
@Mixin(ServerPropertiesHandler.class)
2021-11-30 20:53:13 +01:00
public class ServerPropertiesHandlerMixin {
2021-06-02 13:31:04 +02:00
@Mutable @Final @Shadow public String resourcePackHash;
@Mutable @Final @Shadow public String resourcePackSha1;
@Mutable @Final @Shadow public String resourcePack;
2020-09-07 13:29:44 +02:00
2021-06-08 20:47:48 +02:00
@Inject(at = @At("RETURN"), method = "<init>(Ljava/util/Properties;)V")
public void init(CallbackInfo info) {
2021-11-30 20:53:13 +01:00
if (DynRes.resFile != null) {
resourcePack = WebPaths.concat(WebServer.getInstance().getServerRoot(), "resources.zip");
DynRes.LOGGER.info("Pack link: " + resourcePack);
2021-11-30 20:53:13 +01:00
resourcePackSha1 = "";
if (Cfg.hashResources) {
try (InputStream fs = Files.newInputStream(DynRes.resFile)) {
resourcePackSha1 = DigestUtils.sha1Hex(fs);
DynRes.LOGGER.info("Set hash to " + resourcePackSha1);
2021-11-30 20:53:13 +01:00
} catch (IOException e) {
DynRes.LOGGER.error("Failed to get hash, continuing with empty", e);
}
2020-09-07 15:03:15 +02:00
}
2021-11-30 20:53:13 +01:00
resourcePackHash = resourcePackSha1;
2020-09-07 15:03:15 +02:00
}
2020-09-07 13:29:44 +02:00
}
}