This commit is contained in:
Jesse Boyd 2016-09-24 15:30:16 +10:00
parent f9ee91f192
commit 6d52e47d3f

View File

@ -83,26 +83,34 @@ public class Sniper {
// Added // Added
public AsyncWorld getWorld() { public AsyncWorld getWorld() {
if (permanentWorld == null) { synchronized (this) {
permanentWorld = new AsyncWorld(null, null); if (permanentWorld == null) {
} permanentWorld = new AsyncWorld(null, null);
if (this.maskQueue == null) {
Player player = getPlayer();
FawePlayer<Player> fp = FawePlayer.wrap(player);
if (this.baseQueue == null || !StringMan.isEqual(baseQueue.getWorldName(), player.getWorld().getName())) {
this.baseQueue = FaweAPI.createQueue(fp.getLocation().world, false);
} }
RegionWrapper[] mask = WEManager.IMP.getMask(fp); if (this.maskQueue == null) {
this.maskQueue = new MaskedFaweQueue(baseQueue, mask); Player player = getPlayer();
com.sk89q.worldedit.world.World worldEditWorld = fp.getWorld(); FawePlayer<Player> fp = FawePlayer.wrap(player);
FaweChangeSet changeSet = FaweChangeSet.getDefaultChangeSet(worldEditWorld, fp.getUUID()); if (this.baseQueue == null || !StringMan.isEqual(baseQueue.getWorldName(), player.getWorld().getName())) {
if (Fawe.imp().getBlocksHubApi() != null) { this.baseQueue = FaweAPI.createQueue(fp.getLocation().world, false);
changeSet = LoggingChangeSet.wrap(fp, changeSet); }
RegionWrapper[] mask = WEManager.IMP.getMask(fp);
this.maskQueue = new MaskedFaweQueue(baseQueue, mask);
com.sk89q.worldedit.world.World worldEditWorld = fp.getWorld();
FaweChangeSet changeSet = FaweChangeSet.getDefaultChangeSet(worldEditWorld, fp.getUUID());
if (Fawe.imp().getBlocksHubApi() != null) {
changeSet = LoggingChangeSet.wrap(fp, changeSet);
}
this.changeQueue = new ChangeSetFaweQueue(changeSet, maskQueue);
permanentWorld.changeWorld(player.getWorld(), changeQueue);
} }
this.changeQueue = new ChangeSetFaweQueue(changeSet, maskQueue); return permanentWorld;
permanentWorld.changeWorld(player.getWorld(), changeQueue); }
}
public void resetMask() {
synchronized (this) {
maskQueue = null;
} }
return permanentWorld;
} }
public Player getPlayer() { public Player getPlayer() {
@ -122,7 +130,7 @@ public class Sniper {
try { try {
Player player = getPlayer(); Player player = getPlayer();
FawePlayer<Player> fp = FawePlayer.wrap(player); FawePlayer<Player> fp = FawePlayer.wrap(player);
maskQueue = null; resetMask();
if (clickedBlock != null) { if (clickedBlock != null) {
clickedBlock = getWorld().getBlockAt(clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ()); clickedBlock = getWorld().getBlockAt(clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());
} }
@ -296,7 +304,7 @@ public class Sniper {
performerBrush.initP(snipeData); performerBrush.initP(snipeData);
} }
final FawePlayer<Player> fp = FawePlayer.wrap(getPlayer()); final FawePlayer<Player> fp = FawePlayer.wrap(getPlayer());
fp.runAction(new RunnableVal<Boolean>() { fp.runAsyncIfFree(new RunnableVal<Boolean>() {
@Override @Override
public void run(Boolean value) { public void run(Boolean value) {
boolean result = brush.perform(snipeAction, snipeData, targetBlock, lastBlock); boolean result = brush.perform(snipeAction, snipeData, targetBlock, lastBlock);
@ -305,7 +313,7 @@ public class Sniper {
} }
world.commit(); world.commit();
} }
}, true, true); });
return true; return true;
} }
} }
@ -375,18 +383,20 @@ public class Sniper {
} }
public void storeUndo(Undo undo) { public void storeUndo(Undo undo) {
if (changeQueue != null) { synchronized (this) {
FaweChangeSet changeSet = changeQueue.getChangeSet(); if (changeQueue != null) {
FawePlayer<Object> fp = FawePlayer.wrap(getPlayer()); FaweChangeSet changeSet = changeQueue.getChangeSet();
LocalSession session = fp.getSession(); FawePlayer<Object> fp = FawePlayer.wrap(getPlayer());
session.remember(changeSet.toEditSession(fp)); LocalSession session = fp.getSession();
com.sk89q.worldedit.world.World worldEditWorld = fp.getWorld(); session.remember(changeSet.toEditSession(fp));
changeSet = FaweChangeSet.getDefaultChangeSet(worldEditWorld, fp.getUUID()); com.sk89q.worldedit.world.World worldEditWorld = fp.getWorld();
changeQueue.setChangeSet(changeSet); changeSet = FaweChangeSet.getDefaultChangeSet(worldEditWorld, fp.getUUID());
// NEW QUEUE? changeQueue.setChangeSet(changeSet);
maskQueue = null; // NEW QUEUE?
baseQueue = null; maskQueue = null;
changeQueue = null; baseQueue = null;
changeQueue = null;
}
} }
} }