Plex/src/main/java/dev/plex/services/ServiceManager.java

45 lines
997 B
Java
Raw Normal View History

2021-01-03 07:21:15 +00:00
package dev.plex.services;
import com.google.common.collect.Lists;
2021-01-03 07:21:15 +00:00
import dev.plex.Plex;
import dev.plex.services.impl.BanService;
import org.bukkit.Bukkit;
import java.util.List;
public class ServiceManager
{
private final List<AbstractService> services = Lists.newArrayList();
public ServiceManager()
{
registerService(new BanService());
}
public void startServices()
{
for (AbstractService service : services)
{
if (service.isAsynchronous())
{
Bukkit.getScheduler().runTaskTimerAsynchronously(Plex.get(), service::run, 0, 20 * service.repeatInSeconds());
} else {
Bukkit.getScheduler().runTaskTimer(Plex.get(), service::run, 0, 20 * service.repeatInSeconds());
}
}
}
private void registerService(AbstractService service)
{
services.add(service);
}
public int serviceCount()
{
return services.size();
}
}