mirror of
https://github.com/SimplexDevelopment/SimplexSS.git
synced 2024-12-22 13:07:37 +00:00
Minor update
This commit is contained in:
parent
262115a52e
commit
99c78e320f
@ -9,8 +9,15 @@ import reactor.core.scheduler.Scheduler;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public record ReactorBukkitScheduler(JavaPlugin plugin, BukkitScheduler scheduler)
|
||||
public final class ReactorBukkitScheduler
|
||||
implements Scheduler, Scheduler.Worker {
|
||||
private final JavaPlugin plugin;
|
||||
private final BukkitScheduler scheduler;
|
||||
|
||||
public ReactorBukkitScheduler(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.scheduler = plugin.getServer().getScheduler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to the {@link BukkitScheduler}.
|
||||
@ -58,9 +65,9 @@ public record ReactorBukkitScheduler(JavaPlugin plugin, BukkitScheduler schedule
|
||||
}
|
||||
|
||||
/**
|
||||
* A new {@link Scheduler.Worker}.
|
||||
* A new {@link Worker}.
|
||||
*
|
||||
* @return This class instance, as it implements {@link Scheduler.Worker}.
|
||||
* @return This class instance, as it implements {@link Worker}.
|
||||
*/
|
||||
@Override
|
||||
public @NotNull Worker createWorker() {
|
||||
@ -72,6 +79,5 @@ public record ReactorBukkitScheduler(JavaPlugin plugin, BukkitScheduler schedule
|
||||
*/
|
||||
@Override
|
||||
public void dispose() {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public final class SchedulingSystem<T extends JavaPlugin> implements ISchedule {
|
||||
this.serviceManager = new ServiceManager();
|
||||
this.plugin = plugin;
|
||||
this.repeatingPools = new HashSet<>();
|
||||
this.mainScheduler = new ReactorBukkitScheduler(plugin, plugin.getServer().getScheduler());
|
||||
this.mainScheduler = new ReactorBukkitScheduler(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,6 @@
|
||||
package io.github.simplexdevelopment.scheduler;
|
||||
|
||||
import io.github.simplexdevelopment.api.IService;
|
||||
import io.github.simplexdevelopment.api.InvalidServicePoolException;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
@ -34,7 +33,6 @@ public final class ServicePool {
|
||||
* The key used to identify this service pool.
|
||||
*/
|
||||
private final NamespacedKey name;
|
||||
private final ReactorBukkitScheduler rbScheduler;
|
||||
|
||||
/**
|
||||
* This will create a new instance of a Service Pool with a {@link Scheduler} as its main scheduler.
|
||||
@ -51,7 +49,6 @@ public final class ServicePool {
|
||||
} else {
|
||||
this.scheduler = Schedulers.single();
|
||||
}
|
||||
this.rbScheduler = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,8 +60,7 @@ public final class ServicePool {
|
||||
public ServicePool(NamespacedKey name, JavaPlugin plugin) {
|
||||
this.name = name;
|
||||
this.associatedServices = new HashSet<>();
|
||||
this.scheduler = null;
|
||||
this.rbScheduler = new ReactorBukkitScheduler(plugin, plugin.getServer().getScheduler());
|
||||
this.scheduler = new ReactorBukkitScheduler(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,31 +103,14 @@ public final class ServicePool {
|
||||
public @NotNull Mono<Disposable> queueService(IService service) {
|
||||
return Mono.just(service).map(s -> {
|
||||
if (s.isPeriodic()) {
|
||||
if (scheduler != null) {
|
||||
return scheduler.schedulePeriodically(s,
|
||||
s.getDelay() * 50,
|
||||
s.getPeriod() * 50,
|
||||
TimeUnit.MILLISECONDS);
|
||||
} else if (rbScheduler != null) {
|
||||
return rbScheduler.schedulePeriodically(s,
|
||||
s.getDelay() * 50,
|
||||
s.getPeriod() * 50,
|
||||
TimeUnit.MILLISECONDS);
|
||||
} else {
|
||||
throw new InvalidServicePoolException("Service pool is not initialized properly.");
|
||||
}
|
||||
} else {
|
||||
if (scheduler != null) {
|
||||
return scheduler.schedule(s,
|
||||
s.getDelay() * 50,
|
||||
TimeUnit.MILLISECONDS);
|
||||
} else if (rbScheduler != null) {
|
||||
return rbScheduler.schedule(s,
|
||||
s.getDelay() * 50,
|
||||
TimeUnit.MILLISECONDS);
|
||||
} else {
|
||||
throw new InvalidServicePoolException("Service pool is not initialized properly.");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user