Remove IOExceptions from packet handling (#783)

This commit is contained in:
Alex 2024-02-28 05:11:53 +01:00 committed by GitHub
parent 4f2e7a5b55
commit f2bc83c2c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
86 changed files with 187 additions and 280 deletions

View file

@ -7,6 +7,9 @@ repositories {
}
dependencies {
// this is OK as long as the same version catalog is used in the main build and build-logic
// see https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
implementation(libs.indra.common)
implementation(libs.indra.git)
implementation(libs.lombok)

View file

@ -0,0 +1,6 @@
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType
val Project.libs: LibrariesForLibs
get() = rootProject.extensions.getByType()

View file

@ -19,14 +19,7 @@ indra {
}
lombok {
// ugh https://discuss.gradle.org/t/precompiled-script-plugin-accessing-another-precompiled-script-plugin-extension/46177/4
version = project.rootProject
.extensions
.getByType(VersionCatalogsExtension::class.java)
.named("libs")
.findVersion("lombok")
.get()
.displayName
version = libs.versions.lombok.version.get()
}
tasks.withType<JavaCompile> {
@ -38,4 +31,4 @@ tasks.withType<Javadoc> {
val options = options as StandardJavadocDocletOptions
options.encoding = "UTF-8"
options.addStringOption("Xdoclint:all,-missing", "-quiet")
}
}

View file

@ -14,7 +14,7 @@ junit = "5.8.2"
# buildSrc
indra = "3.1.3"
lombok = "1.18.30"
lombok-version = "1.18.30"
lombok-plugin = "8.4"
[libraries]

View file

@ -3,8 +3,6 @@ package org.geysermc.mcprotocollib.network.codec;
import org.geysermc.mcprotocollib.network.packet.Packet;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
/**
* Represents a definition of a packet with various
* information about it, such as it's id, class and
@ -50,7 +48,7 @@ public class PacketDefinition<T extends Packet, H extends PacketCodecHelper> {
return this.serializer;
}
public T newInstance(ByteBuf buf, H helper) throws IOException {
public T newInstance(ByteBuf buf, H helper) {
return this.serializer.deserialize(buf, helper, this);
}
}

View file

@ -3,11 +3,9 @@ package org.geysermc.mcprotocollib.network.codec;
import org.geysermc.mcprotocollib.network.packet.Packet;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
public interface PacketSerializer<T extends Packet, H extends PacketCodecHelper> {
void serialize(ByteBuf buf, H helper, T packet) throws IOException;
void serialize(ByteBuf buf, H helper, T packet);
T deserialize(ByteBuf buf, H helper, PacketDefinition<T, H> definition) throws IOException;
T deserialize(ByteBuf buf, H helper, PacketDefinition<T, H> definition);
}

View file

@ -9,7 +9,6 @@ import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.io.IOException;
import java.util.IdentityHashMap;
import java.util.Map;
@ -145,11 +144,10 @@ public abstract class PacketProtocol {
* @param buf The buffer to read the packet from.
* @param codecHelper The codec helper.
* @return The created packet.
* @throws IOException if there was an IO error whilst reading the packet.
* @throws IllegalArgumentException If the packet ID is not registered.
*/
@SuppressWarnings("unchecked")
public <H extends PacketCodecHelper> Packet createClientboundPacket(int id, ByteBuf buf, H codecHelper) throws IOException {
public <H extends PacketCodecHelper> Packet createClientboundPacket(int id, ByteBuf buf, H codecHelper) {
PacketDefinition<?, H> definition = (PacketDefinition<?, H>) this.clientbound.get(id);
if (definition == null) {
throw new IllegalArgumentException("Invalid packet id: " + id);
@ -211,11 +209,10 @@ public abstract class PacketProtocol {
* @param buf The buffer to read the packet from.
* @param codecHelper The codec helper.
* @return The created packet.
* @throws IOException if there was an IO error whilst reading the packet.
* @throws IllegalArgumentException If the packet ID is not registered.
*/
@SuppressWarnings("unchecked")
public <H extends PacketCodecHelper> Packet createServerboundPacket(int id, ByteBuf buf, H codecHelper) throws IOException {
public <H extends PacketCodecHelper> Packet createServerboundPacket(int id, ByteBuf buf, H codecHelper) {
PacketDefinition<?, H> definition = (PacketDefinition<?, H>) this.serverbound.get(id);
if (definition == null) {
throw new IllegalArgumentException("Invalid packet id: " + id);

View file

@ -23,7 +23,7 @@ public class TcpPacketCodec extends ByteToMessageCodec<Packet> {
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void encode(ChannelHandlerContext ctx, Packet packet, ByteBuf buf) throws Exception {
public void encode(ChannelHandlerContext ctx, Packet packet, ByteBuf buf) {
int initial = buf.writerIndex();
PacketProtocol packetProtocol = this.session.getPacketProtocol();
@ -47,7 +47,7 @@ public class TcpPacketCodec extends ByteToMessageCodec<Packet> {
}
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) {
int initial = buf.readerIndex();
PacketProtocol packetProtocol = this.session.getPacketProtocol();

View file

@ -1,6 +0,0 @@
package org.geysermc.mcprotocollib.protocol;
@FunctionalInterface
public interface CheckedBiConsumer<T, U, E extends Throwable> {
void accept(T t, U u) throws E;
}

View file

@ -1,6 +0,0 @@
package org.geysermc.mcprotocollib.protocol;
@FunctionalInterface
public interface CheckedFunction<T, R, E extends Throwable> {
R apply(T t) throws E;
}

View file

@ -25,7 +25,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.GeneralSecurityException;
import java.security.Key;
@ -203,7 +202,7 @@ public class MinecraftProtocol extends PacketProtocol {
}
@Override
public Packet createClientboundPacket(int id, ByteBuf buf, PacketCodecHelper codecHelper) throws IOException {
public Packet createClientboundPacket(int id, ByteBuf buf, PacketCodecHelper codecHelper) {
return this.stateCodec.createClientboundPacket(id, buf, codecHelper);
}
@ -223,7 +222,7 @@ public class MinecraftProtocol extends PacketProtocol {
}
@Override
public Packet createServerboundPacket(int id, ByteBuf buf, PacketCodecHelper codecHelper) throws IOException {
public Packet createServerboundPacket(int id, ByteBuf buf, PacketCodecHelper codecHelper) {
return this.stateCodec.createServerboundPacket(id, buf, codecHelper);
}

View file

@ -1,8 +1,6 @@
package org.geysermc.mcprotocollib.protocol.codec;
import com.github.steveice10.mc.auth.data.GameProfile;
import org.geysermc.mcprotocollib.protocol.CheckedBiConsumer;
import org.geysermc.mcprotocollib.protocol.CheckedFunction;
import org.geysermc.mcprotocollib.protocol.data.DefaultComponentSerializer;
import org.geysermc.mcprotocollib.protocol.data.game.Identifier;
import org.geysermc.mcprotocollib.protocol.data.game.chat.numbers.BlankFormat;
@ -86,6 +84,7 @@ import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.ObjIntConsumer;
@ -105,7 +104,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
protected CompoundTag registry;
@Nullable
public <T, E extends Throwable> T readNullable(ByteBuf buf, CheckedFunction<ByteBuf, T, E> ifPresent) throws E {
public <T> T readNullable(ByteBuf buf, Function<ByteBuf, T> ifPresent) {
if (buf.readBoolean()) {
return ifPresent.apply(buf);
} else {
@ -113,7 +112,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
}
}
public <T, E extends Throwable> void writeNullable(ByteBuf buf, @Nullable T value, CheckedBiConsumer<ByteBuf, T, E> ifPresent) throws E {
public <T> void writeNullable(ByteBuf buf, @Nullable T value, BiConsumer<ByteBuf, T> ifPresent) {
if (value != null) {
buf.writeBoolean(true);
ifPresent.accept(buf, value);
@ -189,12 +188,12 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
}
@Nullable
public CompoundTag readAnyTag(ByteBuf buf) throws IOException {
public CompoundTag readAnyTag(ByteBuf buf) {
return readAnyTag(buf, CompoundTag.class);
}
@NonNull
public CompoundTag readAnyTagOrThrow(ByteBuf buf) throws IOException {
public CompoundTag readAnyTagOrThrow(ByteBuf buf) {
CompoundTag tag = readAnyTag(buf);
if (tag == null) {
throw new IllegalArgumentException("Got end-tag when trying to read CompoundTag");
@ -203,13 +202,18 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
}
@Nullable
public <T extends Tag> T readAnyTag(ByteBuf buf, Class<T> expected) throws IOException {
Tag tag = NBTIO.readAnyTag(new InputStream() {
@Override
public int read() {
return buf.readUnsignedByte();
}
});
public <T extends Tag> T readAnyTag(ByteBuf buf, Class<T> expected) {
Tag tag;
try {
tag = NBTIO.readAnyTag(new InputStream() {
@Override
public int read() {
return buf.readUnsignedByte();
}
});
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
if (tag == null) {
return null;
@ -222,17 +226,21 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
return expected.cast(tag);
}
public <T extends Tag> void writeAnyTag(ByteBuf buf, @Nullable T tag) throws IOException {
NBTIO.writeAnyTag(new OutputStream() {
@Override
public void write(int b) {
buf.writeByte(b);
}
}, tag);
public <T extends Tag> void writeAnyTag(ByteBuf buf, @Nullable T tag) {
try {
NBTIO.writeAnyTag(new OutputStream() {
@Override
public void write(int b) {
buf.writeByte(b);
}
}, tag);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
@Nullable
public ItemStack readItemStack(ByteBuf buf) throws IOException {
public ItemStack readItemStack(ByteBuf buf) {
boolean present = buf.readBoolean();
if (!present) {
return null;
@ -242,7 +250,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
return new ItemStack(item, buf.readByte(), this.readAnyTag(buf));
}
public void writeItemStack(ByteBuf buf, @Nullable ItemStack item) throws IOException {
public void writeItemStack(ByteBuf buf, @Nullable ItemStack item) {
buf.writeBoolean(item != null);
if (item != null) {
this.writeVarInt(buf, item.getId());
@ -335,7 +343,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
this.writeVarInt(buf, e.ordinal());
}
public Component readComponent(ByteBuf buf) throws IOException {
public Component readComponent(ByteBuf buf) {
// do not use CompoundTag, as mojang serializes a plaintext component as just a single StringTag
Tag tag = readAnyTag(buf, Tag.class);
if (tag == null) {
@ -345,13 +353,13 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
return DefaultComponentSerializer.get().deserializeFromTree(json);
}
public void writeComponent(ByteBuf buf, Component component) throws IOException {
public void writeComponent(ByteBuf buf, Component component) {
JsonElement json = DefaultComponentSerializer.get().serializeToTree(component);
Tag tag = NbtComponentSerializer.jsonComponentToTag(json);
writeAnyTag(buf, tag);
}
public EntityMetadata<?, ?>[] readEntityMetadata(ByteBuf buf) throws IOException {
public EntityMetadata<?, ?>[] readEntityMetadata(ByteBuf buf) {
List<EntityMetadata<?, ?>> ret = new ArrayList<>();
int id;
while ((id = buf.readUnsignedByte()) != 255) {
@ -361,7 +369,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
return ret.toArray(new EntityMetadata<?, ?>[0]);
}
public void writeEntityMetadata(ByteBuf buf, EntityMetadata<?, ?>[] metadata) throws IOException {
public void writeEntityMetadata(ByteBuf buf, EntityMetadata<?, ?>[] metadata) {
for (EntityMetadata<?, ?> meta : metadata) {
this.writeMetadata(buf, meta);
}
@ -369,12 +377,12 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
buf.writeByte(255);
}
public EntityMetadata<?, ?> readMetadata(ByteBuf buf, int id) throws IOException {
public EntityMetadata<?, ?> readMetadata(ByteBuf buf, int id) {
MetadataType<?> type = this.readMetadataType(buf);
return type.readMetadata(this, buf, id);
}
public void writeMetadata(ByteBuf buf, EntityMetadata<?, ?> metadata) throws IOException {
public void writeMetadata(ByteBuf buf, EntityMetadata<?, ?> metadata) {
buf.writeByte(metadata.getId());
this.writeMetadataType(buf, metadata.getType());
metadata.write(this, buf);
@ -437,19 +445,22 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
this.writeEnum(buf, type);
}
public Particle readParticle(ByteBuf buf) throws IOException {
public Particle readParticle(ByteBuf buf) {
ParticleType particleType = this.readParticleType(buf);
return new Particle(particleType, this.readParticleData(buf, particleType));
}
public void writeParticle(ByteBuf buf, Particle particle) throws IOException {
public void writeParticle(ByteBuf buf, Particle particle) {
this.writeEnum(buf, particle.getType());
this.writeParticleData(buf, particle.getType(), particle.getData());
}
public ParticleData readParticleData(ByteBuf buf, ParticleType type) throws IOException {
public ParticleData readParticleData(ByteBuf buf, ParticleType type) {
return switch (type) {
case BLOCK, BLOCK_MARKER -> new BlockParticleData(this.readVarInt(buf));
case BLOCK, BLOCK_MARKER -> {
int blockState = this.readVarInt(buf);
yield new BlockParticleData(blockState);
}
case DUST -> {
float red = buf.readFloat();
float green = buf.readFloat();
@ -476,9 +487,12 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
};
}
public void writeParticleData(ByteBuf buf, ParticleType type, ParticleData data) throws IOException {
public void writeParticleData(ByteBuf buf, ParticleType type, ParticleData data) {
switch (type) {
case BLOCK, BLOCK_MARKER -> this.writeVarInt(buf, ((BlockParticleData) data).getBlockState());
case BLOCK, BLOCK_MARKER -> {
BlockParticleData block = (BlockParticleData) data;
this.writeVarInt(buf, block.getBlockState());
}
case DUST -> {
DustParticleData dust = (DustParticleData) data;
buf.writeFloat(dust.getRed());
@ -521,7 +535,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
}
}
public NumberFormat readNumberFormat(ByteBuf buf) throws IOException {
public NumberFormat readNumberFormat(ByteBuf buf) {
int id = this.readVarInt(buf);
return switch (id) {
case 0 -> BlankFormat.INSTANCE;
@ -531,7 +545,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
};
}
public void writeNumberFormat(ByteBuf buf, NumberFormat numberFormat) throws IOException {
public void writeNumberFormat(ByteBuf buf, NumberFormat numberFormat) {
if (numberFormat instanceof BlankFormat) {
this.writeVarInt(buf, 0);
} else if (numberFormat instanceof StyledFormat styledFormat) {
@ -708,7 +722,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
buf.writeByte(event.ordinal());
}
public Ingredient readRecipeIngredient(ByteBuf buf) throws IOException {
public Ingredient readRecipeIngredient(ByteBuf buf) {
ItemStack[] options = new ItemStack[this.readVarInt(buf)];
for (int i = 0; i < options.length; i++) {
options[i] = this.readItemStack(buf);
@ -717,14 +731,14 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
return new Ingredient(options);
}
public void writeRecipeIngredient(ByteBuf buf, Ingredient ingredient) throws IOException {
public void writeRecipeIngredient(ByteBuf buf, Ingredient ingredient) {
this.writeVarInt(buf, ingredient.getOptions().length);
for (ItemStack option : ingredient.getOptions()) {
this.writeItemStack(buf, option);
}
}
public DataPalette readDataPalette(ByteBuf buf, PaletteType paletteType) throws IOException {
public DataPalette readDataPalette(ByteBuf buf, PaletteType paletteType) {
int bitsPerEntry = buf.readByte() & 0xFF;
Palette palette = this.readPalette(buf, paletteType, bitsPerEntry);
BitStorage storage;
@ -746,7 +760,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
* @deprecated globalPaletteBits is no longer in use, use {@link #readDataPalette(ByteBuf, PaletteType)} instead.
*/
@Deprecated(forRemoval = true)
public DataPalette readDataPalette(ByteBuf buf, PaletteType paletteType, int globalPaletteBits) throws IOException {
public DataPalette readDataPalette(ByteBuf buf, PaletteType paletteType, int globalPaletteBits) {
return this.readDataPalette(buf, paletteType);
}
@ -785,7 +799,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
}
}
public ChunkSection readChunkSection(ByteBuf buf) throws IOException {
public ChunkSection readChunkSection(ByteBuf buf) {
int blockCount = buf.readShort();
DataPalette chunkPalette = this.readDataPalette(buf, PaletteType.CHUNK);
@ -797,7 +811,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
* @deprecated globalBiomePaletteBits is no longer in use, use {@link #readChunkSection(ByteBuf)} instead.
*/
@Deprecated(forRemoval = true)
public ChunkSection readChunkSection(ByteBuf buf, int globalBiomePaletteBits) throws IOException {
public ChunkSection readChunkSection(ByteBuf buf, int globalBiomePaletteBits) {
return this.readChunkSection(buf);
}

View file

@ -3,9 +3,7 @@ package org.geysermc.mcprotocollib.protocol.codec;
import org.geysermc.mcprotocollib.network.packet.Packet;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
public interface MinecraftPacket extends Packet {
void serialize(ByteBuf buf, MinecraftCodecHelper helper) throws IOException;
void serialize(ByteBuf buf, MinecraftCodecHelper helper);
}

View file

@ -5,19 +5,17 @@ import org.geysermc.mcprotocollib.network.codec.PacketSerializer;
import io.netty.buffer.ByteBuf;
import lombok.RequiredArgsConstructor;
import java.io.IOException;
@RequiredArgsConstructor
public class MinecraftPacketSerializer<T extends MinecraftPacket> implements PacketSerializer<T, MinecraftCodecHelper> {
private final PacketFactory<T, MinecraftCodecHelper> factory;
@Override
public void serialize(ByteBuf buf, MinecraftCodecHelper helper, T packet) throws IOException {
public void serialize(ByteBuf buf, MinecraftCodecHelper helper, T packet) {
packet.serialize(buf, helper);
}
@Override
public T deserialize(ByteBuf buf, MinecraftCodecHelper helper, PacketDefinition<T, MinecraftCodecHelper> definition) throws IOException {
public T deserialize(ByteBuf buf, MinecraftCodecHelper helper, PacketDefinition<T, MinecraftCodecHelper> definition) {
return this.factory.construct(buf, helper);
}
}

View file

@ -4,8 +4,6 @@ import org.geysermc.mcprotocollib.network.codec.PacketCodecHelper;
import org.geysermc.mcprotocollib.network.packet.Packet;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
/**
* Factory for constructing {@link Packet}s.
*
@ -21,5 +19,5 @@ public interface PacketFactory<T extends Packet, H extends PacketCodecHelper> {
* @param codecHelper the codec helper
* @return a new packet from the input
*/
T construct(ByteBuf buf, H codecHelper) throws IOException;
T construct(ByteBuf buf, H codecHelper);
}

View file

@ -7,7 +7,6 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import java.io.IOException;
import java.util.Objects;
@Data
@ -25,7 +24,7 @@ public abstract class EntityMetadata<V, T extends MetadataType<V>> {
* Overridden for primitive classes. This write method still checks for these primitives in the event
* they are manually created using {@link ObjectEntityMetadata}.
*/
public void write(MinecraftCodecHelper helper, ByteBuf out) throws IOException {
public void write(MinecraftCodecHelper helper, ByteBuf out) {
this.type.writeMetadata(helper, out, this.getValue());
}

View file

@ -18,7 +18,6 @@ import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.math.vector.Vector3i;
import org.cloudburstmc.math.vector.Vector4f;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@ -71,38 +70,38 @@ public class MetadataType<T> {
VALUES.add(this);
}
public EntityMetadata<T, ? extends MetadataType<T>> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) throws IOException {
public EntityMetadata<T, ? extends MetadataType<T>> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) {
return this.metadataFactory.create(id, this, this.reader.read(helper, input));
}
public void writeMetadata(MinecraftCodecHelper helper, ByteBuf output, T value) throws IOException {
public void writeMetadata(MinecraftCodecHelper helper, ByteBuf output, T value) {
this.writer.write(helper, output, value);
}
@FunctionalInterface
public interface Reader<V> {
V read(MinecraftCodecHelper helper, ByteBuf input) throws IOException;
V read(MinecraftCodecHelper helper, ByteBuf input);
}
@FunctionalInterface
public interface Writer<V> {
void write(MinecraftCodecHelper helper, ByteBuf output, V value) throws IOException;
void write(MinecraftCodecHelper helper, ByteBuf output, V value);
}
@FunctionalInterface
public interface BasicReader<V> extends Reader<V> {
V read(ByteBuf input) throws IOException;
V read(ByteBuf input);
default V read(MinecraftCodecHelper helper, ByteBuf input) throws IOException {
default V read(MinecraftCodecHelper helper, ByteBuf input) {
return this.read(input);
}
}
@FunctionalInterface
public interface BasicWriter<V> extends Writer<V> {
void write(ByteBuf output, V value) throws IOException;
void write(ByteBuf output, V value);
default void write(MinecraftCodecHelper helper, ByteBuf output, V value) throws IOException {
default void write(MinecraftCodecHelper helper, ByteBuf output, V value) {
this.write(output, value);
}
}
@ -134,19 +133,15 @@ public class MetadataType<T> {
private static <T> BasicWriter<Optional<T>> optionalWriter(BasicWriter<T> writer) {
return (output, value) -> {
output.writeBoolean(value.isPresent());
if (value.isPresent()) {
writer.write(output, value.get());
}
output.writeBoolean(value.isPresent());
value.ifPresent(t -> writer.write(output, t));
};
}
private static <T> Writer<Optional<T>> optionalWriter(Writer<T> writer) {
return (helper, output, value) -> {
output.writeBoolean(value.isPresent());
if (value.isPresent()) {
writer.write(helper, output, value.get());
}
value.ifPresent(t -> writer.write(helper, output, t));
};
}

View file

@ -6,8 +6,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetad
import io.netty.buffer.ByteBuf;
import lombok.NonNull;
import java.io.IOException;
public class BooleanEntityMetadata extends EntityMetadata<Boolean, BooleanMetadataType> {
private final boolean value;
@ -27,7 +25,7 @@ public class BooleanEntityMetadata extends EntityMetadata<Boolean, BooleanMetada
}
@Override
public void write(MinecraftCodecHelper helper, ByteBuf out) throws IOException {
public void write(MinecraftCodecHelper helper, ByteBuf out) {
this.type.writeMetadataPrimitive(out, this.value);
}
}

View file

@ -6,8 +6,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetad
import io.netty.buffer.ByteBuf;
import lombok.NonNull;
import java.io.IOException;
public class ByteEntityMetadata extends EntityMetadata<Byte, ByteMetadataType> {
private final byte value;
@ -27,7 +25,7 @@ public class ByteEntityMetadata extends EntityMetadata<Byte, ByteMetadataType> {
}
@Override
public void write(MinecraftCodecHelper helper, ByteBuf out) throws IOException {
public void write(MinecraftCodecHelper helper, ByteBuf out) {
this.type.writeMetadataPrimitive(out, this.value);
}
}

View file

@ -6,8 +6,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.FloatMetada
import io.netty.buffer.ByteBuf;
import lombok.NonNull;
import java.io.IOException;
public class FloatEntityMetadata extends EntityMetadata<Float, FloatMetadataType> {
private final float value;
@ -27,7 +25,7 @@ public class FloatEntityMetadata extends EntityMetadata<Float, FloatMetadataType
}
@Override
public void write(MinecraftCodecHelper helper, ByteBuf out) throws IOException {
public void write(MinecraftCodecHelper helper, ByteBuf out) {
this.type.writeMetadataPrimitive(out, this.value);
}
}

View file

@ -6,8 +6,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.IntMetadata
import io.netty.buffer.ByteBuf;
import lombok.NonNull;
import java.io.IOException;
public class IntEntityMetadata extends EntityMetadata<Integer, IntMetadataType> {
private final int value;
@ -27,7 +25,7 @@ public class IntEntityMetadata extends EntityMetadata<Integer, IntMetadataType>
}
@Override
public void write(MinecraftCodecHelper helper, ByteBuf out) throws IOException {
public void write(MinecraftCodecHelper helper, ByteBuf out) {
this.type.writeMetadataPrimitive(helper, out, value);
}
}

View file

@ -6,8 +6,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.LongMetadat
import io.netty.buffer.ByteBuf;
import lombok.NonNull;
import java.io.IOException;
public class LongEntityMetadata extends EntityMetadata<Long, LongMetadataType> {
private final long value;
@ -27,7 +25,7 @@ public class LongEntityMetadata extends EntityMetadata<Long, LongMetadataType> {
}
@Override
public void write(MinecraftCodecHelper helper, ByteBuf out) throws IOException {
public void write(MinecraftCodecHelper helper, ByteBuf out) {
this.type.writeMetadataPrimitive(helper, out, value);
}
}

View file

@ -6,7 +6,6 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
@ -44,7 +43,7 @@ public class LightUpdateData {
}
}
public static void write(ByteBuf out, MinecraftCodecHelper helper, LightUpdateData data) throws IOException {
public static void write(ByteBuf out, MinecraftCodecHelper helper, LightUpdateData data) {
data.write(out, helper);
}

View file

@ -10,8 +10,6 @@ import lombok.NonNull;
import lombok.With;
import net.kyori.adventure.text.Component;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -22,12 +20,12 @@ public class ClientboundDisconnectPacket implements MinecraftPacket {
this(DefaultComponentSerializer.get().deserialize(reason));
}
public ClientboundDisconnectPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundDisconnectPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.reason = helper.readComponent(in);
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeComponent(out, this.reason);
}

View file

@ -10,7 +10,6 @@ import lombok.With;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
import java.util.UUID;
@Data
@ -23,7 +22,7 @@ public class ClientboundResourcePackPushPacket implements MinecraftPacket {
private final boolean required;
private final @Nullable Component prompt;
public ClientboundResourcePackPushPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundResourcePackPushPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.id = helper.readUUID(in);
this.url = helper.readString(in);
this.hash = helper.readString(in);
@ -32,7 +31,7 @@ public class ClientboundResourcePackPushPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeUUID(out, this.id);
helper.writeString(out, this.url);
helper.writeString(out, this.hash);

View file

@ -8,20 +8,18 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
public class ClientboundRegistryDataPacket implements MinecraftPacket {
private final CompoundTag registry;
public ClientboundRegistryDataPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundRegistryDataPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.registry = helper.readAnyTag(in);
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeAnyTag(out, this.registry);
}
}

View file

@ -9,7 +9,6 @@ import io.netty.buffer.ByteBuf;
import lombok.*;
import net.kyori.adventure.text.Component;
import java.io.IOException;
import java.util.UUID;
@Data
@ -64,7 +63,7 @@ public class ClientboundBossEventPacket implements MinecraftPacket {
this.showFog = showFog;
}
public ClientboundBossEventPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundBossEventPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.uuid = helper.readUUID(in);
this.action = BossBarAction.from(helper.readVarInt(in));
@ -101,7 +100,7 @@ public class ClientboundBossEventPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeUUID(out, this.uuid);
helper.writeVarInt(out, this.action.ordinal());

View file

@ -8,7 +8,6 @@ import lombok.NonNull;
import lombok.With;
import net.kyori.adventure.text.Component;
import java.io.IOException;
import java.util.Arrays;
@Data
@ -32,7 +31,7 @@ public class ClientboundCommandSuggestionsPacket implements MinecraftPacket {
this.tooltips = Arrays.copyOf(tooltips, tooltips.length);
}
public ClientboundCommandSuggestionsPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundCommandSuggestionsPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.transactionId = helper.readVarInt(in);
this.start = helper.readVarInt(in);
this.length = helper.readVarInt(in);
@ -47,7 +46,7 @@ public class ClientboundCommandSuggestionsPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.transactionId);
helper.writeVarInt(out, this.start);
helper.writeVarInt(out, this.length);

View file

@ -10,8 +10,6 @@ import lombok.With;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -25,7 +23,7 @@ public class ClientboundDisguisedChatPacket implements MinecraftPacket {
private final @Nullable Component targetName;
public ClientboundDisguisedChatPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundDisguisedChatPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.message = helper.readComponent(in);
this.chatType = helper.readVarInt(in);
this.name = helper.readComponent(in);
@ -33,7 +31,7 @@ public class ClientboundDisguisedChatPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeComponent(out, this.message);
helper.writeVarInt(out, this.chatType);
helper.writeComponent(out, this.name);

View file

@ -12,7 +12,6 @@ import lombok.With;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@ -37,7 +36,7 @@ public class ClientboundPlayerChatPacket implements MinecraftPacket {
private final Component name;
private final @Nullable Component targetName;
public ClientboundPlayerChatPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundPlayerChatPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.sender = helper.readUUID(in);
this.index = helper.readVarInt(in);
if (in.readBoolean()) {
@ -65,7 +64,7 @@ public class ClientboundPlayerChatPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeUUID(out, this.sender);
helper.writeVarInt(out, this.index);
out.writeBoolean(this.messageSignature != null);

View file

@ -12,7 +12,6 @@ import lombok.Data;
import lombok.With;
import net.kyori.adventure.text.Component;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.KeyFactory;
import java.security.PublicKey;
@ -28,7 +27,7 @@ public class ClientboundPlayerInfoUpdatePacket implements MinecraftPacket {
private final EnumSet<PlayerListEntryAction> actions;
private final PlayerListEntry[] entries;
public ClientboundPlayerInfoUpdatePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundPlayerInfoUpdatePacket(ByteBuf in, MinecraftCodecHelper helper) {
this.actions = helper.readEnumSet(in, PlayerListEntryAction.VALUES);
this.entries = new PlayerListEntry[helper.readVarInt(in)];
for (int count = 0; count < this.entries.length; count++) {
@ -58,7 +57,7 @@ public class ClientboundPlayerInfoUpdatePacket implements MinecraftPacket {
try {
publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(keyBytes));
} catch (GeneralSecurityException e) {
throw new IOException("Could not decode public key.", e);
throw new IllegalStateException("Could not decode public key.", e);
}
entry.setPublicKey(publicKey);
@ -91,7 +90,7 @@ public class ClientboundPlayerInfoUpdatePacket implements MinecraftPacket {
}
}
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeEnumSet(out, this.actions, PlayerListEntryAction.VALUES);
helper.writeVarInt(out, this.entries.length);
for (PlayerListEntry entry : this.entries) {

View file

@ -9,8 +9,6 @@ import lombok.With;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -19,14 +17,14 @@ public class ClientboundServerDataPacket implements MinecraftPacket {
private final byte @Nullable[] iconBytes;
private final boolean enforcesSecureChat;
public ClientboundServerDataPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundServerDataPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.motd = helper.readComponent(in);
this.iconBytes = helper.readNullable(in, helper::readByteArray);
this.enforcesSecureChat = in.readBoolean();
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeComponent(out, this.motd);
helper.writeNullable(out, this.iconBytes, helper::writeByteArray);
out.writeBoolean(this.enforcesSecureChat);

View file

@ -8,8 +8,6 @@ import lombok.Data;
import lombok.With;
import net.kyori.adventure.text.Component;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -17,13 +15,13 @@ public class ClientboundSystemChatPacket implements MinecraftPacket {
private final Component content;
private final boolean overlay;
public ClientboundSystemChatPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundSystemChatPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.content = helper.readComponent(in);
this.overlay = in.readBoolean();
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeComponent(out, this.content);
out.writeBoolean(this.overlay);
}

View file

@ -9,8 +9,6 @@ import lombok.NonNull;
import lombok.With;
import net.kyori.adventure.text.Component;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -18,13 +16,13 @@ public class ClientboundTabListPacket implements MinecraftPacket {
private final @NonNull Component header;
private final @NonNull Component footer;
public ClientboundTabListPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundTabListPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.header = helper.readComponent(in);
this.footer = helper.readComponent(in);
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeComponent(out, this.header);
helper.writeComponent(out, this.footer);
}

View file

@ -13,7 +13,6 @@ import lombok.NonNull;
import lombok.With;
import net.kyori.adventure.text.Component;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -45,7 +44,7 @@ public class ClientboundUpdateAdvancementsPacket implements MinecraftPacket {
return progress.get(criterionId);
}
public ClientboundUpdateAdvancementsPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundUpdateAdvancementsPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.reset = in.readBoolean();
this.advancements = new Advancement[helper.readVarInt(in)];
@ -111,7 +110,7 @@ public class ClientboundUpdateAdvancementsPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
out.writeBoolean(this.reset);
helper.writeVarInt(out, this.advancements.length);

View file

@ -14,15 +14,13 @@ import lombok.Data;
import lombok.NonNull;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
public class ClientboundUpdateRecipesPacket implements MinecraftPacket {
private final @NonNull Recipe[] recipes;
public ClientboundUpdateRecipesPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundUpdateRecipesPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.recipes = new Recipe[helper.readVarInt(in)];
for (int i = 0; i < this.recipes.length; i++) {
RecipeType type = RecipeType.from(helper.readResourceLocation(in));
@ -102,7 +100,7 @@ public class ClientboundUpdateRecipesPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.recipes.length);
for (Recipe recipe : this.recipes) {
helper.writeResourceLocation(out, recipe.getType().getResourceLocation());

View file

@ -9,8 +9,6 @@ import lombok.Data;
import lombok.NonNull;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -18,13 +16,13 @@ public class ClientboundSetEntityDataPacket implements MinecraftPacket {
private final int entityId;
private final @NonNull EntityMetadata<?, ?>[] metadata;
public ClientboundSetEntityDataPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundSetEntityDataPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.entityId = helper.readVarInt(in);
this.metadata = helper.readEntityMetadata(in);
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.entityId);
helper.writeEntityMetadata(out, this.metadata);
}

View file

@ -11,7 +11,6 @@ import lombok.Data;
import lombok.NonNull;
import lombok.With;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -22,7 +21,7 @@ public class ClientboundSetEquipmentPacket implements MinecraftPacket {
private final int entityId;
private final @NonNull Equipment[] equipment;
public ClientboundSetEquipmentPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundSetEquipmentPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.entityId = helper.readVarInt(in);
boolean hasNextEntry = true;
List<Equipment> list = new ArrayList<>();
@ -37,7 +36,7 @@ public class ClientboundSetEquipmentPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.entityId);
for (int i = 0; i < this.equipment.length; i++) {
int rawSlot = this.equipment[i].getSlot().ordinal();

View file

@ -11,8 +11,6 @@ import lombok.NonNull;
import lombok.With;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -30,7 +28,7 @@ public class ClientboundUpdateMobEffectPacket implements MinecraftPacket {
private final boolean showIcon;
private final @Nullable CompoundTag factorData;
public ClientboundUpdateMobEffectPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundUpdateMobEffectPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.entityId = helper.readVarInt(in);
this.effect = helper.readEffect(in);
this.amplifier = in.readByte();
@ -44,7 +42,7 @@ public class ClientboundUpdateMobEffectPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.entityId);
helper.writeEffect(out, this.effect);
out.writeByte(this.amplifier);

View file

@ -8,8 +8,6 @@ import lombok.Data;
import lombok.With;
import net.kyori.adventure.text.Component;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -17,13 +15,13 @@ public class ClientboundPlayerCombatKillPacket implements MinecraftPacket {
private final int playerId;
private final Component message;
public ClientboundPlayerCombatKillPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundPlayerCombatKillPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.playerId = helper.readVarInt(in);
this.message = helper.readComponent(in);
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.playerId);
helper.writeComponent(out, this.message);
}

View file

@ -10,8 +10,6 @@ import lombok.NonNull;
import lombok.With;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -21,7 +19,7 @@ public class ClientboundContainerSetContentPacket implements MinecraftPacket {
private final @Nullable ItemStack @NonNull [] items;
private final @Nullable ItemStack carriedItem;
public ClientboundContainerSetContentPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundContainerSetContentPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.containerId = in.readUnsignedByte();
this.stateId = helper.readVarInt(in);
this.items = new ItemStack[helper.readVarInt(in)];
@ -32,7 +30,7 @@ public class ClientboundContainerSetContentPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
out.writeByte(this.containerId);
helper.writeVarInt(out, this.stateId);
helper.writeVarInt(out, this.items.length);

View file

@ -9,8 +9,6 @@ import lombok.Data;
import lombok.With;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -20,7 +18,7 @@ public class ClientboundContainerSetSlotPacket implements MinecraftPacket {
private final int slot;
private final @Nullable ItemStack item;
public ClientboundContainerSetSlotPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundContainerSetSlotPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.containerId = in.readUnsignedByte();
this.stateId = helper.readVarInt(in);
this.slot = in.readShort();
@ -28,7 +26,7 @@ public class ClientboundContainerSetSlotPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
out.writeByte(this.containerId);
helper.writeVarInt(out, this.stateId);
out.writeShort(this.slot);

View file

@ -10,8 +10,6 @@ import lombok.Data;
import lombok.NonNull;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -23,7 +21,7 @@ public class ClientboundMerchantOffersPacket implements MinecraftPacket {
private final boolean regularVillager;
private final boolean canRestock;
public ClientboundMerchantOffersPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundMerchantOffersPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.containerId = helper.readVarInt(in);
int size = helper.readVarInt(in);
@ -51,7 +49,7 @@ public class ClientboundMerchantOffersPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.containerId);
helper.writeVarInt(out, this.trades.length);

View file

@ -11,8 +11,6 @@ import lombok.NonNull;
import lombok.With;
import net.kyori.adventure.text.Component;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -21,7 +19,7 @@ public class ClientboundOpenScreenPacket implements MinecraftPacket {
private final @NonNull ContainerType type;
private final @NonNull Component title;
public ClientboundOpenScreenPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundOpenScreenPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.containerId = helper.readVarInt(in);
this.type = ContainerType.from(helper.readVarInt(in));
this.title = helper.readComponent(in);
@ -35,7 +33,7 @@ public class ClientboundOpenScreenPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.containerId);
helper.writeVarInt(out, this.type.ordinal());
helper.writeComponent(out, this.title);

View file

@ -12,8 +12,6 @@ import lombok.With;
import org.cloudburstmc.math.vector.Vector3i;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -22,14 +20,14 @@ public class ClientboundBlockEntityDataPacket implements MinecraftPacket {
private final @NonNull BlockEntityType type;
private final @Nullable CompoundTag nbt;
public ClientboundBlockEntityDataPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundBlockEntityDataPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.position = helper.readPosition(in);
this.type = helper.readBlockEntityType(in);
this.nbt = helper.readAnyTag(in);
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writePosition(out, this.position);
helper.writeBlockEntityType(out, this.type);
helper.writeAnyTag(out, this.nbt);

View file

@ -12,7 +12,6 @@ import lombok.NonNull;
import lombok.With;
import org.cloudburstmc.math.vector.Vector3i;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -33,7 +32,7 @@ public class ClientboundExplodePacket implements MinecraftPacket {
private final @NonNull ExplosionInteraction blockInteraction;
private final @NonNull Sound explosionSound;
public ClientboundExplodePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundExplodePacket(ByteBuf in, MinecraftCodecHelper helper) {
this.x = in.readDouble();
this.y = in.readDouble();
this.z = in.readDouble();
@ -54,7 +53,7 @@ public class ClientboundExplodePacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
out.writeDouble(this.x);
out.writeDouble(this.y);
out.writeDouble(this.z);

View file

@ -12,8 +12,6 @@ import lombok.Data;
import lombok.NonNull;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -25,7 +23,7 @@ public class ClientboundLevelChunkWithLightPacket implements MinecraftPacket {
private final @NonNull BlockEntityInfo @NonNull [] blockEntities;
private final @NonNull LightUpdateData lightData;
public ClientboundLevelChunkWithLightPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundLevelChunkWithLightPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.x = in.readInt();
this.z = in.readInt();
this.heightMaps = helper.readAnyTagOrThrow(in);
@ -46,7 +44,7 @@ public class ClientboundLevelChunkWithLightPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
out.writeInt(this.x);
out.writeInt(this.z);
helper.writeAnyTag(out, this.heightMaps);

View file

@ -10,8 +10,6 @@ import lombok.Data;
import lombok.NonNull;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -27,7 +25,7 @@ public class ClientboundLevelParticlesPacket implements MinecraftPacket {
private final float velocityOffset;
private final int amount;
public ClientboundLevelParticlesPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundLevelParticlesPacket(ByteBuf in, MinecraftCodecHelper helper) {
ParticleType type = helper.readParticleType(in);
this.longDistance = in.readBoolean();
this.x = in.readDouble();
@ -42,7 +40,7 @@ public class ClientboundLevelParticlesPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeParticleType(out, this.particle.getType());
out.writeBoolean(this.longDistance);
out.writeDouble(this.x);

View file

@ -12,8 +12,6 @@ import lombok.NonNull;
import lombok.With;
import net.kyori.adventure.text.Component;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -29,7 +27,7 @@ public class ClientboundMapItemDataPacket implements MinecraftPacket {
this(mapId, scale, locked, icons, null);
}
public ClientboundMapItemDataPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundMapItemDataPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.mapId = helper.readVarInt(in);
this.scale = in.readByte();
this.locked = in.readBoolean();
@ -64,7 +62,7 @@ public class ClientboundMapItemDataPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.mapId);
out.writeByte(this.scale);
out.writeBoolean(this.locked);

View file

@ -9,8 +9,6 @@ import lombok.Data;
import lombok.With;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -18,13 +16,13 @@ public class ClientboundTagQueryPacket implements MinecraftPacket {
private final int transactionId;
private final @Nullable CompoundTag nbt;
public ClientboundTagQueryPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundTagQueryPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.transactionId = helper.readVarInt(in);
this.nbt = helper.readAnyTag(in);
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.transactionId);
helper.writeAnyTag(out, this.nbt);
}

View file

@ -12,8 +12,6 @@ import lombok.With;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
@Data
@With
public class ClientboundSetObjectivePacket implements MinecraftPacket {
@ -61,7 +59,7 @@ public class ClientboundSetObjectivePacket implements MinecraftPacket {
this.numberFormat = numberFormat;
}
public ClientboundSetObjectivePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundSetObjectivePacket(ByteBuf in, MinecraftCodecHelper helper) {
this.name = helper.readString(in);
this.action = ObjectiveAction.from(in.readByte());
if (this.action == ObjectiveAction.ADD || this.action == ObjectiveAction.UPDATE) {
@ -76,7 +74,7 @@ public class ClientboundSetObjectivePacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeString(out, this.name);
out.writeByte(this.action.ordinal());
if (this.action == ObjectiveAction.ADD || this.action == ObjectiveAction.UPDATE) {

View file

@ -11,7 +11,6 @@ import lombok.*;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
import java.util.Arrays;
@Data
@ -104,7 +103,7 @@ public class ClientboundSetPlayerTeamPacket implements MinecraftPacket {
this.players = Arrays.copyOf(players, players.length);
}
public ClientboundSetPlayerTeamPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundSetPlayerTeamPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.teamName = helper.readString(in);
this.action = TeamAction.from(in.readByte());
if (this.action == TeamAction.CREATE || this.action == TeamAction.UPDATE) {
@ -141,7 +140,7 @@ public class ClientboundSetPlayerTeamPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeString(out, this.teamName);
out.writeByte(this.action.ordinal());
if (this.action == TeamAction.CREATE || this.action == TeamAction.UPDATE) {

View file

@ -8,8 +8,6 @@ import lombok.*;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
@Data
@With
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@ -31,7 +29,7 @@ public class ClientboundSetScorePacket implements MinecraftPacket {
this.numberFormat = null;
}
public ClientboundSetScorePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundSetScorePacket(ByteBuf in, MinecraftCodecHelper helper) {
this.owner = helper.readString(in);
this.objective = helper.readString(in);
this.value = helper.readVarInt(in);
@ -40,7 +38,7 @@ public class ClientboundSetScorePacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeString(out, this.owner);
helper.writeString(out, this.objective);
helper.writeVarInt(out, this.value);

View file

@ -8,20 +8,18 @@ import lombok.Data;
import lombok.With;
import net.kyori.adventure.text.Component;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
public class ClientboundSetActionBarTextPacket implements MinecraftPacket {
private final Component text;
public ClientboundSetActionBarTextPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundSetActionBarTextPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.text = helper.readComponent(in);
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeComponent(out, this.text);
}
}

View file

@ -8,20 +8,18 @@ import lombok.Data;
import lombok.With;
import net.kyori.adventure.text.Component;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
public class ClientboundSetSubtitleTextPacket implements MinecraftPacket {
private final Component text;
public ClientboundSetSubtitleTextPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundSetSubtitleTextPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.text = helper.readComponent(in);
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeComponent(out, this.text);
}
}

View file

@ -10,15 +10,13 @@ import lombok.With;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
public class ClientboundSetTitleTextPacket implements MinecraftPacket {
private final @Nullable Component text;
public ClientboundSetTitleTextPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundSetTitleTextPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.text = helper.readComponent(in);
}

View file

@ -7,7 +7,6 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.KeyFactory;
import java.security.PublicKey;
@ -23,7 +22,7 @@ public class ServerboundChatSessionUpdatePacket implements MinecraftPacket {
private final PublicKey publicKey;
private final byte[] keySignature;
public ServerboundChatSessionUpdatePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ServerboundChatSessionUpdatePacket(ByteBuf in, MinecraftCodecHelper helper) {
this.sessionId = helper.readUUID(in);
this.expiresAt = in.readLong();
byte[] keyBytes = helper.readByteArray(in);
@ -33,7 +32,7 @@ public class ServerboundChatSessionUpdatePacket implements MinecraftPacket {
try {
publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(keyBytes));
} catch (GeneralSecurityException e) {
throw new IOException("Could not decode public key.", e);
throw new IllegalStateException("Could not decode public key.", e);
}
this.publicKey = publicKey;

View file

@ -20,7 +20,6 @@ import lombok.NonNull;
import lombok.With;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
import java.util.Map;
@Data
@ -60,7 +59,7 @@ public class ServerboundContainerClickPacket implements MinecraftPacket {
this.changedSlots = changedSlots;
}
public ServerboundContainerClickPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ServerboundContainerClickPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.containerId = in.readByte();
this.stateId = helper.readVarInt(in);
this.slot = in.readShort();
@ -96,7 +95,7 @@ public class ServerboundContainerClickPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
out.writeByte(this.containerId);
helper.writeVarInt(out, this.stateId);
out.writeShort(this.slot);

View file

@ -9,7 +9,7 @@ import lombok.Getter;
import lombok.NonNull;
import lombok.ToString;
import java.io.IOException;
import java.util.function.Consumer;
@ToString
@EqualsAndHashCode
@ -40,23 +40,22 @@ public class ServerboundSeenAdvancementsPacket implements MinecraftPacket {
return this.tabId;
}
public ServerboundSeenAdvancementsPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ServerboundSeenAdvancementsPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.action = AdvancementTabAction.from(helper.readVarInt(in));
switch (this.action) {
case CLOSED_SCREEN -> this.tabId = null;
case OPENED_TAB -> this.tabId = helper.readString(in);
default -> throw new IOException("Unknown advancement tab action: " + this.action);
}
this.tabId = switch (this.action) {
case CLOSED_SCREEN -> null;
case OPENED_TAB -> helper.readString(in);
};
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.action.ordinal());
switch (this.action) {
case CLOSED_SCREEN -> {
}
case OPENED_TAB -> helper.writeString(out, this.tabId);
default -> throw new IOException("Unknown advancement tab action: " + this.action);
}
Consumer<String> tabIdWriter = switch (this.action) {
case CLOSED_SCREEN -> tabId -> {
};
case OPENED_TAB -> tabId -> helper.writeString(out, tabId);
};
tabIdWriter.accept(this.tabId);
}
}

View file

@ -6,12 +6,9 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.ItemStack;
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import lombok.With;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -19,13 +16,13 @@ public class ServerboundSetCreativeModeSlotPacket implements MinecraftPacket {
private final int slot;
private final @Nullable ItemStack clickedItem;
public ServerboundSetCreativeModeSlotPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ServerboundSetCreativeModeSlotPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.slot = in.readShort();
this.clickedItem = helper.readItemStack(in);
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
out.writeShort(this.slot);
helper.writeItemStack(out, this.clickedItem);
}

View file

@ -8,7 +8,6 @@ import lombok.Data;
import lombok.NonNull;
import lombok.With;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.KeyFactory;
import java.security.PublicKey;
@ -22,7 +21,7 @@ public class ClientboundHelloPacket implements MinecraftPacket {
private final @NonNull PublicKey publicKey;
private final byte @NonNull [] challenge;
public ClientboundHelloPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundHelloPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.serverId = helper.readString(in);
byte[] publicKey = helper.readByteArray(in);
this.challenge = helper.readByteArray(in);
@ -30,7 +29,7 @@ public class ClientboundHelloPacket implements MinecraftPacket {
try {
this.publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(publicKey));
} catch (GeneralSecurityException e) {
throw new IOException("Could not decode public key.", e);
throw new IllegalStateException("Could not decode public key.", e);
}
}

View file

@ -10,8 +10,6 @@ import io.netty.buffer.Unpooled;
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -38,7 +36,7 @@ public class ChunkTest {
}
@Test
public void testChunkSectionEncoding() throws IOException {
public void testChunkSectionEncoding() {
MinecraftCodecHelper helper = new MinecraftCodecHelper(Int2ObjectMaps.emptyMap(), Collections.emptyMap());
for (ChunkSection section : chunkSectionsToTest) {
ByteBuf buf = Unpooled.buffer();