From 39a85d54ea6c1d9a76a86ce4e491f1f1802ba226 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 8 Sep 2018 01:31:30 +1000 Subject: [PATCH] pull changes from boy0001/FastAsyncWorldEdit --- .../com/boydti/fawe/object/FawePlayer.java | 39 +++---- .../worldedit/command/ClipboardCommands.java | 40 ++++--- .../worldedit/command/GenerationCommands.java | 109 +++++++++--------- .../worldedit/command/RegionCommands.java | 67 ++++++----- 4 files changed, 123 insertions(+), 132 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/FawePlayer.java b/worldedit-core/src/main/java/com/boydti/fawe/object/FawePlayer.java index 5d08d83fd..3feeea852 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/FawePlayer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/FawePlayer.java @@ -219,6 +219,22 @@ public abstract class FawePlayer extends Metadatable { if (task != null) task.run(); } + public synchronized boolean confirm() { + Runnable confirm = deleteMeta("cmdConfirm"); + if (!(confirm instanceof Runnable)) { + return false; + } + queueAction(() -> { + setMeta("cmdConfirmRunning", true); + try { + confirm.run(); + } finally { + setMeta("cmdConfirmRunning", false); + } + }); + return true; + } + public void checkAllowedRegion(Region wrappedSelection) { Region[] allowed = WEManager.IMP.getMask(this, FaweMaskManager.MaskType.OWNER); HashSet allowedSet = new HashSet<>(Arrays.asList(allowed)); @@ -229,29 +245,6 @@ public abstract class FawePlayer extends Metadatable { } } - public synchronized boolean confirm() { - Object confirm = deleteMeta("cmdConfirm"); - if (confirm == null) { - return false; - } - queueAction(() -> { - setMeta("cmdConfirmRunning", true); - try { - if (confirm instanceof String) { - CommandEvent event = new CommandEvent(getPlayer(), (String) confirm); - CommandManager.getInstance().handleCommandOnCurrentThread(event); - } else if (confirm instanceof Runnable) { - ((Runnable) confirm).run(); - } else { - throw new RuntimeException("Invalid confirm action: " + confirm); - } - } finally { - setMeta("cmdConfirmRunning", false); - } - }); - return true; - } - public boolean toggle(String perm) { if (this.hasPermission(perm)) { this.setPermission(perm, false); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java index 2716bdcb8..041438ee0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java @@ -151,19 +151,20 @@ public class ClipboardCommands extends MethodCommands { public void copy(FawePlayer fp, Player player, LocalSession session, EditSession editSession, @Selection Region region, @Switch('e') boolean skipEntities, @Switch('m') Mask mask, CommandContext context, @Switch('b') boolean copyBiomes) throws WorldEditException { + Vector min = region.getMinimumPoint(); + Vector max = region.getMaximumPoint(); + long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1)); + FaweLimit limit = FawePlayer.wrap(player).getLimit(); + if (volume >= limit.MAX_CHECKS) { + throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS); + } + Vector pos = session.getPlacementPosition(player); fp.checkConfirmationRegion(() -> { - Vector min = region.getMinimumPoint(); - Vector max = region.getMaximumPoint(); - long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1)); - FaweLimit limit = FawePlayer.wrap(player).getLimit(); - if (volume >= limit.MAX_CHECKS) { - throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS); - } session.setClipboard(null); BlockArrayClipboard clipboard = new BlockArrayClipboard(region, player.getUniqueId()); session.setClipboard(new ClipboardHolder(clipboard)); - clipboard.setOrigin(session.getPlacementPosition(player)); + clipboard.setOrigin(pos); ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint()); copy.setCopyingEntities(!skipEntities); copy.setCopyBiomes(copyBiomes); @@ -241,20 +242,21 @@ public class ClipboardCommands extends MethodCommands { public void cut(FawePlayer fp, Player player, LocalSession session, EditSession editSession, @Selection Region region, @Optional("air") Pattern leavePattern, @Switch('e') boolean skipEntities, @Switch('m') Mask mask, @Switch('b') boolean copyBiomes, CommandContext context) throws WorldEditException { + Vector min = region.getMinimumPoint(); + Vector max = region.getMaximumPoint(); + long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1)); + FaweLimit limit = FawePlayer.wrap(player).getLimit(); + if (volume >= limit.MAX_CHECKS) { + throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS); + } + if (volume >= limit.MAX_CHANGES) { + throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHANGES); + } + Vector pos = session.getPlacementPosition(player); fp.checkConfirmationRegion(() -> { - Vector min = region.getMinimumPoint(); - Vector max = region.getMaximumPoint(); - long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1)); - FaweLimit limit = FawePlayer.wrap(player).getLimit(); - if (volume >= limit.MAX_CHECKS) { - throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS); - } - if (volume >= limit.MAX_CHANGES) { - throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHANGES); - } session.setClipboard(null); BlockArrayClipboard clipboard = new BlockArrayClipboard(region, player.getUniqueId()); - clipboard.setOrigin(session.getPlacementPosition(player)); + clipboard.setOrigin(pos); ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint()); copy.setSourceFunction(new BlockReplace(editSession, leavePattern)); copy.setCopyingEntities(!skipEntities); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java index 8893c7a37..62ac71009 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java @@ -269,8 +269,6 @@ public class GenerationCommands extends MethodCommands { player.findFreePosition(); BBC.VISITOR_BLOCK.send(fp, affected); }, getArguments(context), (int) max); - - } @Command( @@ -366,34 +364,34 @@ public class GenerationCommands extends MethodCommands { @Switch('o') boolean offset, @Switch('c') boolean offsetCenter, CommandContext context) throws WorldEditException, ParameterException { + final Vector zero; + Vector unit; + + if (useRawCoords) { + zero = Vector.ZERO; + unit = Vector.ONE; + } else if (offset) { + zero = session.getPlacementPosition(player); + unit = Vector.ONE; + } else if (offsetCenter) { + final Vector min = region.getMinimumPoint(); + final Vector max = region.getMaximumPoint(); + + zero = max.add(min).multiply(0.5); + unit = Vector.ONE; + } else { + final Vector min = region.getMinimumPoint(); + final Vector max = region.getMaximumPoint(); + + zero = max.add(min).multiply(0.5); + unit = max.subtract(zero); + + if (unit.getX() == 0) unit.mutX(1); + if (unit.getY() == 0) unit.mutY(1); + if (unit.getZ() == 0) unit.mutZ(1); + } + fp.checkConfirmationRegion(() -> { - final Vector zero; - Vector unit; - - if (useRawCoords) { - zero = Vector.ZERO; - unit = Vector.ONE; - } else if (offset) { - zero = session.getPlacementPosition(player); - unit = Vector.ONE; - } else if (offsetCenter) { - final Vector min = region.getMinimumPoint(); - final Vector max = region.getMaximumPoint(); - - zero = max.add(min).multiply(0.5); - unit = Vector.ONE; - } else { - final Vector min = region.getMinimumPoint(); - final Vector max = region.getMaximumPoint(); - - zero = max.add(min).multiply(0.5); - unit = max.subtract(zero); - - if (unit.getX() == 0) unit.mutX(1); - if (unit.getY() == 0) unit.mutY(1); - if (unit.getZ() == 0) unit.mutZ(1); - } - try { final int affected = editSession.makeShape(region, zero, unit, pattern, expression, hollow); player.findFreePosition(); @@ -434,34 +432,33 @@ public class GenerationCommands extends MethodCommands { @Switch('o') boolean offset, @Switch('c') boolean offsetCenter, CommandContext context) throws WorldEditException, ParameterException { + final Vector zero; + Vector unit; + + if (useRawCoords) { + zero = Vector.ZERO; + unit = Vector.ONE; + } else if (offset) { + zero = session.getPlacementPosition(player); + unit = Vector.ONE; + } else if (offsetCenter) { + final Vector min = region.getMinimumPoint(); + final Vector max = region.getMaximumPoint(); + + zero = max.add(min).multiply(0.5); + unit = Vector.ONE; + } else { + final Vector min = region.getMinimumPoint(); + final Vector max = region.getMaximumPoint(); + + zero = max.add(min).multiply(0.5); + unit = max.subtract(zero); + + if (unit.getX() == 0) unit.mutX(1); + if (unit.getY() == 0) unit.mutY(1); + if (unit.getZ() == 0) unit.mutZ(1); + } fp.checkConfirmationRegion(() -> { - final Vector zero; - Vector unit; - - if (useRawCoords) { - zero = Vector.ZERO; - unit = Vector.ONE; - } else if (offset) { - zero = session.getPlacementPosition(player); - unit = Vector.ONE; - } else if (offsetCenter) { - final Vector min = region.getMinimumPoint(); - final Vector max = region.getMaximumPoint(); - - zero = max.add(min).multiply(0.5); - unit = Vector.ONE; - } else { - final Vector min = region.getMinimumPoint(); - final Vector max = region.getMaximumPoint(); - - zero = max.add(min).multiply(0.5); - unit = max.subtract(zero); - - if (unit.getX() == 0) unit.mutX(1); - if (unit.getY() == 0) unit.mutY(1); - if (unit.getZ() == 0) unit.mutZ(1); - } - try { final int affected = editSession.makeBiomeShape(region, zero, unit, target, expression, hollow); player.findFreePosition(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java index 97c7502a6..f313cc3e8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java @@ -465,23 +465,23 @@ public class RegionCommands extends MethodCommands { @CommandPermissions("worldedit.region.smoothsnow") @Logging(REGION) public void smooth(FawePlayer player, EditSession editSession, @Selection Region region, @Optional("1") int iterations, @Switch('n') boolean affectNatural, @Switch('s') boolean snow, CommandContext context) throws WorldEditException { - try { - Vector min = region.getMinimumPoint(); - Vector max = region.getMaximumPoint(); - long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1)); - FaweLimit limit = FawePlayer.wrap(player).getLimit(); - if (volume >= limit.MAX_CHECKS) { - throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS); - } - player.checkConfirmationRegion(() -> { + Vector min = region.getMinimumPoint(); + Vector max = region.getMaximumPoint(); + long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1)); + FaweLimit limit = FawePlayer.wrap(player).getLimit(); + if (volume >= limit.MAX_CHECKS) { + throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS); + } + player.checkConfirmationRegion(() -> { + try { HeightMap heightMap = new HeightMap(editSession, region, affectNatural, snow); HeightMapFilter filter = (HeightMapFilter) HeightMapFilter.class.getConstructors()[0].newInstance(GaussianKernel.class.getConstructors()[0].newInstance(5, 1)); int affected = heightMap.applyFilter(filter, iterations); BBC.VISITOR_BLOCK.send(player, affected); - }, getArguments(context), region); - } catch (Throwable e) { - throw new RuntimeException(e); - } + } catch (Throwable e) { + throw new RuntimeException(e); + } + }, getArguments(context), region); } @Command( @@ -653,28 +653,27 @@ public class RegionCommands extends MethodCommands { @Switch('r') boolean useRawCoords, @Switch('o') boolean offset, CommandContext context) throws WorldEditException { + final Vector zero; + Vector unit; + + if (useRawCoords) { + zero = Vector.ZERO; + unit = Vector.ONE; + } else if (offset) { + zero = session.getPlacementPosition(player); + unit = Vector.ONE; + } else { + final Vector min = region.getMinimumPoint(); + final Vector max = region.getMaximumPoint(); + + zero = max.add(min).multiply(0.5); + unit = max.subtract(zero); + + if (unit.getX() == 0) unit.mutX(1); + if (unit.getY() == 0) unit.mutY(1); + if (unit.getZ() == 0) unit.mutZ(1); + } fp.checkConfirmationRegion(() -> { - final Vector zero; - Vector unit; - - if (useRawCoords) { - zero = Vector.ZERO; - unit = Vector.ONE; - } else if (offset) { - zero = session.getPlacementPosition(player); - unit = Vector.ONE; - } else { - final Vector min = region.getMinimumPoint(); - final Vector max = region.getMaximumPoint(); - - zero = max.add(min).multiply(0.5); - unit = max.subtract(zero); - - if (unit.getX() == 0) unit.mutX(1); - if (unit.getY() == 0) unit.mutY(1); - if (unit.getZ() == 0) unit.mutZ(1); - } - try { final int affected = editSession.deformRegion(region, zero, unit, expression); player.findFreePosition();