From c65c72b249c9fceb85f2e909233722dcdac4ed52 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Fri, 13 Aug 2021 11:44:18 +0100 Subject: [PATCH] Allow adapters to override World#getEntities to avoid AsyncCatcher - Even if we access (cache) the entities synchronously, we'd then be doing stuff asynchronously so adapters can override this and either use the world#getEntities normally (pre 1.17) or get entities async anyway. --- .../bukkit/adapter/IBukkitAdapter.java | 12 +++++++++--- .../java/com/sk89q/worldedit/bukkit/BukkitWorld.java | 9 ++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/IBukkitAdapter.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/IBukkitAdapter.java index cc5c028e4..01efd6695 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/IBukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/IBukkitAdapter.java @@ -1,6 +1,7 @@ package com.fastasyncworldedit.bukkit.adapter; import com.fastasyncworldedit.bukkit.util.BukkitItemStack; +import com.fastasyncworldedit.core.util.TaskManager; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.NotABlockException; import com.sk89q.worldedit.blocks.BaseItemStack; @@ -36,6 +37,7 @@ import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import java.util.List; import java.util.Locale; import static com.google.common.base.Preconditions.checkNotNull; @@ -362,10 +364,10 @@ public interface IBukkitAdapter { /** * Generate a given tree type to the given editsession. * - * @param type Type of tree to generate + * @param type Type of tree to generate * @param editSession Editsession to set blocks to - * @param pt Point to generate tree at - * @param world World to "generate" tree from (seed-wise) + * @param pt Point to generate tree at + * @param world World to "generate" tree from (seed-wise) * @return If successsful */ default boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, BlockVector3 pt, org.bukkit.World world) { @@ -379,4 +381,8 @@ public interface IBukkitAdapter { ); } + default List getEntities(org.bukkit.World world) { + return TaskManager.IMP.sync(world::getEntities); + } + } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index 28ce99b72..d06f603d3 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -138,9 +138,10 @@ public class BukkitWorld extends AbstractWorld { @Override public List getEntities(Region region) { - World world = getWorld(); + //FAWE start - allow async entity retrieval + List ents = WorldEditPlugin.getInstance().getBukkitImplAdapter().getEntities(getWorld()); + //FAWE end - List ents = world.getEntities(); List entities = new ArrayList<>(); for (Entity ent : ents) { if (region.contains(BukkitAdapter.asBlockVector(ent.getLocation()))) { @@ -153,7 +154,9 @@ public class BukkitWorld extends AbstractWorld { @Override public List getEntities() { List list = new ArrayList<>(); - for (Entity entity : getWorld().getEntities()) { + //FAWE start - allow async entity retrieval + for (Entity entity : WorldEditPlugin.getInstance().getBukkitImplAdapter().getEntities(getWorld())) { + //FAWE end list.add(BukkitAdapter.adapt(entity)); } return list;