summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/aizistral/nochatreports
diff options
context:
space:
mode:
authorMadis Otenurm2022-11-11 13:23:31 +0200
committerGitHub2022-11-11 12:23:31 +0100
commitc95c3281c5feb12de12d8d7828178f6ffc6be650 (patch)
treea1b0c6b2c33bb981d033e62665d89af777db5df4 /src/main/java/com/aizistral/nochatreports
parentfc480ee33130be8a0bcd8f7699edbe2a7b1fa5af (diff)
Resend message automatically when warning is skipped (#282)
* Resend message when warning is skipped * Fix the crash * Instance variable * Add signing actions * Hide rejection message when hide Co-authored-by: Aizistral <VictorShadow-Integral@yandex.ru>
Diffstat (limited to 'src/main/java/com/aizistral/nochatreports')
-rw-r--r--src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java13
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java19
2 files changed, 28 insertions, 4 deletions
diff --git a/src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java b/src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java
index 0e879b4..2af0846 100644
--- a/src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java
+++ b/src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java
@@ -29,6 +29,7 @@ import net.minecraft.network.chat.SignedMessageChain.Encoder;
@Environment(EnvType.CLIENT)
public final class ServerSafetyState {
private static final List<Runnable> resetActions = new ArrayList<>();
+ private static final List<Runnable> signingActions = new ArrayList<>();
private static final AtomicBoolean allowChatSigning = new AtomicBoolean(false);
private volatile static ServerSafetyLevel current = ServerSafetyLevel.UNDEFINED;
private volatile static ServerAddress lastServer = null;
@@ -52,9 +53,11 @@ public final class ServerSafetyState {
if (allow && connection.chatSession == null) {
Minecraft.getInstance().getProfileKeyPairManager().prepareKeyPair()
- .thenAcceptAsync(optional -> optional.ifPresent(profileKeyPair ->
- connection.setChatSession(LocalChatSession.create(profileKeyPair))),
- Minecraft.getInstance());
+ .thenAcceptAsync(optional -> optional.ifPresent(profileKeyPair -> {
+ connection.setChatSession(LocalChatSession.create(profileKeyPair));
+ signingActions.forEach(Runnable::run);
+ signingActions.clear();
+ }), Minecraft.getInstance());
}
}
}
@@ -86,6 +89,10 @@ public final class ServerSafetyState {
resetActions.add(action);
}
+ public static void scheduleSigningAction(Runnable action) {
+ signingActions.add(action);
+ }
+
public static void reset() {
lastServer = null;
current = ServerSafetyLevel.UNDEFINED;
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 0c926d3..54ac0c7 100644
--- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java
+++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java
@@ -4,6 +4,7 @@ import java.time.Instant;
import java.util.Base64;
import java.util.UUID;
+import net.minecraft.client.gui.screens.Screen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@@ -52,8 +53,24 @@ public class MixinChatListener {
if (UnsafeServerScreen.hideThisSession() || ServerSafetyState.allowChatSigning())
return;
- if(NCRConfig.getClient().skipSigningWarning()){
+ if (NCRConfig.getClient().skipSigningWarning()) {
+ ServerSafetyState.scheduleSigningAction(() -> {
+ var mc = Minecraft.getInstance();
+ var chatScr = mc.screen instanceof ChatScreen chat ? chat : null;
+
+ if (chatScr == null) {
+ chatScr = new ChatScreen("");
+ chatScr.init(mc, mc.getWindow().getGuiScaledWidth(), mc.getWindow().getGuiScaledHeight());
+ }
+ chatScr.handleChatInput(NCRConfig.getEncryption().getLastMessage(), false);
+ });
+
ServerSafetyState.setAllowChatSigning(true);
+
+ if (NCRConfig.getClient().hideSigningRequestMessage()) {
+ info.cancel();
+ }
+
return;
}