ServerboundCommandSuggestionPacket .java

net.minecraft.network.protocol.game.ServerboundCommandSuggestionPacket (record): members: command, CHAT_ONLY_STREAM_CODEC, createStreamCodec, handle, type.

net.minecraft.network.protocol.gamerecord48 linescommon1.9 KB

Implements

API Surface (4)

ServerboundCommandSuggestionPacket decode(final ByteBuf input)
void encode(final ByteBuf output, final ServerboundCommandSuggestionPacket packet)
PacketType<ServerboundCommandSuggestionPacket> type()
void handle(final ServerGamePacketListener listener)

Fields & Constants (2)

STREAM_CODEC
CHAT_ONLY_STREAM_CODEC

Same Package (197)

Code Graph: Dependencies (6)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

ServerboundCommandSuggestionPacket.java48 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.network.protocol.game;
2
3
import io.netty.buffer.ByteBuf;
4
import io.netty.handler.codec.DecoderException;
5
import net.minecraft.network.SkipPacketDecoderException;
6
import net.minecraft.network.codec.ByteBufCodecs;
7
import net.minecraft.network.codec.StreamCodec;
8
import net.minecraft.network.protocol.Packet;
9
import net.minecraft.network.protocol.PacketType;
10
11
public record ServerboundCommandSuggestionPacket(int id, String command) implements Packet<ServerGamePacketListener> {
12
	public static final StreamCodec<ByteBuf, ServerboundCommandSuggestionPacket> STREAM_CODEC = createStreamCodec(32500);
13
	public static final StreamCodec<ByteBuf, ServerboundCommandSuggestionPacket> CHAT_ONLY_STREAM_CODEC = new StreamCodec<ByteBuf, ServerboundCommandSuggestionPacket>() {
14
		private final StreamCodec<ByteBuf, ServerboundCommandSuggestionPacket> downstream = ServerboundCommandSuggestionPacket.createStreamCodec(256);
15
16
		public ServerboundCommandSuggestionPacket decode(final ByteBuf input) {
17
			try {
18
				return this.downstream.decode(input);
19
			} catch (DecoderException e) {
20
				throw new SkipPacketDecoderException(e);
21
			}
22
		}
23
24
		public void encode(final ByteBuf output, final ServerboundCommandSuggestionPacket packet) {
25
			ServerboundCommandSuggestionPacket.STREAM_CODEC.encode(output, packet);
26
		}
27
	};
28
29
	private static StreamCodec<ByteBuf, ServerboundCommandSuggestionPacket> createStreamCodec(final int maxLength) {
30
		return StreamCodec.composite(
31
			ByteBufCodecs.VAR_INT,
32
			ServerboundCommandSuggestionPacket::id,
33
			ByteBufCodecs.stringUtf8(maxLength),
34
			ServerboundCommandSuggestionPacket::command,
35
			ServerboundCommandSuggestionPacket::new
36
		);
37
	}
38
39
	@Override
40
	public PacketType<ServerboundCommandSuggestionPacket> type() {
41
		return GamePacketTypes.SERVERBOUND_COMMAND_SUGGESTION;
42
	}
43
44
	public void handle(final ServerGamePacketListener listener) {
45
		listener.handleCustomCommandSuggestions(this);
46
	}
47
}
48

Decompiled Minecraft 26.3 source of ServerboundCommandSuggestionPacket (net/minecraft/network/protocol/game/ServerboundCommandSuggestionPacket.java) with Mojang official mappings, stored verbatim on the site.