Allow only one instance of macro per page

I’m developing Confluence macro (via addon/plugin).
Is there a way to restrict quantity of macro instance on a page?
In other words: Suppose, I created new page. Then I add the Macro. And when I try to add second instance of the Macro , I see alert, that ‘Only one instance of the Macro allowed’ (another behaivour is also suitable, e.g. the Macro is not available for adding to page).