62 lines
2.4 KiB
Java
62 lines
2.4 KiB
Java
package io.gitlab.jfronny.dynres.mixin;
|
|
|
|
import io.gitlab.jfronny.dynres.DynRes;
|
|
import io.gitlab.jfronny.dynres.ServerPropertiesHandlerExt;
|
|
import net.minecraft.server.dedicated.ServerPropertiesHandler;
|
|
import net.minecraft.util.registry.DynamicRegistryManager;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
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;
|
|
import java.util.Objects;
|
|
import java.util.Properties;
|
|
|
|
@Mixin(ServerPropertiesHandler.class)
|
|
public class ServerPropertiesHandlerMixin implements ServerPropertiesHandlerExt {
|
|
@Shadow public String resourcePack;
|
|
|
|
@Shadow public String resourcePackHash;
|
|
|
|
@Shadow public String resourcePackSha1;
|
|
|
|
private String resourcePackSha1Temp;
|
|
private String resourcePackTemp;
|
|
|
|
@Inject(at = @At("RETURN"), method = "<init>(Ljava/util/Properties;Lnet/minecraft/util/registry/DynamicRegistryManager;)V")
|
|
public void init(Properties properties, DynamicRegistryManager dynamicRegistryManager, CallbackInfo info) {
|
|
applyChanges(true);
|
|
}
|
|
|
|
@Override
|
|
public void applyChanges(boolean print) {
|
|
resourcePack = DynRes.removePort(DynRes.simplifyElement(DynRes.cfg.baseLink)) + ":" + DynRes.getPort() + "/resources.zip";
|
|
if (print)
|
|
DynRes.logger.info("Pack link: " + resourcePack);
|
|
if (!Objects.equals(resourcePackTemp, resourcePack)) {
|
|
resourcePackTemp = resourcePack;
|
|
resourcePackSha1 = "";
|
|
if (DynRes.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);
|
|
}
|
|
}
|
|
resourcePackSha1Temp = resourcePackSha1;
|
|
}
|
|
else {
|
|
resourcePackSha1 = resourcePackSha1Temp;
|
|
}
|
|
resourcePackHash = resourcePackSha1;
|
|
}
|
|
}
|