only close clipboard on error during copy

apply to //cut as well
This commit is contained in:
dordsor21 2021-09-11 00:27:26 +01:00
parent 470ba64fe4
commit db24b429c1
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B

View File

@ -139,8 +139,8 @@ public class ClipboardCommands {
} }
session.setClipboard(null); session.setClipboard(null);
try (Clipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId())) { Clipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId());
try {
clipboard.setOrigin(centerClipboard ? region.getCenter().toBlockPoint() : session.getPlacementPosition(actor)); clipboard.setOrigin(centerClipboard ? region.getCenter().toBlockPoint() : session.getPlacementPosition(actor));
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint()); ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
copy.setCopyingEntities(copyEntities); copy.setCopyingEntities(copyEntities);
@ -170,6 +170,9 @@ public class ClipboardCommands {
session.setClipboard(new ClipboardHolder(clipboard)); session.setClipboard(new ClipboardHolder(clipboard));
copy.getStatusMessages().forEach(actor::print); copy.getStatusMessages().forEach(actor::print);
} catch (Throwable e) {
clipboard.close();
throw e;
} }
//FAWE end //FAWE end
} }
@ -274,38 +277,43 @@ public class ClipboardCommands {
session.setClipboard(null); session.setClipboard(null);
BlockArrayClipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId()); BlockArrayClipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId());
clipboard.setOrigin(session.getPlacementPosition(actor)); try {
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint()); clipboard.setOrigin(session.getPlacementPosition(actor));
copy.setSourceFunction(new BlockReplace(editSession, leavePattern)); ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
copy.setCopyingEntities(copyEntities); copy.setSourceFunction(new BlockReplace(editSession, leavePattern));
copy.setRemovingEntities(true); copy.setCopyingEntities(copyEntities);
copy.setCopyingBiomes(copyBiomes); copy.setRemovingEntities(true);
Mask sourceMask = editSession.getSourceMask(); copy.setCopyingBiomes(copyBiomes);
Region[] regions = editSession.getAllowedRegions(); Mask sourceMask = editSession.getSourceMask();
Region allowedRegion; Region[] regions = editSession.getAllowedRegions();
if (regions == null || regions.length == 0) { Region allowedRegion;
allowedRegion = new NullRegion(); if (regions == null || regions.length == 0) {
} else { allowedRegion = new NullRegion();
allowedRegion = new RegionIntersection(regions); } else {
} allowedRegion = new RegionIntersection(regions);
final Mask firstSourceMask = mask != null ? mask : sourceMask; }
final Mask finalMask = MaskIntersection.of(firstSourceMask, new RegionMask(allowedRegion)).optimize(); final Mask firstSourceMask = mask != null ? mask : sourceMask;
if (finalMask != Masks.alwaysTrue()) { final Mask finalMask = MaskIntersection.of(firstSourceMask, new RegionMask(allowedRegion)).optimize();
copy.setSourceMask(finalMask); if (finalMask != Masks.alwaysTrue()) {
} copy.setSourceMask(finalMask);
if (sourceMask != null) { }
editSession.setSourceMask(null); if (sourceMask != null) {
new MaskTraverser(sourceMask).reset(editSession); editSession.setSourceMask(null);
editSession.setSourceMask(null); new MaskTraverser(sourceMask).reset(editSession);
} editSession.setSourceMask(null);
Operations.completeLegacy(copy); }
saveDiskClipboard(clipboard); Operations.completeLegacy(copy);
session.setClipboard(new ClipboardHolder(clipboard)); saveDiskClipboard(clipboard);
session.setClipboard(new ClipboardHolder(clipboard));
if (!actor.hasPermission("fawe.tips")) { if (!actor.hasPermission("fawe.tips")) {
actor.print(Caption.of("fawe.tips.tip.lazycut")); actor.print(Caption.of("fawe.tips.tip.lazycut"));
}
copy.getStatusMessages().forEach(actor::print);
} catch (Throwable e) {
clipboard.close();
throw e;
} }
copy.getStatusMessages().forEach(actor::print);
//FAWE end //FAWE end
} }