From 1308dcb8dd2a10ea271e234f0dc85a9cac9ddc2a Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Mon, 23 May 2022 18:24:32 +0200 Subject: [PATCH] No need to queue messages anymore The client now uses the main registry instead of the level registry --- .../bungee/handlers/BungeeServerHandler.java | 9 ++- .../Protocol1_19To1_18_2.java | 13 ---- .../packets/EntityPackets.java | 25 ------- .../storage/QueuedMessagesStorage.java | 65 ------------------- 4 files changed, 6 insertions(+), 106 deletions(-) delete mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/storage/QueuedMessagesStorage.java diff --git a/bungee/src/main/java/com/viaversion/viaversion/bungee/handlers/BungeeServerHandler.java b/bungee/src/main/java/com/viaversion/viaversion/bungee/handlers/BungeeServerHandler.java index 5250b8082..9e58bf241 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/bungee/handlers/BungeeServerHandler.java +++ b/bungee/src/main/java/com/viaversion/viaversion/bungee/handlers/BungeeServerHandler.java @@ -48,9 +48,12 @@ import net.md_5.bungee.protocol.packet.PluginMessage; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.stream.Collectors; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.UUID; public class BungeeServerHandler implements Listener { private static Method getHandshake; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java index 8f31c6734..6c71c23ad 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java @@ -40,7 +40,6 @@ 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; @@ -170,15 +169,6 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol { - // 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.hasSent()) { - final QueuedMessagesStorage.Message message = new QueuedMessagesStorage.Message(wrapper.get(Type.COMPONENT, 0), wrapper.get(Type.VAR_INT, 0)); - messagesStorage.messages().add(message); - wrapper.cancel(); - } - }); } }); @@ -295,9 +285,6 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol { @@ -280,29 +278,6 @@ public final class EntityPackets extends EntityRewriter { 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().get(QueuedMessagesStorage.class); - if (messagesStorage.hasSent()) { - return; - } - - final Queue messages = messagesStorage.messages(); - messagesStorage.setSent(); - 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); - } }); } }); 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 deleted file mode 100644 index 246db9501..000000000 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/storage/QueuedMessagesStorage.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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 . - */ -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 Queue messages = new ArrayDeque<>(); - - public @Nullable Queue messages() { - return messages; - } - - public boolean hasSent() { - return messages == null; - } - - public void setSent() { - messages = null; - } - - @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; - } - } -}