From edd8dcc552817e2a450083cfb4539eb80d426e32 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 19 Jun 2017 16:38:07 +1000 Subject: [PATCH] Various minor Tweak some messages Add command confirmation Optimize surface mask Optimize angle mask (further) Fix help formatting Fix rollback import from disk being a shallow summary --- build.gradle | 2 +- .../fawe/command/FawePrimitiveBinding.java | 19 ++++ .../com/boydti/fawe/command/Rollback.java | 2 +- .../main/java/com/boydti/fawe/config/BBC.java | 2 + .../java/com/boydti/fawe/config/Settings.java | 7 +- .../com/boydti/fawe/object/FaweLimit.java | 4 + .../com/boydti/fawe/object/FawePlayer.java | 39 ++++++++ .../com/boydti/fawe/object/Metadatable.java | 4 +- .../fawe/object/brush/InspectBrush.java | 2 +- .../fawe/object/brush/SurfaceSphereBrush.java | 2 +- .../collection/LocalBlockVectorSet.java | 15 ++++ .../function/mask/AbstractDelegateMask.java | 4 + .../fawe/object/mask/AdjacentAnyMask.java | 55 ++++-------- .../boydti/fawe/object/mask/AngleMask.java | 43 +++++---- .../boydti/fawe/object/mask/CachedMask.java | 65 ++++++++++++++ .../boydti/fawe/object/mask/SurfaceMask.java | 4 +- .../fawe/regions/general/plot/MoveTo512.java | 88 +++++++++++++++++++ .../worldedit/command/HistoryCommands.java | 11 ++- .../worldedit/command/MethodCommands.java | 2 +- .../worldedit/command/RegionCommands.java | 13 +-- .../worldedit/command/UtilityCommands.java | 12 ++- 21 files changed, 324 insertions(+), 71 deletions(-) create mode 100644 core/src/main/java/com/boydti/fawe/object/mask/CachedMask.java create mode 100644 core/src/main/java/com/boydti/fawe/regions/general/plot/MoveTo512.java diff --git a/build.gradle b/build.gradle index ad5001ee..d5daa5e4 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ ext { date = git.head().date.format("yy.MM.dd") revision = "-${git.head().abbreviatedId}" parents = git.head().parentIds; - index = -93; // Offset to match CI + index = -94; // Offset to match CI int major, minor, patch; major = minor = patch = 0; for (;parents != null && !parents.isEmpty();index++) { diff --git a/core/src/main/java/com/boydti/fawe/command/FawePrimitiveBinding.java b/core/src/main/java/com/boydti/fawe/command/FawePrimitiveBinding.java index 956e506d..dce0828a 100644 --- a/core/src/main/java/com/boydti/fawe/command/FawePrimitiveBinding.java +++ b/core/src/main/java/com/boydti/fawe/command/FawePrimitiveBinding.java @@ -1,6 +1,7 @@ package com.boydti.fawe.command; import com.boydti.fawe.Fawe; +import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.extent.NullExtent; import com.boydti.fawe.object.extent.ResettableExtent; import com.sk89q.worldedit.WorldEdit; @@ -61,6 +62,24 @@ public class FawePrimitiveBinding extends BindingHelper { } } + /** + * Gets an {@link com.boydti.fawe.object.FawePlayer} from a {@link ArgumentStack}. + * + * @param context the context + * @return a FawePlayer + * @throws ParameterException on other error + */ + @BindingMatch(type = FawePlayer.class, + behavior = BindingBehavior.PROVIDES) + public FawePlayer getFawePlayer(ArgumentStack context) throws ParameterException, InputParseException { + Actor sender = context.getContext().getLocals().get(Actor.class); + if (sender == null) { + throw new ParameterException("Missing 'Actor'"); + } else { + return FawePlayer.wrap(sender); + } + } + /** * Gets an {@link com.sk89q.worldedit.extent.Extent} from a {@link ArgumentStack}. * diff --git a/core/src/main/java/com/boydti/fawe/command/Rollback.java b/core/src/main/java/com/boydti/fawe/command/Rollback.java index 61fe30c6..f98cbd7b 100644 --- a/core/src/main/java/com/boydti/fawe/command/Rollback.java +++ b/core/src/main/java/com/boydti/fawe/command/Rollback.java @@ -29,7 +29,7 @@ public class Rollback extends FaweCommand { @Override public boolean execute(final FawePlayer player, final String... args) { if (!Settings.IMP.HISTORY.USE_DATABASE) { - BBC.SETTING_DISABLE.send(player, "history.use-database"); + BBC.SETTING_DISABLE.send(player, "history.use-database (Import with /frb #import )"); return false; } if (args.length != 3) { diff --git a/core/src/main/java/com/boydti/fawe/config/BBC.java b/core/src/main/java/com/boydti/fawe/config/BBC.java index 791f2bc5..3a529695 100644 --- a/core/src/main/java/com/boydti/fawe/config/BBC.java +++ b/core/src/main/java/com/boydti/fawe/config/BBC.java @@ -172,6 +172,7 @@ public enum BBC { PLACE_DISABLED("Now placing at the block you stand in.", "WorldEdit.General"), KILL_SUCCESS("Killed %s0 entities in a radius of %s1.", "WorldEdit.Utility"), + NOTHING_CONFIRMED("You have no actions pending confirmation.", "WorldEdit.Utility"), SCHEMATIC_DELETE("%s0 has been deleted.", "Worldedit.Schematic"), @@ -234,6 +235,7 @@ public enum BBC { WORLDEDIT_SOME_FAILS_BLOCKBAG("&cMissing blocks: %s0", "Error"), WORLDEDIT_CANCEL_COUNT("&cCancelled %s0 edits.", "Cancel"), + WORLDEDIT_CANCEL_REASON_CONFIRM("&7Your selection is large (%s0 -> %s1). Use &c//confirm &7to execute &c%s2", "Cancel"), WORLDEDIT_CANCEL_REASON("&cYour WorldEdit action was cancelled:&7 %s0&c.", "Cancel"), WORLDEDIT_CANCEL_REASON_MANUAL("Manual cancellation", "Cancel"), WORLDEDIT_CANCEL_REASON_LOW_MEMORY("Low memory", "Cancel"), diff --git a/core/src/main/java/com/boydti/fawe/config/Settings.java b/core/src/main/java/com/boydti/fawe/config/Settings.java index 2f5397e6..a4ac3aa6 100644 --- a/core/src/main/java/com/boydti/fawe/config/Settings.java +++ b/core/src/main/java/com/boydti/fawe/config/Settings.java @@ -130,9 +130,13 @@ public class Settings extends Config { }) public int INVENTORY_MODE = 0; @Comment({ - "Place chunks instead of individual blocks" + "Place chunks instead of individual blocks" }) public boolean FAST_PLACEMENT = true; + @Comment({ + "Should large edits require confirmation (>16384 chunks)", + }) + public boolean CONFIRM_LARGE = true; } public static class HISTORY { @@ -402,6 +406,7 @@ public class Settings extends Config { limit.INVENTORY_MODE = Math.min(limit.INVENTORY_MODE, newLimit.INVENTORY_MODE); limit.SPEED_REDUCTION = Math.min(limit.SPEED_REDUCTION, newLimit.SPEED_REDUCTION); limit.FAST_PLACEMENT |= newLimit.FAST_PLACEMENT; + limit.CONFIRM_LARGE &= newLimit.CONFIRM_LARGE; } } return limit; diff --git a/core/src/main/java/com/boydti/fawe/object/FaweLimit.java b/core/src/main/java/com/boydti/fawe/object/FaweLimit.java index 84e7dcae..1158de1b 100644 --- a/core/src/main/java/com/boydti/fawe/object/FaweLimit.java +++ b/core/src/main/java/com/boydti/fawe/object/FaweLimit.java @@ -16,6 +16,7 @@ public class FaweLimit { public int INVENTORY_MODE = Integer.MAX_VALUE; public int SPEED_REDUCTION = Integer.MAX_VALUE; public boolean FAST_PLACEMENT = false; + public boolean CONFIRM_LARGE = true; public static FaweLimit MAX; @@ -58,6 +59,7 @@ public class FaweLimit { MAX.MAX_HISTORY = Integer.MAX_VALUE; MAX.MAX_EXPRESSION_MS = 50; MAX.FAST_PLACEMENT = true; + MAX.CONFIRM_LARGE = true; } public boolean MAX_CHANGES() { @@ -109,6 +111,7 @@ public class FaweLimit { INVENTORY_MODE = limit.INVENTORY_MODE; SPEED_REDUCTION = limit.SPEED_REDUCTION; FAST_PLACEMENT = limit.FAST_PLACEMENT; + CONFIRM_LARGE = limit.CONFIRM_LARGE; } public FaweLimit copy() { @@ -124,6 +127,7 @@ public class FaweLimit { limit.MAX_ITERATIONS = MAX_ITERATIONS; limit.MAX_HISTORY = MAX_HISTORY; limit.FAST_PLACEMENT = FAST_PLACEMENT; + limit.CONFIRM_LARGE = CONFIRM_LARGE; return limit; } diff --git a/core/src/main/java/com/boydti/fawe/object/FawePlayer.java b/core/src/main/java/com/boydti/fawe/object/FawePlayer.java index ff031bc1..00d712bd 100644 --- a/core/src/main/java/com/boydti/fawe/object/FawePlayer.java +++ b/core/src/main/java/com/boydti/fawe/object/FawePlayer.java @@ -21,9 +21,12 @@ import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.event.platform.CommandEvent; import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.extension.platform.CommandManager; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.regions.RegionOperationException; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.session.ClipboardHolder; @@ -64,6 +67,9 @@ public abstract class FawePlayer extends Metadatable { if (obj == null) { return FakePlayer.getConsole().toFawePlayer(); } + if (obj instanceof FawePlayer) { + return (FawePlayer) obj; + } if (obj instanceof FakePlayer) { return ((FakePlayer) obj).toFawePlayer(); } @@ -120,6 +126,39 @@ public abstract class FawePlayer extends Metadatable { } } + public void checkConfirmation(String command) throws RegionOperationException { + if (getMeta("cmdConfirmRunning", false)) { + return; + } + Region sel = getSelection(); + if (sel != null) { + Vector min = sel.getMinimumPoint(); + Vector max = sel.getMaximumPoint(); + int area = (int) ((max.getX() - min.getX()) * (max.getZ() - min.getZ() + 1)); + if (area > 2 << 22) { + setMeta("cmdConfirm", command); + throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM.f(min, max, command)); + } + } + } + + public boolean confirm() { + String confirm = deleteMeta("cmdConfirm"); + if (confirm == null) { + return false; + } + queueAction(new Runnable() { + @Override + public void run() { + setMeta("cmdConfirmRunning", true); + CommandEvent event = new CommandEvent(getPlayer(), confirm); + CommandManager.getInstance().handleCommandOnCurrentThread(event); + setMeta("cmdConfirmRunning", false); + } + }); + return true; + } + public boolean toggle(String perm) { if (this.hasPermission(perm)) { this.setPermission(perm, false); diff --git a/core/src/main/java/com/boydti/fawe/object/Metadatable.java b/core/src/main/java/com/boydti/fawe/object/Metadatable.java index 0b8f910b..2c57bf34 100644 --- a/core/src/main/java/com/boydti/fawe/object/Metadatable.java +++ b/core/src/main/java/com/boydti/fawe/object/Metadatable.java @@ -54,7 +54,7 @@ public class Metadatable { * - deleting other plugin's metadata may cause issues * @param key */ - public Object deleteMeta(String key) { - return this.meta == null ? null : this.meta.remove(key); + public V deleteMeta(String key) { + return this.meta == null ? null : (V) this.meta.remove(key); } } diff --git a/core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java b/core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java index 4972296a..e3af69fb 100644 --- a/core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java +++ b/core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java @@ -63,7 +63,7 @@ public class InspectBrush extends BrushTool implements DoubleActionTraceTool { return false; } if (!Settings.IMP.HISTORY.USE_DATABASE) { - player.print(BBC.getPrefix() + BBC.SETTING_DISABLE.f("history.use-database")); + player.print(BBC.getPrefix() + BBC.SETTING_DISABLE.f("history.use-database (Import with /frb #import )")); return false; } WorldVector target = getTarget(player, rightClick); diff --git a/core/src/main/java/com/boydti/fawe/object/brush/SurfaceSphereBrush.java b/core/src/main/java/com/boydti/fawe/object/brush/SurfaceSphereBrush.java index 4a9e3552..c3fa7544 100644 --- a/core/src/main/java/com/boydti/fawe/object/brush/SurfaceSphereBrush.java +++ b/core/src/main/java/com/boydti/fawe/object/brush/SurfaceSphereBrush.java @@ -19,7 +19,7 @@ public class SurfaceSphereBrush implements Brush { SurfaceMask surface = new SurfaceMask(editSession); final SolidBlockMask solid = new SolidBlockMask(editSession); final RadiusMask radius = new RadiusMask(0, (int) size); - RecursiveVisitor visitor = new RecursiveVisitor(vector -> radius.test(vector) && surface.test(vector), vector -> editSession.setBlock(vector, pattern)); + RecursiveVisitor visitor = new RecursiveVisitor(vector -> surface.test(vector) && radius.test(vector), vector -> editSession.setBlock(vector, pattern)); visitor.visit(position); visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS)); Operations.completeBlindly(visitor); diff --git a/core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVectorSet.java b/core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVectorSet.java index e3e92cde..54a00db1 100644 --- a/core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVectorSet.java +++ b/core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVectorSet.java @@ -182,6 +182,21 @@ public class LocalBlockVectorSet implements Set { return array; } + public boolean canAdd(int x, int y, int z) { + if (offsetX == Integer.MAX_VALUE) { + return false; + } + int relX = x - offsetX; + int relZ = z - offsetZ; + if (relX > 1023 || relX < -1024 || relZ > 1023 || relZ < -1024) { + return false; + } + if (y < 0 || y > 256) { + return false; + } + return true; + } + public boolean add(int x, int y, int z) { if (offsetX == Integer.MAX_VALUE) { offsetX = x; diff --git a/core/src/main/java/com/boydti/fawe/object/function/mask/AbstractDelegateMask.java b/core/src/main/java/com/boydti/fawe/object/function/mask/AbstractDelegateMask.java index 2473c625..6adcc0a0 100644 --- a/core/src/main/java/com/boydti/fawe/object/function/mask/AbstractDelegateMask.java +++ b/core/src/main/java/com/boydti/fawe/object/function/mask/AbstractDelegateMask.java @@ -14,6 +14,10 @@ public class AbstractDelegateMask extends AbstractMask { this.mask = parent; } + public final Mask getMask() { + return mask; + } + @Override public boolean test(Vector vector) { return mask.test(vector); diff --git a/core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java b/core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java index aacf8b12..36e32c57 100644 --- a/core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java +++ b/core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java @@ -10,15 +10,12 @@ import com.sk89q.worldedit.function.mask.Mask; */ public class AdjacentAnyMask extends AbstractMask implements ResettableMask { - private final Mask mask; + private final CachedMask mask; private transient MutableBlockVector mutable = new MutableBlockVector(); public AdjacentAnyMask(Mask mask) { - this.mask = mask; - } - - public Mask getMask() { - return mask; + this.mask = CachedMask.cache(mask); + mutable = new MutableBlockVector(); } @Override @@ -26,26 +23,21 @@ public class AdjacentAnyMask extends AbstractMask implements ResettableMask { mutable = new MutableBlockVector(); } + public CachedMask getParentMask() { + return mask; + } + @Override public boolean test(Vector v) { int x = v.getBlockX(); int y = v.getBlockY(); int z = v.getBlockZ(); - v.mutY(y + 1); - if (mask.test(v)) { v.mutY(y); return true; } - v.mutY(y - 1); - if (mask.test(v)) { v.mutY(y); return true; } - v.mutY(y); - v.mutX(x + 1); - if (mask.test(v)) { v.mutX(x); return true; } - v.mutX(x - 1); - if (mask.test(v)) { v.mutX(x); return true; } - v.mutX(x); - v.mutZ(z + 1); - if (mask.test(v)) { v.mutZ(z); return true; } - v.mutZ(z - 1); - if (mask.test(v)) { v.mutZ(z); return true; } - v.mutZ(z); + if (mask.test(x, y + 1, z)) { return true; } + if (mask.test(x + 1, y, z)) { return true; } + if (mask.test(x - 1, y, z)) { return true; } + if (mask.test(x, y, z + 1)) { return true; } + if (mask.test(x, y, z - 1)) { return true; } + if (mask.test(x, y - 1, z)) { return true; } return false; } @@ -53,21 +45,12 @@ public class AdjacentAnyMask extends AbstractMask implements ResettableMask { int x = v.getBlockX(); int y = v.getBlockY(); int z = v.getBlockZ(); - v.mutY(y + 1); - if (mask.test(v)) { v.mutY(y); return mutable.setComponents(0, 1, 0); } - v.mutY(y - 1); - if (mask.test(v)) { v.mutY(y); return mutable.setComponents(0, -1, 0); } - v.mutY(y); - v.mutX(x + 1); - if (mask.test(v)) { v.mutX(x); return mutable.setComponents(1, 0, 0); } - v.mutX(x - 1); - if (mask.test(v)) { v.mutX(x); return mutable.setComponents(-1, 0, 0); } - v.mutX(x); - v.mutZ(z + 1); - if (mask.test(v)) { v.mutZ(z); return mutable.setComponents(0, 0, 1); } - v.mutZ(z - 1); - if (mask.test(v)) { v.mutZ(z); return mutable.setComponents(0, 0, - 1); } - v.mutZ(z); + if (mask.test(x, y + 1, z)) { return mutable.setComponents(0, 1, 0); } + if (mask.test(x + 1, y, z)) { return mutable.setComponents(1, 0, 0); } + if (mask.test(x - 1, y, z)) { return mutable.setComponents(-1, 0, 0); } + if (mask.test(x, y, z + 1)) { return mutable.setComponents(0, 0, 1); } + if (mask.test(x, y, z - 1)) { return mutable.setComponents(0, 0, - 1); } + if (mask.test(x, y - 1, z)) { return mutable.setComponents(0, -1, 0); } return null; } } \ No newline at end of file diff --git a/core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java b/core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java index 7bad8c3e..57aa4f0a 100644 --- a/core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java +++ b/core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java @@ -33,6 +33,8 @@ public class AngleMask extends SolidBlockMask implements ResettableMask { mutable = new MutableBlockVector(); cacheBotX = Integer.MIN_VALUE; cacheBotZ = Integer.MIN_VALUE; + lastX = Integer.MIN_VALUE; + lastX = Integer.MIN_VALUE; if (cacheHeights != null) { Arrays.fill(cacheHeights, (byte) 0); } @@ -43,8 +45,12 @@ public class AngleMask extends SolidBlockMask implements ResettableMask { private transient int cacheBotX = Integer.MIN_VALUE; private transient int cacheBotZ = Integer.MIN_VALUE; private transient int cacheCenterZ; - private transient byte[] cacheHeights = null; - private transient int lastY = 0; + private transient byte[] cacheHeights; + private transient int lastY; + private transient int lastX = Integer.MIN_VALUE; + private transient int lastZ = Integer.MIN_VALUE; + private transient boolean foundY; + private transient boolean lastValue; public int getHeight(int x, int y, int z) { try { @@ -74,6 +80,22 @@ public class AngleMask extends SolidBlockMask implements ResettableMask { } } + private boolean testSlope(int x, int y, int z) { + double slope; + boolean aboveMin; + if ((lastX == (lastX = x) & lastZ == (lastZ = z))) { + return lastValue; + } + slope = Math.abs(getHeight(x + 1, y, z) - getHeight(x - 1, y, z)) * ADJACENT_MOD; + if (slope >= min && max >= Math.max(maxY - y, y)) { + return lastValue = true; + } + slope = Math.max(slope, Math.abs(getHeight(x, y, z + 1) - getHeight(x, y, z - 1)) * ADJACENT_MOD); + slope = Math.max(slope, Math.abs(getHeight(x + 1, y, z + 1) - getHeight(x - 1, y, z - 1)) * DIAGONAL_MOD); + slope = Math.max(slope, Math.abs(getHeight(x - 1, y, z + 1) - getHeight(x + 1, y, z - 1)) * DIAGONAL_MOD); + return lastValue = (slope >= min && slope <= max); + } + @Override public boolean test(Vector vector) { int x = vector.getBlockX(); @@ -83,20 +105,11 @@ public class AngleMask extends SolidBlockMask implements ResettableMask { if (!test(block.getId(), block.getData())) { return false; } - block = getExtent().getLazyBlock(x, y + 1, z); - if (overlay && test(block.getId(), block.getData())) { - return false; + if (overlay) { + block = getExtent().getLazyBlock(x, y + 1, z); + if (test(block.getId(), block.getData())) return lastValue = false; } - double slope; - boolean aboveMin; - slope = Math.abs(getHeight(x + 1, y, z) - getHeight(x - 1, y, z)) * ADJACENT_MOD; - if (slope >= min && max >= Math.max(maxY - y, y)) { - return true; - } - slope = Math.max(slope, Math.abs(getHeight(x, y, z + 1) - getHeight(x, y, z - 1)) * ADJACENT_MOD); - slope = Math.max(slope, Math.abs(getHeight(x + 1, y, z + 1) - getHeight(x - 1, y, z - 1)) * DIAGONAL_MOD); - slope = Math.max(slope, Math.abs(getHeight(x - 1, y, z + 1) - getHeight(x + 1, y, z - 1)) * DIAGONAL_MOD); - return (slope >= min && slope <= max); + return testSlope(x, y, z); } @Nullable diff --git a/core/src/main/java/com/boydti/fawe/object/mask/CachedMask.java b/core/src/main/java/com/boydti/fawe/object/mask/CachedMask.java new file mode 100644 index 00000000..f9c08fc1 --- /dev/null +++ b/core/src/main/java/com/boydti/fawe/object/mask/CachedMask.java @@ -0,0 +1,65 @@ +package com.boydti.fawe.object.mask; + +import com.boydti.fawe.object.collection.LocalBlockVectorSet; +import com.boydti.fawe.object.function.mask.AbstractDelegateMask; +import com.sk89q.worldedit.MutableBlockVector; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.function.mask.Mask; + +public class CachedMask extends AbstractDelegateMask implements ResettableMask { + + private transient MutableBlockVector mutable = new MutableBlockVector(); + private transient LocalBlockVectorSet cache_checked = new LocalBlockVectorSet(); + private transient LocalBlockVectorSet cache_results = new LocalBlockVectorSet(); + + public CachedMask(Mask mask) { + super(mask); + cache_checked.setOffset(Integer.MIN_VALUE, Integer.MIN_VALUE); + cache_results.setOffset(Integer.MIN_VALUE, Integer.MIN_VALUE); + } + + public static CachedMask cache(Mask mask) { + if (mask instanceof CachedMask) { + return (CachedMask) mask; + } + return new CachedMask(mask); + } + + @Override + public void reset() { + mutable = new MutableBlockVector(); + cache_checked = new LocalBlockVectorSet(); + cache_results = new LocalBlockVectorSet(); + resetCache(); + } + + private void resetCache() { + cache_checked.clear(); + cache_results.clear(); + cache_checked.setOffset(Integer.MIN_VALUE, Integer.MIN_VALUE); + cache_results.setOffset(Integer.MIN_VALUE, Integer.MIN_VALUE); + } + + @Override + public boolean test(Vector vector) { + return test(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); + } + + public boolean test(int x, int y, int z) { + if (cache_checked.contains(x, y, z)) { + return cache_results.contains(x, y, z); + } + boolean result = getMask().test(mutable.setComponents(x, y, z)); + try { + cache_checked.add(x, y, z); + if (result) cache_results.add(x, y, z); + } catch (UnsupportedOperationException ignore) { + resetCache(); + cache_checked.setOffset(x, z); + cache_results.setOffset(x, z); + cache_checked.add(x, y, z); + if (result) cache_results.add(x, y, z); + } + return result; + } +} diff --git a/core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java b/core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java index 3e462067..518608da 100644 --- a/core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java +++ b/core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java @@ -11,7 +11,7 @@ public class SurfaceMask extends AdjacentAnyMask { public SurfaceMask(Extent extent) { super(new BlockMask(extent, new BaseBlock(0))); - BlockMask mask = (BlockMask) getMask(); + BlockMask mask = (BlockMask) getParentMask().getMask(); for (int id = 0; id < 256; id++) { if (FaweCache.canPassThrough(id, 0)) { mask.add(new BaseBlock(id, -1)); @@ -22,6 +22,6 @@ public class SurfaceMask extends AdjacentAnyMask { @Override public boolean test(Vector v) { - return !getMask().test(v) && super.test(v); + return !getParentMask().test(v.getBlockX(), v.getBlockY(), v.getBlockZ()) && super.test(v); } } diff --git a/core/src/main/java/com/boydti/fawe/regions/general/plot/MoveTo512.java b/core/src/main/java/com/boydti/fawe/regions/general/plot/MoveTo512.java new file mode 100644 index 00000000..f8b04884 --- /dev/null +++ b/core/src/main/java/com/boydti/fawe/regions/general/plot/MoveTo512.java @@ -0,0 +1,88 @@ +package com.boydti.fawe.regions.general.plot; + +import com.boydti.fawe.jnbt.anvil.MCAChunk; +import com.boydti.fawe.jnbt.anvil.MCAQueue; +import com.boydti.fawe.jnbt.anvil.MCAWriter; +import com.boydti.fawe.object.FaweQueue; +import com.boydti.fawe.util.SetQueue; +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.commands.CommandCategory; +import com.intellectualcrafters.plot.commands.MainCommand; +import com.intellectualcrafters.plot.commands.RequiredType; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RunnableVal2; +import com.intellectualcrafters.plot.object.RunnableVal3; +import com.plotsquared.general.commands.Command; +import com.plotsquared.general.commands.CommandDeclaration; +import java.io.File; + +@CommandDeclaration( + command = "moveto512", + permission = "plots.moveto512", + category = CommandCategory.ADMINISTRATION, + requiredType = RequiredType.CONSOLE, + description = "Move plots to a 512 sized region", + usage = "/plots moveto512 [world]" +) +public class MoveTo512 extends Command { + public MoveTo512() { + super(MainCommand.getInstance(), true); + } + + @Override + public void execute(PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) throws CommandException { + checkTrue(args.length == 1, C.COMMAND_SYNTAX, getUsage()); + PlotArea area = PS.get().getPlotAreaByString(args[0]); + check(area, C.COMMAND_SYNTAX, getUsage()); + + FaweQueue defaultQueue = SetQueue.IMP.getNewQueue(area.worldname, true, false); + MCAQueue queueFrom = new MCAQueue(area.worldname, defaultQueue.getSaveFolder(), defaultQueue.hasSky()); + + File folder = null; // TODO + + int minRoad = 5; + PlotId nextId = new PlotId(0, 0); + for (Plot plot : area.getPlots()) { + Location bot = plot.getBottomAbs(); + Location top = plot.getTopAbs(); + + int pLen = Math.max(top.getX() - bot.getX(), 512 - minRoad); + int roadWidth = pLen - 512; + int roadPosLower; + if ((roadWidth & 1) == 0) { + roadPosLower = (short) (Math.floor(roadWidth / 2) - 1); + } else { + roadPosLower = (short) Math.floor(roadWidth / 2); + } + int roadPosUpper = 512 - roadWidth + roadPosLower; + MCAWriter writer = new MCAWriter(512, 512, folder) { + + @Override + public boolean shouldWrite(int chunkX, int chunkZ) { + return true; + } + + @Override + public MCAChunk write(MCAChunk input, int bx, int tx, int bz, int tz) { +// int obx = bx - oX; +// int obz = bz - oZ; +// int otx = tx - oX; +// int otz = tz - oZ; +// int otherBCX = (obx) >> 4; +// int otherBCZ = (obz) >> 4; +// int otherTCX = (otx) >> 4; +// int otherTCZ = (otz) >> 4; + return input; + } + }; + writer.setMCAOffset(nextId.x, nextId.y); + nextId = nextId.getNextId(1); + } + + } +} diff --git a/core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java b/core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java index f412a5d9..61425e57 100644 --- a/core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java +++ b/core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java @@ -74,14 +74,16 @@ public class HistoryCommands { @Command( aliases = { "/frb", "frb", "fawerollback", "/fawerollback", "/rollback" }, usage = " ", - desc = "Undo a specific edit. The time uses s, m, h, d, y.", + desc = "Undo a specific edit. " + + " - The time uses s, m, h, d, y.\n" + + " - Import from disk: /frb #import", min = 1, max = 3 ) @CommandPermissions("worldedit.history.rollback") public void faweRollback(final Player player, LocalSession session, final String user, @Optional("0") int radius, @Optional("0") String time) throws WorldEditException { if (!Settings.IMP.HISTORY.USE_DATABASE) { - BBC.SETTING_DISABLE.send(player, "history.use-database"); + BBC.SETTING_DISABLE.send(player, "history.use-database (Import with /frb #import )"); return; } switch (user.charAt(0)) { @@ -115,7 +117,7 @@ public class HistoryCommands { continue; } RollbackOptimizedHistory rollback = new RollbackOptimizedHistory(world, uuid, Integer.parseInt(name.substring(0, name.length() - 3))); - DiskStorageHistory.DiskStorageSummary summary = rollback.summarize(RegionWrapper.GLOBAL(), true); + DiskStorageHistory.DiskStorageSummary summary = rollback.summarize(RegionWrapper.GLOBAL(), false); if (summary != null) { rollback.setDimensions(new Vector(summary.minX, 0, summary.minZ), new Vector(summary.maxX, 255, summary.maxZ)); rollback.setTime(historyFile.lastModified()); @@ -125,6 +127,7 @@ public class HistoryCommands { } } } catch (IllegalArgumentException e) { + e.printStackTrace(); continue; } } @@ -135,7 +138,7 @@ public class HistoryCommands { } String toParse = user.substring(1); if (!MathMan.isInteger(toParse)) { - BBC.COMMAND_SYNTAX.send(player, "/frb