Folia scheduler and owned region API

Pulling Folia API to Paper is primarily intended for plugins
that want to target both Paper and Folia without unnecessary
compatibility layers.

Add both a location based scheduler, an entity based scheduler,
and a global region scheduler.

Owned region API may be useful for plugins which want to perform
operations over large areas outside of the buffer zone provided
by the regionaliser, as it is not guaranteed that anything
outside of the buffer zone is owned. Then, the plugins may use
the schedulers depending on the result of the ownership check.
This commit is contained in:
Spottedleaf
2023-06-17 11:52:52 +02:00
parent 31871f6b40
commit a13bff4a5f
11 changed files with 1374 additions and 135 deletions

View File

@ -313,6 +313,88 @@ public final class CraftServer implements Server {
private final io.papermc.paper.logging.SysoutCatcher sysoutCatcher = new io.papermc.paper.logging.SysoutCatcher(); // Paper
private final io.papermc.paper.potion.PaperPotionBrewer potionBrewer; // Paper - Custom Potion Mixes
// Paper start - Folia region threading API
private final io.papermc.paper.threadedregions.scheduler.FallbackRegionScheduler regionizedScheduler = new io.papermc.paper.threadedregions.scheduler.FallbackRegionScheduler();
private final io.papermc.paper.threadedregions.scheduler.FoliaAsyncScheduler asyncScheduler = new io.papermc.paper.threadedregions.scheduler.FoliaAsyncScheduler();
private final io.papermc.paper.threadedregions.scheduler.FoliaGlobalRegionScheduler globalRegionScheduler = new io.papermc.paper.threadedregions.scheduler.FoliaGlobalRegionScheduler();
@Override
public final io.papermc.paper.threadedregions.scheduler.RegionScheduler getRegionScheduler() {
return this.regionizedScheduler;
}
@Override
public final io.papermc.paper.threadedregions.scheduler.AsyncScheduler getAsyncScheduler() {
return this.asyncScheduler;
}
@Override
public final io.papermc.paper.threadedregions.scheduler.FoliaGlobalRegionScheduler getGlobalRegionScheduler() {
return this.globalRegionScheduler;
}
@Override
public final boolean isOwnedByCurrentRegion(World world, io.papermc.paper.math.Position position) {
return ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(
((CraftWorld) world).getHandle(), position.blockX() >> 4, position.blockZ() >> 4
);
}
@Override
public final boolean isOwnedByCurrentRegion(World world, io.papermc.paper.math.Position position, int squareRadiusChunks) {
return ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(
((CraftWorld) world).getHandle(), position.blockX() >> 4, position.blockZ() >> 4, squareRadiusChunks
);
}
@Override
public final boolean isOwnedByCurrentRegion(Location location) {
World world = location.getWorld();
return ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(
((CraftWorld) world).getHandle(), location.getBlockX() >> 4, location.getBlockZ() >> 4
);
}
@Override
public final boolean isOwnedByCurrentRegion(Location location, int squareRadiusChunks) {
World world = location.getWorld();
return ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(
((CraftWorld) world).getHandle(), location.getBlockX() >> 4, location.getBlockZ() >> 4, squareRadiusChunks
);
}
@Override
public final boolean isOwnedByCurrentRegion(World world, int chunkX, int chunkZ) {
return ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(
((CraftWorld) world).getHandle(), chunkX, chunkZ
);
}
@Override
public final boolean isOwnedByCurrentRegion(World world, int chunkX, int chunkZ, int squareRadiusChunks) {
return ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(
((CraftWorld) world).getHandle(), chunkX, chunkZ, squareRadiusChunks
);
}
@Override
public final boolean isOwnedByCurrentRegion(World world, int minChunkX, int minChunkZ, int maxChunkX, int maxChunkZ) {
return ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(
((CraftWorld) world).getHandle(), minChunkX, minChunkZ, maxChunkX, maxChunkZ
);
}
@Override
public final boolean isOwnedByCurrentRegion(Entity entity) {
return ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(((org.bukkit.craftbukkit.entity.CraftEntity) entity).getHandleRaw());
}
@Override
public final boolean isGlobalTickThread() {
return ca.spottedleaf.moonrise.common.util.TickThread.isTickThread();
}
// Paper end - Folia reagion threading API
static {
ConfigurationSerialization.registerClass(CraftOfflinePlayer.class);
ConfigurationSerialization.registerClass(CraftPlayerProfile.class);