Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-19 14:30:16 +01:00
No need to queue messages anymore
The client now uses the main registry instead of the level registry
Dieser Commit ist enthalten in:
Ursprung
b4ecba8382
Commit
1308dcb8dd
@ -48,9 +48,12 @@ import net.md_5.bungee.protocol.packet.PluginMessage;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.util.ArrayList;
|
||||||
import java.util.*;
|
import java.util.Collection;
|
||||||
import java.util.stream.Collectors;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class BungeeServerHandler implements Listener {
|
public class BungeeServerHandler implements Listener {
|
||||||
private static Method getHandshake;
|
private static Method getHandshake;
|
||||||
|
@ -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.packets.WorldPackets;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage.DimensionRegistryStorage;
|
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.NonceStorage;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage.QueuedMessagesStorage;
|
|
||||||
import com.viaversion.viaversion.rewriter.CommandRewriter;
|
import com.viaversion.viaversion.rewriter.CommandRewriter;
|
||||||
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
||||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||||
@ -170,15 +169,6 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol<ClientboundPack
|
|||||||
map(Type.COMPONENT); // Message
|
map(Type.COMPONENT); // Message
|
||||||
map(Type.BYTE, Type.VAR_INT); // Type
|
map(Type.BYTE, Type.VAR_INT); // Type
|
||||||
read(Type.UUID); // Sender
|
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.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<ClientboundPack
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(final UserConnection user) {
|
public void init(final UserConnection user) {
|
||||||
if (!user.has(QueuedMessagesStorage.class)) {
|
|
||||||
user.put(new QueuedMessagesStorage());
|
|
||||||
}
|
|
||||||
if (!user.has(DimensionRegistryStorage.class)) {
|
if (!user.has(DimensionRegistryStorage.class)) {
|
||||||
user.put(new DimensionRegistryStorage());
|
user.put(new DimensionRegistryStorage());
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,6 @@ 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.ClientboundPackets1_19;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.Protocol1_19To1_18_2;
|
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.DimensionRegistryStorage;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage.QueuedMessagesStorage;
|
|
||||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -45,7 +44,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Queue;
|
|
||||||
|
|
||||||
public final class EntityPackets extends EntityRewriter<Protocol1_19To1_18_2> {
|
public final class EntityPackets extends EntityRewriter<Protocol1_19To1_18_2> {
|
||||||
|
|
||||||
@ -280,29 +278,6 @@ public final class EntityPackets extends EntityRewriter<Protocol1_19To1_18_2> {
|
|||||||
final PacketWrapper displayPreviewPacket = wrapper.create(ClientboundPackets1_19.SET_DISPLAY_CHAT_PREVIEW);
|
final PacketWrapper displayPreviewPacket = wrapper.create(ClientboundPackets1_19.SET_DISPLAY_CHAT_PREVIEW);
|
||||||
displayPreviewPacket.write(Type.BOOLEAN, false);
|
displayPreviewPacket.write(Type.BOOLEAN, false);
|
||||||
displayPreviewPacket.send(Protocol1_19To1_18_2.class);
|
displayPreviewPacket.send(Protocol1_19To1_18_2.class);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -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 <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 org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
|
||||||
import java.util.Queue;
|
|
||||||
|
|
||||||
public final class QueuedMessagesStorage implements StorableObject {
|
|
||||||
|
|
||||||
private Queue<Message> messages = new ArrayDeque<>();
|
|
||||||
|
|
||||||
public @Nullable Queue<Message> 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren