From e03cb44b16ab03abfa24d0224ed77de5e618ee38 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 10 May 2017 12:08:27 +1000 Subject: [PATCH] Fix disk clipboard initialization --- .../com/boydti/fawe/jnbt/NBTStreamer.java | 2 +- .../clipboard/DiskOptimizedClipboard.java | 104 ++++++++---------- .../extension/factory/DefaultBlockParser.java | 2 +- 3 files changed, 47 insertions(+), 61 deletions(-) diff --git a/core/src/main/java/com/boydti/fawe/jnbt/NBTStreamer.java b/core/src/main/java/com/boydti/fawe/jnbt/NBTStreamer.java index 7f1480d1..379947f9 100644 --- a/core/src/main/java/com/boydti/fawe/jnbt/NBTStreamer.java +++ b/core/src/main/java/com/boydti/fawe/jnbt/NBTStreamer.java @@ -68,7 +68,7 @@ public class NBTStreamer { public static abstract class ByteReader extends RunnableVal2 { @Override public void run(Integer index, Integer value) { - run(index, value); + run((int) index, (int) value); } public abstract void run(int index, int byteValue); diff --git a/core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java b/core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java index 335a2422..7fb563e1 100644 --- a/core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java +++ b/core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java @@ -61,7 +61,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable { private FileChannel fc; public DiskOptimizedClipboard(int width, int height, int length, UUID uuid) { - this(width, height, length, MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.CLIPBOARD + File.separator + uuid + ".bd")); + this(width, height, length, MainUtil.getFile(Fawe.get() != null ? Fawe.imp().getDirectory() : new File("."), Settings.IMP.PATHS.CLIPBOARD + File.separator + uuid + ".bd")); } public DiskOptimizedClipboard(File file) { @@ -144,13 +144,15 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable { long volume = (long) width * (long) height * (long) length * 2l + (long) HEADER_SIZE; braf.setLength(0); braf.setLength(volume); - init(); - // write length etc - mbb.position(2); - last = Integer.MIN_VALUE; - mbb.putChar((char) width); - mbb.putChar((char) height); - mbb.putChar((char) length); + if (width * height * length != 0) { + init(); + // write length etc + mbb.position(2); + last = Integer.MIN_VALUE; + mbb.putChar((char) width); + mbb.putChar((char) height); + mbb.putChar((char) length); + } } catch (IOException e) { throw new RuntimeException(e); } @@ -419,71 +421,55 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable { @Override public void setId(int i, int id) { - try { - int index; - if (i != last + 1) { - index = (HEADER_SIZE) + (i << 1); - } else { - index = mbb.position(); - } - last = i; - mbb.position(index + 1); - // 00000000 00000000 - // [ id ]data - byte id2 = mbb.get(); - mbb.position(index); - mbb.put((byte) (id >> 4)); - mbb.put((byte) (((id & 0xFF) << 4) + (id2 & 0xFF))); - } catch (Exception e) { - MainUtil.handleError(e); + int index; + if (i != last + 1) { + index = (HEADER_SIZE) + (i << 1); + } else { + index = mbb.position(); } + last = i; + mbb.position(index + 1); + // 00000000 00000000 + // [ id ]data + byte id2 = mbb.get(); + mbb.position(index); + mbb.put((byte) (id >> 4)); + mbb.put((byte) (((id & 0xFF) << 4) + (id2 & 0xFF))); } public void setCombined(int i, int combined) { - try { - if (i != last + 1) { - mbb.position((HEADER_SIZE) + (i << 1)); - } - last = i; - mbb.putChar((char) combined); - } catch (Exception e) { - MainUtil.handleError(e); + if (i != last + 1) { + mbb.position((HEADER_SIZE) + (i << 1)); } + last = i; + mbb.putChar((char) combined); } @Override public void setAdd(int i, int add) { - try { - last = i; - int index = (HEADER_SIZE) + (i << 1); - mbb.position(index); - // 00000000 00000000 - // [ id ]data - char combined = mbb.getChar(); - mbb.position(index); - mbb.putChar((char) ((combined & 0xFFFF) + (add << 12))); - } catch (Exception e) { - MainUtil.handleError(e); - } + last = i; + int index = (HEADER_SIZE) + (i << 1); + mbb.position(index); + // 00000000 00000000 + // [ id ]data + char combined = mbb.getChar(); + mbb.position(index); + mbb.putChar((char) ((combined & 0xFFFF) + (add << 12))); } @Override public void setData(int i, int data) { - try { - int index; - if (i != last + 1) { - index = (HEADER_SIZE) + (i << 1) + 1; - } else { - index = mbb.position() + 1; - } - mbb.position(index); - last = i; - byte id = mbb.get(); - mbb.position(index); - mbb.put((byte) ((id & 0xF0) + data)); - } catch (Exception e) { - MainUtil.handleError(e); + int index; + if (i != last + 1) { + index = (HEADER_SIZE) + (i << 1) + 1; + } else { + index = mbb.position() + 1; } + mbb.position(index); + last = i; + byte id = mbb.get(); + mbb.position(index); + mbb.put((byte) ((id & 0xF0) + data)); } @Override diff --git a/core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java b/core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java index e0b09f8a..c0713e46 100644 --- a/core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java +++ b/core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java @@ -230,8 +230,8 @@ public class DefaultBlockParser extends InputParser { if (typeAndData.length > 1 && !typeAndData[1].isEmpty()) { if (MathMan.isInteger(typeAndData[1])) { data = Integer.parseInt(typeAndData[1]); - } else { data = -1; // Some invalid value + } else { BundledBlockData.BlockEntry block = BundledBlockData.getInstance().findById(blockId); if (block != null && block.states != null) { loop: