Fixes #253 + other stuff

Fixes clipboard on disk
Fixed hybrid MCAQueue hybrid get (tile/block/refresh)
Fixed no NMS queue messages
This commit is contained in:
Jesse Boyd 2016-08-22 22:18:59 +10:00
parent f538fc5898
commit 814ac60823
10 changed files with 130 additions and 67 deletions

View File

@ -33,7 +33,7 @@ ext {
version = date + revision + buildNumber
if ( project.hasProperty("lzNoVersion") ) { // gradle build -PlzNoVersion
version = "";
version = "unknown";
}
description = """FastAsyncWorldEdit"""

View File

@ -25,6 +25,6 @@ permissions:
fawe.bypass:
default: false
fawe.admin:
default: false
default: op
fawe.reload:
default: false

View File

@ -25,6 +25,6 @@ permissions:
fawe.bypass:
default: false
fawe.admin:
default: false
default: op
fawe.reload:
default: false

View File

@ -25,6 +25,6 @@ permissions:
fawe.bypass:
default: false
fawe.admin:
default: false
default: op
fawe.reload:
default: false

View File

@ -28,8 +28,6 @@ permissions:
fawe.bypass:
default: false
fawe.admin:
default: false
fawe.fixlighting:
default: false
default: op
fawe.reload:
default: false

View File

@ -2,7 +2,6 @@ package com.boydti.fawe.jnbt.anvil;
import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.example.NMSMappedFaweQueue;
import com.boydti.fawe.example.NullFaweChunk;
import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.RunnableVal;
@ -132,14 +131,18 @@ public class MCAQueue extends NMSMappedFaweQueue<FaweQueue, FaweChunk, FaweChunk
@Override
public void refreshChunk(FaweChunk fs) {
if (parent != null && !(fs instanceof MCAChunk) && !(fs instanceof NullFaweChunk) && parent instanceof NMSMappedFaweQueue) {
((NMSMappedFaweQueue) parent).refreshChunk(fs);
if (fs.getClass() != MCAChunk.class) {
parentNMS.refreshChunk(fs);
}
}
@Override
public CompoundTag getTileEntity(FaweChunk sections, int x, int y, int z) {
if (sections.getClass() == MCAChunk.class) {
return sections.getTile(x, y, z);
} else {
return parentNMS.getTileEntity(x, y, z);
}
}
@Override
@ -187,7 +190,11 @@ public class MCAQueue extends NMSMappedFaweQueue<FaweQueue, FaweChunk, FaweChunk
@Override
public int getCombinedId4Data(FaweChunk sections, int x, int y, int z) {
if (sections.getClass() == MCAChunk.class) {
return sections.getBlockCombinedId(x, y, z);
} else {
return parentNMS.getCombinedId4Data(x, y, z);
}
}
@Override

View File

@ -3,11 +3,10 @@ package com.boydti.fawe.object.clipboard;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.io.BufferedRandomAccessFile;
import com.boydti.fawe.object.IntegerTrio;
import com.boydti.fawe.object.RunnableVal2;
import com.boydti.fawe.object.io.BufferedRandomAccessFile;
import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.EditSession;
@ -21,6 +20,7 @@ import com.sk89q.worldedit.regions.CuboidRegion;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.HashMap;
@ -68,7 +68,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
raf.setLength(file.length());
long size = (raf.length() - HEADER_SIZE) >> 1;
raf.seek(2);
last = -1;
last = Integer.MIN_VALUE;
width = (int) raf.readChar();
height = (int) raf.readChar();
length = (int) raf.readChar();
@ -93,7 +93,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
open();
}
raf.seek(8);
last = -1;
last = Integer.MIN_VALUE;
int ox = raf.readShort();
int oy = raf.readShort();
int oz = raf.readShort();
@ -119,8 +119,12 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
try {
if (!file.exists()) {
file.getParentFile().mkdirs();
}
file.createNewFile();
} else {
PrintWriter writer = new PrintWriter(file);
writer.print("");
writer.close();
}
} catch (Exception e) {
MainUtil.handleError(e);
}
@ -133,7 +137,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
open();
}
raf.seek(8);
last = -1;
last = Integer.MIN_VALUE;
raf.writeShort(offset.getBlockX());
raf.writeShort(offset.getBlockY());
raf.writeShort(offset.getBlockZ());
@ -154,7 +158,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
long size = width * height * length * 2l + HEADER_SIZE;
raf.setLength(size);
raf.seek(2);
last = -1;
last = Integer.MIN_VALUE;
raf.writeChar(width);
raf.writeChar(height);
raf.writeChar(length);
@ -181,6 +185,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
public void close() {
try {
raf.flush();
RandomAccessFile tmp = raf;
raf = null;
tmp.close();
@ -202,7 +207,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
raf.setLength(size);
// write length etc
raf.seek(2);
last = -1;
last = Integer.MIN_VALUE;
raf.writeChar(width);
raf.writeChar(height);
raf.writeChar(length);
@ -211,18 +216,18 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
}
private void autoCloseTask() {
TaskManager.IMP.laterAsync(new Runnable() {
@Override
public void run() {
if (raf != null && System.currentTimeMillis() - lastAccessed > 10000) {
close();
} else if (raf == null) {
return;
} else {
TaskManager.IMP.laterAsync(this, 200);
}
}
}, 200);
// TaskManager.IMP.laterAsync(new Runnable() {
// @Override
// public void run() {
// if (raf != null && System.currentTimeMillis() - lastAccessed > 10000) {
// close();
// } else if (raf == null) {
// return;
// } else {
// TaskManager.IMP.laterAsync(this, 200);
// }
// }
// }, 200);
}
private int ylast;
@ -344,9 +349,12 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
lastAccessed = System.currentTimeMillis();
}
last = i;
int combined = FaweCache.getData(raf.readChar()) + (id << 4);
raf.seekUnsafe(raf.getFilePointer() - 2);
raf.writeChar(combined);
// 00000000 00000000
// [ id ]data
int id1 = raf.readCurrent();
raf.write(id >> 4);
int id2 = raf.readCurrent();
raf.write(((id & 0xFF) << 4) + (id2 & 0xFF));
} catch (Exception e) {
MainUtil.handleError(e);
}
@ -379,9 +387,10 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
lastAccessed = System.currentTimeMillis();
}
last = i;
int combined = raf.readChar() + (add << 4);
raf.seekUnsafe(raf.getFilePointer() - 2);
raf.writeChar(combined);
// 00000000 00000000
// [ id ]data
raf.write((raf.readCurrent() & 0xFF) + (add >> 4));
raf.read1();
} catch (Exception e) {
MainUtil.handleError(e);
}
@ -398,9 +407,11 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
lastAccessed = System.currentTimeMillis();
}
last = i;
int combined = (FaweCache.getId(raf.readChar()) << 4) + data;
raf.seekUnsafe(raf.getFilePointer() - 2);
raf.writeChar(combined);
// 00000000 00000000
// [ id ]data
int id1 = raf.read1();
int id2 = raf.readCurrent();
raf.write((id2 & 0xF0) + data);
} catch (Exception e) {
MainUtil.handleError(e);
}

View File

@ -244,30 +244,30 @@ public class BufferedRandomAccessFile extends RandomAccessFile
this.curr_ = pos;
}
/*
* Seek and do not flush if within the current buffer when going backwards
* - Assumes no writes were made
* @param pos
* @throws IOException
*/
public void seekUnsafe(long pos) throws IOException
{
if (pos >= this.hi_ || pos < this.lo_)
{
// seeking outside of current buffer -- flush and read
this.flushBuffer();
this.lo_ = pos & BuffMask_; // start at BuffSz boundary
this.maxHi_ = this.lo_ + (long) this.buff_.length;
if (this.diskPos_ != this.lo_)
{
super.seek(this.lo_);
this.diskPos_ = this.lo_;
}
int n = this.fillBuffer();
this.hi_ = this.lo_ + (long) n;
}
this.curr_ = pos;
}
// /*
// * Seek and do not flush if within the current buffer when going backwards
// * - Assumes no writes were made
// * @param pos
// * @throws IOException
// */
// public void seekUnsafe(long pos) throws IOException
// {
// if (pos >= this.hi_ || pos < this.lo_)
// {
// // seeking outside of current buffer -- flush and read
// this.flushBuffer();
// this.lo_ = pos & BuffMask_; // start at BuffSz boundary
// this.maxHi_ = this.lo_ + (long) this.buff_.length;
// if (this.diskPos_ != this.lo_)
// {
// super.seek(this.lo_);
// this.diskPos_ = this.lo_;
// }
// int n = this.fillBuffer();
// this.hi_ = this.lo_ + (long) n;
// }
// this.curr_ = pos;
// }
public long getFilePointer()
{
@ -341,6 +341,46 @@ public class BufferedRandomAccessFile extends RandomAccessFile
return len;
}
public byte readCurrent() throws IOException {
if (this.curr_ >= this.hi_)
{
// test for EOF
// if (this.hi < this.maxHi) return -1;
if (this.hitEOF_)
return -1;
// slow path -- read another buffer
this.seek(this.curr_);
if (this.curr_ == this.hi_)
return -1;
}
byte res = this.buff_[(int) (this.curr_ - this.lo_)];
return res;
}
public void writeCurrent(byte b) throws IOException {
if (this.curr_ >= this.hi_)
{
if (this.hitEOF_ && this.hi_ < this.maxHi_)
{
// at EOF -- bump "hi"
this.hi_++;
}
else
{
// slow path -- write current buffer; read next one
this.seek(this.curr_);
if (this.curr_ == this.hi_)
{
// appending to EOF -- bump "hi"
this.hi_++;
}
}
}
this.buff_[(int) (this.curr_ - this.lo_)] = (byte) b;
this.dirty_ = true;
}
public void write(int b) throws IOException
{
if (this.curr_ >= this.hi_)

View File

@ -100,7 +100,7 @@ public class Schematic {
if (allowUndo) {
editSession = builder.build();
} else {
editSession = builder.changeSetNull().build();
editSession = builder.changeSetNull().fastmode(true).build();
}
Extent extent = clipboard;
if (transform != null) {

View File

@ -436,9 +436,16 @@ public class EditSession implements Extent {
}
}
if (Settings.EXTENT.DEBUG) {
Fawe.debug("&cPotentially inefficient WorldEdit extent: " + toReturn.getClass().getName());
Fawe.debug("&cPotentially unsafe extent blocked: " + toReturn.getClass().getName());
Fawe.debug("&8 - &7For area restrictions, it is recommended to use the FaweAPI");
Fawe.debug("&8 - &7For block logging, it is recommended to use use BlocksHub");
Fawe.debug("&8 - &7To allow this plugin add it to the FAWE `allowed-plugins` list");
Fawe.debug("&8 - &7To hide this message set `debug` to false in the config.yml");
if (toReturn.getClass().getName().contains("CoreProtect")) {
Fawe.debug("Note on CoreProtect: ");
Fawe.debug(" - If you disable CoreProtect's WorldEdit logger (CP config) it still tries to add it (CP bug?)");
Fawe.debug(" - Use BlocksHub and set `debug` false in the FAWE config");
}
}
}
return extent;