From 836dc75b65db706da83eab7c963e45545d56f1e9 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 25 Mar 2023 18:50:36 +0100 Subject: [PATCH] Replace Vector with Position in isOwnedByCurrentRegion methods Closes #3 --- ...king-ownership-of-region-by-position.patch | 20 ++++++------ patches/server/0004-Threaded-Regions.patch | 31 ++++++++----------- ...-getHandle-and-overrides-perform-thr.patch | 4 +-- ...edOperationException-for-broken-APIs.patch | 6 ++-- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/patches/api/0005-Add-API-for-checking-ownership-of-region-by-position.patch b/patches/api/0005-Add-API-for-checking-ownership-of-region-by-position.patch index b3032e8..0ad8457 100644 --- a/patches/api/0005-Add-API-for-checking-ownership-of-region-by-position.patch +++ b/patches/api/0005-Add-API-for-checking-ownership-of-region-by-position.patch @@ -11,7 +11,7 @@ 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 7986b9fcaf256e9042f6d9ddc38e8bd76645cbb7..16043d6f7894182e8ff75a8faf57dedf8db50d84 100644 +index 7986b9fcaf256e9042f6d9ddc38e8bd76645cbb7..a1295698beee025120beb3d151e77646bb44723b 100644 --- a/src/main/java/org/bukkit/Bukkit.java +++ b/src/main/java/org/bukkit/Bukkit.java @@ -2496,6 +2496,100 @@ public final class Bukkit { @@ -25,7 +25,7 @@ index 7986b9fcaf256e9042f6d9ddc38e8bd76645cbb7..16043d6f7894182e8ff75a8faf57dedf + * @param world Specified world. + * @param position Specified block position. + */ -+ public static boolean isOwnedByCurrentRegion(@NotNull World world, @NotNull org.bukkit.util.Vector position) { ++ public static boolean isOwnedByCurrentRegion(@NotNull World world, @NotNull io.papermc.paper.math.Position position) { + return server.isOwnedByCurrentRegion(world, position); + } + @@ -39,7 +39,7 @@ index 7986b9fcaf256e9042f6d9ddc38e8bd76645cbb7..16043d6f7894182e8ff75a8faf57dedf + * @param squareRadiusChunks Specified square radius. Must be >= 0. Note that this parameter is not a squared + * radius, but rather a Chebyshev Distance. + */ -+ public static boolean isOwnedByCurrentRegion(@NotNull World world, @NotNull org.bukkit.util.Vector position, int squareRadiusChunks) { ++ public static boolean isOwnedByCurrentRegion(@NotNull World world, @NotNull io.papermc.paper.math.Position position, int squareRadiusChunks) { + return server.isOwnedByCurrentRegion(world, position, squareRadiusChunks); + } + @@ -72,7 +72,7 @@ index 7986b9fcaf256e9042f6d9ddc38e8bd76645cbb7..16043d6f7894182e8ff75a8faf57dedf + * @param block Specified block position. + */ + public static boolean isOwnedByCurrentRegion(@NotNull org.bukkit.block.Block block) { -+ return server.isOwnedByCurrentRegion(block); ++ return server.isOwnedByCurrentRegion(block.getLocation()); + } + + /** @@ -116,10 +116,10 @@ index 7986b9fcaf256e9042f6d9ddc38e8bd76645cbb7..16043d6f7894182e8ff75a8faf57dedf @NotNull diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java -index 5caa00a413450dee18739f6430ffaf5095ea3036..c72eee72401e275af57d4fd67a04df1eac13954c 100644 +index 5caa00a413450dee18739f6430ffaf5095ea3036..b04742bafbb4045d5842ac96761a941cfd3fc758 100644 --- a/src/main/java/org/bukkit/Server.java +++ b/src/main/java/org/bukkit/Server.java -@@ -2170,5 +2170,83 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi +@@ -2170,5 +2170,85 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi * @return the global region scheduler */ public @NotNull io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler getGlobalRegionScheduler(); @@ -130,7 +130,7 @@ index 5caa00a413450dee18739f6430ffaf5095ea3036..c72eee72401e275af57d4fd67a04df1e + * @param world Specified world. + * @param position Specified block position. + */ -+ public boolean isOwnedByCurrentRegion(@NotNull World world, @NotNull org.bukkit.util.Vector position); ++ public boolean isOwnedByCurrentRegion(@NotNull World world, @NotNull io.papermc.paper.math.Position position); + + /** + * Returns whether the current thread is ticking a region and that the region being ticked @@ -142,7 +142,7 @@ index 5caa00a413450dee18739f6430ffaf5095ea3036..c72eee72401e275af57d4fd67a04df1e + * @param squareRadiusChunks Specified square radius. Must be >= 0. Note that this parameter is not a squared + * radius, but rather a Chebyshev Distance. + */ -+ public boolean isOwnedByCurrentRegion(@NotNull World world, @NotNull org.bukkit.util.Vector position, int squareRadiusChunks); ++ public boolean isOwnedByCurrentRegion(@NotNull World world, @NotNull io.papermc.paper.math.Position position, int squareRadiusChunks); + + /** + * Returns whether the current thread is ticking a region and that the region being ticked @@ -168,7 +168,9 @@ index 5caa00a413450dee18739f6430ffaf5095ea3036..c72eee72401e275af57d4fd67a04df1e + * owns the chunk at the specified block position. + * @param block Specified block position. + */ -+ public boolean isOwnedByCurrentRegion(@NotNull org.bukkit.block.Block block); ++ default boolean isOwnedByCurrentRegion(@NotNull org.bukkit.block.Block block) { ++ return isOwnedByCurrentRegion(block.getLocation()); ++ } + + /** + * Returns whether the current thread is ticking a region and that the region being ticked diff --git a/patches/server/0004-Threaded-Regions.patch b/patches/server/0004-Threaded-Regions.patch index 164ba85..5073ea6 100644 --- a/patches/server/0004-Threaded-Regions.patch +++ b/patches/server/0004-Threaded-Regions.patch @@ -22946,10 +22946,10 @@ index 1d7c663fa0e550bd0cfb9a4b83ccd7e2968666f0..f3df9c9b6cff85565514f990597f3fe5 LevelChunkTicks levelChunkTicks = this.allContainers.get(l); if (levelChunkTicks == null) { diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java -index e0b6c737f9de2b6e692d6813d8dea4c35f038573..71663e4f16fb59c36c53badfd19c63702ba792f9 100644 +index e0b6c737f9de2b6e692d6813d8dea4c35f038573..851937baff90177e648d970cf1c462b897aaf9f5 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java -@@ -303,6 +303,81 @@ public final class CraftServer implements Server { +@@ -303,6 +303,76 @@ public final class CraftServer implements Server { CraftItemFactory.instance(); } @@ -22974,16 +22974,16 @@ index e0b6c737f9de2b6e692d6813d8dea4c35f038573..71663e4f16fb59c36c53badfd19c6370 + } + + @Override -+ public final boolean isOwnedByCurrentRegion(World world, org.bukkit.util.Vector position) { ++ public final boolean isOwnedByCurrentRegion(World world, io.papermc.paper.math.Position position) { + return io.papermc.paper.util.TickThread.isTickThreadFor( -+ ((CraftWorld)world).getHandle(), position.getBlockX() >> 4, position.getBlockZ() >> 4 ++ ((CraftWorld) world).getHandle(), position.blockX() >> 4, position.blockZ() >> 4 + ); + } + + @Override -+ public final boolean isOwnedByCurrentRegion(World world, org.bukkit.util.Vector position, int squareRadiusChunks) { ++ public final boolean isOwnedByCurrentRegion(World world, io.papermc.paper.math.Position position, int squareRadiusChunks) { + return io.papermc.paper.util.TickThread.isTickThreadFor( -+ ((CraftWorld)world).getHandle(), position.getBlockX() >> 4, position.getBlockZ() >> 4, squareRadiusChunks ++ ((CraftWorld) world).getHandle(), position.blockX() >> 4, position.blockZ() >> 4, squareRadiusChunks + ); + } + @@ -22991,7 +22991,7 @@ index e0b6c737f9de2b6e692d6813d8dea4c35f038573..71663e4f16fb59c36c53badfd19c6370 + public final boolean isOwnedByCurrentRegion(Location location) { + World world = location.getWorld(); + return io.papermc.paper.util.TickThread.isTickThreadFor( -+ ((CraftWorld)world).getHandle(), location.getBlockX() >> 4, location.getBlockZ() >> 4 ++ ((CraftWorld) world).getHandle(), location.getBlockX() >> 4, location.getBlockZ() >> 4 + ); + } + @@ -22999,26 +22999,21 @@ index e0b6c737f9de2b6e692d6813d8dea4c35f038573..71663e4f16fb59c36c53badfd19c6370 + public final boolean isOwnedByCurrentRegion(Location location, int squareRadiusChunks) { + World world = location.getWorld(); + return io.papermc.paper.util.TickThread.isTickThreadFor( -+ ((CraftWorld)world).getHandle(), location.getBlockX() >> 4, location.getBlockZ() >> 4, squareRadiusChunks ++ ((CraftWorld) world).getHandle(), location.getBlockX() >> 4, location.getBlockZ() >> 4, squareRadiusChunks + ); + } + + @Override -+ public final boolean isOwnedByCurrentRegion(org.bukkit.block.Block block) { -+ return this.isOwnedByCurrentRegion(block.getLocation()); -+ } -+ -+ @Override + public final boolean isOwnedByCurrentRegion(World world, int chunkX, int chunkZ) { + return io.papermc.paper.util.TickThread.isTickThreadFor( -+ ((CraftWorld)world).getHandle(), chunkX, chunkZ ++ ((CraftWorld) world).getHandle(), chunkX, chunkZ + ); + } + + @Override + public final boolean isOwnedByCurrentRegion(World world, int chunkX, int chunkZ, int squareRadiusChunks) { + return io.papermc.paper.util.TickThread.isTickThreadFor( -+ ((CraftWorld)world).getHandle(), chunkX, chunkZ, squareRadiusChunks ++ ((CraftWorld) world).getHandle(), chunkX, chunkZ, squareRadiusChunks + ); + } + @@ -23031,7 +23026,7 @@ index e0b6c737f9de2b6e692d6813d8dea4c35f038573..71663e4f16fb59c36c53badfd19c6370 public CraftServer(DedicatedServer console, PlayerList playerList) { this.console = console; this.playerList = (DedicatedPlayerList) playerList; -@@ -856,6 +931,9 @@ public final class CraftServer implements Server { +@@ -856,6 +926,9 @@ public final class CraftServer implements Server { // NOTE: Should only be called from DedicatedServer.ah() public boolean dispatchServerCommand(CommandSender sender, ConsoleInput serverCommand) { @@ -23041,7 +23036,7 @@ index e0b6c737f9de2b6e692d6813d8dea4c35f038573..71663e4f16fb59c36c53badfd19c6370 if (sender instanceof Conversable) { Conversable conversable = (Conversable) sender; -@@ -875,12 +953,44 @@ public final class CraftServer implements Server { +@@ -875,12 +948,44 @@ public final class CraftServer implements Server { } } @@ -23086,7 +23081,7 @@ index e0b6c737f9de2b6e692d6813d8dea4c35f038573..71663e4f16fb59c36c53badfd19c6370 // Paper Start if (!org.spigotmc.AsyncCatcher.shuttingDown && !Bukkit.isPrimaryThread()) { final CommandSender fSender = sender; -@@ -2894,7 +3004,7 @@ public final class CraftServer implements Server { +@@ -2894,7 +2999,7 @@ public final class CraftServer implements Server { @Override public int getCurrentTick() { diff --git a/patches/server/0009-Make-CraftEntity-getHandle-and-overrides-perform-thr.patch b/patches/server/0009-Make-CraftEntity-getHandle-and-overrides-perform-thr.patch index c653000..cef7201 100644 --- a/patches/server/0009-Make-CraftEntity-getHandle-and-overrides-perform-thr.patch +++ b/patches/server/0009-Make-CraftEntity-getHandle-and-overrides-perform-thr.patch @@ -87,10 +87,10 @@ index 006695237ddd0cc5f1910c307d4e8a696128807f..64ddd3415878b6a86a98d7718d5e3e5b if (this.passengers.size() == 1 && this.passengers.get(0) == entity) { this.passengers = ImmutableList.of(); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java -index 71663e4f16fb59c36c53badfd19c63702ba792f9..9902d216c8659acd128bb85e4624ad682e4de804 100644 +index 851937baff90177e648d970cf1c462b897aaf9f5..8fbe4e8a43940163efaa74da99eb077ae0a426f9 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java -@@ -374,7 +374,7 @@ public final class CraftServer implements Server { +@@ -369,7 +369,7 @@ public final class CraftServer implements Server { @Override public final boolean isOwnedByCurrentRegion(Entity entity) { diff --git a/patches/server/0011-Throw-UnsupportedOperationException-for-broken-APIs.patch b/patches/server/0011-Throw-UnsupportedOperationException-for-broken-APIs.patch index 4deb12f..0f12957 100644 --- a/patches/server/0011-Throw-UnsupportedOperationException-for-broken-APIs.patch +++ b/patches/server/0011-Throw-UnsupportedOperationException-for-broken-APIs.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Throw UnsupportedOperationException() for broken APIs diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java -index 9902d216c8659acd128bb85e4624ad682e4de804..2252a3d84d5fe746647e16edfc989d7eaf19fd96 100644 +index 8fbe4e8a43940163efaa74da99eb077ae0a426f9..29602f9c2f1e04677a462079c094e9b51cec43af 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java -@@ -1244,6 +1244,7 @@ public final class CraftServer implements Server { +@@ -1239,6 +1239,7 @@ public final class CraftServer implements Server { @Override public World createWorld(WorldCreator creator) { @@ -16,7 +16,7 @@ index 9902d216c8659acd128bb85e4624ad682e4de804..2252a3d84d5fe746647e16edfc989d7e Preconditions.checkState(this.console.getAllLevels().iterator().hasNext(), "Cannot create additional worlds on STARTUP"); //Preconditions.checkState(!this.console.isIteratingOverLevels, "Cannot create a world while worlds are being ticked"); // Paper - Cat - Temp disable. We'll see how this goes. Validate.notNull(creator, "Creator may not be null"); -@@ -1384,6 +1385,7 @@ public final class CraftServer implements Server { +@@ -1379,6 +1380,7 @@ public final class CraftServer implements Server { @Override public boolean unloadWorld(World world, boolean save) {