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.blocks.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.biome.BaseBiome;
import java.util.List; import java.util.List;
public class FastWorldEditExtent extends AbstractDelegateExtent { public class FastWorldEditExtent extends FaweExtent {
private final FaweQueue queue; private final FaweQueue queue;
@ -131,11 +130,12 @@ public class FastWorldEditExtent extends AbstractDelegateExtent {
case 151: case 151:
case 178: { case 178: {
if (block.hasNbtData()) { if (block.hasNbtData()) {
final Vector loc = new Vector(location.x, location.y, location.z);
queue.addTask(x >> 4, z >> 4, new Runnable() { queue.addTask(x >> 4, z >> 4, new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
FastWorldEditExtent.super.setBlock(location, block); FastWorldEditExtent.super.setBlock(loc, block);
} catch (WorldEditException e) { } catch (WorldEditException e) {
e.printStackTrace(); 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.blocks.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.Location;
@ -24,7 +23,7 @@ import com.sk89q.worldedit.world.biome.BaseBiome;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
public class ProcessedWEExtent extends AbstractDelegateExtent { public class ProcessedWEExtent extends FaweExtent {
private final FaweQueue queue; private final FaweQueue queue;
private final FaweLimit limit; private final FaweLimit limit;
private Extent parent; private Extent parent;
@ -160,11 +159,12 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
return false; return false;
} }
if (block.hasNbtData()) { if (block.hasNbtData()) {
final Vector loc = new Vector(location.x, location.y, location.z);
queue.addTask(x >> 4, z >> 4, new Runnable() { queue.addTask(x >> 4, z >> 4, new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
ProcessedWEExtent.super.setBlock(location, block); ProcessedWEExtent.super.setBlock(loc, block);
} catch (WorldEditException e) { } catch (WorldEditException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -299,4 +299,9 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
} }
return false; 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.FaweCache;
import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.object.changeset.FaweChangeSet; 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.FaweQueue;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
import com.sk89q.worldedit.BlockVector2D; import com.sk89q.worldedit.BlockVector2D;
@ -180,6 +181,7 @@ public class WorldWrapper extends AbstractWorld {
public boolean regenerate(final Region region, EditSession session) { public boolean regenerate(final Region region, EditSession session) {
final FaweQueue queue = session.getQueue(); final FaweQueue queue = session.getQueue();
final FaweChangeSet fcs = (FaweChangeSet) session.getChangeSet(); final FaweChangeSet fcs = (FaweChangeSet) session.getChangeSet();
final FaweExtent fe = session.getFaweExtent();
session.setChangeSet(fcs); session.setChangeSet(fcs);
final CuboidRegion cb = (CuboidRegion) region; final CuboidRegion cb = (CuboidRegion) region;
final boolean cuboid = region instanceof CuboidRegion; final boolean cuboid = region instanceof CuboidRegion;
@ -193,7 +195,14 @@ public class WorldWrapper extends AbstractWorld {
int bz = cz << 4; int bz = cz << 4;
Vector cmin = new Vector(bx, 0, bz); Vector cmin = new Vector(bx, 0, bz);
Vector cmax = cmin.add(15, getMaxY(), 15); 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) { if (fcs != null) {
for (int x = 0; x < 16; x++) { for (int x = 0; x < 16; x++) {
int xx = x + bx; int xx = x + bx;
@ -224,13 +233,13 @@ public class WorldWrapper extends AbstractWorld {
for (int y = 0; y < getMaxY() + 1; y++) { for (int y = 0; y < getMaxY() + 1; y++) {
final Vector loc = new Vector(xx, y, zz); final Vector loc = new Vector(xx, y, zz);
int from = queue.getCombinedId4Data(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 (fcs != null) {
if (!FaweCache.hasNBT(from >> 4)) { if (!FaweCache.hasNBT(from >> 4)) {
fcs.add(xx, y, zz, from, 0); fcs.add(xx, y, zz, from, 0);
} else { } else {
try { try {
BaseBlock block = getLazyBlock(loc); BaseBlock block = getLazyBlock(loc);
fcs.add(loc, block, FaweCache.CACHE_BLOCK[0]); fcs.add(loc, block, FaweCache.CACHE_BLOCK[0]);
} catch (Throwable e) { } catch (Throwable e) {
@ -245,18 +254,20 @@ public class WorldWrapper extends AbstractWorld {
queue.setBlock(xx, y, zz, id, data); queue.setBlock(xx, y, zz, id, data);
} else { } else {
try { 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() { queue.addTask(cx, cz, new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
setBlock(loc, block, false); setBlock(v, block, false);
} catch (WorldEditException e) { } catch (WorldEditException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
}); });
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace();
queue.setBlock(xx, y, zz, id, data); 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.FaweChangeSet;
import com.boydti.fawe.object.changeset.MemoryOptimizedHistory; import com.boydti.fawe.object.changeset.MemoryOptimizedHistory;
import com.boydti.fawe.object.extent.FastWorldEditExtent; 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.NullExtent;
import com.boydti.fawe.object.extent.ProcessedWEExtent; import com.boydti.fawe.object.extent.ProcessedWEExtent;
import com.boydti.fawe.object.extent.SafeExtentWrapper; import com.boydti.fawe.object.extent.SafeExtentWrapper;
@ -160,6 +161,7 @@ public class EditSession implements Extent {
private World world; private World world;
private FaweChangeSet changeSet; private FaweChangeSet changeSet;
private final EditSessionWrapper wrapper; private final EditSessionWrapper wrapper;
private FaweExtent faweExtent;
private MaskingExtent maskingExtent; private MaskingExtent maskingExtent;
private final Extent bypassReorderHistory; private final Extent bypassReorderHistory;
private final Extent bypassHistory; private final Extent bypassHistory;
@ -214,6 +216,7 @@ public class EditSession implements Extent {
checkNotNull(eventBus); checkNotNull(eventBus);
checkArgument(maxBlocks >= -1, "maxBlocks >= -1 required"); checkArgument(maxBlocks >= -1, "maxBlocks >= -1 required");
checkNotNull(event); checkNotNull(event);
// Wrap world // Wrap world
this.blockBag = blockBag; this.blockBag = blockBag;
this.maxBlocks = maxBlocks; this.maxBlocks = maxBlocks;
@ -228,12 +231,13 @@ public class EditSession implements Extent {
return; return;
} }
final Actor actor = event.getActor(); final Actor actor = event.getActor();
this.queue = SetQueue.IMP.getNewQueue(world.getName()); this.queue = SetQueue.IMP.getNewQueue(world.getName());
this.world = (world = new WorldWrapper((AbstractWorld) world)); this.world = (world = new WorldWrapper((AbstractWorld) world));
this.wrapper = Fawe.imp().getEditSessionWrapper(this); this.wrapper = Fawe.imp().getEditSessionWrapper(this);
// Not a player; bypass history // Not a player; bypass history
if ((actor == null) || !actor.isPlayer()) { if ((actor == null) || !actor.isPlayer()) {
Extent extent = new FastWorldEditExtent(world, queue); Extent extent = (this.faweExtent = new FastWorldEditExtent(world, queue));
// Everything bypasses // Everything bypasses
extent = this.wrapExtent(extent, eventBus, event, Stage.BEFORE_CHANGE); extent = this.wrapExtent(extent, eventBus, event, Stage.BEFORE_CHANGE);
extent = this.wrapExtent(extent, eventBus, event, Stage.BEFORE_REORDER); extent = this.wrapExtent(extent, eventBus, event, Stage.BEFORE_REORDER);
@ -252,7 +256,7 @@ public class EditSession implements Extent {
this.fastmode = session.hasFastMode(); this.fastmode = session.hasFastMode();
if (fp.hasWorldEditBypass()) { if (fp.hasWorldEditBypass()) {
// Bypass skips processing and area restrictions // Bypass skips processing and area restrictions
extent = new FastWorldEditExtent(world, queue); extent = (this.faweExtent = new FastWorldEditExtent(world, queue));
if (this.hasFastMode()) { if (this.hasFastMode()) {
// Fastmode skips history and memory checks // Fastmode skips history and memory checks
extent = this.wrapExtent(extent, eventBus, event, Stage.BEFORE_CHANGE); extent = this.wrapExtent(extent, eventBus, event, Stage.BEFORE_CHANGE);
@ -280,7 +284,7 @@ public class EditSession implements Extent {
return; return;
} }
// Process the WorldEdit action // 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; extent = processed;
if (this.hasFastMode()) { if (this.hasFastMode()) {
// Fastmode skips history, masking, and memory checks // 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. * Set the mask.
* *