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

55 lines
2.1 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.dynres.Logger;
import io.gitlab.jfronny.dynres.ServerPropertiesHandlerExt;
2021-06-02 13:31:04 +02:00
import io.gitlab.jfronny.libjf.Libjf;
2020-09-23 20:22:36 +02:00
import io.gitlab.jfronny.libweb.extra.LibWeb;
import io.gitlab.jfronny.libweb.extra.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.FileInputStream;
import java.io.IOException;
2020-09-07 13:29:44 +02:00
@Mixin(ServerPropertiesHandler.class)
public class ServerPropertiesHandlerMixin implements ServerPropertiesHandlerExt {
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) {
applyChanges(true);
}
@Override
public void applyChanges(boolean print) {
2020-09-23 20:22:36 +02:00
resourcePack = WebPaths.concat(LibWeb.api.getServerRoot(), "resources.zip");
if (print)
Logger.l.info("Pack link: " + resourcePack);
resourcePackSha1 = "";
2021-06-02 13:31:04 +02:00
Libjf.registerConfig("dynres", Cfg.class);
if (Cfg.hashResources) {
try {
FileInputStream fs = new FileInputStream(DynRes.resFile);
resourcePackSha1 = DigestUtils.sha1Hex(fs);
if (print)
Logger.l.info("Set hash to " + resourcePackSha1);
fs.close();
} catch (IOException e) {
Logger.l.error("Failed to get hash, continuing with empty", e);
2020-09-07 15:03:15 +02:00
}
}
2020-09-07 13:29:44 +02:00
resourcePackHash = resourcePackSha1;
}
}