Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Queue up messages before the chat type registry has been sent
Fixes #2898
Dieser Commit ist enthalten in:
Ursprung
3d3e09977c
Commit
4213c4cce5
@ -40,6 +40,7 @@ import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.packets.Inventor
|
||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.packets.WorldPackets;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage.DimensionRegistryStorage;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage.NonceStorage;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage.QueuedMessagesStorage;
|
||||
import com.viaversion.viaversion.rewriter.CommandRewriter;
|
||||
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
@ -169,6 +170,15 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol<ClientboundPack
|
||||
map(Type.COMPONENT); // Message
|
||||
map(Type.BYTE, Type.VAR_INT); // Type
|
||||
read(Type.UUID); // Sender
|
||||
handler(wrapper -> {
|
||||
// We can't send chat messages before the chat type registry has been sent in the join packet
|
||||
final QueuedMessagesStorage messagesStorage = wrapper.user().get(QueuedMessagesStorage.class);
|
||||
if (messagesStorage != null) {
|
||||
final QueuedMessagesStorage.Message message = new QueuedMessagesStorage.Message(wrapper.get(Type.COMPONENT, 0), wrapper.get(Type.VAR_INT, 0));
|
||||
messagesStorage.messages().add(message);
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -285,6 +295,9 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol<ClientboundPack
|
||||
|
||||
@Override
|
||||
public void init(final UserConnection user) {
|
||||
if (!user.has(QueuedMessagesStorage.class)) {
|
||||
user.put(new QueuedMessagesStorage());
|
||||
}
|
||||
if (!user.has(DimensionRegistryStorage.class)) {
|
||||
user.put(new DimensionRegistryStorage());
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPacke
|
||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ClientboundPackets1_19;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.Protocol1_19To1_18_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage.DimensionRegistryStorage;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage.QueuedMessagesStorage;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -44,6 +45,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
|
||||
public final class EntityPackets extends EntityRewriter<Protocol1_19To1_18_2> {
|
||||
|
||||
@ -274,6 +276,28 @@ public final class EntityPackets extends EntityRewriter<Protocol1_19To1_18_2> {
|
||||
final PacketWrapper displayPreviewPacket = wrapper.create(ClientboundPackets1_19.SET_DISPLAY_CHAT_PREVIEW);
|
||||
displayPreviewPacket.write(Type.BOOLEAN, false);
|
||||
displayPreviewPacket.send(Protocol1_19To1_18_2.class);
|
||||
|
||||
final QueuedMessagesStorage messagesStorage = wrapper.user().remove(QueuedMessagesStorage.class);
|
||||
if (messagesStorage == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Queue<QueuedMessagesStorage.Message> messages = messagesStorage.messages();
|
||||
if (messages.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Manually send off and send queued messages
|
||||
wrapper.send(Protocol1_19To1_18_2.class);
|
||||
wrapper.cancel();
|
||||
|
||||
QueuedMessagesStorage.Message message;
|
||||
while ((message = messages.poll()) != null) {
|
||||
final PacketWrapper chatPacket = wrapper.create(ClientboundPackets1_19.SYSTEM_CHAT);
|
||||
chatPacket.write(Type.COMPONENT, message.content());
|
||||
chatPacket.write(Type.VAR_INT, message.chatType());
|
||||
chatPacket.send(Protocol1_19To1_18_2.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Queue;
|
||||
|
||||
public final class QueuedMessagesStorage implements StorableObject {
|
||||
|
||||
private final Queue<Message> messages = new ArrayDeque<>();
|
||||
|
||||
public Queue<Message> messages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearOnServerSwitch() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static final class Message {
|
||||
private final JsonElement content;
|
||||
private final int chatType;
|
||||
|
||||
public Message(final JsonElement content, final int chatType) {
|
||||
this.content = content;
|
||||
this.chatType = chatType;
|
||||
}
|
||||
|
||||
public JsonElement content() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public int chatType() {
|
||||
return chatType;
|
||||
}
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren