Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand all runAtLocation methods to support chunk coordinate arguments #20

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.tcoded.folialib.enums.EntityTaskResult;
import com.tcoded.folialib.wrapper.task.WrappedTask;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -222,6 +223,18 @@ public interface ServerImplementation {
*/
CompletableFuture<Void> runAtLocation(Location location, @NotNull Consumer<WrappedTask> consumer);

/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
* Spigot: Synced with the server main thread
* @param world The world to run the task at
* @param chunkX The x coordinate of the chunk to run the task at
* @param chunkZ The z coordinate of the chunk to run the task at
* @param consumer Task to run
* @return Future when the task is completed
*/
CompletableFuture<Void> runAtLocation(World world, int chunkX, int chunkZ, @NotNull Consumer<WrappedTask> consumer);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we possibly do runAtChunk please? It makes it a little more obvious what int & int parameters will be. (Same for all other runAtChunk changes)


/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
Expand All @@ -233,6 +246,19 @@ public interface ServerImplementation {
*/
WrappedTask runAtLocationLater(Location location, @NotNull Runnable runnable, long delay);

/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
* Spigot: Synced with the server main thread
* @param world The world to run the task at
* @param chunkX The x coordinate of the chunk to run the task at
* @param chunkZ The z coordinate of the chunk to run the task at
* @param runnable Task to run
* @param delay Delay before execution in ticks
* @return WrappedTask instance
*/
WrappedTask runAtLocationLater(World world, int chunkX, int chunkZ, @NotNull Runnable runnable, long delay);

/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
Expand All @@ -243,6 +269,18 @@ public interface ServerImplementation {
*/
void runAtLocationLater(Location location, @NotNull Consumer<WrappedTask> consumer, long delay);

/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
* Spigot: Synced with the server main thread
* @param world The world to run the task at
* @param chunkX The x coordinate of the chunk to run the task at
* @param chunkZ The z coordinate of the chunk to run the task at
* @param consumer Task to run
* @param delay Delay before execution in ticks
*/
void runAtLocationLater(World world, int chunkX, int chunkZ, @NotNull Consumer<WrappedTask> consumer, long delay);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return a CompleteableFuture<Void>, matching the other methods from #16

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep


/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
Expand All @@ -255,6 +293,20 @@ public interface ServerImplementation {
*/
WrappedTask runAtLocationLater(Location location, @NotNull Runnable runnable, long delay, TimeUnit unit);

/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
* Spigot: Synced with the server main thread
* @param world The world to run the task at
* @param chunkX The x coordinate of the chunk to run the task at
* @param chunkZ The z coordinate of the chunk to run the task at
* @param runnable Task to run
* @param delay Delay before execution
* @param unit Time unit
* @return WrappedTask instance
*/
WrappedTask runAtLocationLater(World world, int chunkX, int chunkZ, @NotNull Runnable runnable, long delay, TimeUnit unit);

/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
Expand All @@ -266,6 +318,19 @@ public interface ServerImplementation {
*/
void runAtLocationLater(Location location, @NotNull Consumer<WrappedTask> consumer, long delay, TimeUnit unit);

/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
* Spigot: Synced with the server main thread
* @param world The world to run the task at
* @param chunkX The x coordinate of the chunk to run the task at
* @param chunkZ The z coordinate of the chunk to run the task at
* @param consumer Task to run
* @param delay Delay before execution
* @param unit Time unit
*/
void runAtLocationLater(World world, int chunkX, int chunkZ, @NotNull Consumer<WrappedTask> consumer, long delay, TimeUnit unit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return a CompleteableFuture<Void>, matching the other methods from #16


/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
Expand All @@ -278,6 +343,20 @@ public interface ServerImplementation {
*/
WrappedTask runAtLocationTimer(Location location, @NotNull Runnable runnable, long delay, long period);

/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
* Spigot: Synced with the server main thread
* @param world The world to run the task at
* @param chunkX The x coordinate of the chunk to run the task at
* @param chunkZ The z coordinate of the chunk to run the task at
* @param runnable Task to run
* @param delay Delay before first execution in ticks
* @param period Delay between executions in ticks
* @return WrappedTask instance
*/
WrappedTask runAtLocationTimer(World world, int chunkX, int chunkZ, @NotNull Runnable runnable, long delay, long period);

/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
Expand All @@ -289,6 +368,19 @@ public interface ServerImplementation {
*/
void runAtLocationTimer(Location location, @NotNull Consumer<WrappedTask> consumer, long delay, long period);

/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
* Spigot: Synced with the server main thread
* @param world The world to run the task at
* @param chunkX The x coordinate of the chunk to run the task at
* @param chunkZ The z coordinate of the chunk to run the task at
* @param consumer Task to run
* @param delay Delay before first execution in ticks
* @param period Delay between executions in ticks
*/
void runAtLocationTimer(World world, int chunkX, int chunkZ, @NotNull Consumer<WrappedTask> consumer, long delay, long period);

/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
Expand All @@ -302,6 +394,21 @@ public interface ServerImplementation {
*/
WrappedTask runAtLocationTimer(Location location, @NotNull Runnable runnable, long delay, long period, TimeUnit unit);

/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
* Spigot: Synced with the server main thread
* @param world The world to run the task at
* @param chunkX The x coordinate of the chunk to run the task at
* @param chunkZ The z coordinate of the chunk to run the task at
* @param runnable Task to run
* @param delay Delay before first execution
* @param period Delay between executions
* @param unit Time unit
* @return WrappedTask instance
*/
WrappedTask runAtLocationTimer(World world, int chunkX, int chunkZ, @NotNull Runnable runnable, long delay, long period, TimeUnit unit);

/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
Expand All @@ -314,6 +421,19 @@ public interface ServerImplementation {
*/
void runAtLocationTimer(Location location, @NotNull Consumer<WrappedTask> consumer, long delay, long period, TimeUnit unit);

/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
* Spigot: Synced with the server main thread
* @param world The world to run the task at
* @param chunkX The x coordinate of the chunk to run the task at
* @param chunkZ The z coordinate of the chunk to run the task at
* @param consumer Task to run
* @param delay Delay before first execution
* @param period Delay between executions
* @param unit Time unit
*/
void runAtLocationTimer(World world, int chunkX, int chunkZ, @NotNull Consumer<WrappedTask> consumer, long delay, long period, TimeUnit unit);

// ----- Entity based -----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -187,6 +188,18 @@ public CompletableFuture<Void> runAtLocation(Location location, @NotNull Consume
future.complete(null);
});

return future;
}

@Override
public CompletableFuture<Void> runAtLocation(World world, int chunkX, int chunkZ, @NotNull Consumer<WrappedTask> consumer) {
CompletableFuture<Void> future = new CompletableFuture<>();

this.plugin.getServer().getRegionScheduler().run(plugin, world, chunkX, chunkZ, task -> {
consumer.accept(this.wrapTask(task));
future.complete(null);
});

return future;
}

Expand All @@ -201,6 +214,17 @@ public WrappedTask runAtLocationLater(Location location, @NotNull Runnable runna
);
}

@Override
public WrappedTask runAtLocationLater(World world, int chunkX, int chunkZ, @NotNull Runnable runnable, long delay) {
if (delay <= 0) {
InvalidTickDelayNotifier.notifyOnce(plugin.getLogger(), delay);
delay = 1;
}
return this.wrapTask(
this.plugin.getServer().getRegionScheduler().runDelayed(plugin, world, chunkX, chunkZ, task -> runnable.run(), delay)
);
}

@Override
public void runAtLocationLater(Location location, @NotNull Consumer<WrappedTask> consumer, long delay) {
if (delay <= 0) {
Expand All @@ -210,16 +234,35 @@ public void runAtLocationLater(Location location, @NotNull Consumer<WrappedTask>
this.plugin.getServer().getRegionScheduler().runDelayed(plugin, location, task -> consumer.accept(this.wrapTask(task)), delay);
}

@Override
public void runAtLocationLater(World world, int chunkX, int chunkZ, @NotNull Consumer<WrappedTask> consumer, long delay) {
if (delay <= 0) {
InvalidTickDelayNotifier.notifyOnce(plugin.getLogger(), delay);
delay = 1;
}
this.plugin.getServer().getRegionScheduler().runDelayed(plugin, world, chunkX, chunkZ, task -> consumer.accept(this.wrapTask(task)), delay);
}

@Override
public WrappedTask runAtLocationLater(Location location, @NotNull Runnable runnable, long delay, TimeUnit unit) {
return this.runAtLocationLater(location, runnable, TimeConverter.toTicks(delay, unit));
}

@Override
public WrappedTask runAtLocationLater(World world, int chunkX, int chunkZ, @NotNull Runnable runnable, long delay, TimeUnit unit) {
return this.runAtLocationLater(world, chunkX, chunkZ, runnable, TimeConverter.toTicks(delay, unit));
}

@Override
public void runAtLocationLater(Location location, @NotNull Consumer<WrappedTask> consumer, long delay, TimeUnit unit) {
this.runAtLocationLater(location, consumer, TimeConverter.toTicks(delay, unit));
}

@Override
public void runAtLocationLater(World world, int chunkX, int chunkZ, @NotNull Consumer<WrappedTask> consumer, long delay, TimeUnit unit) {
this.runAtLocationLater(world, chunkX, chunkZ, consumer, TimeConverter.toTicks(delay, unit));
}

@Override
public WrappedTask runAtLocationTimer(Location location, @NotNull Runnable runnable, long delay, long period) {
if (delay <= 0) {
Expand All @@ -235,6 +278,21 @@ public WrappedTask runAtLocationTimer(Location location, @NotNull Runnable runna
);
}

@Override
public WrappedTask runAtLocationTimer(World world, int chunkX, int chunkZ, @NotNull Runnable runnable, long delay, long period) {
if (delay <= 0) {
InvalidTickDelayNotifier.notifyOnce(plugin.getLogger(), delay);
delay = 1;
}
if (period <= 0) {
InvalidTickDelayNotifier.notifyOnce(plugin.getLogger(), period);
period = 1;
}
return this.wrapTask(
this.plugin.getServer().getRegionScheduler().runAtFixedRate(plugin, world, chunkX, chunkZ, task -> runnable.run(), delay, period)
);
}

@Override
public void runAtLocationTimer(Location location, @NotNull Consumer<WrappedTask> consumer, long delay, long period) {
if (delay <= 0) {
Expand All @@ -248,16 +306,39 @@ public void runAtLocationTimer(Location location, @NotNull Consumer<WrappedTask>
this.plugin.getServer().getRegionScheduler().runAtFixedRate(plugin, location, task -> consumer.accept(this.wrapTask(task)), delay, period);
}

@Override
public void runAtLocationTimer(World world, int chunkX, int chunkZ, @NotNull Consumer<WrappedTask> consumer, long delay, long period) {
if (delay <= 0) {
InvalidTickDelayNotifier.notifyOnce(plugin.getLogger(), delay);
delay = 1;
}
if (period <= 0) {
InvalidTickDelayNotifier.notifyOnce(plugin.getLogger(), period);
period = 1;
}
this.plugin.getServer().getRegionScheduler().runAtFixedRate(plugin, world, chunkX, chunkZ, task -> consumer.accept(this.wrapTask(task)), delay, period);
}

@Override
public WrappedTask runAtLocationTimer(Location location, @NotNull Runnable runnable, long delay, long period, TimeUnit unit) {
return this.runAtLocationTimer(location, runnable, TimeConverter.toTicks(delay, unit), TimeConverter.toTicks(period, unit));
}

@Override
public WrappedTask runAtLocationTimer(World world, int chunkX, int chunkZ, @NotNull Runnable runnable, long delay, long period, TimeUnit unit) {
return this.runAtLocationTimer(world, chunkX, chunkZ, runnable, TimeConverter.toTicks(delay, unit), TimeConverter.toTicks(period, unit));
}

@Override
public void runAtLocationTimer(Location location, @NotNull Consumer<WrappedTask> consumer, long delay, long period, TimeUnit unit) {
this.runAtLocationTimer(location, consumer, TimeConverter.toTicks(delay, unit), TimeConverter.toTicks(period, unit));
}

@Override
public void runAtLocationTimer(World world, int chunkX, int chunkZ, @NotNull Consumer<WrappedTask> consumer, long delay, long period, TimeUnit unit) {
this.runAtLocationTimer(world, chunkX, chunkZ, consumer, TimeConverter.toTicks(delay, unit), TimeConverter.toTicks(period, unit));
}

@Override
public CompletableFuture<EntityTaskResult> runAtEntity(Entity entity, @NotNull Consumer<WrappedTask> consumer) {
CompletableFuture<EntityTaskResult> future = new CompletableFuture<>();
Expand Down
Loading