Add some thread checking helper methods

pending PaperMC/Folia#5 for global region helpers
This commit is contained in:
Josh Roy 2023-03-28 21:57:24 -04:00
parent 20882940c5
commit a649f978c5
No known key found for this signature in database
GPG Key ID: 86A69D08540BC29A
3 changed files with 24 additions and 0 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);