This commit is contained in:
Jesse Boyd 2016-01-11 06:54:04 +11:00
commit d37396716f
17 changed files with 181 additions and 75 deletions

View File

@ -210,6 +210,11 @@
<artifactId>towny</artifactId> <artifactId>towny</artifactId>
<version>0.84.0.9</version> <version>0.84.0.9</version>
</dependency> </dependency>
<dependency>
<groupId>com.intellectualcrafters.plot</groupId>
<artifactId>plotsquared</artifactId>
<version>3.2.24</version>
</dependency>
<dependency> <dependency>
<groupId>com.worldcretornica</groupId> <groupId>com.worldcretornica</groupId>
<artifactId>plotme_core</artifactId> <artifactId>plotme_core</artifactId>

View File

@ -20,7 +20,7 @@ import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
import com.boydti.fawe.util.Lag; import com.boydti.fawe.util.Lag;
import com.boydti.fawe.util.MemUtil; import com.boydti.fawe.util.MemUtil;
import com.boydti.fawe.util.SetBlockQueue; import com.boydti.fawe.util.SetQueue;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.util.WEManager; import com.boydti.fawe.util.WEManager;
import com.boydti.fawe.util.WESubscriber; import com.boydti.fawe.util.WESubscriber;
@ -107,7 +107,7 @@ public class Fawe {
// TODO command event - queue? // TODO command event - queue?
TaskManager.IMP = IMP.getTaskManager(); TaskManager.IMP = IMP.getTaskManager();
SetBlockQueue.IMP.queue = IMP.getQueue(); SetQueue.IMP.queue = IMP.getQueue();
// Delayed setup // Delayed setup
TaskManager.IMP.later(new Runnable() { TaskManager.IMP.later(new Runnable() {

View File

@ -17,7 +17,7 @@ import org.bukkit.Material;
import com.boydti.fawe.object.ChunkLoc; import com.boydti.fawe.object.ChunkLoc;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FaweLocation; import com.boydti.fawe.object.FaweLocation;
import com.boydti.fawe.util.SetBlockQueue; import com.boydti.fawe.util.SetQueue;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
import com.sk89q.jnbt.ByteArrayTag; import com.sk89q.jnbt.ByteArrayTag;
import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.IntTag;
@ -40,7 +40,7 @@ public class FaweAPI {
* @param m * @param m
*/ */
public static void setBlockAsync(final Location loc, final Material m) { public static void setBlockAsync(final Location loc, final Material m) {
SetBlockQueue.IMP.setBlock(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), (short) m.getId()); SetQueue.IMP.setBlock(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), (short) m.getId());
} }
/** /**
@ -53,7 +53,7 @@ public class FaweAPI {
* @param data * @param data
*/ */
public static void setBlockAsync(final String world, final int x, final int y, final int z, final short id, final byte data) { public static void setBlockAsync(final String world, final int x, final int y, final int z, final short id, final byte data) {
SetBlockQueue.IMP.setBlock(world, x, y, z, id, data); SetQueue.IMP.setBlock(world, x, y, z, id, data);
} }
/** /**
@ -65,7 +65,7 @@ public class FaweAPI {
* @param data * @param data
*/ */
public static void setBiomeAsync(final String world, final int x, final int z, BaseBiome biome) { public static void setBiomeAsync(final String world, final int x, final int z, BaseBiome biome) {
SetBlockQueue.IMP.setBiome(world, x, z, biome); SetQueue.IMP.setBiome(world, x, z, biome);
} }
/** /**
@ -74,7 +74,7 @@ public class FaweAPI {
* @param biome * @param biome
*/ */
public static void setBiomeAsync(Location loc, BaseBiome biome) { public static void setBiomeAsync(Location loc, BaseBiome biome) {
SetBlockQueue.IMP.setBiome(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockZ(), biome); SetQueue.IMP.setBiome(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockZ(), biome);
} }
/** /**
@ -86,7 +86,7 @@ public class FaweAPI {
* @return * @return
*/ */
public static FaweChunk<?> createChunk() { public static FaweChunk<?> createChunk() {
return SetBlockQueue.IMP.queue.getChunk(new ChunkLoc(null, 0, 0)); return SetQueue.IMP.queue.getChunk(new ChunkLoc(null, 0, 0));
} }
/** /**
@ -116,7 +116,7 @@ public class FaweAPI {
* @param loc * @param loc
*/ */
public static void fixLighting(ChunkLoc loc, boolean fixAll) { public static void fixLighting(ChunkLoc loc, boolean fixAll) {
SetBlockQueue.IMP.queue.fixLighting(SetBlockQueue.IMP.queue.getChunk(loc), fixAll); SetQueue.IMP.queue.fixLighting(SetQueue.IMP.queue.getChunk(loc), fixAll);
} }
/** /**
@ -126,7 +126,7 @@ public class FaweAPI {
*/ */
public static void fixLighting(Chunk chunk, boolean fixAll) { public static void fixLighting(Chunk chunk, boolean fixAll) {
ChunkLoc loc = new ChunkLoc(chunk.getWorld().getName(), chunk.getX(), chunk.getZ()); ChunkLoc loc = new ChunkLoc(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
SetBlockQueue.IMP.queue.fixLighting(SetBlockQueue.IMP.queue.getChunk(loc), fixAll); SetQueue.IMP.queue.fixLighting(SetQueue.IMP.queue.getChunk(loc), fixAll);
} }
/** /**
@ -322,6 +322,6 @@ public class FaweAPI {
* @param whenDone * @param whenDone
*/ */
public static void addTask(final Runnable whenDone) { public static void addTask(final Runnable whenDone) {
SetBlockQueue.IMP.addTask(whenDone); SetQueue.IMP.addTask(whenDone);
} }
} }

View File

@ -10,7 +10,7 @@ import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FawePlayer;
import com.massivecraft.factions.entity.BoardColl; import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.massivecore.ps.PS;
public class FactionsFeature extends BukkitMaskManager implements Listener { public class FactionsFeature extends BukkitMaskManager implements Listener {
FaweBukkit plugin; FaweBukkit plugin;
@ -27,7 +27,8 @@ public class FactionsFeature extends BukkitMaskManager implements Listener {
public FaweMask getMask(final FawePlayer<Player> fp) { public FaweMask getMask(final FawePlayer<Player> fp) {
final Player player = fp.parent; final Player player = fp.parent;
final Location loc = player.getLocation(); final Location loc = player.getLocation();
final Faction fac = BoardColl.get().getFactionAt(PS.valueOf(loc)); PS ps = PS.valueOf(loc);
final Faction fac = BoardColl.get().getFactionAt(ps);
if (fac != null) { if (fac != null) {
if (fac.getOnlinePlayers().contains(player)) { if (fac.getOnlinePlayers().contains(player)) {
if (fac.getComparisonName().equals("wilderness") == false) { if (fac.getComparisonName().equals("wilderness") == false) {

View File

@ -1,8 +1,10 @@
package com.boydti.fawe.bukkit.v0; package com.boydti.fawe.bukkit.v0;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -10,10 +12,15 @@ import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
@ -21,7 +28,7 @@ import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.ChunkLoc; import com.boydti.fawe.object.ChunkLoc;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.util.FaweQueue; import com.boydti.fawe.util.FaweQueue;
import com.boydti.fawe.util.SetBlockQueue; import com.boydti.fawe.util.SetQueue;
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;
@ -29,6 +36,8 @@ public abstract class BukkitQueue_0 extends FaweQueue implements Listener {
private final HashMap<ChunkLoc, FaweChunk<Chunk>> toLight = new HashMap<>(); private final HashMap<ChunkLoc, FaweChunk<Chunk>> toLight = new HashMap<>();
private final HashMap<String, HashSet<Long>> loaded = new HashMap<>();
public BukkitQueue_0() { public BukkitQueue_0() {
TaskManager.IMP.task(new Runnable() { TaskManager.IMP.task(new Runnable() {
@Override @Override
@ -36,30 +45,91 @@ public abstract class BukkitQueue_0 extends FaweQueue implements Listener {
Bukkit.getPluginManager().registerEvents(BukkitQueue_0.this, (Plugin) Fawe.imp()); Bukkit.getPluginManager().registerEvents(BukkitQueue_0.this, (Plugin) Fawe.imp());
} }
}); });
for (World world : Bukkit.getWorlds()) {
for (Chunk chunk : world.getLoadedChunks()) {
addLoaded(chunk);
}
}
} }
@EventHandler @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onWorldLoad(WorldLoadEvent event) {
World world = event.getWorld();
for (Chunk chunk : world.getLoadedChunks()) {
addLoaded(chunk);
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onWorldUnload(WorldUnloadEvent event) {
loaded.remove(event.getWorld().getName());
}
public void addLoaded(Chunk chunk) {
String world = chunk.getWorld().getName();
long x = chunk.getX();
long z = chunk.getZ();
long id = x << 32 | z & 0xFFFFFFFFL;
HashSet<Long> map = loaded.get(world);
if (map != null) {
map.add(id);
} else {
map = new HashSet<>(Arrays.asList(id));
loaded.put(world, map);
}
}
public void removeLoaded(Chunk chunk) {
String world = chunk.getWorld().getName();
long x = chunk.getX();
long z = chunk.getZ();
long id = x << 32 | z & 0xFFFFFFFFL;
HashSet<Long> map = loaded.get(world);
if (map != null) {
map.remove(id);
}
}
@Override
public boolean isChunkLoaded(String world, int x, int z) {
long id = (long) x << 32 | z & 0xFFFFFFFFL;
HashSet<Long> map = loaded.get(world);
if (map != null) {
return map.contains(id);
}
return false;
};
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onMove(PlayerMoveEvent event) { public void onMove(PlayerMoveEvent event) {
Location loc = event.getTo(); Location loc = event.getTo();
if (!loc.getChunk().equals(event.getFrom().getChunk())) { if (!loc.getChunk().equals(event.getFrom().getChunk())) {
Chunk chunk = loc.getChunk(); Chunk chunk = loc.getChunk();
ChunkLoc cl = new ChunkLoc(chunk.getWorld().getName(), chunk.getX(), chunk.getZ()); ChunkLoc cl = new ChunkLoc(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
FaweChunk<Chunk> fc = toLight.remove(cl);
if (fc != null) {
if (fixLighting(fc, Settings.FIX_ALL_LIGHTING)) {
return;
}
}
} }
} }
@EventHandler @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onChunkLoad(ChunkLoadEvent event) { public void onChunkLoad(ChunkLoadEvent event) {
Chunk chunk = event.getChunk();
addLoaded(chunk);
if (toLight.size() == 0) { if (toLight.size() == 0) {
return; return;
} }
Chunk chunk = event.getChunk();
ChunkLoc loc = new ChunkLoc(chunk.getWorld().getName(), chunk.getX(), chunk.getZ()); ChunkLoc loc = new ChunkLoc(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
for (int x = -1; x <= 1; x++) { for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) { for (int z = -1; z <= 1; z++) {
ChunkLoc a = new ChunkLoc(loc.world, loc.x + x, loc.z + z); ChunkLoc a = new ChunkLoc(loc.world, loc.x + x, loc.z + z);
if (toLight.containsKey(a)) { FaweChunk<Chunk> fc = toLight.remove(a);
if (fixLighting(toLight.get(a), Settings.FIX_ALL_LIGHTING)) { if (fc != null) {
toLight.remove(a); if (fixLighting(fc, Settings.FIX_ALL_LIGHTING)) {
return; return;
} }
} }
@ -67,6 +137,11 @@ public abstract class BukkitQueue_0 extends FaweQueue implements Listener {
} }
} }
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onChunkUnload(ChunkUnloadEvent event) {
removeLoaded(event.getChunk());
}
private final ConcurrentHashMap<ChunkLoc, FaweChunk<Chunk>> blocks = new ConcurrentHashMap<>(); private final ConcurrentHashMap<ChunkLoc, FaweChunk<Chunk>> blocks = new ConcurrentHashMap<>();
@Override @Override
@ -118,7 +193,7 @@ public abstract class BukkitQueue_0 extends FaweQueue implements Listener {
} }
final Iterator<Entry<ChunkLoc, FaweChunk<Chunk>>> iter = blocks.entrySet().iterator(); final Iterator<Entry<ChunkLoc, FaweChunk<Chunk>>> iter = blocks.entrySet().iterator();
final FaweChunk<Chunk> toReturn = iter.next().getValue(); final FaweChunk<Chunk> toReturn = iter.next().getValue();
if (SetBlockQueue.IMP.isWaiting()) { if (SetQueue.IMP.isWaiting()) {
return null; return null;
} }
iter.remove(); iter.remove();
@ -145,7 +220,7 @@ public abstract class BukkitQueue_0 extends FaweQueue implements Listener {
} }
toUpdate.add(fc); toUpdate.add(fc);
// Fix lighting // Fix lighting
SetBlockQueue.IMP.addTask(new Runnable() { SetQueue.IMP.addTask(new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -2,8 +2,10 @@ package com.boydti.fawe.object;
import java.util.List; import java.util.List;
import com.boydti.fawe.util.SetBlockQueue; import com.boydti.fawe.util.SetQueue;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.EditSession;
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;
@ -28,14 +30,21 @@ public class FastWorldEditExtent extends AbstractDelegateExtent {
} }
@Override @Override
public Entity createEntity(Location location, BaseEntity entity) { public Entity createEntity(final Location location, final BaseEntity entity) {
synchronized (thread) { TaskManager.IMP.task(new Runnable() {
return super.createEntity(location, entity); @Override
public void run() {
FastWorldEditExtent.super.createEntity(location, entity);
} }
});
return null;
} }
@Override @Override
public BaseBiome getBiome(Vector2D position) { public BaseBiome getBiome(Vector2D position) {
if (!SetQueue.IMP.isChunkLoaded(world, position.getBlockX() >> 4, position.getBlockZ() >> 4)) {
return EditSession.nullBiome;
}
synchronized (thread) { synchronized (thread) {
return super.getBiome(position); return super.getBiome(position);
} }
@ -49,6 +58,9 @@ public class FastWorldEditExtent extends AbstractDelegateExtent {
if (lastBlock != null && lastVector.equals(position.toBlockVector())) { if (lastBlock != null && lastVector.equals(position.toBlockVector())) {
return lastBlock; return lastBlock;
} }
if (!SetQueue.IMP.isChunkLoaded(world, position.getBlockX() >> 4, position.getBlockZ() >> 4)) {
return EditSession.nullBlock;
}
synchronized (thread) { synchronized (thread) {
lastVector = position.toBlockVector(); lastVector = position.toBlockVector();
return lastBlock = super.getBlock(position); return lastBlock = super.getBlock(position);
@ -71,14 +83,12 @@ public class FastWorldEditExtent extends AbstractDelegateExtent {
@Override @Override
public BaseBlock getBlock(Vector position) { public BaseBlock getBlock(Vector position) {
synchronized (thread) { return getLazyBlock(position);
return super.getLazyBlock(position);
}
} }
@Override @Override
public boolean setBiome(Vector2D position, BaseBiome biome) { public boolean setBiome(Vector2D position, BaseBiome biome) {
SetBlockQueue.IMP.setBiome(world, position.getBlockX(), position.getBlockZ(), biome); SetQueue.IMP.setBiome(world, position.getBlockX(), position.getBlockZ(), biome);
return true; return true;
} }
@ -173,11 +183,11 @@ public class FastWorldEditExtent extends AbstractDelegateExtent {
case 190: case 190:
case 191: case 191:
case 192: { case 192: {
SetBlockQueue.IMP.setBlock(world, x, y, z, id); SetQueue.IMP.setBlock(world, x, y, z, id);
return true; return true;
} }
default: { default: {
SetBlockQueue.IMP.setBlock(world, x, y, z, id, (byte) block.getData()); SetQueue.IMP.setBlock(world, x, y, z, id, (byte) block.getData());
return true; return true;
} }
} }

View File

@ -1,7 +1,7 @@
package com.boydti.fawe.object; package com.boydti.fawe.object;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
import com.boydti.fawe.util.SetBlockQueue; import com.boydti.fawe.util.SetQueue;
import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.biome.BaseBiome;
public abstract class FaweChunk<T> { public abstract class FaweChunk<T> {
@ -27,11 +27,11 @@ public abstract class FaweChunk<T> {
if (chunk == null) { if (chunk == null) {
throw new IllegalArgumentException("Chunk location cannot be null!"); throw new IllegalArgumentException("Chunk location cannot be null!");
} }
SetBlockQueue.IMP.queue.setChunk(this); SetQueue.IMP.queue.setChunk(this);
} }
public void fixLighting() { public void fixLighting() {
SetBlockQueue.IMP.queue.fixLighting(this, Settings.FIX_ALL_LIGHTING); SetQueue.IMP.queue.fixLighting(this, Settings.FIX_ALL_LIGHTING);
} }
public void fill(int id, byte data) { public void fill(int id, byte data) {

View File

@ -1,6 +1,6 @@
package com.boydti.fawe.object; package com.boydti.fawe.object;
import com.boydti.fawe.util.SetBlockQueue; import com.boydti.fawe.util.SetQueue;
/** /**
*/ */
@ -40,6 +40,6 @@ public class FaweLocation {
} }
public void setBlockAsync(short id, byte data) { public void setBlockAsync(short id, byte data) {
SetBlockQueue.IMP.setBlock(world, x, y, z, id, data); SetQueue.IMP.setBlock(world, x, y, z, id, data);
} }
} }

View File

@ -3,6 +3,7 @@ package com.boydti.fawe.object;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.sk89q.worldedit.EditSession;
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;
@ -17,23 +18,19 @@ import com.sk89q.worldedit.world.biome.BaseBiome;
public class NullExtent implements Extent { public class NullExtent implements Extent {
private final BaseBiome nullBiome = new BaseBiome(0);
private final BaseBlock nullBlock = new BaseBlock(0);
@Override @Override
public BaseBiome getBiome(final Vector2D arg0) { public BaseBiome getBiome(final Vector2D arg0) {
return nullBiome; return EditSession.nullBiome;
} }
@Override @Override
public BaseBlock getBlock(final Vector arg0) { public BaseBlock getBlock(final Vector arg0) {
return nullBlock; return EditSession.nullBlock;
} }
@Override @Override
public BaseBlock getLazyBlock(final Vector arg0) { public BaseBlock getLazyBlock(final Vector arg0) {
return nullBlock; return EditSession.nullBlock;
} }
@Override @Override

View File

@ -6,9 +6,11 @@ import java.util.List;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.SetBlockQueue; import com.boydti.fawe.util.SetQueue;
import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.util.WEManager; import com.boydti.fawe.util.WEManager;
import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.EditSession;
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;
@ -55,7 +57,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
} }
@Override @Override
public Entity createEntity(Location location, BaseEntity entity) { public Entity createEntity(final Location location, final BaseEntity entity) {
if (Eblocked) { if (Eblocked) {
return null; return null;
} }
@ -65,15 +67,21 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
MainUtil.sendAdmin(BBC.WORLDEDIT_DANGEROUS_WORLDEDIT.format(world + ": " + location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ(), user)); MainUtil.sendAdmin(BBC.WORLDEDIT_DANGEROUS_WORLDEDIT.format(world + ": " + location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ(), user));
} }
if (WEManager.IMP.maskContains(mask, location.getBlockX(), location.getBlockZ())) { if (WEManager.IMP.maskContains(mask, location.getBlockX(), location.getBlockZ())) {
synchronized (thread) { TaskManager.IMP.task(new Runnable() {
return super.createEntity(location, entity); @Override
public void run() {
ProcessedWEExtent.super.createEntity(location, entity);
} }
});
} }
return null; return null;
} }
@Override @Override
public BaseBiome getBiome(Vector2D position) { public BaseBiome getBiome(Vector2D position) {
if (!SetQueue.IMP.isChunkLoaded(world, position.getBlockX() >> 4, position.getBlockZ() >> 4)) {
return EditSession.nullBiome;
}
synchronized (thread) { synchronized (thread) {
return super.getBiome(position); return super.getBiome(position);
} }
@ -87,6 +95,9 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
if (lastBlock != null && lastVector.equals(position.toBlockVector())) { if (lastBlock != null && lastVector.equals(position.toBlockVector())) {
return lastBlock; return lastBlock;
} }
if (!SetQueue.IMP.isChunkLoaded(world, position.getBlockX() >> 4, position.getBlockZ() >> 4)) {
return EditSession.nullBlock;
}
synchronized (thread) { synchronized (thread) {
lastVector = position.toBlockVector(); lastVector = position.toBlockVector();
return lastBlock = super.getLazyBlock(position); return lastBlock = super.getLazyBlock(position);
@ -109,9 +120,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
@Override @Override
public BaseBlock getBlock(Vector position) { public BaseBlock getBlock(Vector position) {
synchronized (thread) { return getLazyBlock(position);
return super.getLazyBlock(position);
}
} }
@Override @Override
@ -172,7 +181,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
} }
return false; return false;
} }
SetBlockQueue.IMP.setBlock(world, x, location.getBlockY(), z, id, (byte) block.getData()); SetQueue.IMP.setBlock(world, x, location.getBlockY(), z, id, (byte) block.getData());
} }
break; break;
} }
@ -271,11 +280,11 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
case 190: case 190:
case 191: case 191:
case 192: { case 192: {
SetBlockQueue.IMP.setBlock(world, x, y, z, id); SetQueue.IMP.setBlock(world, x, y, z, id);
break; break;
} }
default: { default: {
SetBlockQueue.IMP.setBlock(world, x, y, z, id, (byte) block.getData()); SetQueue.IMP.setBlock(world, x, y, z, id, (byte) block.getData());
break; break;
} }
} }
@ -290,7 +299,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
@Override @Override
public boolean setBiome(final Vector2D position, final BaseBiome biome) { public boolean setBiome(final Vector2D position, final BaseBiome biome) {
if (WEManager.IMP.maskContains(mask, position.getBlockX(), position.getBlockZ())) { if (WEManager.IMP.maskContains(mask, position.getBlockX(), position.getBlockZ())) {
SetBlockQueue.IMP.setBiome(world, position.getBlockX(), position.getBlockZ(), biome); SetQueue.IMP.setBiome(world, position.getBlockX(), position.getBlockZ(), biome);
} }
return false; return false;
} }

View File

@ -17,6 +17,8 @@ public abstract class FaweQueue {
public abstract boolean fixLighting(FaweChunk<?> chunk, boolean fixAll); public abstract boolean fixLighting(FaweChunk<?> chunk, boolean fixAll);
public abstract boolean isChunkLoaded(String world, int x, int z);
/** /**
* Gets the FaweChunk and sets the requested blocks * Gets the FaweChunk and sets the requested blocks
* @return * @return
@ -28,7 +30,7 @@ public abstract class FaweQueue {
// Set memory limited // Set memory limited
MemUtil.memoryLimitedTask(); MemUtil.memoryLimitedTask();
// Clear block placement // Clear block placement
SetBlockQueue.IMP.queue.clear(); SetQueue.IMP.queue.clear();
Fawe.get().getWorldEdit().clearSessions(); Fawe.get().getWorldEdit().clearSessions();
// GC // GC
System.gc(); System.gc();

View File

@ -6,9 +6,9 @@ import java.util.concurrent.atomic.AtomicInteger;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.biome.BaseBiome;
public class SetBlockQueue { public class SetQueue {
public static final SetBlockQueue IMP = new SetBlockQueue(); public static final SetQueue IMP = new SetQueue();
public FaweQueue queue; public FaweQueue queue;
@ -18,7 +18,7 @@ public class SetBlockQueue {
private long last; private long last;
private long last2; private long last2;
public SetBlockQueue() { public SetQueue() {
TaskManager.IMP.repeat(new Runnable() { TaskManager.IMP.repeat(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -110,7 +110,7 @@ public class SetBlockQueue {
* @return * @return
*/ */
public boolean setBlock(final String world, final int x, final int y, final int z, final short id, final byte data) { public boolean setBlock(final String world, final int x, final int y, final int z, final short id, final byte data) {
SetBlockQueue.IMP.setWaiting(); SetQueue.IMP.setWaiting();
return queue.setBlock(world, x, y, z, id, data); return queue.setBlock(world, x, y, z, id, data);
} }
@ -123,7 +123,7 @@ public class SetBlockQueue {
* @return * @return
*/ */
public boolean setBlock(final String world, final int x, final int y, final int z, final short id) { public boolean setBlock(final String world, final int x, final int y, final int z, final short id) {
SetBlockQueue.IMP.setWaiting(); SetQueue.IMP.setWaiting();
return queue.setBlock(world, x, y, z, id, (byte) 0); return queue.setBlock(world, x, y, z, id, (byte) 0);
} }
@ -137,7 +137,11 @@ public class SetBlockQueue {
* @return * @return
*/ */
public boolean setBiome(final String world, final int x, final int z, BaseBiome biome) { public boolean setBiome(final String world, final int x, final int z, BaseBiome biome) {
SetBlockQueue.IMP.setWaiting(); SetQueue.IMP.setWaiting();
return queue.setBiome(world, x, z, biome); return queue.setBiome(world, x, z, biome);
} }
public boolean isChunkLoaded(String world, int x, int z) {
return queue.isChunkLoaded(world, x, z);
}
} }

View File

@ -86,7 +86,7 @@ public class WEManager {
TaskManager.IMP.later(new Runnable() { TaskManager.IMP.later(new Runnable() {
@Override @Override
public void run() { public void run() {
SetBlockQueue.IMP.addTask(new Runnable() { SetQueue.IMP.addTask(new Runnable() {
@Override @Override
public void run() { public void run() {
if ((System.currentTimeMillis() - start) > 1000) { if ((System.currentTimeMillis() - start) > 1000) {
@ -106,7 +106,7 @@ public class WEManager {
} }
public boolean delay(final FawePlayer<?> player, final Runnable whenDone, final boolean delayed, final boolean onlyDelayedExecution) { public boolean delay(final FawePlayer<?> player, final Runnable whenDone, final boolean delayed, final boolean onlyDelayedExecution) {
final boolean free = SetBlockQueue.IMP.addTask(null); final boolean free = SetQueue.IMP.addTask(null);
if (free) { if (free) {
if (delayed) { if (delayed) {
if (whenDone != null) { if (whenDone != null) {
@ -123,7 +123,7 @@ public class WEManager {
if (!delayed && (player != null)) { if (!delayed && (player != null)) {
BBC.WORLDEDIT_DELAYED.send(player); BBC.WORLDEDIT_DELAYED.send(player);
} }
SetBlockQueue.IMP.addTask(whenDone); SetQueue.IMP.addTask(whenDone);
} }
return true; return true;
} }

View File

@ -161,6 +161,9 @@ public class EditSession implements Extent {
private boolean fastmode; private boolean fastmode;
private Mask oldMask; private Mask oldMask;
public static BaseBiome nullBiome = new BaseBiome(0);
public static BaseBlock nullBlock = new BaseBlock(0);
/** /**
* Create a new instance. * Create a new instance.
* *

View File

@ -33,7 +33,7 @@ import java.util.Comparator;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.boydti.fawe.util.SetBlockQueue; import com.boydti.fawe.util.SetQueue;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandContext;
@ -98,7 +98,7 @@ public class SchematicCommands {
return; return;
} }
SetBlockQueue.IMP.addTask(new Runnable() { SetQueue.IMP.addTask(new Runnable() {
@Override @Override
public void run() { public void run() {
TaskManager.IMP.async(new Runnable() { TaskManager.IMP.async(new Runnable() {
@ -167,7 +167,7 @@ public class SchematicCommands {
target = clipboard; target = clipboard;
} }
SetBlockQueue.IMP.addTask(new Runnable() { SetQueue.IMP.addTask(new Runnable() {
@Override @Override
public void run() { public void run() {
TaskManager.IMP.async(new Runnable() { TaskManager.IMP.async(new Runnable() {

View File

@ -24,7 +24,7 @@ import static com.sk89q.minecraft.util.commands.Logging.LogMode.ALL;
import java.io.File; import java.io.File;
import com.boydti.fawe.util.SetBlockQueue; import com.boydti.fawe.util.SetQueue;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandContext;
@ -69,7 +69,7 @@ public class ScriptingCommands {
final File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir); final File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir);
final File f = worldEdit.getSafeOpenFile(player, dir, name, "js", "js"); final File f = worldEdit.getSafeOpenFile(player, dir, name, "js", "js");
SetBlockQueue.IMP.addTask(new Runnable() { SetQueue.IMP.addTask(new Runnable() {
@Override @Override
public void run() { public void run() {
TaskManager.IMP.async(new Runnable() { TaskManager.IMP.async(new Runnable() {
@ -107,7 +107,7 @@ public class ScriptingCommands {
final File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir); final File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir);
final File f = worldEdit.getSafeOpenFile(player, dir, lastScript, "js", "js"); final File f = worldEdit.getSafeOpenFile(player, dir, lastScript, "js", "js");
SetBlockQueue.IMP.addTask(new Runnable() { SetQueue.IMP.addTask(new Runnable() {
@Override @Override
public void run() { public void run() {
TaskManager.IMP.async(new Runnable() { TaskManager.IMP.async(new Runnable() {

View File

@ -19,7 +19,7 @@
package com.sk89q.worldedit.function.operation; package com.sk89q.worldedit.function.operation;
import com.boydti.fawe.util.SetBlockQueue; import com.boydti.fawe.util.SetQueue;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
@ -85,7 +85,7 @@ public final class Operations {
} }
return; return;
} }
SetBlockQueue.IMP.addTask(new Runnable() { SetQueue.IMP.addTask(new Runnable() {
@Override @Override
public void run() { public void run() {
TaskManager.IMP.async(new Runnable() { TaskManager.IMP.async(new Runnable() {