diff --git a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentTime.java b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentTime.java index 445f8804b..b7f5e4ee8 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentTime.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentTime.java @@ -5,8 +5,10 @@ import it.unimi.dsi.fastutil.chars.CharList; import net.minestom.server.command.CommandSender; import net.minestom.server.command.builder.arguments.Argument; import net.minestom.server.command.builder.exception.ArgumentSyntaxException; +import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.time.TimeUnit; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.time.Duration; import java.time.temporal.TemporalUnit; @@ -23,10 +25,17 @@ public class ArgumentTime extends Argument { private static final CharList SUFFIXES = new CharArrayList(new char[]{'d', 's', 't'}); + private int min = 0; + public ArgumentTime(String id) { super(id); } + public @NotNull ArgumentTime min(int min) { + this.min = min; + return this; + } + @NotNull @Override public Duration parse(@NotNull CommandSender sender, @NotNull String input) throws ArgumentSyntaxException { @@ -57,7 +66,13 @@ public class ArgumentTime extends Argument { } catch (NumberFormatException e) { throw new ArgumentSyntaxException("Time needs to be a number", input, NO_NUMBER); } + } + @Override + public byte @Nullable [] nodeProperties() { + return BinaryWriter.makeArray(packetWriter -> { + packetWriter.writeInt(min); + }); } @Override diff --git a/src/main/java/net/minestom/server/network/NetworkBuffer.java b/src/main/java/net/minestom/server/network/NetworkBuffer.java index 7f97e8d55..ff7cc7882 100644 --- a/src/main/java/net/minestom/server/network/NetworkBuffer.java +++ b/src/main/java/net/minestom/server/network/NetworkBuffer.java @@ -72,6 +72,7 @@ public final class NetworkBuffer { public static final Type FROG_VARIANT = NetworkBufferTypes.FROG_VARIANT; public static final Type SNIFFER_STATE = NetworkBufferTypes.SNIFFER_STATE; public static final Type VECTOR3 = NetworkBufferTypes.VECTOR3; + public static final Type VECTOR3D = NetworkBufferTypes.VECTOR3D; public static final Type QUATERNION = NetworkBufferTypes.QUATERNION; ByteBuffer nioBuffer; diff --git a/src/main/java/net/minestom/server/network/NetworkBufferTypes.java b/src/main/java/net/minestom/server/network/NetworkBufferTypes.java index abf3068fe..cb11bad3c 100644 --- a/src/main/java/net/minestom/server/network/NetworkBufferTypes.java +++ b/src/main/java/net/minestom/server/network/NetworkBufferTypes.java @@ -572,6 +572,19 @@ final class NetworkBufferTypes { final float z = buffer.read(FLOAT); return new Vec(x, y, z); }); + static final TypeImpl VECTOR3D = new TypeImpl<>(Point.class, + (buffer, value) -> { + buffer.write(DOUBLE, value.x()); + buffer.write(DOUBLE, value.y()); + buffer.write(DOUBLE, value.z()); + return -1; + }, + buffer -> { + final double x = buffer.read(DOUBLE); + final double y = buffer.read(DOUBLE); + final double z = buffer.read(DOUBLE); + return new Vec(x, y, z); + }); static final TypeImpl QUATERNION = new TypeImpl<>(float[].class, (buffer, value) -> { buffer.write(FLOAT, value[0]); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/DamageEventPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/DamageEventPacket.java index 2f9ad6ed3..d86a6e998 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/DamageEventPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/DamageEventPacket.java @@ -1,6 +1,6 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.coordinate.Vec; +import net.minestom.server.coordinate.Point; import net.minestom.server.network.NetworkBuffer; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; @@ -12,13 +12,12 @@ import static net.minestom.server.network.NetworkBuffer.*; // Notes // sourceEntityId - 0 indicates no source entity, otherwise it is entityId + 1 // sourceDirectId - 0 indicates no direct source. Direct attacks (e.g. melee) will have this number me the same as sourceEntityId, indirect attacks (e.g. projectiles) will have this be be the projectile entity id + 1 -public record DamageEventPacket(int targetEntityId, int damageTypeId, int sourceEntityId, int sourceDirectId, @Nullable Vec sourcePos) implements ServerPacket { +public record DamageEventPacket(int targetEntityId, int damageTypeId, int sourceEntityId, int sourceDirectId, @Nullable Point sourcePos) implements ServerPacket { public DamageEventPacket(@NotNull NetworkBuffer reader) { - this(reader.read(VAR_INT), reader.read(VAR_INT), reader.read(VAR_INT), reader.read(VAR_INT), - reader.read(BOOLEAN) ? new Vec(reader.read(DOUBLE), reader.read(DOUBLE), reader.read(DOUBLE)) : null - ); + this(reader.read(VAR_INT), reader.read(VAR_INT), reader.read(VAR_INT), reader.read(VAR_INT), reader.readOptional(VECTOR3D)); } + @Override public int getId() { return ServerPacketIdentifier.DAMAGE_EVENT; @@ -27,16 +26,9 @@ public record DamageEventPacket(int targetEntityId, int damageTypeId, int source @Override public void write(@NotNull NetworkBuffer writer) { writer.write(VAR_INT, targetEntityId); - writer.write(VAR_INT, targetEntityId); - writer.write(VAR_INT, targetEntityId); - writer.write(VAR_INT, targetEntityId); - if (sourcePos != null) { - writer.write(BOOLEAN, true); - writer.write(DOUBLE, sourcePos.x()); - writer.write(DOUBLE, sourcePos.y()); - writer.write(DOUBLE, sourcePos.z()); - } else { - writer.write(BOOLEAN, false); - } + writer.write(VAR_INT, damageTypeId); + writer.write(VAR_INT, sourceEntityId); + writer.write(VAR_INT, sourceDirectId); + writer.writeOptional(VECTOR3D, sourcePos); } }