Fix masking extent + process non plot worlds

This commit is contained in:
boy0001 2015-08-28 08:33:32 +10:00
parent 5b44e39bec
commit 56d50bd9e1
3 changed files with 70 additions and 13 deletions

View File

@ -35,7 +35,7 @@ public class SetBlockQueue {
public synchronized static boolean addNotify(Runnable whenDone) { public synchronized static boolean addNotify(Runnable whenDone) {
if (runnables == null) { if (runnables == null) {
if (blocks == null) { if (blocks == null || blocks.size() == 0) {
if (whenDone != null) { if (whenDone != null) {
whenDone.run(); whenDone.run();
} }
@ -46,8 +46,23 @@ public class SetBlockQueue {
runnables = new ArrayDeque<>(); runnables = new ArrayDeque<>();
} }
if (whenDone != null) { if (whenDone != null) {
init();
runnables.add(whenDone); runnables.add(whenDone);
} }
if (blocks == null || blocks.size() == 0) {
ArrayDeque<Runnable> tasks = runnables;
lastInt = -1;
lastBlock = null;
runnables = null;
running = false;
blocks = null;
slow = false;
if (tasks != null) {
for (Runnable runnable : tasks) {
runnable.run();
}
}
}
return false; return false;
} }
@ -66,6 +81,7 @@ public class SetBlockQueue {
@Override @Override
public void run() { public void run() {
if (locked) { if (locked) {
System.out.print("LOCKED!");
return; return;
} }
if (blocks == null || blocks.size() == 0) { if (blocks == null || blocks.size() == 0) {
@ -74,8 +90,8 @@ public class SetBlockQueue {
lastInt = -1; lastInt = -1;
lastBlock = null; lastBlock = null;
runnables = null; runnables = null;
blocks = null;
running = false; running = false;
blocks = null;
slow = false; slow = false;
if (tasks != null) { if (tasks != null) {
for (Runnable runnable : tasks) { for (Runnable runnable : tasks) {
@ -92,6 +108,19 @@ public class SetBlockQueue {
} }
Iterator<Entry<ChunkWrapper, PlotBlock[][]>> iter = blocks.entrySet().iterator(); Iterator<Entry<ChunkWrapper, PlotBlock[][]>> iter = blocks.entrySet().iterator();
if (!iter.hasNext()) { if (!iter.hasNext()) {
PS.get().TASK.cancelTask(TaskManager.tasks.get(current));
ArrayDeque<Runnable> tasks = runnables;
lastInt = -1;
lastBlock = null;
runnables = null;
running = false;
blocks = null;
slow = false;
if (tasks != null) {
for (Runnable runnable : tasks) {
runnable.run();
}
}
return; return;
} }
Entry<ChunkWrapper, PlotBlock[][]> n = iter.next(); Entry<ChunkWrapper, PlotBlock[][]> n = iter.next();
@ -196,7 +225,10 @@ public class SetBlockQueue {
ChunkWrapper wrap = new ChunkWrapper(world, X, Z); ChunkWrapper wrap = new ChunkWrapper(world, X, Z);
PlotBlock[][] result; PlotBlock[][] result;
result = blocks.get(wrap); result = blocks.get(wrap);
if (!blocks.containsKey(wrap)) { if (result == null) {
if (blocks == null) {
init();
}
result = new PlotBlock[16][]; result = new PlotBlock[16][];
blocks.put(wrap, result); blocks.put(wrap, result);
} }
@ -219,7 +251,10 @@ public class SetBlockQueue {
ChunkWrapper wrap = new ChunkWrapper(world, X, Z); ChunkWrapper wrap = new ChunkWrapper(world, X, Z);
PlotBlock[][] result; PlotBlock[][] result;
result = blocks.get(wrap); result = blocks.get(wrap);
if (!blocks.containsKey(wrap)) { if (result == null) {
if (blocks == null) {
init();
}
result = new PlotBlock[16][]; result = new PlotBlock[16][];
blocks.put(wrap, result); blocks.put(wrap, result);
} }

View File

@ -27,6 +27,12 @@ public class WEManager {
public static HashSet<RegionWrapper> getMask(PlotPlayer player) { public static HashSet<RegionWrapper> getMask(PlotPlayer player) {
HashSet<RegionWrapper> regions = new HashSet<>(); HashSet<RegionWrapper> regions = new HashSet<>();
UUID uuid = player.getUUID(); UUID uuid = player.getUUID();
Location location = player.getLocation();
String world = location.getWorld();
if (!PS.get().isPlotWorld(world)) {
regions.add(new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE));
return regions;
}
for (Plot plot : PS.get().getPlotsInWorld(player.getLocation().getWorld())) { for (Plot plot : PS.get().getPlotsInWorld(player.getLocation().getWorld())) {
if (!plot.isBasePlot() || (Settings.DONE_RESTRICTS_BUILDING && FlagManager.getPlotFlag(plot, "done") != null)) { if (!plot.isBasePlot() || (Settings.DONE_RESTRICTS_BUILDING && FlagManager.getPlotFlag(plot, "done") != null)) {
continue; continue;

View File

@ -23,6 +23,7 @@ import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.ChangeSetExtent; import com.sk89q.worldedit.extent.ChangeSetExtent;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.MaskingExtent;
import com.sk89q.worldedit.extent.cache.LastAccessExtentCache; import com.sk89q.worldedit.extent.cache.LastAccessExtentCache;
import com.sk89q.worldedit.extent.inventory.BlockBagExtent; import com.sk89q.worldedit.extent.inventory.BlockBagExtent;
import com.sk89q.worldedit.extent.reorder.MultiStageReorder; import com.sk89q.worldedit.extent.reorder.MultiStageReorder;
@ -31,6 +32,7 @@ import com.sk89q.worldedit.extent.world.BlockQuirkExtent;
import com.sk89q.worldedit.extent.world.ChunkLoadingExtent; import com.sk89q.worldedit.extent.world.ChunkLoadingExtent;
import com.sk89q.worldedit.extent.world.FastModeExtent; import com.sk89q.worldedit.extent.world.FastModeExtent;
import com.sk89q.worldedit.extent.world.SurvivalModeExtent; import com.sk89q.worldedit.extent.world.SurvivalModeExtent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.util.eventbus.EventHandler.Priority; import com.sk89q.worldedit.util.eventbus.EventHandler.Priority;
import com.sk89q.worldedit.util.eventbus.Subscribe; import com.sk89q.worldedit.util.eventbus.Subscribe;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
@ -41,9 +43,6 @@ public class WESubscriber {
public void onEditSession(EditSessionEvent event) { public void onEditSession(EditSessionEvent event) {
World worldObj = event.getWorld(); World worldObj = event.getWorld();
String world = worldObj.getName(); String world = worldObj.getName();
if (!PS.get().isPlotWorld(world)) {
return;
}
Actor actor = event.getActor(); Actor actor = event.getActor();
if (actor != null && actor.isPlayer()) { if (actor != null && actor.isPlayer()) {
String name = actor.getName(); String name = actor.getName();
@ -58,16 +57,21 @@ public class WESubscriber {
if (Permissions.hasPermission(player, "plots.worldedit.bypass")) { if (Permissions.hasPermission(player, "plots.worldedit.bypass")) {
MainUtil.sendMessage(player, C.WORLDEDIT_BYPASS); MainUtil.sendMessage(player, C.WORLDEDIT_BYPASS);
} }
if (PS.get().isPlotWorld(world)) {
event.setExtent(new NullExtent()); event.setExtent(new NullExtent());
}
return; return;
} }
if (Settings.CHUNK_PROCESSOR) { if (Settings.CHUNK_PROCESSOR) {
if (Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) { if (Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) {
try { try {
LocalSession session = ((BukkitMain) PS.get().IMP).worldEdit.getWorldEdit().getSession(name);
boolean hasMask = session.getMask() != null;
AbstractDelegateExtent extent = (AbstractDelegateExtent) event.getExtent(); AbstractDelegateExtent extent = (AbstractDelegateExtent) event.getExtent();
ChangeSetExtent history = null; ChangeSetExtent history = null;
MultiStageReorder reorder = null; MultiStageReorder reorder = null;
boolean fast = ((BukkitMain) PS.get().IMP).worldEdit.getWorldEdit().getSession(name).hasFastMode(); MaskingExtent maskextent = null;
boolean fast = session.hasFastMode();
while (extent.getExtent() != null && extent.getExtent() instanceof AbstractDelegateExtent) { while (extent.getExtent() != null && extent.getExtent() instanceof AbstractDelegateExtent) {
AbstractDelegateExtent tmp = (AbstractDelegateExtent) extent.getExtent(); AbstractDelegateExtent tmp = (AbstractDelegateExtent) extent.getExtent();
if (tmp.getExtent() != null && tmp.getExtent() instanceof AbstractDelegateExtent) { if (tmp.getExtent() != null && tmp.getExtent() instanceof AbstractDelegateExtent) {
@ -77,6 +81,9 @@ public class WESubscriber {
if (tmp instanceof MultiStageReorder) { if (tmp instanceof MultiStageReorder) {
reorder = (MultiStageReorder) tmp; reorder = (MultiStageReorder) tmp;
} }
if (hasMask && tmp instanceof MaskingExtent) {
maskextent = tmp;
}
extent = tmp; extent = tmp;
} }
else { else {
@ -95,9 +102,16 @@ public class WESubscriber {
if (fast) { if (fast) {
event.setExtent(new ExtentWrapper(extent)); event.setExtent(new ExtentWrapper(extent));
} }
else {
if (maskextent != null) {
ExtentWrapper wrapper = new ExtentWrapper(maskextent);
field.set(maskextent, history);
event.setExtent(wrapper);
}
else { else {
ExtentWrapper wrapper = new ExtentWrapper(history); ExtentWrapper wrapper = new ExtentWrapper(history);
event.setExtent(wrapper); event.setExtent(wrapper);
}
field.set(history, reorder); field.set(history, reorder);
field.set(reorder, new ProcessedWEExtent(world, mask, max, new FastModeExtent(worldObj, true), wrapper)); field.set(reorder, new ProcessedWEExtent(world, mask, max, new FastModeExtent(worldObj, true), wrapper));
} }
@ -108,9 +122,11 @@ public class WESubscriber {
e.printStackTrace(); e.printStackTrace();
} }
} }
if (PS.get().isPlotWorld(world)) {
event.setExtent(new ProcessedWEExtent(world, mask, event.getMaxBlocks(), event.getExtent(), event.getExtent())); event.setExtent(new ProcessedWEExtent(world, mask, event.getMaxBlocks(), event.getExtent(), event.getExtent()));
} }
else { }
else if (PS.get().isPlotWorld(world)) {
event.setExtent(new WEExtent(mask, event.getExtent())); event.setExtent(new WEExtent(mask, event.getExtent()));
} }
} }