|
17 | 17 | */ |
18 | 18 | package com.viaversion.viabackwards.protocol.v1_21_9to1_21_7; |
19 | 19 |
|
| 20 | +import com.viaversion.nbt.tag.CompoundTag; |
20 | 21 | import com.viaversion.viabackwards.api.BackwardsProtocol; |
21 | 22 | import com.viaversion.viabackwards.api.data.BackwardsMappingData; |
22 | 23 | import com.viaversion.viabackwards.api.rewriters.SoundRewriter; |
|
32 | 33 | import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; |
33 | 34 | import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider; |
34 | 35 | import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider; |
| 36 | +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; |
35 | 37 | import com.viaversion.viaversion.api.type.Types; |
36 | 38 | import com.viaversion.viaversion.api.type.types.version.Types1_20_5; |
37 | 39 | import com.viaversion.viaversion.api.type.types.version.VersionedTypes; |
@@ -123,11 +125,58 @@ protected void registerPackets() { |
123 | 125 | } |
124 | 126 | }); |
125 | 127 |
|
126 | | - registerClientbound(ClientboundConfigurationPackets1_21_9.CODE_OF_CONDUCT, null, wrapper -> { |
127 | | - wrapper.cancel(); |
| 128 | + registerClientbound(ClientboundConfigurationPackets1_21_9.CODE_OF_CONDUCT, ClientboundConfigurationPackets1_21_6.SHOW_DIALOG, wrapper -> { |
| 129 | + if (wrapper.user().getProtocolInfo().protocolVersion().olderThanOrEqualTo(ProtocolVersion.v1_21_5)) { |
| 130 | + // TODO Remove once we implement dialogs during the configuration state in 1.21.6->1.21.5 |
| 131 | + wrapper.cancel(); |
128 | 132 |
|
129 | | - final PacketWrapper acceptPacket = wrapper.create(ServerboundConfigurationPackets1_21_9.ACCEPT_CODE_OF_CONDUCT); |
130 | | - acceptPacket.scheduleSendToServer(Protocol1_21_9To1_21_7.class); |
| 133 | + final PacketWrapper acceptPacket = wrapper.create(ServerboundConfigurationPackets1_21_9.ACCEPT_CODE_OF_CONDUCT); |
| 134 | + acceptPacket.sendToServer(Protocol1_21_9To1_21_7.class); |
| 135 | + return; |
| 136 | + } |
| 137 | + |
| 138 | + final String codeOfConduct = wrapper.read(Types.STRING); |
| 139 | + |
| 140 | + final CompoundTag tag = new CompoundTag(); |
| 141 | + tag.putString("type", "minecraft:confirmation"); |
| 142 | + tag.putString("title", "Server Code of Conduct"); |
| 143 | + |
| 144 | + final CompoundTag body = new CompoundTag(); |
| 145 | + body.putString("type", "minecraft:plain_message"); |
| 146 | + body.putString("contents", codeOfConduct); |
| 147 | + tag.put("body", body); |
| 148 | + |
| 149 | + final CompoundTag yes = new CompoundTag(); |
| 150 | + yes.putString("label", "Acknowledge"); |
| 151 | + |
| 152 | + final CompoundTag acceptAction = new CompoundTag(); |
| 153 | + acceptAction.putString("type", "minecraft:custom"); |
| 154 | + acceptAction.putString("id", "viabackwards:ack_code_of_conduct"); |
| 155 | + yes.put("action", acceptAction); |
| 156 | + tag.put("yes", yes); |
| 157 | + |
| 158 | + final CompoundTag no = new CompoundTag(); |
| 159 | + no.putString("label", "Disconnect"); |
| 160 | + |
| 161 | + final CompoundTag disconnectAction = new CompoundTag(); |
| 162 | + disconnectAction.putString("type", "minecraft:custom"); |
| 163 | + disconnectAction.putString("id", "viabackwards:disconnect"); |
| 164 | + no.put("action", disconnectAction); |
| 165 | + tag.put("no", no); |
| 166 | + |
| 167 | + wrapper.write(Types.TAG, tag); |
| 168 | + }); |
| 169 | + |
| 170 | + registerServerbound(ServerboundConfigurationPackets1_21_6.CUSTOM_CLICK_ACTION, wrapper -> { |
| 171 | + final String id = wrapper.passthrough(Types.STRING); |
| 172 | + if ("viabackwards:ack_code_of_conduct".equals(id)) { |
| 173 | + wrapper.cancel(); |
| 174 | + final PacketWrapper acceptPacket = wrapper.create(ServerboundConfigurationPackets1_21_9.ACCEPT_CODE_OF_CONDUCT); |
| 175 | + acceptPacket.sendToServer(Protocol1_21_9To1_21_7.class); |
| 176 | + } else if ("viabackwards:disconnect".equals(id)) { |
| 177 | + wrapper.cancel(); |
| 178 | + wrapper.user().disconnect("Disconnected by user"); |
| 179 | + } |
131 | 180 | }); |
132 | 181 | } |
133 | 182 |
|
|
0 commit comments