diff options
| author | Aizistral | 2022-08-26 19:28:38 +0200 |
|---|---|---|
| committer | Aizistral | 2022-08-26 19:28:38 +0200 |
| commit | e1cfc84ede1a8f779e01bd1f277c95b7e0af3882 (patch) | |
| tree | 8357fb9d2c5d3216993fc208016fddc5075fba25 /src | |
| parent | 64bf55ccc5166e4f064fd07e69be20b046d68cac (diff) | |
Commence work on config file separation
Diffstat (limited to 'src')
25 files changed, 724 insertions, 340 deletions
diff --git a/src/main/java/com/aizistral/nochatreports/NoChatReports.java b/src/main/java/com/aizistral/nochatreports/NoChatReports.java index c2f83de..d9f8daa 100644 --- a/src/main/java/com/aizistral/nochatreports/NoChatReports.java +++ b/src/main/java/com/aizistral/nochatreports/NoChatReports.java @@ -4,6 +4,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; import com.aizistral.nochatreports.network.ServerChannelHandler; import com.mojang.authlib.minecraft.UserApiService; import com.mojang.patchy.MojangBlockListSupplier; @@ -39,12 +40,13 @@ public final class NoChatReports implements ModInitializer { ServerPlayNetworking.registerGlobalReceiver(CHANNEL, ServerChannelHandler.INSTANCE); ServerPlayConnectionEvents.JOIN.register(this::onPlayReady); - NCRConfig.loadConfig(); + NCRConfigLegacy.loadConfig(); + NCRConfig.load(); } private void onPlayReady(ServerGamePacketListenerImpl handler, PacketSender sender, MinecraftServer server) { server.execute(() -> { - if (NCRConfig.demandsOnClient() && !ServerPlayNetworking.canSend(handler, CHANNEL)) { + if (NCRConfigLegacy.demandsOnClient() && !ServerPlayNetworking.canSend(handler, CHANNEL)) { handler.disconnect(Component.literal("You do not have No Chat Reports, and this server is configured to require it on client!")); } diff --git a/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java b/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java index a0ed8de..c8f8e4e 100644 --- a/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java +++ b/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java @@ -3,7 +3,7 @@ package com.aizistral.nochatreports; import java.util.List; import com.aizistral.nochatreports.core.ServerSafetyState; -import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; import com.aizistral.nochatreports.core.ServerSafetyLevel; import com.aizistral.nochatreports.gui.UnsafeServerScreen; import com.aizistral.nochatreports.mixins.client.AccessorDisconnectedScreen; @@ -70,7 +70,7 @@ public final class NoChatReportsClient implements ClientModInitializer { return; } else if (KEY_DISCONNECT_REASONS.contains(contents.getKey())) { if (ServerSafetyState.getLastServerAddress() != null) { - if (!NCRConfig.isWhitelistedServer(ServerSafetyState.getLastServerAddress()) && !NCRConfig.whitelistAllServers()) { + if (!NCRConfigLegacy.isWhitelistedServer(ServerSafetyState.getLastServerAddress()) && !NCRConfigLegacy.whitelistAllServers()) { client.setScreen(new UnsafeServerScreen()); } else { if (ServerSafetyState.getReconnectCount() <= 0) { @@ -106,7 +106,7 @@ public final class NoChatReportsClient implements ClientModInitializer { } } - if (NCRConfig.demandsOnServer() && !ClientPlayNetworking.canSend(NoChatReports.CHANNEL)) { + if (NCRConfigLegacy.demandsOnServer() && !ClientPlayNetworking.canSend(NoChatReports.CHANNEL)) { handler.getConnection().disconnect(Component.translatable("disconnect.nochatreports.client")); } }); diff --git a/src/main/java/com/aizistral/nochatreports/config/AbstractJSONConfig.java b/src/main/java/com/aizistral/nochatreports/config/AbstractJSONConfig.java new file mode 100644 index 0000000..19f6d75 --- /dev/null +++ b/src/main/java/com/aizistral/nochatreports/config/AbstractJSONConfig.java @@ -0,0 +1,96 @@ +package com.aizistral.nochatreports.config; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Optional; +import java.util.function.Supplier; + +import javax.annotation.Nullable; + +import com.aizistral.nochatreports.NoChatReports; +import com.google.gson.ExclusionStrategy; +import com.google.gson.FieldAttributes; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import net.fabricmc.loader.api.FabricLoader; + +public abstract class AbstractJSONConfig { + protected static final Path CONFIG_DIR = FabricLoader.getInstance().getConfigDir(); + protected static final Gson GSON = new GsonBuilder().setPrettyPrinting() + .setExclusionStrategies(JSONExclusions.INSTANCE).create(); + protected final String fileName; + protected final Path filePath; + + protected AbstractJSONConfig(String file) { + this.fileName = file; + this.filePath = CONFIG_DIR.resolve(this.fileName); + } + + public Path getFile() { + return this.filePath; + } + + protected void save() { + NoChatReports.LOGGER.info("Writing config file {}...", this.fileName); + writeFile(this.fileName, this); + } + + protected static <T extends AbstractJSONConfig> T loadConfig(Class<T> configClass, Supplier<T> freshInstance, String fileName) { + NoChatReports.LOGGER.info("Reading config file {}...", fileName); + return readFile(fileName, configClass).orElseGet(freshInstance); + } + + private static <T extends AbstractJSONConfig> Optional<T> readFile(String fileName, Class<T> configClass) { + Path file = CONFIG_DIR.resolve(fileName); + + if (!Files.isRegularFile(file)) + return Optional.empty(); + + try (BufferedReader reader = Files.newBufferedReader(file)) { + return Optional.of(GSON.fromJson(reader, configClass)); + } catch (IOException ex) { + NoChatReports.LOGGER.fatal("Could not read config file: {}", file); + ex.printStackTrace(); + return null; + } + } + + private static <T> void writeFile(String fileName, T config) { + Path file = CONFIG_DIR.resolve(fileName); + + try { + Files.createDirectories(file.getParent()); + try (BufferedWriter writer = Files.newBufferedWriter(file)) { + GSON.toJson(config, writer); + } + } catch (Exception ex) { + NoChatReports.LOGGER.fatal("Could not write config file: {}", file); + throw new RuntimeException(ex); + } + } + + private static final class JSONExclusions implements ExclusionStrategy { + private static final JSONExclusions INSTANCE = new JSONExclusions(); + + private JSONExclusions() { + // TODO NO-OP + } + + @Override + public boolean shouldSkipField(FieldAttributes field) { + return field.getDeclaringClass() == AbstractJSONConfig.class; + } + + @Override + public boolean shouldSkipClass(Class<?> theClass) { + return false; + } + + } + +} diff --git a/src/main/java/com/aizistral/nochatreports/config/ModMenuIntegration.java b/src/main/java/com/aizistral/nochatreports/config/ModMenuIntegration.java index 5445ce4..ffdee5c 100644 --- a/src/main/java/com/aizistral/nochatreports/config/ModMenuIntegration.java +++ b/src/main/java/com/aizistral/nochatreports/config/ModMenuIntegration.java @@ -62,10 +62,10 @@ public final class ModMenuIntegration implements ModMenuApi { ConfigEntryBuilder entryBuilder = builder.entryBuilder(); // Set an option for showServerSafety - visual.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.showServerSafety"), NCRConfig.getInstance().showServerSafety) + visual.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.showServerSafety"), NCRConfigLegacy.getInstance().showServerSafety) .setDefaultValue(true) .setTooltip(this.makeTooltip("option.NoChatReports.showServerSafety.tooltip")) - .setSaveConsumer(newValue -> NCRConfig.getInstance().showServerSafety = newValue) + .setSaveConsumer(newValue -> NCRConfigLegacy.getInstance().showServerSafety = newValue) .build()); // Add link for documentation for showServerSafety @@ -75,80 +75,80 @@ public final class ModMenuIntegration implements ModMenuApi { .build()); // Set an option for hideRedChatIndicators - visual.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.hideRedChatIndicators"), NCRConfig.getInstance().hideRedChatIndicators) + visual.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.hideRedChatIndicators"), NCRConfigLegacy.getInstance().hideRedChatIndicators) .setDefaultValue(true) .setTooltip(this.makeTooltip("option.NoChatReports.hideRedChatIndicators.tooltip")) - .setSaveConsumer(newValue -> NCRConfig.getInstance().hideRedChatIndicators = newValue) + .setSaveConsumer(newValue -> NCRConfigLegacy.getInstance().hideRedChatIndicators = newValue) .build()); // Set an option for hideYellowChatIndicators - visual.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.hideYellowChatIndicators"), NCRConfig.getInstance().hideYellowChatIndicators) + visual.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.hideYellowChatIndicators"), NCRConfigLegacy.getInstance().hideYellowChatIndicators) .setDefaultValue(true) .setTooltip(this.makeTooltip("option.NoChatReports.hideYellowChatIndicators.tooltip")) - .setSaveConsumer(newValue -> NCRConfig.getInstance().hideYellowChatIndicators = newValue) + .setSaveConsumer(newValue -> NCRConfigLegacy.getInstance().hideYellowChatIndicators = newValue) .build()); // Set an option for hideGrayChatIndicators - visual.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.hideGrayChatIndicators"), NCRConfig.getInstance().hideGrayChatIndicators) + visual.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.hideGrayChatIndicators"), NCRConfigLegacy.getInstance().hideGrayChatIndicators) .setDefaultValue(true) .setTooltip(this.makeTooltip("option.NoChatReports.hideGrayChatIndicators.tooltip")) - .setSaveConsumer(newValue -> NCRConfig.getInstance().hideGrayChatIndicators = newValue) + .setSaveConsumer(newValue -> NCRConfigLegacy.getInstance().hideGrayChatIndicators = newValue) .build()); // Set an option for hideWarningToast - visual.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.hideWarningToast"), NCRConfig.getInstance().hideWarningToast) + visual.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.hideWarningToast"), NCRConfigLegacy.getInstance().hideWarningToast) .setDefaultValue(true) .setTooltip(this.makeTooltip("option.NoChatReports.hideWarningToast.tooltip")) - .setSaveConsumer(newValue -> NCRConfig.getInstance().hideWarningToast = newValue) + .setSaveConsumer(newValue -> NCRConfigLegacy.getInstance().hideWarningToast = newValue) .build()); // Set an option for alwaysHideReportButton - visual.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.alwaysHideReportButton"), NCRConfig.getInstance().alwaysHideReportButton) + visual.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.alwaysHideReportButton"), NCRConfigLegacy.getInstance().alwaysHideReportButton) .setDefaultValue(false) .setTooltip(this.makeTooltip("option.NoChatReports.alwaysHideReportButton.tooltip")) - .setSaveConsumer(newValue -> NCRConfig.getInstance().alwaysHideReportButton = newValue) + .setSaveConsumer(newValue -> NCRConfigLegacy.getInstance().alwaysHideReportButton = newValue) .build()); // Set an option for demandOnServer - technical.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.demandOnServer"), NCRConfig.getInstance().demandOnServer) + technical.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.demandOnServer"), NCRConfigLegacy.getInstance().demandOnServer) .setDefaultValue(false) .setTooltip(this.makeTooltip("option.NoChatReports.demandOnServer.tooltip")) - .setSaveConsumer(newValue -> NCRConfig.getInstance().demandOnServer = newValue) + .setSaveConsumer(newValue -> NCRConfigLegacy.getInstance().demandOnServer = newValue) .build()); // Set an option for enableDebugLog - technical.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.enableDebugLog"), NCRConfig.getInstance().enableDebugLog) + technical.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.enableDebugLog"), NCRConfigLegacy.getInstance().enableDebugLog) .setDefaultValue(false) .setTooltip(this.makeTooltip("option.NoChatReports.enableDebugLog.tooltip")) - .setSaveConsumer(newValue -> NCRConfig.getInstance().enableDebugLog = newValue) + .setSaveConsumer(newValue -> NCRConfigLegacy.getInstance().enableDebugLog = newValue) .build()); // Set an option for convertToGameMessage - technical.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.convertToGameMessage"), NCRConfig.getInstance().convertToGameMessage) + technical.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.convertToGameMessage"), NCRConfigLegacy.getInstance().convertToGameMessage) .setDefaultValue(false) .setTooltip(this.makeTooltip("option.NoChatReports.convertToGameMessage.tooltip")) - .setSaveConsumer(newValue -> NCRConfig.getInstance().convertToGameMessage = newValue) + .setSaveConsumer(newValue -> NCRConfigLegacy.getInstance().convertToGameMessage = newValue) .build()); // Set an option for disableTelemetry - technical.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.disableTelemetry"), NCRConfig.getInstance().disableTelemetry) + technical.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.disableTelemetry"), NCRConfigLegacy.getInstance().disableTelemetry) .setDefaultValue(true) .setTooltip(this.makeTooltip("option.NoChatReports.disableTelemetry.tooltip")) - .setSaveConsumer(newValue -> NCRConfig.getInstance().disableTelemetry = newValue) + .setSaveConsumer(newValue -> NCRConfigLegacy.getInstance().disableTelemetry = newValue) .build()); // Set an option for showReloadButton - technical.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.showReloadButton"), NCRConfig.getInstance().showReloadButton) + technical.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.showReloadButton"), NCRConfigLegacy.getInstance().showReloadButton) .setDefaultValue(true) .setTooltip(this.makeTooltip("option.NoChatReports.showReloadButton.tooltip")) - .setSaveConsumer(newValue -> NCRConfig.getInstance().showReloadButton = newValue) + .setSaveConsumer(newValue -> NCRConfigLegacy.getInstance().showReloadButton = newValue) .build()); // Set an option for whitelistAllServers - technical.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.whitelistAllServers"), NCRConfig.getInstance().whitelistAllServers) + technical.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.whitelistAllServers"), NCRConfigLegacy.getInstance().whitelistAllServers) .setDefaultValue(false) .setTooltip(this.makeTooltip("option.NoChatReports.whitelistAllServers.tooltip")) - .setSaveConsumer(newValue -> NCRConfig.getInstance().whitelistAllServers = newValue) + .setSaveConsumer(newValue -> NCRConfigLegacy.getInstance().whitelistAllServers = newValue) .build()); // Instructions for adding servers @@ -156,21 +156,21 @@ public final class ModMenuIntegration implements ModMenuApi { .build()); // Add or remove whitelisted servers - whitelistedServers.addEntry(entryBuilder.startStrList(Component.translatable("option.NoChatReports.whitelistedServers"), NCRConfig.getInstance().whitelistedServers) + whitelistedServers.addEntry(entryBuilder.startStrList(Component.translatable("option.NoChatReports.whitelistedServers"), NCRConfigLegacy.getInstance().whitelistedServers) .setExpanded(true) .setInsertInFront(true) .setDefaultValue(DEFAULT_WHITELISTED_SERVERS) .setTooltip(this.makeTooltip("option.NoChatReports.whitelistedServers.tooltip")) .setAddButtonTooltip(Component.translatable("option.NoChatReports.whitelistedServers.addButtonTooltip")) .setRemoveButtonTooltip(Component.translatable("option.NoChatReports.whitelistedServers.removeButtonTooltip")) - .setSaveConsumer(newValue -> NCRConfig.getInstance().whitelistedServers = newValue) + .setSaveConsumer(newValue -> NCRConfigLegacy.getInstance().whitelistedServers = newValue) .setCreateNewInstance(baseListEntry -> new StringListListEntry.StringListCell(Language.getInstance().getOrDefault(("option.NoChatReports.whitelistedServers.serverAddress")), baseListEntry)) .build()); // Save config builder.setSavingRunnable(() -> { - NCRConfig.saveConfig(); - NCRConfig.loadConfig(); + NCRConfigLegacy.saveConfig(); + NCRConfigLegacy.loadConfig(); }); return builder.build(); }; diff --git a/src/main/java/com/aizistral/nochatreports/config/NCRClientConfig.java b/src/main/java/com/aizistral/nochatreports/config/NCRClientConfig.java new file mode 100644 index 0000000..ea1bc9a --- /dev/null +++ b/src/main/java/com/aizistral/nochatreports/config/NCRClientConfig.java @@ -0,0 +1,166 @@ +package com.aizistral.nochatreports.config; + +import java.util.ArrayList; +import java.util.List; + +import com.aizistral.nochatreports.core.ServerSafetyLevel; +import com.aizistral.nochatreports.gui.UnsafeServerScreen; +import com.aizistral.nochatreports.mixins.client.MixinChatListener; +import com.aizistral.nochatreports.mixins.client.MixinToastComponent; + +import net.minecraft.client.multiplayer.resolver.ServerAddress; + +public final class NCRClientConfig extends AbstractJSONConfig { + protected static final String FILE_NAME = "NoChatReports/NCR-Client.json"; + protected boolean demandOnServer = false, showServerSafety = true, hideRedChatIndicators = true, + hideYellowChatIndicators = true, hideGrayChatIndicators = true, hideWarningToast = true, + alwaysHideReportButton = false, disableTelemetry = true, showReloadButton = true, + whitelistAllServers = false; + protected List<String> whitelistedServers = new ArrayList<>(); + + protected NCRClientConfig() { + super(FILE_NAME); + } + + /** + * @return True if client with No Chat Reports installed should demand that mod is present on + * every server that it tries to join. In that case client will not be able to join servers that + * don't have the mod installed. Servers without the mod can still provide varying degrees of + * safety, which {@link ServerSafetyLevel} and respective icon in bottom-right corner of the chat + * screen is designed to indicate.<br><br> + * + * This is false by default. + */ + + public boolean demandsOnServer() { + return this.demandOnServer; + } + + /** + * @return True if current {@link ServerSafetyLevel} should be indicated on client by an icon in + * the bottom-right corner of chat screen.<br><br> + * + * This is true by default. + */ + + public boolean showServerSafety() { + return this.showServerSafety; + } + + /** + * @return Current list of whitelisted unsafe servers. Used on client to remember which servers + * user disabled unsafety warnings for.<br><br> + * + * This is empty by default. + * + * @see UnsafeServerScreen + */ + + public List<String> getWhitelistedServers() { + return this.whitelistedServers; + } + + /** + * @param address Address of the server to be check. + * @return Whether this server is in the whitelist of unsafe servers, as returned by + * {@link #getWhitelistedServers()}. + * @see UnsafeServerScreen + */ + + public boolean isWhitelistedServer(ServerAddress address) { + return this.getWhitelistedServers().contains(address.getHost() + ":" + address.getPort()); + } + + /** + * @return True if vanilla's unsigned messages trust indicator should be removed.<br><br> + * + * This is true by default. + * + * @see MixinChatListener#onEvaluateTrustLevel + */ + + public boolean hideRedChatIndicators() { + return this.hideRedChatIndicators; + } + + /** + * @return True if vanilla's modified/hidden messages trust indicator should be removed.<br><br> + * + * This is true by default. + * + * @see MixinChatListener#onEvaluateTrustLevel + */ + + public boolean hideYellowChatIndicators() { + return this.hideYellowChatIndicators; + } + + /** + * @return True if vanilla's system messages trust indicator should be removed.<br><br> + * + * This is true by default. + * + * @see com.aizistral.nochatreports.mixins.client.MixinGuiMessageTag#onSystem + */ + + public boolean hideGrayChatIndicators() { + return this.hideGrayChatIndicators; + } + + /** + * @return True if "Chat messages can't be verified" toast should be removed.<br><br> + * + * This is true by default. + * + * @see MixinToastComponent#onAddToast + */ + + public boolean hideWarningToast() { + return this.hideWarningToast; + } + + /** + * @return True if reporting buttons should always be hidden from social interactions screen, + * instead of simply being disabled.<br><br> + * + * This is false by default. + */ + + public boolean alwaysHideReportButton() { + return this.alwaysHideReportButton; + } + + /** + * @return True if sending telemetry to Mojang should be disabled.<br><br> + * + * This is true by default. + */ + + public boolean disableTelemetry() { + return this.disableTelemetry; + } + + /** + * @return True if the configuration reload button should be displayed in multiplayer screen. + * <br><br> + * + * This is true by default. + */ + + public boolean showReloadButton() { + return this.showReloadButton; + } + + /** + * @return True if the full-screen warning should be skipped for servers that require chat signing, + * letting users simply join the server. Because of that, servers will no longer be added to the whitelist. + * <br><br> + * + * This is false by default. + */ + + public boolean whitelistAllServers() { + return this.whitelistAllServers; + } + +} diff --git a/src/main/java/com/aizistral/nochatreports/config/NCRCommonConfig.java b/src/main/java/com/aizistral/nochatreports/config/NCRCommonConfig.java new file mode 100644 index 0000000..e9ad0a5 --- /dev/null +++ b/src/main/java/com/aizistral/nochatreports/config/NCRCommonConfig.java @@ -0,0 +1,67 @@ +package com.aizistral.nochatreports.config; + +import java.nio.file.Path; +import java.util.List; + +import com.aizistral.nochatreports.core.ServerSafetyLevel; +import com.aizistral.nochatreports.gui.UnsafeServerScreen; +import com.aizistral.nochatreports.mixins.client.MixinChatListener; +import com.aizistral.nochatreports.mixins.client.MixinToastComponent; + +import net.minecraft.client.multiplayer.resolver.ServerAddress; + +public final class NCRCommonConfig extends AbstractJSONConfig { + protected static final String FILE_NAME = "NoChatReports/NCR-Common.json"; + protected boolean demandOnClient = true, enableDebugLog = false, convertToGameMessage = false, + addQueryData = true; + + protected NCRCommonConfig() { + super(FILE_NAME); + } + + /** + * @return True if server with No Chat Reports installed should demand that mod is present on + * every client that tries to join. Mod's installation on client is optional otherwise.<br><br> + * + * This is false by default. + */ + + public boolean demandsOnClient() { + return this.demandOnClient; + } + + /** + * @return True if server should convert all player messages to system messages. System messages + * do not feature signatures and look completely identical in the chat, with exception of gray line + * next to them added in pre-release 3. They are also unselectable for chat reporting.<br><br> + * + * This is false by default. + */ + + public boolean convertToGameMessage() { + return this.convertToGameMessage; + } + + /** + * @return True if mod should log some additional information about its activity and message + * signatures. Generally only useful for debugging.<br><br> + * + * This is false by default. + */ + + public boolean enableDebugLog() { + return this.enableDebugLog; + } + + /** + * @return True if server should include extra query data to help clients know that your server + * is secure.<br><br> + * + * This is true by default. + */ + + public boolean addQueryData() { + return this.addQueryData; + } + +} diff --git a/src/main/java/com/aizistral/nochatreports/config/NCRConfig.java b/src/main/java/com/aizistral/nochatreports/config/NCRConfig.java index 7abf623..9d7c7e7 100644 --- a/src/main/java/com/aizistral/nochatreports/config/NCRConfig.java +++ b/src/main/java/com/aizistral/nochatreports/config/NCRConfig.java @@ -1,295 +1,53 @@ package com.aizistral.nochatreports.config; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.annotation.Nullable; - -import com.aizistral.nochatreports.NoChatReports; -import com.aizistral.nochatreports.core.ServerSafetyLevel; -import com.aizistral.nochatreports.gui.UnsafeServerScreen; -import com.aizistral.nochatreports.mixins.client.MixinChatListener; -import com.aizistral.nochatreports.mixins.client.MixinToastComponent; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; -import com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService; +import java.util.Objects; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.multiplayer.chat.ChatTrustLevel; -import net.minecraft.client.multiplayer.resolver.ServerAddress; -import net.minecraft.util.Tuple; - -/** - * Simple implementation of JSON-config for the mod. Can be loaded at any time and does not depend - * on modloader-specific API. The only disadvantage is that we don't get to comment options.<br><br> - * - * For now, the config file is called <code>NoChatReports.json</code> and is located in default config - * folder. In the future this should be separated into client and server configs. - * - * @author Aizistral - */ public final class NCRConfig { - private static final Path CONFIG_FILE = FabricLoader.getInstance().getConfigDir().resolve("NoChatReports.json"); - private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); - private static NCRConfig INSTANCE; - protected boolean demandOnClient = true, demandOnServer = false, enableDebugLog = false, - convertToGameMessage = false, showServerSafety = true, hideRedChatIndicators = true, - hideYellowChatIndicators = true, hideGrayChatIndicators = true, hideWarningToast = true, - alwaysHideReportButton = false, disableTelemetry = true, showReloadButton = true, - whitelistAllServers = false, addQueryData = true; - protected List<String> whitelistedServers; - - protected static NCRConfig getInstance() { - if (INSTANCE == null) { - loadConfig(); - } + private static NCRCommonConfig common = null; + private static NCRClientConfig client = null; - return INSTANCE; + private NCRConfig() { + throw new IllegalStateException("Can't touch this"); } - /** - * Loads (or reloads) the config from local file, or creates default one if that fails. - * Re-searializes validated {@link #INSTANCE} object back into the file. - */ - - public static void loadConfig() { - NoChatReports.LOGGER.info(INSTANCE == null ? "Loading config..." : "Reloading config..."); - - INSTANCE = readFile(); - - if (INSTANCE == null) { - INSTANCE = new NCRConfig(); + public static AbstractJSONConfig getCommon() { + if (common == null) { + load(); } - if (INSTANCE.whitelistedServers == null) { - INSTANCE.whitelistedServers = new ArrayList<>(); - } - - writeFile(INSTANCE); + return common; } - /** - * Writes current config instance into local file. - */ - - public static void saveConfig() { - if (INSTANCE != null) { - writeFile(INSTANCE); + @Environment(EnvType.CLIENT) + public static AbstractJSONConfig getClient() { + if (client == null) { + load(); } - } - @Nullable - private static NCRConfig readFile() { - if (!Files.isRegularFile(CONFIG_FILE)) - return null; - - try (BufferedReader reader = Files.newBufferedReader(CONFIG_FILE)) { - return GSON.fromJson(reader, NCRConfig.class); - } catch (IOException ex) { - throw new RuntimeException(ex); - } + return client; } - private static void writeFile(NCRConfig instance) { - try (BufferedWriter writer = Files.newBufferedWriter(CONFIG_FILE)) { - GSON.toJson(instance, writer); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - /** - * @return True if server with No Chat Reports installed should demand that mod is present on - * every client that tries to join. Mod's installation on client is optional otherwise.<br><br> - * - * This is false by default. - */ - - public static boolean demandsOnClient() { - return getInstance().demandOnClient; - } - - /** - * @return True if client with No Chat Reports installed should demand that mod is present on - * every server that it tries to join. In that case client will not be able to join servers that - * don't have the mod installed. Servers without the mod can still provide varying degrees of - * safety, which {@link ServerSafetyLevel} and respective icon in bottom-right corner of the chat - * screen is designed to indicate.<br><br> - * - * This is false by default. - */ - - public static boolean demandsOnServer() { - return getInstance().demandOnServer; - } - - /** - * @return True if server should convert all player messages to system messages. System messages - * do not feature signatures and look completely identical in the chat, with exception of gray line - * next to them added in pre-release 3. They are also unselectable for chat reporting.<br><br> - * - * This is false by default. - */ - - public static boolean convertToGameMessage() { - return getInstance().convertToGameMessage; - } - - /** - * @return True if current {@link ServerSafetyLevel} should be indicated on client by an icon in - * the bottom-right corner of chat screen.<br><br> - * - * This is true by default. - */ - - public static boolean showServerSafety() { - return getInstance().showServerSafety; - } - - /** - * @return Current list of whitelisted unsafe servers. Used on client to remember which servers - * user disabled unsafety warnings for.<br><br> - * - * This is empty by default. - * - * @see UnsafeServerScreen - */ - - public static List<String> getWhitelistedServers() { - return getInstance().whitelistedServers; - } + public static void load() { + common = AbstractJSONConfig.loadConfig(NCRCommonConfig.class, NCRCommonConfig::new, NCRCommonConfig.FILE_NAME); + common.save(); - /** - * @param address Address of the server to be check. - * @return Whether this server is in the whitelist of unsafe servers, as returned by - * {@link #getWhitelistedServers()}. - * @see UnsafeServerScreen - */ - - public static boolean isWhitelistedServer(ServerAddress address) { - return getWhitelistedServers().contains(address.getHost() + ":" + address.getPort()); - } - - /** - * @return True if vanilla's unsigned messages trust indicator should be removed.<br><br> - * - * This is true by default. - * - * @see MixinChatListener#onEvaluateTrustLevel - */ - - public static boolean hideRedChatIndicators() { - return getInstance().hideRedChatIndicators; - } - - /** - * @return True if vanilla's modified/hidden messages trust indicator should be removed.<br><br> - * - * This is true by default. - * - * @see MixinChatListener#onEvaluateTrustLevel - */ - - public static boolean hideYellowChatIndicators() { - return getInstance().hideYellowChatIndicators; - } - - /** - * @return True if vanilla's system messages trust indicator should be removed.<br><br> - * - * This is true by default. - * - * @see com.aizistral.nochatreports.mixins.client.MixinGuiMessageTag#onSystem - */ - - public static boolean hideGrayChatIndicators() { - return getInstance().hideGrayChatIndicators; - } - - /** - * @return True if "Chat messages can't be verified" toast should be removed.<br><br> - * - * This is true by default. - * - * @see MixinToastComponent#onAddToast - */ - - public static boolean hideWarningToast() { - return getInstance().hideWarningToast; - } - - /** - * @return True if mod should log some additional information about its activity and message - * signatures. Generally only useful for debugging.<br><br> - * - * This is false by default. - */ - - public static boolean enableDebugLog() { - return getInstance().enableDebugLog; - } - - /** - * @return True if reporting buttons should always be hidden from social interactions screen, - * instead of simply being disabled.<br><br> - * - * This is false by default. - */ - - public static boolean alwaysHideReportButton() { - return getInstance().alwaysHideReportButton; - } - - /** - * @return True if sending telemetry to Mojang should be disabled.<br><br> - * - * This is true by default. - */ - - public static boolean disableTelemetry() { - return getInstance().disableTelemetry; - } - - /** - * @return True if the configuration reload button should be displayed in multiplayer screen. - * <br><br> - * - * This is true by default. - */ - - public static boolean showReloadButton() { - return getInstance().showReloadButton; - } - - /** - * @return True if the full-screen warning should be skipped for servers that require chat signing, - * letting users simply join the server. Because of that, servers will no longer be added to the whitelist. - * <br><br> - * - * This is false by default. - */ - - public static boolean whitelistAllServers() { - return getInstance().whitelistAllServers; + if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { + client = AbstractJSONConfig.loadConfig(NCRClientConfig.class, NCRClientConfig::new, NCRClientConfig.FILE_NAME); + client.save(); + } } - /** - * @return True if server should include extra query data to help clients know that your server - * is secure.<br><br> - * - * This is true by default. - */ + public static void save() { + Objects.requireNonNull(common, "Cannot save config because it was not loaded!").save(); - public static boolean addQueryData() { - return getInstance().addQueryData; + if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { + Objects.requireNonNull(client, "Cannot save config because it was not loaded!").save(); + } } } diff --git a/src/main/java/com/aizistral/nochatreports/config/NCRConfigLegacy.java b/src/main/java/com/aizistral/nochatreports/config/NCRConfigLegacy.java new file mode 100644 index 0000000..d0de3ab --- /dev/null +++ b/src/main/java/com/aizistral/nochatreports/config/NCRConfigLegacy.java @@ -0,0 +1,295 @@ +package com.aizistral.nochatreports.config; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.annotation.Nullable; + +import com.aizistral.nochatreports.NoChatReports; +import com.aizistral.nochatreports.core.ServerSafetyLevel; +import com.aizistral.nochatreports.gui.UnsafeServerScreen; +import com.aizistral.nochatreports.mixins.client.MixinChatListener; +import com.aizistral.nochatreports.mixins.client.MixinToastComponent; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; +import com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService; + +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.client.multiplayer.chat.ChatTrustLevel; +import net.minecraft.client.multiplayer.resolver.ServerAddress; +import net.minecraft.util.Tuple; + +/** + * Simple implementation of JSON-config for the mod. Can be loaded at any time and does not depend + * on modloader-specific API. The only disadvantage is that we don't get to comment options.<br><br> + * + * For now, the config file is called <code>NoChatReports.json</code> and is located in default config + * folder. In the future this should be separated into client and server configs. + * + * @author Aizistral + */ + +public final class NCRConfigLegacy { + private static final Path CONFIG_FILE = FabricLoader.getInstance().getConfigDir().resolve("NoChatReports.json"); + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + private static NCRConfigLegacy INSTANCE; + protected boolean demandOnClient = true, demandOnServer = false, enableDebugLog = false, + convertToGameMessage = false, showServerSafety = true, hideRedChatIndicators = true, + hideYellowChatIndicators = true, hideGrayChatIndicators = true, hideWarningToast = true, + alwaysHideReportButton = false, disableTelemetry = true, showReloadButton = true, + whitelistAllServers = false, addQueryData = true; + protected List<String> whitelistedServers; + + protected static NCRConfigLegacy getInstance() { + if (INSTANCE == null) { + loadConfig(); + } + + return INSTANCE; + } + + /** + * Loads (or reloads) the config from local file, or creates default one if that fails. + * Re-searializes validated {@link #INSTANCE} object back into the file. + */ + + public static void loadConfig() { + NoChatReports.LOGGER.info(INSTANCE == null ? "Loading config..." : "Reloading config..."); + + INSTANCE = readFile(); + + if (INSTANCE == null) { + INSTANCE = new NCRConfigLegacy(); + } + + if (INSTANCE.whitelistedServers == null) { + INSTANCE.whitelistedServers = new ArrayList<>(); + } + + writeFile(INSTANCE); + } + + /** + * Writes current config instance into local file. + */ + + public static void saveConfig() { + if (INSTANCE != null) { + writeFile(INSTANCE); + } + } + + @Nullable + private static NCRConfigLegacy readFile() { + if (!Files.isRegularFile(CONFIG_FILE)) + return null; + + try (BufferedReader reader = Files.newBufferedReader(CONFIG_FILE)) { + return GSON.fromJson(reader, NCRConfigLegacy.class); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + } + + private static void writeFile(NCRConfigLegacy instance) { + try (BufferedWriter writer = Files.newBufferedWriter(CONFIG_FILE)) { + GSON.toJson(instance, writer); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + + /** + * @return True if server with No Chat Reports installed should demand that mod is present on + * every client that tries to join. Mod's installation on client is optional otherwise.<br><br> + * + * This is false by default. + */ + + public static boolean demandsOnClient() { + return getInstance().demandOnClient; + } + + /** + * @return True if client with No Chat Reports installed should demand that mod is present on + * every server that it tries to join. In that case client will not be able to join servers that + * don't have the mod installed. Servers without the mod can still provide varying degrees of + * safety, which {@link ServerSafetyLevel} and respective icon in bottom-right corner of the chat + * screen is designed to indicate.<br><br> + * + * This is false by default. + */ + + public static boolean demandsOnServer() { + return getInstance().demandOnServer; + } + + /** + * @return True if server should convert all player messages to system messages. System messages + * do not feature signatures and look completely identical in the chat, with exception of gray line + * next to them added in pre-release 3. They are also unselectable for chat reporting.<br><br> + * + * This is false by default. + */ + + public static boolean convertToGameMessage() { + return getInstance().convertToGameMessage; + } + + /** + * @return True if current {@link ServerSafetyLevel} should be indicated on client by an icon in + * the bottom-right corner of chat screen.<br><br> + * + * This is true by default. + */ + + public static boolean showServerSafety() { + return getInstance().showServerSafety; + } + + /** + * @return Current list of whitelisted unsafe servers. Used on client to remember which servers + * user disabled unsafety warnings for.<br><br> + * + * This is empty by default. + * + * @see UnsafeServerScreen + */ + + public static List<String> getWhitelistedServers() { + return getInstance().whitelistedServers; + } + + /** + * @param address Address of the server to be check. + * @return Whether this server is in the whitelist of unsafe servers, as returned by + * {@link #getWhitelistedServers()}. + * @see UnsafeServerScreen + */ + + public static boolean isWhitelistedServer(ServerAddress address) { + return getWhitelistedServers().contains(address.getHost() + ":" + address.getPort()); + } + + /** + * @return True if vanilla's unsigned messages trust indicator should be removed.<br><br> + * + * This is true by default. + * + * @see MixinChatListener#onEvaluateTrustLevel + */ + + public static boolean hideRedChatIndicators() { + return getInstance().hideRedChatIndicators; + } + + /** + * @return True if vanilla's modified/hidden messages trust indicator should be removed.<br><br> + * + * This is true by default. + * + * @see MixinChatListener#onEvaluateTrustLevel + */ + + public static boolean hideYellowChatIndicators() { + return getInstance().hideYellowChatIndicators; + } + + /** + * @return True if vanilla's system messages trust indicator should be removed.<br><br> + * + * This is true by default. + * + * @see com.aizistral.nochatreports.mixins.client.MixinGuiMessageTag#onSystem + */ + + public static boolean hideGrayChatIndicators() { + return getInstance().hideGrayChatIndicators; + } + + /** + * @return True if "Chat messages can't be verified" toast should be removed.<br><br> + * + * This is true by default. + * + * @see MixinToastComponent#onAddToast + */ + + public static boolean hideWarningToast() { + return getInstance().hideWarningToast; + } + + /** + * @return True if mod should log some additional information about its activity and message + * signatures. Generally only useful for debugging.<br><br> + * + * This is false by default. + */ + + public static boolean enableDebugLog() { + return getInstance().enableDebugLog; + } + + /** + * @return True if reporting buttons should always be hidden from social interactions screen, + * instead of simply being disabled.<br><br> + * + * This is false by default. + */ + + public static boolean alwaysHideReportButton() { + return getInstance().alwaysHideReportButton; + } + + /** + * @return True if sending telemetry to Mojang should be disabled.<br><br> + * + * This is true by default. + */ + + public static boolean disableTelemetry() { + return getInstance().disableTelemetry; + } + + /** + * @return True if the configuration reload button should be displayed in multiplayer screen. + * <br><br> + * + * This is true by default. + */ + + public static boolean showReloadButton() { + return getInstance().showReloadButton; + } + + /** + * @return True if the full-screen warning should be skipped for servers that require chat signing, + * letting users simply join the server. Because of that, servers will no longer be added to the whitelist. + * <br><br> + * + * This is false by default. + */ + + public static boolean whitelistAllServers() { + return getInstance().whitelistAllServers; + } + + /** + * @return True if server should include extra query data to help clients know that your server + * is secure.<br><br> + * + * This is true by default. + */ + + public static boolean addQueryData() { + return getInstance().addQueryData; + } + +} diff --git a/src/main/java/com/aizistral/nochatreports/core/ServerSafetyLevel.java b/src/main/java/com/aizistral/nochatreports/core/ServerSafetyLevel.java index 11d867f..28a9edc 100644 --- a/src/main/java/com/aizistral/nochatreports/core/ServerSafetyLevel.java +++ b/src/main/java/com/aizistral/nochatreports/core/ServerSafetyLevel.java @@ -1,7 +1,7 @@ package com.aizistral.nochatreports.core; import com.aizistral.nochatreports.NoChatReports; -import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -48,7 +48,7 @@ public enum ServerSafetyLevel { @Environment(EnvType.CLIENT) public Component getTooltip() { - if(NCRConfig.whitelistAllServers() && this.equals(ServerSafetyLevel.INSECURE)) + if(NCRConfigLegacy.whitelistAllServers() && this.equals(ServerSafetyLevel.INSECURE)) return Component.translatable("gui.nochatreports.status_insecure_whitelist_all_servers"); return Component.translatable("gui.nochatreports.status_" + this.name().toLowerCase()); } diff --git a/src/main/java/com/aizistral/nochatreports/gui/UnsafeServerScreen.java b/src/main/java/com/aizistral/nochatreports/gui/UnsafeServerScreen.java index a502529..81af0ca 100644 --- a/src/main/java/com/aizistral/nochatreports/gui/UnsafeServerScreen.java +++ b/src/main/java/com/aizistral/nochatreports/gui/UnsafeServerScreen.java @@ -3,7 +3,7 @@ package com.aizistral.nochatreports.gui; import javax.print.attribute.standard.MediaSize.NA; import com.aizistral.nochatreports.NoChatReportsClient; -import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; import com.aizistral.nochatreports.core.ServerSafetyState; import net.fabricmc.api.EnvType; @@ -52,8 +52,8 @@ public final class UnsafeServerScreen extends WarningScreen { if (address != null) { if (this.stopShowing.selected()) { - NCRConfig.getWhitelistedServers().add(address.getHost() + ":" + address.getPort()); - NCRConfig.saveConfig(); + NCRConfigLegacy.getWhitelistedServers().add(address.getHost() + ":" + address.getPort()); + NCRConfigLegacy.saveConfig(); } ServerSafetyState.setAllowsUnsafeServer(true); diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java index d5ac4a4..705718a 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java @@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import com.aizistral.nochatreports.NoChatReports; -import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; import net.minecraft.client.multiplayer.PlayerInfo; import net.minecraft.client.multiplayer.chat.ChatListener; @@ -49,16 +49,16 @@ public class MixinChatListener { return; } - if (evaluate == ChatTrustLevel.NOT_SECURE && NCRConfig.hideRedChatIndicators()) { + if (evaluate == ChatTrustLevel.NOT_SECURE && NCRConfigLegacy.hideRedChatIndicators()) { info.setReturnValue(ChatTrustLevel.SECURE); } else if ((evaluate == ChatTrustLevel.FILTERED || evaluate == ChatTrustLevel.MODIFIED) - && NCRConfig.hideYellowChatIndicators()) { + && NCRConfigLegacy.hideYellowChatIndicators()) { info.setReturnValue(ChatTrustLevel.SECURE); } } // Debug never dies - if (NCRConfig.enableDebugLog()) { + if (NCRConfigLegacy.enableDebugLog()) { NoChatReports.LOGGER.info("Received message: {}, from: {}, signature: {}", Component.Serializer.toStableJson(playerChatMessage.serverContent()), playerChatMessage.signer().profileId(), diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatScreen.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatScreen.java index 5bbf2f1..5354885 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatScreen.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatScreen.java @@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.aizistral.nochatreports.core.ServerSafetyState; -import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; import com.aizistral.nochatreports.core.ServerSafetyLevel; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.BufferBuilder; @@ -49,7 +49,7 @@ public abstract class MixinChatScreen extends Screen { @Inject(method = "init", at = @At("HEAD")) private void onInit(CallbackInfo info) { - if (!NCRConfig.showServerSafety()) + if (!NCRConfigLegacy.showServerSafety()) return; ServerSafetyLevel trust = this.minecraft.isLocalServer() ? ServerSafetyLevel.SECURE : ServerSafetyState.getCurrent(); diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinClientTelemetryManager.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinClientTelemetryManager.java index 578478b..a00620f 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinClientTelemetryManager.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinClientTelemetryManager.java @@ -1,6 +1,6 @@ package com.aizistral.nochatreports.mixins.client; -import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; import com.mojang.authlib.minecraft.TelemetrySession; import com.mojang.authlib.minecraft.UserApiService; @@ -24,7 +24,7 @@ public class MixinClientTelemetryManager { + "newTelemetrySession(Ljava/util/concurrent/Executor;)Lcom/mojang/authlib/minecraft/TelemetrySession;", remap = false)) private TelemetrySession onCreateTelemetrySession(UserApiService service, Executor executor) { - if (NCRConfig.disableTelemetry()) + if (NCRConfigLegacy.disableTelemetry()) return TelemetrySession.DISABLED; else return service.newTelemetrySession(executor); diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinConnectScreen.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinConnectScreen.java index 981bd51..e310bbf 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinConnectScreen.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinConnectScreen.java @@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.aizistral.nochatreports.NoChatReports; -import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; import com.aizistral.nochatreports.core.ServerSafetyLevel; import com.aizistral.nochatreports.core.ServerSafetyState; @@ -32,7 +32,7 @@ public class MixinConnectScreen { ServerSafetyState.updateCurrent(ServerSafetyLevel.UNKNOWN); // just to be 100% sure ServerSafetyState.setLastConnectedServer(serverAddress, serverData); - if (NCRConfig.enableDebugLog()) { + if (NCRConfigLegacy.enableDebugLog()) { NoChatReports.LOGGER.info("Connecting to: {}, will expose public key: {}", serverAddress.getHost() + ":" + serverAddress.getPort(), ServerSafetyState.allowsUnsafeServer()); diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTag.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTag.java index 71671ef..322ef99 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTag.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTag.java @@ -5,7 +5,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; import net.minecraft.client.GuiMessageTag; @@ -21,7 +21,7 @@ public class MixinGuiMessageTag { @Inject(method = "system", at = @At("HEAD"), cancellable = true) private static void onSystem(CallbackInfoReturnable<GuiMessageTag> info) { - if (NCRConfig.hideGrayChatIndicators()) { + if (NCRConfigLegacy.hideGrayChatIndicators()) { info.setReturnValue(null); } } diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinJoinMultiplayerScreen.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinJoinMultiplayerScreen.java index 1c3ba06..32de526 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinJoinMultiplayerScreen.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinJoinMultiplayerScreen.java @@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.BufferUploader; @@ -45,11 +45,11 @@ public abstract class MixinJoinMultiplayerScreen extends Screen { @Inject(method = "init", at = @At("HEAD")) private void onInit(CallbackInfo info) { - if (!NCRConfig.showReloadButton()) + if (!NCRConfigLegacy.showReloadButton()) return; var button = new ImageButton(this.width/2 + 158, this.height - 52, 20, 20, 0, 0, 20, RELOAD_TEXTURE, - 64, 64, btn -> NCRConfig.loadConfig(), (btn, poseStack, i, j) -> + 64, 64, btn -> NCRConfigLegacy.loadConfig(), (btn, poseStack, i, j) -> this.renderTooltipNoGap(poseStack, this.minecraft.font.split(RELOAD_TOOLTIP, 250), i, j), Component.translatable("gui.nochatrepords.reload_config")); button.active = true; diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinLocalPlayer.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinLocalPlayer.java index 0d7e617..61fa8b2 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinLocalPlayer.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinLocalPlayer.java @@ -1,6 +1,6 @@ package com.aizistral.nochatreports.mixins.client; -import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; import com.aizistral.nochatreports.core.ServerSafetyState; import com.mojang.brigadier.ParseResults; diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinPlayerEntry.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinPlayerEntry.java index 6f47163..d5e9d6d 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinPlayerEntry.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinPlayerEntry.java @@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; import com.aizistral.nochatreports.core.ServerSafetyLevel; import com.aizistral.nochatreports.core.ServerSafetyState; import com.mojang.blaze3d.vertex.PoseStack; @@ -47,7 +47,7 @@ public class MixinPlayerEntry { @Inject(method = "<init>", at = @At("RETURN")) private void onConstructed(Minecraft minecraft, SocialInteractionsScreen socialInteractionsScreen, UUID uUID, String string, Supplier<ResourceLocation> supplier, boolean reportable, CallbackInfo info) { - if (NCRConfig.alwaysHideReportButton()) { + if (NCRConfigLegacy.alwaysHideReportButton()) { this.reportButton = new Button(0, 0, 20, 20, Component.empty(), button -> {}) { @Override public void render(PoseStack poseStack, int i, int j, float f) { diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinServerStatusPinger$1.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinServerStatusPinger$1.java index 3552c07..e568d70 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinServerStatusPinger$1.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinServerStatusPinger$1.java @@ -1,7 +1,7 @@ package com.aizistral.nochatreports.mixins.client; import com.aizistral.nochatreports.NoChatReports; -import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; import com.aizistral.nochatreports.core.ServerDataExtension; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket; @@ -31,7 +31,7 @@ public class MixinServerStatusPinger$1 { boolean preventsReports = ((ServerDataExtension) packet.getStatus()).preventsChatReports(); ((ServerDataExtension) this.val$data).setPreventsChatReports(preventsReports); - if (NCRConfig.enableDebugLog()) { + if (NCRConfigLegacy.enableDebugLog()) { NoChatReports.LOGGER.info("Received status response packet from server, preventsChatReports: {}", preventsReports); } diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinToastComponent.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinToastComponent.java index b233e19..e4a2197 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinToastComponent.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinToastComponent.java @@ -5,7 +5,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; import net.minecraft.client.gui.components.toasts.SystemToast; import net.minecraft.client.gui.components.toasts.SystemToast.SystemToastIds; @@ -17,7 +17,7 @@ public class MixinToastComponent { @Inject(method = "addToast", at = @At("HEAD"), cancellable = true) private void onAddToast(Toast toast, CallbackInfo info) { - if (NCRConfig.hideWarningToast()) + if (NCRConfigLegacy.hideWarningToast()) if (toast instanceof SystemToast sys && sys.getToken() == SystemToastIds.UNSECURE_SERVER_WARNING) { info.cancel(); } diff --git a/src/main/java/com/aizistral/nochatreports/mixins/common/MixinServerStatus.java b/src/main/java/com/aizistral/nochatreports/mixins/common/MixinServerStatus.java index 6379fa6..8a3901c 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/common/MixinServerStatus.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/common/MixinServerStatus.java @@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; import com.aizistral.nochatreports.core.ServerDataExtension; import net.minecraft.network.protocol.game.ClientboundServerDataPacket; @@ -34,7 +34,7 @@ public class MixinServerStatus implements ServerDataExtension { @Inject(method = "enforcesSecureChat", at = @At("HEAD"), cancellable = true) public void onSecureChatCheck(CallbackInfoReturnable<Boolean> info) { - if (NCRConfig.convertToGameMessage()) { + if (NCRConfigLegacy.convertToGameMessage()) { info.setReturnValue(true); } } diff --git a/src/main/java/com/aizistral/nochatreports/mixins/common/MixinServerStatusSerializer.java b/src/main/java/com/aizistral/nochatreports/mixins/common/MixinServerStatusSerializer.java index 87c252d..140c52c 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/common/MixinServerStatusSerializer.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/common/MixinServerStatusSerializer.java @@ -1,6 +1,6 @@ package com.aizistral.nochatreports.mixins.common; -import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; import com.aizistral.nochatreports.core.ServerDataExtension; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonElement; @@ -30,7 +30,7 @@ public class MixinServerStatusSerializer { at = @At("RETURN")) private void onSerialize(ServerStatus serverStatus, Type type, JsonSerializationContext context, CallbackInfoReturnable<JsonElement> info) { - if (!NCRConfig.addQueryData()) + if (!NCRConfigLegacy.addQueryData()) return; ((JsonObject) info.getReturnValue()).addProperty("preventsChatReports", true); diff --git a/src/main/java/com/aizistral/nochatreports/mixins/server/MixinServerGamePacketListenerImpl.java b/src/main/java/com/aizistral/nochatreports/mixins/server/MixinServerGamePacketListenerImpl.java index a6bb8e0..099264c 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/server/MixinServerGamePacketListenerImpl.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/server/MixinServerGamePacketListenerImpl.java @@ -19,7 +19,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; @Mixin(ServerGamePacketListenerImpl.class) public abstract class MixinServerGamePacketListenerImpl implements ServerPlayerConnection { @@ -35,7 +35,7 @@ public abstract class MixinServerGamePacketListenerImpl implements ServerPlayerC @Inject(method = "send(Lnet/minecraft/network/protocol/Packet;)V", at = @At("HEAD"), cancellable = true) private void onSend(Packet<?> packet, CallbackInfo info) { - if (NCRConfig.convertToGameMessage()) { + if (NCRConfigLegacy.convertToGameMessage()) { if (packet instanceof ClientboundPlayerChatHeaderPacket) { info.cancel(); } else if (packet instanceof ClientboundPlayerChatPacket chat) { @@ -57,7 +57,7 @@ public abstract class MixinServerGamePacketListenerImpl implements ServerPlayerC @Inject(method = "send(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketSendListener;)V", at = @At("HEAD"), cancellable = true) private void onSend(Packet<?> packet, @Nullable PacketSendListener packetSendListener, CallbackInfo info) { - if (NCRConfig.convertToGameMessage()) { + if (NCRConfigLegacy.convertToGameMessage()) { if (packet instanceof ClientboundPlayerChatHeaderPacket) { info.cancel(); } else if (packet instanceof ClientboundPlayerChatPacket chat && packetSendListener != null) { diff --git a/src/main/java/com/aizistral/nochatreports/mixins/server/MixinServerboundChatPacket.java b/src/main/java/com/aizistral/nochatreports/mixins/server/MixinServerboundChatPacket.java index 12d4a01..2b48bb9 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/server/MixinServerboundChatPacket.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/server/MixinServerboundChatPacket.java @@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; import java.util.UUID; @@ -20,7 +20,7 @@ public class MixinServerboundChatPacket { /** * @reason Strip signatures before relaying messages to other clients, if they arrive signed * This is important for mod to be able to operate in server-only mode without - * {@link NCRConfig#convertToGameMessage()} enabled. + * {@link NCRConfigLegacy#convertToGameMessage()} enabled. * @author Aizistral */ diff --git a/src/test/java/com/aizistral/nochatreports/debug/NoChatReportsDebug.java b/src/test/java/com/aizistral/nochatreports/debug/NoChatReportsDebug.java index 390316a..4922068 100644 --- a/src/test/java/com/aizistral/nochatreports/debug/NoChatReportsDebug.java +++ b/src/test/java/com/aizistral/nochatreports/debug/NoChatReportsDebug.java @@ -6,7 +6,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import com.aizistral.nochatreports.NoChatReports; -import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.config.NCRConfigLegacy; import com.aizistral.nochatreports.network.ServerChannelHandler; import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.BanDetails; |
