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.
Dieser Commit ist enthalten in:
dordsor21 2021-08-13 11:44:18 +01:00
Ursprung 3e4f1d5cd8
Commit c65c72b249
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
2 geänderte Dateien mit 15 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -1,6 +1,7 @@
package com.fastasyncworldedit.bukkit.adapter; package com.fastasyncworldedit.bukkit.adapter;
import com.fastasyncworldedit.bukkit.util.BukkitItemStack; import com.fastasyncworldedit.bukkit.util.BukkitItemStack;
import com.fastasyncworldedit.core.util.TaskManager;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.NotABlockException; import com.sk89q.worldedit.NotABlockException;
import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.blocks.BaseItemStack;
@ -36,6 +37,7 @@ import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -362,10 +364,10 @@ public interface IBukkitAdapter {
/** /**
* Generate a given tree type to the given editsession. * 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 editSession Editsession to set blocks to
* @param pt Point to generate tree at * @param pt Point to generate tree at
* @param world World to "generate" tree from (seed-wise) * @param world World to "generate" tree from (seed-wise)
* @return If successsful * @return If successsful
*/ */
default boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, BlockVector3 pt, org.bukkit.World world) { default boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, BlockVector3 pt, org.bukkit.World world) {
@ -379,4 +381,8 @@ public interface IBukkitAdapter {
); );
} }
default List<org.bukkit.entity.Entity> getEntities(org.bukkit.World world) {
return TaskManager.IMP.sync(world::getEntities);
}
} }

Datei anzeigen

@ -138,9 +138,10 @@ public class BukkitWorld extends AbstractWorld {
@Override @Override
public List<com.sk89q.worldedit.entity.Entity> getEntities(Region region) { public List<com.sk89q.worldedit.entity.Entity> getEntities(Region region) {
World world = getWorld(); //FAWE start - allow async entity retrieval
List<Entity> ents = WorldEditPlugin.getInstance().getBukkitImplAdapter().getEntities(getWorld());
//FAWE end
List<Entity> ents = world.getEntities();
List<com.sk89q.worldedit.entity.Entity> entities = new ArrayList<>(); List<com.sk89q.worldedit.entity.Entity> entities = new ArrayList<>();
for (Entity ent : ents) { for (Entity ent : ents) {
if (region.contains(BukkitAdapter.asBlockVector(ent.getLocation()))) { if (region.contains(BukkitAdapter.asBlockVector(ent.getLocation()))) {
@ -153,7 +154,9 @@ public class BukkitWorld extends AbstractWorld {
@Override @Override
public List<com.sk89q.worldedit.entity.Entity> getEntities() { public List<com.sk89q.worldedit.entity.Entity> getEntities() {
List<com.sk89q.worldedit.entity.Entity> list = new ArrayList<>(); List<com.sk89q.worldedit.entity.Entity> 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)); list.add(BukkitAdapter.adapt(entity));
} }
return list; return list;