Prevent unsafe velocity packet (#1550)

This commit is contained in:
Obyvante 2022-12-05 15:06:18 +03:00 committed by GitHub
parent e5d0a43ba4
commit ee7ac62b75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@ 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;
import net.minestom.server.utils.MathUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.SHORT;
@ -16,7 +17,12 @@ public record EntityVelocityPacket(int entityId, short velocityX, short velocity
}
public EntityVelocityPacket(int entityId, Point velocity) {
this(entityId, (short) velocity.x(), (short) velocity.y(), (short) velocity.z());
this(
entityId,
(short) MathUtils.clamp(velocity.x(), Short.MIN_VALUE, Short.MAX_VALUE),
(short) MathUtils.clamp(velocity.y(), Short.MIN_VALUE, Short.MAX_VALUE),
(short) MathUtils.clamp(velocity.z(), Short.MIN_VALUE, Short.MAX_VALUE)
);
}
@Override