Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -19,6 +19,7 @@

package com.sk89q.worldedit.bukkit;

import com.fastasyncworldedit.core.util.TaskManager;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
Expand Down Expand Up @@ -110,17 +111,21 @@ public BaseEntity getState() {

@Override
public boolean remove() {
org.bukkit.entity.Entity entity = entityRef.get();
if (entity != null) {
try {
entity.remove();
} catch (UnsupportedOperationException e) {
return false;
// synchronize the whole method, not just the remove operation as we always need to synchronize and
// can make sure the entity reference was not invalidated in the few milliseconds between the next available tick (lol)
return TaskManager.taskManager().sync(() -> {
org.bukkit.entity.Entity entity = entityRef.get();
if (entity != null) {
try {
entity.remove();
} catch (UnsupportedOperationException e) {
return false;
}
return entity.isDead();
} else {
return true;
}
return entity.isDead();
} else {
return true;
}
});
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.fastasyncworldedit.core.util.ImgurUtility;
import com.fastasyncworldedit.core.util.MainUtil;
import com.fastasyncworldedit.core.util.MaskTraverser;
import com.fastasyncworldedit.core.util.TaskManager;
import com.fastasyncworldedit.core.util.task.RunnableVal;
import com.google.common.collect.Lists;
import com.sk89q.worldedit.EditSession;
Expand Down Expand Up @@ -98,6 +99,7 @@
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -479,7 +481,14 @@ public void place(
.apply(region.getMaximumPoint().subtract(region.getMinimumPoint()).toVector3())
.toBlockPoint());
if (removeEntities) {
editSession.getEntities(new CuboidRegion(realTo, max)).forEach(Entity::remove);
// Collect entities on the current (command) thread, in case it benefits from asynchronous retrieval (unlikely)
final Collection<? extends Entity> entities = editSession.getEntities(new CuboidRegion(realTo, max));
// BukkitEntity#remove is synchronized, but it makes more sense to synchronize here beforehand in case many
// entities are affected. BukkitEntity will not synchronize if it's already called on the main thread.
TaskManager.taskManager().sync(() -> {
entities.forEach(Entity::remove);
return true;
});
}
if (selectPasted || onlySelect) {
RegionSelector selector = new CuboidRegionSelector(world, realTo, max);
Expand Down
Loading