Skip to content
Permalink
Browse files

Make lrbuild tool use history.

  • Loading branch information
wizjany committed Nov 9, 2019
1 parent e5fe051 commit 2b1a7ed9433b3b3a9e45bc8b82ca56159e3c131b
Showing with 41 additions and 25 deletions.
  1. +41 −25 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java
@@ -26,6 +26,7 @@
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
@@ -55,41 +56,56 @@ public boolean canUse(Actor player) {
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
Location pos = getTargetFace(player);
if (pos == null) return false;
try (EditSession eS = session.createEditSession(player)) {
eS.disableBuffering();
BlockVector3 blockPoint = pos.toVector().toBlockPoint();
BaseBlock applied = secondary.apply(blockPoint);
if (applied.getBlockType().getMaterial().isAir()) {
eS.setBlock(blockPoint, secondary);
} else {
eS.setBlock(pos.toVector().subtract(pos.getDirection()).toBlockPoint(), secondary);
BlockBag bag = session.getBlockBag(player);

try (EditSession editSession = session.createEditSession(player)) {
try {
editSession.disableBuffering();
BlockVector3 blockPoint = pos.toVector().toBlockPoint();
BaseBlock applied = secondary.apply(blockPoint);
if (applied.getBlockType().getMaterial().isAir()) {
editSession.setBlock(blockPoint, secondary);
} else {
editSession.setBlock(pos.toVector().subtract(pos.getDirection()).toBlockPoint(), secondary);
}
} catch (MaxChangedBlocksException ignored) {
} finally {
session.remember(editSession);
}
} finally {
if (bag != null) {
bag.flushChanges();
}
return true;
} catch (MaxChangedBlocksException ignored) {
// one block? eat it
}
return false;

return true;
}

@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
Location pos = getTargetFace(player);
if (pos == null) return false;
try (EditSession eS = session.createEditSession(player)) {
eS.disableBuffering();
BlockVector3 blockPoint = pos.toVector().toBlockPoint();
BaseBlock applied = primary.apply(blockPoint);
if (applied.getBlockType().getMaterial().isAir()) {
eS.setBlock(blockPoint, primary);
} else {
eS.setBlock(pos.toVector().subtract(pos.getDirection()).toBlockPoint(), primary);
BlockBag bag = session.getBlockBag(player);

try (EditSession editSession = session.createEditSession(player)) {
try {
editSession.disableBuffering();
BlockVector3 blockPoint = pos.toVector().toBlockPoint();
BaseBlock applied = primary.apply(blockPoint);
if (applied.getBlockType().getMaterial().isAir()) {
editSession.setBlock(blockPoint, primary);
} else {
editSession.setBlock(pos.toVector().subtract(pos.getDirection()).toBlockPoint(), primary);
}
} catch (MaxChangedBlocksException ignored) {
} finally {
session.remember(editSession);
}
} finally {
if (bag != null) {
bag.flushChanges();
}
return true;
} catch (MaxChangedBlocksException ignored) {
// one block? eat it
}
return false;
return true;
}

private Location getTargetFace(Player player) {

0 comments on commit 2b1a7ed

Please sign in to comment.
You can’t perform that action at this time.