package io.gitlab.jfronny.dynres.mixin; import io.gitlab.jfronny.dynres.Cfg; import io.gitlab.jfronny.dynres.DynRes; import io.gitlab.jfronny.dynres.ServerPropertiesHandlerExt; import io.gitlab.jfronny.libjf.web.api.WebServer; import io.gitlab.jfronny.libjf.web.impl.JfWeb; import io.gitlab.jfronny.libjf.web.impl.util.WebPaths; import net.minecraft.server.dedicated.ServerPropertiesHandler; import org.apache.commons.codec.digest.DigestUtils; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; 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; import java.io.FileInputStream; import java.io.IOException; @Mixin(ServerPropertiesHandler.class) public class ServerPropertiesHandlerMixin implements ServerPropertiesHandlerExt { @Mutable @Final @Shadow public String resourcePackHash; @Mutable @Final @Shadow public String resourcePackSha1; @Mutable @Final @Shadow public String resourcePack; @Inject(at = @At("RETURN"), method = "(Ljava/util/Properties;)V") public void init(CallbackInfo info) { applyChanges(true); } @Override public void applyChanges(boolean print) { resourcePack = WebPaths.concat(WebServer.getInstance().getServerRoot(), "resources.zip"); if (print) DynRes.LOGGER.info("Pack link: " + resourcePack); resourcePackSha1 = ""; if (Cfg.hashResources) { try { FileInputStream fs = new FileInputStream(DynRes.resFile); resourcePackSha1 = DigestUtils.sha1Hex(fs); if (print) DynRes.LOGGER.info("Set hash to " + resourcePackSha1); fs.close(); } catch (IOException e) { DynRes.LOGGER.error("Failed to get hash, continuing with empty", e); } } resourcePackHash = resourcePackSha1; } }