Have regen respect protection

This commit is contained in:
Jesse Boyd 2016-04-14 19:22:13 +10:00
parent 9f57b89756
commit caa0e475ad
5 changed files with 59 additions and 14 deletions

View File

@ -11,14 +11,13 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BaseBiome;
import java.util.List;
public class FastWorldEditExtent extends AbstractDelegateExtent {
public class FastWorldEditExtent extends FaweExtent {
private final FaweQueue queue;
@ -131,11 +130,12 @@ public class FastWorldEditExtent extends AbstractDelegateExtent {
case 151:
case 178: {
if (block.hasNbtData()) {
final Vector loc = new Vector(location.x, location.y, location.z);
queue.addTask(x >> 4, z >> 4, new Runnable() {
@Override
public void run() {
try {
FastWorldEditExtent.super.setBlock(location, block);
FastWorldEditExtent.super.setBlock(loc, block);
} catch (WorldEditException e) {
e.printStackTrace();
}
@ -222,4 +222,8 @@ public class FastWorldEditExtent extends AbstractDelegateExtent {
}
}
@Override
public boolean contains(int x, int y, int z) {
return true;
}
}

View File

@ -0,0 +1,17 @@
package com.boydti.fawe.object.extent;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
public abstract class FaweExtent extends AbstractDelegateExtent {
/**
* Create a new instance.
*
* @param extent the extent
*/
protected FaweExtent(Extent extent) {
super(extent);
}
public abstract boolean contains(int x, int y, int z);
}

View File

@ -15,7 +15,6 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
@ -24,7 +23,7 @@ import com.sk89q.worldedit.world.biome.BaseBiome;
import java.util.HashSet;
import java.util.List;
public class ProcessedWEExtent extends AbstractDelegateExtent {
public class ProcessedWEExtent extends FaweExtent {
private final FaweQueue queue;
private final FaweLimit limit;
private Extent parent;
@ -160,11 +159,12 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
return false;
}
if (block.hasNbtData()) {
final Vector loc = new Vector(location.x, location.y, location.z);
queue.addTask(x >> 4, z >> 4, new Runnable() {
@Override
public void run() {
try {
ProcessedWEExtent.super.setBlock(location, block);
ProcessedWEExtent.super.setBlock(loc, block);
} catch (WorldEditException e) {
e.printStackTrace();
}
@ -299,4 +299,9 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
}
return false;
}
@Override
public boolean contains(int x, int y, int z) {
return WEManager.IMP.maskContains(this.mask, x, z);
}
}

View File

@ -3,6 +3,7 @@ package com.boydti.fawe.wrappers;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.object.changeset.FaweChangeSet;
import com.boydti.fawe.object.extent.FaweExtent;
import com.boydti.fawe.util.FaweQueue;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.worldedit.BlockVector2D;
@ -180,6 +181,7 @@ public class WorldWrapper extends AbstractWorld {
public boolean regenerate(final Region region, EditSession session) {
final FaweQueue queue = session.getQueue();
final FaweChangeSet fcs = (FaweChangeSet) session.getChangeSet();
final FaweExtent fe = session.getFaweExtent();
session.setChangeSet(fcs);
final CuboidRegion cb = (CuboidRegion) region;
final boolean cuboid = region instanceof CuboidRegion;
@ -193,7 +195,14 @@ public class WorldWrapper extends AbstractWorld {
int bz = cz << 4;
Vector cmin = new Vector(bx, 0, bz);
Vector cmax = cmin.add(15, getMaxY(), 15);
if (cuboid && region.contains(cmin) && region.contains(cmax)) {
boolean containsBot1 = (fe != null && fe.contains(cmin.getBlockX(), cmin.getBlockY(), cmin.getBlockZ()));
boolean containsBot2 = region.contains(cmin);
boolean containsTop1 = (fe != null && fe.contains(cmax.getBlockX(), cmax.getBlockY(), cmax.getBlockZ()));
boolean containsTop2 = region.contains(cmax);
if (fe == null || (containsBot2 && containsTop2 && !containsBot1 && !containsTop1)) {
return;
}
if (cuboid && containsBot1 && containsBot2 && containsTop1 && containsTop2) {
if (fcs != null) {
for (int x = 0; x < 16; x++) {
int xx = x + bx;
@ -224,13 +233,13 @@ public class WorldWrapper extends AbstractWorld {
for (int y = 0; y < getMaxY() + 1; y++) {
final Vector loc = new Vector(xx, y, zz);
int from = queue.getCombinedId4Data(xx, y, zz);
if (region.contains(loc)) {
boolean contains = (fe != null && fe.contains(xx, y, zz)) && region.contains(loc);
if (contains) {
if (fcs != null) {
if (!FaweCache.hasNBT(from >> 4)) {
fcs.add(xx, y, zz, from, 0);
} else {
try {
BaseBlock block = getLazyBlock(loc);
fcs.add(loc, block, FaweCache.CACHE_BLOCK[0]);
} catch (Throwable e) {
@ -245,18 +254,20 @@ public class WorldWrapper extends AbstractWorld {
queue.setBlock(xx, y, zz, id, data);
} else {
try {
final BaseBlock block = getLazyBlock(loc);
final BaseBlock block = getBlock(loc);
final Vector v = new Vector(loc.x, loc.y, loc.z);
queue.addTask(cx, cz, new Runnable() {
@Override
public void run() {
try {
setBlock(loc, block, false);
setBlock(v, block, false);
} catch (WorldEditException e) {
e.printStackTrace();
}
}
});
} catch (Throwable e) {
e.printStackTrace();
queue.setBlock(xx, y, zz, id, data);
}
}

View File

@ -33,6 +33,7 @@ import com.boydti.fawe.object.changeset.DiskStorageHistory;
import com.boydti.fawe.object.changeset.FaweChangeSet;
import com.boydti.fawe.object.changeset.MemoryOptimizedHistory;
import com.boydti.fawe.object.extent.FastWorldEditExtent;
import com.boydti.fawe.object.extent.FaweExtent;
import com.boydti.fawe.object.extent.NullExtent;
import com.boydti.fawe.object.extent.ProcessedWEExtent;
import com.boydti.fawe.object.extent.SafeExtentWrapper;
@ -160,6 +161,7 @@ public class EditSession implements Extent {
private World world;
private FaweChangeSet changeSet;
private final EditSessionWrapper wrapper;
private FaweExtent faweExtent;
private MaskingExtent maskingExtent;
private final Extent bypassReorderHistory;
private final Extent bypassHistory;
@ -214,6 +216,7 @@ public class EditSession implements Extent {
checkNotNull(eventBus);
checkArgument(maxBlocks >= -1, "maxBlocks >= -1 required");
checkNotNull(event);
// Wrap world
this.blockBag = blockBag;
this.maxBlocks = maxBlocks;
@ -228,12 +231,13 @@ public class EditSession implements Extent {
return;
}
final Actor actor = event.getActor();
this.queue = SetQueue.IMP.getNewQueue(world.getName());
this.world = (world = new WorldWrapper((AbstractWorld) world));
this.wrapper = Fawe.imp().getEditSessionWrapper(this);
// Not a player; bypass history
if ((actor == null) || !actor.isPlayer()) {
Extent extent = new FastWorldEditExtent(world, queue);
Extent extent = (this.faweExtent = new FastWorldEditExtent(world, queue));
// Everything bypasses
extent = this.wrapExtent(extent, eventBus, event, Stage.BEFORE_CHANGE);
extent = this.wrapExtent(extent, eventBus, event, Stage.BEFORE_REORDER);
@ -252,7 +256,7 @@ public class EditSession implements Extent {
this.fastmode = session.hasFastMode();
if (fp.hasWorldEditBypass()) {
// Bypass skips processing and area restrictions
extent = new FastWorldEditExtent(world, queue);
extent = (this.faweExtent = new FastWorldEditExtent(world, queue));
if (this.hasFastMode()) {
// Fastmode skips history and memory checks
extent = this.wrapExtent(extent, eventBus, event, Stage.BEFORE_CHANGE);
@ -280,7 +284,7 @@ public class EditSession implements Extent {
return;
}
// Process the WorldEdit action
ProcessedWEExtent processed = new ProcessedWEExtent(world, fp, mask, limit, queue);
ProcessedWEExtent processed = (ProcessedWEExtent) (this.faweExtent = new ProcessedWEExtent(world, fp, mask, limit, queue));
extent = processed;
if (this.hasFastMode()) {
// Fastmode skips history, masking, and memory checks
@ -449,6 +453,10 @@ public class EditSession implements Extent {
}
}
public FaweExtent getFaweExtent() {
return this.faweExtent;
}
/**
* Set the mask.
*