mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 17:18:37 +01:00
Add some thread checking helper methods
pending PaperMC/Folia#5 for global region helpers
This commit is contained in:
parent
20882940c5
commit
a649f978c5
@ -6,6 +6,10 @@ import org.bukkit.entity.Entity;
|
||||
public interface SchedulingProvider extends Provider {
|
||||
void registerInitTask(Runnable runnable);
|
||||
|
||||
boolean isEntityThread(Entity entity);
|
||||
|
||||
boolean isRegionThread(Location location);
|
||||
|
||||
void runEntityTask(Entity entity, Runnable runnable);
|
||||
|
||||
EssentialsTask runEntityTask(Entity entity, Runnable runnable, long delay);
|
||||
|
@ -18,6 +18,16 @@ public class BukkitSchedulingProvider implements SchedulingProvider {
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEntityThread(Entity entity) {
|
||||
return plugin.getServer().isPrimaryThread();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRegionThread(Location location) {
|
||||
return plugin.getServer().isPrimaryThread();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runEntityTask(Entity entity, Runnable runnable) {
|
||||
runEntityTask(entity, runnable, 1);
|
||||
|
@ -38,6 +38,16 @@ public class FoliaSchedulingProvider implements SchedulingProvider, Listener {
|
||||
initTasks.add(runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEntityThread(Entity entity) {
|
||||
return plugin.getServer().isOwnedByCurrentRegion(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRegionThread(Location location) {
|
||||
return plugin.getServer().isOwnedByCurrentRegion(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runEntityTask(Entity entity, Runnable runnable) {
|
||||
runEntityTask(entity, runnable, 1);
|
||||
|
Loading…
Reference in New Issue
Block a user