Skip to content
Merged
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 @@ -2,7 +2,10 @@

import com.tcoded.folialib.enums.EntityTaskResult;
import com.tcoded.folialib.wrapper.task.WrappedTask;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
Expand All @@ -21,6 +24,103 @@
@Deprecated
public interface ServerImplementation {

// ----- Check thread -----

/**
* 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: Returns {@link Bukkit#isPrimaryThread()}
* Spigot: Returns {@link Bukkit#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: Returns {@link Bukkit#isPrimaryThread()}
* Spigot: Returns {@link Bukkit#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: Returns {@link Bukkit#isPrimaryThread()}
* Spigot: Returns {@link Bukkit#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: Returns {@link Bukkit#isPrimaryThread()}
* Spigot: Returns {@link Bukkit#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: Returns {@link Bukkit#isPrimaryThread()}
* Spigot: Returns {@link Bukkit#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: Returns {@link Bukkit#isPrimaryThread()}
* Spigot: Returns {@link Bukkit#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: Returns {@link Bukkit#isPrimaryThread()}
* Spigot: Returns {@link Bukkit#isPrimaryThread()}
*
* @return true if the current thread is ticking the global region
*/
boolean isGlobalTickThread();

// ----- Run now -----

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -40,7 +43,42 @@ public FoliaImplementation(FoliaLib foliaLib) {
this.asyncScheduler = plugin.getServer().getAsyncScheduler();
}

@Override
@Override
public boolean isOwnedByCurrentRegion(@NotNull Location location) {
return this.plugin.getServer().isOwnedByCurrentRegion(location);
}

@Override
public boolean isOwnedByCurrentRegion(@NotNull Location location, int squareRadiusChunks) {
return this.plugin.getServer().isOwnedByCurrentRegion(location, squareRadiusChunks);
}

@Override
public boolean isOwnedByCurrentRegion(@NotNull Block block) {
return this.plugin.getServer().isOwnedByCurrentRegion(block);
}

@Override
public boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ) {
return this.plugin.getServer().isOwnedByCurrentRegion(world, chunkX, chunkZ);
}

@Override
public boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ, int squareRadiusChunks) {
return this.plugin.getServer().isOwnedByCurrentRegion(world, chunkX, chunkZ, squareRadiusChunks);
}

@Override
public boolean isOwnedByCurrentRegion(@NotNull Entity entity) {
return this.plugin.getServer().isOwnedByCurrentRegion(entity);
}

@Override
public boolean isGlobalTickThread() {
return this.plugin.getServer().isGlobalTickThread();
}

@Override
public @NotNull CompletableFuture<Void> runNextTick(@NotNull Consumer<WrappedTask> consumer) {
CompletableFuture<Void> future = new CompletableFuture<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.tcoded.folialib.wrapper.task.WrappedTask;
import com.tcoded.folialib.wrapper.task.WrappedLegacyBukkitTask;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -36,6 +38,41 @@ public LegacySpigotImplementation(FoliaLib foliaLib) {
this.scheduler = plugin.getServer().getScheduler();
}

@Override
public boolean isOwnedByCurrentRegion(@NotNull Location location) {
return this.plugin.getServer().isPrimaryThread();
}

@Override
public boolean isOwnedByCurrentRegion(@NotNull Location location, int squareRadiusChunks) {
return this.plugin.getServer().isPrimaryThread();
}

@Override
public boolean isOwnedByCurrentRegion(@NotNull Block block) {
return this.plugin.getServer().isPrimaryThread();
}

@Override
public boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ) {
return this.plugin.getServer().isPrimaryThread();
}

@Override
public boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ, int squareRadiusChunks) {
return this.plugin.getServer().isPrimaryThread();
}

@Override
public boolean isOwnedByCurrentRegion(@NotNull Entity entity) {
return this.plugin.getServer().isPrimaryThread();
}

@Override
public boolean isGlobalTickThread() {
return this.plugin.getServer().isPrimaryThread();
}

@Override
public @NotNull CompletableFuture<Void> runNextTick(@NotNull Consumer<WrappedTask> consumer) {
CompletableFuture<Void> future = new CompletableFuture<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.tcoded.folialib.wrapper.task.WrappedTask;
import com.tcoded.folialib.wrapper.task.WrappedBukkitTask;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -34,6 +36,41 @@ public SpigotImplementation(FoliaLib foliaLib) {
this.scheduler = plugin.getServer().getScheduler();
}

@Override
public boolean isOwnedByCurrentRegion(@NotNull Location location) {
return this.plugin.getServer().isPrimaryThread();
}

@Override
public boolean isOwnedByCurrentRegion(@NotNull Location location, int squareRadiusChunks) {
return this.plugin.getServer().isPrimaryThread();
}

@Override
public boolean isOwnedByCurrentRegion(@NotNull Block block) {
return this.plugin.getServer().isPrimaryThread();
}

@Override
public boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ) {
return this.plugin.getServer().isPrimaryThread();
}

@Override
public boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ, int squareRadiusChunks) {
return this.plugin.getServer().isPrimaryThread();
}

@Override
public boolean isOwnedByCurrentRegion(@NotNull Entity entity) {
return this.plugin.getServer().isPrimaryThread();
}

@Override
public boolean isGlobalTickThread() {
return this.plugin.getServer().isPrimaryThread();
}

@Override
public @NotNull CompletableFuture<Void> runNextTick(@NotNull Consumer<WrappedTask> consumer) {
CompletableFuture<Void> future = new CompletableFuture<>();
Expand Down