Various fixes

This commit is contained in:
Jesse Boyd 2016-06-20 14:06:14 +10:00
parent 706b44a26a
commit 0d7c0474cc
9 changed files with 57 additions and 38 deletions

View File

@ -8,7 +8,6 @@ import com.boydti.fawe.util.StringMan;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.entity.BukkitEntity;
import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.biome.BaseBiome;
import java.io.File; import java.io.File;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -91,6 +90,10 @@ public class AsyncWorld implements World {
queue.enqueue(); queue.enqueue();
} }
public void flush() {
queue.flush();
}
@Override @Override
public WorldBorder getWorldBorder() { public WorldBorder getWorldBorder() {
return TaskManager.IMP.sync(new RunnableVal<WorldBorder>() { return TaskManager.IMP.sync(new RunnableVal<WorldBorder>() {

View File

@ -22,6 +22,7 @@ import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.MutableClassToInstanceMap; import com.google.common.collect.MutableClassToInstanceMap;
import com.intellectualcrafters.plot.util.StringMan;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.thevoxelbox.voxelsniper.brush.IBrush; import com.thevoxelbox.voxelsniper.brush.IBrush;
import com.thevoxelbox.voxelsniper.brush.SnipeBrush; import com.thevoxelbox.voxelsniper.brush.SnipeBrush;
@ -87,7 +88,7 @@ public class Sniper {
if (this.tmpWorld == null) { if (this.tmpWorld == null) {
Player player = getPlayer(); Player player = getPlayer();
FawePlayer<Player> fp = FawePlayer.wrap(player); FawePlayer<Player> fp = FawePlayer.wrap(player);
if (this.baseQueue == null) { if (this.baseQueue == null || !StringMan.isEqual(baseQueue.getWorldName(), player.getWorld().getName())) {
this.baseQueue = FaweAPI.createQueue(fp.getLocation().world, false); this.baseQueue = FaweAPI.createQueue(fp.getLocation().world, false);
} }
RegionWrapper[] mask = WEManager.IMP.getMask(fp); RegionWrapper[] mask = WEManager.IMP.getMask(fp);
@ -398,7 +399,7 @@ public class Sniper {
FaweChangeSet changeSet = changeQueue.getChangeSet(); FaweChangeSet changeSet = changeQueue.getChangeSet();
FawePlayer<Object> fp = FawePlayer.wrap(getPlayer()); FawePlayer<Object> fp = FawePlayer.wrap(getPlayer());
LocalSession session = fp.getSession(); LocalSession session = fp.getSession();
baseQueue.enqueue(); baseQueue.flush();
session.remember(changeSet.toEditSession(fp)); session.remember(changeSet.toEditSession(fp));
changeQueue.flush(); changeQueue.flush();
com.sk89q.worldedit.world.World worldEditWorld = fp.getWorld(); com.sk89q.worldedit.world.World worldEditWorld = fp.getWorld();

View File

@ -2,6 +2,7 @@ package com.boydti.fawe.object.change;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.object.extent.FastWorldEditExtent; import com.boydti.fawe.object.extent.FastWorldEditExtent;
import com.boydti.fawe.util.ExtentTraverser;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.history.UndoContext; import com.sk89q.worldedit.history.UndoContext;
@ -36,8 +37,9 @@ public class MutableBlockChange implements Change {
public void create(UndoContext context) { public void create(UndoContext context) {
Extent extent = context.getExtent(); Extent extent = context.getExtent();
if (extent.getClass() == FastWorldEditExtent.class) { ExtentTraverser<FastWorldEditExtent> find = new ExtentTraverser(extent).find(FastWorldEditExtent.class);
FastWorldEditExtent fwee = (FastWorldEditExtent) extent; if (find != null) {
FastWorldEditExtent fwee = find.get();
fwee.getQueue().setBlock(x, y, z, id, data); fwee.getQueue().setBlock(x, y, z, id, data);
} else { } else {
Fawe.debug("FAWE doesn't support: " + extent + " for " + getClass() + " (bug Empire92)"); Fawe.debug("FAWE doesn't support: " + extent + " for " + getClass() + " (bug Empire92)");

View File

@ -3,6 +3,7 @@ package com.boydti.fawe.object.change;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.extent.FastWorldEditExtent; import com.boydti.fawe.object.extent.FastWorldEditExtent;
import com.boydti.fawe.util.ExtentTraverser;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.history.UndoContext; import com.sk89q.worldedit.history.UndoContext;
@ -30,8 +31,9 @@ public class MutableChunkChange implements Change {
public void create(UndoContext context, boolean undo) { public void create(UndoContext context, boolean undo) {
Extent extent = context.getExtent(); Extent extent = context.getExtent();
if (extent.getClass() == FastWorldEditExtent.class) { ExtentTraverser<FastWorldEditExtent> find = new ExtentTraverser(extent).find(FastWorldEditExtent.class);
FastWorldEditExtent fwee = (FastWorldEditExtent) extent; if (find != null) {
FastWorldEditExtent fwee = find.get();
if (undo) { if (undo) {
fwee.getQueue().setChunk(from); fwee.getQueue().setChunk(from);
} else { } else {

View File

@ -2,6 +2,7 @@ package com.boydti.fawe.object.change;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.object.extent.FastWorldEditExtent; import com.boydti.fawe.object.extent.FastWorldEditExtent;
import com.boydti.fawe.util.ExtentTraverser;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.DoubleTag; import com.sk89q.jnbt.DoubleTag;
import com.sk89q.jnbt.LongTag; import com.sk89q.jnbt.LongTag;
@ -44,8 +45,9 @@ public class MutableEntityChange implements Change {
public void delete(UndoContext context) { public void delete(UndoContext context) {
Extent extent = context.getExtent(); Extent extent = context.getExtent();
if (extent.getClass() == FastWorldEditExtent.class) { ExtentTraverser<FastWorldEditExtent> find = new ExtentTraverser(extent).find(FastWorldEditExtent.class);
FastWorldEditExtent fwee = (FastWorldEditExtent) extent; if (find != null) {
FastWorldEditExtent fwee = find.get();
Map<String, Tag> map = tag.getValue(); Map<String, Tag> map = tag.getValue();
long most; long most;
long least; long least;
@ -72,8 +74,9 @@ public class MutableEntityChange implements Change {
public void create(UndoContext context) { public void create(UndoContext context) {
Extent extent = context.getExtent(); Extent extent = context.getExtent();
if (extent.getClass() == FastWorldEditExtent.class) { ExtentTraverser<FastWorldEditExtent> find = new ExtentTraverser(extent).find(FastWorldEditExtent.class);
FastWorldEditExtent fwee = (FastWorldEditExtent) extent; if (find != null) {
FastWorldEditExtent fwee = find.get();
Map<String, Tag> map = tag.getValue(); Map<String, Tag> map = tag.getValue();
List<DoubleTag> pos = (List<DoubleTag>) map.get("Pos").getValue(); List<DoubleTag> pos = (List<DoubleTag>) map.get("Pos").getValue();
int x = (int) Math.round(pos.get(0).getValue()); int x = (int) Math.round(pos.get(0).getValue());

View File

@ -2,6 +2,7 @@ package com.boydti.fawe.object.change;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.object.extent.FastWorldEditExtent; import com.boydti.fawe.object.extent.FastWorldEditExtent;
import com.boydti.fawe.util.ExtentTraverser;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
@ -37,8 +38,9 @@ public class MutableTileChange implements Change {
public void create(UndoContext context) { public void create(UndoContext context) {
Extent extent = context.getExtent(); Extent extent = context.getExtent();
if (extent.getClass() == FastWorldEditExtent.class) { ExtentTraverser<FastWorldEditExtent> find = new ExtentTraverser(extent).find(FastWorldEditExtent.class);
FastWorldEditExtent fwee = (FastWorldEditExtent) extent; if (find != null) {
FastWorldEditExtent fwee = find.get();
Map<String, Tag> map = tag.getValue(); Map<String, Tag> map = tag.getValue();
int x = ((IntTag) map.get("x")).getValue(); int x = ((IntTag) map.get("x")).getValue();
int y = ((IntTag) map.get("y")).getValue(); int y = ((IntTag) map.get("y")).getValue();

View File

@ -71,7 +71,9 @@ public abstract class FaweChangeSet implements ChangeSet {
public abstract Iterator<Change> getIterator(boolean redo); public abstract Iterator<Change> getIterator(boolean redo);
public EditSession toEditSession(FawePlayer player) { public EditSession toEditSession(FawePlayer player) {
return new EditSessionBuilder(world).player(player).autoQueue(false).fastmode(true).checkMemory(false).changeSet(this).allowedRegions(RegionWrapper.GLOBAL().toArray()).build(); EditSession editSession = new EditSessionBuilder(world).player(player).autoQueue(false).fastmode(false).checkMemory(false).changeSet(this).allowedRegions(RegionWrapper.GLOBAL().toArray()).build();
editSession.setSize(1);
return editSession;
} }
public void add(EntityCreate change) { public void add(EntityCreate change) {

View File

@ -12,7 +12,7 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.ConcurrentLinkedDeque;
public class DelegateFaweQueue extends FaweQueue { public class DelegateFaweQueue extends FaweQueue {
private final FaweQueue parent; private FaweQueue parent;
public DelegateFaweQueue(FaweQueue parent) { public DelegateFaweQueue(FaweQueue parent) {
super(parent.getWorldName()); super(parent.getWorldName());
@ -23,6 +23,10 @@ public class DelegateFaweQueue extends FaweQueue {
return parent; return parent;
} }
public void setParent(FaweQueue parent) {
this.parent = parent;
}
@Override @Override
public String getWorldName() { public String getWorldName() {
return parent.getWorldName(); return parent.getWorldName();

View File

@ -156,7 +156,7 @@ public class EditSession implements Extent {
private World world; private World world;
private FaweQueue queue; private FaweQueue queue;
private Extent bypassNone; private Extent extent;
private HistoryExtent history; private HistoryExtent history;
private Extent bypassHistory; private Extent bypassHistory;
private Extent bypassAll; private Extent bypassAll;
@ -248,19 +248,19 @@ public class EditSession implements Extent {
this.limit = limit; this.limit = limit;
this.queue = SetQueue.IMP.getNewQueue(Fawe.imp().getWorldName(world), fastmode, autoQueue); this.queue = SetQueue.IMP.getNewQueue(Fawe.imp().getWorldName(world), fastmode, autoQueue);
this.bypassAll = wrapExtent(new FastWorldEditExtent(world, queue), bus, event, Stage.BEFORE_CHANGE); this.bypassAll = wrapExtent(new FastWorldEditExtent(world, queue), bus, event, Stage.BEFORE_CHANGE);
this.bypassHistory = (bypassNone = wrapExtent(bypassAll, bus, event, Stage.BEFORE_REORDER)); this.bypassHistory = (this.extent = wrapExtent(bypassAll, bus, event, Stage.BEFORE_REORDER));
if (!fastmode && !(changeSet instanceof NullChangeSet)) { if (!fastmode && !(changeSet instanceof NullChangeSet)) {
if (combineStages) { if (combineStages) {
changeTask = changeSet; changeTask = changeSet;
changeSet.addChangeTask(queue); changeSet.addChangeTask(queue);
} else { } else {
this.bypassNone = (history = new HistoryExtent(this, bypassHistory, changeSet, queue)); this.extent = (history = new HistoryExtent(this, bypassHistory, changeSet, queue));
} }
} }
if (allowedRegions != null) { if (allowedRegions != null) {
this.bypassNone = new ProcessedWEExtent(bypassNone, allowedRegions, limit); this.extent = new ProcessedWEExtent(this.extent, allowedRegions, limit);
} }
bypassNone = wrapExtent(bypassNone, bus, event, Stage.BEFORE_HISTORY); this.extent = wrapExtent(this.extent, bus, event, Stage.BEFORE_HISTORY);
} }
/** /**
@ -302,7 +302,7 @@ public class EditSession implements Extent {
} }
public FaweRegionExtent getRegionExtent() { public FaweRegionExtent getRegionExtent() {
ExtentTraverser<FaweRegionExtent> traverser = new ExtentTraverser(bypassNone).find(FaweRegionExtent.class); ExtentTraverser<FaweRegionExtent> traverser = new ExtentTraverser(this.extent).find(FaweRegionExtent.class);
return traverser == null ? null : traverser.get(); return traverser == null ? null : traverser.get();
} }
@ -316,7 +316,7 @@ public class EditSession implements Extent {
} }
public boolean cancel() { public boolean cancel() {
ExtentTraverser traverser = new ExtentTraverser(bypassNone); ExtentTraverser traverser = new ExtentTraverser(this.extent);
NullExtent nullExtent = new NullExtent(world, BBC.WORLDEDIT_CANCEL_REASON_MANUAL); NullExtent nullExtent = new NullExtent(world, BBC.WORLDEDIT_CANCEL_REASON_MANUAL);
while (traverser != null) { while (traverser != null) {
ExtentTraverser next = traverser.next(); ExtentTraverser next = traverser.next();
@ -324,7 +324,7 @@ public class EditSession implements Extent {
traverser = next; traverser = next;
} }
bypassHistory = nullExtent; bypassHistory = nullExtent;
bypassNone = nullExtent; this.extent = nullExtent;
bypassAll = nullExtent; bypassAll = nullExtent;
dequeue(); dequeue();
queue.clear(); queue.clear();
@ -452,7 +452,7 @@ public class EditSession implements Extent {
* @return mask, may be null * @return mask, may be null
*/ */
public Mask getMask() { public Mask getMask() {
ExtentTraverser<MaskingExtent> maskingExtent = new ExtentTraverser(bypassNone).find(MaskingExtent.class); ExtentTraverser<MaskingExtent> maskingExtent = new ExtentTraverser(this.extent).find(MaskingExtent.class);
return maskingExtent != null ? maskingExtent.get().getMask() : null; return maskingExtent != null ? maskingExtent.get().getMask() : null;
} }
@ -465,11 +465,11 @@ public class EditSession implements Extent {
if (mask == null) { if (mask == null) {
mask = Masks.alwaysTrue(); mask = Masks.alwaysTrue();
} }
ExtentTraverser<MaskingExtent> maskingExtent = new ExtentTraverser(bypassNone).find(MaskingExtent.class); ExtentTraverser<MaskingExtent> maskingExtent = new ExtentTraverser(this.extent).find(MaskingExtent.class);
if (maskingExtent != null) { if (maskingExtent != null) {
maskingExtent.get().setMask(mask); maskingExtent.get().setMask(mask);
} else if (mask != Masks.alwaysTrue()) { } else if (mask != Masks.alwaysTrue()) {
bypassNone = new MaskingExtent(bypassNone, mask); this.extent = new MaskingExtent(this.extent, mask);
} }
} }
@ -494,11 +494,11 @@ public class EditSession implements Extent {
* @return the survival simulation extent * @return the survival simulation extent
*/ */
public SurvivalModeExtent getSurvivalExtent() { public SurvivalModeExtent getSurvivalExtent() {
ExtentTraverser<SurvivalModeExtent> survivalExtent = new ExtentTraverser(bypassNone).find(SurvivalModeExtent.class); ExtentTraverser<SurvivalModeExtent> survivalExtent = new ExtentTraverser(this.extent).find(SurvivalModeExtent.class);
if (survivalExtent != null) { if (survivalExtent != null) {
return survivalExtent.get(); return survivalExtent.get();
} else { } else {
return (SurvivalModeExtent) (bypassNone = new SurvivalModeExtent(bypassNone, getWorld())); return (SurvivalModeExtent) (this.extent = new SurvivalModeExtent(this.extent, getWorld()));
} }
} }
@ -522,7 +522,7 @@ public class EditSession implements Extent {
if (history == null) { if (history == null) {
return; return;
} }
ExtentTraverser traverseHistory = new ExtentTraverser(bypassNone).find(HistoryExtent.class); ExtentTraverser traverseHistory = new ExtentTraverser(this.extent).find(HistoryExtent.class);
if (disableHistory) { if (disableHistory) {
if (traverseHistory != null) { if (traverseHistory != null) {
ExtentTraverser beforeHistory = traverseHistory.previous(); ExtentTraverser beforeHistory = traverseHistory.previous();
@ -530,7 +530,7 @@ public class EditSession implements Extent {
beforeHistory.setNext(afterHistory.get()); beforeHistory.setNext(afterHistory.get());
} }
} else if (traverseHistory == null) { } else if (traverseHistory == null) {
ExtentTraverser traverseBypass = new ExtentTraverser(bypassNone).find(bypassHistory); ExtentTraverser traverseBypass = new ExtentTraverser(this.extent).find(bypassHistory);
if (traverseBypass != null) { if (traverseBypass != null) {
ExtentTraverser beforeHistory = traverseBypass.previous(); ExtentTraverser beforeHistory = traverseBypass.previous();
beforeHistory.setNext(history); beforeHistory.setNext(history);
@ -591,13 +591,13 @@ public class EditSession implements Extent {
@Override @Override
public BaseBiome getBiome(final Vector2D position) { public BaseBiome getBiome(final Vector2D position) {
return this.bypassNone.getBiome(position); return this.extent.getBiome(position);
} }
@Override @Override
public boolean setBiome(final Vector2D position, final BaseBiome biome) { public boolean setBiome(final Vector2D position, final BaseBiome biome) {
this.changes++; this.changes++;
return this.bypassNone.setBiome(position, biome); return this.extent.setBiome(position, biome);
} }
@Override @Override
@ -809,7 +809,7 @@ public class EditSession implements Extent {
this.changes++; this.changes++;
switch (stage) { switch (stage) {
case BEFORE_HISTORY: case BEFORE_HISTORY:
return this.bypassNone.setBlock(position, block); return this.extent.setBlock(position, block);
case BEFORE_CHANGE: case BEFORE_CHANGE:
return this.bypassHistory.setBlock(position, block); return this.bypassHistory.setBlock(position, block);
case BEFORE_REORDER: case BEFORE_REORDER:
@ -855,7 +855,7 @@ public class EditSession implements Extent {
public boolean setBlock(final Vector position, final BaseBlock block) throws MaxChangedBlocksException { public boolean setBlock(final Vector position, final BaseBlock block) throws MaxChangedBlocksException {
this.changes++; this.changes++;
try { try {
return this.bypassNone.setBlock(position, block); return this.extent.setBlock(position, block);
} catch (final MaxChangedBlocksException e) { } catch (final MaxChangedBlocksException e) {
throw e; throw e;
} catch (final WorldEditException e) { } catch (final WorldEditException e) {
@ -924,7 +924,7 @@ public class EditSession implements Extent {
@Override @Override
@Nullable @Nullable
public Entity createEntity(final com.sk89q.worldedit.util.Location location, final BaseEntity entity) { public Entity createEntity(final com.sk89q.worldedit.util.Location location, final BaseEntity entity) {
Entity result = this.bypassNone.createEntity(location, entity); Entity result = this.extent.createEntity(location, entity);
return result; return result;
} }
@ -1005,12 +1005,12 @@ public class EditSession implements Extent {
@Override @Override
public List<? extends Entity> getEntities(final Region region) { public List<? extends Entity> getEntities(final Region region) {
return this.bypassNone.getEntities(region); return this.extent.getEntities(region);
} }
@Override @Override
public List<? extends Entity> getEntities() { public List<? extends Entity> getEntities() {
return this.bypassNone.getEntities(); return this.extent.getEntities();
} }
/** /**
@ -1234,7 +1234,7 @@ public class EditSession implements Extent {
Iterator<BlockVector> iter = region.iterator(); Iterator<BlockVector> iter = region.iterator();
try { try {
while (iter.hasNext()) { while (iter.hasNext()) {
this.bypassNone.setBlock(iter.next(), block); this.extent.setBlock(iter.next(), block);
} }
} catch (final MaxChangedBlocksException e) { } catch (final MaxChangedBlocksException e) {
throw e; throw e;