forked from mirror/Folia
206 lines
11 KiB
Diff
206 lines
11 KiB
Diff
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||
|
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
||
|
Date: Tue, 7 Mar 2023 14:34:09 -0800
|
||
|
Subject: [PATCH] Add API for checking ownership of region by position/entity
|
||
|
|
||
|
This may be useful for plugins which want to perform operations
|
||
|
over large areas outside of the buffer zone provided by the
|
||
|
regionaliser, as it is not guaranteed that anything outside
|
||
|
of the buffer zone is owned. Then, the plugins may use
|
||
|
the schedulers depending on the result of the ownership
|
||
|
check.
|
||
|
|
||
|
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
|
||
|
index 3b8a6d7336b0cb20594de9c6b56f215f1370ce89..aee6508cec0631fc7b5fe6bf1b978a5c01437422 100644
|
||
|
--- a/src/main/java/org/bukkit/Bukkit.java
|
||
|
+++ b/src/main/java/org/bukkit/Bukkit.java
|
||
|
@@ -2474,6 +2474,100 @@ public final class Bukkit {
|
||
|
public static @NotNull io.papermc.paper.threadedregions.scheduler.RegionisedScheduler getRegionScheduler() {
|
||
|
return server.getRegionScheduler();
|
||
|
}
|
||
|
+
|
||
|
+ /**
|
||
|
+ * 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.
|
||
|
+ * @param world Specified world.
|
||
|
+ * @param position Specified block position.
|
||
|
+ */
|
||
|
+ public static boolean isOwnedByCurrentRegion(@NotNull World world, @NotNull org.bukkit.util.Vector position) {
|
||
|
+ return server.isOwnedByCurrentRegion(world, position);
|
||
|
+ }
|
||
|
+
|
||
|
+ /**
|
||
|
+ * Returns whether the current thread is ticking a region and that the region being ticked
|
||
|
+ * owns the chunks centered at the specified block 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.
|
||
|
+ * @param world Specified world.
|
||
|
+ * @param position Specified block position.
|
||
|
+ * @param squareRadiusChunks Specified square radius. Must be >= 0. Note that this parameter is <i>not</i> a <i>squared</i>
|
||
|
+ * radius, but rather a <i>Chebyshev Distance</i>.
|
||
|
+ */
|
||
|
+ public static boolean isOwnedByCurrentRegion(@NotNull World world, @NotNull org.bukkit.util.Vector position, int squareRadiusChunks) {
|
||
|
+ return server.isOwnedByCurrentRegion(world, position, squareRadiusChunks);
|
||
|
+ }
|
||
|
+
|
||
|
+ /**
|
||
|
+ * 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.
|
||
|
+ * @param location Specified location, must have a non-null world.
|
||
|
+ */
|
||
|
+ public static boolean isOwnedByCurrentRegion(@NotNull Location location) {
|
||
|
+ return server.isOwnedByCurrentRegion(location);
|
||
|
+ }
|
||
|
+
|
||
|
+ /**
|
||
|
+ * 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.
|
||
|
+ * @param location Specified location, must have a non-null world.
|
||
|
+ * @param squareRadiusChunks Specified square radius. Must be >= 0. Note that this parameter is <i>not</i> a <i>squared</i>
|
||
|
+ * radius, but rather a <i>Chebyshev Distance</i>.
|
||
|
+ */
|
||
|
+ public static boolean isOwnedByCurrentRegion(@NotNull Location location, int squareRadiusChunks) {
|
||
|
+ return server.isOwnedByCurrentRegion(location, squareRadiusChunks);
|
||
|
+ }
|
||
|
+
|
||
|
+ /**
|
||
|
+ * Returns whether the current thread is ticking a region and that the region being ticked
|
||
|
+ * owns the chunk at the specified block position.
|
||
|
+ * @param block Specified block position.
|
||
|
+ */
|
||
|
+ public static boolean isOwnedByCurrentRegion(@NotNull org.bukkit.block.Block block) {
|
||
|
+ return server.isOwnedByCurrentRegion(block);
|
||
|
+ }
|
||
|
+
|
||
|
+ /**
|
||
|
+ * 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.
|
||
|
+ * @param world Specified world.
|
||
|
+ * @param chunkX Specified x-coordinate of the chunk position.
|
||
|
+ * @param chunkZ Specified z-coordinate of the chunk position.
|
||
|
+ */
|
||
|
+ public static boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ) {
|
||
|
+ return server.isOwnedByCurrentRegion(world, chunkX, chunkZ);
|
||
|
+ }
|
||
|
+
|
||
|
+ /**
|
||
|
+ * 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.
|
||
|
+ * @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 <i>not</i> a <i>squared</i>
|
||
|
+ * radius, but rather a <i>Chebyshev Distance</i>.
|
||
|
+ */
|
||
|
+ public static boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ, int squareRadiusChunks) {
|
||
|
+ return server.isOwnedByCurrentRegion(world, chunkX, chunkZ, squareRadiusChunks);
|
||
|
+ }
|
||
|
+
|
||
|
+ /**
|
||
|
+ * 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.
|
||
|
+ * @param entity Specified entity.
|
||
|
+ */
|
||
|
+ public static boolean isOwnedByCurrentRegion(@NotNull Entity entity) {
|
||
|
+ return server.isOwnedByCurrentRegion(entity);
|
||
|
+ }
|
||
|
// Folia end - region threading API
|
||
|
|
||
|
@NotNull
|
||
|
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
|
||
|
index 135467092eec33a21b171df39267d15bad26003e..48902e9aec6af7a4252db5b567d08a80f5709cbf 100644
|
||
|
--- a/src/main/java/org/bukkit/Server.java
|
||
|
+++ b/src/main/java/org/bukkit/Server.java
|
||
|
@@ -2152,5 +2152,83 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
|
||
|
* @return the region task scheduler
|
||
|
*/
|
||
|
@NotNull io.papermc.paper.threadedregions.scheduler.RegionisedScheduler getRegionScheduler();
|
||
|
+
|
||
|
+ /**
|
||
|
+ * 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.
|
||
|
+ * @param world Specified world.
|
||
|
+ * @param position Specified block position.
|
||
|
+ */
|
||
|
+ public boolean isOwnedByCurrentRegion(@NotNull World world, @NotNull org.bukkit.util.Vector position);
|
||
|
+
|
||
|
+ /**
|
||
|
+ * Returns whether the current thread is ticking a region and that the region being ticked
|
||
|
+ * owns the chunks centered at the specified block 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.
|
||
|
+ * @param world Specified world.
|
||
|
+ * @param position Specified block position.
|
||
|
+ * @param squareRadiusChunks Specified square radius. Must be >= 0. Note that this parameter is <i>not</i> a <i>squared</i>
|
||
|
+ * radius, but rather a <i>Chebyshev Distance</i>.
|
||
|
+ */
|
||
|
+ public boolean isOwnedByCurrentRegion(@NotNull World world, @NotNull org.bukkit.util.Vector position, int squareRadiusChunks);
|
||
|
+
|
||
|
+ /**
|
||
|
+ * 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.
|
||
|
+ * @param location Specified location, must have a non-null world.
|
||
|
+ */
|
||
|
+ public boolean isOwnedByCurrentRegion(@NotNull Location location);
|
||
|
+
|
||
|
+ /**
|
||
|
+ * 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.
|
||
|
+ * @param location Specified location, must have a non-null world.
|
||
|
+ * @param squareRadiusChunks Specified square radius. Must be >= 0. Note that this parameter is <i>not</i> a <i>squared</i>
|
||
|
+ * radius, but rather a <i>Chebyshev Distance</i>.
|
||
|
+ */
|
||
|
+ public boolean isOwnedByCurrentRegion(@NotNull Location location, int squareRadiusChunks);
|
||
|
+
|
||
|
+ /**
|
||
|
+ * Returns whether the current thread is ticking a region and that the region being ticked
|
||
|
+ * owns the chunk at the specified block position.
|
||
|
+ * @param block Specified block position.
|
||
|
+ */
|
||
|
+ public boolean isOwnedByCurrentRegion(@NotNull org.bukkit.block.Block block);
|
||
|
+
|
||
|
+ /**
|
||
|
+ * 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.
|
||
|
+ * @param world Specified world.
|
||
|
+ * @param chunkX Specified x-coordinate of the chunk position.
|
||
|
+ * @param chunkZ Specified z-coordinate of the chunk position.
|
||
|
+ */
|
||
|
+ public boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ);
|
||
|
+
|
||
|
+ /**
|
||
|
+ * 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.
|
||
|
+ * @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 <i>not</i> a <i>squared</i>
|
||
|
+ * radius, but rather a <i>Chebyshev Distance</i>.
|
||
|
+ */
|
||
|
+ public boolean isOwnedByCurrentRegion(@NotNull World world, int chunkX, int chunkZ, int squareRadiusChunks);
|
||
|
+
|
||
|
+ /**
|
||
|
+ * 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.
|
||
|
+ * @param entity Specified entity.
|
||
|
+ */
|
||
|
+ public boolean isOwnedByCurrentRegion(@NotNull Entity entity);
|
||
|
// Folia end - region threading API
|
||
|
}
|