2024-06-25 10:40:17 +01:00
|
|
|
package cc.fascinated.bat.service;
|
|
|
|
|
|
|
|
import cc.fascinated.bat.event.EventListener;
|
2024-06-25 11:55:26 +01:00
|
|
|
import cc.fascinated.bat.features.scoresaber.NumberOneScoreFeedListener;
|
2024-06-25 11:14:12 +01:00
|
|
|
import cc.fascinated.bat.features.scoresaber.UserScoreFeedListener;
|
2024-06-25 10:40:17 +01:00
|
|
|
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<EventListener> LISTENERS = new HashSet<>();
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
public EventService(@NonNull ApplicationContext context) {
|
|
|
|
registerListeners(
|
2024-06-25 11:55:26 +01:00
|
|
|
context.getBean(UserScoreFeedListener.class),
|
|
|
|
context.getBean(NumberOneScoreFeedListener.class)
|
2024-06-25 10:40:17 +01:00
|
|
|
);
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|