mirror of
https://github.com/kaboomserver/extras.git
synced 2024-05-17 10:21:19 +00:00
Make forceload limiter comply with Folia
This commit is contained in:
parent
a631777be7
commit
2a793b6faf
|
@ -1,5 +1,6 @@
|
|||
package pw.kaboom.extras.platform;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -11,4 +12,5 @@ public interface IScheduler {
|
|||
final long delay, final TimeUnit unit);
|
||||
void runSync(final Plugin plugin, final Runnable runnable);
|
||||
void runAsync(final Plugin plugin, final Runnable runnable);
|
||||
void executeOnChunk(final Plugin plugin, final Chunk chunk, final Runnable runnable);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package pw.kaboom.extras.platform;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -33,4 +34,8 @@ public final class PlatformScheduler {
|
|||
public static void runAsync(final Plugin plugin, final Runnable runnable) {
|
||||
currentScheduler.runAsync(plugin, runnable);
|
||||
}
|
||||
|
||||
public static void executeOnChunk(final Plugin plugin, final Chunk chunk, final Runnable runnable) {
|
||||
currentScheduler.executeOnChunk(plugin, chunk, runnable);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package pw.kaboom.extras.platform.folia;
|
||||
|
||||
import io.papermc.paper.threadedregions.scheduler.AsyncScheduler;
|
||||
import io.papermc.paper.threadedregions.scheduler.RegionScheduler;
|
||||
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import pw.kaboom.extras.platform.IScheduler;
|
||||
|
||||
|
@ -11,6 +14,7 @@ import java.util.function.Consumer;
|
|||
|
||||
public final class FoliaScheduler implements IScheduler {
|
||||
private static final AsyncScheduler ASYNC_SCHEDULER = Bukkit.getAsyncScheduler();
|
||||
private static final RegionScheduler REGION_SCHEDULER = Bukkit.getRegionScheduler();
|
||||
|
||||
@Override
|
||||
public void runRepeating(final Plugin plugin, final Runnable runnable,
|
||||
|
@ -35,6 +39,15 @@ public final class FoliaScheduler implements IScheduler {
|
|||
ASYNC_SCHEDULER.runNow(plugin, FoliaTask.from(runnable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeOnChunk(final Plugin plugin, final Chunk chunk, final Runnable runnable) {
|
||||
final World world = chunk.getWorld();
|
||||
final int chunkX = chunk.getX();
|
||||
final int chunkZ = chunk.getZ();
|
||||
|
||||
REGION_SCHEDULER.execute(plugin, world, chunkX, chunkZ, runnable);
|
||||
}
|
||||
|
||||
private static final class FoliaTask implements Consumer<ScheduledTask> {
|
||||
private final Runnable runnable;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package pw.kaboom.extras.platform.paper;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import pw.kaboom.extras.platform.IScheduler;
|
||||
|
@ -39,4 +40,9 @@ public final class PaperScheduler implements IScheduler {
|
|||
public void runAsync(final Plugin plugin, final Runnable runnable) {
|
||||
BUKKIT_SCHEDULER.runTaskAsynchronously(plugin, runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeOnChunk(final Plugin plugin, final Chunk chunk, final Runnable runnable) {
|
||||
BUKKIT_SCHEDULER.runTask(plugin, runnable);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,9 @@ import org.bukkit.event.Listener;
|
|||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import pw.kaboom.extras.Main;
|
||||
import pw.kaboom.extras.platform.PlatformScheduler;
|
||||
|
||||
public final class BlockCheck implements Listener {
|
||||
@EventHandler
|
||||
|
@ -25,8 +28,10 @@ public final class BlockCheck implements Listener {
|
|||
|
||||
@EventHandler
|
||||
void onChunkUnload(final ChunkUnloadEvent event) {
|
||||
final Main plugin = JavaPlugin.getPlugin(Main.class);
|
||||
|
||||
for (Chunk chunk : event.getChunk().getWorld().getForceLoadedChunks()) {
|
||||
chunk.setForceLoaded(false);
|
||||
PlatformScheduler.executeOnChunk(plugin, chunk, () -> chunk.setForceLoaded(false));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue