Queue optimizations + WorldGuard global region

This commit is contained in:
Jesse Boyd 2016-04-21 07:53:06 +10:00
parent 9f289f8fac
commit e5590ed12f
12 changed files with 160 additions and 185 deletions

View File

@ -10,7 +10,7 @@ buildscript {
} }
group = 'com.boydti.fawe' group = 'com.boydti.fawe'
version = '3.3.17' version = '3.3.18'
description = """FastAsyncWorldEdit""" description = """FastAsyncWorldEdit"""
subprojects { subprojects {

View File

@ -1,6 +1,6 @@
name: FastAsyncWorldEdit name: FastAsyncWorldEdit
main: com.boydti.fawe.bukkit.FaweBukkit main: com.boydti.fawe.bukkit.FaweBukkit
version: 3.3.17 version: 3.3.18
description: Fast Async WorldEdit plugin description: Fast Async WorldEdit plugin
authors: [Empire92] authors: [Empire92]
loadbefore: [WorldEdit] loadbefore: [WorldEdit]

View File

@ -2,7 +2,7 @@ package com.boydti.fawe.bukkit.regions;
import com.boydti.fawe.bukkit.FaweBukkit; import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FawePlayer;
import com.sk89q.worldedit.BlockVector; import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.managers.RegionManager;
@ -35,46 +35,40 @@ public class Worldguard extends BukkitMaskManager implements Listener {
} }
public ProtectedRegion isowner(final Player player, final Location location) { public ProtectedRegion getRegion(final Player player, final Location loc) {
final com.sk89q.worldguard.LocalPlayer localplayer = this.worldguard.wrapPlayer(player); final com.sk89q.worldguard.LocalPlayer localplayer = this.worldguard.wrapPlayer(player);
final RegionManager manager = this.worldguard.getRegionManager(player.getWorld()); RegionManager manager = this.worldguard.getRegionManager(player.getWorld());
final ProtectedRegion global = manager.getRegion("__global__");
if (isAllowed(localplayer, global)) {
return global;
}
final ApplicableRegionSet regions = manager.getApplicableRegions(player.getLocation()); final ApplicableRegionSet regions = manager.getApplicableRegions(player.getLocation());
for (final ProtectedRegion region : regions) { for (final ProtectedRegion region : regions) {
if (region.isOwner(localplayer)) { if (isAllowed(localplayer, region)) {
return region;
} else if (region.getId().toLowerCase().equals(player.getName().toLowerCase())) {
return region;
} else if (region.getId().toLowerCase().contains(player.getName().toLowerCase() + "//")) {
return region;
} else if (region.isOwner("*")) {
return region; return region;
} }
} }
return null; return null;
} }
public ProtectedRegion getregion(final Player player, final BlockVector location) { public boolean isAllowed(LocalPlayer localplayer, ProtectedRegion region) {
final com.sk89q.worldguard.LocalPlayer localplayer = this.worldguard.wrapPlayer(player); if (region.isOwner(localplayer)) {
final ApplicableRegionSet regions = this.worldguard.getRegionManager(player.getWorld()).getApplicableRegions(location); return true;
for (final ProtectedRegion region : regions) { } else if (region.getId().toLowerCase().equals(localplayer.getName().toLowerCase())) {
if (region.isOwner(localplayer)) { return true;
return region; } else if (region.getId().toLowerCase().contains(localplayer.getName().toLowerCase() + "//")) {
} else if (region.getId().toLowerCase().equals(player.getName().toLowerCase())) { return true;
return region; } else if (region.isOwner("*")) {
} else if (region.getId().toLowerCase().contains(player.getName().toLowerCase() + "//")) { return true;
return region;
} else if (region.isOwner("*")) {
return region;
}
} }
return null; return false;
} }
@Override @Override
public BukkitMask getMask(final FawePlayer<Player> fp) { public BukkitMask getMask(final FawePlayer<Player> fp) {
final Player player = fp.parent; final Player player = fp.parent;
final Location location = player.getLocation(); final Location location = player.getLocation();
final ProtectedRegion myregion = this.isowner(player, location); final ProtectedRegion myregion = this.getRegion(player, location);
if (myregion != null) { if (myregion != null) {
final Location pos1 = new Location(location.getWorld(), myregion.getMinimumPoint().getBlockX(), myregion.getMinimumPoint().getBlockY(), myregion.getMinimumPoint().getBlockZ()); final Location pos1 = new Location(location.getWorld(), myregion.getMinimumPoint().getBlockX(), myregion.getMinimumPoint().getBlockY(), myregion.getMinimumPoint().getBlockZ());
final Location pos2 = new Location(location.getWorld(), myregion.getMaximumPoint().getBlockX(), myregion.getMaximumPoint().getBlockY(), myregion.getMaximumPoint().getBlockZ()); final Location pos2 = new Location(location.getWorld(), myregion.getMaximumPoint().getBlockX(), myregion.getMaximumPoint().getBlockY(), myregion.getMaximumPoint().getBlockZ());

View File

@ -5,7 +5,6 @@ import com.boydti.fawe.object.FaweChunk;
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.world.biome.BaseBiome; import com.sk89q.worldedit.world.biome.BaseBiome;
import java.util.ArrayDeque;
import java.util.Collection; import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.LinkedBlockingDeque;
@ -78,25 +77,35 @@ public abstract class BukkitQueue_0 extends FaweQueue implements Listener {
result.addTask(runnable); result.addTask(runnable);
} }
private FaweChunk lastChunk;
private int lastX = Integer.MIN_VALUE;
private int lastZ = Integer.MIN_VALUE;
@Override @Override
public boolean setBlock(int x, int y, int z, short id, byte data) { public boolean setBlock(int x, int y, int z, short id, byte data) {
if ((y > 255) || (y < 0)) { if ((y > 255) || (y < 0)) {
return false; return false;
} }
long pair = (long) (x >> 4) << 32 | (z >> 4) & 0xFFFFFFFFL; int cx = x >> 4;
FaweChunk<Chunk> result = this.blocks.get(pair); int cz = z >> 4;
if (result == null) { if (cx != lastX || cz != lastZ) {
result = this.getChunk(x >> 4, z >> 4); lastX = cx;
result.setBlock(x & 15, y, z & 15, id, data); lastZ = cz;
FaweChunk<Chunk> previous = this.blocks.put(pair, result); long pair = (long) (cx) << 32 | (cz) & 0xFFFFFFFFL;
if (previous == null) { lastChunk = this.blocks.get(pair);
chunks.add(result); if (lastChunk == null) {
return true; lastChunk = this.getChunk(x >> 4, z >> 4);
lastChunk.setBlock(x & 15, y, z & 15, id, data);
FaweChunk<Chunk> previous = this.blocks.put(pair, lastChunk);
if (previous == null) {
chunks.add(lastChunk);
return true;
}
this.blocks.put(pair, previous);
lastChunk = previous;
} }
this.blocks.put(pair, previous);
result = previous;
} }
result.setBlock(x & 15, y, z & 15, id, data); lastChunk.setBlock(x & 15, y, z & 15, id, data);
return true; return true;
} }
@ -120,6 +129,8 @@ public abstract class BukkitQueue_0 extends FaweQueue implements Listener {
@Override @Override
public FaweChunk<Chunk> next() { public FaweChunk<Chunk> next() {
lastX = Integer.MIN_VALUE;
lastZ = Integer.MIN_VALUE;
try { try {
if (this.blocks.size() == 0) { if (this.blocks.size() == 0) {
return null; return null;

View File

@ -1,6 +1,6 @@
name: FastAsyncWorldEdit name: FastAsyncWorldEdit
main: com.boydti.fawe.bukkit.FaweBukkit main: com.boydti.fawe.bukkit.FaweBukkit
version: 3.3.17 version: 3.3.18
description: Fast Async WorldEdit plugin description: Fast Async WorldEdit plugin
authors: [Empire92] authors: [Empire92]
loadbefore: [WorldEdit] loadbefore: [WorldEdit]

View File

@ -49,7 +49,7 @@ public enum BBC {
WORLDEDIT_CANCEL_REASON_MAX_ENTITIES("Too many entities", "Cancel"), WORLDEDIT_CANCEL_REASON_MAX_ENTITIES("Too many entities", "Cancel"),
WORLDEDIT_CANCEL_REASON_MAX_ITERATIONS("Max iterations", "Cancel"), WORLDEDIT_CANCEL_REASON_MAX_ITERATIONS("Max iterations", "Cancel"),
WORLDEDIT_CANCEL_REASON_MAX_FAILS("Outside allowed region", "Cancel"), WORLDEDIT_CANCEL_REASON_MAX_FAILS("Outside allowed region", "Cancel"),
WORLDEDIT_FAILED_LOAD_CHUNK("&cFailed to load chunk: &7%s0;%s1&c. Try increasing chunk-wait.", "Cancel"), WORLDEDIT_FAILED_LOAD_CHUNK("&cSkipped loading chunk: &7%s0;%s1&c. Try increasing chunk-wait.", "Cancel"),
WORLDEDIT_OOM_ADMIN("&cPossible options:\n&8 - &7//fast\n&8 - &7Do smaller edits\n&8 - &7Allocate more memory\n&8 - &7Disable this safeguard", "Info"), WORLDEDIT_OOM_ADMIN("&cPossible options:\n&8 - &7//fast\n&8 - &7Do smaller edits\n&8 - &7Allocate more memory\n&8 - &7Disable this safeguard", "Info"),
NOT_PLAYER("&cYou must be a player to perform this action!", "Error"), NOT_PLAYER("&cYou must be a player to perform this action!", "Error"),

View File

@ -1,6 +1,7 @@
package com.boydti.fawe.object.extent; package com.boydti.fawe.object.extent;
import com.sk89q.worldedit.EditSession; import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.exception.FaweException;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
@ -19,17 +20,17 @@ public class NullExtent implements Extent {
@Override @Override
public BaseBiome getBiome(final Vector2D arg0) { public BaseBiome getBiome(final Vector2D arg0) {
return EditSession.nullBiome; throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS);
} }
@Override @Override
public BaseBlock getBlock(final Vector arg0) { public BaseBlock getBlock(final Vector arg0) {
return EditSession.nullBlock; throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS);
} }
@Override @Override
public BaseBlock getLazyBlock(final Vector arg0) { public BaseBlock getLazyBlock(final Vector arg0) {
return EditSession.nullBlock; throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS);
} }
@Override @Override
@ -39,17 +40,17 @@ public class NullExtent implements Extent {
@Override @Override
public boolean setBiome(final Vector2D arg0, final BaseBiome arg1) { public boolean setBiome(final Vector2D arg0, final BaseBiome arg1) {
return false; throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS);
} }
@Override @Override
public boolean setBlock(final Vector arg0, final BaseBlock arg1) throws WorldEditException { public boolean setBlock(final Vector arg0, final BaseBlock arg1) throws WorldEditException {
return false; throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS);
} }
@Override @Override
public Entity createEntity(final Location arg0, final BaseEntity arg1) { public Entity createEntity(final Location arg0, final BaseEntity arg1) {
return null; throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS);
} }
@Override @Override

View File

@ -123,6 +123,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -388,7 +389,7 @@ public class EditSession implements Extent {
} }
public void setChangeSet(FaweChangeSet set) { public void setChangeSet(FaweChangeSet set) {
changes = -1; changes++;
this.changeSet = set; this.changeSet = set;
} }
@ -562,7 +563,7 @@ public class EditSession implements Extent {
@Override @Override
public boolean setBiome(final Vector2D position, final BaseBiome biome) { public boolean setBiome(final Vector2D position, final BaseBiome biome) {
this.changes = -1; this.changes++;
return this.bypassNone.setBiome(position, biome); return this.bypassNone.setBiome(position, biome);
} }
@ -672,7 +673,7 @@ public class EditSession implements Extent {
* @throws WorldEditException thrown on a set error * @throws WorldEditException thrown on a set error
*/ */
public boolean setBlock(final Vector position, final BaseBlock block, final Stage stage) throws WorldEditException { public boolean setBlock(final Vector position, final BaseBlock block, final Stage stage) throws WorldEditException {
this.changes = -1; this.changes++;
switch (stage) { switch (stage) {
case BEFORE_HISTORY: case BEFORE_HISTORY:
return this.bypassNone.setBlock(position, block); return this.bypassNone.setBlock(position, block);
@ -750,11 +751,10 @@ public class EditSession implements Extent {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private int setBlocks(final Set<Vector> vset, final Pattern pattern) throws MaxChangedBlocksException { private int setBlocks(final Set<Vector> vset, final Pattern pattern) throws MaxChangedBlocksException {
int affected = 0;
for (final Vector v : vset) { for (final Vector v : vset) {
affected += this.setBlock(v, pattern) ? 1 : 0; changes += this.setBlock(v, pattern) ? 1 : 0;
} }
return affected; return changes;
} }
/** /**
@ -988,7 +988,7 @@ public class EditSession implements Extent {
EditSession.this.flushQueue(); EditSession.this.flushQueue();
} }
}, true); }, true);
return this.changes = -1; return this.changes = visitor.getAffected();
} }
/** /**
@ -1065,7 +1065,19 @@ public class EditSession implements Extent {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public int setBlocks(final Region region, final BaseBlock block) throws MaxChangedBlocksException { public int setBlocks(final Region region, final BaseBlock block) throws MaxChangedBlocksException {
return this.setBlocks(region, new SingleBlockPattern(block)); checkNotNull(region);
checkNotNull(block);
Iterator<BlockVector> iter = region.iterator();
try {
while (iter.hasNext()) {
this.bypassNone.setBlock(iter.next(), block);
}
} catch (final MaxChangedBlocksException e) {
throw e;
} catch (final WorldEditException e) {
throw new RuntimeException("Unexpected exception", e);
}
return changes;
} }
/** /**
@ -1088,7 +1100,7 @@ public class EditSession implements Extent {
EditSession.this.flushQueue(); EditSession.this.flushQueue();
} }
}, true); }, true);
return this.changes = -1; return this.changes = visitor.getAffected();
} }
/** /**
@ -1146,7 +1158,7 @@ public class EditSession implements Extent {
EditSession.this.flushQueue(); EditSession.this.flushQueue();
} }
}, true); }, true);
return this.changes = -1; return this.changes = visitor.getAffected();
} }
/** /**
@ -1330,7 +1342,7 @@ public class EditSession implements Extent {
EditSession.this.flushQueue(); EditSession.this.flushQueue();
} }
}, true); }, true);
return this.changes = -1; return this.changes = ground.getAffected();
} }
/** /**
@ -1352,7 +1364,7 @@ public class EditSession implements Extent {
EditSession.this.flushQueue(); EditSession.this.flushQueue();
} }
}, true); }, true);
return this.changes = -1; return this.changes = naturalizer.getAffected();
} }
/** /**
@ -1383,7 +1395,7 @@ public class EditSession implements Extent {
EditSession.this.flushQueue(); EditSession.this.flushQueue();
} }
}, true); }, true);
return this.changes = -1; return this.changes = copy.getAffected();
} }
/** /**
@ -1428,7 +1440,7 @@ public class EditSession implements Extent {
EditSession.this.flushQueue(); EditSession.this.flushQueue();
} }
}, true); }, true);
return this.changes = -1; return this.changes = visitor.getAffected();
} }
/** /**
@ -1476,7 +1488,7 @@ public class EditSession implements Extent {
EditSession.this.flushQueue(); EditSession.this.flushQueue();
} }
}, true); }, true);
return this.changes = -1; return this.changes = visitor.getAffected();
} }
/** /**
@ -1518,7 +1530,7 @@ public class EditSession implements Extent {
EditSession.this.flushQueue(); EditSession.this.flushQueue();
} }
}, true); }, true);
return this.changes = -1; return this.changes = visitor.getAffected();
} }
/** /**
@ -1549,13 +1561,11 @@ public class EditSession implements Extent {
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public int makeCylinder(Vector pos, final Pattern block, double radiusX, double radiusZ, int height, final boolean filled) throws MaxChangedBlocksException { public int makeCylinder(Vector pos, final Pattern block, double radiusX, double radiusZ, int height, final boolean filled) throws MaxChangedBlocksException {
int affected = 0;
radiusX += 0.5; radiusX += 0.5;
radiusZ += 0.5; radiusZ += 0.5;
if (height == 0) { if (height == 0) {
return this.changes = -1; return this.changes;
} else if (height < 0) { } else if (height < 0) {
height = -height; height = -height;
pos = pos.subtract(0, height, 0); pos = pos.subtract(0, height, 0);
@ -1597,23 +1607,15 @@ public class EditSession implements Extent {
} }
for (int y = 0; y < height; ++y) { for (int y = 0; y < height; ++y) {
if (this.setBlock(pos.add(x, y, z), block)) { this.setBlock(pos.add(x, y, z), block);
++affected; this.setBlock(pos.add(-x, y, z), block);
} this.setBlock(pos.add(x, y, -z), block);
if (this.setBlock(pos.add(-x, y, z), block)) { this.setBlock(pos.add(-x, y, -z), block);
++affected;
}
if (this.setBlock(pos.add(x, y, -z), block)) {
++affected;
}
if (this.setBlock(pos.add(-x, y, -z), block)) {
++affected;
}
} }
} }
} }
return affected; return this.changes;
} }
/** /**
@ -1643,8 +1645,6 @@ public class EditSession implements Extent {
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public int makeSphere(final Vector pos, final Pattern block, double radiusX, double radiusY, double radiusZ, final boolean filled) throws MaxChangedBlocksException { public int makeSphere(final Vector pos, final Pattern block, double radiusX, double radiusY, double radiusZ, final boolean filled) throws MaxChangedBlocksException {
int affected = 0;
radiusX += 0.5; radiusX += 0.5;
radiusY += 0.5; radiusY += 0.5;
radiusZ += 0.5; radiusZ += 0.5;
@ -1687,35 +1687,19 @@ public class EditSession implements Extent {
} }
} }
if (this.setBlock(pos.add(x, y, z), block)) { this.setBlock(pos.add(x, y, z), block);
++affected; this.setBlock(pos.add(-x, y, z), block);
} this.setBlock(pos.add(x, -y, z), block);
if (this.setBlock(pos.add(-x, y, z), block)) { this.setBlock(pos.add(x, y, -z), block);
++affected; this.setBlock(pos.add(-x, -y, z), block);
} this.setBlock(pos.add(x, -y, -z), block);
if (this.setBlock(pos.add(x, -y, z), block)) { this.setBlock(pos.add(-x, y, -z), block);
++affected; this.setBlock(pos.add(-x, -y, -z), block);
}
if (this.setBlock(pos.add(x, y, -z), block)) {
++affected;
}
if (this.setBlock(pos.add(-x, -y, z), block)) {
++affected;
}
if (this.setBlock(pos.add(x, -y, -z), block)) {
++affected;
}
if (this.setBlock(pos.add(-x, y, -z), block)) {
++affected;
}
if (this.setBlock(pos.add(-x, -y, -z), block)) {
++affected;
}
} }
} }
} }
return affected; return changes;
} }
/** /**
@ -1729,35 +1713,23 @@ public class EditSession implements Extent {
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public int makePyramid(final Vector position, final Pattern block, int size, final boolean filled) throws MaxChangedBlocksException { public int makePyramid(final Vector position, final Pattern block, int size, final boolean filled) throws MaxChangedBlocksException {
int affected = 0;
final int height = size; final int height = size;
for (int y = 0; y <= height; ++y) { for (int y = 0; y <= height; ++y) {
size--; size--;
for (int x = 0; x <= size; ++x) { for (int x = 0; x <= size; ++x) {
for (int z = 0; z <= size; ++z) { for (int z = 0; z <= size; ++z) {
if ((filled && (z <= size) && (x <= size)) || (z == size) || (x == size)) { if ((filled && (z <= size) && (x <= size)) || (z == size) || (x == size)) {
this.setBlock(position.add(x, y, z), block);
if (this.setBlock(position.add(x, y, z), block)) { this.setBlock(position.add(-x, y, z), block);
++affected; this.setBlock(position.add(x, y, -z), block);
} this.setBlock(position.add(-x, y, -z), block);
if (this.setBlock(position.add(-x, y, z), block)) {
++affected;
}
if (this.setBlock(position.add(x, y, -z), block)) {
++affected;
}
if (this.setBlock(position.add(-x, y, -z), block)) {
++affected;
}
} }
} }
} }
} }
return affected; return changes;
} }
/** /**
@ -1769,7 +1741,6 @@ public class EditSession implements Extent {
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public int thaw(final Vector position, final double radius) throws MaxChangedBlocksException { public int thaw(final Vector position, final double radius) throws MaxChangedBlocksException {
int affected = 0;
final double radiusSq = radius * radius; final double radiusSq = radius * radius;
final int ox = position.getBlockX(); final int ox = position.getBlockX();
@ -1792,15 +1763,11 @@ public class EditSession implements Extent {
switch (id) { switch (id) {
case BlockID.ICE: case BlockID.ICE:
if (this.setBlock(pt, water)) { this.setBlock(pt, water);
++affected;
}
break; break;
case BlockID.SNOW: case BlockID.SNOW:
if (this.setBlock(pt, air)) { this.setBlock(pt, air);
++affected;
}
break; break;
case BlockID.AIR: case BlockID.AIR:
@ -1815,7 +1782,7 @@ public class EditSession implements Extent {
} }
} }
return affected; return changes;
} }
/** /**
@ -1827,7 +1794,7 @@ public class EditSession implements Extent {
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public int simulateSnow(final Vector position, final double radius) throws MaxChangedBlocksException { public int simulateSnow(final Vector position, final double radius) throws MaxChangedBlocksException {
int affected = 0;
final double radiusSq = radius * radius; final double radiusSq = radius * radius;
final int ox = position.getBlockX(); final int ox = position.getBlockX();
@ -1854,9 +1821,7 @@ public class EditSession implements Extent {
// Ice! // Ice!
if ((id == BlockID.WATER) || (id == BlockID.STATIONARY_WATER)) { if ((id == BlockID.WATER) || (id == BlockID.STATIONARY_WATER)) {
if (this.setBlock(pt, ice)) { this.setBlock(pt, ice);
++affected;
}
break; break;
} }
@ -1871,15 +1836,13 @@ public class EditSession implements Extent {
} }
// add snow cover // add snow cover
if (this.setBlock(pt.add(0, 1, 0), snow)) { this.setBlock(pt.add(0, 1, 0), snow);
++affected;
}
break; break;
} }
} }
} }
return affected; return changes;
} }
/** /**
@ -1906,7 +1869,7 @@ public class EditSession implements Extent {
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public int green(final Vector position, final double radius, final boolean onlyNormalDirt) throws MaxChangedBlocksException { public int green(final Vector position, final double radius, final boolean onlyNormalDirt) throws MaxChangedBlocksException {
int affected = 0;
final double radiusSq = radius * radius; final double radiusSq = radius * radius;
final int ox = position.getBlockX(); final int ox = position.getBlockX();
@ -1932,10 +1895,7 @@ public class EditSession implements Extent {
if (onlyNormalDirt && (data != 0)) { if (onlyNormalDirt && (data != 0)) {
break loop; break loop;
} }
this.setBlock(pt, grass);
if (this.setBlock(pt, grass)) {
++affected;
}
break loop; break loop;
case BlockID.WATER: case BlockID.WATER:
@ -1955,7 +1915,7 @@ public class EditSession implements Extent {
} }
} }
return affected; return changes;
} }
/** /**
@ -1985,7 +1945,7 @@ public class EditSession implements Extent {
EditSession.this.flushQueue(); EditSession.this.flushQueue();
} }
}, true); }, true);
return this.changes = -1; return this.changes = ground.getAffected();
} }
/** /**
@ -2040,7 +2000,7 @@ public class EditSession implements Extent {
} }
}); });
} }
return this.changes = -1; return this.changes = trees.size();
} }
/** /**
@ -2201,7 +2161,7 @@ public class EditSession implements Extent {
final RValue z = expression.getVariable("z", false); final RValue z = expression.getVariable("z", false);
final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment(this, unit, zero); final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment(this, unit, zero);
expression.setEnvironment(environment); expression.setEnvironment(environment);
int affected = 0;
for (BlockVector position : region) { for (BlockVector position : region) {
// offset, scale // offset, scale
final Vector scaled = position.subtract(zero).divide(unit); final Vector scaled = position.subtract(zero).divide(unit);
@ -2211,11 +2171,9 @@ public class EditSession implements Extent {
// read block from world // read block from world
BaseBlock material = FaweCache.CACHE_BLOCK[this.queue.getCombinedId4DataDebug(sourcePosition.getBlockX(), sourcePosition.getBlockY(), sourcePosition.getBlockZ(), 0, this)]; BaseBlock material = FaweCache.CACHE_BLOCK[this.queue.getCombinedId4DataDebug(sourcePosition.getBlockX(), sourcePosition.getBlockY(), sourcePosition.getBlockZ(), 0, this)];
// queue operation // queue operation
if (this.setBlock(position, material)) { this.setBlock(position, material);
++affected;
}
} }
return affected; return changes;
} }
/** /**
@ -2229,7 +2187,7 @@ public class EditSession implements Extent {
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public int hollowOutRegion(final Region region, final int thickness, final Pattern pattern) throws MaxChangedBlocksException { public int hollowOutRegion(final Region region, final int thickness, final Pattern pattern) throws MaxChangedBlocksException {
int affected = 0;
final Set<BlockVector> outside = new HashSet<BlockVector>(); final Set<BlockVector> outside = new HashSet<BlockVector>();
@ -2276,7 +2234,6 @@ public class EditSession implements Extent {
} }
} }
} }
outside.addAll(newOutside); outside.addAll(newOutside);
} }
@ -2288,13 +2245,10 @@ public class EditSession implements Extent {
continue outer; continue outer;
} }
} }
this.setBlock(position, pattern.next(position));
if (this.setBlock(position, pattern.next(position))) {
++affected;
}
} }
return affected; return changes;
} }
/** /**
@ -2354,7 +2308,6 @@ public class EditSession implements Extent {
vset.add(new Vector(tipx, tipy, tipz)); vset.add(new Vector(tipx, tipy, tipz));
} }
notdrawn = false;
} }
vset = this.getBallooned(vset, radius); vset = this.getBallooned(vset, radius);

View File

@ -29,6 +29,8 @@ public final class Operations {
private Operations() {} private Operations() {}
private static RunContext context = new RunContext();
/** /**
* Complete a given operation synchronously until it completes. * Complete a given operation synchronously until it completes.
* *
@ -36,9 +38,11 @@ public final class Operations {
* @throws WorldEditException WorldEdit exception * @throws WorldEditException WorldEdit exception
*/ */
public static void complete(Operation operation) throws WorldEditException { public static void complete(Operation operation) throws WorldEditException {
while (operation != null) { try {
operation = operation.resume(new RunContext()); while (true) {
} operation = operation.resume(context);
}
} catch (NullPointerException ignore) {}
} }
/** /**
@ -50,12 +54,12 @@ public final class Operations {
*/ */
public static void completeLegacy(Operation operation) throws MaxChangedBlocksException { public static void completeLegacy(Operation operation) throws MaxChangedBlocksException {
try { try {
while (operation != null) { while (true) {
operation = operation.resume(new RunContext()); operation = operation.resume(context);
} }
} catch (final WorldEditException e) { } catch (final WorldEditException e) {
e.printStackTrace(); e.printStackTrace();
} } catch (NullPointerException ignore) {}
} }
/** /**
@ -67,12 +71,12 @@ public final class Operations {
*/ */
public static void completeBlindly(Operation operation) { public static void completeBlindly(Operation operation) {
try { try {
while (operation != null) { while (true) {
operation = operation.resume(new RunContext()); operation = operation.resume(context);
} }
} catch (WorldEditException e) { } catch (WorldEditException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} } catch (NullPointerException ignore) {}
} }
public static void completeSmart(final Operation op, final Runnable whenDone, final boolean threadsafe) { public static void completeSmart(final Operation op, final Runnable whenDone, final boolean threadsafe) {

View File

@ -18,7 +18,7 @@ import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.profile.GameProfileManager; import org.spongepowered.api.profile.GameProfileManager;
import org.spongepowered.api.world.World; import org.spongepowered.api.world.World;
@Plugin(id = "com.boydti.fawe", name = "FastAsyncWorldEdit", description = "Lagless WorldEdit, Area restrictions, Memory mangement, Block logging", url = "https://github.com/boy0001/FastAsyncWorldedit", version = "3.3.17") @Plugin(id = "com.boydti.fawe", name = "FastAsyncWorldEdit", description = "Lagless WorldEdit, Area restrictions, Memory mangement, Block logging", url = "https://github.com/boy0001/FastAsyncWorldedit", version = "3.3.18")
public class SpongeMain { public class SpongeMain {
public PluginContainer plugin; public PluginContainer plugin;

View File

@ -50,25 +50,35 @@ public abstract class SpongeQueue_0 extends FaweQueue {
result.addTask(runnable); result.addTask(runnable);
} }
private FaweChunk lastChunk;
private int lastX = Integer.MIN_VALUE;
private int lastZ = Integer.MIN_VALUE;
@Override @Override
public boolean setBlock(int x, final int y, int z, final short id, final byte data) { public boolean setBlock(int x, final int y, int z, final short id, final byte data) {
if ((y > 255) || (y < 0)) { if ((y > 255) || (y < 0)) {
return false; return false;
} }
long pair = (long) (x >> 4) << 32 | (z >> 4) & 0xFFFFFFFFL; int cx = x >> 4;
FaweChunk<Chunk> result = this.blocks.get(pair); int cz = z >> 4;
if (result == null) { if (cx != lastX || cz != lastZ) {
result = this.getChunk(x >> 4, z >> 4); lastX = cx;
result.setBlock(x & 15, y, z & 15, id, data); lastZ = cz;
final FaweChunk<Chunk> previous = this.blocks.put(pair, result); long pair = (long) (cx) << 32 | (cz) & 0xFFFFFFFFL;
if (previous == null) { lastChunk = this.blocks.get(pair);
chunks.add(result); if (lastChunk == null) {
return true; lastChunk = this.getChunk(x >> 4, z >> 4);
lastChunk.setBlock(x & 15, y, z & 15, id, data);
FaweChunk<Chunk> previous = this.blocks.put(pair, lastChunk);
if (previous == null) {
chunks.add(lastChunk);
return true;
}
this.blocks.put(pair, previous);
lastChunk = previous;
} }
this.blocks.put(pair, previous);
result = previous;
} }
result.setBlock(x & 15, y, z & 15, id, data); lastChunk.setBlock(x & 15, y, z & 15, id, data);
return true; return true;
} }
@ -90,6 +100,8 @@ public abstract class SpongeQueue_0 extends FaweQueue {
@Override @Override
public FaweChunk<Chunk> next() { public FaweChunk<Chunk> next() {
lastX = Integer.MIN_VALUE;
lastZ = Integer.MIN_VALUE;
try { try {
if (this.blocks.size() == 0) { if (this.blocks.size() == 0) {
return null; return null;

View File

@ -8,7 +8,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<artifactId>FastAsyncWorldEdit</artifactId> <artifactId>FastAsyncWorldEdit</artifactId>
<version>3.3.17</version> <version>3.3.18</version>
<name>FastAsyncWorldEdit</name> <name>FastAsyncWorldEdit</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<build> <build>