Have NullExtent extend FaweRegionExtent instead (more uses)

This commit is contained in:
Jesse Boyd 2016-05-02 13:19:25 +10:00
parent d7f121f8a9
commit c599e75fa6
3 changed files with 23 additions and 14 deletions

View File

@ -15,16 +15,18 @@ import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.biome.BaseBiome;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
public class NullExtent implements Extent {
public class NullExtent extends FaweRegionExtent {
private final BBC reason;
/**
* Create a new instance.
*
* @param extent the extent
*/
public NullExtent(BBC failReason) {
public NullExtent(Extent extent, BBC failReason) {
super(extent);
this.reason = failReason;
}
@ -48,12 +50,6 @@ public class NullExtent implements Extent {
throw new FaweException(reason);
}
@Nullable
@Override
public Operation commit() {
return null;
}
@Override
public boolean setBlock(final Vector arg0, final BaseBlock arg1) throws WorldEditException {
throw new FaweException(reason);
@ -83,4 +79,17 @@ public class NullExtent implements Extent {
public Vector getMinimumPoint() {
return new Vector(0, 0, 0);
}
@Override
public boolean contains(int x, int y, int z) { return false; }
@Override
protected Operation commitBefore() {
return null;
}
@Override
public Extent getExtent() {
return this;
}
}

View File

@ -26,7 +26,7 @@ public class WEManager {
try {
final Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
field.setAccessible(true);
field.set(parent, new NullExtent(reason));
field.set(parent, new NullExtent((Extent) field.get(parent), reason));
} catch (final Exception e) {
e.printStackTrace();
}

View File

@ -225,7 +225,7 @@ public class EditSession implements Extent {
// Invalid world: return null extent
if (world == null) {
NullExtent extent = new NullExtent(BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS);
Extent extent = this.regionExtent = new NullExtent(world, BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS);
this.bypassReorderHistory = extent;
this.bypassHistory = extent;
this.bypassNone = extent;
@ -284,7 +284,7 @@ public class EditSession implements Extent {
mask = WEManager.IMP.getMask(fp);
if (mask.size() == 0) {
// No allowed area; return null extent
extent = new NullExtent(BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS);
extent = this.regionExtent = new NullExtent(world, BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS);
this.bypassReorderHistory = extent;
this.bypassHistory = extent;
this.bypassNone = extent;
@ -309,7 +309,7 @@ public class EditSession implements Extent {
BBC.WORLDEDIT_OOM_ADMIN.send(fp);
}
// Memory limit reached; return null extent
extent = new NullExtent(BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS);
extent = this.regionExtent = new NullExtent(world, BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS);
this.bypassReorderHistory = extent;
this.bypassHistory = extent;
this.bypassNone = extent;
@ -369,7 +369,7 @@ public class EditSession implements Extent {
try {
WEManager.IMP.cancelEdit(primaryExtent, BBC.WORLDEDIT_CANCEL_REASON_MANUAL);
} catch (Throwable ignore) {}
NullExtent nullExtent = new NullExtent(BBC.WORLDEDIT_CANCEL_REASON_MANUAL);
NullExtent nullExtent = new NullExtent(world, BBC.WORLDEDIT_CANCEL_REASON_MANUAL);
primaryExtent = nullExtent;
dequeue();
queue.clear();