mirror of
https://github.com/SimplexDevelopment/SimplexSS.git
synced 2024-11-14 22:03:31 +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;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public record ReactorBukkitScheduler(JavaPlugin plugin, BukkitScheduler scheduler)
|
public final class ReactorBukkitScheduler
|
||||||
implements Scheduler, Scheduler.Worker {
|
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}.
|
* 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
|
@Override
|
||||||
public @NotNull Worker createWorker() {
|
public @NotNull Worker createWorker() {
|
||||||
@ -72,6 +79,5 @@ public record ReactorBukkitScheduler(JavaPlugin plugin, BukkitScheduler schedule
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ public final class SchedulingSystem<T extends JavaPlugin> implements ISchedule {
|
|||||||
this.serviceManager = new ServiceManager();
|
this.serviceManager = new ServiceManager();
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.repeatingPools = new HashSet<>();
|
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;
|
package io.github.simplexdevelopment.scheduler;
|
||||||
|
|
||||||
import io.github.simplexdevelopment.api.IService;
|
import io.github.simplexdevelopment.api.IService;
|
||||||
import io.github.simplexdevelopment.api.InvalidServicePoolException;
|
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
@ -34,7 +33,6 @@ public final class ServicePool {
|
|||||||
* The key used to identify this service pool.
|
* The key used to identify this service pool.
|
||||||
*/
|
*/
|
||||||
private final NamespacedKey name;
|
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.
|
* 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 {
|
} else {
|
||||||
this.scheduler = Schedulers.single();
|
this.scheduler = Schedulers.single();
|
||||||
}
|
}
|
||||||
this.rbScheduler = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,8 +60,7 @@ public final class ServicePool {
|
|||||||
public ServicePool(NamespacedKey name, JavaPlugin plugin) {
|
public ServicePool(NamespacedKey name, JavaPlugin plugin) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.associatedServices = new HashSet<>();
|
this.associatedServices = new HashSet<>();
|
||||||
this.scheduler = null;
|
this.scheduler = new ReactorBukkitScheduler(plugin);
|
||||||
this.rbScheduler = new ReactorBukkitScheduler(plugin, plugin.getServer().getScheduler());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,31 +103,14 @@ public final class ServicePool {
|
|||||||
public @NotNull Mono<Disposable> queueService(IService service) {
|
public @NotNull Mono<Disposable> queueService(IService service) {
|
||||||
return Mono.just(service).map(s -> {
|
return Mono.just(service).map(s -> {
|
||||||
if (s.isPeriodic()) {
|
if (s.isPeriodic()) {
|
||||||
if (scheduler != null) {
|
|
||||||
return scheduler.schedulePeriodically(s,
|
return scheduler.schedulePeriodically(s,
|
||||||
s.getDelay() * 50,
|
s.getDelay() * 50,
|
||||||
s.getPeriod() * 50,
|
s.getPeriod() * 50,
|
||||||
TimeUnit.MILLISECONDS);
|
TimeUnit.MILLISECONDS);
|
||||||
} else if (rbScheduler != null) {
|
|
||||||
return rbScheduler.schedulePeriodically(s,
|
|
||||||
s.getDelay() * 50,
|
|
||||||
s.getPeriod() * 50,
|
|
||||||
TimeUnit.MILLISECONDS);
|
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidServicePoolException("Service pool is not initialized properly.");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (scheduler != null) {
|
|
||||||
return scheduler.schedule(s,
|
return scheduler.schedule(s,
|
||||||
s.getDelay() * 50,
|
s.getDelay() * 50,
|
||||||
TimeUnit.MILLISECONDS);
|
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