Skip to content

Commit

Permalink
fix: do not retain clipboards that completed exceptionally (#2358)
Browse files Browse the repository at this point in the history
  • Loading branch information
dordsor21 authored Jul 20, 2023
1 parent f65c474 commit fe1859e
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +29,7 @@
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;
Expand Down Expand Up @@ -160,7 +162,7 @@ public void copy(
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
Expand Down Expand Up @@ -271,7 +273,7 @@ public void cut(
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"));
Expand All @@ -281,6 +283,7 @@ public void cut(
}

private void createCopy(
final Actor actor,
final LocalSession session,
final EditSession editSession,
final boolean copyBiomes,
Expand Down Expand Up @@ -311,9 +314,22 @@ private void createCopy(

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));
}

Expand Down

0 comments on commit fe1859e

Please sign in to comment.