Remove unused exceptions, use java 9+ features and checkerframework, other cleanup (#780)

This commit is contained in:
Alex 2024-01-04 19:04:25 +01:00 committed by GitHub
parent eaac051d1f
commit 8d4878c1fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
250 changed files with 757 additions and 1228 deletions

View file

@ -79,6 +79,9 @@ dependencies {
// Netty
api(libs.bundles.netty)
// Checker Framework
api(libs.checkerframework.qual)
// Test dependencies
testImplementation(libs.junit.jupiter)
}

View file

@ -38,9 +38,11 @@ import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import java.net.Proxy;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.BitSet;
public class MinecraftProtocolTest {
@ -157,7 +159,7 @@ public class MinecraftProtocolTest {
+ " / " + info.getPlayerInfo().getMaxPlayers());
System.out.println("Players: " + Arrays.toString(info.getPlayerInfo().getPlayers().toArray()));
System.out.println("Description: " + info.getDescription());
System.out.println("Icon: " + info.getIconPng());
System.out.println("Icon: " + new String(Base64.getEncoder().encode(info.getIconPng()), StandardCharsets.UTF_8));
});
client.setFlag(MinecraftConstants.SERVER_PING_TIME_HANDLER_KEY, (ServerPingTimeHandler) (session, pingTime) ->

View file

@ -12,6 +12,7 @@ math = "2.0"
fastutil-maps = "8.5.3"
netty = "4.1.103.Final"
netty-io_uring = "0.0.24.Final"
checkerframework = "3.42.0"
junit = "5.8.2"
[libraries]
@ -27,10 +28,13 @@ math-immutable = { module = "org.cloudburstmc.math:immutable", version.ref = "ma
fastutil-object2int-maps = { module = "com.nukkitx.fastutil:fastutil-object-int-maps", version.ref = "fastutil-maps" }
fastutil-int2object-maps = { module = "com.nukkitx.fastutil:fastutil-int-object-maps", version.ref = "fastutil-maps" }
fastutil-int2int-maps = { module = "com.nukkitx.fastutil:fastutil-int-int-maps", version.ref = "fastutil-maps" }
netty-all = { module = "io.netty:netty-all", version.ref = "netty" }
netty-incubator-transport-native-io_uring = { module = "io.netty.incubator:netty-incubator-transport-native-io_uring", version.ref = "netty-io_uring" }
checkerframework-qual = { module = "org.checkerframework:checker-qual", version.ref = "checkerframework" }
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
[plugins]
@ -44,5 +48,5 @@ lombok = { id = "io.freefair.lombok", version.ref = "lombok-plugin" }
adventure = ["adventure-text-serializer-gson", "adventure-text-serializer-json-legacy-impl"]
math = ["math-api", "math-immutable"]
fastutil = ["fastutil-object2int-maps", "fastutil-int2object-maps"]
fastutil = ["fastutil-object2int-maps", "fastutil-int2object-maps", "fastutil-int2int-maps"]
netty = ["netty-all", "netty-incubator-transport-native-io_uring"]

1
lombok.config Normal file
View file

@ -0,0 +1 @@
lombok.addNullAnnotations = checkerframework

View file

@ -54,7 +54,7 @@ public class ClientListener extends SessionAdapter {
public void packetReceived(Session session, Packet packet) {
MinecraftProtocol protocol = (MinecraftProtocol) session.getPacketProtocol();
if (protocol.getState() == ProtocolState.LOGIN) {
if (packet instanceof ClientboundHelloPacket) {
if (packet instanceof ClientboundHelloPacket helloPacket) {
GameProfile profile = session.getFlag(MinecraftConstants.PROFILE_KEY);
String accessToken = session.getFlag(MinecraftConstants.ACCESS_TOKEN_KEY);
@ -62,7 +62,6 @@ public class ClientListener extends SessionAdapter {
throw new UnexpectedEncryptionException();
}
ClientboundHelloPacket helloPacket = (ClientboundHelloPacket) packet;
SecretKey key;
try {
KeyGenerator gen = KeyGenerator.getInstance("AES");
@ -91,22 +90,22 @@ public class ClientListener extends SessionAdapter {
session.enableEncryption(protocol.enableEncryption(key));
} else if (packet instanceof ClientboundGameProfilePacket) {
session.send(new ServerboundLoginAcknowledgedPacket());
} else if (packet instanceof ClientboundLoginDisconnectPacket) {
session.disconnect(((ClientboundLoginDisconnectPacket) packet).getReason());
} else if (packet instanceof ClientboundLoginCompressionPacket) {
session.setCompressionThreshold(((ClientboundLoginCompressionPacket) packet).getThreshold(), false);
} else if (packet instanceof ClientboundLoginDisconnectPacket loginDisconnectPacket) {
session.disconnect(loginDisconnectPacket.getReason());
} else if (packet instanceof ClientboundLoginCompressionPacket loginCompressionPacket) {
session.setCompressionThreshold(loginCompressionPacket.getThreshold(), false);
}
} else if (protocol.getState() == ProtocolState.STATUS) {
if (packet instanceof ClientboundStatusResponsePacket) {
ServerStatusInfo info = ((ClientboundStatusResponsePacket) packet).getInfo();
if (packet instanceof ClientboundStatusResponsePacket statusResponsePacket) {
ServerStatusInfo info = statusResponsePacket.getInfo();
ServerInfoHandler handler = session.getFlag(MinecraftConstants.SERVER_INFO_HANDLER_KEY);
if (handler != null) {
handler.handle(session, info);
}
session.send(new ServerboundPingRequestPacket(System.currentTimeMillis()));
} else if (packet instanceof ClientboundPongResponsePacket) {
long time = System.currentTimeMillis() - ((ClientboundPongResponsePacket) packet).getPingTime();
} else if (packet instanceof ClientboundPongResponsePacket pongResponsePacket) {
long time = System.currentTimeMillis() - pongResponsePacket.getPingTime();
ServerPingTimeHandler handler = session.getFlag(MinecraftConstants.SERVER_PING_TIME_HANDLER_KEY);
if (handler != null) {
handler.handle(session, time);
@ -115,10 +114,10 @@ public class ClientListener extends SessionAdapter {
session.disconnect("Finished");
}
} else if (protocol.getState() == ProtocolState.GAME) {
if (packet instanceof ClientboundKeepAlivePacket && session.getFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, true)) {
session.send(new ServerboundKeepAlivePacket(((ClientboundKeepAlivePacket) packet).getPingId()));
} else if (packet instanceof ClientboundDisconnectPacket) {
session.disconnect(((ClientboundDisconnectPacket) packet).getReason());
if (packet instanceof ClientboundKeepAlivePacket keepAlivePacket && session.getFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, true)) {
session.send(new ServerboundKeepAlivePacket(keepAlivePacket.getPingId()));
} else if (packet instanceof ClientboundDisconnectPacket disconnectPacket) {
session.disconnect(disconnectPacket.getReason());
} else if (packet instanceof ClientboundStartConfigurationPacket) {
session.send(new ServerboundConfigurationAcknowledgedPacket());
}
@ -154,10 +153,15 @@ public class ClientListener extends SessionAdapter {
@Override
public void connected(ConnectedEvent event) {
MinecraftProtocol protocol = (MinecraftProtocol) event.getSession().getPacketProtocol();
if (this.targetState == ProtocolState.LOGIN) {
event.getSession().send(new ClientIntentionPacket(protocol.getCodec().getProtocolVersion(), event.getSession().getHost(), event.getSession().getPort(), HandshakeIntent.LOGIN));
} else if (this.targetState == ProtocolState.STATUS) {
event.getSession().send(new ClientIntentionPacket(protocol.getCodec().getProtocolVersion(), event.getSession().getHost(), event.getSession().getPort(), HandshakeIntent.STATUS));
}
event.getSession().send(new ClientIntentionPacket(
protocol.getCodec().getProtocolVersion(),
event.getSession().getHost(),
event.getSession().getPort(),
switch (this.targetState) {
case LOGIN -> HandshakeIntent.LOGIN;
case STATUS -> HandshakeIntent.STATUS;
default -> throw new IllegalArgumentException("Invalid target state: " + this.targetState);
}
));
}
}

View file

@ -21,7 +21,7 @@ import io.netty.buffer.ByteBuf;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.DataInput;
import java.io.DataInputStream;

View file

@ -33,6 +33,7 @@ import com.github.steveice10.packetlib.event.session.ConnectedEvent;
import com.github.steveice10.packetlib.event.session.DisconnectingEvent;
import com.github.steveice10.packetlib.event.session.SessionAdapter;
import com.github.steveice10.packetlib.packet.Packet;
import lombok.RequiredArgsConstructor;
import net.kyori.adventure.text.Component;
import javax.crypto.SecretKey;
@ -87,36 +88,31 @@ public class ServerListener extends SessionAdapter {
public void packetReceived(Session session, Packet packet) {
MinecraftProtocol protocol = (MinecraftProtocol) session.getPacketProtocol();
if (protocol.getState() == ProtocolState.HANDSHAKE) {
if (packet instanceof ClientIntentionPacket) {
ClientIntentionPacket intentionPacket = (ClientIntentionPacket) packet;
if (packet instanceof ClientIntentionPacket intentionPacket) {
switch (intentionPacket.getIntent()) {
case STATUS:
protocol.setState(ProtocolState.STATUS);
break;
case LOGIN:
case STATUS -> protocol.setState(ProtocolState.STATUS);
case LOGIN -> {
protocol.setState(ProtocolState.LOGIN);
if (intentionPacket.getProtocolVersion() > protocol.getCodec().getProtocolVersion()) {
session.disconnect("Outdated server! I'm still on " + protocol.getCodec().getMinecraftVersion() + ".");
} else if (intentionPacket.getProtocolVersion() < protocol.getCodec().getProtocolVersion()) {
session.disconnect("Outdated client! Please use " + protocol.getCodec().getMinecraftVersion() + ".");
}
break;
default:
}
default ->
throw new UnsupportedOperationException("Invalid client intent: " + intentionPacket.getIntent());
}
}
} else if (protocol.getState() == ProtocolState.LOGIN) {
if (packet instanceof ServerboundHelloPacket) {
this.username = ((ServerboundHelloPacket) packet).getUsername();
if (packet instanceof ServerboundHelloPacket helloPacket) {
this.username = helloPacket.getUsername();
if (session.getFlag(MinecraftConstants.VERIFY_USERS_KEY, true)) {
session.send(new ClientboundHelloPacket(SERVER_ID, KEY_PAIR.getPublic(), this.challenge));
} else {
new Thread(new UserAuthTask(session, null)).start();
}
} else if (packet instanceof ServerboundKeyPacket) {
ServerboundKeyPacket keyPacket = (ServerboundKeyPacket) packet;
} else if (packet instanceof ServerboundKeyPacket keyPacket) {
PrivateKey privateKey = KEY_PAIR.getPrivate();
if (!Arrays.equals(this.challenge, keyPacket.getEncryptedChallenge(privateKey))) {
@ -147,19 +143,19 @@ public class ServerListener extends SessionAdapter {
ServerStatusInfo info = builder.buildInfo(session);
session.send(new ClientboundStatusResponsePacket(info));
} else if (packet instanceof ServerboundPingRequestPacket) {
session.send(new ClientboundPongResponsePacket(((ServerboundPingRequestPacket) packet).getPingTime()));
} else if (packet instanceof ServerboundPingRequestPacket pingRequestPacket) {
session.send(new ClientboundPongResponsePacket(pingRequestPacket.getPingTime()));
}
} else if (protocol.getState() == ProtocolState.GAME) {
if (packet instanceof ServerboundKeepAlivePacket) {
if (((ServerboundKeepAlivePacket) packet).getPingId() == this.lastPingId) {
if (packet instanceof ServerboundKeepAlivePacket keepAlivePacket) {
if (keepAlivePacket.getPingId() == this.lastPingId) {
long time = System.currentTimeMillis() - this.lastPingTime;
session.setFlag(MinecraftConstants.PING_KEY, time);
}
} else if (packet instanceof ServerboundConfigurationAcknowledgedPacket) {
protocol.setState(ProtocolState.CONFIGURATION);
} else if (packet instanceof ServerboundPingRequestPacket) {
session.send(new ClientboundPongResponsePacket(((ServerboundPingRequestPacket) packet).getPingTime()));
} else if (packet instanceof ServerboundPingRequestPacket pingRequestPacket) {
session.send(new ClientboundPongResponsePacket(pingRequestPacket.getPingTime()));
}
} else if (protocol.getState() == ProtocolState.CONFIGURATION) {
if (packet instanceof ServerboundFinishConfigurationPacket) {
@ -178,9 +174,9 @@ public class ServerListener extends SessionAdapter {
@Override
public void packetSent(Session session, Packet packet) {
if (packet instanceof ClientboundLoginCompressionPacket) {
session.setCompressionThreshold(((ClientboundLoginCompressionPacket) packet).getThreshold(), true);
session.send(new ClientboundGameProfilePacket((GameProfile) session.getFlag(MinecraftConstants.PROFILE_KEY)));
if (packet instanceof ClientboundLoginCompressionPacket loginCompressionPacket) {
session.setCompressionThreshold(loginCompressionPacket.getThreshold(), true);
session.send(new ClientboundGameProfilePacket(session.getFlag(MinecraftConstants.PROFILE_KEY)));
}
}
@ -194,14 +190,10 @@ public class ServerListener extends SessionAdapter {
}
}
@RequiredArgsConstructor
private class UserAuthTask implements Runnable {
private Session session;
private SecretKey key;
public UserAuthTask(Session session, SecretKey key) {
this.key = key;
this.session = session;
}
private final Session session;
private final SecretKey key;
@Override
public void run() {
@ -229,12 +221,9 @@ public class ServerListener extends SessionAdapter {
}
}
@RequiredArgsConstructor
private class KeepAliveTask implements Runnable {
private Session session;
public KeepAliveTask(Session session) {
this.session = session;
}
private final Session session;
@Override
public void run() {

View file

@ -12,5 +12,5 @@ public interface ServerLoginHandler {
*
* @param session Session that logged in.
*/
public void loggedIn(Session session);
void loggedIn(Session session);
}

View file

@ -70,11 +70,11 @@ import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import lombok.RequiredArgsConstructor;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.math.vector.Vector3i;
import org.cloudburstmc.math.vector.Vector4f;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
import java.io.InputStream;
@ -193,7 +193,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
return readAnyTag(buf, CompoundTag.class);
}
@NotNull
@NonNull
public CompoundTag readAnyTagOrThrow(ByteBuf buf) throws IOException {
CompoundTag tag = readAnyTag(buf);
if (tag == null) {
@ -221,10 +221,11 @@ 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) throws IOException {
public void write(int b) {
buf.writeByte(b);
}
}, tag);
@ -241,7 +242,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
return new ItemStack(item, buf.readByte(), this.readAnyTag(buf));
}
public void writeItemStack(ByteBuf buf, ItemStack item) throws IOException {
public void writeItemStack(ByteBuf buf, @Nullable ItemStack item) throws IOException {
buf.writeBoolean(item != null);
if (item != null) {
this.writeVarInt(buf, item.getId());
@ -357,7 +358,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
ret.add(this.readMetadata(buf, id));
}
return ret.toArray(new EntityMetadata[0]);
return ret.toArray(new EntityMetadata<?, ?>[0]);
}
public void writeEntityMetadata(ByteBuf buf, EntityMetadata<?, ?>[] metadata) throws IOException {
@ -447,105 +448,96 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
}
public ParticleData readParticleData(ByteBuf buf, ParticleType type) throws IOException {
switch (type) {
case BLOCK:
case BLOCK_MARKER:
return new BlockParticleData(this.readVarInt(buf));
case DUST:
return switch (type) {
case BLOCK, BLOCK_MARKER -> new BlockParticleData(this.readVarInt(buf));
case DUST -> {
float red = buf.readFloat();
float green = buf.readFloat();
float blue = buf.readFloat();
float scale = buf.readFloat();
yield new DustParticleData(red, green, blue, scale);
}
case DUST_COLOR_TRANSITION -> {
float red = buf.readFloat();
float green = buf.readFloat();
float blue = buf.readFloat();
float scale = buf.readFloat();
return new DustParticleData(red, green, blue, scale);
case DUST_COLOR_TRANSITION:
red = buf.readFloat();
green = buf.readFloat();
blue = buf.readFloat();
scale = buf.readFloat();
float newRed = buf.readFloat();
float newGreen = buf.readFloat();
float newBlue = buf.readFloat();
return new DustColorTransitionParticleData(red, green, blue, scale, newRed, newGreen, newBlue);
case FALLING_DUST:
return new FallingDustParticleData(this.readVarInt(buf));
case ITEM:
return new ItemParticleData(this.readItemStack(buf));
case SCULK_CHARGE:
return new SculkChargeParticleData(buf.readFloat());
case SHRIEK:
return new ShriekParticleData(this.readVarInt(buf));
case VIBRATION:
return new VibrationParticleData(this.readPositionSource(buf), this.readVarInt(buf));
default:
return null;
yield new DustColorTransitionParticleData(red, green, blue, scale, newRed, newGreen, newBlue);
}
case FALLING_DUST -> new FallingDustParticleData(this.readVarInt(buf));
case ITEM -> new ItemParticleData(this.readItemStack(buf));
case SCULK_CHARGE -> new SculkChargeParticleData(buf.readFloat());
case SHRIEK -> new ShriekParticleData(this.readVarInt(buf));
case VIBRATION -> new VibrationParticleData(this.readPositionSource(buf), this.readVarInt(buf));
default -> null;
};
}
public void writeParticleData(ByteBuf buf, ParticleType type, ParticleData data) throws IOException {
switch (type) {
case BLOCK:
case BLOCK_MARKER:
this.writeVarInt(buf, ((BlockParticleData) data).getBlockState());
break;
case DUST:
buf.writeFloat(((DustParticleData) data).getRed());
buf.writeFloat(((DustParticleData) data).getGreen());
buf.writeFloat(((DustParticleData) data).getBlue());
buf.writeFloat(((DustParticleData) data).getScale());
break;
case DUST_COLOR_TRANSITION:
buf.writeFloat(((DustParticleData) data).getRed());
buf.writeFloat(((DustParticleData) data).getGreen());
buf.writeFloat(((DustParticleData) data).getBlue());
buf.writeFloat(((DustParticleData) data).getScale());
buf.writeFloat(((DustColorTransitionParticleData) data).getNewRed());
buf.writeFloat(((DustColorTransitionParticleData) data).getNewGreen());
buf.writeFloat(((DustColorTransitionParticleData) data).getNewBlue());
break;
case FALLING_DUST:
this.writeVarInt(buf, ((FallingDustParticleData) data).getBlockState());
break;
case ITEM:
this.writeItemStack(buf, ((ItemParticleData) data).getItemStack());
break;
case SCULK_CHARGE:
buf.writeFloat(((SculkChargeParticleData) data).getRoll());
break;
case SHRIEK:
this.writeVarInt(buf, ((ShriekParticleData) data).getDelay());
break;
case VIBRATION:
this.writePositionSource(buf, ((VibrationParticleData) data).getPositionSource());
this.writeVarInt(buf, ((VibrationParticleData) data).getArrivalTicks());
break;
case BLOCK, BLOCK_MARKER -> this.writeVarInt(buf, ((BlockParticleData) data).getBlockState());
case DUST -> {
DustParticleData dust = (DustParticleData) data;
buf.writeFloat(dust.getRed());
buf.writeFloat(dust.getGreen());
buf.writeFloat(dust.getBlue());
buf.writeFloat(dust.getScale());
}
case DUST_COLOR_TRANSITION -> {
DustColorTransitionParticleData dust = (DustColorTransitionParticleData) data;
buf.writeFloat(dust.getRed());
buf.writeFloat(dust.getGreen());
buf.writeFloat(dust.getBlue());
buf.writeFloat(dust.getScale());
buf.writeFloat(dust.getNewRed());
buf.writeFloat(dust.getNewGreen());
buf.writeFloat(dust.getNewBlue());
}
case FALLING_DUST -> {
FallingDustParticleData fallingDust = (FallingDustParticleData) data;
this.writeVarInt(buf, fallingDust.getBlockState());
}
case ITEM -> {
ItemParticleData item = (ItemParticleData) data;
this.writeItemStack(buf, item.getItemStack());
}
case SCULK_CHARGE -> {
SculkChargeParticleData sculkCharge = (SculkChargeParticleData) data;
buf.writeFloat(sculkCharge.getRoll());
}
case SHRIEK -> {
ShriekParticleData shriek = (ShriekParticleData) data;
this.writeVarInt(buf, shriek.getDelay());
}
case VIBRATION -> {
VibrationParticleData vibration = (VibrationParticleData) data;
this.writePositionSource(buf, vibration.getPositionSource());
this.writeVarInt(buf, vibration.getArrivalTicks());
}
}
}
public NumberFormat readNumberFormat(ByteBuf buf) throws IOException {
int id = this.readVarInt(buf);
switch (id) {
case 0:
return BlankFormat.INSTANCE;
case 1:
return new StyledFormat(this.readAnyTagOrThrow(buf));
case 2:
return new FixedFormat(this.readComponent(buf));
default:
throw new IllegalArgumentException("Unknown number format type: " + id);
}
return switch (id) {
case 0 -> BlankFormat.INSTANCE;
case 1 -> new StyledFormat(this.readAnyTagOrThrow(buf));
case 2 -> new FixedFormat(this.readComponent(buf));
default -> throw new IllegalArgumentException("Unknown number format type: " + id);
};
}
public void writeNumberFormat(ByteBuf buf, NumberFormat numberFormat) throws IOException {
if (numberFormat instanceof BlankFormat) {
this.writeVarInt(buf, 0);
} else if (numberFormat instanceof StyledFormat) {
StyledFormat styledFormat = (StyledFormat) numberFormat;
} else if (numberFormat instanceof StyledFormat styledFormat) {
this.writeVarInt(buf, 1);
this.writeAnyTag(buf, styledFormat.getStyle());
} else if (numberFormat instanceof FixedFormat) {
FixedFormat fixedFormat = (FixedFormat) numberFormat;
} else if (numberFormat instanceof FixedFormat fixedFormat) {
this.writeVarInt(buf, 2);
this.writeComponent(buf, fixedFormat.getValue());
} else {
@ -555,23 +547,19 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
public PositionSource readPositionSource(ByteBuf buf) {
PositionSourceType type = PositionSourceType.from(this.readVarInt(buf));
switch (type) {
case BLOCK:
return new BlockPositionSource(this.readPosition(buf));
case ENTITY:
return new EntityPositionSource(this.readVarInt(buf), buf.readFloat());
default:
throw new IllegalStateException("Unknown position source type!");
}
return switch (type) {
case BLOCK -> new BlockPositionSource(this.readPosition(buf));
case ENTITY -> new EntityPositionSource(this.readVarInt(buf), buf.readFloat());
};
}
public void writePositionSource(ByteBuf buf, PositionSource positionSource) {
this.writeVarInt(buf, positionSource.getType().ordinal());
if (positionSource instanceof BlockPositionSource) {
this.writePosition(buf, ((BlockPositionSource) positionSource).getPosition());
} else if (positionSource instanceof EntityPositionSource) {
this.writeVarInt(buf, ((EntityPositionSource) positionSource).getEntityId());
buf.writeFloat(((EntityPositionSource) positionSource).getYOffset());
if (positionSource instanceof BlockPositionSource blockPositionSource) {
this.writePosition(buf, blockPositionSource.getPosition());
} else if (positionSource instanceof EntityPositionSource entityPositionSource) {
this.writeVarInt(buf, entityPositionSource.getEntityId());
buf.writeFloat(entityPositionSource.getYOffset());
} else {
throw new IllegalStateException("Unknown position source type!");
}
@ -620,7 +608,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
}
}
@NotNull
@NonNull
public BlockEntityType readBlockEntityType(ByteBuf buf) {
int id = this.readVarInt(buf);
BlockEntityType type = BlockEntityType.from(id);
@ -784,7 +772,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
this.writeLongArray(buf, data);
}
private Palette readPalette(ByteBuf buf, PaletteType paletteType, int bitsPerEntry) throws IOException {
private Palette readPalette(ByteBuf buf, PaletteType paletteType, int bitsPerEntry) {
if (bitsPerEntry == 0) {
return new SingletonPalette(this.readVarInt(buf));
}

View file

@ -19,8 +19,8 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.google.gson.internal.LazilyParsedNumber;
import lombok.AllArgsConstructor;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.HashSet;
@ -207,15 +207,13 @@ public class NbtComponentSerializer {
convertCompoundTagEntry(entry.getName(), entry, object);
}
return object;
} else if (tag instanceof ListTag) {
final ListTag list = (ListTag) tag;
} else if (tag instanceof ListTag list) {
final JsonArray array = new JsonArray();
for (final Tag listEntry : list) {
array.add(convertToJson(null, listEntry));
}
return array;
} else if (tag.getValue() instanceof Number) {
final Number number = (Number) tag.getValue();
} else if (tag.getValue() instanceof Number number) {
if (key != null && BOOLEAN_TYPES.contains(key)) {
// Booleans don't have a direct representation in nbt
return new JsonPrimitive(number.byteValue() != 0);
@ -223,22 +221,19 @@ public class NbtComponentSerializer {
return new JsonPrimitive(number);
} else if (tag instanceof StringTag) {
return new JsonPrimitive(((StringTag) tag).getValue());
} else if (tag instanceof ByteArrayTag) {
final ByteArrayTag arrayTag = (ByteArrayTag) tag;
} else if (tag instanceof ByteArrayTag arrayTag) {
final JsonArray array = new JsonArray();
for (final byte num : arrayTag.getValue()) {
array.add(num);
}
return array;
} else if (tag instanceof IntArrayTag) {
final IntArrayTag arrayTag = (IntArrayTag) tag;
} else if (tag instanceof IntArrayTag arrayTag) {
final JsonArray array = new JsonArray();
for (final int num : arrayTag.getValue()) {
array.add(num);
}
return array;
} else if (tag instanceof LongArrayTag) {
final LongArrayTag arrayTag = (LongArrayTag) tag;
} else if (tag instanceof LongArrayTag arrayTag) {
final JsonArray array = new JsonArray();
for (final long num : arrayTag.getValue()) {
array.add(num);
@ -249,9 +244,8 @@ public class NbtComponentSerializer {
}
private static void convertCompoundTagEntry(final String key, final Tag tag, final JsonObject object) {
if ((key.equals("contents")) && tag instanceof CompoundTag) {
if ((key.equals("contents")) && tag instanceof CompoundTag showEntity) {
// Back to a UUID string
final CompoundTag showEntity = (CompoundTag) tag;
final Tag idTag = showEntity.get("id");
if (idTag instanceof IntArrayTag) {
showEntity.remove("id");

View file

@ -7,6 +7,8 @@ import com.github.steveice10.packetlib.codec.PacketCodecHelper;
import com.github.steveice10.packetlib.codec.PacketDefinition;
import com.github.steveice10.packetlib.packet.PacketHeader;
import com.github.steveice10.packetlib.packet.PacketProtocol;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.HashMap;
import java.util.Map;
@ -43,8 +45,8 @@ public class PacketStateCodec extends PacketProtocol {
}
public static class Builder {
private final Map<Integer, PacketDefinition<? extends MinecraftPacket, MinecraftCodecHelper>> clientboundPackets = new HashMap<>();
private final Map<Integer, PacketDefinition<? extends MinecraftPacket, MinecraftCodecHelper>> serverboundPackets = new HashMap<>();
private final Int2ObjectMap<PacketDefinition<? extends MinecraftPacket, MinecraftCodecHelper>> clientboundPackets = new Int2ObjectOpenHashMap<>();
private final Int2ObjectMap<PacketDefinition<? extends MinecraftPacket, MinecraftCodecHelper>> serverboundPackets = new Int2ObjectOpenHashMap<>();
private int nextClientboundId = 0x00;
private int nextServerboundId = 0x00;
@ -73,11 +75,11 @@ public class PacketStateCodec extends PacketProtocol {
public PacketStateCodec build() {
PacketStateCodec codec = new PacketStateCodec();
for (Map.Entry<Integer, PacketDefinition<? extends MinecraftPacket, MinecraftCodecHelper>> entry : this.clientboundPackets.entrySet()) {
for (Int2ObjectMap.Entry<PacketDefinition<? extends MinecraftPacket, MinecraftCodecHelper>> entry : this.clientboundPackets.int2ObjectEntrySet()) {
codec.registerClientbound(entry.getValue());
}
for (Map.Entry<Integer, PacketDefinition<? extends MinecraftPacket, MinecraftCodecHelper>> entry : this.serverboundPackets.entrySet()) {
for (Int2ObjectMap.Entry<PacketDefinition<? extends MinecraftPacket, MinecraftCodecHelper>> entry : this.serverboundPackets.int2ObjectEntrySet()) {
codec.registerServerbound(entry.getValue());
}

View file

@ -1,10 +1,15 @@
package com.github.steveice10.mc.protocol.data;
import java.io.Serial;
/**
* Thrown whenever a ClientboundHelloPacket is sent when we aren't expecting it
* (I.E.: online mode server and offline mode client)
*/
public class UnexpectedEncryptionException extends IllegalStateException {
@Serial
private static final long serialVersionUID = 1L;
public UnexpectedEncryptionException() {
super("Cannot reply to ClientboundHelloPacket without profile and access token.");
}

View file

@ -6,7 +6,7 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.security.PublicKey;
import java.util.UUID;

View file

@ -5,7 +5,7 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;

View file

@ -4,7 +4,7 @@ import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
@Data
@AllArgsConstructor

View file

@ -1,7 +1,7 @@
package com.github.steveice10.mc.protocol.data.game.chunk;
import lombok.*;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Arrays;

View file

@ -7,7 +7,7 @@ import lombok.NonNull;
@Data
@AllArgsConstructor
public class NibbleArray3d {
private final @NonNull byte[] data;
private final byte @NonNull [] data;
public NibbleArray3d(int size) {
this(new byte[size >> 1]);

View file

@ -7,7 +7,6 @@ import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import java.io.IOException;
import java.util.Arrays;
/**
@ -17,18 +16,18 @@ import java.util.Arrays;
@EqualsAndHashCode
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class ListPalette implements Palette {
private final int maxId;
private final int capacity;
private final int[] data;
private int nextId = 0;
public ListPalette(int bitsPerEntry) {
this.maxId = (1 << bitsPerEntry) - 1;
this.capacity = 1 << bitsPerEntry;
this.data = new int[this.maxId + 1];
this.data = new int[this.capacity];
}
public ListPalette(int bitsPerEntry, ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ListPalette(int bitsPerEntry, ByteBuf in, MinecraftCodecHelper helper) {
this(bitsPerEntry);
int paletteLength = helper.readVarInt(in);
@ -53,7 +52,7 @@ public class ListPalette implements Palette {
break;
}
}
if (id == -1 && this.size() < this.maxId + 1) {
if (id == -1 && this.size() < this.capacity) {
id = this.nextId++;
this.data[id] = state;
}
@ -72,6 +71,6 @@ public class ListPalette implements Palette {
@Override
public ListPalette copy() {
return new ListPalette(this.maxId, Arrays.copyOf(this.data, this.data.length), this.nextId);
return new ListPalette(this.capacity, Arrays.copyOf(this.data, this.data.length), this.nextId);
}
}

View file

@ -2,13 +2,12 @@ package com.github.steveice10.mc.protocol.data.game.chunk.palette;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import io.netty.buffer.ByteBuf;
import io.netty.util.collection.IntObjectHashMap;
import io.netty.util.collection.IntObjectMap;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import java.io.IOException;
import java.util.Arrays;
/**
@ -17,19 +16,21 @@ import java.util.Arrays;
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@EqualsAndHashCode
public class MapPalette implements Palette {
private final int maxId;
private static final int MISSING_ID = -1;
private final int capacity;
private final int[] idToState;
private final IntObjectMap<Integer> stateToId = new IntObjectHashMap<>();
private final Int2IntMap stateToId = new Int2IntOpenHashMap();
private int nextId = 0;
public MapPalette(int bitsPerEntry) {
this.maxId = (1 << bitsPerEntry) - 1;
this.capacity = 1 << bitsPerEntry;
this.idToState = new int[this.maxId + 1];
this.idToState = new int[this.capacity];
this.stateToId.defaultReturnValue(MISSING_ID);
}
public MapPalette(int bitsPerEntry, ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public MapPalette(int bitsPerEntry, ByteBuf in, MinecraftCodecHelper helper) {
this(bitsPerEntry);
int paletteLength = helper.readVarInt(in);
@ -48,18 +49,14 @@ public class MapPalette implements Palette {
@Override
public int stateToId(int state) {
Integer id = this.stateToId.get(state);
if (id == null && this.size() < this.maxId + 1) {
int id = this.stateToId.get(state);
if (id == MISSING_ID && this.size() < this.capacity) {
id = this.nextId++;
this.idToState[id] = state;
this.stateToId.put(state, id);
}
if (id != null) {
return id;
} else {
return -1;
}
}
@Override
@ -73,7 +70,7 @@ public class MapPalette implements Palette {
@Override
public MapPalette copy() {
MapPalette mapPalette = new MapPalette(this.maxId, Arrays.copyOf(this.idToState, this.idToState.length), this.nextId);
MapPalette mapPalette = new MapPalette(this.capacity, Arrays.copyOf(this.idToState, this.idToState.length), this.nextId);
mapPalette.stateToId.putAll(this.stateToId);
return mapPalette;
}

View file

@ -1,18 +1,16 @@
package com.github.steveice10.mc.protocol.data.game.chunk.palette;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;
/**
* A palette containing one state.
*/
@EqualsAndHashCode
@RequiredArgsConstructor
public class SingletonPalette implements Palette {
private final int state;
public SingletonPalette(int state) {
this.state = state;
}
@Override
public int size() {
return 1;
@ -20,18 +18,12 @@ public class SingletonPalette implements Palette {
@Override
public int stateToId(int state) {
if (this.state == state) {
return 0;
}
return -1;
return this.state == state ? 0 : -1;
}
@Override
public int idToState(int id) {
if (id == 0) {
return this.state;
}
return 0;
return id == 0 ? this.state : 0;
}
@Override

View file

@ -23,7 +23,7 @@ public class CommandNode {
/**
* Child node indices.
*/
private final @NonNull int[] childIndices;
private final int @NonNull [] childIndices;
/**
* Redirect index, or empty if none is set.

View file

@ -1,7 +1,7 @@
package com.github.steveice10.mc.protocol.data.game.command;
import com.github.steveice10.mc.protocol.data.game.Identifier;
import org.jetbrains.annotations.NotNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.HashMap;
import java.util.Locale;
@ -25,7 +25,7 @@ public enum SuggestionType {
private static final Map<String, SuggestionType> VALUES = new HashMap<>();
@NotNull
@NonNull
public static SuggestionType from(String resourceLocation) {
// Vanilla behavior as of 1.19.3
// 1.16.5 still has AVAILABLE_BIOMES and vanilla doesn't care

View file

@ -4,8 +4,6 @@ import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
public class BooleanMetadataType extends MetadataType<Boolean> {
private final BooleanReader primitiveReader;
private final BooleanWriter primitiveWriter;
@ -20,32 +18,32 @@ public class BooleanMetadataType extends MetadataType<Boolean> {
}
@Override
public EntityMetadata<Boolean, BooleanMetadataType> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) throws IOException {
public EntityMetadata<Boolean, BooleanMetadataType> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) {
return this.primitiveFactory.createPrimitive(id, this, this.primitiveReader.readPrimitive(input));
}
public void writeMetadataPrimitive(ByteBuf output, boolean value) throws IOException {
public void writeMetadataPrimitive(ByteBuf output, boolean value) {
this.primitiveWriter.writePrimitive(output, value);
}
@FunctionalInterface
public interface BooleanReader extends BasicReader<Boolean> {
boolean readPrimitive(ByteBuf input) throws IOException;
boolean readPrimitive(ByteBuf input);
@Deprecated
@Override
default Boolean read(ByteBuf input) throws IOException {
default Boolean read(ByteBuf input) {
return this.readPrimitive(input);
}
}
@FunctionalInterface
public interface BooleanWriter extends BasicWriter<Boolean> {
void writePrimitive(ByteBuf output, boolean value) throws IOException;
void writePrimitive(ByteBuf output, boolean value);
@Deprecated
@Override
default void write(ByteBuf output, Boolean value) throws IOException {
default void write(ByteBuf output, Boolean value) {
this.writePrimitive(output, value);
}
}

View file

@ -4,8 +4,6 @@ import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
public class ByteMetadataType extends MetadataType<Byte> {
private final ByteReader primitiveReader;
private final ByteWriter primitiveWriter;
@ -20,32 +18,32 @@ public class ByteMetadataType extends MetadataType<Byte> {
}
@Override
public EntityMetadata<Byte, ByteMetadataType> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) throws IOException {
public EntityMetadata<Byte, ByteMetadataType> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) {
return this.primitiveFactory.createPrimitive(id, this, this.primitiveReader.readPrimitive(input));
}
public void writeMetadataPrimitive(ByteBuf output, byte value) throws IOException {
public void writeMetadataPrimitive(ByteBuf output, byte value) {
this.primitiveWriter.writePrimitive(output, value);
}
@FunctionalInterface
public interface ByteReader extends BasicReader<Byte> {
byte readPrimitive(ByteBuf input) throws IOException;
byte readPrimitive(ByteBuf input);
@Deprecated
@Override
default Byte read(ByteBuf input) throws IOException {
default Byte read(ByteBuf input) {
return this.readPrimitive(input);
}
}
@FunctionalInterface
public interface ByteWriter extends BasicWriter<Byte> {
void writePrimitive(ByteBuf output, byte value) throws IOException;
void writePrimitive(ByteBuf output, byte value);
@Deprecated
@Override
default void write(ByteBuf output, Byte value) throws IOException {
default void write(ByteBuf output, Byte value) {
this.writePrimitive(output, value);
}
}

View file

@ -39,10 +39,9 @@ public abstract class EntityMetadata<V, T extends MetadataType<V>> {
if (this == o) {
return true;
}
if (!(o instanceof EntityMetadata)) {
if (!(o instanceof EntityMetadata<?, ?> that)) {
return false;
}
EntityMetadata<?, ?> that = (EntityMetadata<?, ?>) o;
return this.id == that.id && this.type == that.type && Objects.equals(this.getValue(), that.getValue());
}

View file

@ -4,7 +4,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.EquipmentSlot;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
@Data
@AllArgsConstructor

View file

@ -4,8 +4,6 @@ import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.FloatEntityMetadata;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
public class FloatMetadataType extends MetadataType<Float> {
private final FloatReader primitiveReader;
private final FloatWriter primitiveWriter;
@ -20,32 +18,32 @@ public class FloatMetadataType extends MetadataType<Float> {
}
@Override
public EntityMetadata<Float, FloatMetadataType> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) throws IOException {
public EntityMetadata<Float, FloatMetadataType> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) {
return this.primitiveFactory.createPrimitive(id, this, this.primitiveReader.readPrimitive(input));
}
public void writeMetadataPrimitive(ByteBuf output, float value) throws IOException {
public void writeMetadataPrimitive(ByteBuf output, float value) {
this.primitiveWriter.writePrimitive(output, value);
}
@FunctionalInterface
public interface FloatReader extends BasicReader<Float> {
float readPrimitive(ByteBuf input) throws IOException;
float readPrimitive(ByteBuf input);
@Deprecated
@Override
default Float read(ByteBuf input) throws IOException {
default Float read(ByteBuf input) {
return this.readPrimitive(input);
}
}
@FunctionalInterface
public interface FloatWriter extends BasicWriter<Float> {
void writePrimitive(ByteBuf output, float value) throws IOException;
void writePrimitive(ByteBuf output, float value);
@Deprecated
@Override
default void write(ByteBuf output, Float value) throws IOException {
default void write(ByteBuf output, Float value) {
this.writePrimitive(output, value);
}
}

View file

@ -4,8 +4,6 @@ import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
public class IntMetadataType extends MetadataType<Integer> {
private final IntReader primitiveReader;
private final IntWriter primitiveWriter;
@ -20,32 +18,32 @@ public class IntMetadataType extends MetadataType<Integer> {
}
@Override
public EntityMetadata<Integer, IntMetadataType> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) throws IOException {
public EntityMetadata<Integer, IntMetadataType> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) {
return this.primitiveFactory.createPrimitive(id, this, this.primitiveReader.readPrimitive(helper, input));
}
public void writeMetadataPrimitive(MinecraftCodecHelper helper, ByteBuf output, int value) throws IOException {
public void writeMetadataPrimitive(MinecraftCodecHelper helper, ByteBuf output, int value) {
this.primitiveWriter.writePrimitive(helper, output, value);
}
@FunctionalInterface
public interface IntReader extends Reader<Integer> {
int readPrimitive(MinecraftCodecHelper helper, ByteBuf input) throws IOException;
int readPrimitive(MinecraftCodecHelper helper, ByteBuf input);
@Deprecated
@Override
default Integer read(MinecraftCodecHelper helper, ByteBuf input) throws IOException {
default Integer read(MinecraftCodecHelper helper, ByteBuf input) {
return this.readPrimitive(helper, input);
}
}
@FunctionalInterface
public interface IntWriter extends Writer<Integer> {
void writePrimitive(MinecraftCodecHelper helper, ByteBuf output, int value) throws IOException;
void writePrimitive(MinecraftCodecHelper helper, ByteBuf output, int value);
@Deprecated
@Override
default void write(MinecraftCodecHelper helper, ByteBuf output, Integer value) throws IOException {
default void write(MinecraftCodecHelper helper, ByteBuf output, Integer value) {
this.writePrimitive(helper, output, value);
}
}

View file

@ -3,7 +3,7 @@ package com.github.steveice10.mc.protocol.data.game.entity.metadata;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
@Data
@AllArgsConstructor

View file

@ -4,8 +4,6 @@ import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.LongEntityMetadata;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
public class LongMetadataType extends MetadataType<Long> {
private final LongReader primitiveReader;
private final LongWriter primitiveWriter;
@ -20,32 +18,32 @@ public class LongMetadataType extends MetadataType<Long> {
}
@Override
public EntityMetadata<Long, LongMetadataType> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) throws IOException {
public EntityMetadata<Long, LongMetadataType> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) {
return this.primitiveFactory.createPrimitive(id, this, this.primitiveReader.readPrimitive(helper, input));
}
public void writeMetadataPrimitive(MinecraftCodecHelper helper, ByteBuf output, long value) throws IOException {
public void writeMetadataPrimitive(MinecraftCodecHelper helper, ByteBuf output, long value) {
this.primitiveWriter.writePrimitive(helper, output, value);
}
@FunctionalInterface
public interface LongReader extends Reader<Long> {
long readPrimitive(MinecraftCodecHelper helper, ByteBuf input) throws IOException;
long readPrimitive(MinecraftCodecHelper helper, ByteBuf input);
@Deprecated
@Override
default Long read(MinecraftCodecHelper helper, ByteBuf input) throws IOException {
default Long read(MinecraftCodecHelper helper, ByteBuf input) {
return this.readPrimitive(helper, input);
}
}
@FunctionalInterface
public interface LongWriter extends Writer<Long> {
void writePrimitive(MinecraftCodecHelper helper, ByteBuf output, long value) throws IOException;
void writePrimitive(MinecraftCodecHelper helper, ByteBuf output, long value);
@Deprecated
@Override
default void write(MinecraftCodecHelper helper, ByteBuf output, Long value) throws IOException {
default void write(MinecraftCodecHelper helper, ByteBuf output, Long value) {
this.writePrimitive(helper, output, value);
}
}

View file

@ -150,7 +150,7 @@ public class MetadataType<T> {
};
}
public static MetadataType<?> read(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public static MetadataType<?> read(ByteBuf in, MinecraftCodecHelper helper) {
int id = helper.readVarInt(in);
if (id >= VALUES.size()) {
throw new IllegalArgumentException("Received id " + id + " for MetadataType when the maximum was " + VALUES.size() + "!");

View file

@ -3,7 +3,6 @@ package com.github.steveice10.mc.protocol.data.game.entity.metadata;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
import java.util.OptionalInt;
public class OptionalIntMetadataType extends MetadataType<OptionalInt> {
@ -15,7 +14,7 @@ public class OptionalIntMetadataType extends MetadataType<OptionalInt> {
protected static final OptionalIntReader INSTANCE = new OptionalIntReader();
@Override
public OptionalInt read(MinecraftCodecHelper helper, ByteBuf input) throws IOException {
public OptionalInt read(MinecraftCodecHelper helper, ByteBuf input) {
int value = helper.readVarInt(input);
if (value == 0) {
return OptionalInt.empty();
@ -29,7 +28,7 @@ public class OptionalIntMetadataType extends MetadataType<OptionalInt> {
protected static final OptionalIntWriter INSTANCE = new OptionalIntWriter();
@Override
public void write(MinecraftCodecHelper helper, ByteBuf output, OptionalInt value) throws IOException {
public void write(MinecraftCodecHelper helper, ByteBuf output, OptionalInt value) {
if (value.isPresent()) {
helper.writeVarInt(output, value.getAsInt() + 1);
} else {

View file

@ -3,7 +3,6 @@ package com.github.steveice10.mc.protocol.data.game.entity.metadata.type;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.IntMetadataType;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType;
import io.netty.buffer.ByteBuf;
import lombok.NonNull;

View file

@ -2,7 +2,7 @@ package com.github.steveice10.mc.protocol.data.game.entity.player;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
public enum Animation {
SWING_ARM(0),

View file

@ -1,7 +1,7 @@
package com.github.steveice10.mc.protocol.data.game.entity.player;
import com.github.steveice10.mc.protocol.data.game.level.notify.GameEventValue;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
public enum GameMode implements GameEventValue {
SURVIVAL,

View file

@ -4,7 +4,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.GlobalPos;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
@Data
@AllArgsConstructor

View file

@ -25,7 +25,7 @@ public enum MoveToHotbarAction implements ContainerAction {
return id;
}
private static Int2ObjectMap<MoveToHotbarAction> VALUES = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<MoveToHotbarAction> VALUES = new Int2ObjectOpenHashMap<>();
public static MoveToHotbarAction from(int id) {
return VALUES.get(id);

View file

@ -24,7 +24,7 @@ public enum SpreadItemAction implements ContainerAction {
return id;
}
private static Int2ObjectMap<SpreadItemAction> VALUES = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<SpreadItemAction> VALUES = new Int2ObjectOpenHashMap<>();
public static SpreadItemAction from(int id) {
return VALUES.get(id);

View file

@ -3,7 +3,7 @@ package com.github.steveice10.mc.protocol.data.game.inventory;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
@Data
@AllArgsConstructor

View file

@ -21,11 +21,11 @@ public class LightUpdateData {
private final @NonNull List<byte[]> skyUpdates;
private final @NonNull List<byte[]> blockUpdates;
public static LightUpdateData read(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public static LightUpdateData read(ByteBuf in, MinecraftCodecHelper helper) {
return new LightUpdateData(in, helper);
}
private LightUpdateData(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
private LightUpdateData(ByteBuf in, MinecraftCodecHelper helper) {
this.skyYMask = BitSet.valueOf(helper.readLongArray(in));
this.blockYMask = BitSet.valueOf(helper.readLongArray(in));
this.emptySkyYMask = BitSet.valueOf(helper.readLongArray(in));
@ -48,7 +48,7 @@ public class LightUpdateData {
data.write(out, helper);
}
private void write(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
private void write(ByteBuf out, MinecraftCodecHelper helper) {
writeBitSet(out, helper, this.skyYMask);
writeBitSet(out, helper, this.blockYMask);
writeBitSet(out, helper, this.emptySkyYMask);
@ -65,7 +65,7 @@ public class LightUpdateData {
}
}
private void writeBitSet(ByteBuf out, MinecraftCodecHelper helper, BitSet bitSet) throws IOException {
private void writeBitSet(ByteBuf out, MinecraftCodecHelper helper, BitSet bitSet) {
long[] array = bitSet.toLongArray();
helper.writeLongArray(out, array);
}

View file

@ -3,7 +3,7 @@ package com.github.steveice10.mc.protocol.data.game.level.block;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
@Data
@AllArgsConstructor

View file

@ -1,6 +1,6 @@
package com.github.steveice10.mc.protocol.data.game.level.block;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
public enum BlockEntityType {
FURNACE,

View file

@ -2,7 +2,6 @@ package com.github.steveice10.mc.protocol.data.game.level.event;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
@Data
@AllArgsConstructor

View file

@ -11,5 +11,5 @@ public class MapData {
private final int rows;
private final int x;
private final int y;
private final @NonNull byte data[];
private final byte @NonNull [] data;
}

View file

@ -20,7 +20,7 @@ public enum DemoMessageValue implements GameEventValue {
return this.id;
}
private static Int2ObjectMap<DemoMessageValue> VALUES = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<DemoMessageValue> VALUES = new Int2ObjectOpenHashMap<>();
public static DemoMessageValue from(int id) {
return VALUES.get(id);

View file

@ -3,7 +3,7 @@ package com.github.steveice10.mc.protocol.data.game.level.particle;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
@Data
@AllArgsConstructor

View file

@ -2,12 +2,12 @@ package com.github.steveice10.mc.protocol.data.game.level.sound;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.jetbrains.annotations.NotNull;
import lombok.NonNull;
@Data
@AllArgsConstructor
public class CustomSound implements Sound {
private final @NotNull String name;
private final @NonNull String name;
private final boolean newSystem;
private final float range;
}

View file

@ -4,7 +4,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
@Data
@AllArgsConstructor

View file

@ -6,7 +6,7 @@ import com.github.steveice10.mc.protocol.data.game.recipe.Ingredient;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
@Data
@AllArgsConstructor

View file

@ -6,7 +6,7 @@ import com.github.steveice10.mc.protocol.data.game.recipe.Ingredient;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
@Data
@AllArgsConstructor

View file

@ -6,7 +6,7 @@ import com.github.steveice10.mc.protocol.data.game.recipe.Ingredient;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
@Data
@AllArgsConstructor

View file

@ -5,7 +5,7 @@ import com.github.steveice10.mc.protocol.data.game.recipe.Ingredient;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
@Data
@AllArgsConstructor

View file

@ -5,7 +5,7 @@ import com.github.steveice10.mc.protocol.data.game.recipe.Ingredient;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
@Data
@AllArgsConstructor

View file

@ -4,5 +4,5 @@ import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
import com.github.steveice10.packetlib.Session;
public interface ServerInfoBuilder {
public ServerStatusInfo buildInfo(Session session);
ServerStatusInfo buildInfo(Session session);
}

View file

@ -4,5 +4,5 @@ import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
import com.github.steveice10.packetlib.Session;
public interface ServerInfoHandler {
public void handle(Session session, ServerStatusInfo info);
void handle(Session session, ServerStatusInfo info);
}

View file

@ -3,5 +3,5 @@ package com.github.steveice10.mc.protocol.data.status.handler;
import com.github.steveice10.packetlib.Session;
public interface ServerPingTimeHandler {
public void handle(Session session, long pingTime);
void handle(Session session, long pingTime);
}

View file

@ -8,8 +8,6 @@ import lombok.Data;
import lombok.NonNull;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -17,13 +15,13 @@ public class ClientboundCustomPayloadPacket implements MinecraftPacket {
private final @NonNull String channel;
private final byte @NonNull[] data;
public ClientboundCustomPayloadPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundCustomPayloadPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.channel = helper.readString(in);
this.data = helper.readByteArray(in, ByteBuf::readableBytes);
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeString(out, this.channel);
out.writeBytes(this.data);
}

View file

@ -7,20 +7,18 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
public class ClientboundKeepAlivePacket implements MinecraftPacket {
private final long pingId;
public ClientboundKeepAlivePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundKeepAlivePacket(ByteBuf in, MinecraftCodecHelper helper) {
this.pingId = in.readLong();
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
out.writeLong(this.pingId);
}
}

View file

@ -7,20 +7,18 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
public class ClientboundPingPacket implements MinecraftPacket {
private final int id;
public ClientboundPingPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundPingPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.id = in.readInt();
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
out.writeInt(this.id);
}
}

View file

@ -6,9 +6,8 @@ import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
import java.util.UUID;
@Data
@ -26,7 +25,7 @@ public class ClientboundResourcePackPopPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeNullable(out, this.id, helper::writeUUID);
}
}

View file

@ -8,7 +8,7 @@ import lombok.Data;
import lombok.NonNull;
import lombok.With;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
import java.util.UUID;

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;
@ -31,7 +30,7 @@ public class ServerboundClientInformationPacket implements MinecraftPacket {
*/
private final boolean allowsListing;
public ServerboundClientInformationPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ServerboundClientInformationPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.locale = helper.readString(in);
this.renderDistance = in.readByte();
this.chatVisibility = ChatVisibility.from(helper.readVarInt(in));
@ -52,7 +51,7 @@ public class ServerboundClientInformationPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeString(out, this.locale);
out.writeByte(this.renderDistance);
helper.writeVarInt(out, this.chatVisibility.ordinal());

View file

@ -8,8 +8,6 @@ import lombok.Data;
import lombok.NonNull;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -17,13 +15,13 @@ public class ServerboundCustomPayloadPacket implements MinecraftPacket {
private final @NonNull String channel;
private final byte @NonNull[] data;
public ServerboundCustomPayloadPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ServerboundCustomPayloadPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.channel = helper.readString(in);
this.data = helper.readByteArray(in, ByteBuf::readableBytes);
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeString(out, this.channel);
out.writeBytes(this.data);
}

View file

@ -7,20 +7,18 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
public class ServerboundKeepAlivePacket implements MinecraftPacket {
private final long pingId;
public ServerboundKeepAlivePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ServerboundKeepAlivePacket(ByteBuf in, MinecraftCodecHelper helper) {
this.pingId = in.readLong();
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
out.writeLong(this.pingId);
}

View file

@ -7,20 +7,18 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
public class ServerboundPongPacket implements MinecraftPacket {
private final int id;
public ServerboundPongPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ServerboundPongPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.id = in.readInt();
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
out.writeInt(this.id);
}
}

View file

@ -9,7 +9,6 @@ import lombok.Data;
import lombok.NonNull;
import lombok.With;
import java.io.IOException;
import java.util.UUID;
@Data
@ -20,13 +19,13 @@ public class ServerboundResourcePackPacket implements MinecraftPacket {
private final @NonNull UUID id;
private final @NonNull ResourcePackStatus status;
public ServerboundResourcePackPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ServerboundResourcePackPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.id = helper.readUUID(in);
this.status = ResourcePackStatus.from(helper.readVarInt(in));
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeUUID(out, id);
helper.writeVarInt(out, this.status.ordinal());
}

View file

@ -7,22 +7,20 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
public class ClientboundUpdateEnabledFeaturesPacket implements MinecraftPacket {
private final String[] features;
public ClientboundUpdateEnabledFeaturesPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundUpdateEnabledFeaturesPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.features = new String[helper.readVarInt(in)];
for (int i = 0; i < this.features.length; i++) {
this.features[i] = helper.readString(in);
}
}
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.features.length);
for (String feature : this.features) {
helper.writeString(out, feature);

View file

@ -9,8 +9,6 @@ import lombok.Data;
import lombok.NonNull;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -20,7 +18,7 @@ public class ClientIntentionPacket implements MinecraftPacket {
private final int port;
private final @NonNull HandshakeIntent intent;
public ClientIntentionPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientIntentionPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.protocolVersion = helper.readVarInt(in);
this.hostname = helper.readString(in);
this.port = in.readUnsignedShort();
@ -28,7 +26,7 @@ public class ClientIntentionPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.protocolVersion);
helper.writeString(out, this.hostname);
out.writeShort(this.port);

View file

@ -12,10 +12,6 @@ import lombok.Data;
import lombok.NonNull;
import lombok.With;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@Data
@With
@AllArgsConstructor
@ -27,44 +23,23 @@ public class ClientboundAwardStatsPacket implements MinecraftPacket {
for (int index = 0; index < length; index++) {
StatisticCategory category = helper.readStatisticCategory(in);
int statisticId = helper.readVarInt(in);
Statistic statistic;
switch (category) {
case BREAK_BLOCK:
statistic = new BreakBlockStatistic(statisticId);
break;
case CRAFT_ITEM:
statistic = new CraftItemStatistic(statisticId);
break;
case USE_ITEM:
statistic = new UseItemStatistic(statisticId);
break;
case BREAK_ITEM:
statistic = new BreakItemStatistic(statisticId);
break;
case PICKED_UP_ITEM:
statistic = new PickupItemStatistic(statisticId);
break;
case DROP_ITEM:
statistic = new DropItemStatistic(statisticId);
break;
case KILL_ENTITY:
statistic = new KillEntityStatistic(EntityType.from(statisticId));
break;
case KILLED_BY_ENTITY:
statistic = new KilledByEntityStatistic(EntityType.from(statisticId));
break;
case CUSTOM:
statistic = CustomStatistic.from(statisticId);
break;
default:
throw new IllegalStateException();
}
Statistic statistic = switch (category) {
case BREAK_BLOCK -> new BreakBlockStatistic(statisticId);
case CRAFT_ITEM -> new CraftItemStatistic(statisticId);
case USE_ITEM -> new UseItemStatistic(statisticId);
case BREAK_ITEM -> new BreakItemStatistic(statisticId);
case PICKED_UP_ITEM -> new PickupItemStatistic(statisticId);
case DROP_ITEM -> new DropItemStatistic(statisticId);
case KILL_ENTITY -> new KillEntityStatistic(EntityType.from(statisticId));
case KILLED_BY_ENTITY -> new KilledByEntityStatistic(EntityType.from(statisticId));
case CUSTOM -> CustomStatistic.from(statisticId);
};
this.statistics.put(statistic, helper.readVarInt(in));
}
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.statistics.size());
for (Object2IntMap.Entry<Statistic> entry : statistics.object2IntEntrySet()) {
Statistic statistic = entry.getKey();

View file

@ -2,7 +2,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.game.BossBarAction;
import com.github.steveice10.mc.protocol.data.game.BossBarColor;
import com.github.steveice10.mc.protocol.data.game.BossBarDivision;

View file

@ -6,7 +6,6 @@ import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.io.IOException;
import java.util.List;
@Data
@ -15,6 +14,6 @@ public class ClientboundBundlePacket implements MinecraftPacket {
private final List<MinecraftPacket> packets;
@Override
public void serialize(ByteBuf buf, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf buf, MinecraftCodecHelper helper) {
}
}

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 ClientboundChangeDifficultyPacket implements MinecraftPacket {
private final @NonNull Difficulty difficulty;
private final boolean difficultyLocked;
public ClientboundChangeDifficultyPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundChangeDifficultyPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.difficulty = Difficulty.from(in.readUnsignedByte());
this.difficultyLocked = in.readBoolean();
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
out.writeByte(this.difficulty.ordinal());
out.writeBoolean(this.difficultyLocked);
}

View file

@ -2,7 +2,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.NonNull;
@ -18,10 +17,10 @@ public class ClientboundCommandSuggestionsPacket implements MinecraftPacket {
private final int transactionId;
private final int start;
private final int length;
private final @NonNull String[] matches;
private final @NonNull Component[] tooltips;
private final @NonNull String @NonNull [] matches;
private final Component @NonNull [] tooltips;
public ClientboundCommandSuggestionsPacket(int transactionId, int start, int length, @NonNull String[] matches, @NonNull Component[] tooltips) {
public ClientboundCommandSuggestionsPacket(int transactionId, int start, int length, @NonNull String @NonNull [] matches, Component @NonNull [] tooltips) {
if (tooltips.length != matches.length) {
throw new IllegalArgumentException("Length of matches and tooltips must be equal.");
}

View file

@ -62,7 +62,7 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
if (type == CommandType.ARGUMENT) {
parser = CommandParser.from(helper.readVarInt(in));
switch (parser) {
case DOUBLE: {
case DOUBLE -> {
byte numberFlags = in.readByte();
double min = -Double.MAX_VALUE;
double max = Double.MAX_VALUE;
@ -75,9 +75,8 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
}
properties = new DoubleProperties(min, max);
break;
}
case FLOAT: {
case FLOAT -> {
byte numberFlags = in.readByte();
float min = -Float.MAX_VALUE;
float max = Float.MAX_VALUE;
@ -90,9 +89,8 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
}
properties = new FloatProperties(min, max);
break;
}
case INTEGER: {
case INTEGER -> {
byte numberFlags = in.readByte();
int min = Integer.MIN_VALUE;
int max = Integer.MAX_VALUE;
@ -105,9 +103,8 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
}
properties = new IntegerProperties(min, max);
break;
}
case LONG: {
case LONG -> {
byte numberFlags = in.readByte();
long min = Long.MIN_VALUE;
long max = Long.MAX_VALUE;
@ -120,31 +117,19 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
}
properties = new LongProperties(min, max);
break;
}
case STRING:
properties = StringProperties.from(helper.readVarInt(in));
break;
case ENTITY: {
case STRING -> properties = StringProperties.from(helper.readVarInt(in));
case ENTITY -> {
byte entityFlags = in.readByte();
properties = new EntityProperties((entityFlags & ENTITY_FLAG_SINGLE_TARGET) != 0,
(entityFlags & ENTITY_FLAG_PLAYERS_ONLY) != 0);
break;
}
case SCORE_HOLDER:
properties = new ScoreHolderProperties(in.readBoolean());
break;
case TIME:
properties = new TimeProperties(in.readInt());
break;
case RESOURCE_OR_TAG:
case RESOURCE_OR_TAG_KEY:
case RESOURCE:
case RESOURCE_KEY:
case SCORE_HOLDER -> properties = new ScoreHolderProperties(in.readBoolean());
case TIME -> properties = new TimeProperties(in.readInt());
case RESOURCE_OR_TAG, RESOURCE_OR_TAG_KEY, RESOURCE, RESOURCE_KEY ->
properties = new ResourceProperties(helper.readString(in));
break;
default:
break;
default -> {
}
}
if ((flags & FLAG_SUGGESTION_TYPE) != 0) {
@ -193,7 +178,7 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
if (node.getType() == CommandType.ARGUMENT) {
helper.writeVarInt(out, node.getParser().ordinal());
switch (node.getParser()) {
case DOUBLE: {
case DOUBLE -> {
DoubleProperties properties = (DoubleProperties) node.getProperties();
int numberFlags = 0;
@ -213,10 +198,8 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
if ((numberFlags & NUMBER_FLAG_MAX_DEFINED) != 0) {
out.writeDouble(properties.getMax());
}
break;
}
case FLOAT: {
case FLOAT -> {
FloatProperties properties = (FloatProperties) node.getProperties();
int numberFlags = 0;
@ -236,10 +219,8 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
if ((numberFlags & NUMBER_FLAG_MAX_DEFINED) != 0) {
out.writeFloat(properties.getMax());
}
break;
}
case INTEGER: {
case INTEGER -> {
IntegerProperties properties = (IntegerProperties) node.getProperties();
int numberFlags = 0;
@ -259,10 +240,8 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
if ((numberFlags & NUMBER_FLAG_MAX_DEFINED) != 0) {
out.writeInt(properties.getMax());
}
break;
}
case LONG: {
case LONG -> {
LongProperties properties = (LongProperties) node.getProperties();
int numberFlags = 0;
@ -282,13 +261,9 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
if ((numberFlags & NUMBER_FLAG_MAX_DEFINED) != 0) {
out.writeLong(properties.getMax());
}
break;
}
case STRING:
helper.writeVarInt(out, ((StringProperties) node.getProperties()).ordinal());
break;
case ENTITY: {
case STRING -> helper.writeVarInt(out, ((StringProperties) node.getProperties()).ordinal());
case ENTITY -> {
EntityProperties properties = (EntityProperties) node.getProperties();
int entityFlags = 0;
if (properties.isSingleTarget()) {
@ -300,22 +275,14 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
}
out.writeByte(entityFlags);
break;
}
case SCORE_HOLDER:
case SCORE_HOLDER ->
out.writeBoolean(((ScoreHolderProperties) node.getProperties()).isAllowMultiple());
break;
case TIME:
out.writeInt(((TimeProperties) node.getProperties()).getMin());
break;
case RESOURCE_OR_TAG:
case RESOURCE_OR_TAG_KEY:
case RESOURCE:
case RESOURCE_KEY:
case TIME -> out.writeInt(((TimeProperties) node.getProperties()).getMin());
case RESOURCE_OR_TAG, RESOURCE_OR_TAG_KEY, RESOURCE, RESOURCE_KEY ->
helper.writeString(out, ((ResourceProperties) node.getProperties()).getRegistryKey());
break;
default:
break;
default -> {
}
}
if (node.getSuggestionType() != null) {

View file

@ -7,8 +7,6 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -16,13 +14,13 @@ public class ClientboundCooldownPacket implements MinecraftPacket {
private final int itemId;
private final int cooldownTicks;
public ClientboundCooldownPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundCooldownPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.itemId = helper.readVarInt(in);
this.cooldownTicks = helper.readVarInt(in);
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.itemId);
helper.writeVarInt(out, this.cooldownTicks);
}

View file

@ -8,8 +8,6 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor

View file

@ -8,7 +8,7 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;

View file

@ -2,18 +2,12 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.GlobalPos;
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerSpawnInfo;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import lombok.With;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
@Data
@With
@ -30,7 +24,7 @@ public class ClientboundLoginPacket implements MinecraftPacket {
private final boolean doLimitedCrafting;
private final PlayerSpawnInfo commonPlayerSpawnInfo;
public ClientboundLoginPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundLoginPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.entityId = in.readInt();
this.hardcore = in.readBoolean();
int worldCount = helper.readVarInt(in);
@ -48,7 +42,7 @@ public class ClientboundLoginPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
out.writeInt(this.entityId);
out.writeBoolean(this.hardcore);
helper.writeVarInt(out, this.worldNames.length);

View file

@ -10,7 +10,7 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
import java.util.ArrayList;

View file

@ -7,7 +7,6 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@ -18,7 +17,7 @@ import java.util.UUID;
public class ClientboundPlayerInfoRemovePacket implements MinecraftPacket {
private final List<UUID> profileIds;
public ClientboundPlayerInfoRemovePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundPlayerInfoRemovePacket(ByteBuf in, MinecraftCodecHelper helper) {
this.profileIds = new ArrayList<>();
int numIds = helper.readVarInt(in);
for (int i = 0; i < numIds; i++) {
@ -26,7 +25,7 @@ public class ClientboundPlayerInfoRemovePacket implements MinecraftPacket {
}
}
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.profileIds.size());
for (UUID id : this.profileIds) {
helper.writeUUID(out, id);

View file

@ -20,7 +20,6 @@ import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.UUID;
@Data
@With
@ -36,7 +35,7 @@ public class ClientboundPlayerInfoUpdatePacket implements MinecraftPacket {
PlayerListEntry entry = new PlayerListEntry(helper.readUUID(in));
for (PlayerListEntryAction action : this.actions) {
switch (action) {
case ADD_PLAYER: {
case ADD_PLAYER -> {
GameProfile profile = new GameProfile(entry.getProfileId(), helper.readString(in, 16));
int propertyCount = helper.readVarInt(in);
List<GameProfile.Property> propertyList = new ArrayList<>();
@ -47,9 +46,8 @@ public class ClientboundPlayerInfoUpdatePacket implements MinecraftPacket {
profile.setProperties(propertyList);
entry.setProfile(profile);
break;
}
case INITIALIZE_CHAT: {
case INITIALIZE_CHAT -> {
if (in.readBoolean()) {
entry.setSessionId(helper.readUUID(in));
entry.setExpiresAt(in.readLong());
@ -65,31 +63,26 @@ public class ClientboundPlayerInfoUpdatePacket implements MinecraftPacket {
entry.setPublicKey(publicKey);
}
break;
}
case UPDATE_GAME_MODE: {
case UPDATE_GAME_MODE -> {
GameMode gameMode = GameMode.byId(helper.readVarInt(in));
entry.setGameMode(gameMode);
break;
}
case UPDATE_LISTED: {
case UPDATE_LISTED -> {
boolean listed = in.readBoolean();
entry.setListed(listed);
break;
}
case UPDATE_LATENCY: {
case UPDATE_LATENCY -> {
int latency = helper.readVarInt(in);
entry.setLatency(latency);
break;
}
case UPDATE_DISPLAY_NAME: {
case UPDATE_DISPLAY_NAME -> {
Component displayName = helper.readNullable(in, helper::readComponent);
entry.setDisplayName(displayName);
break;
}
}
}
@ -105,14 +98,14 @@ public class ClientboundPlayerInfoUpdatePacket implements MinecraftPacket {
helper.writeUUID(out, entry.getProfile().getId());
for (PlayerListEntryAction action : this.actions) {
switch (action) {
case ADD_PLAYER:
case ADD_PLAYER -> {
helper.writeString(out, entry.getProfile().getName());
helper.writeVarInt(out, entry.getProfile().getProperties().size());
for (GameProfile.Property property : entry.getProfile().getProperties()) {
helper.writeProperty(out, property);
}
break;
case INITIALIZE_CHAT:
}
case INITIALIZE_CHAT -> {
out.writeBoolean(entry.getPublicKey() != null);
if (entry.getPublicKey() != null) {
helper.writeUUID(out, entry.getSessionId());
@ -120,19 +113,12 @@ public class ClientboundPlayerInfoUpdatePacket implements MinecraftPacket {
helper.writeByteArray(out, entry.getPublicKey().getEncoded());
helper.writeByteArray(out, entry.getKeySignature());
}
break;
case UPDATE_GAME_MODE:
helper.writeVarInt(out, entry.getGameMode().ordinal());
break;
case UPDATE_LISTED:
out.writeBoolean(entry.isListed());
break;
case UPDATE_LATENCY:
helper.writeVarInt(out, entry.getLatency());
break;
case UPDATE_DISPLAY_NAME:
}
case UPDATE_GAME_MODE -> helper.writeVarInt(out, entry.getGameMode().ordinal());
case UPDATE_LISTED -> out.writeBoolean(entry.isListed());
case UPDATE_LATENCY -> helper.writeVarInt(out, entry.getLatency());
case UPDATE_DISPLAY_NAME ->
helper.writeNullable(out, entry.getDisplayName(), helper::writeComponent);
break;
}
}
}

View file

@ -6,7 +6,6 @@ import com.github.steveice10.mc.protocol.data.game.UnlockRecipesAction;
import io.netty.buffer.ByteBuf;
import lombok.*;
import java.io.IOException;
import java.util.Arrays;
@Data
@ -71,7 +70,7 @@ public class ClientboundRecipePacket implements MinecraftPacket {
this.alreadyKnownRecipes = Arrays.copyOf(alreadyKnownRecipes, alreadyKnownRecipes.length);
}
public ClientboundRecipePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundRecipePacket(ByteBuf in, MinecraftCodecHelper helper) {
this.action = UnlockRecipesAction.from(helper.readVarInt(in));
this.openCraftingBook = in.readBoolean();
@ -99,7 +98,7 @@ public class ClientboundRecipePacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.action.ordinal());
out.writeBoolean(this.openCraftingBook);

View file

@ -2,15 +2,11 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.GlobalPos;
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerSpawnInfo;
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import lombok.With;
import org.jetbrains.annotations.Nullable;
@Data
@With

View file

@ -7,15 +7,13 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
public class ClientboundSelectAdvancementsTabPacket implements MinecraftPacket {
private final String tabId;
public ClientboundSelectAdvancementsTabPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundSelectAdvancementsTabPacket(ByteBuf in, MinecraftCodecHelper helper) {
if (in.readBoolean()) {
this.tabId = helper.readString(in);
} else {
@ -24,7 +22,7 @@ public class ClientboundSelectAdvancementsTabPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
if (this.tabId != null) {
out.writeBoolean(true);
helper.writeString(out, this.tabId);

View file

@ -7,7 +7,7 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;

View file

@ -7,20 +7,18 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
public class ClientboundSetCameraPacket implements MinecraftPacket {
private final int cameraEntityId;
public ClientboundSetCameraPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundSetCameraPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.cameraEntityId = helper.readVarInt(in);
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.cameraEntityId);
}
}

View file

@ -12,8 +12,6 @@ import lombok.Data;
import lombok.NonNull;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -35,7 +33,7 @@ public class ClientboundSoundEntityPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
if (this.sound instanceof CustomSound) {
helper.writeVarInt(out, 0);
helper.writeSoundEvent(out, this.sound);

View file

@ -6,8 +6,6 @@ import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.IOException;
@Data
@NoArgsConstructor
public class ClientboundStartConfigurationPacket implements MinecraftPacket {
@ -15,6 +13,6 @@ public class ClientboundStartConfigurationPacket implements MinecraftPacket {
public ClientboundStartConfigurationPacket(ByteBuf in, MinecraftCodecHelper helper) {
}
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
}
}

View file

@ -2,17 +2,12 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.game.level.sound.BuiltinSound;
import com.github.steveice10.mc.protocol.data.game.level.sound.CustomSound;
import com.github.steveice10.mc.protocol.data.game.level.sound.Sound;
import com.github.steveice10.mc.protocol.data.game.level.sound.SoundCategory;
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import org.checkerframework.checker.nullness.qual.Nullable;
@Data
@With
@ -24,7 +19,7 @@ public class ClientboundStopSoundPacket implements MinecraftPacket {
private final @Nullable SoundCategory category;
private final @Nullable String sound;
public ClientboundStopSoundPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundStopSoundPacket(ByteBuf in, MinecraftCodecHelper helper) {
int flags = in.readByte();
if ((flags & FLAG_CATEGORY) != 0) {
this.category = helper.readSoundCategory(in);
@ -40,7 +35,7 @@ public class ClientboundStopSoundPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
int flags = 0;
if (this.category != null) {
flags |= FLAG_CATEGORY;

View file

@ -7,8 +7,6 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -23,7 +21,7 @@ public class ClientboundTickingStatePacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
out.writeFloat(tickRate);
out.writeBoolean(isFrozen);
}

View file

@ -7,8 +7,6 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -21,7 +19,7 @@ public class ClientboundTickingStepPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.tickSteps);
}
}

View file

@ -29,7 +29,7 @@ public class ClientboundUpdateRecipesPacket implements MinecraftPacket {
String identifier = helper.readResourceLocation(in);
RecipeData data;
switch (type) {
case CRAFTING_SHAPELESS: {
case CRAFTING_SHAPELESS -> {
String group = helper.readString(in);
CraftingBookCategory category = CraftingBookCategory.from(helper.readVarInt(in));
Ingredient[] ingredients = new Ingredient[helper.readVarInt(in)];
@ -40,9 +40,8 @@ public class ClientboundUpdateRecipesPacket implements MinecraftPacket {
ItemStack result = helper.readItemStack(in);
data = new ShapelessRecipeData(group, category, ingredients, result);
break;
}
case CRAFTING_SHAPED: {
case CRAFTING_SHAPED -> {
String group = helper.readString(in);
CraftingBookCategory category = CraftingBookCategory.from(helper.readVarInt(in));
@ -58,12 +57,8 @@ public class ClientboundUpdateRecipesPacket implements MinecraftPacket {
boolean showNotification = in.readBoolean();
data = new ShapedRecipeData(width, height, group, category, ingredients, result, showNotification);
break;
}
case SMELTING:
case BLASTING:
case SMOKING:
case CAMPFIRE_COOKING: {
case SMELTING, BLASTING, SMOKING, CAMPFIRE_COOKING -> {
String group = helper.readString(in);
CraftingBookCategory category = CraftingBookCategory.from(helper.readVarInt(in));
Ingredient ingredient = helper.readRecipeIngredient(in);
@ -72,38 +67,33 @@ public class ClientboundUpdateRecipesPacket implements MinecraftPacket {
int cookingTime = helper.readVarInt(in);
data = new CookedRecipeData(group, category, ingredient, result, experience, cookingTime);
break;
}
case STONECUTTING: {
case STONECUTTING -> {
String group = helper.readString(in);
Ingredient ingredient = helper.readRecipeIngredient(in);
ItemStack result = helper.readItemStack(in);
data = new StoneCuttingRecipeData(group, ingredient, result);
break;
}
case SMITHING_TRANSFORM: {
case SMITHING_TRANSFORM -> {
Ingredient template = helper.readRecipeIngredient(in);
Ingredient base = helper.readRecipeIngredient(in);
Ingredient addition = helper.readRecipeIngredient(in);
ItemStack result = helper.readItemStack(in);
data = new SmithingTransformRecipeData(template, base, addition, result);
break;
}
case SMITHING_TRIM: {
case SMITHING_TRIM -> {
Ingredient template = helper.readRecipeIngredient(in);
Ingredient base = helper.readRecipeIngredient(in);
Ingredient addition = helper.readRecipeIngredient(in);
data = new SmithingTrimRecipeData(template, base, addition);
break;
}
default: {
default -> {
CraftingBookCategory category = CraftingBookCategory.from(helper.readVarInt(in));
data = new SimpleCraftingRecipeData(category);
break;
}
}
@ -118,7 +108,7 @@ public class ClientboundUpdateRecipesPacket implements MinecraftPacket {
helper.writeResourceLocation(out, recipe.getType().getResourceLocation());
helper.writeResourceLocation(out, recipe.getIdentifier());
switch (recipe.getType()) {
case CRAFTING_SHAPELESS: {
case CRAFTING_SHAPELESS -> {
ShapelessRecipeData data = (ShapelessRecipeData) recipe.getData();
helper.writeString(out, data.getGroup());
@ -129,9 +119,8 @@ public class ClientboundUpdateRecipesPacket implements MinecraftPacket {
}
helper.writeItemStack(out, data.getResult());
break;
}
case CRAFTING_SHAPED: {
case CRAFTING_SHAPED -> {
ShapedRecipeData data = (ShapedRecipeData) recipe.getData();
if (data.getIngredients().length != data.getWidth() * data.getHeight()) {
throw new IllegalStateException("Shaped recipe must have ingredient count equal to width * height.");
@ -149,12 +138,8 @@ public class ClientboundUpdateRecipesPacket implements MinecraftPacket {
helper.writeItemStack(out, data.getResult());
out.writeBoolean(data.isShowNotification());
break;
}
case SMELTING:
case BLASTING:
case SMOKING:
case CAMPFIRE_COOKING: {
case SMELTING, BLASTING, SMOKING, CAMPFIRE_COOKING -> {
CookedRecipeData data = (CookedRecipeData) recipe.getData();
helper.writeString(out, data.getGroup());
@ -163,38 +148,33 @@ public class ClientboundUpdateRecipesPacket implements MinecraftPacket {
helper.writeItemStack(out, data.getResult());
out.writeFloat(data.getExperience());
helper.writeVarInt(out, data.getCookingTime());
break;
}
case STONECUTTING: {
case STONECUTTING -> {
StoneCuttingRecipeData data = (StoneCuttingRecipeData) recipe.getData();
helper.writeString(out, data.getGroup());
helper.writeRecipeIngredient(out, data.getIngredient());
helper.writeItemStack(out, data.getResult());
break;
}
case SMITHING_TRANSFORM: {
case SMITHING_TRANSFORM -> {
SmithingTransformRecipeData data = (SmithingTransformRecipeData) recipe.getData();
helper.writeRecipeIngredient(out, data.getTemplate());
helper.writeRecipeIngredient(out, data.getBase());
helper.writeRecipeIngredient(out, data.getAddition());
helper.writeItemStack(out, data.getResult());
break;
}
case SMITHING_TRIM: {
case SMITHING_TRIM -> {
SmithingTrimRecipeData data = (SmithingTrimRecipeData) recipe.getData();
helper.writeRecipeIngredient(out, data.getTemplate());
helper.writeRecipeIngredient(out, data.getBase());
helper.writeRecipeIngredient(out, data.getAddition());
break;
}
default: {
default -> {
SimpleCraftingRecipeData data = (SimpleCraftingRecipeData) recipe.getData();
helper.writeVarInt(out, data.getCategory().ordinal());
break;
}
}
}

View file

@ -7,9 +7,7 @@ import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import org.checkerframework.checker.nullness.qual.Nullable;
@Data
@With
@ -18,13 +16,13 @@ public class ClientboundAnimatePacket implements MinecraftPacket {
private final int entityId;
private final @Nullable Animation animation;
public ClientboundAnimatePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundAnimatePacket(ByteBuf in, MinecraftCodecHelper helper) {
this.entityId = helper.readVarInt(in);
this.animation = Animation.from(in.readUnsignedByte());
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.entityId);
if (this.animation == null) {
out.writeByte(-1); // Client does nothing on unknown ID

View file

@ -6,7 +6,7 @@ import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.cloudburstmc.math.vector.Vector3d;
import org.jetbrains.annotations.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
@Data
@AllArgsConstructor

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 ClientboundEntityEventPacket implements MinecraftPacket {
private final int entityId;
private final @NonNull EntityEvent event;
public ClientboundEntityEventPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundEntityEventPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.entityId = in.readInt();
this.event = helper.readEntityEvent(in);
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
out.writeInt(this.entityId);
helper.writeEntityEvent(out, this.event);
}

View file

@ -7,8 +7,6 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -19,7 +17,7 @@ public class ClientboundMoveEntityPosPacket implements MinecraftPacket {
private final double moveZ;
private final boolean onGround;
public ClientboundMoveEntityPosPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundMoveEntityPosPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.entityId = helper.readVarInt(in);
this.moveX = in.readShort() / 4096D;
this.moveY = in.readShort() / 4096D;
@ -28,7 +26,7 @@ public class ClientboundMoveEntityPosPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.entityId);
out.writeShort((int) (this.moveX * 4096));
out.writeShort((int) (this.moveY * 4096));

View file

@ -7,8 +7,6 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -21,7 +19,7 @@ public class ClientboundMoveEntityPosRotPacket implements MinecraftPacket {
private final float pitch;
private final boolean onGround;
public ClientboundMoveEntityPosRotPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundMoveEntityPosRotPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.entityId = helper.readVarInt(in);
this.moveX = in.readShort() / 4096D;
this.moveY = in.readShort() / 4096D;
@ -32,7 +30,7 @@ public class ClientboundMoveEntityPosRotPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.entityId);
out.writeShort((int) (this.moveX * 4096));
out.writeShort((int) (this.moveY * 4096));

View file

@ -7,8 +7,6 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -18,7 +16,7 @@ public class ClientboundMoveEntityRotPacket implements MinecraftPacket {
private final float pitch;
private final boolean onGround;
public ClientboundMoveEntityRotPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundMoveEntityRotPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.entityId = helper.readVarInt(in);
this.yaw = in.readByte() * 360 / 256f;
this.pitch = in.readByte() * 360 / 256f;
@ -26,7 +24,7 @@ public class ClientboundMoveEntityRotPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.entityId);
out.writeByte((byte) (this.yaw * 256 / 360));
out.writeByte((byte) (this.pitch * 256 / 360));

View file

@ -7,8 +7,6 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.With;
import java.io.IOException;
@Data
@With
@AllArgsConstructor
@ -19,7 +17,7 @@ public class ClientboundMoveVehiclePacket implements MinecraftPacket {
private final float yaw;
private final float pitch;
public ClientboundMoveVehiclePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
public ClientboundMoveVehiclePacket(ByteBuf in, MinecraftCodecHelper helper) {
this.x = in.readDouble();
this.y = in.readDouble();
this.z = in.readDouble();
@ -28,7 +26,7 @@ public class ClientboundMoveVehiclePacket 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);

Some files were not shown because too many files have changed in this diff Show more