replace scheduler and paperlib with platform utils

This commit is contained in:
Julian Krings 2025-06-19 17:46:08 +02:00
parent bef99f18c3
commit cf0bc81778
No known key found for this signature in database
GPG Key ID: 208C6E08C3B718D2
64 changed files with 88 additions and 2239 deletions

View File

@ -90,7 +90,9 @@ nmsBindings.forEach { key, value ->
dependencies {
compileOnly(project(":core"))
compileOnly(project(":scheduler"))
compileOnly("com.github.CrazyDev05:PlatformUtils:4bac4f6e75") {
isTransitive = false
}
compileOnly("org.jetbrains:annotations:26.0.2")
}
}

View File

@ -65,12 +65,13 @@ dependencies {
// Shaded
implementation("com.dfsek:paralithic:0.8.1")
implementation("io.papermc:paperlib:1.0.5")
implementation("net.kyori:adventure-text-minimessage:4.17.0")
implementation("net.kyori:adventure-platform-bukkit:4.3.4")
implementation("net.kyori:adventure-api:4.17.0")
implementation("org.bstats:bstats-bukkit:3.1.0")
implementation(project(":scheduler"))
implementation("com.github.CrazyDev05:PlatformUtils:4bac4f6e75") {
isTransitive = false
}
//implementation("org.bytedeco:javacpp:1.5.10")
//implementation("org.bytedeco:cuda-platform:12.3-8.9-1.5.10")
@ -135,6 +136,7 @@ tasks {
relocate("net.kyori", "com.volmit.iris.util.kyori")
relocate("org.bstats", "com.volmit.iris.util.metrics")
relocate("io.sentry", "com.volmit.iris.util.sentry")
relocate("de.crazydev22.platformutils", "com.volmit.iris.util.platform")
//minimize()
dependencies {

View File

@ -64,13 +64,13 @@ import com.volmit.iris.util.plugin.VolmitPlugin;
import com.volmit.iris.util.plugin.VolmitSender;
import com.volmit.iris.util.reflect.ShadeFix;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.Platform;
import com.volmit.iris.util.scheduling.Queue;
import com.volmit.iris.util.scheduling.ShurikenQueue;
import com.volmit.iris.util.sentry.Attachments;
import com.volmit.iris.util.sentry.IrisLogger;
import com.volmit.iris.util.sentry.ServerID;
import io.papermc.lib.PaperLib;
import de.crazydev22.platformutils.Platform;
import de.crazydev22.platformutils.PlatformUtils;
import io.sentry.Sentry;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.serializer.ComponentSerializer;
@ -119,7 +119,7 @@ public class Iris extends VolmitPlugin implements Listener {
public static MythicMobsLink linkMythicMobs;
public static IrisCompat compat;
public static FileWatcher configWatcher;
public static Platform scheduler;
public static Platform platform;
private static VolmitSender sender;
static {
@ -338,7 +338,7 @@ public class Iris extends VolmitPlugin implements Listener {
@SuppressWarnings("deprecation")
public static void later(NastyRunnable object) {
try {
scheduler.async().runDelayed(task -> {
platform.getAsyncScheduler().runDelayed(task -> {
try {
object.run();
} catch (Throwable e) {
@ -463,7 +463,7 @@ public class Iris extends VolmitPlugin implements Listener {
}
private void enable() {
instance = this;
scheduler = Platform.create(this);
platform = PlatformUtils.createPlatform(this);
services = new KMap<>();
setupAudience();
setupSentry();
@ -482,7 +482,7 @@ public class Iris extends VolmitPlugin implements Listener {
services.values().forEach(IrisService::onEnable);
services.values().forEach(this::registerListener);
J.s(() -> {
J.a(() -> PaperLib.suggestPaper(this));
//J.a(() -> PaperLib.suggestPaper(this)); //TODO reimplement this
J.a(() -> IO.delete(getTemp()));
J.a(LazyPregenerator::loadLazyGenerators, 100);
J.a(this::bstats);

View File

@ -156,7 +156,7 @@ public class CommandIris implements DecreeExecutor {
return;
}
Iris.scheduler.teleportAsync(target, world.getSpawnLocation()).thenRun(() ->
Iris.platform.teleportAsync(target, world.getSpawnLocation()).thenRun(() ->
new VolmitSender(target).sendMessage(C.GREEN + "You have been teleported to " + world.getName() + "."));
}

View File

@ -57,7 +57,6 @@ import com.volmit.iris.util.plugin.VolmitSender;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import com.volmit.iris.util.scheduling.jobs.QueueJob;
import io.papermc.lib.PaperLib;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
@ -310,7 +309,7 @@ public class CommandStudio implements DecreeExecutor {
}
Player player = player();
var scheduler = Iris.scheduler.entity(player);
var scheduler = Iris.platform.getEntityScheduler(player);
scheduler.run(() -> {
sender().sendMessage(C.GREEN + "Opening inventory now!");
player.openInventory(inv);
@ -692,7 +691,7 @@ public class CommandStudio implements DecreeExecutor {
pw.println("Iris Version: " + Iris.instance.getDescription().getVersion());
pw.println("Bukkit Version: " + Bukkit.getBukkitVersion());
pw.println("MC Version: " + Bukkit.getVersion());
pw.println("PaperSpigot: " + (PaperLib.isPaper() ? "Yup!" : "Nope!"));
//pw.println("PaperSpigot: " + (PaperLib.isPaper() ? "Yup!" : "Nope!")); //TODO update this
pw.println("Report Captured At: " + new Date());
pw.println("Chunks: (" + chunks.size() + "): ");

View File

@ -22,7 +22,6 @@ import com.volmit.iris.Iris;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.scheduling.AR;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.SR;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
@ -89,7 +88,7 @@ public class BlockSignal {
return;
}
Iris.scheduler.teleportAsync(e, tg.clone()).thenAccept(b -> {
Iris.platform.teleportAsync(e, tg.clone()).thenAccept(b -> {
e.setTicksLived(1);
e.setVelocity(new Vector(0, 0, 0));
}).join();

View File

@ -30,7 +30,7 @@ import com.volmit.iris.util.json.JSONObject;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.Task;
import de.crazydev22.platformutils.scheduler.task.Task;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;

View File

@ -14,7 +14,6 @@ import com.volmit.iris.util.math.Position2;
import com.volmit.iris.util.math.RollingSequence;
import com.volmit.iris.util.profile.LoadBalancer;
import com.volmit.iris.util.scheduling.J;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
@ -223,7 +222,7 @@ public class ChunkUpdater {
for (int dx = -1; dx <= 1; dx++) {
for (int dz = -1; dz <= 1; dz++) {
if (!PaperLib.isChunkGenerated(world, x + dx, z + dz)) {
if (!Iris.platform.isChunkGenerated(world, x + dx, z + dz)) {
return false;
}
}
@ -239,7 +238,7 @@ public class ChunkUpdater {
try {
Chunk c;
try {
c = PaperLib.getChunkAtAsync(world, xx, zz, false, true)
c = Iris.platform.getChunkAtAsync(world, xx, zz, false, true)
.thenApply(chunk -> {
if (chunk != null)
chunk.addPluginChunkTicket(Iris.instance);
@ -260,7 +259,7 @@ public class ChunkUpdater {
if (future != null) future.join();
}
if (!PaperLib.isChunkGenerated(c.getWorld(), xx, zz))
if (!Iris.platform.isChunkGenerated(c.getWorld(), xx, zz))
generated.set(false);
var pair = lastUse.computeIfAbsent(Cache.key(c), k -> new Pair<>(0L, new AtomicInteger(-1)));

View File

@ -11,7 +11,6 @@ import com.volmit.iris.util.math.RollingSequence;
import com.volmit.iris.util.math.Spiraler;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.J;
import io.papermc.lib.PaperLib;
import lombok.Data;
import lombok.Getter;
import org.bukkit.Bukkit;
@ -148,23 +147,9 @@ public class LazyPregenerator extends Thread implements Listener {
private void tickGenerate(Position2 chunk) {
executorService.submit(() -> {
CountDownLatch latch = new CountDownLatch(1);
if (PaperLib.isPaper()) {
PaperLib.getChunkAtAsync(world, chunk.getX(), chunk.getZ(), true)
.thenAccept((i) -> {
Iris.verbose("Generated Async " + chunk);
latch.countDown();
});
} else {
J.s(() -> {
world.getChunkAt(chunk.getX(), chunk.getZ());
Iris.verbose("Generated " + chunk);
latch.countDown();
});
}
try {
latch.await();
} catch (InterruptedException ignored) {}
Iris.platform.getChunkAtAsync(world, chunk.getX(), chunk.getZ(), true).thenAccept((i) -> {
Iris.verbose("Generated Async " + chunk);
}).join();
lazyGeneratedChunks.addAndGet(1);
});
}

View File

@ -17,7 +17,6 @@ import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import io.papermc.lib.PaperLib;
import lombok.Data;
import lombok.Getter;
import org.apache.logging.log4j.core.util.ExecutorServices;
@ -226,7 +225,7 @@ public class TurboPregenerator extends Thread implements Listener {
private void tickGenerate(Position2 chunk) {
executorService.submit(() -> {
CountDownLatch latch = new CountDownLatch(1);
PaperLib.getChunkAtAsync(world, chunk.getX(), chunk.getZ(), true)
Iris.platform.getChunkAtAsync(world, chunk.getX(), chunk.getZ(), true)
.thenAccept((i) -> {
latch.countDown();
});

View File

@ -1,73 +0,0 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.core.pregenerator.methods;
import com.volmit.iris.core.pregenerator.PregenListener;
import com.volmit.iris.core.pregenerator.PregeneratorMethod;
import com.volmit.iris.util.mantle.Mantle;
import io.papermc.lib.PaperLib;
import org.bukkit.World;
public class AsyncOrMedievalPregenMethod implements PregeneratorMethod {
private final PregeneratorMethod method;
public AsyncOrMedievalPregenMethod(World world, int threads) {
method = PaperLib.isPaper() ? new AsyncPregenMethod(world, threads) : new MedievalPregenMethod(world);
}
@Override
public void init() {
method.init();
}
@Override
public void close() {
method.close();
}
@Override
public void save() {
method.save();
}
@Override
public String getMethod(int x, int z) {
return method.getMethod(x, z);
}
@Override
public boolean supportsRegions(int x, int z, PregenListener listener) {
return false;
}
@Override
public void generateRegion(int x, int z, PregenListener listener) {
throw new UnsupportedOperationException();
}
@Override
public void generateChunk(int x, int z, PregenListener listener) {
method.generateChunk(x, z, listener);
}
@Override
public Mantle getMantle() {
return method.getMantle();
}
}

View File

@ -28,7 +28,6 @@ import com.volmit.iris.util.mantle.Mantle;
import com.volmit.iris.util.math.M;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.scheduling.J;
import io.papermc.lib.PaperLib;
import org.bukkit.Chunk;
import org.bukkit.World;
@ -48,11 +47,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
private final boolean urgent;
private final Map<Chunk, Long> lastUse;
public AsyncPregenMethod(World world, int unusedThreads) {
if (!PaperLib.isPaper()) {
throw new UnsupportedOperationException("Cannot use PaperAsync on non paper!");
}
public AsyncPregenMethod(World world) {
this.world = world;
this.executor = IrisSettings.get().getPregen().isUseTicketQueue() ? new TicketExecutor() : new ServiceExecutor();
this.threads = IrisSettings.get().getPregen().getMaxConcurrency();
@ -197,7 +192,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
public void generate(int x, int z, PregenListener listener) {
service.submit(() -> {
try {
PaperLib.getChunkAtAsync(world, x, z, true, urgent).thenAccept((i) -> {
Iris.platform.getChunkAtAsync(world, x, z, true, urgent).thenAccept((i) -> {
listener.onChunkGenerated(x, z);
listener.onChunkCleaned(x, z);
if (i == null) return;
@ -222,7 +217,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
private class TicketExecutor implements Executor {
@Override
public void generate(int x, int z, PregenListener listener) {
PaperLib.getChunkAtAsync(world, x, z, true, urgent)
Iris.platform.getChunkAtAsync(world, x, z, true, urgent)
.exceptionally(e -> {
Iris.reportError(e);
e.printStackTrace();

View File

@ -1,74 +0,0 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.core.pregenerator.methods;
import com.volmit.iris.core.pregenerator.PregenListener;
import com.volmit.iris.core.pregenerator.PregeneratorMethod;
import com.volmit.iris.util.mantle.Mantle;
import org.bukkit.World;
public class HybridPregenMethod implements PregeneratorMethod {
private final PregeneratorMethod inWorld;
private final World world;
public HybridPregenMethod(World world, int threads) {
this.world = world;
inWorld = new AsyncOrMedievalPregenMethod(world, threads);
}
@Override
public String getMethod(int x, int z) {
return "Hybrid<" + inWorld.getMethod(x, z) + ">";
}
@Override
public void init() {
inWorld.init();
}
@Override
public void close() {
inWorld.close();
}
@Override
public void save() {
inWorld.save();
}
@Override
public boolean supportsRegions(int x, int z, PregenListener listener) {
return inWorld.supportsRegions(x, z, listener);
}
@Override
public void generateRegion(int x, int z, PregenListener listener) {
inWorld.generateRegion(x, z, listener);
}
@Override
public void generateChunk(int x, int z, PregenListener listener) {
inWorld.generateChunk(x, z, listener);
}
@Override
public Mantle getMantle() {
return inWorld.getMantle();
}
}

View File

@ -1,138 +0,0 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.core.pregenerator.methods;
import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.pregenerator.PregenListener;
import com.volmit.iris.core.pregenerator.PregeneratorMethod;
import com.volmit.iris.core.tools.IrisToolbelt;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.mantle.Mantle;
import com.volmit.iris.util.math.M;
import com.volmit.iris.util.scheduling.J;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
import java.util.ArrayList;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
public class MedievalPregenMethod implements PregeneratorMethod {
private final World world;
private final KList<CompletableFuture<?>> futures;
private final Map<Chunk, Long> lastUse;
public MedievalPregenMethod(World world) {
this.world = world;
futures = new KList<>();
this.lastUse = new KMap<>();
}
private void waitForChunks() {
for (CompletableFuture<?> i : futures) {
try {
i.get();
} catch (Throwable e) {
e.printStackTrace();
}
}
futures.clear();
}
private void unloadAndSaveAllChunks() {
try {
J.sfut(() -> {
if (world == null) {
Iris.warn("World was null somehow...");
return;
}
for (Chunk i : new ArrayList<>(lastUse.keySet())) {
Long lastUseTime = lastUse.get(i);
if (lastUseTime != null && M.ms() - lastUseTime >= 10) {
i.unload();
lastUse.remove(i);
}
}
world.save();
}).get();
} catch (Throwable e) {
e.printStackTrace();
}
}
@Override
public void init() {
unloadAndSaveAllChunks();
}
@Override
public void close() {
unloadAndSaveAllChunks();
}
@Override
public void save() {
unloadAndSaveAllChunks();
}
@Override
public boolean supportsRegions(int x, int z, PregenListener listener) {
return false;
}
@Override
public void generateRegion(int x, int z, PregenListener listener) {
throw new UnsupportedOperationException();
}
@Override
public String getMethod(int x, int z) {
return "Medieval";
}
@Override
public void generateChunk(int x, int z, PregenListener listener) {
if (futures.size() > IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getParallelism())) {
waitForChunks();
}
listener.onChunkGenerating(x, z);
futures.add(J.sfut(() -> {
world.getChunkAt(x, z);
Chunk c = Bukkit.getWorld(world.getUID()).getChunkAt(x, z);
lastUse.put(c, M.ms());
listener.onChunkGenerated(x, z);
listener.onChunkCleaned(x, z);
}));
}
@Override
public Mantle getMantle() {
if (IrisToolbelt.isIrisWorld(world)) {
return IrisToolbelt.access(world).getEngine().getMantle().getMantle();
}
return null;
}
}

View File

@ -24,7 +24,6 @@ import com.volmit.iris.core.edit.BukkitBlockEditor;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.math.M;
import com.volmit.iris.util.plugin.IrisService;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;
@ -38,7 +37,7 @@ public class EditSVC implements IrisService {
@Override
public void onEnable() {
this.editors = new KMap<>();
Iris.scheduler.global().runAtFixedRate(this::update, 1000, 1000);
Iris.platform.getGlobalScheduler().runAtFixedRate(this::update, 1000, 1000);
}
@Override

View File

@ -22,7 +22,6 @@ import com.volmit.iris.Iris;
import com.volmit.iris.util.plugin.IrisService;
import com.volmit.iris.util.scheduling.J;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
@ -71,7 +70,7 @@ public class ObjectSVC implements IrisService {
*/
private void revert(Map<Block, BlockData> blocks) {
Iterator<Map.Entry<Block, BlockData>> it = blocks.entrySet().iterator();
var scheduler = Iris.scheduler.region();
var scheduler = Iris.platform.getRegionScheduler();
for (int i = 0; i < 200 && it.hasNext(); i++) {
Map.Entry<Block, BlockData> entry = it.next();
Block block = entry.getKey();

View File

@ -11,7 +11,7 @@ import com.volmit.iris.util.plugin.VolmitSender;
import com.volmit.iris.util.reflect.V;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import com.volmit.iris.util.scheduling.Task;
import de.crazydev22.platformutils.scheduler.task.Task;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;

View File

@ -24,8 +24,8 @@ import com.volmit.iris.core.gui.PregeneratorJob;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.core.pregenerator.PregenTask;
import com.volmit.iris.core.pregenerator.PregeneratorMethod;
import com.volmit.iris.core.pregenerator.methods.AsyncPregenMethod;
import com.volmit.iris.core.pregenerator.methods.CachedPregenMethod;
import com.volmit.iris.core.pregenerator.methods.HybridPregenMethod;
import com.volmit.iris.core.service.StudioSVC;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.IrisDimension;
@ -165,8 +165,7 @@ public class IrisToolbelt {
* @return the pregenerator job (already started)
*/
public static PregeneratorJob pregenerate(PregenTask task, PlatformChunkGenerator gen) {
return pregenerate(task, new HybridPregenMethod(gen.getEngine().getWorld().realWorld(),
IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getParallelism())), gen.getEngine());
return pregenerate(task, new AsyncPregenMethod(gen.getEngine().getWorld().realWorld()), gen.getEngine());
}
/**
@ -182,7 +181,7 @@ public class IrisToolbelt {
return pregenerate(task, access(world));
}
return pregenerate(task, new HybridPregenMethod(world, IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getParallelism())), null);
return pregenerate(task, new AsyncPregenMethod(world), null);
}
/**

View File

@ -50,7 +50,7 @@ import com.volmit.iris.util.matter.MatterStructurePOI;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import com.volmit.iris.util.scheduling.Task;
import de.crazydev22.platformutils.scheduler.task.Task;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

View File

@ -41,7 +41,6 @@ import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.Looper;
import com.volmit.iris.util.scheduling.jobs.QueueJob;
import io.papermc.lib.PaperLib;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.bukkit.Chunk;
@ -62,7 +61,6 @@ import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -202,7 +200,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
for (Player i : getEngine().getWorld().realWorld().getPlayers()) {
int r = 1;
Iris.scheduler.entity(i).run(() -> {
Iris.platform.getEntityScheduler(i).run(() -> {
Chunk c = i.getLocation().getChunk();
for (int x = -r; x <= r; x++) {
for (int z = -r; z <= r; z++) {
@ -499,7 +497,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
}
futures.add(MultiBurst.burst.completeValue(()
-> PaperLib.getChunkAtAsync(to.getWorld(),
-> Iris.platform.getChunkAtAsync(to.getWorld(),
(to.getBlockX() >> 4) + finalI,
(to.getBlockZ() >> 4) + finalJ,
true, IrisSettings.get().getWorld().getAsyncTeleport().isUrgent()).get()));
@ -536,9 +534,9 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
IrisPosition pos = new IrisPosition((c.getX() << 4) + x, y, (c.getZ() << 4) + z);
if (mark.isEmptyAbove()) {
Boolean remove = Iris.scheduler.region()
Boolean remove = Iris.platform.getRegionScheduler()
.run(c.getWorld(), c.getX(), c.getZ(), () -> c.getBlock(x, y + 1, z).getType().isSolid() || c.getBlock(x, y + 2, z).getType().isSolid())
.result()
.getResult()
.exceptionally(e -> {
Iris.reportError(e);
e.printStackTrace();

View File

@ -64,7 +64,6 @@ import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import com.volmit.iris.util.stream.ProceduralStream;
import io.papermc.lib.PaperLib;
import org.bukkit.*;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
@ -293,7 +292,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
try {
Semaphore semaphore = new Semaphore(3);
chunk.raiseFlag(MantleFlag.ETCHED, () -> {
var region = Iris.scheduler.region();
var region = Iris.platform.getRegionScheduler();
chunk.raiseFlag(MantleFlag.TILE, run(semaphore, () -> region.run(c.getWorld(), c.getX(), c.getZ(), () -> {
mantle.iterateChunk(c.getX(), c.getZ(), TileWrapper.class, (x, y, z, v) -> {
int betterY = y + getWorld().minHeight();
@ -541,8 +540,8 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
if (IrisLootEvent.callLootEvent(items, inv, world, x, y, z))
return;
if (PaperLib.isPaper() && getWorld().hasRealWorld()) {
PaperLib.getChunkAtAsync(getWorld().realWorld(), x >> 4, z >> 4).thenAccept((c) -> {
if (getWorld().hasRealWorld()) {
Iris.platform.getChunkAtAsync(getWorld().realWorld(), x >> 4, z >> 4, true, false).thenAccept((c) -> {
Runnable r = () -> {
for (ItemStack i : items) {
inv.addItem(i);
@ -899,7 +898,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
player.sendMessage(C.GOLD + "No strongholds in world.");
} else {
Location ll = new Location(player.getWorld(), pr.getX(), 40, pr.getZ());
Iris.scheduler.teleportAsync(player, ll);
Iris.platform.teleportAsync(player, ll);
}
return;

View File

@ -20,24 +20,18 @@ package com.volmit.iris.engine.framework;
import com.volmit.iris.Iris;
import com.volmit.iris.core.events.IrisEngineHotloadEvent;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.math.Position2;
import com.volmit.iris.util.plugin.VolmitSender;
import com.volmit.iris.util.scheduling.Task;
import de.crazydev22.platformutils.scheduler.task.Task;
import org.bukkit.*;
import org.bukkit.entity.EnderSignal;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.WorldSaveEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.inventory.EquipmentSlot;
import java.util.concurrent.atomic.AtomicBoolean;
@ -53,7 +47,7 @@ public abstract class EngineAssignedWorldManager extends EngineAssignedComponent
public EngineAssignedWorldManager(Engine engine) {
super(engine, "World");
Iris.instance.registerListener(this);
task = Iris.scheduler.global().runAtFixedRate(this::onTick, 1, 1);
task = Iris.platform.getGlobalScheduler().runAtFixedRate(this::onTick, 1, 1);
}
@EventHandler

View File

@ -114,7 +114,7 @@ public interface Locator<T> {
default void find(Player player, boolean teleport, String message) {
find(player, location -> {
if (teleport) {
Iris.scheduler.teleportAsync(player, location);
Iris.platform.teleportAsync(player, location);
} else {
player.sendMessage(C.GREEN + message + " at: " + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ());
}

View File

@ -65,7 +65,7 @@ public class IrisCommand {
return;
}
var scheduler = Iris.scheduler.global();
var scheduler = Iris.platform.getGlobalScheduler();
for (String command : commands) {
command = (command.startsWith("/") ? command.replaceFirst("/", "") : command)
.replaceAll("\\Q{x}\\E", String.valueOf(at.getBlockX()))

View File

@ -24,7 +24,6 @@ import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.annotations.*;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.J;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -281,6 +280,6 @@ public class IrisEffect {
}
private void schedule(Entity entity, Runnable task) {
Iris.scheduler.entity(entity).run(task, null);
Iris.platform.getEntityScheduler(entity).run(task, null);
}
}

View File

@ -178,11 +178,11 @@ public class IrisEntity extends IrisRegistrant {
}
public Entity spawn(Engine gen, final Location at, RNG rng) {
if (!Iris.scheduler.isOwnedByCurrentRegion(at)) {
if (!Iris.platform.isOwnedByCurrentRegion(at)) {
try {
final Location finalAt = at;
return Iris.scheduler.region().run(at, () -> spawn(gen, finalAt, rng))
.result()
return Iris.platform.getRegionScheduler().run(at, () -> spawn(gen, finalAt, rng))
.getResult()
.get(500, TimeUnit.MILLISECONDS);
} catch (Throwable e) {
return null;
@ -350,7 +350,7 @@ public class IrisEntity extends IrisRegistrant {
living.setCollidable(false);
living.setNoDamageTicks(100000);
AtomicInteger t = new AtomicInteger(0);
Iris.scheduler.region().runAtFixedRate(at, task -> {
Iris.platform.getRegionScheduler().runAtFixedRate(at, task -> {
if (t.get() > 100) {
task.cancel();
return;
@ -358,7 +358,7 @@ public class IrisEntity extends IrisRegistrant {
t.incrementAndGet();
if (e.getLocation().getBlock().getType().isSolid() || living.getEyeLocation().getBlock().getType().isSolid()) {
Iris.scheduler.teleportAsync(e, at.add(0, 0.1, 0));
Iris.platform.teleportAsync(e, at.add(0, 0.1, 0));
ItemStack itemCrackData = new ItemStack(living.getEyeLocation().clone().subtract(0, 2, 0).getBlock().getBlockData().getMaterial());
e.getWorld().spawnParticle(ITEM, living.getEyeLocation(), 6, 0.2, 0.4, 0.2, 0.06f, itemCrackData);
if (M.r(0.2)) {

View File

@ -42,7 +42,7 @@ import org.bukkit.entity.Entity;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicBoolean;
import static com.volmit.iris.Iris.scheduler;
import static com.volmit.iris.Iris.platform;
@Snippet("entity-spawn")
@Accessors(chain = true)
@ -172,9 +172,9 @@ public class IrisEntitySpawn implements IRare {
if (!ignoreSurfaces) {
Location block = at.clone().subtract(0, 1, 0);
BlockData data = scheduler.region()
BlockData data = platform.getRegionScheduler()
.run(block, () -> block.getBlock().getBlockData())
.result()
.getResult()
.join();
if (!irisEntity.getSurface().matches(data)) {
return null;
@ -212,7 +212,7 @@ public class IrisEntitySpawn implements IRare {
int startZ = center.getBlockZ() - (int) (boundingBox.z / 2);
int endZ = center.getBlockZ() + (int) (boundingBox.z / 2);
var region = scheduler.region();
var region = platform.getRegionScheduler();
var lock = new Semaphore(Integer.MAX_VALUE, true);
var bool = new AtomicBoolean(true);
for (int x = startX; x <= endX; x++) {
@ -223,7 +223,7 @@ public class IrisEntitySpawn implements IRare {
region.run(l, () -> {
if (!bool.get()) return false;
return bool.compareAndSet(true, l.getBlock().getType() == Material.AIR);
}).result().exceptionally(f -> false).thenRun(lock::release);
}).getResult().exceptionally(f -> false).thenRun(lock::release);
}
}
}

View File

@ -80,7 +80,7 @@ public class LegacyTileData extends TileData {
@Override
public void toBukkit(Block block) {
Iris.scheduler.region().run(block.getLocation(), () -> handler.toBukkit(block));
Iris.platform.getRegionScheduler().run(block.getLocation(), () -> handler.toBukkit(block));
}
@Override

View File

@ -40,7 +40,6 @@ import com.volmit.iris.util.io.ReactiveFolder;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.Looper;
import io.papermc.lib.PaperLib;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Setter;
@ -149,7 +148,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
@Override
public Location getFixedSpawnLocation(@NotNull World world, @NotNull Random random) {
Location location = new Location(world, 0, 64, 0);
PaperLib.getChunkAtAsync(location)
Iris.platform.getChunkAtAsync(location)
.thenAccept(c -> {
World w = c.getWorld();
if (!w.getSpawnLocation().equals(location))

View File

@ -19,7 +19,7 @@
package com.volmit.iris.util.board;
import com.volmit.iris.Iris;
import com.volmit.iris.util.scheduling.Task;
import de.crazydev22.platformutils.scheduler.task.Task;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
@ -43,7 +43,7 @@ public class BoardManager {
this.plugin = plugin;
this.boardSettings = boardSettings;
this.scoreboards = new ConcurrentHashMap<>();
this.updateTask = Iris.scheduler.global().runAtFixedRate(new BoardUpdateTask(this), 2L, 20L);
this.updateTask = Iris.platform.getGlobalScheduler().runAtFixedRate(new BoardUpdateTask(this), 2L, 20L);
plugin.getServer().getOnlinePlayers().forEach(this::setup);
}

View File

@ -50,7 +50,6 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
/**
@ -300,7 +299,7 @@ public class VolmitSender implements CommandSender {
public <T> void showWaiting(String passive, CompletableFuture<T> f) {
AtomicReference<T> g = new AtomicReference<>();
Iris.scheduler.async().runAtFixedRate(task -> {
Iris.platform.getAsyncScheduler().runAtFixedRate(task -> {
if (f.isDone() && g.get() != null) {
task.cancel();
sendAction(" ");

View File

@ -2,10 +2,8 @@ package com.volmit.iris.util.profile;
import com.volmit.iris.Iris;
import com.volmit.iris.util.math.M;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.Looper;
import com.volmit.iris.util.scheduling.Task;
import org.bukkit.Bukkit;
import de.crazydev22.platformutils.scheduler.task.Task;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
@ -54,10 +52,10 @@ public abstract class MsptTimings extends Looper {
protected abstract void update(int mspt);
private boolean startTickTask() {
if (task != null && !task.cancelled())
if (task != null && !task.isCancelled())
return false;
task = Iris.scheduler.global().runAtFixedRate(t -> {
task = Iris.platform.getGlobalScheduler().runAtFixedRate(t -> {
if (isInterrupted()) {
t.cancel();
return;

View File

@ -19,6 +19,7 @@
package com.volmit.iris.util.scheduling;
import com.volmit.iris.util.plugin.CancellableTask;
import de.crazydev22.platformutils.scheduler.task.Task;
public abstract class AR implements Runnable, CancellableTask {
private final Task task;

View File

@ -26,6 +26,7 @@ import com.volmit.iris.util.function.NastyRunnable;
import com.volmit.iris.util.function.NastySupplier;
import com.volmit.iris.util.math.FinalInteger;
import com.volmit.iris.util.parallel.MultiBurst;
import de.crazydev22.platformutils.scheduler.task.Task;
import org.bukkit.Bukkit;
import java.util.concurrent.Callable;
@ -92,7 +93,7 @@ public class J {
if (!Bukkit.getPluginManager().isPluginEnabled(Iris.instance)) {
return;
}
Iris.scheduler.async().run(a);
Iris.platform.getAsyncScheduler().run(a);
}
public static <T> Future<T> a(Callable<T> a) {
@ -225,7 +226,7 @@ public class J {
if (!Bukkit.getPluginManager().isPluginEnabled(Iris.instance)) {
return;
}
Iris.scheduler.global().run(r);
Iris.platform.getGlobalScheduler().run(r);
}
public static CompletableFuture sfut(Runnable r) {
@ -233,10 +234,10 @@ public class J {
return null;
}
return Iris.scheduler.global().run(() -> {
return Iris.platform.getGlobalScheduler().run(() -> {
r.run();
return null;
}).result();
}).getResult();
}
public static CompletableFuture sfut(Runnable r, int delay) {
@ -244,10 +245,10 @@ public class J {
return null;
}
return Iris.scheduler.global().runDelayed(() -> {
return Iris.platform.getGlobalScheduler().runDelayed(() -> {
r.run();
return null;
}, delay).result();
}, delay).getResult();
}
public static CompletableFuture afut(Runnable r) {
@ -270,7 +271,7 @@ public class J {
if (!Bukkit.getPluginManager().isPluginEnabled(Iris.instance)) {
return;
}
Iris.scheduler.global().runDelayed(r, delay);
Iris.platform.getGlobalScheduler().runDelayed(r, delay);
} catch (Throwable e) {
Iris.reportError(e);
}
@ -287,7 +288,7 @@ public class J {
if (!Bukkit.getPluginManager().isPluginEnabled(Iris.instance)) {
return null;
}
return Iris.scheduler.global().runAtFixedRate(r, 1, Math.max(interval, 1));
return Iris.platform.getGlobalScheduler().runAtFixedRate(r, 1, Math.max(interval, 1));
}
/**
@ -298,7 +299,7 @@ public class J {
*/
public static void a(Runnable r, int delay) {
if (Bukkit.getPluginManager().isPluginEnabled(Iris.instance)) {
Iris.scheduler.async().runDelayed(r, Math.max(delay * 50, 0), TimeUnit.MILLISECONDS);
Iris.platform.getAsyncScheduler().runDelayed(r, Math.max(delay * 50, 0), TimeUnit.MILLISECONDS);
}
}
@ -313,7 +314,7 @@ public class J {
if (!Bukkit.getPluginManager().isPluginEnabled(Iris.instance)) {
return null;
}
return Iris.scheduler.async().runAtFixedRate(r, 0, Math.max(interval, 1) * 50, TimeUnit.MILLISECONDS);
return Iris.platform.getAsyncScheduler().runAtFixedRate(r, 0, Math.max(interval, 1) * 50, TimeUnit.MILLISECONDS);
}
/**

View File

@ -19,6 +19,7 @@
package com.volmit.iris.util.scheduling;
import com.volmit.iris.util.plugin.CancellableTask;
import de.crazydev22.platformutils.scheduler.task.Task;
public abstract class SR implements Runnable, CancellableTask {
private final Task id;

View File

@ -16,11 +16,9 @@ import com.volmit.iris.util.json.JSONObject;
import com.volmit.iris.util.mantle.Mantle;
import com.volmit.iris.util.math.Vector3d;
import com.volmit.iris.util.matter.MatterBiomeInject;
import com.volmit.iris.util.nbt.io.NBTUtil;
import com.volmit.iris.util.nbt.mca.NBTWorld;
import com.volmit.iris.util.nbt.mca.palette.*;
import com.volmit.iris.util.nbt.tag.CompoundTag;
import com.volmit.iris.util.scheduling.J;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import lombok.SneakyThrows;
import net.minecraft.core.*;
@ -35,9 +33,7 @@ import net.minecraft.server.WorldLoader;
import net.minecraft.server.commands.data.BlockDataAccessor;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
@ -63,31 +59,21 @@ import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlock;
import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlockState;
import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlockStates;
import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftDolphin;
import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack;
import org.bukkit.entity.Dolphin;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.entity.EntityType;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import sun.misc.Unsafe;
import java.awt.Color;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Function;
public class NMSBinding implements INMSBinding {
@ -211,7 +197,7 @@ public class NMSBinding implements INMSBinding {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) convertToTag(map, 0, 64);
var level = ((CraftWorld) pos.getWorld()).getHandle();
var blockPos = new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
Iris.scheduler.region().run(pos, () -> merge(level, blockPos, tag));
Iris.platform.getRegionScheduler().run(pos, () -> merge(level, blockPos, tag));
}
private void merge(ServerLevel level, BlockPos blockPos, net.minecraft.nbt.CompoundTag tag) {

View File

@ -1,23 +1,17 @@
package com.volmit.iris.core.nms.v1_20_R2;
import java.awt.Color;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Function;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Lifecycle;
import com.volmit.iris.core.nms.container.AutoClosing;
import com.volmit.iris.core.nms.container.BiomeColor;
import com.volmit.iris.util.scheduling.J;
import lombok.SneakyThrows;
import net.minecraft.core.*;
import net.minecraft.core.Registry;
@ -45,10 +39,8 @@ import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R2.block.CraftBlockState;
import org.bukkit.craftbukkit.v1_20_R2.block.CraftBlockStates;
import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftDolphin;
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_20_R2.util.CraftNamespacedKey;
import org.bukkit.entity.Dolphin;
import org.bukkit.entity.Entity;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.generator.ChunkGenerator;
@ -68,7 +60,6 @@ import com.volmit.iris.util.json.JSONObject;
import com.volmit.iris.util.mantle.Mantle;
import com.volmit.iris.util.math.Vector3d;
import com.volmit.iris.util.matter.MatterBiomeInject;
import com.volmit.iris.util.nbt.io.NBTUtil;
import com.volmit.iris.util.nbt.mca.NBTWorld;
import com.volmit.iris.util.nbt.mca.palette.*;
import com.volmit.iris.util.nbt.tag.CompoundTag;
@ -79,14 +70,12 @@ import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.chunk.LevelChunk;
import sun.misc.Unsafe;
public class NMSBinding implements INMSBinding {
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
@ -208,7 +197,7 @@ public class NMSBinding implements INMSBinding {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) convertToTag(map, 0, 64);
var level = ((CraftWorld) pos.getWorld()).getHandle();
var blockPos = new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
Iris.scheduler.region().run(pos, () -> merge(level, blockPos, tag));
Iris.platform.getRegionScheduler().run(pos, () -> merge(level, blockPos, tag));
}
private void merge(ServerLevel level, BlockPos blockPos, net.minecraft.nbt.CompoundTag tag) {

View File

@ -1,23 +1,17 @@
package com.volmit.iris.core.nms.v1_20_R3;
import java.awt.Color;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Function;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Lifecycle;
import com.volmit.iris.core.nms.container.AutoClosing;
import com.volmit.iris.core.nms.container.BiomeColor;
import com.volmit.iris.util.scheduling.J;
import lombok.SneakyThrows;
import net.minecraft.core.*;
import net.minecraft.core.Registry;
@ -45,10 +39,8 @@ import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlockState;
import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlockStates;
import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftDolphin;
import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_20_R3.util.CraftNamespacedKey;
import org.bukkit.entity.Dolphin;
import org.bukkit.entity.Entity;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.generator.ChunkGenerator;
@ -68,7 +60,6 @@ import com.volmit.iris.util.json.JSONObject;
import com.volmit.iris.util.mantle.Mantle;
import com.volmit.iris.util.math.Vector3d;
import com.volmit.iris.util.matter.MatterBiomeInject;
import com.volmit.iris.util.nbt.io.NBTUtil;
import com.volmit.iris.util.nbt.mca.NBTWorld;
import com.volmit.iris.util.nbt.mca.palette.*;
import com.volmit.iris.util.nbt.tag.CompoundTag;
@ -79,14 +70,12 @@ import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.chunk.LevelChunk;
import sun.misc.Unsafe;
public class NMSBinding implements INMSBinding {
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
@ -208,7 +197,7 @@ public class NMSBinding implements INMSBinding {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) convertToTag(map, 0, 64);
var level = ((CraftWorld) pos.getWorld()).getHandle();
var blockPos = new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
Iris.scheduler.region().run(pos, () -> merge(level, blockPos, tag));
Iris.platform.getRegionScheduler().run(pos, () -> merge(level, blockPos, tag));
}
private void merge(ServerLevel level, BlockPos blockPos, net.minecraft.nbt.CompoundTag tag) {

View File

@ -7,7 +7,6 @@ import java.lang.reflect.Modifier;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Function;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Lifecycle;
@ -15,7 +14,6 @@ import com.volmit.iris.core.nms.container.AutoClosing;
import com.volmit.iris.core.nms.container.BiomeColor;
import com.volmit.iris.core.nms.datapack.DataVersion;
import com.volmit.iris.util.nbt.tag.CompoundTag;
import com.volmit.iris.util.scheduling.J;
import lombok.SneakyThrows;
import net.minecraft.core.*;
import net.minecraft.core.Registry;
@ -33,7 +31,6 @@ import net.minecraft.nbt.Tag;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.WorldLoader;
import net.minecraft.server.commands.data.BlockDataAccessor;
import net.minecraft.server.commands.data.DataCommands;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.component.CustomData;
@ -41,7 +38,6 @@ import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.chunk.status.ChunkStatus;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem;
@ -56,13 +52,9 @@ import org.bukkit.craftbukkit.v1_20_R4.CraftServer;
import org.bukkit.craftbukkit.v1_20_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R4.block.CraftBlockState;
import org.bukkit.craftbukkit.v1_20_R4.block.CraftBlockStates;
import org.bukkit.craftbukkit.v1_20_R4.block.CraftBlockType;
import org.bukkit.craftbukkit.v1_20_R4.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_20_R4.entity.CraftDolphin;
import org.bukkit.craftbukkit.v1_20_R4.generator.CustomChunkGenerator;
import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_20_R4.util.CraftNamespacedKey;
import org.bukkit.entity.Dolphin;
import org.bukkit.entity.Entity;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.generator.ChunkGenerator;
@ -217,7 +209,7 @@ public class NMSBinding implements INMSBinding {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) convertToTag(map, 0, 64);
var level = ((CraftWorld) pos.getWorld()).getHandle();
var blockPos = new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
Iris.scheduler.region().run(pos, () -> merge(level, blockPos, tag));
Iris.platform.getRegionScheduler().run(pos, () -> merge(level, blockPos, tag));
}
private void merge(ServerLevel level, BlockPos blockPos, net.minecraft.nbt.CompoundTag tag) {

View File

@ -1,24 +1,18 @@
package com.volmit.iris.core.nms.v1_21_R1;
import java.awt.Color;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Function;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Lifecycle;
import com.volmit.iris.core.nms.container.AutoClosing;
import com.volmit.iris.core.nms.container.BiomeColor;
import com.volmit.iris.core.nms.datapack.DataVersion;
import com.volmit.iris.util.scheduling.J;
import lombok.SneakyThrows;
import net.minecraft.core.*;
import net.minecraft.core.Registry;
@ -28,7 +22,6 @@ import net.minecraft.nbt.Tag;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.WorldLoader;
import net.minecraft.server.commands.data.BlockDataAccessor;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.level.LevelReader;
@ -51,10 +44,8 @@ import org.bukkit.craftbukkit.v1_21_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_21_R1.block.CraftBlockState;
import org.bukkit.craftbukkit.v1_21_R1.block.CraftBlockStates;
import org.bukkit.craftbukkit.v1_21_R1.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_21_R1.entity.CraftDolphin;
import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_21_R1.util.CraftNamespacedKey;
import org.bukkit.entity.Dolphin;
import org.bukkit.entity.Entity;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.generator.ChunkGenerator;
@ -74,7 +65,6 @@ import com.volmit.iris.util.json.JSONObject;
import com.volmit.iris.util.mantle.Mantle;
import com.volmit.iris.util.math.Vector3d;
import com.volmit.iris.util.matter.MatterBiomeInject;
import com.volmit.iris.util.nbt.io.NBTUtil;
import com.volmit.iris.util.nbt.mca.NBTWorld;
import com.volmit.iris.util.nbt.mca.palette.*;
import com.volmit.iris.util.nbt.tag.CompoundTag;
@ -85,13 +75,11 @@ import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.LevelChunk;
import sun.misc.Unsafe;
public class NMSBinding implements INMSBinding {
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
@ -214,7 +202,7 @@ public class NMSBinding implements INMSBinding {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) convertToTag(map, 0, 64);
var level = ((CraftWorld) pos.getWorld()).getHandle();
var blockPos = new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
Iris.scheduler.region().run(pos, () -> merge(level, blockPos, tag));
Iris.platform.getRegionScheduler().run(pos, () -> merge(level, blockPos, tag));
}
private void merge(ServerLevel level, BlockPos blockPos, net.minecraft.nbt.CompoundTag tag) {

View File

@ -7,14 +7,11 @@ import java.lang.reflect.Modifier;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Function;
import com.mojang.serialization.Lifecycle;
import com.volmit.iris.core.nms.container.AutoClosing;
import com.volmit.iris.core.nms.container.BiomeColor;
import com.volmit.iris.core.nms.container.Pair;
import com.volmit.iris.core.nms.datapack.DataVersion;
import com.volmit.iris.util.scheduling.J;
import lombok.SneakyThrows;
import net.minecraft.core.*;
import net.minecraft.core.Registry;
@ -204,7 +201,7 @@ public class NMSBinding implements INMSBinding {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) convertToTag(map, 0, 64);
var level = ((CraftWorld) pos.getWorld()).getHandle();
var blockPos = new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
Iris.scheduler.region().run(pos, () -> merge(level, blockPos, tag));
Iris.platform.getRegionScheduler().run(pos, () -> merge(level, blockPos, tag));
}
private void merge(ServerLevel level, BlockPos blockPos, net.minecraft.nbt.CompoundTag tag) {

View File

@ -6,7 +6,6 @@ import com.volmit.iris.Iris;
import com.volmit.iris.core.nms.INMSBinding;
import com.volmit.iris.core.nms.container.AutoClosing;
import com.volmit.iris.core.nms.container.BiomeColor;
import com.volmit.iris.core.nms.container.Pair;
import com.volmit.iris.core.nms.datapack.DataVersion;
import com.volmit.iris.engine.data.cache.AtomicCache;
import com.volmit.iris.engine.framework.Engine;
@ -20,7 +19,6 @@ import com.volmit.iris.util.matter.MatterBiomeInject;
import com.volmit.iris.util.nbt.mca.NBTWorld;
import com.volmit.iris.util.nbt.mca.palette.*;
import com.volmit.iris.util.nbt.tag.CompoundTag;
import com.volmit.iris.util.scheduling.J;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import lombok.SneakyThrows;
import net.minecraft.core.Registry;
@ -80,7 +78,6 @@ import java.util.List;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Function;
public class NMSBinding implements INMSBinding {
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
@ -203,7 +200,7 @@ public class NMSBinding implements INMSBinding {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) convertToTag(map, 0, 64);
var level = ((CraftWorld) pos.getWorld()).getHandle();
var blockPos = new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
Iris.scheduler.region().run(pos, () -> merge(level, blockPos, tag));
Iris.platform.getRegionScheduler().run(pos, () -> merge(level, blockPos, tag));
}
private void merge(ServerLevel level, BlockPos blockPos, net.minecraft.nbt.CompoundTag tag) {

View File

@ -19,7 +19,6 @@ import com.volmit.iris.util.matter.MatterBiomeInject;
import com.volmit.iris.util.nbt.mca.NBTWorld;
import com.volmit.iris.util.nbt.mca.palette.*;
import com.volmit.iris.util.nbt.tag.CompoundTag;
import com.volmit.iris.util.scheduling.J;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import lombok.SneakyThrows;
import net.minecraft.core.Registry;
@ -201,7 +200,7 @@ public class NMSBinding implements INMSBinding {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) convertToTag(map, 0, 64);
var level = ((CraftWorld) pos.getWorld()).getHandle();
var blockPos = new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
Iris.scheduler.region().run(pos, () -> merge(level, blockPos, tag));
Iris.platform.getRegionScheduler().run(pos, () -> merge(level, blockPos, tag));
}
private void merge(ServerLevel level, BlockPos blockPos, net.minecraft.nbt.CompoundTag tag) {

View File

@ -1,7 +0,0 @@
plugins {
java
}
dependencies {
compileOnly("dev.folia:folia-api:1.20.1-R0.1-SNAPSHOT")
}

View File

@ -1,190 +0,0 @@
package com.volmit.iris.util.scheduling;
import com.volmit.iris.util.scheduling.paper.PaperPlatform;
import com.volmit.iris.util.scheduling.spigot.SpigotPlatform;
import com.volmit.iris.util.scheduling.split.IAsyncScheduler;
import com.volmit.iris.util.scheduling.split.IEntityScheduler;
import com.volmit.iris.util.scheduling.split.IGlobalScheduler;
import com.volmit.iris.util.scheduling.split.IRegionScheduler;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture;
@SuppressWarnings("unused")
public interface Platform {
/**
* Folia: Returns whether the current thread is ticking a region and that
* the region being ticked owns the chunk at the specified world and block
* position as included in the specified location.
* Paper/Spigot: Returns {@link Server#isPrimaryThread()}
*
* @param location Specified location, must have a non-null world
* @return true if the current thread is ticking the region that owns the chunk at the specified location
*/
boolean isOwnedByCurrentRegion(@NotNull Location location);
/**
* Folia: Returns whether the current thread is ticking a region and that
* the region being ticked owns the chunks centered at the specified world
* and block position as included in the specified location within the
* specified square radius. Specifically, this function checks that every
* chunk with position x in [centerX - radius, centerX + radius] and
* position z in [centerZ - radius, centerZ + radius] is owned by the
* current ticking region.
* Paper/Spigot: Returns {@link Server#isPrimaryThread()}
*
* @param location Specified location, must have a non-null world
* @param squareRadiusChunks Specified square radius. Must be >= 0. Note that this parameter is not a squared radius, but rather a Chebyshev Distance
* @return true if the current thread is ticking the region that owns the chunks centered at the specified location within the specified square radius
*/
boolean isOwnedByCurrentRegion(@NotNull Location location, int squareRadiusChunks);
/**
* Folia: Returns whether the current thread is ticking a region and that
* the region being ticked owns the chunk at the specified block position.
* Paper/Spigot: Returns {@link Server#isPrimaryThread()}
*
* @param block Specified block position
* @return true if the current thread is ticking the region that owns the chunk at the specified block position
*/
boolean isOwnedByCurrentRegion(@NotNull Block block);
/**
* Folia: Returns whether the current thread is ticking a region and that
* the region being ticked owns the chunk at the specified world and chunk
* position.
* Paper/Spigot: Returns {@link Server#isPrimaryThread()}
*
* @param world Specified world
* @param chunkX Specified x-coordinate of the chunk position
* @param chunkZ Specified z-coordinate of the chunk position
* @return true if the current thread is ticking the region that owns the chunk at the specified world and chunk position
*/
boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ);
/**
* Folia: Returns whether the current thread is ticking a region and that
* the region being ticked owns the chunks centered at the specified world
* and chunk position within the specified square radius. Specifically,
* this function checks that every chunk with position x in [centerX -
* radius, centerX + radius] and position z in [centerZ - radius, centerZ +
* radius] is owned by the current ticking region.
* Paper/Spigot: Returns {@link Server#isPrimaryThread()}
*
* @param world Specified world
* @param chunkX Specified x-coordinate of the chunk position
* @param chunkZ Specified z-coordinate of the chunk position
* @param squareRadiusChunks Specified square radius. Must be >= 0. Note that this parameter is not a squared radius, but rather a Chebyshev Distance.
* @return true if the current thread is ticking the region that owns the chunks centered at the specified world and chunk position within the specified square radius
*/
boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ, int squareRadiusChunks);
/**
* Folia: Returns whether the current thread is ticking a region and that
* the region being ticked owns the specified entity. Note that this
* function is the only appropriate method of checking for ownership of an
* entity, as retrieving the entity's location is undefined unless the
* entity is owned by the current region.
* Paper/Spigot: Returns {@link Server#isPrimaryThread()}
*
* @param entity Specified entity
* @return true if the current thread is ticking the region that owns the specified entity
*/
boolean isOwnedByCurrentRegion(@NotNull Entity entity);
/**
* Folia: Returns whether the current thread is ticking the global region.
* Paper/Spigot: Returns {@link Server#isPrimaryThread()}
*
* @return true if the current thread is ticking the global region
*/
boolean isGlobalTickThread();
/**
* Scheduler that may be used by plugins to schedule tasks to execute asynchronously from the server tick process.
*/
@NotNull IAsyncScheduler async();
/**
* An entity can move between worlds with an arbitrary tick delay, be temporarily removed
* for players (i.e end credits), be partially removed from world state (i.e inactive but not removed),
* teleport between ticking regions, teleport between worlds, and even be removed entirely from the server.
* The uncertainty of an entity's state can make it difficult to schedule tasks without worrying about undefined
* behaviors resulting from any of the states listed previously.
*
* <p>
* This class is designed to eliminate those states by providing an interface to run tasks only when an entity
* is contained in a world, on the owning thread for the region, and by providing the current Entity object.
* The scheduler also allows a task to provide a callback, the "retired" callback, that will be invoked
* if the entity is removed before a task that was scheduled could be executed. The scheduler is also
* completely thread-safe, allowing tasks to be scheduled from any thread context. The scheduler also indicates
* properly whether a task was scheduled successfully (i.e scheduler not retired), thus the code scheduling any task
* knows whether the given callbacks will be invoked eventually or not - which may be critical for off-thread
* contexts.
* </p>
*/
@NotNull IEntityScheduler entity(@NotNull Entity entity);
/**
* The global region task scheduler may be used to schedule tasks that will execute on the global region.
* <p>
* The global region is responsible for maintaining world day time, world game time, weather cycle,
* sleep night skipping, executing commands for console, and other misc. tasks that do not belong to any specific region.
* </p>
*/
@NotNull IGlobalScheduler global();
/**
* The region task scheduler can be used to schedule tasks by location to be executed on the region which owns the location.
* <p>
* <b>Note</b>: It is entirely inappropriate to use the region scheduler to schedule tasks for entities.
* If you wish to schedule tasks to perform actions on entities, you should be using {@link Entity#getScheduler()}
* as the entity scheduler will "follow" an entity if it is teleported, whereas the region task scheduler
* will not.
* </p>
*/
@NotNull IRegionScheduler region();
/**
* Teleport an entity to a location async
* @param entity Entity to teleport
* @param location Location to teleport to
* @return Future when the teleport is completed or failed
*/
default @NotNull CompletableFuture<@NotNull Boolean> teleportAsync(@NotNull Entity entity, @NotNull Location location) {
return teleportAsync(entity, location, PlayerTeleportEvent.TeleportCause.PLUGIN);
}
/**
* Teleport an entity to a location async with a cause
* @param entity Entity to teleport
* @param location Location to teleport to
* @param cause Cause of the teleport
* @return Future when the teleport is completed or failed
*/
@NotNull CompletableFuture<@NotNull Boolean> teleportAsync(@NotNull Entity entity, @NotNull Location location, @NotNull PlayerTeleportEvent.TeleportCause cause);
static @NotNull Platform create(@NotNull Plugin plugin) {
if (hasClass("com.destroystokyo.paper.PaperConfig") || hasClass("io.papermc.paper.configuration.Configuration"))
return new PaperPlatform(plugin);
if (hasClass("org.spigotmc.SpigotConfig"))
return new SpigotPlatform(plugin);
throw new IllegalStateException("Unsupported platform!");
}
static boolean hasClass(String name) {
try {
Class.forName(name);
return true;
} catch (Throwable e) {
return false;
}
}
}

View File

@ -1,5 +0,0 @@
package com.volmit.iris.util.scheduling;
public final class Ref<T> {
public transient T value;
}

View File

@ -1,27 +0,0 @@
package com.volmit.iris.util.scheduling;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
public interface Task {
void cancel();
boolean cancelled();
@NotNull Plugin owner();
boolean async();
interface Completable<T> extends Task {
@NotNull CompletableFuture<T> result();
default void complete(Function<Completable<T>, T> function) {
var future = result();
try {
future.complete(function.apply(this));
} catch (Throwable e) {
future.completeExceptionally(e);
}
}
}
}

View File

@ -1,107 +0,0 @@
package com.volmit.iris.util.scheduling.paper;
import com.volmit.iris.util.scheduling.Platform;
import com.volmit.iris.util.scheduling.paper.split.PaperAsyncScheduler;
import com.volmit.iris.util.scheduling.paper.split.PaperEntityScheduler;
import com.volmit.iris.util.scheduling.paper.split.PaperGlobalScheduler;
import com.volmit.iris.util.scheduling.paper.split.PaperRegionScheduler;
import com.volmit.iris.util.scheduling.split.IAsyncScheduler;
import com.volmit.iris.util.scheduling.split.IEntityScheduler;
import com.volmit.iris.util.scheduling.split.IGlobalScheduler;
import com.volmit.iris.util.scheduling.split.IRegionScheduler;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture;
import java.util.function.BooleanSupplier;
public class PaperPlatform implements Platform {
private final Plugin plugin;
private final Server server;
private final IAsyncScheduler async;
private final IGlobalScheduler global;
private final IRegionScheduler region;
private final BooleanSupplier globalTickThread;
public PaperPlatform(@NotNull Plugin plugin) {
this.plugin = plugin;
this.server = plugin.getServer();
async = new PaperAsyncScheduler(plugin, server.getAsyncScheduler());
global = new PaperGlobalScheduler(plugin, server.getGlobalRegionScheduler());
region = new PaperRegionScheduler(plugin, server.getRegionScheduler());
BooleanSupplier method;
try {
method = server::isGlobalTickThread;
} catch (Throwable e) {
method = server::isPrimaryThread;
}
globalTickThread = method;
}
@Override
public boolean isOwnedByCurrentRegion(@NotNull Location location) {
return server.isOwnedByCurrentRegion(location);
}
@Override
public boolean isOwnedByCurrentRegion(@NotNull Location location, int squareRadiusChunks) {
return server.isOwnedByCurrentRegion(location, squareRadiusChunks);
}
@Override
public boolean isOwnedByCurrentRegion(@NotNull Block block) {
return server.isOwnedByCurrentRegion(block);
}
@Override
public boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ) {
return server.isOwnedByCurrentRegion(world, chunkX, chunkZ);
}
@Override
public boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ, int squareRadiusChunks) {
return server.isOwnedByCurrentRegion(world, chunkX, chunkZ, squareRadiusChunks);
}
@Override
public boolean isOwnedByCurrentRegion(@NotNull Entity entity) {
return server.isOwnedByCurrentRegion(entity);
}
@Override
public boolean isGlobalTickThread() {
return globalTickThread.getAsBoolean();
}
@Override
public @NotNull IAsyncScheduler async() {
return async;
}
@Override
public @NotNull IEntityScheduler entity(@NotNull Entity entity) {
return new PaperEntityScheduler(plugin, entity.getScheduler());
}
@Override
public @NotNull IGlobalScheduler global() {
return global;
}
@Override
public @NotNull IRegionScheduler region() {
return region;
}
@Override
public @NotNull CompletableFuture<@NotNull Boolean> teleportAsync(@NotNull Entity entity, @NotNull Location location, PlayerTeleportEvent.@NotNull TeleportCause cause) {
return entity.teleportAsync(location, cause);
}
}

View File

@ -1,59 +0,0 @@
package com.volmit.iris.util.scheduling.paper;
import com.volmit.iris.util.scheduling.Task;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture;
public class PaperTask implements Task {
protected final ScheduledTask task;
protected final boolean async;
public PaperTask(@NotNull ScheduledTask task, boolean async) {
this.task = task;
this.async = async;
}
@Override
public void cancel() {
task.cancel();
}
@Override
public boolean cancelled() {
return task.isCancelled();
}
@Override
public @NotNull Plugin owner() {
return task.getOwningPlugin();
}
@Override
public boolean async() {
return async;
}
public static class Completable<T> extends PaperTask implements Task.Completable<T> {
private final CompletableFuture<T> result = new CompletableFuture<>();
public Completable(@NotNull ScheduledTask task, boolean async) {
super(task, async);
}
@Override
public void cancel() {
ScheduledTask.CancelledState cancel = task.cancel();
if (cancel == ScheduledTask.CancelledState.CANCELLED_BY_CALLER || cancel == ScheduledTask.CancelledState.NEXT_RUNS_CANCELLED || cancel == ScheduledTask.CancelledState.CANCELLED_ALREADY) {
result.cancel(false);
}
}
@Override
public @NotNull CompletableFuture<T> result() {
return result;
}
}
}

View File

@ -1,48 +0,0 @@
package com.volmit.iris.util.scheduling.paper.split;
import com.volmit.iris.util.scheduling.Ref;
import com.volmit.iris.util.scheduling.Task;
import com.volmit.iris.util.scheduling.Task.Completable;
import com.volmit.iris.util.scheduling.paper.PaperTask;
import com.volmit.iris.util.scheduling.split.IAsyncScheduler;
import io.papermc.paper.threadedregions.scheduler.AsyncScheduler;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Range;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Function;
public class PaperAsyncScheduler implements IAsyncScheduler {
private final Plugin plugin;
private final AsyncScheduler scheduler;
public PaperAsyncScheduler(Plugin plugin, AsyncScheduler scheduler) {
this.plugin = plugin;
this.scheduler = scheduler;
}
@Override
public @NotNull <R> Completable<R> run(@NotNull Function<Completable<R>, R> task) {
Ref<Completable<R>> ref = new Ref<>();
return ref.value = new PaperTask.Completable<>(scheduler.runNow(plugin, t -> ref.value.complete(task)), true);
}
@Override
public @NotNull <R> Completable<R> runDelayed(@NotNull Function<Completable<R>, R> task,
@Range(from = 0, to = Long.MAX_VALUE) long delay,
@NotNull TimeUnit unit) {
Ref<Completable<R>> ref = new Ref<>();
return ref.value = new PaperTask.Completable<>(scheduler.runDelayed(plugin, t -> ref.value.complete(task), delay, unit), true);
}
@Override
public @NotNull Task runAtFixedRate(@NotNull Consumer<Task> task,
@Range(from = 0, to = Long.MAX_VALUE) long initialDelay,
@Range(from = 1, to = Long.MAX_VALUE) long period,
@NotNull TimeUnit unit) {
Ref<Task> ref = new Ref<>();
return ref.value = new PaperTask(scheduler.runAtFixedRate(plugin, t -> task.accept(ref.value), initialDelay, period, unit), true);
}
}

View File

@ -1,49 +0,0 @@
package com.volmit.iris.util.scheduling.paper.split;
import com.volmit.iris.util.scheduling.Ref;
import com.volmit.iris.util.scheduling.Task;
import com.volmit.iris.util.scheduling.Task.Completable;
import com.volmit.iris.util.scheduling.paper.PaperTask;
import com.volmit.iris.util.scheduling.split.IEntityScheduler;
import io.papermc.paper.threadedregions.scheduler.EntityScheduler;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Range;
import java.util.function.Consumer;
import java.util.function.Function;
public class PaperEntityScheduler implements IEntityScheduler {
private final Plugin plugin;
private final EntityScheduler scheduler;
public PaperEntityScheduler(Plugin plugin, EntityScheduler scheduler) {
this.plugin = plugin;
this.scheduler = scheduler;
}
@Override
public @Nullable <R> Completable<R> runDelayed(@NotNull Function<Completable<R>, R> task,
@Nullable Runnable retired,
@Range(from = 1, to = Long.MAX_VALUE) long delayTicks) {
Ref<Completable<R>> ref = new Ref<>();
var raw = scheduler.runDelayed(plugin, t -> ref.value.complete(task), () -> {
if (retired != null) retired.run();
ref.value.cancel();
}, delayTicks);
if (raw == null) return null;
return ref.value = new PaperTask.Completable<>(raw, false);
}
@Override
public @Nullable Task runAtFixedRate(@NotNull Consumer<Task> task,
@Nullable Runnable retired,
@Range(from = 1, to = Long.MAX_VALUE) long initialDelayTicks,
@Range(from = 1, to = Long.MAX_VALUE) long periodTicks) {
Ref<Task> ref = new Ref<>();
var raw = scheduler.runAtFixedRate(plugin, t -> task.accept(ref.value), retired, initialDelayTicks, periodTicks);
if (raw == null) return null;
return ref.value = new PaperTask(raw, false);
}
}

View File

@ -1,39 +0,0 @@
package com.volmit.iris.util.scheduling.paper.split;
import com.volmit.iris.util.scheduling.Ref;
import com.volmit.iris.util.scheduling.Task;
import com.volmit.iris.util.scheduling.Task.Completable;
import com.volmit.iris.util.scheduling.paper.PaperTask;
import com.volmit.iris.util.scheduling.split.IGlobalScheduler;
import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Range;
import java.util.function.Consumer;
import java.util.function.Function;
public class PaperGlobalScheduler implements IGlobalScheduler {
private final Plugin plugin;
private final GlobalRegionScheduler scheduler;
public PaperGlobalScheduler(Plugin plugin, GlobalRegionScheduler scheduler) {
this.plugin = plugin;
this.scheduler = scheduler;
}
@Override
public @NotNull <R> Completable<R> runDelayed(@NotNull Function<Completable<R>, R> task,
@Range(from = 1, to = Long.MAX_VALUE) long delayTicks) {
Ref<Completable<R>> ref = new Ref<>();
return ref.value = new PaperTask.Completable<>(scheduler.runDelayed(plugin, t -> ref.value.complete(task), delayTicks), false);
}
@Override
public @NotNull Task runAtFixedRate(@NotNull Consumer<Task> task,
@Range(from = 1, to = Long.MAX_VALUE) long initialDelayTicks,
@Range(from = 1, to = Long.MAX_VALUE) long periodTicks) {
Ref<Task> ref = new Ref<>();
return ref.value = new PaperTask(scheduler.runAtFixedRate(plugin, t -> task.accept(ref.value), initialDelayTicks, periodTicks), false);
}
}

View File

@ -1,45 +0,0 @@
package com.volmit.iris.util.scheduling.paper.split;
import com.volmit.iris.util.scheduling.Ref;
import com.volmit.iris.util.scheduling.Task;
import com.volmit.iris.util.scheduling.Task.Completable;
import com.volmit.iris.util.scheduling.paper.PaperTask;
import com.volmit.iris.util.scheduling.split.IRegionScheduler;
import io.papermc.paper.threadedregions.scheduler.RegionScheduler;
import org.bukkit.World;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Range;
import java.util.function.Consumer;
import java.util.function.Function;
public class PaperRegionScheduler implements IRegionScheduler {
private final Plugin plugin;
private final RegionScheduler scheduler;
public PaperRegionScheduler(Plugin plugin, RegionScheduler scheduler) {
this.plugin = plugin;
this.scheduler = scheduler;
}
@Override
public @NotNull <R> Completable<R> runDelayed(@NotNull World world,
int chunkX,
int chunkZ,
@NotNull Function<Completable<R>, R> task, @Range(from = 1, to = Long.MAX_VALUE) long delayTicks) {
Ref<Completable<R>> ref = new Ref<>();
return ref.value = new PaperTask.Completable<>(scheduler.runDelayed(plugin, world, chunkX, chunkZ, t -> ref.value.complete(task), delayTicks), false);
}
@Override
public @NotNull Task runAtFixedRate(@NotNull World world,
int chunkX,
int chunkZ,
@NotNull Consumer<Task> task,
@Range(from = 1, to = Long.MAX_VALUE) long initialDelayTicks,
@Range(from = 1, to = Long.MAX_VALUE) long periodTicks) {
Ref<Task> ref = new Ref<>();
return ref.value = new PaperTask(scheduler.runAtFixedRate(plugin, world, chunkX, chunkZ, t -> task.accept(ref.value), initialDelayTicks, periodTicks), false);
}
}

View File

@ -1,105 +0,0 @@
package com.volmit.iris.util.scheduling.spigot;
import com.volmit.iris.util.scheduling.Platform;
import com.volmit.iris.util.scheduling.spigot.split.SpigotAsyncScheduler;
import com.volmit.iris.util.scheduling.spigot.split.SpigotEntityScheduler;
import com.volmit.iris.util.scheduling.spigot.split.SpigotGlobalScheduler;
import com.volmit.iris.util.scheduling.spigot.split.SpigotRegionScheduler;
import com.volmit.iris.util.scheduling.split.IAsyncScheduler;
import com.volmit.iris.util.scheduling.split.IEntityScheduler;
import com.volmit.iris.util.scheduling.split.IGlobalScheduler;
import com.volmit.iris.util.scheduling.split.IRegionScheduler;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture;
public class SpigotPlatform implements Platform {
private final Server server;
private final IAsyncScheduler async;
private final IGlobalScheduler global;
private final IRegionScheduler region;
public SpigotPlatform(@NotNull Plugin plugin) {
server = plugin.getServer();
var scheduler = server.getScheduler();
async = new SpigotAsyncScheduler(plugin, scheduler);
global = new SpigotGlobalScheduler(plugin, scheduler);
region = new SpigotRegionScheduler(global);
}
@Override
public boolean isOwnedByCurrentRegion(@NotNull Location location) {
return server.isPrimaryThread();
}
@Override
public boolean isOwnedByCurrentRegion(@NotNull Location location, int squareRadiusChunks) {
return server.isPrimaryThread();
}
@Override
public boolean isOwnedByCurrentRegion(@NotNull Block block) {
return server.isPrimaryThread();
}
@Override
public boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ) {
return server.isPrimaryThread();
}
@Override
public boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ, int squareRadiusChunks) {
return server.isPrimaryThread();
}
@Override
public boolean isOwnedByCurrentRegion(@NotNull Entity entity) {
return server.isPrimaryThread();
}
@Override
public boolean isGlobalTickThread() {
return server.isPrimaryThread();
}
@Override
public @NotNull IAsyncScheduler async() {
return async;
}
@Override
public @NotNull IEntityScheduler entity(@NotNull Entity entity) {
return new SpigotEntityScheduler(global, entity);
}
@Override
public @NotNull IGlobalScheduler global() {
return global;
}
@Override
public @NotNull IRegionScheduler region() {
return region;
}
@Override
public @NotNull CompletableFuture<@NotNull Boolean> teleportAsync(@NotNull Entity entity, @NotNull Location location, PlayerTeleportEvent.@NotNull TeleportCause cause) {
return global().<Boolean>run(task -> isValid(entity) && entity.teleport(location)).result().thenApply(b -> b != null ? b : false);
}
public static boolean isValid(Entity entity) {
if (entity.isValid()) {
return !(entity instanceof Player) || ((Player) entity).isOnline();
}
return entity instanceof Projectile && !entity.isDead();
}
}

View File

@ -1,60 +0,0 @@
package com.volmit.iris.util.scheduling.spigot;
import com.volmit.iris.util.scheduling.Task;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture;
public class SpigotTask implements Task {
protected final BukkitTask task;
public SpigotTask(@NotNull BukkitTask task) {
this.task = task;
}
@Override
public void cancel() {
task.cancel();
}
@Override
public boolean cancelled() {
return task.isCancelled();
}
@Override
public @NotNull Plugin owner() {
return task.getOwner();
}
@Override
public boolean async() {
return !task.isSync();
}
@SuppressWarnings("deprecation")
public static class Completable<T> extends SpigotTask implements Task.Completable<T> {
private final CompletableFuture<T> result = new CompletableFuture<>();
private final BukkitScheduler scheduler;
public Completable(@NotNull BukkitTask task, @NotNull BukkitScheduler scheduler) {
super(task);
this.scheduler = scheduler;
}
@Override
public void cancel() {
scheduler.cancelTask(task.getTaskId());
if (scheduler.isCurrentlyRunning(task.getTaskId())) return;
result.cancel(false);
}
@Override
public @NotNull CompletableFuture<T> result() {
return result;
}
}
}

View File

@ -1,44 +0,0 @@
package com.volmit.iris.util.scheduling.spigot.split;
import com.volmit.iris.util.scheduling.Ref;
import com.volmit.iris.util.scheduling.Task;
import com.volmit.iris.util.scheduling.Task.Completable;
import com.volmit.iris.util.scheduling.spigot.SpigotTask;
import com.volmit.iris.util.scheduling.split.IAsyncScheduler;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitScheduler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Range;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Function;
@SuppressWarnings("deprecation")
public class SpigotAsyncScheduler implements IAsyncScheduler {
private final Plugin plugin;
private final BukkitScheduler scheduler;
public SpigotAsyncScheduler(Plugin plugin, BukkitScheduler scheduler) {
this.plugin = plugin;
this.scheduler = scheduler;
}
@Override
public @NotNull <R> Completable<R> run(@NotNull Function<Completable<R>, R> task) {
Ref<Completable<R>> ref = new Ref<>();
return ref.value = new SpigotTask.Completable<>(scheduler.runTaskAsynchronously(plugin, () -> ref.value.complete(task)), scheduler);
}
@Override
public @NotNull <R> Completable<R> runDelayed(@NotNull Function<Completable<R>, R> task, @Range(from = 0, to = Long.MAX_VALUE) long delay, @NotNull TimeUnit unit) {
Ref<Completable<R>> ref = new Ref<>();
return ref.value = new SpigotTask.Completable<>(scheduler.runTaskLaterAsynchronously(plugin, () -> ref.value.complete(task), unit.toMillis(delay) / 50), scheduler);
}
@Override
public @NotNull Task runAtFixedRate(@NotNull Consumer<Task> task, @Range(from = 0, to = Long.MAX_VALUE) long initialDelay, @Range(from = 0, to = Long.MAX_VALUE) long period, @NotNull TimeUnit unit) {
Ref<Task> ref = new Ref<>();
return ref.value = new SpigotTask(scheduler.runTaskTimerAsynchronously(plugin, () -> task.accept(ref.value), unit.toMillis(initialDelay) / 50, unit.toMillis(period) / 50));
}
}

View File

@ -1,53 +0,0 @@
package com.volmit.iris.util.scheduling.spigot.split;
import com.volmit.iris.util.scheduling.Task;
import com.volmit.iris.util.scheduling.Task.Completable;
import com.volmit.iris.util.scheduling.split.IEntityScheduler;
import com.volmit.iris.util.scheduling.split.IGlobalScheduler;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Range;
import java.util.function.Consumer;
import java.util.function.Function;
import static com.volmit.iris.util.scheduling.spigot.SpigotPlatform.isValid;
public class SpigotEntityScheduler implements IEntityScheduler {
private final IGlobalScheduler scheduler;
private final Entity entity;
public SpigotEntityScheduler(IGlobalScheduler scheduler, Entity entity) {
this.scheduler = scheduler;
this.entity = entity;
}
@Override
public @Nullable <R> Completable<R> runDelayed(@NotNull Function<Completable<R>, R> task, @Nullable Runnable retired, @Range(from = 1, to = Long.MAX_VALUE) long delayTicks) {
if (!isValid(entity)) return null;
return scheduler.runDelayed(t -> {
if (!isValid(entity)) {
t.cancel();
if (retired != null)
retired.run();
return null;
}
return task.apply(t);
}, delayTicks);
}
@Override
public @Nullable Task runAtFixedRate(@NotNull Consumer<Task> task, @Nullable Runnable retired, @Range(from = 1, to = Long.MAX_VALUE) long initialDelayTicks, @Range(from = 1, to = Long.MAX_VALUE) long periodTicks) {
if (!isValid(entity)) return null;
return scheduler.runAtFixedRate(t -> {
if (!isValid(entity)) {
t.cancel();
if (retired != null)
retired.run();
return;
}
task.accept(t);
}, initialDelayTicks, periodTicks);
}
}

View File

@ -1,37 +0,0 @@
package com.volmit.iris.util.scheduling.spigot.split;
import com.volmit.iris.util.scheduling.Ref;
import com.volmit.iris.util.scheduling.Task;
import com.volmit.iris.util.scheduling.Task.Completable;
import com.volmit.iris.util.scheduling.spigot.SpigotTask;
import com.volmit.iris.util.scheduling.split.IGlobalScheduler;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitScheduler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Range;
import java.util.function.Consumer;
import java.util.function.Function;
@SuppressWarnings("deprecation")
public class SpigotGlobalScheduler implements IGlobalScheduler {
private final Plugin plugin;
private final BukkitScheduler scheduler;
public SpigotGlobalScheduler(Plugin plugin, BukkitScheduler scheduler) {
this.plugin = plugin;
this.scheduler = scheduler;
}
@Override
public @NotNull <R> Completable<R> runDelayed(@NotNull Function<Completable<R>, R> task, @Range(from = 1, to = Long.MAX_VALUE) long delayTicks) {
Ref<Completable<R>> ref = new Ref<>();
return ref.value = new SpigotTask.Completable<>(scheduler.runTaskLater(plugin, () -> ref.value.complete(task), delayTicks), scheduler);
}
@Override
public @NotNull Task runAtFixedRate(@NotNull Consumer<Task> task, @Range(from = 1, to = Long.MAX_VALUE) long initialDelayTicks, @Range(from = 1, to = Long.MAX_VALUE) long periodTicks) {
Ref<Task> ref = new Ref<>();
return ref.value = new SpigotTask(scheduler.runTaskTimer(plugin, () -> task.accept(ref.value), initialDelayTicks, periodTicks));
}
}

View File

@ -1,30 +0,0 @@
package com.volmit.iris.util.scheduling.spigot.split;
import com.volmit.iris.util.scheduling.Task;
import com.volmit.iris.util.scheduling.Task.Completable;
import com.volmit.iris.util.scheduling.split.IGlobalScheduler;
import com.volmit.iris.util.scheduling.split.IRegionScheduler;
import org.bukkit.World;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Range;
import java.util.function.Consumer;
import java.util.function.Function;
public class SpigotRegionScheduler implements IRegionScheduler {
private final IGlobalScheduler scheduler;
public SpigotRegionScheduler(IGlobalScheduler scheduler) {
this.scheduler = scheduler;
}
@Override
public @NotNull <R> Completable<R> runDelayed(@NotNull World world, int chunkX, int chunkZ, @NotNull Function<Completable<R>, R> task, @Range(from = 1, to = Long.MAX_VALUE) long delayTicks) {
return scheduler.runDelayed(task, delayTicks);
}
@Override
public @NotNull Task runAtFixedRate(@NotNull World world, int chunkX, int chunkZ, @NotNull Consumer<Task> task, @Range(from = 1, to = Long.MAX_VALUE) long initialDelayTicks, @Range(from = 1, to = Long.MAX_VALUE) long periodTicks) {
return scheduler.runAtFixedRate(task, initialDelayTicks, periodTicks);
}
}

View File

@ -1,146 +0,0 @@
package com.volmit.iris.util.scheduling.split;
import com.volmit.iris.util.scheduling.Task;
import com.volmit.iris.util.scheduling.Task.Completable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Range;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* Scheduler that may be used by plugins to schedule tasks to execute asynchronously from the server tick process.
*/
public interface IAsyncScheduler {
/**
* Schedules the specified task to be executed asynchronously immediately.
* @param task Specified task.
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task run(@NotNull Consumer<Task> task) {
return run(t -> {
task.accept(t);
return null;
});
}
/**
* Schedules the specified task to be executed asynchronously immediately.
* @param task Specified task.
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task run(@NotNull Runnable task) {
return run(t -> {
task.run();
return null;
});
}
/**
* Schedules the specified task to be executed asynchronously immediately.
* @param task Specified task.
* @return The {@link Completable} that represents the scheduled task.
*/
default @NotNull <R> Completable<R> run(@NotNull Supplier<R> task) {
return run(t -> {
return task.get();
});
}
/**
* Schedules the specified task to be executed asynchronously immediately.
* @param task Specified task.
* @return The {@link Completable} that represents the scheduled task.
*/
@NotNull <R> Completable<R> run(@NotNull Function<Completable<R>, R> task);
/**
* Schedules the specified task to be executed asynchronously after the time delay has passed.
* @param task Specified task.
* @param delay The time delay to pass before the task should be executed.
* @param unit The time unit for the time delay.
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task runDelayed(@NotNull Consumer<Task> task,
@Range(from = 0, to = Long.MAX_VALUE) long delay,
@NotNull TimeUnit unit) {
return runDelayed(t -> {
task.accept(t);
return null;
}, delay, unit);
}
/**
* Schedules the specified task to be executed asynchronously after the time delay has passed.
* @param task Specified task.
* @param delay The time delay to pass before the task should be executed.
* @param unit The time unit for the time delay.
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task runDelayed(@NotNull Runnable task,
@Range(from = 0, to = Long.MAX_VALUE) long delay,
@NotNull TimeUnit unit) {
return runDelayed(t -> {
task.run();
return null;
}, delay, unit);
}
/**
* Schedules the specified task to be executed asynchronously after the time delay has passed.
* @param task Specified task.
* @param delay The time delay to pass before the task should be executed.
* @param unit The time unit for the time delay.
* @return The {@link Completable} that represents the scheduled task.
*/
default @NotNull <R> Completable<R> runDelayed(@NotNull Supplier<R> task,
@Range(from = 0, to = Long.MAX_VALUE) long delay,
@NotNull TimeUnit unit) {
return runDelayed(t -> {
return task.get();
}, delay, unit);
}
/**
* Schedules the specified task to be executed asynchronously after the time delay has passed.
* @param task Specified task.
* @param delay The time delay to pass before the task should be executed.
* @param unit The time unit for the time delay.
* @return The {@link Completable} that represents the scheduled task.
*/
@NotNull <R> Completable<R> runDelayed(@NotNull Function<Completable<R>, R> task,
@Range(from = 0, to = Long.MAX_VALUE) long delay,
@NotNull TimeUnit unit);
/**
* Schedules the specified task to be executed asynchronously after the initial delay has passed,
* and then periodically executed with the specified period.
* @param task Specified task.
* @param initialDelay The time delay to pass before the first execution of the task.
* @param period The time between task executions after the first execution of the task.
* @param unit The time unit for the initial delay and period.
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task runAtFixedRate(@NotNull Runnable task,
@Range(from = 0, to = Long.MAX_VALUE) long initialDelay,
@Range(from = 1, to = Long.MAX_VALUE) long period,
@NotNull TimeUnit unit) {
return runAtFixedRate(t -> task.run(), initialDelay, period, unit);
}
/**
* Schedules the specified task to be executed asynchronously after the initial delay has passed,
* and then periodically executed with the specified period.
* @param task Specified task.
* @param initialDelay The time delay to pass before the first execution of the task.
* @param period The time between task executions after the first execution of the task.
* @param unit The time unit for the initial delay and period.
* @return The {@link Task} that represents the scheduled task.
*/
@NotNull Task runAtFixedRate(@NotNull Consumer<Task> task,
@Range(from = 0, to = Long.MAX_VALUE) long initialDelay,
@Range(from = 1, to = Long.MAX_VALUE) long period,
@NotNull TimeUnit unit);
}

View File

@ -1,250 +0,0 @@
package com.volmit.iris.util.scheduling.split;
import com.volmit.iris.util.scheduling.Task;
import com.volmit.iris.util.scheduling.Task.Completable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Range;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* An entity can move between worlds with an arbitrary tick delay, be temporarily removed
* for players (i.e end credits), be partially removed from world state (i.e inactive but not removed),
* teleport between ticking regions, teleport between worlds, and even be removed entirely from the server.
* The uncertainty of an entity's state can make it difficult to schedule tasks without worrying about undefined
* behaviors resulting from any of the states listed previously.
*
* <p>
* This class is designed to eliminate those states by providing an interface to run tasks only when an entity
* is contained in a world, on the owning thread for the region, and by providing the current Entity object.
* The scheduler also allows a task to provide a callback, the "retired" callback, that will be invoked
* if the entity is removed before a task that was scheduled could be executed. The scheduler is also
* completely thread-safe, allowing tasks to be scheduled from any thread context. The scheduler also indicates
* properly whether a task was scheduled successfully (i.e scheduler not retired), thus the code scheduling any task
* knows whether the given callbacks will be invoked eventually or not - which may be critical for off-thread
* contexts.
* </p>
*/
public interface IEntityScheduler {
/**
* Schedules a task to execute on the next tick. If the task failed to schedule because the scheduler is retired (entity
* removed), then returns {@code null}. Otherwise, either the task callback will be invoked after the specified delay,
* or the retired callback will be invoked if the scheduler is retired.
* Note that the retired callback is invoked in critical code, so it should not attempt to remove the entity, remove
* other entities, load chunks, load worlds, modify ticket levels, etc.
*
* <p>
* It is guaranteed that the task and retired callback are invoked on the region which owns the entity.
* </p>
* @param task The task to execute
* @param retired Retire callback to run if the entity is retired before the run callback can be invoked, may be null.
* @return The {@link Task} that represents the scheduled task, or {@code null} if the entity has been removed.
*/
default @Nullable Task run(@NotNull Consumer<Task> task,
@Nullable Runnable retired) {
return run(t -> {
task.accept(t);
return null;
}, retired);
}
/**
* Schedules a task to execute on the next tick. If the task failed to schedule because the scheduler is retired (entity
* removed), then returns {@code null}. Otherwise, either the task callback will be invoked after the specified delay,
* or the retired callback will be invoked if the scheduler is retired.
* Note that the retired callback is invoked in critical code, so it should not attempt to remove the entity, remove
* other entities, load chunks, load worlds, modify ticket levels, etc.
*
* <p>
* It is guaranteed that the task and retired callback are invoked on the region which owns the entity.
* </p>
* @param task The task to execute
* @param retired Retire callback to run if the entity is retired before the run callback can be invoked, may be null.
* @return The {@link Task} that represents the scheduled task, or {@code null} if the entity has been removed.
*/
default @Nullable Task run(@NotNull Runnable task,
@Nullable Runnable retired) {
return run(t -> {
task.run();
return null;
}, retired);
}
/**
* Schedules a task to execute on the next tick. If the task failed to schedule because the scheduler is retired (entity
* removed), then returns {@code null}. Otherwise, either the task callback will be invoked after the specified delay,
* or the retired callback will be invoked if the scheduler is retired.
* Note that the retired callback is invoked in critical code, so it should not attempt to remove the entity, remove
* other entities, load chunks, load worlds, modify ticket levels, etc.
*
* <p>
* It is guaranteed that the task and retired callback are invoked on the region which owns the entity.
* </p>
* @param task The task to execute
* @param retired Retire callback to run if the entity is retired before the run callback can be invoked, may be null.
* @return The {@link Completable} that represents the scheduled task, or {@code null} if the entity has been removed.
*/
default @Nullable <R> Completable<R> run(@NotNull Supplier<R> task,
@Nullable Runnable retired) {
return run(t -> {
return task.get();
}, retired);
}
/**
* Schedules a task to execute on the next tick. If the task failed to schedule because the scheduler is retired (entity
* removed), then returns {@code null}. Otherwise, either the task callback will be invoked after the specified delay,
* or the retired callback will be invoked if the scheduler is retired.
* Note that the retired callback is invoked in critical code, so it should not attempt to remove the entity, remove
* other entities, load chunks, load worlds, modify ticket levels, etc.
*
* <p>
* It is guaranteed that the task and retired callback are invoked on the region which owns the entity.
* </p>
* @param task The task to execute
* @param retired Retire callback to run if the entity is retired before the run callback can be invoked, may be null.
* @return The {@link Completable} that represents the scheduled task, or {@code null} if the entity has been removed.
*/
default @Nullable <R> Completable<R> run(@NotNull Function<Completable<R>, R> task,
@Nullable Runnable retired) {
return runDelayed(task, retired, 1);
}
/**
* Schedules a task with the given delay. If the task failed to schedule because the scheduler is retired (entity
* removed), then returns {@code null}. Otherwise, either the task callback will be invoked after the specified delay,
* or the retired callback will be invoked if the scheduler is retired.
* Note that the retired callback is invoked in critical code, so it should not attempt to remove the entity, remove
* other entities, load chunks, load worlds, modify ticket levels, etc.
*
* <p>
* It is guaranteed that the task and retired callback are invoked on the region which owns the entity.
* </p>
* @param task The task to execute
* @param retired Retire callback to run if the entity is retired before the run callback can be invoked, may be null.
* @param delayTicks The delay, in ticks.
* @return The {@link Task} that represents the scheduled task, or {@code null} if the entity has been removed.
*/
default @Nullable Task runDelayed(@NotNull Consumer<Task> task,
@Nullable Runnable retired,
@Range(from = 1, to = Long.MAX_VALUE) long delayTicks) {
return runDelayed(t -> {
task.accept(t);
return null;
}, retired, delayTicks);
}
/**
* Schedules a task with the given delay. If the task failed to schedule because the scheduler is retired (entity
* removed), then returns {@code null}. Otherwise, either the task callback will be invoked after the specified delay,
* or the retired callback will be invoked if the scheduler is retired.
* Note that the retired callback is invoked in critical code, so it should not attempt to remove the entity, remove
* other entities, load chunks, load worlds, modify ticket levels, etc.
*
* <p>
* It is guaranteed that the task and retired callback are invoked on the region which owns the entity.
* </p>
* @param task The task to execute
* @param retired Retire callback to run if the entity is retired before the run callback can be invoked, may be null.
* @param delayTicks The delay, in ticks.
* @return The {@link Task} that represents the scheduled task, or {@code null} if the entity has been removed.
*/
default @Nullable Task runDelayed(@NotNull Runnable task,
@Nullable Runnable retired,
@Range(from = 1, to = Long.MAX_VALUE) long delayTicks) {
return runDelayed(t -> {
task.run();
return null;
}, retired, delayTicks);
}
/**
* Schedules a task with the given delay. If the task failed to schedule because the scheduler is retired (entity
* removed), then returns {@code null}. Otherwise, either the task callback will be invoked after the specified delay,
* or the retired callback will be invoked if the scheduler is retired.
* Note that the retired callback is invoked in critical code, so it should not attempt to remove the entity, remove
* other entities, load chunks, load worlds, modify ticket levels, etc.
*
* <p>
* It is guaranteed that the task and retired callback are invoked on the region which owns the entity.
* </p>
* @param task The task to execute
* @param retired Retire callback to run if the entity is retired before the run callback can be invoked, may be null.
* @param delayTicks The delay, in ticks.
* @return The {@link Completable} that represents the scheduled task, or {@code null} if the entity has been removed.
*/
default @Nullable <R> Completable<R> runDelayed(@NotNull Supplier<R> task,
@Nullable Runnable retired,
@Range(from = 1, to = Long.MAX_VALUE) long delayTicks) {
return runDelayed(t -> {
return task.get();
}, retired, delayTicks);
}
/**
* Schedules a task with the given delay. If the task failed to schedule because the scheduler is retired (entity
* removed), then returns {@code null}. Otherwise, either the task callback will be invoked after the specified delay,
* or the retired callback will be invoked if the scheduler is retired.
* Note that the retired callback is invoked in critical code, so it should not attempt to remove the entity, remove
* other entities, load chunks, load worlds, modify ticket levels, etc.
*
* <p>
* It is guaranteed that the task and retired callback are invoked on the region which owns the entity.
* </p>
* @param task The task to execute
* @param retired Retire callback to run if the entity is retired before the run callback can be invoked, may be null.
* @param delayTicks The delay, in ticks.
* @return The {@link Completable} that represents the scheduled task, or {@code null} if the entity has been removed.
*/
@Nullable <R> Completable<R> runDelayed(@NotNull Function<Completable<R>, R> task,
@Nullable Runnable retired,
@Range(from = 1, to = Long.MAX_VALUE) long delayTicks);
/**
* Schedules a repeating task with the given delay and period. If the task failed to schedule because the scheduler
* is retired (entity removed), then returns {@code null}. Otherwise, either the task callback will be invoked after
* the specified delay, or the retired callback will be invoked if the scheduler is retired.
* Note that the retired callback is invoked in critical code, so it should not attempt to remove the entity, remove
* other entities, load chunks, load worlds, modify ticket levels, etc.
*
* <p>
* It is guaranteed that the task and retired callback are invoked on the region which owns the entity.
* </p>
* @param task The task to execute
* @param retired Retire callback to run if the entity is retired before the run callback can be invoked, may be null.
* @param initialDelayTicks The initial delay, in ticks.
* @param periodTicks The period, in ticks.
* @return The {@link Task} that represents the scheduled task, or {@code null} if the entity has been removed.
*/
default @Nullable Task runAtFixedRate(@NotNull Runnable task,
@Nullable Runnable retired,
@Range(from = 1, to = Long.MAX_VALUE) long initialDelayTicks,
@Range(from = 1, to = Long.MAX_VALUE) long periodTicks) {
return runAtFixedRate(t -> task.run(), retired, initialDelayTicks, periodTicks);
}
/**
* Schedules a repeating task with the given delay and period. If the task failed to schedule because the scheduler
* is retired (entity removed), then returns {@code null}. Otherwise, either the task callback will be invoked after
* the specified delay, or the retired callback will be invoked if the scheduler is retired.
* Note that the retired callback is invoked in critical code, so it should not attempt to remove the entity, remove
* other entities, load chunks, load worlds, modify ticket levels, etc.
*
* <p>
* It is guaranteed that the task and retired callback are invoked on the region which owns the entity.
* </p>
* @param task The task to execute
* @param retired Retire callback to run if the entity is retired before the run callback can be invoked, may be null.
* @param initialDelayTicks The initial delay, in ticks.
* @param periodTicks The period, in ticks.
* @return The {@link Task} that represents the scheduled task, or {@code null} if the entity has been removed.
*/
@Nullable Task runAtFixedRate(@NotNull Consumer<Task> task,
@Nullable Runnable retired,
@Range(from = 1, to = Long.MAX_VALUE) long initialDelayTicks,
@Range(from = 1, to = Long.MAX_VALUE) long periodTicks);
}

View File

@ -1,139 +0,0 @@
package com.volmit.iris.util.scheduling.split;
import com.volmit.iris.util.scheduling.Task;
import com.volmit.iris.util.scheduling.Task.Completable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Range;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* The global region task scheduler may be used to schedule tasks that will execute on the global region.
* <p>
* The global region is responsible for maintaining world day time, world game time, weather cycle,
* sleep night skipping, executing commands for console, and other misc. tasks that do not belong to any specific region.
* </p>
*/
public interface IGlobalScheduler {
/**
* Schedules a task to be executed on the global region on the next tick.
* @param task The task to execute
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task run(@NotNull Consumer<Task> task) {
return run(t -> {
task.accept(t);
return null;
});
}
/**
* Schedules a task to be executed on the global region on the next tick.
* @param task The task to execute
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task run(@NotNull Runnable task) {
return run(t -> {
task.run();
return null;
});
}
/**
* Schedules a task to be executed on the global region on the next tick.
* @param task The task to execute
* @return The {@link Completable} that represents the scheduled task.
*/
default @NotNull <R> Completable<R> run(@NotNull Supplier<R> task) {
return run(t -> {
return task.get();
});
}
/**
* Schedules a task to be executed on the global region on the next tick.
* @param task The task to execute
* @return The {@link Completable} that represents the scheduled task.
*/
default @NotNull <R> Completable<R> run(@NotNull Function<Completable<R>, R> task) {
return runDelayed(task, 1);
}
/**
* Schedules a task to be executed on the global region after the specified delay in ticks.
* @param task The task to execute
* @param delayTicks The delay, in ticks.
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task runDelayed(@NotNull Consumer<Task> task,
@Range(from = 1, to = Long.MAX_VALUE) long delayTicks) {
return runDelayed(t -> {
task.accept(t);
return null;
}, delayTicks);
}
/**
* Schedules a task to be executed on the global region after the specified delay in ticks.
* @param task The task to execute
* @param delayTicks The delay, in ticks.
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task runDelayed(@NotNull Runnable task,
@Range(from = 1, to = Long.MAX_VALUE) long delayTicks) {
return runDelayed(t -> {
task.run();
return null;
}, delayTicks);
}
/**
* Schedules a task to be executed on the global region after the specified delay in ticks.
* @param task The task to execute
* @param delayTicks The delay, in ticks.
* @return The {@link Completable} that represents the scheduled task.
*/
default @NotNull <R> Completable<R> runDelayed(@NotNull Supplier<R> task,
@Range(from = 1, to = Long.MAX_VALUE) long delayTicks) {
return runDelayed(t -> {
return task.get();
}, delayTicks);
}
/**
* Schedules a task to be executed on the global region after the specified delay in ticks.
* @param task The task to execute
* @param delayTicks The delay, in ticks.
* @return The {@link Completable} that represents the scheduled task.
*/
@NotNull <R> Completable<R> runDelayed(@NotNull Function<Completable<R>, R> task,
@Range(from = 1, to = Long.MAX_VALUE) long delayTicks);
/**
* Schedules a repeating task to be executed on the global region after the initial delay with the
* specified period.
* @param task The task to execute
* @param initialDelayTicks The initial delay, in ticks.
* @param periodTicks The period, in ticks.
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task runAtFixedRate(@NotNull Runnable task,
@Range(from = 1, to = Long.MAX_VALUE) long initialDelayTicks,
@Range(from = 1, to = Long.MAX_VALUE) long periodTicks) {
return runAtFixedRate(t -> task.run(), initialDelayTicks, periodTicks);
}
/**
* Schedules a repeating task to be executed on the global region after the initial delay with the
* specified period.
* @param task The task to execute
* @param initialDelayTicks The initial delay, in ticks.
* @param periodTicks The period, in ticks.
* @return The {@link Task} that represents the scheduled task.
*/
@NotNull Task runAtFixedRate(@NotNull Consumer<Task> task,
@Range(from = 1, to = Long.MAX_VALUE) long initialDelayTicks,
@Range(from = 1, to = Long.MAX_VALUE) long periodTicks);
}

View File

@ -1,328 +0,0 @@
package com.volmit.iris.util.scheduling.split;
import com.volmit.iris.util.scheduling.Task;
import com.volmit.iris.util.scheduling.Task.Completable;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Range;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* The region task scheduler can be used to schedule tasks by location to be executed on the region which owns the location.
* <p>
* <b>Note</b>: It is entirely inappropriate to use the region scheduler to schedule tasks for entities.
* If you wish to schedule tasks to perform actions on entities, you should be using {@link Entity#getScheduler()}
* as the entity scheduler will "follow" an entity if it is teleported, whereas the region task scheduler
* will not.
* </p>
*/
public interface IRegionScheduler {
/**
* Schedules a task to be executed on the region which owns the location on the next tick.
*
* @param world The world of the region that owns the task
* @param chunkX The chunk X coordinate of the region that owns the task
* @param chunkZ The chunk Z coordinate of the region that owns the task
* @param task The task to execute
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task run(@NotNull World world,
int chunkX,
int chunkZ,
@NotNull Consumer<Task> task) {
return run(world, chunkX, chunkZ, t -> {
task.accept(t);
return null;
});
}
/**
* Schedules a task to be executed on the region which owns the location on the next tick.
*
* @param world The world of the region that owns the task
* @param chunkX The chunk X coordinate of the region that owns the task
* @param chunkZ The chunk Z coordinate of the region that owns the task
* @param task The task to execute
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task run(@NotNull World world,
int chunkX,
int chunkZ,
@NotNull Runnable task) {
return run(world, chunkX, chunkZ, t -> {
task.run();
return null;
});
}
/**
* Schedules a task to be executed on the region which owns the location on the next tick.
*
* @param world The world of the region that owns the task
* @param chunkX The chunk X coordinate of the region that owns the task
* @param chunkZ The chunk Z coordinate of the region that owns the task
* @param task The task to execute
* @return The {@link Completable} that represents the scheduled task.
*/
default @NotNull <R> Completable<R> run(@NotNull World world,
int chunkX,
int chunkZ,
@NotNull Supplier<R> task) {
return run(world, chunkX, chunkZ, t -> {
return task.get();
});
}
/**
* Schedules a task to be executed on the region which owns the location on the next tick.
*
* @param world The world of the region that owns the task
* @param chunkX The chunk X coordinate of the region that owns the task
* @param chunkZ The chunk Z coordinate of the region that owns the task
* @param task The task to execute
* @return The {@link Completable} that represents the scheduled task.
*/
default @NotNull <R> Completable<R> run(@NotNull World world,
int chunkX,
int chunkZ,
@NotNull Function<Completable<R>, R> task) {
return runDelayed(world, chunkX, chunkZ, task, 1);
}
/**
* Schedules a task to be executed on the region which owns the location on the next tick.
*
* @param location The location at which the region executing should own
* @param task The task to execute
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task run(@NotNull Location location,
@NotNull Consumer<Task> task) {
return run(location.getWorld(), location.getBlockX() >> 4, location.getBlockZ() >> 4, task);
}
/**
* Schedules a task to be executed on the region which owns the location on the next tick.
*
* @param location The location at which the region executing should own
* @param task The task to execute
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task run(@NotNull Location location,
@NotNull Runnable task) {
return run(location, t -> {
task.run();
});
}
/**
* Schedules a task to be executed on the region which owns the location on the next tick.
*
* @param location The location at which the region executing should own
* @param task The task to execute
* @return The {@link Completable} that represents the scheduled task.
*/
default @NotNull <R> Completable<R> run(@NotNull Location location,
@NotNull Supplier<R> task) {
return run(location, t -> {
return task.get();
});
}
/**
* Schedules a task to be executed on the region which owns the location on the next tick.
*
* @param location The location at which the region executing should own
* @param task The task to execute
* @return The {@link Completable} that represents the scheduled task.
*/
default @NotNull <R> Completable<R> run(@NotNull Location location,
@NotNull Function<Completable<R>, R> task) {
return run(location.getWorld(), location.getBlockX() >> 4, location.getBlockZ() >> 4, task);
}
/**
* Schedules a task to be executed on the region which owns the location after the specified delay in ticks.
*
* @param world The world of the region that owns the task
* @param chunkX The chunk X coordinate of the region that owns the task
* @param chunkZ The chunk Z coordinate of the region that owns the task
* @param task The task to execute
* @param delayTicks The delay, in ticks.
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task runDelayed(@NotNull World world,
int chunkX,
int chunkZ,
@NotNull Consumer<Task> task,
@Range(from = 1, to = Long.MAX_VALUE) long delayTicks) {
return runDelayed(world, chunkX, chunkZ, t -> {
task.accept(t);
return null;
}, delayTicks);
}
/**
* Schedules a task to be executed on the region which owns the location after the specified delay in ticks.
*
* @param world The world of the region that owns the task
* @param chunkX The chunk X coordinate of the region that owns the task
* @param chunkZ The chunk Z coordinate of the region that owns the task
* @param task The task to execute
* @param delayTicks The delay, in ticks.
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task runDelayed(@NotNull World world,
int chunkX,
int chunkZ,
@NotNull Runnable task,
@Range(from = 1, to = Long.MAX_VALUE) long delayTicks) {
return runDelayed(world, chunkX, chunkZ, t -> {
task.run();
return null;
}, delayTicks);
}
/**
* Schedules a task to be executed on the region which owns the location after the specified delay in ticks.
*
* @param world The world of the region that owns the task
* @param chunkX The chunk X coordinate of the region that owns the task
* @param chunkZ The chunk Z coordinate of the region that owns the task
* @param task The task to execute
* @param delayTicks The delay, in ticks.
* @return The {@link Completable} that represents the scheduled task.
*/
default @NotNull <R> Completable<R> runDelayed(@NotNull World world,
int chunkX,
int chunkZ,
@NotNull Supplier<R> task,
@Range(from = 1, to = Long.MAX_VALUE) long delayTicks) {
return runDelayed(world, chunkX, chunkZ, t -> {
return task.get();
}, delayTicks);
}
/**
* Schedules a task to be executed on the region which owns the location after the specified delay in ticks.
*
* @param world The world of the region that owns the task
* @param chunkX The chunk X coordinate of the region that owns the task
* @param chunkZ The chunk Z coordinate of the region that owns the task
* @param task The task to execute
* @param delayTicks The delay, in ticks.
* @return The {@link Completable} that represents the scheduled task.
*/
@NotNull <R> Completable<R> runDelayed(@NotNull World world,
int chunkX,
int chunkZ,
@NotNull Function<Completable<R>, R> task,
@Range(from = 1, to = Long.MAX_VALUE) long delayTicks);
/**
* Schedules a task to be executed on the region which owns the location after the specified delay in ticks.
*
* @param location The location at which the region executing should own
* @param task The task to execute
* @param delayTicks The delay, in ticks.
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task runDelayed(@NotNull Location location,
@NotNull Consumer<Task> task,
@Range(from = 1, to = Long.MAX_VALUE) long delayTicks) {
return runDelayed(location.getWorld(), location.getBlockX() >> 4, location.getBlockZ() >> 4, task, delayTicks);
}
/**
* Schedules a task to be executed on the region which owns the location after the specified delay in ticks.
*
* @param location The location at which the region executing should own
* @param task The task to execute
* @param delayTicks The delay, in ticks.
* @return The {@link Completable} that represents the scheduled task.
*/
default @NotNull <R> Completable<R> runDelayed(@NotNull Location location,
@NotNull Function<Completable<R>, R> task,
@Range(from = 1, to = Long.MAX_VALUE) long delayTicks) {
return runDelayed(location.getWorld(), location.getBlockX() >> 4, location.getBlockZ() >> 4, task, delayTicks);
}
/**
* Schedules a repeating task to be executed on the region which owns the location after the initial delay with the
* specified period.
*
* @param world The world of the region that owns the task
* @param chunkX The chunk X coordinate of the region that owns the task
* @param chunkZ The chunk Z coordinate of the region that owns the task
* @param task The task to execute
* @param initialDelayTicks The initial delay, in ticks.
* @param periodTicks The period, in ticks.
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task runAtFixedRate(@NotNull World world,
int chunkX,
int chunkZ,
@NotNull Runnable task,
@Range(from = 1, to = Long.MAX_VALUE) long initialDelayTicks,
@Range(from = 1, to = Long.MAX_VALUE) long periodTicks) {
return runAtFixedRate(world, chunkX, chunkZ, t -> task.run(), initialDelayTicks, periodTicks);
}
/**
* Schedules a repeating task to be executed on the region which owns the location after the initial delay with the
* specified period.
*
* @param world The world of the region that owns the task
* @param chunkX The chunk X coordinate of the region that owns the task
* @param chunkZ The chunk Z coordinate of the region that owns the task
* @param task The task to execute
* @param initialDelayTicks The initial delay, in ticks.
* @param periodTicks The period, in ticks.
* @return The {@link Task} that represents the scheduled task.
*/
@NotNull Task runAtFixedRate(@NotNull World world,
int chunkX,
int chunkZ,
@NotNull Consumer<Task> task,
@Range(from = 1, to = Long.MAX_VALUE) long initialDelayTicks,
@Range(from = 1, to = Long.MAX_VALUE) long periodTicks);
/**
* Schedules a repeating task to be executed on the region which owns the location after the initial delay with the
* specified period.
*
* @param location The location at which the region executing should own
* @param task The task to execute
* @param initialDelayTicks The initial delay, in ticks.
* @param periodTicks The period, in ticks.
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task runAtFixedRate(@NotNull Location location,
@NotNull Runnable task,
@Range(from = 1, to = Long.MAX_VALUE) long initialDelayTicks,
@Range(from = 1, to = Long.MAX_VALUE) long periodTicks) {
return runAtFixedRate(location, t -> task.run(), initialDelayTicks, periodTicks);
}
/**
* Schedules a repeating task to be executed on the region which owns the location after the initial delay with the
* specified period.
*
* @param location The location at which the region executing should own
* @param task The task to execute
* @param initialDelayTicks The initial delay, in ticks.
* @param periodTicks The period, in ticks.
* @return The {@link Task} that represents the scheduled task.
*/
default @NotNull Task runAtFixedRate(@NotNull Location location,
@NotNull Consumer<Task> task,
@Range(from = 1, to = Long.MAX_VALUE) long initialDelayTicks,
@Range(from = 1, to = Long.MAX_VALUE) long periodTicks) {
return runAtFixedRate(location.getWorld(), location.getBlockX() >> 4, location.getBlockZ() >> 4, task, initialDelayTicks, periodTicks);
}
}

View File

@ -38,5 +38,4 @@ include(
":nms:v1_20_R3",
":nms:v1_20_R2",
":nms:v1_20_R1",
)
include("scheduler")
)