From 6882aa416d99e3034a28407c0a7c9d99397650a8 Mon Sep 17 00:00:00 2001 From: sk89q Date: Mon, 11 Oct 2010 11:21:43 -0700 Subject: [PATCH] Switched undo/redo buffer to use BlockPoint. Added Point.toBlockPoint(). --- src/EditSession.java | 24 ++++++++++++------------ src/com/sk89q/worldedit/Point.java | 9 +++++++++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/EditSession.java b/src/EditSession.java index 0b69515d9..a1889b5d8 100644 --- a/src/EditSession.java +++ b/src/EditSession.java @@ -36,15 +36,15 @@ public class EditSession { /** * Stores the original blocks before modification. */ - private HashMap original = new HashMap(); + private HashMap original = new HashMap(); /** * Stores the current blocks. */ - private HashMap current = new HashMap(); + private HashMap current = new HashMap(); /** * Queue. */ - private HashMap queue = new HashMap(); + private HashMap queue = new HashMap(); /** * The maximum number of blocks to change at a time. If this number is * exceeded, a MaxChangedBlocksException exception will be @@ -130,14 +130,14 @@ public class EditSession { public boolean setBlock(Point pt, int blockType) throws MaxChangedBlocksException { if (!original.containsKey(pt)) { - original.put(pt, getBlock(pt)); + original.put(pt.toBlockPoint(), getBlock(pt)); if (maxBlocks != -1 && original.size() > maxBlocks) { throw new MaxChangedBlocksException(maxBlocks); } } - current.put(pt, blockType); + current.put(pt.toBlockPoint(), blockType); return smartSetBlock(pt, blockType); } @@ -153,7 +153,7 @@ public class EditSession { if (queued) { if (blockType != 0 && queuedBlocks.contains(blockType) && rawGetBlock(pt.add(0, -1, 0)) == 0) { - queue.put(pt, blockType); + queue.put(pt.toBlockPoint(), blockType); return getBlock(pt) != blockType; } else if (blockType == 0 && queuedBlocks.contains(rawGetBlock(pt.add(0, 1, 0)))) { @@ -207,8 +207,8 @@ public class EditSession { * Restores all blocks to their initial state. */ public void undo() { - for (Map.Entry entry : original.entrySet()) { - Point pt = (Point)entry.getKey(); + for (Map.Entry entry : original.entrySet()) { + BlockPoint pt = (BlockPoint)entry.getKey(); smartSetBlock(pt, (int)entry.getValue()); } flushQueue(); @@ -218,8 +218,8 @@ public class EditSession { * Sets to new state. */ public void redo() { - for (Map.Entry entry : current.entrySet()) { - Point pt = (Point)entry.getKey(); + for (Map.Entry entry : current.entrySet()) { + BlockPoint pt = (BlockPoint)entry.getKey(); smartSetBlock(pt, (int)entry.getValue()); } flushQueue(); @@ -287,8 +287,8 @@ public class EditSession { public void flushQueue() { if (!queued) { return; } - for (Map.Entry entry : queue.entrySet()) { - Point pt = (Point)entry.getKey(); + for (Map.Entry entry : queue.entrySet()) { + BlockPoint pt = (BlockPoint)entry.getKey(); rawSetBlock(pt, (int)entry.getValue()); } } diff --git a/src/com/sk89q/worldedit/Point.java b/src/com/sk89q/worldedit/Point.java index 2401b07cd..80674ca6c 100644 --- a/src/com/sk89q/worldedit/Point.java +++ b/src/com/sk89q/worldedit/Point.java @@ -377,4 +377,13 @@ public class Point { public String toString() { return "(" + x + ", " + y + ", " + z + ")"; } + + /** + * Gets a BlockPoint version. + * + * @return BlockPoint + */ + public BlockPoint toBlockPoint() { + return new BlockPoint(this); + } }