How can I prevent from getting another chalazion?

Probably cannot. Obstruction to the small glands along the eyelid can occur without know cause. Some suggest use of warm, damp compresses may help in encouraging the secretion to effectively drain, thereby avoiding plugging and infection (like a pimple).