mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
Refactor the try-catch for copy/cut commands, switch to saveDiskClipboard
instead of closing the clipboard on error
Address #1291
This commit is contained in:
parent
adf83bdd0a
commit
fcbbc72a19
@ -140,40 +140,40 @@ public class ClipboardCommands {
|
|||||||
session.setClipboard(null);
|
session.setClipboard(null);
|
||||||
|
|
||||||
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);
|
copy.setCopyingBiomes(copyBiomes);
|
||||||
copy.setCopyingBiomes(copyBiomes);
|
|
||||||
|
|
||||||
Mask sourceMask = editSession.getSourceMask();
|
Mask sourceMask = editSession.getSourceMask();
|
||||||
Region[] regions = editSession.getAllowedRegions();
|
Region[] regions = editSession.getAllowedRegions();
|
||||||
Region allowedRegion;
|
Region allowedRegion;
|
||||||
if (regions == null || regions.length == 0) {
|
if (regions == null || regions.length == 0) {
|
||||||
allowedRegion = new NullRegion();
|
allowedRegion = new NullRegion();
|
||||||
} else {
|
} else {
|
||||||
allowedRegion = new RegionIntersection(regions);
|
allowedRegion = new RegionIntersection(regions);
|
||||||
}
|
|
||||||
final Mask firstSourceMask = mask != null ? mask : sourceMask;
|
|
||||||
final Mask finalMask = MaskIntersection.of(firstSourceMask, new RegionMask(allowedRegion)).optimize();
|
|
||||||
if (finalMask != Masks.alwaysTrue()) {
|
|
||||||
copy.setSourceMask(finalMask);
|
|
||||||
}
|
|
||||||
if (sourceMask != null) {
|
|
||||||
editSession.setSourceMask(null);
|
|
||||||
new MaskTraverser(sourceMask).reset(editSession);
|
|
||||||
editSession.setSourceMask(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
Operations.completeLegacy(copy);
|
|
||||||
saveDiskClipboard(clipboard);
|
|
||||||
session.setClipboard(new ClipboardHolder(clipboard));
|
|
||||||
|
|
||||||
copy.getStatusMessages().forEach(actor::print);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
clipboard.close();
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
|
final Mask firstSourceMask = mask != null ? mask : sourceMask;
|
||||||
|
final Mask finalMask = MaskIntersection.of(firstSourceMask, new RegionMask(allowedRegion)).optimize();
|
||||||
|
if (finalMask != Masks.alwaysTrue()) {
|
||||||
|
copy.setSourceMask(finalMask);
|
||||||
|
}
|
||||||
|
if (sourceMask != null) {
|
||||||
|
editSession.setSourceMask(null);
|
||||||
|
new MaskTraverser(sourceMask).reset(editSession);
|
||||||
|
editSession.setSourceMask(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Operations.completeLegacy(copy);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
saveDiskClipboard(clipboard);
|
||||||
|
}
|
||||||
|
session.setClipboard(new ClipboardHolder(clipboard));
|
||||||
|
|
||||||
|
copy.getStatusMessages().forEach(actor::print);
|
||||||
//FAWE end
|
//FAWE end
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,43 +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());
|
||||||
try {
|
clipboard.setOrigin(session.getPlacementPosition(actor));
|
||||||
clipboard.setOrigin(session.getPlacementPosition(actor));
|
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
|
||||||
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
|
copy.setSourceFunction(new BlockReplace(editSession, leavePattern));
|
||||||
copy.setSourceFunction(new BlockReplace(editSession, leavePattern));
|
copy.setCopyingEntities(copyEntities);
|
||||||
copy.setCopyingEntities(copyEntities);
|
copy.setRemovingEntities(true);
|
||||||
copy.setRemovingEntities(true);
|
copy.setCopyingBiomes(copyBiomes);
|
||||||
copy.setCopyingBiomes(copyBiomes);
|
Mask sourceMask = editSession.getSourceMask();
|
||||||
Mask sourceMask = editSession.getSourceMask();
|
Region[] regions = editSession.getAllowedRegions();
|
||||||
Region[] regions = editSession.getAllowedRegions();
|
Region allowedRegion;
|
||||||
Region allowedRegion;
|
if (regions == null || regions.length == 0) {
|
||||||
if (regions == null || regions.length == 0) {
|
allowedRegion = new NullRegion();
|
||||||
allowedRegion = new NullRegion();
|
} else {
|
||||||
} else {
|
allowedRegion = new RegionIntersection(regions);
|
||||||
allowedRegion = new RegionIntersection(regions);
|
|
||||||
}
|
|
||||||
final Mask firstSourceMask = mask != null ? mask : sourceMask;
|
|
||||||
final Mask finalMask = MaskIntersection.of(firstSourceMask, new RegionMask(allowedRegion)).optimize();
|
|
||||||
if (finalMask != Masks.alwaysTrue()) {
|
|
||||||
copy.setSourceMask(finalMask);
|
|
||||||
}
|
|
||||||
if (sourceMask != null) {
|
|
||||||
editSession.setSourceMask(null);
|
|
||||||
new MaskTraverser(sourceMask).reset(editSession);
|
|
||||||
editSession.setSourceMask(null);
|
|
||||||
}
|
|
||||||
Operations.completeLegacy(copy);
|
|
||||||
saveDiskClipboard(clipboard);
|
|
||||||
session.setClipboard(new ClipboardHolder(clipboard));
|
|
||||||
|
|
||||||
if (!actor.hasPermission("fawe.tips")) {
|
|
||||||
actor.print(Caption.of("fawe.tips.tip.lazycut"));
|
|
||||||
}
|
|
||||||
copy.getStatusMessages().forEach(actor::print);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
clipboard.close();
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
|
final Mask firstSourceMask = mask != null ? mask : sourceMask;
|
||||||
|
final Mask finalMask = MaskIntersection.of(firstSourceMask, new RegionMask(allowedRegion)).optimize();
|
||||||
|
if (finalMask != Masks.alwaysTrue()) {
|
||||||
|
copy.setSourceMask(finalMask);
|
||||||
|
}
|
||||||
|
if (sourceMask != null) {
|
||||||
|
editSession.setSourceMask(null);
|
||||||
|
new MaskTraverser(sourceMask).reset(editSession);
|
||||||
|
editSession.setSourceMask(null);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Operations.completeLegacy(copy);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
saveDiskClipboard(clipboard);
|
||||||
|
}
|
||||||
|
session.setClipboard(new ClipboardHolder(clipboard));
|
||||||
|
|
||||||
|
if (!actor.hasPermission("fawe.tips")) {
|
||||||
|
actor.print(Caption.of("fawe.tips.tip.lazycut"));
|
||||||
|
}
|
||||||
|
copy.getStatusMessages().forEach(actor::print);
|
||||||
//FAWE end
|
//FAWE end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user