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;
|
2020-09-08 13:41:43 +02:00
|
|
|
import io.gitlab.jfronny.dynres.Logger;
|
2020-09-07 17:22:06 +02:00
|
|
|
import io.gitlab.jfronny.dynres.ServerPropertiesHandlerExt;
|
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)
|
2020-09-07 17:22:06 +02:00
|
|
|
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) {
|
2020-09-07 17:22:06 +02:00
|
|
|
applyChanges(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void applyChanges(boolean print) {
|
2020-09-23 20:22:36 +02:00
|
|
|
resourcePack = WebPaths.concat(LibWeb.api.getServerRoot(), "resources.zip");
|
2020-09-07 17:22:06 +02:00
|
|
|
if (print)
|
2020-09-08 13:41:43 +02:00
|
|
|
Logger.l.info("Pack link: " + resourcePack);
|
|
|
|
resourcePackSha1 = "";
|
2021-06-02 13:31:04 +02:00
|
|
|
if (Cfg.hashResources) {
|
2020-09-08 13:41:43 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|