You need to use a normal class and the create function in Rarity.java like this:
public static final Rarity RARITY_NAME = Rarity.create("rarity_name", ChatFormatting.COLOR);
and if you want you can add
"rarity.rarity_name.name": "Rarity Name"
to your language file to make your rarity compatible with my rarity tooltip system, but this would only make sense when you're using 1.18.1 and please do what @diesieben07said and learn basic Java before you try making your own mod and if you don't want to learn basic Java but still want to make your own mod try using MCreator even tho you don't have any rights to your mod if you use MCreator.