Overwrite entities when copy-pasting with entities enabled.
LM-Wolfert opened this issue ยท 0 comments
What feature do you want to see added?
Brief: When using copy-paste with entities enabled (-e, or using the API), also remove the existing entities in the areas you are pasting to.
Using the API to copy-paste and allowing entities works fine, however when I try to paste that selection to an area that already includes entities, they do not get removed first, as you may expect, blocks on the other hand do get replaced. I'd like to see this also work for entities.
I tried to apply a workaround solution but the issue lies with entities being loaded differently from chunks, at least if I've understood this correctly.
If this is something that is unrealistic to add, or unwanted then feel free to deny this request.
See the example code below of what I've been using to copy-paste.
//Get the worlds in worldEdit format
com.sk89q.worldedit.world.World copyWorld = new BukkitWorld(copy);
com.sk89q.worldedit.world.World pasteWorld = new BukkitWorld(paste);
Polygonal2DRegion copyRegion = new Polygonal2DRegion(copyWorld, copyVector, MIN_Y, MAX_Y - 1);
Polygonal2DRegion pasteRegion = new Polygonal2DRegion(pasteWorld, pasteVector, MIN_Y, MAX_Y - 1);
BlockArrayClipboard clipboard = new BlockArrayClipboard(copyRegion);
try (EditSession editSession = WorldEdit.getInstance().newEditSessionBuilder()
.world(copyWorld).fastMode(true).checkMemory(false).limitUnlimited().changeSetNull().build()) {
ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(
editSession, copyRegion, clipboard, copyRegion.getMinimumPoint()
);
forwardExtentCopy.setCopyingBiomes(true);
forwardExtentCopy.setCopyingEntities(true);
// configure here
Operations.complete(forwardExtentCopy);
} catch (WorldEditException e) {
e.printStackTrace();
return false;
}
try (EditSession editSession = WorldEdit.getInstance().newEditSessionBuilder()
.world(pasteWorld).fastMode(true).checkMemory(false).limitUnlimited().changeSetNull().build()) {
Operation operation = new ClipboardHolder(clipboard)
.createPaste(editSession)
.to(pasteRegion.getMinimumPoint())
.copyBiomes(true)
.copyEntities(true)
// configure here
.build();
Operations.complete(operation);
editSession.flushQueue();
} catch (WorldEditException e) {
e.printStackTrace();
return false;
}
Are there any alternatives?
For my personal use I have applied a more dramatic workaround of deleting all entities to prevent people from being able to leave entities in the area of a region after they've deleted them. Else it could be abused by the playerbase.
This is obviously not a workaround for most situations, but to make sure our servers are secure from abuse, this had to be done.
Example:
/**
* Deletes all entities in the given world
*
* @param world the world
*/
public static void deleteEntities(World world) {
@NotNull List<Entity> entities = world.getEntities();
final int[] count = {0};
entities.forEach(entity -> {
if (!entity.getType().equals(EntityType.PLAYER)) {
count[0]++;
entity.remove();
}
});
LOGGER.info(String.format("Removed %d entities from world %s", count[0], world.getName()));
}
Anything else?
I have only tested this using the API, not with the ingame commands, but I'd assume it functions the same. If not then this suggestion can be regarded as an API suggestion only.
If there is already a way to do this, then I'd be happy to hear, but I was unable to find it.