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

48 lines
1.3 KiB
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;
2022-01-27 06:36:00 +00:00
import dev.plex.services.impl.GameRuleService;
import java.util.List;
2022-01-27 21:23:01 +00:00
import org.bukkit.Bukkit;
public class ServiceManager
{
private final List<AbstractService> services = Lists.newArrayList();
public ServiceManager()
{
//registerService(new BanService());
2022-01-27 06:36:00 +00:00
registerService(new GameRuleService());
}
public void startServices()
{
for (AbstractService service : services)
{
if (!service.isRepeating())
{
2022-01-04 03:04:39 +00:00
Bukkit.getScheduler().runTask(Plex.get(), service::run);
}
else if (service.isRepeating() && service.isAsynchronous())
{
Bukkit.getScheduler().runTaskTimerAsynchronously(Plex.get(), service::run, 0, 20 * service.repeatInSeconds());
}
else if (service.isRepeating() && !service.isAsynchronous())
{
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();
}
}