From 5d424ef8b3eefdd26698ed37cc21073ccbd15a5b Mon Sep 17 00:00:00 2001 From: Aizistral Date: Sun, 25 Sep 2022 20:11:05 +0200 Subject: Final adjustments to encryption --- .../nochatreports/config/NCRConfigEncryption.java | 10 ++++++-- .../nochatreports/gui/EncryptionWarningScreen.java | 2 +- .../mixins/client/MixinChatScreen.java | 27 ++++++++++++---------- 3 files changed, 24 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/main/java/com/aizistral/nochatreports/config/NCRConfigEncryption.java b/src/main/java/com/aizistral/nochatreports/config/NCRConfigEncryption.java index 0dc0e11..2144c1a 100644 --- a/src/main/java/com/aizistral/nochatreports/config/NCRConfigEncryption.java +++ b/src/main/java/com/aizistral/nochatreports/config/NCRConfigEncryption.java @@ -16,10 +16,12 @@ import net.minecraft.util.StringUtil; public class NCRConfigEncryption extends JSONConfig { protected static final String FILE_NAME = "NoChatReports/NCR-Encryption.json"; - protected boolean skipWarning = false, enableEncryption = false, encryptPublic = true; + protected boolean skipWarning = false, enableEncryption = false, encryptPublic = true, + showEncryptionButton = true; protected String encryptionKey = Encryption.AES_CFB8.getDefaultKey(), encryptionPassphrase = "", algorithmName = Encryption.AES_CFB8.getName(); - protected List encryptableCommands = List.of("msg:1", "w:1", "whisper:1", "tell:1", "r:0", "dm:1", "me:0"); + protected List encryptableCommands = List.of("msg:1", "w:1", "whisper:1", "tell:1", "r:0", "dm:1", + "me:0", "m:1", "t:1", "pm:1", "emsg:1", "epm:1", "etell:1", "ewhisper:1"); private transient Encryption algorithm; private transient boolean isValid = false; private transient String lastMessage = "???"; @@ -112,6 +114,10 @@ public class NCRConfigEncryption extends JSONConfig { return this.isEnabledAndValid() && this.getEncryptionStartIndex(message) != -1; } + public boolean showEncryptionButton() { + return this.showEncryptionButton; + } + public int getEncryptionStartIndex(String message) { if (!message.startsWith("/")) return this.encryptPublic ? 0 : -1; diff --git a/src/main/java/com/aizistral/nochatreports/gui/EncryptionWarningScreen.java b/src/main/java/com/aizistral/nochatreports/gui/EncryptionWarningScreen.java index eb6e313..349c52d 100644 --- a/src/main/java/com/aizistral/nochatreports/gui/EncryptionWarningScreen.java +++ b/src/main/java/com/aizistral/nochatreports/gui/EncryptionWarningScreen.java @@ -25,7 +25,7 @@ public class EncryptionWarningScreen extends WarningScreen { private static final Component CONTENT = Component.translatable("gui.nochatreports.encryption_warning.contents"); private static final Component CHECK = Component.translatable("gui.nochatreports.encryption_warning.check"); private static final Component NARRATION = TITLE.copy().append("\n").append(CONTENT); - private static final String WIKI_LINK = "https://github.com/Aizistral-Studios/No-Chat-Reports/wiki/To-Encrypt-or-Not-To-Encrypt"; + private static final String WIKI_LINK = "https://github.com/Aizistral-Studios/No-Chat-Reports/wiki/To-Encrypt-or-Not-to-Encrypt"; private static boolean sessionSeen = false; private final Screen previous; 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 eb43b4a..ac3acb4 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatScreen.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatScreen.java @@ -71,25 +71,28 @@ public abstract class MixinChatScreen extends Screen { @Inject(method = "init", at = @At("HEAD")) private void onInit(CallbackInfo info) { - if (!NCRConfig.getClient().showServerSafety() || !NCRConfig.getClient().enableMod()) - return; + if (NCRConfig.getClient().showServerSafety() && NCRConfig.getClient().enableMod()) { + ServerSafetyLevel trust = this.minecraft.isLocalServer() ? ServerSafetyLevel.SECURE : ServerSafetyState.getCurrent(); - ServerSafetyLevel trust = this.minecraft.isLocalServer() ? ServerSafetyLevel.SECURE : ServerSafetyState.getCurrent(); + var button = new ImageButton(this.width - 23, this.height - 37, 20, 20, this.getXOffset(trust), + 0, 20, CHAT_STATUS_ICONS, 64, 64, btn -> {}, (btn, poseStack, i, j) -> + this.renderTooltipNoGap(poseStack, this.minecraft.font.split(trust.getTooltip(), 250), i, j), + Component.empty()); + button.active = false; + button.visible = true; - var button = new ImageButton(this.width - 23, this.height - 37, 20, 20, this.getXOffset(trust), - 0, 20, CHAT_STATUS_ICONS, 64, 64, btn -> {}, (btn, poseStack, i, j) -> - this.renderTooltipNoGap(poseStack, this.minecraft.font.split(trust.getTooltip(), 250), i, j), - Component.empty()); - button.active = false; - button.visible = true; + this.addRenderableOnly(button); + } - this.addRenderableOnly(button); + if (!NCRConfig.getEncryption().showEncryptionButton()) + return; int xStart = !NCRConfig.getEncryption().isValid() ? 40 : (NCRConfig.getEncryption().isEnabled() ? 0 : 20); - button = new ImageButton(this.width - 48, this.height - 37, 20, 20, xStart, + var button = new ImageButton(this.width - 48, this.height - 37, 20, 20, xStart, 0, 20, ENCRYPTION_BUTTON, 64, 64, btn -> { - if (!EncryptionWarningScreen.seenOnThisSession() && !NCRConfig.getEncryption().isWarningDisabled()) { + if (!EncryptionWarningScreen.seenOnThisSession() && !NCRConfig.getEncryption().isWarningDisabled() + && !NCRConfig.getEncryption().isEnabled()) { Minecraft.getInstance().setScreen(new EncryptionWarningScreen(this)); } else if (NCRConfig.getEncryption().isValid()) { NCRConfig.getEncryption().toggleEncryption(); -- cgit v1.2.3