Sanity check for queued messages

This commit is contained in:
Nassim Jahnke 2022-05-21 11:00:55 +02:00
parent 4213c4cce5
commit 3529d6a229
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
2 changed files with 14 additions and 4 deletions

View File

@ -277,12 +277,13 @@ public final class EntityPackets extends EntityRewriter<Protocol1_19To1_18_2> {
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<QueuedMessagesStorage.Message> messages = messagesStorage.messages();
messagesStorage.setSent();
if (messages.isEmpty()) {
return;
}

View File

@ -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<Message> messages = new ArrayDeque<>();
private Queue<Message> messages = new ArrayDeque<>();
public Queue<Message> messages() {
public @Nullable Queue<Message> messages() {
return messages;
}
public boolean hasSent() {
return messages == null;
}
public void setSent() {
messages = null;
}
@Override
public boolean clearOnServerSwitch() {
return false;