2021-01-03 07:21:15 +00:00
|
|
|
package dev.plex.services;
|
2020-11-10 02:47:03 +00:00
|
|
|
|
|
|
|
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;
|
2020-11-10 02:47:03 +00:00
|
|
|
import java.util.List;
|
2022-01-27 21:23:01 +00:00
|
|
|
import org.bukkit.Bukkit;
|
2020-11-10 02:47:03 +00:00
|
|
|
|
2022-01-30 20:56:08 +00:00
|
|
|
public class ServiceManager
|
|
|
|
{
|
2020-11-10 02:47:03 +00:00
|
|
|
private final List<AbstractService> services = Lists.newArrayList();
|
|
|
|
|
2022-01-30 20:56:08 +00:00
|
|
|
public ServiceManager()
|
|
|
|
{
|
|
|
|
//registerService(new BanService());
|
2022-01-27 06:36:00 +00:00
|
|
|
registerService(new GameRuleService());
|
2020-11-10 02:47:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-30 20:56:08 +00:00
|
|
|
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);
|
2022-01-30 20:56:08 +00:00
|
|
|
}
|
|
|
|
else if (service.isRepeating() && service.isAsynchronous())
|
|
|
|
{
|
2020-11-10 02:47:03 +00:00
|
|
|
Bukkit.getScheduler().runTaskTimerAsynchronously(Plex.get(), service::run, 0, 20 * service.repeatInSeconds());
|
2022-01-30 20:56:08 +00:00
|
|
|
}
|
|
|
|
else if (service.isRepeating() && !service.isAsynchronous())
|
|
|
|
{
|
2020-11-10 02:47:03 +00:00
|
|
|
Bukkit.getScheduler().runTaskTimer(Plex.get(), service::run, 0, 20 * service.repeatInSeconds());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-30 20:56:08 +00:00
|
|
|
private void registerService(AbstractService service)
|
|
|
|
{
|
2020-11-10 02:47:03 +00:00
|
|
|
services.add(service);
|
|
|
|
}
|
|
|
|
|
2022-01-30 20:56:08 +00:00
|
|
|
public int serviceCount()
|
|
|
|
{
|
2020-11-10 02:47:03 +00:00
|
|
|
return services.size();
|
|
|
|
}
|
|
|
|
}
|