1
mirror of https://github.com/Shiewk/ViewServerResources.git synced 2026-04-28 03:44:17 +02:00

Update dependencies & improve logging

This commit is contained in:
Shy
2025-07-10 16:28:06 +02:00
parent 70e70cb443
commit f4e19ebafd
5 changed files with 19 additions and 25 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway. // Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "maven.modrinth:modmenu:11.0.1" modImplementation "maven.modrinth:modmenu:${project.modmenu_version}"
} }
processResources { processResources {
+2
View File
@@ -12,3 +12,5 @@ archives_base_name=ViewServerResources
# Dependencies # Dependencies
# check this on https://modmuss50.me/fabric.html # check this on https://modmuss50.me/fabric.html
fabric_version=0.119.5+1.21.5 fabric_version=0.119.5+1.21.5
# Mod Dependencies
modmenu_version=14.0.0-rc.1
@@ -4,20 +4,11 @@ import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException;
public class ViewServerResourcesMod implements ModInitializer { public class ViewServerResourcesMod implements ModInitializer {
public static final String MOD_ID = "viewserverresources"; public static final String MOD_ID = "viewserverresources";
public static final Logger LOGGER = LoggerFactory.getLogger(ViewServerResourcesMod.class); public static final Logger LOGGER = LoggerFactory.getLogger(ViewServerResourcesMod.class);
public static void logThrowable(IOException e) {
LOGGER.error(e.toString());
for (StackTraceElement element : e.getStackTrace()) {
LOGGER.error(element.toString());
}
}
@Override @Override
public void onInitialize() { public void onInitialize() {
} }
@@ -6,7 +6,6 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.internal.Streams; import com.google.gson.internal.Streams;
import com.google.gson.stream.JsonWriter; import com.google.gson.stream.JsonWriter;
import de.shiewk.viewserverresources.ViewServerResourcesMod;
import de.shiewk.viewserverresources.event.ChatAnnouncer; import de.shiewk.viewserverresources.event.ChatAnnouncer;
import de.shiewk.viewserverresources.event.ScreenListener; import de.shiewk.viewserverresources.event.ScreenListener;
import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@@ -20,6 +19,8 @@ import java.io.*;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
import static de.shiewk.viewserverresources.ViewServerResourcesMod.LOGGER;
public class ViewServerResourcesClient implements ClientModInitializer { public class ViewServerResourcesClient implements ClientModInitializer {
private static final ObjectArrayList<String> whitelistedURLs = new ObjectArrayList<>(); private static final ObjectArrayList<String> whitelistedURLs = new ObjectArrayList<>();
@@ -30,10 +31,12 @@ public class ViewServerResourcesClient implements ClientModInitializer {
public static boolean allowedURL(URL uRL) { public static boolean allowedURL(URL uRL) {
if (whitelistedURLs.contains(uRL.toString())){ if (whitelistedURLs.contains(uRL.toString())){
ViewServerResourcesMod.LOGGER.info("URL {} is whitelisted", uRL); if (LOGGER.isDebugEnabled())
LOGGER.debug("URL {} is whitelisted", uRL);
return true; return true;
} else if (whitelistedHosts.contains(uRL.getHost())){ } else if (whitelistedHosts.contains(uRL.getHost())){
ViewServerResourcesMod.LOGGER.info("Host {} is whitelisted", uRL.getHost()); if (LOGGER.isDebugEnabled())
LOGGER.debug("Host {} is whitelisted", uRL.getHost());
return true; return true;
} }
return false; return false;
@@ -41,7 +44,7 @@ public class ViewServerResourcesClient implements ClientModInitializer {
public static void addWhitelistURL(URL url){ public static void addWhitelistURL(URL url){
final String urls = url.toString(); final String urls = url.toString();
ViewServerResourcesMod.LOGGER.info("Whitelist url {}", urls); LOGGER.info("Whitelisting url {}", urls);
if (!whitelistedURLs.contains(urls)){ if (!whitelistedURLs.contains(urls)){
whitelistedURLs.add(urls); whitelistedURLs.add(urls);
} }
@@ -49,14 +52,14 @@ public class ViewServerResourcesClient implements ClientModInitializer {
public static void addWhitelistHost(URL url){ public static void addWhitelistHost(URL url){
final String h = url.getHost(); final String h = url.getHost();
ViewServerResourcesMod.LOGGER.info("Whitelist host {}", h); LOGGER.info("Whitelisting host {}", h);
if (!whitelistedHosts.contains(h)){ if (!whitelistedHosts.contains(h)){
whitelistedHosts.add(h); whitelistedHosts.add(h);
} }
} }
public static void loadConfig(){ public static void loadConfig(){
ViewServerResourcesMod.LOGGER.info("Loading config"); LOGGER.info("Loading config");
try (FileReader fr = new FileReader(whitelistFile)){ try (FileReader fr = new FileReader(whitelistFile)){
final JsonObject cfg = gson.fromJson(fr, JsonObject.class); final JsonObject cfg = gson.fromJson(fr, JsonObject.class);
final JsonObject whitelist = cfg.get("whitelist").getAsJsonObject(); final JsonObject whitelist = cfg.get("whitelist").getAsJsonObject();
@@ -73,14 +76,14 @@ public class ViewServerResourcesClient implements ClientModInitializer {
final JsonElement bdl = cfg.get("broadcastDownloads"); final JsonElement bdl = cfg.get("broadcastDownloads");
broadcastDownloads = bdl == null || !bdl.isJsonPrimitive() || bdl.getAsBoolean(); broadcastDownloads = bdl == null || !bdl.isJsonPrimitive() || bdl.getAsBoolean();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
ViewServerResourcesMod.LOGGER.warn("Config file not found"); LOGGER.warn("Config file not found");
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
public static void saveConfig() { public static void saveConfig() {
ViewServerResourcesMod.LOGGER.info("Saving config"); LOGGER.info("Saving config");
try (FileWriter fw = new FileWriter(whitelistFile)) { try (FileWriter fw = new FileWriter(whitelistFile)) {
final JsonObject cfg = getConfigObject(); final JsonObject cfg = getConfigObject();
@@ -89,7 +92,7 @@ public class ViewServerResourcesClient implements ClientModInitializer {
} }
} catch (IOException e) { } catch (IOException e) {
ViewServerResourcesMod.logThrowable(e); LOGGER.error("Error saving config", e);
} }
} }
@@ -1,12 +1,10 @@
package de.shiewk.viewserverresources.mixin; package de.shiewk.viewserverresources.mixin;
import com.llamalad7.mixinextras.sugar.Local; import com.llamalad7.mixinextras.sugar.Local;
import de.shiewk.viewserverresources.ViewServerResourcesMod;
import de.shiewk.viewserverresources.client.ViewServerResourcesClient; import de.shiewk.viewserverresources.client.ViewServerResourcesClient;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.network.ClientCommonNetworkHandler; import net.minecraft.client.network.ClientCommonNetworkHandler;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.s2c.common.ResourcePackSendS2CPacket; import net.minecraft.network.packet.s2c.common.ResourcePackSendS2CPacket;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -20,6 +18,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.net.URL; import java.net.URL;
import java.util.UUID; import java.util.UUID;
import static de.shiewk.viewserverresources.ViewServerResourcesMod.LOGGER;
@Mixin(ClientCommonNetworkHandler.class) @Mixin(ClientCommonNetworkHandler.class)
public abstract class MixinClientCommonNetworkHandler { public abstract class MixinClientCommonNetworkHandler {
@@ -27,12 +27,10 @@ public abstract class MixinClientCommonNetworkHandler {
@Shadow @Final protected MinecraftClient client; @Shadow @Final protected MinecraftClient client;
@Shadow @Final protected ClientConnection connection;
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/common/ResourcePackSendS2CPacket;hash()Ljava/lang/String;"), method = "onResourcePackSend", cancellable = true) @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/common/ResourcePackSendS2CPacket;hash()Ljava/lang/String;"), method = "onResourcePackSend", cancellable = true)
public void onResourcePackSend(ResourcePackSendS2CPacket packet, CallbackInfo ci, @Local UUID uUID, @Local URL uRL){ public void onResourcePackSend(ResourcePackSendS2CPacket packet, CallbackInfo ci, @Local UUID uUID, @Local URL uRL){
ViewServerResourcesMod.LOGGER.info(packet.url()); if (LOGGER.isDebugEnabled())
LOGGER.debug(packet.url());
String hash = packet.hash(); String hash = packet.hash();
if (ViewServerResourcesClient.allowedURL(uRL)){ if (ViewServerResourcesClient.allowedURL(uRL)){
this.client.getServerResourcePackProvider().addResourcePack(uUID, uRL, hash); this.client.getServerResourcePackProvider().addResourcePack(uUID, uRL, hash);