summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorAizistral2022-07-30 13:26:00 +0200
committerGitHub2022-07-30 13:26:00 +0200
commitce0da5097604507178f0dd80bf20c0b2bb7be10c (patch)
treecc12c76d4a62976059a50f74175cbdfd2fc6379c /src/main
parentcf19f812fe32aa3f0206001d7af8fe87afd90c4e (diff)
parent8f3af2d8535b89b8537ebdeb18ef4c54aac1250c (diff)
Merge pull request #110 from Madis0/options-2
More options
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/aizistral/nochatreports/core/NoReportsConfig.java45
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java31
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTag.java4
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinToastComponent.java2
4 files changed, 66 insertions, 16 deletions
diff --git a/src/main/java/com/aizistral/nochatreports/core/NoReportsConfig.java b/src/main/java/com/aizistral/nochatreports/core/NoReportsConfig.java
index 3aaad30..20491e5 100644
--- a/src/main/java/com/aizistral/nochatreports/core/NoReportsConfig.java
+++ b/src/main/java/com/aizistral/nochatreports/core/NoReportsConfig.java
@@ -40,7 +40,8 @@ public class NoReportsConfig {
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
private static NoReportsConfig INSTANCE;
private boolean demandOnClient = true, demandOnServer = false, enableDebugLog = false,
- convertToGameMessage = false, showServerSafety = true, suppressVanillaSecurityNotices = true,
+ convertToGameMessage = false, showServerSafety = true, hideRedChatIndicators = true,
+ hideYellowChatIndicators = true, hideGrayChatIndicators = true, hideWarningToast = true,
alwaysHideReportButton = false, versionEasterEgg = true, disableTelemetry = true,
showReloadButton = true;
private List<String> whitelistedServers;
@@ -177,17 +178,51 @@ public class NoReportsConfig {
}
/**
- * @return True if vanilla's Chat Trust Status indicators and "Chat messages can't be verified"
- * toast should be removed.<br><br>
+ * @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 suppressVanillaSecurityNotices() {
- return getInstance().suppressVanillaSecurityNotices;
+ public static boolean hideWarningToast() {
+ return getInstance().hideWarningToast;
}
/**
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 47e16bf..274e67e 100644
--- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java
+++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java
@@ -2,9 +2,10 @@ package com.aizistral.nochatreports.mixins.client;
import java.time.Instant;
import java.util.Base64;
+import java.util.UUID;
import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.Overwrite;
+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;
@@ -13,35 +14,49 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.aizistral.nochatreports.NoChatReports;
import com.aizistral.nochatreports.core.NoReportsConfig;
-import net.minecraft.client.gui.components.toasts.SystemToast;
import net.minecraft.client.multiplayer.PlayerInfo;
import net.minecraft.client.multiplayer.chat.ChatListener;
import net.minecraft.client.multiplayer.chat.ChatTrustLevel;
-import net.minecraft.network.chat.ChatSender;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.PlayerChatMessage;
@Mixin(ChatListener.class)
public class MixinChatListener {
+ @Shadow
+ private boolean isSenderLocalPlayer(UUID uuid) {
+ throw new IllegalStateException("@Shadow transformation failed. Should never happen.");
+ }
+
/**
* @reason Removes "Not Secure" and "Modified" statuses of chat messages. They ultimately
- * server no purpose but to annoy the user and scare them away from servers that actually
+ * serve no purpose but to annoy the user and scare them away from servers that actually
* try to protect them by stripping message signatures.
* @author Aizistral
*/
@Inject(method = "evaluateTrustLevel", at = @At("HEAD"), cancellable = true)
- private void onEvaluateTrustLevel(PlayerChatMessage playerChatMessage,
- Component component, PlayerInfo playerInfo, Instant instant, CallbackInfoReturnable<ChatTrustLevel> info) {
- if (NoReportsConfig.suppressVanillaSecurityNotices()) {
+ private void onEvaluateTrustLevel(PlayerChatMessage playerChatMessage, Component component, PlayerInfo playerInfo,
+ Instant instant, CallbackInfoReturnable<ChatTrustLevel> info) {
+
+ if (this.isSenderLocalPlayer(playerChatMessage.signer().profileId())) {
info.setReturnValue(ChatTrustLevel.SECURE);
+ } else {
+ var evaluate = ChatTrustLevel.evaluate(playerChatMessage, component, playerInfo, instant);
+
+ if ((evaluate == ChatTrustLevel.NOT_SECURE || evaluate == ChatTrustLevel.BROKEN_CHAIN)
+ && NoReportsConfig.hideRedChatIndicators()) {
+ info.setReturnValue(ChatTrustLevel.SECURE);
+ } else if ((evaluate == ChatTrustLevel.FILTERED || evaluate == ChatTrustLevel.MODIFIED)
+ && NoReportsConfig.hideYellowChatIndicators()) {
+ info.setReturnValue(ChatTrustLevel.SECURE);
+ }
}
// Debug never dies
if (NoReportsConfig.isDebugLogEnabled()) {
NoChatReports.LOGGER.info("Received message: {}, from: {}, signature: {}",
- Component.Serializer.toStableJson(playerChatMessage.signedContent().decorated()),
+ Component.Serializer.toStableJson(playerChatMessage.serverContent()),
playerChatMessage.signer().profileId(),
Base64.getEncoder().encodeToString(playerChatMessage.headerSignature().bytes()));
}
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 cac9460..1edcf7e 100644
--- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTag.java
+++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTag.java
@@ -14,14 +14,14 @@ public class MixinGuiMessageTag {
/**
* @reason Remove gray bar as indication besides system messages, if mod is configured
- * respectively. The mod converts all player messages to system messages by default when
+ * respectively. The mod can convert all player messages to system messages when
* installed on server, so we don't need that most of the time.
* @author Aizistral
*/
@Inject(method = "system", at = @At("HEAD"), cancellable = true)
private static void onSystem(CallbackInfoReturnable<GuiMessageTag> info) {
- if (NoReportsConfig.suppressVanillaSecurityNotices()) {
+ if (NoReportsConfig.hideGrayChatIndicators()) {
info.setReturnValue(null);
}
}
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 239f5df..36cfe7e 100644
--- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinToastComponent.java
+++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinToastComponent.java
@@ -17,7 +17,7 @@ public class MixinToastComponent {
@Inject(method = "addToast", at = @At("HEAD"), cancellable = true)
private void onAddToast(Toast toast, CallbackInfo info) {
- if (NoReportsConfig.suppressVanillaSecurityNotices())
+ if (NoReportsConfig.hideWarningToast())
if (toast instanceof SystemToast sys && sys.getToken() == SystemToastIds.UNSECURE_SERVER_WARNING) {
info.cancel();
}