1
mirror of https://github.com/Shiewk/ViewServerResources.git synced 2026-04-28 03:44:17 +02:00
This commit is contained in:
Shy
2024-08-24 17:12:08 +02:00
parent ee4407928e
commit 02d1d8df8e
18 changed files with 74 additions and 75 deletions
+2 -2
View File
@@ -6,9 +6,9 @@ minecraft_version=1.21
yarn_mappings=1.21+build.9
loader_version=0.16.2
# Mod Properties
mod_version=0.0.3
mod_version=1.0.0
maven_group=de.shiewk
archives_base_name=ResourcePackPrivacy
archives_base_name=ViewServerResources
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.102.0+1.21
@@ -1,4 +1,4 @@
package de.shiewk.resourcepackprivacy;
package de.shiewk.viewserverresources;
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
@@ -6,10 +6,10 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
public class ResourcePackPrivacy implements ModInitializer {
public class ViewServerResourcesMod implements ModInitializer {
public static final String MOD_ID = "resourcepackprivacy";
public static final Logger LOGGER = LoggerFactory.getLogger(ResourcePackPrivacy.class);
public static final String MOD_ID = "viewserverresources";
public static final Logger LOGGER = LoggerFactory.getLogger(ViewServerResourcesMod.class);
public static void logThrowable(IOException e) {
LOGGER.error(e.toString());
@@ -1,13 +1,13 @@
package de.shiewk.resourcepackprivacy.client;
package de.shiewk.viewserverresources.client;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import de.shiewk.resourcepackprivacy.screen.ResourcePackPrivacyConfigScreen;
import de.shiewk.viewserverresources.screen.ViewServerResources;
public class ModMenuConfig implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return ResourcePackPrivacyConfigScreen::new;
return ViewServerResources::new;
}
}
@@ -1,4 +1,4 @@
package de.shiewk.resourcepackprivacy.client;
package de.shiewk.viewserverresources.client;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
@@ -6,9 +6,9 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.internal.Streams;
import com.google.gson.stream.JsonWriter;
import de.shiewk.resourcepackprivacy.ResourcePackPrivacy;
import de.shiewk.resourcepackprivacy.event.ChatAnnouncer;
import de.shiewk.resourcepackprivacy.event.ScreenListener;
import de.shiewk.viewserverresources.ViewServerResourcesMod;
import de.shiewk.viewserverresources.event.ChatAnnouncer;
import de.shiewk.viewserverresources.event.ScreenListener;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
@@ -20,7 +20,7 @@ import java.io.*;
import java.net.URL;
import java.util.List;
public class ResourcePackPrivacyClient implements ClientModInitializer {
public class ViewServerResourcesClient implements ClientModInitializer {
private static final ObjectArrayList<String> whitelistedURLs = new ObjectArrayList<>();
private static final ObjectArrayList<String> whitelistedHosts = new ObjectArrayList<>();
@@ -30,10 +30,10 @@ public class ResourcePackPrivacyClient implements ClientModInitializer {
public static boolean allowedURL(URL uRL) {
if (whitelistedURLs.contains(uRL.toString())){
ResourcePackPrivacy.LOGGER.info("URL {} is whitelisted", uRL);
ViewServerResourcesMod.LOGGER.info("URL {} is whitelisted", uRL);
return true;
} else if (whitelistedHosts.contains(uRL.getHost())){
ResourcePackPrivacy.LOGGER.info("Host {} is whitelisted", uRL.getHost());
ViewServerResourcesMod.LOGGER.info("Host {} is whitelisted", uRL.getHost());
return true;
}
return false;
@@ -41,7 +41,7 @@ public class ResourcePackPrivacyClient implements ClientModInitializer {
public static void addWhitelistURL(URL url){
final String urls = url.toString();
ResourcePackPrivacy.LOGGER.info("Whitelist url {}", urls);
ViewServerResourcesMod.LOGGER.info("Whitelist url {}", urls);
if (!whitelistedURLs.contains(urls)){
whitelistedURLs.add(urls);
}
@@ -49,14 +49,14 @@ public class ResourcePackPrivacyClient implements ClientModInitializer {
public static void addWhitelistHost(URL url){
final String h = url.getHost();
ResourcePackPrivacy.LOGGER.info("Whitelist host {}", h);
ViewServerResourcesMod.LOGGER.info("Whitelist host {}", h);
if (!whitelistedHosts.contains(h)){
whitelistedHosts.add(h);
}
}
public static void loadConfig(){
ResourcePackPrivacy.LOGGER.info("Loading config");
ViewServerResourcesMod.LOGGER.info("Loading config");
try (FileReader fr = new FileReader(whitelistFile)){
final JsonObject cfg = gson.fromJson(fr, JsonObject.class);
final JsonObject whitelist = cfg.get("whitelist").getAsJsonObject();
@@ -73,14 +73,14 @@ public class ResourcePackPrivacyClient implements ClientModInitializer {
final JsonElement bdl = cfg.get("broadcastDownloads");
broadcastDownloads = bdl == null || !bdl.isJsonPrimitive() || bdl.getAsBoolean();
} catch (FileNotFoundException e) {
ResourcePackPrivacy.LOGGER.warn("Config file not found");
ViewServerResourcesMod.LOGGER.warn("Config file not found");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static void saveConfig() {
ResourcePackPrivacy.LOGGER.info("Saving config");
ViewServerResourcesMod.LOGGER.info("Saving config");
try (FileWriter fw = new FileWriter(whitelistFile)) {
final JsonObject cfg = getConfigObject();
@@ -89,7 +89,7 @@ public class ResourcePackPrivacyClient implements ClientModInitializer {
}
} catch (IOException e) {
ResourcePackPrivacy.logThrowable(e);
ViewServerResourcesMod.logThrowable(e);
}
}
@@ -127,12 +127,12 @@ public class ResourcePackPrivacyClient implements ClientModInitializer {
}
public static void setBroadcastDownloads(boolean broadcastDownloads) {
ResourcePackPrivacyClient.broadcastDownloads = broadcastDownloads;
ViewServerResourcesClient.broadcastDownloads = broadcastDownloads;
}
@Override
public void onInitializeClient() {
whitelistFile = new File(MinecraftClient.getInstance().runDirectory.getPath() + "/resourcepackprivacy.json");
whitelistFile = new File(MinecraftClient.getInstance().runDirectory.getPath() + "/viewserverresources.json");
ScreenEvents.AFTER_INIT.register(new ScreenListener());
ClientTickEvents.END_CLIENT_TICK.register(new ChatAnnouncer());
loadConfig();
@@ -1,4 +1,4 @@
package de.shiewk.resourcepackprivacy.event;
package de.shiewk.viewserverresources.event;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
@@ -1,10 +1,10 @@
package de.shiewk.resourcepackprivacy.event;
package de.shiewk.viewserverresources.event;
import de.shiewk.resourcepackprivacy.client.ResourcePackPrivacyClient;
import de.shiewk.resourcepackprivacy.mixin.AccessorConfirmScreen;
import de.shiewk.resourcepackprivacy.mixin.AccessorConfirmServerResourcePackScreen;
import de.shiewk.resourcepackprivacy.mixin.AccessorConfirmServerResourcePackScreenPack;
import de.shiewk.resourcepackprivacy.screen.ViewResourceURLsScreen;
import de.shiewk.viewserverresources.client.ViewServerResourcesClient;
import de.shiewk.viewserverresources.mixin.AccessorConfirmScreen;
import de.shiewk.viewserverresources.mixin.AccessorConfirmServerResourcePackScreen;
import de.shiewk.viewserverresources.mixin.AccessorConfirmServerResourcePackScreenPack;
import de.shiewk.viewserverresources.screen.ViewResourceURLsScreen;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.fabricmc.fabric.api.client.screen.v1.Screens;
import net.minecraft.client.MinecraftClient;
@@ -45,8 +45,8 @@ public class ScreenListener implements ScreenEvents.AfterInit {
adder.add(buttons.removeFirst());
}
adder.add(createButton(Text.translatable(infos.size() == 1 ? "gui.resourcepackprivacy.viewURL" : "gui.resourcepackprivacy.viewURLs"), btn -> viewURLs(client, screen, infos)));
adder.add(createButton(Text.translatable(infos.size() == 1 ? "gui.resourcepackprivacy.alwaysURL" : "gui.resourcepackprivacy.alwaysURLs"), btn -> whitelistURLsAndAccept(btn, screen, infos)));
adder.add(createButton(Text.translatable(infos.size() == 1 ? "gui.viewserverresources.viewURL" : "gui.viewserverresources.viewURLs"), btn -> viewURLs(client, screen, infos)));
adder.add(createButton(Text.translatable(infos.size() == 1 ? "gui.viewserverresources.alwaysURL" : "gui.viewserverresources.alwaysURLs"), btn -> whitelistURLsAndAccept(btn, screen, infos)));
adder.add(createLargeButton(Text.translatable("gui.resourcepackprivacy.alwaysHost", Text.literal(infos.getFirst().url().getHost()).withColor(Color.GREEN.getRGB())), btn -> whitelistHostsAndAccept(btn, screen, infos)), 2);
gw.refreshPositions();
@@ -58,9 +58,9 @@ public class ScreenListener implements ScreenEvents.AfterInit {
private void whitelistURLsAndAccept(ButtonWidget btn, Screen screen, List<PackInfo> infos){
btn.active = false;
for (PackInfo info : infos) {
ResourcePackPrivacyClient.addWhitelistURL(info.url());
ViewServerResourcesClient.addWhitelistURL(info.url());
}
ResourcePackPrivacyClient.saveConfig();
ViewServerResourcesClient.saveConfig();
accept(screen);
}
@@ -71,9 +71,9 @@ public class ScreenListener implements ScreenEvents.AfterInit {
private void whitelistHostsAndAccept(ButtonWidget btn, Screen screen, List<PackInfo> infos){
btn.active = false;
for (PackInfo info : infos) {
ResourcePackPrivacyClient.addWhitelistHost(info.url());
ViewServerResourcesClient.addWhitelistHost(info.url());
}
ResourcePackPrivacyClient.saveConfig();
ViewServerResourcesClient.saveConfig();
accept(screen);
}
@@ -1,4 +1,4 @@
package de.shiewk.resourcepackprivacy.mixin;
package de.shiewk.viewserverresources.mixin;
import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
import net.minecraft.client.gui.screen.ConfirmScreen;
@@ -1,6 +1,5 @@
package de.shiewk.resourcepackprivacy.mixin;
package de.shiewk.viewserverresources.mixin;
import net.minecraft.client.network.ClientCommonNetworkHandler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@@ -1,4 +1,4 @@
package de.shiewk.resourcepackprivacy.mixin;
package de.shiewk.viewserverresources.mixin;
import org.spongepowered.asm.mixin.Mixin;
@@ -1,8 +1,8 @@
package de.shiewk.resourcepackprivacy.mixin;
package de.shiewk.viewserverresources.mixin;
import com.llamalad7.mixinextras.sugar.Local;
import de.shiewk.resourcepackprivacy.ResourcePackPrivacy;
import de.shiewk.resourcepackprivacy.client.ResourcePackPrivacyClient;
import de.shiewk.viewserverresources.ViewServerResourcesMod;
import de.shiewk.viewserverresources.client.ViewServerResourcesClient;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.network.ClientCommonNetworkHandler;
@@ -32,9 +32,9 @@ public abstract class MixinClientCommonNetworkHandler {
@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){
ResourcePackPrivacy.LOGGER.info(packet.url());
ViewServerResourcesMod.LOGGER.info(packet.url());
String hash = packet.hash();
if (ResourcePackPrivacyClient.allowedURL(uRL)){
if (ViewServerResourcesClient.allowedURL(uRL)){
this.client.getServerResourcePackProvider().addResourcePack(uUID, uRL, hash);
} else {
boolean required = packet.required();
@@ -1,7 +1,7 @@
package de.shiewk.resourcepackprivacy.mixin;
package de.shiewk.viewserverresources.mixin;
import de.shiewk.resourcepackprivacy.client.ResourcePackPrivacyClient;
import de.shiewk.resourcepackprivacy.event.ChatAnnouncer;
import de.shiewk.viewserverresources.client.ViewServerResourcesClient;
import de.shiewk.viewserverresources.event.ChatAnnouncer;
import net.minecraft.client.resource.server.ServerResourcePackLoader;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
@@ -18,7 +18,7 @@ public class MixinServerResourcePackLoader {
@Inject(at = @At("HEAD"), method = "addResourcePack(Ljava/util/UUID;Ljava/net/URL;Ljava/lang/String;)V")
public void onResourcePackAdd(UUID id, URL url, String hash, CallbackInfo ci){
if (ResourcePackPrivacyClient.isBroadcastDownloads()){
if (ViewServerResourcesClient.isBroadcastDownloads()){
ChatAnnouncer.announce(Text.translatable("gui.resourcepackprivacy.downloading",
Text.literal(url.toString()))
.withColor(Color.ORANGE.getRGB())
@@ -1,6 +1,6 @@
package de.shiewk.resourcepackprivacy.screen;
package de.shiewk.viewserverresources.screen;
import de.shiewk.resourcepackprivacy.screen.elements.ManageListWidget;
import de.shiewk.viewserverresources.screen.elements.ManageListWidget;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
@@ -1,6 +1,6 @@
package de.shiewk.resourcepackprivacy.screen;
package de.shiewk.viewserverresources.screen;
import de.shiewk.resourcepackprivacy.event.ScreenListener;
import de.shiewk.viewserverresources.event.ScreenListener;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.MultilineTextWidget;
@@ -43,6 +43,6 @@ public class ViewResourceURLsScreen extends Screen {
for (ScreenListener.PackInfo info : infos) {
msg = msg.append(Text.literal("\n"+info.url()));
}
return Text.translatable(infos.size() == 1 ? "gui.resourcepackprivacy.url" : "gui.resourcepackprivacy.urls", msg).withColor(Color.GREEN.getRGB());
return Text.translatable(infos.size() == 1 ? "gui.viewserverresources.url" : "gui.viewserverresources.urls", msg).withColor(Color.GREEN.getRGB());
}
}
@@ -1,6 +1,6 @@
package de.shiewk.resourcepackprivacy.screen;
package de.shiewk.viewserverresources.screen;
import de.shiewk.resourcepackprivacy.client.ResourcePackPrivacyClient;
import de.shiewk.viewserverresources.client.ViewServerResourcesClient;
import it.unimi.dsi.fastutil.booleans.Boolean2ObjectFunction;
import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
import net.minecraft.client.gui.screen.Screen;
@@ -13,11 +13,11 @@ import net.minecraft.text.Text;
import java.awt.*;
import java.util.concurrent.atomic.AtomicBoolean;
public class ResourcePackPrivacyConfigScreen extends Screen {
public class ViewServerResources extends Screen {
private final Screen parent;
private static final int buttonWidth = 192;
private boolean cfgDirty = false;
public ResourcePackPrivacyConfigScreen(Screen parent) {
public ViewServerResources(Screen parent) {
super(Text.translatable("gui.resourcepackprivacy.config"));
this.parent = parent;
}
@@ -25,7 +25,7 @@ public class ResourcePackPrivacyConfigScreen extends Screen {
@Override
public void close() {
if (cfgDirty){
ResourcePackPrivacyClient.saveConfig();
ViewServerResourcesClient.saveConfig();
}
assert client != null;
client.setScreen(parent);
@@ -43,10 +43,10 @@ public class ResourcePackPrivacyConfigScreen extends Screen {
gw.getMainPositioner().margin(4, 4, 4, 0);
final GridWidget.Adder adder = gw.createAdder(2);
adder.add(createToggleableLargeButton(
ResourcePackPrivacyClient.isBroadcastDownloads(),
ViewServerResourcesClient.isBroadcastDownloads(),
bl -> Text.translatable("resourcepackprivacy.settings.broadcast", Text.translatable(bl ? "gui.yes" : "gui.no")).withColor(bl ? new Color(100, 255, 100).getRGB() : new Color(255, 100, 100).getRGB()),
bl -> {
ResourcePackPrivacyClient.setBroadcastDownloads(bl);
ViewServerResourcesClient.setBroadcastDownloads(bl);
cfgDirty = true;
}
), 2);
@@ -54,13 +54,13 @@ public class ResourcePackPrivacyConfigScreen extends Screen {
btn.active = false;
assert client != null;
cfgDirty = true;
client.setScreen(new ManageListScreen<>(Text.translatable("resourcepackprivacy.settings.whitelistedURLs"), this, ResourcePackPrivacyClient.getWhitelistedURLs()));
client.setScreen(new ManageListScreen<>(Text.translatable("resourcepackprivacy.settings.whitelistedURLs"), this, ViewServerResourcesClient.getWhitelistedURLs()));
}));
adder.add(createButton(Text.translatable("resourcepackprivacy.settings.whitelistedHosts"), btn -> {
btn.active = false;
assert client != null;
cfgDirty = true;
client.setScreen(new ManageListScreen<>(Text.translatable("resourcepackprivacy.settings.whitelistedHosts"), this, ResourcePackPrivacyClient.getWhitelistedHosts()));
client.setScreen(new ManageListScreen<>(Text.translatable("resourcepackprivacy.settings.whitelistedHosts"), this, ViewServerResourcesClient.getWhitelistedHosts()));
}));
gw.refreshPositions();
SimplePositioningWidget.setPos(gw, 0, 0, this.width, this.height, 0.5F, 0.5f);
@@ -1,4 +1,4 @@
package de.shiewk.resourcepackprivacy.screen.elements;
package de.shiewk.viewserverresources.screen.elements;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.client.font.TextRenderer;
@@ -11,7 +11,7 @@
"gui.resourcepackprivacy.viewURLs": "View download URLs",
"gui.resourcepackprivacy.downloading": "Downloading server resource pack from %s",
"gui.resourcepackprivacy.config": "Config",
"resourcepackprivacy.settings": "ResourcePackPrivacy Settings",
"resourcepackprivacy.settings": "ViewServerResources Settings",
"resourcepackprivacy.settings.whitelistedURLs": "Manage allowed URLs",
"resourcepackprivacy.settings.whitelistedHosts": "Manage allowed pack hosts",
"resourcepackprivacy.settings.broadcast": "Show downloaded pack URLs in chat: %s"
+8 -8
View File
@@ -1,27 +1,27 @@
{
"schemaVersion": 1,
"id": "resourcepackprivacy",
"id": "viewserverresources",
"version": "${version}",
"name": "ResourcePackPrivacy",
"description": "More Resource Pack Privacy",
"name": "ViewServerResources",
"description": "Allows you to view server resource pack URLs before downloading them",
"authors": [],
"contact": {},
"license": "Apache-2.0",
"icon": "assets/resourcepackprivacy/icon.png",
"icon": "assets/viewserverresources/icon.png",
"environment": "client",
"entrypoints": {
"client": [
"de.shiewk.resourcepackprivacy.client.ResourcePackPrivacyClient"
"de.shiewk.viewserverresources.client.ViewServerResourcesClient"
],
"main": [
"de.shiewk.resourcepackprivacy.ResourcePackPrivacy"
"de.shiewk.viewserverresources.ViewServerResourcesMod"
],
"modmenu": [
"de.shiewk.resourcepackprivacy.client.ModMenuConfig"
"de.shiewk.viewserverresources.client.ModMenuConfig"
]
},
"mixins": [
"resourcepackprivacy.mixins.json"
"viewserverresources.mixins.json"
],
"depends": {
"fabricloader": ">=${loader_version}",
@@ -1,7 +1,7 @@
{
"required": true,
"minVersion": "0.8",
"package": "de.shiewk.resourcepackprivacy.mixin",
"package": "de.shiewk.viewserverresources.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [],
"client": [