package cc.fascinated.bat.service; import cc.fascinated.bat.event.EventListener; import cc.fascinated.bat.features.scoresaber.ScoreSaberScoreFeedListener; import lombok.NonNull; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; import java.util.HashSet; import java.util.Set; /** * @author Fascinated (fascinated7) */ @Service @Log4j2 public class EventService { /** * The list of listeners registered */ public static final Set LISTENERS = new HashSet<>(); @Autowired public EventService(@NonNull ApplicationContext context) { registerListeners( context.getBean(ScoreSaberScoreFeedListener.class) ); log.info("Registered {} listeners.", LISTENERS.size()); } /** * Registers an event listener * * @param listener the listener to register */ public void registerListeners(EventListener... listener) { LISTENERS.addAll(Set.of(listener)); } }