From 9623c5cb3fd5611da243824eb5946eb7f35005cb Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 6 Jan 2020 09:06:38 +0000 Subject: [PATCH] all hsitory types can summarize --- .../object/changeset/DiskStorageHistory.java | 1 + .../changeset}/SimpleChangeSetSummary.java | 10 ++++++++++ .../history/changeset/ArrayListHistory.java | 16 +++++++++++++++ .../history/changeset/ChangeSet.java | 20 +++++++------------ 4 files changed, 34 insertions(+), 13 deletions(-) rename worldedit-core/src/main/java/{ => com/boydti/fawe/object/changeset}/SimpleChangeSetSummary.java (82%) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java index 40330a4af..3ed20bbd3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java @@ -399,6 +399,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet { return new SimpleChangeSetSummary(getOriginX(), getOriginZ()); } + @Override public SimpleChangeSetSummary summarize(Region region, boolean shallow) { if (bdFile.exists()) { int ox = getOriginX(); diff --git a/worldedit-core/src/main/java/SimpleChangeSetSummary.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/SimpleChangeSetSummary.java similarity index 82% rename from worldedit-core/src/main/java/SimpleChangeSetSummary.java rename to worldedit-core/src/main/java/com/boydti/fawe/object/changeset/SimpleChangeSetSummary.java index a60476355..1eec14c7b 100644 --- a/worldedit-core/src/main/java/SimpleChangeSetSummary.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/SimpleChangeSetSummary.java @@ -1,3 +1,5 @@ +package com.boydti.fawe.object.changeset; + import com.sk89q.worldedit.history.changeset.ChangeSetSummary; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypesCache; @@ -14,6 +16,14 @@ public class SimpleChangeSetSummary implements ChangeSetSummary { public int maxX; public int maxZ; + public SimpleChangeSetSummary() { + blocks = new int[BlockTypesCache.states.length]; + this.minX = Integer.MAX_VALUE; + this.minZ = Integer.MAX_VALUE; + this.maxX = Integer.MIN_VALUE; + this.maxZ = Integer.MIN_VALUE; + } + public SimpleChangeSetSummary(int x, int z) { blocks = new int[BlockTypesCache.states.length]; minX = x; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ArrayListHistory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ArrayListHistory.java index d014835d3..47c957419 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ArrayListHistory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ArrayListHistory.java @@ -21,8 +21,12 @@ package com.sk89q.worldedit.history.changeset; import static com.google.common.base.Preconditions.checkNotNull; +import com.boydti.fawe.object.changeset.SimpleChangeSetSummary; import com.google.common.collect.Lists; +import com.sk89q.worldedit.history.change.BlockChange; import com.sk89q.worldedit.history.change.Change; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.Region; import java.util.ArrayList; import java.util.Iterator; @@ -70,4 +74,16 @@ public class ArrayListHistory implements ChangeSet { return changes.size(); } + @Override + public ChangeSetSummary summarize(Region region, boolean shallow) { + SimpleChangeSetSummary summary = new SimpleChangeSetSummary(); + for (Change change : changes) { + if (change instanceof BlockChange) { + BlockChange blockChange = (BlockChange) change; + BlockVector3 pos = blockChange.getPosition(); + summary.add(pos.getX(), pos.getZ(), blockChange.getCurrent().getOrdinal()); + } + } + return summary; + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ChangeSet.java b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ChangeSet.java index b988f6118..57887b7e1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ChangeSet.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ChangeSet.java @@ -97,19 +97,13 @@ public interface ChangeSet extends Closeable { */ default void delete() {} - ChangeSetSummary summarize(Region region, boolean shallow) { - return new ChangeSetSummary() { - @Override - public Map getBlocks() { - return Collections.emptyMap(); - } - - @Override - public int getSize() { - return size(); - } - }; - } + /** + * Get a summary of this changeset + * @param region + * @param shallow + * @return + */ + ChangeSetSummary summarize(Region region, boolean shallow); /** * Get if the changeset is empty (i.e. size == 0)