From 3529d6a229a4600926c51ccdd9fed26f4bcbb16c Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 21 May 2022 11:00:55 +0200 Subject: [PATCH] Sanity check for queued messages --- .../protocol1_19to1_18_2/packets/EntityPackets.java | 5 +++-- .../storage/QueuedMessagesStorage.java | 13 +++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java index b49bfd01c..28af70c09 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java @@ -277,12 +277,13 @@ public final class EntityPackets extends EntityRewriter { displayPreviewPacket.write(Type.BOOLEAN, false); displayPreviewPacket.send(Protocol1_19To1_18_2.class); - final QueuedMessagesStorage messagesStorage = wrapper.user().remove(QueuedMessagesStorage.class); - if (messagesStorage == null) { + final QueuedMessagesStorage messagesStorage = wrapper.user().get(QueuedMessagesStorage.class); + if (messagesStorage.hasSent()) { return; } final Queue messages = messagesStorage.messages(); + messagesStorage.setSent(); if (messages.isEmpty()) { return; } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/storage/QueuedMessagesStorage.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/storage/QueuedMessagesStorage.java index 728b824d5..246db9501 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/storage/QueuedMessagesStorage.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/storage/QueuedMessagesStorage.java @@ -19,18 +19,27 @@ package com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage; import com.google.gson.JsonElement; import com.viaversion.viaversion.api.connection.StorableObject; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.ArrayDeque; import java.util.Queue; public final class QueuedMessagesStorage implements StorableObject { - private final Queue messages = new ArrayDeque<>(); + private Queue messages = new ArrayDeque<>(); - public Queue messages() { + public @Nullable Queue messages() { return messages; } + public boolean hasSent() { + return messages == null; + } + + public void setSent() { + messages = null; + } + @Override public boolean clearOnServerSwitch() { return false;