Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-09-08 13:52:50 +02:00
Send last tags when re-entering config phase
Dieser Commit ist enthalten in:
Ursprung
d600b0cbe1
Commit
cbf8b8f401
@ -48,10 +48,10 @@ import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.rewriter.EntityP
|
|||||||
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.ConfigurationState;
|
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.ConfigurationState;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.ConfigurationState.BridgePhase;
|
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.ConfigurationState.BridgePhase;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.LastResourcePack;
|
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.LastResourcePack;
|
||||||
|
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.LastTags;
|
||||||
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPackets1_19_4, ClientboundPackets1_20_2, ServerboundPackets1_19_4, ServerboundPackets1_20_2> {
|
public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPackets1_19_4, ClientboundPackets1_20_2, ServerboundPackets1_19_4, ServerboundPackets1_20_2> {
|
||||||
|
|
||||||
@ -95,6 +95,10 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPack
|
|||||||
wrapper.user().put(new LastResourcePack(url, hash, required, prompt));
|
wrapper.user().put(new LastResourcePack(url, hash, required, prompt));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
registerClientbound(ClientboundPackets1_19_4.TAGS, wrapper -> wrapper.user().put(new LastTags(wrapper)));
|
||||||
|
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.UPDATE_TAGS.getId(), ClientboundConfigurationPackets1_20_2.UPDATE_TAGS.getId(),
|
||||||
|
wrapper -> wrapper.user().put(new LastTags(wrapper)));
|
||||||
|
|
||||||
registerClientbound(ClientboundPackets1_19_4.DISPLAY_SCOREBOARD, wrapper -> {
|
registerClientbound(ClientboundPackets1_19_4.DISPLAY_SCOREBOARD, wrapper -> {
|
||||||
final byte slot = wrapper.read(Type.BYTE);
|
final byte slot = wrapper.read(Type.BYTE);
|
||||||
wrapper.write(Type.VAR_INT, (int) slot);
|
wrapper.write(Type.VAR_INT, (int) slot);
|
||||||
@ -220,7 +224,13 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPack
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final int unmappedId = packetWrapper.getId();
|
||||||
if (phase == BridgePhase.PROFILE_SENT || phase == BridgePhase.REENTERING_CONFIGURATION) {
|
if (phase == BridgePhase.PROFILE_SENT || phase == BridgePhase.REENTERING_CONFIGURATION) {
|
||||||
|
if (unmappedId == ClientboundPackets1_19_4.TAGS.getId()) {
|
||||||
|
// Don't re-send old tags during config phase
|
||||||
|
packetWrapper.user().remove(LastTags.class);
|
||||||
|
}
|
||||||
|
|
||||||
// Queue packets sent by the server while we wait for the client to transition to the configuration state
|
// Queue packets sent by the server while we wait for the client to transition to the configuration state
|
||||||
configurationBridge.addPacketToQueue(packetWrapper, true);
|
configurationBridge.addPacketToQueue(packetWrapper, true);
|
||||||
throw CancelException.generate();
|
throw CancelException.generate();
|
||||||
@ -228,7 +238,6 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPack
|
|||||||
|
|
||||||
if (packetWrapper.getPacketType() == null || packetWrapper.getPacketType().state() != State.CONFIGURATION) {
|
if (packetWrapper.getPacketType() == null || packetWrapper.getPacketType().state() != State.CONFIGURATION) {
|
||||||
// Map some of them to their configuration state counterparts, but make sure to let join game through
|
// Map some of them to their configuration state counterparts, but make sure to let join game through
|
||||||
final int unmappedId = packetWrapper.getId();
|
|
||||||
if (unmappedId == ClientboundPackets1_19_4.JOIN_GAME.getId()) {
|
if (unmappedId == ClientboundPackets1_19_4.JOIN_GAME.getId()) {
|
||||||
super.transform(direction, State.PLAY, packetWrapper);
|
super.transform(direction, State.PLAY, packetWrapper);
|
||||||
return;
|
return;
|
||||||
@ -287,6 +296,12 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPack
|
|||||||
enableFeaturesPacket.write(Type.STRING, "minecraft:vanilla");
|
enableFeaturesPacket.write(Type.STRING, "minecraft:vanilla");
|
||||||
enableFeaturesPacket.send(Protocol1_20_2To1_20.class);
|
enableFeaturesPacket.send(Protocol1_20_2To1_20.class);
|
||||||
|
|
||||||
|
final LastTags lastTags = connection.get(LastTags.class);
|
||||||
|
if (lastTags != null) {
|
||||||
|
// The server might still follow up with a tags packet, but we wouldn't know
|
||||||
|
lastTags.sendLastTags(connection);
|
||||||
|
}
|
||||||
|
|
||||||
if (lastResourcePack != null) {
|
if (lastResourcePack != null) {
|
||||||
// The client for some reason drops the resource pack when reentering the configuration state
|
// The client for some reason drops the resource pack when reentering the configuration state
|
||||||
final PacketWrapper resourcePackPacket = PacketWrapper.create(ClientboundConfigurationPackets1_20_2.RESOURCE_PACK, connection);
|
final PacketWrapper resourcePackPacket = PacketWrapper.create(ClientboundConfigurationPackets1_20_2.RESOURCE_PACK, connection);
|
||||||
|
@ -50,4 +50,9 @@ public final class LastResourcePack implements StorableObject {
|
|||||||
public @Nullable JsonElement prompt() {
|
public @Nullable JsonElement prompt() {
|
||||||
return prompt;
|
return prompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean clearOnServerSwitch() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2023 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_20_2to1_20.storage;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||||
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.Protocol1_20_2To1_20;
|
||||||
|
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundConfigurationPackets1_20_2;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class LastTags implements StorableObject {
|
||||||
|
|
||||||
|
private final List<RegistryTags> registryTags = new ArrayList<>();
|
||||||
|
|
||||||
|
public LastTags(final PacketWrapper wrapper) throws Exception {
|
||||||
|
final int length = wrapper.passthrough(Type.VAR_INT);
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
final List<Tag> tags = new ArrayList<>();
|
||||||
|
final String registryKey = wrapper.passthrough(Type.STRING);
|
||||||
|
final int tagsSize = wrapper.passthrough(Type.VAR_INT);
|
||||||
|
for (int j = 0; j < tagsSize; j++) {
|
||||||
|
final String key = wrapper.passthrough(Type.STRING);
|
||||||
|
final int[] ids = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
|
||||||
|
tags.add(new Tag(key, ids));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.registryTags.add(new RegistryTags(registryKey, tags));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendLastTags(final UserConnection connection) throws Exception {
|
||||||
|
if (registryTags.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final PacketWrapper packet = PacketWrapper.create(ClientboundConfigurationPackets1_20_2.UPDATE_TAGS, connection);
|
||||||
|
packet.write(Type.VAR_INT, registryTags.size());
|
||||||
|
for (final RegistryTags registryTag : registryTags) {
|
||||||
|
packet.write(Type.STRING, registryTag.registryKey);
|
||||||
|
packet.write(Type.VAR_INT, registryTag.tags.size());
|
||||||
|
for (final Tag tag : registryTag.tags) {
|
||||||
|
packet.write(Type.STRING, tag.key);
|
||||||
|
packet.write(Type.VAR_INT_ARRAY_PRIMITIVE, Arrays.copyOf(tag.ids, tag.ids.length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
packet.send(Protocol1_20_2To1_20.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class RegistryTags {
|
||||||
|
private final String registryKey;
|
||||||
|
private final List<Tag> tags;
|
||||||
|
|
||||||
|
private RegistryTags(final String registryKey, final List<Tag> tags) {
|
||||||
|
this.registryKey = registryKey;
|
||||||
|
this.tags = tags;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class Tag {
|
||||||
|
private final String key;
|
||||||
|
private final int[] ids;
|
||||||
|
|
||||||
|
private Tag(final String key, final int[] ids) {
|
||||||
|
this.key = key;
|
||||||
|
this.ids = ids;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren