Skip to content
Permalink
Browse files

Fixed a few potential Area bugs depending on platform etc

  • Loading branch information...
me4502 committed Oct 22, 2018
1 parent 8c71b1b commit 3ef008aa70bd8512fcdbd027f769db56f61f1b57
Showing with 18 additions and 19 deletions.
  1. +18 −19 src/main/java/com/sk89q/craftbook/mechanics/area/CopyManager.java
@@ -169,11 +169,12 @@ public BlockArrayClipboard load(String namespace, String id) throws IOException
missing.put(cacheKey, System.currentTimeMillis());
throw new IOException("Unknown clipboard format!");
}
ClipboardReader reader = format.getReader(new FileInputStream(file));
copy = (BlockArrayClipboard) reader.read();
missing.remove(cacheKey);
cache.put(cacheKey, copy);
return copy;
try (ClipboardReader reader = format.getReader(new FileInputStream(file))) {
copy = (BlockArrayClipboard) reader.read();
missing.remove(cacheKey);
cache.put(cacheKey, copy);
return copy;
}
} else {
missing.put(cacheKey, System.currentTimeMillis());
throw new FileNotFoundException(id);
@@ -193,7 +194,6 @@ public BlockArrayClipboard load(String namespace, String id) throws IOException
* @throws IOException If the file failed to save
*/
public void save(String namespace, String id, BlockArrayClipboard clipboard) throws IOException {

File folder = new File(new File(plugin.getDataFolder(), "areas"), namespace);

if (!folder.exists()) {
@@ -205,8 +205,9 @@ public void save(String namespace, String id, BlockArrayClipboard clipboard) thr
String cacheKey = namespace + '/' + id;

File file = new File(folder, id + getFileSuffix());
ClipboardWriter writer = getDefaultClipboardFormat().getWriter(new FileOutputStream(file));
writer.write(clipboard);
try (ClipboardWriter writer = getDefaultClipboardFormat().getWriter(new FileOutputStream(file))) {
writer.write(clipboard);
}
missing.remove(cacheKey);
cache.put(cacheKey, clipboard);
}
@@ -238,15 +239,16 @@ public BlockArrayClipboard copy(Region region) throws WorldEditException {
* @throws WorldEditException If it fails
*/
public void paste(BlockArrayClipboard clipboard) throws WorldEditException {
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(clipboard.getRegion().getWorld(), -1);
try (EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(clipboard.getRegion().getWorld(), -1)) {

Operation operation = new ClipboardHolder(clipboard)
.createPaste(editSession)
.to(clipboard.getOrigin())
.ignoreAirBlocks(false)
.build();
Operation operation = new ClipboardHolder(clipboard)
.createPaste(editSession)
.to(clipboard.getOrigin())
.ignoreAirBlocks(false)
.build();

Operations.complete(operation);
Operations.complete(operation);
}
}

/**
@@ -255,11 +257,8 @@ public void paste(BlockArrayClipboard clipboard) throws WorldEditException {
* @param clipboard The clipboard
*/
public void clear(BlockArrayClipboard clipboard) {
try {
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(clipboard.getRegion().getWorld(), -1);
editSession.enableQueue();
try (EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(clipboard.getRegion().getWorld(), -1)) {
editSession.setBlocks(clipboard.getRegion(), BlockTypes.AIR.getDefaultState());
editSession.flushQueue();
} catch (MaxChangedBlocksException e) {
// is never thrown
}

0 comments on commit 3ef008a

Please sign in to comment.
You can’t perform that action at this time.