From fe1859e9d23caba0462593c8d26f90aa9edf9fe4 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 20 Jul 2023 16:56:30 +0100 Subject: [PATCH] fix: do not retain clipboards that completed exceptionally (#2358) --- .../worldedit/command/ClipboardCommands.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java index 40ca530c8..e39bbc641 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.command; +import com.fastasyncworldedit.core.Fawe; import com.fastasyncworldedit.core.FaweAPI; import com.fastasyncworldedit.core.FaweCache; import com.fastasyncworldedit.core.configuration.Caption; @@ -28,6 +29,7 @@ import com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard; import com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder; import com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard; import com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder; +import com.fastasyncworldedit.core.internal.exception.FaweException; import com.fastasyncworldedit.core.internal.io.FastByteArrayOutputStream; import com.fastasyncworldedit.core.limit.FaweLimit; import com.fastasyncworldedit.core.util.ImgurUtility; @@ -160,7 +162,7 @@ public class ClipboardCommands { session.getPlacementPosition(actor)); ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint()); copy.setCopyingEntities(copyEntities); - createCopy(session, editSession, copyBiomes, mask, clipboard, copy); + createCopy(actor, session, editSession, copyBiomes, mask, clipboard, copy); copy.getStatusMessages().forEach(actor::print); //FAWE end @@ -271,7 +273,7 @@ public class ClipboardCommands { copy.setSourceFunction(new BlockReplace(editSession, leavePattern)); copy.setCopyingEntities(copyEntities); copy.setRemovingEntities(true); - createCopy(session, editSession, copyBiomes, mask, clipboard, copy); + createCopy(actor, session, editSession, copyBiomes, mask, clipboard, copy); if (!actor.hasPermission("fawe.tips")) { actor.print(Caption.of("fawe.tips.tip.lazycut")); @@ -281,6 +283,7 @@ public class ClipboardCommands { } private void createCopy( + final Actor actor, final LocalSession session, final EditSession editSession, final boolean copyBiomes, @@ -311,9 +314,22 @@ public class ClipboardCommands { try { Operations.completeLegacy(copy); - } finally { - clipboard.flush(); + } catch (Exception e) { + DiskOptimizedClipboard doc; + if (clipboard instanceof DiskOptimizedClipboard) { + doc = (DiskOptimizedClipboard) clipboard; + } else if (clipboard instanceof BlockArrayClipboard && ((BlockArrayClipboard) clipboard).getParent() instanceof DiskOptimizedClipboard) { + doc = (DiskOptimizedClipboard) ((BlockArrayClipboard) clipboard).getParent(); + } else { + throw e; + } + Fawe.instance().getClipboardExecutor().submit(actor.getUniqueId(), () -> { + clipboard.close(); + doc.getFile().delete(); + }); + throw e; } + clipboard.flush(); session.setClipboard(new ClipboardHolder(clipboard)); }