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 33f956d3c..a89e22cb6 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 @@ -184,19 +184,19 @@ public class GenerationCommands { ) @CommandPermissions("worldedit.generation.cylinder") @Logging(PLACEMENT) - public void hcyl(Player fp, Player player, LocalSession session, EditSession editSession, + public void hcyl(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "The pattern of blocks to generate") - Pattern pattern, + Pattern pattern, BlockVector2 radius, @Arg(desc = "The height of the cylinder", def = "1") int height, @Range(min = 1) @Arg(name = "thickness", desc = "double", def = "1") double thickness, InjectedValueAccess context) throws WorldEditException { double max = MathMan.max(radius.getBlockX(), radius.getBlockZ()); worldEdit.checkMaxRadius(max); - BlockVector3 pos = session.getPlacementPosition(player); - fp.checkConfirmationRadius(() -> { + BlockVector3 pos = session.getPlacementPosition(actor); + actor.checkConfirmationRadius(() -> { int affected = editSession.makeHollowCylinder(pos, pattern, radius.getX(), radius.getZ(), Math.min(256, height), thickness - 1); - BBC.VISITOR_BLOCK.send(fp, affected); + BBC.VISITOR_BLOCK.send(actor, affected); }, "/hcyl", (int) max, context); } @@ -206,20 +206,20 @@ public class GenerationCommands { ) @CommandPermissions("worldedit.generation.cylinder") @Logging(PLACEMENT) - public void cyl(Player player, LocalSession session, EditSession editSession, + public void cyl(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "The pattern of blocks to generate") - Pattern pattern, + Pattern pattern, BlockVector2 radius, @Arg(desc = "The height of the cylinder", def = "1") - int height, + int height, @Switch(name = 'h', desc = "Make a hollow cylinder") - boolean hollow, InjectedValueAccess context) throws WorldEditException { + boolean hollow, InjectedValueAccess context) throws WorldEditException { double max = Math.max(radius.getBlockX(), radius.getBlockZ()); worldEdit.checkMaxRadius(max); - BlockVector3 pos = session.getPlacementPosition(player); - player.checkConfirmationRadius(() -> { + BlockVector3 pos = session.getPlacementPosition(actor); + actor.checkConfirmationRadius(() -> { int affected = editSession.makeCylinder(pos, pattern, radius.getX(), radius.getZ(), Math.min(256, height), !hollow); - BBC.VISITOR_BLOCK.send(player, affected); + BBC.VISITOR_BLOCK.send(actor, affected); }, "/cyl", (int) max, context); } @@ -229,14 +229,14 @@ public class GenerationCommands { ) @CommandPermissions("worldedit.generation.sphere") @Logging(PLACEMENT) - public void hsphere(Player player, LocalSession session, EditSession editSession, + public void hsphere(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "The pattern of blocks to generate") Pattern pattern, @Arg(desc = "The radii of the sphere. Order is N/S, U/D, E/W") BlockVector3 radii, @Switch(name = 'r', desc = "Raise the bottom of the sphere to the placement position") boolean raised, InjectedValueAccess context) throws WorldEditException { - sphere(player, session, editSession, pattern, radii, raised, true, context); + sphere(actor, session, editSession, pattern, radii, raised, true, context); } @Command( @@ -245,7 +245,7 @@ public class GenerationCommands { ) @CommandPermissions("worldedit.generation.sphere") @Logging(PLACEMENT) - public void sphere(Player player, LocalSession session, EditSession editSession, + public void sphere(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "The pattern of blocks to generate") Pattern pattern, @Arg(desc = "The radii of the sphere. Order is N/S, U/D, E/W") @@ -256,12 +256,14 @@ public class GenerationCommands { boolean hollow, InjectedValueAccess context) throws WorldEditException { double max = MathMan.max(radii.getBlockX(), radii.getBlockY(), radii.getBlockZ()); worldEdit.checkMaxRadius(max); - BlockVector3 pos = session.getPlacementPosition(player); + BlockVector3 pos = session.getPlacementPosition(actor); BlockVector3 finalPos = raised ? pos.add(0, radii.getY(), 0) : pos; - player.checkConfirmationRadius(() -> { + actor.checkConfirmationRadius(() -> { int affected = editSession.makeSphere(finalPos, pattern, radii.getX(), radii.getY(), radii.getZ(), !hollow); - player.findFreePosition(); - BBC.VISITOR_BLOCK.send(player, affected); + if (actor instanceof Player) { + ((Player) actor).findFreePosition(); + } + BBC.VISITOR_BLOCK.send(actor, affected); }, "sphere", (int) max, context); } @@ -312,12 +314,12 @@ public class GenerationCommands { ) @CommandPermissions("worldedit.generation.pyramid") @Logging(PLACEMENT) - public void hollowPyramid(Player fp, Player player, LocalSession session, EditSession editSession, + public void hollowPyramid(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "The pattern of blocks to set") Pattern pattern, @Arg(desc = "The size of the pyramid") int size, InjectedValueAccess context) throws WorldEditException { - pyramid(fp, player, session, editSession, pattern, size, true, context); + pyramid(actor, session, editSession, pattern, size, true, context); } @Command( @@ -326,7 +328,7 @@ public class GenerationCommands { ) @CommandPermissions("worldedit.generation.pyramid") @Logging(PLACEMENT) - public void pyramid(Player fp, Player player, LocalSession session, EditSession editSession, + public void pyramid(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "The pattern of blocks to set") Pattern pattern, @Arg(desc = "The size of the pyramid") @@ -334,12 +336,14 @@ public class GenerationCommands { @Switch(name = 'h', desc = "Make a hollow pyramid") boolean hollow, InjectedValueAccess context) throws WorldEditException { - BlockVector3 pos = session.getPlacementPosition(player); + BlockVector3 pos = session.getPlacementPosition(actor); worldEdit.checkMaxRadius(size); - fp.checkConfirmationRadius(() -> { + actor.checkConfirmationRadius(() -> { int affected = editSession.makePyramid(pos, pattern, size, !hollow); - player.findFreePosition(); - BBC.VISITOR_BLOCK.send(fp, affected); + if (actor instanceof Player) { + ((Player) actor).findFreePosition(); + } + BBC.VISITOR_BLOCK.send(actor, affected); }, getArguments(context), size, context); } @@ -351,7 +355,7 @@ public class GenerationCommands { ) @CommandPermissions("worldedit.generation.shape") @Logging(ALL) - public void generate(Player fp, Player player, LocalSession session, EditSession editSession, + public void generate(Actor actor, LocalSession session, EditSession editSession, @Selection Region region, @Arg(desc = "The pattern of blocks to set") Pattern pattern, @@ -374,7 +378,7 @@ public class GenerationCommands { zero = Vector3.ZERO; unit = Vector3.ONE; } else if (offset) { - zero = session.getPlacementPosition(player).toVector3(); + zero = session.getPlacementPosition(actor).toVector3(); unit = Vector3.ONE; } else if (offsetCenter) { final Vector3 min = region.getMinimumPoint().toVector3(); @@ -396,13 +400,15 @@ public class GenerationCommands { final Vector3 unit1 = unit; - fp.checkConfirmationRegion(() -> { + actor.checkConfirmationRegion(() -> { try { final int affected = editSession.makeShape(region, zero, unit1, pattern, String.join(" ", expression), hollow, session.getTimeout()); - player.findFreePosition(); - BBC.VISITOR_BLOCK.send(fp, affected); + if (actor instanceof Player) { + ((Player) actor).findFreePosition(); + } + BBC.VISITOR_BLOCK.send(actor, affected); } catch (ExpressionException e) { - player.printError(e.getMessage()); + actor.printError(e.getMessage()); } }, "/generate", region, context); } @@ -417,7 +423,7 @@ public class GenerationCommands { ) @CommandPermissions("worldedit.generation.shape.biome") @Logging(ALL) - public void generateBiome(Player fp, LocalSession session, EditSession editSession, + public void generateBiome(Actor actor, LocalSession session, EditSession editSession, @Selection Region region, @Arg(desc = "The biome type to set") BiomeType target, @@ -439,7 +445,7 @@ public class GenerationCommands { zero = Vector3.ZERO; unit = Vector3.ONE; } else if (offset) { - zero = session.getPlacementPosition(fp).toVector3(); + zero = session.getPlacementPosition(actor).toVector3(); unit = Vector3.ONE; } else if (offsetCenter) { final Vector3 min = region.getMinimumPoint().toVector3(); @@ -460,12 +466,12 @@ public class GenerationCommands { } final Vector3 unit1 = unit; - fp.checkConfirmationRegion(() -> { + actor.checkConfirmationRegion(() -> { try { final int affected = editSession.makeBiomeShape(region, zero, unit1, target, String.join(" ", expression), hollow, session.getTimeout()); - BBC.VISITOR_FLAT.send(fp, affected); + BBC.VISITOR_FLAT.send(actor, affected); } catch (ExpressionException e) { - fp.printError(e.getMessage()); + actor.printError(e.getMessage()); } }, "/generatebiome", region, context); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java index 8f4c5602f..00d8e9119 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java @@ -20,7 +20,6 @@ package com.sk89q.worldedit.entity; import com.boydti.fawe.Fawe; -import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.FaweLimit; import com.boydti.fawe.object.brush.visualization.VirtualWorld; @@ -40,7 +39,6 @@ import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.regions.RegionOperationException; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.util.Direction; @@ -51,10 +49,7 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.gamemode.GameMode; import java.io.File; -import java.text.NumberFormat; import javax.annotation.Nullable; -import org.enginehub.piston.inject.InjectedValueAccess; -import org.jetbrains.annotations.NotNull; /** * Represents a player @@ -329,15 +324,6 @@ public interface Player extends Entity, Actor { return Settings.IMP.getLimit(this); } - void checkConfirmationStack(@NotNull Runnable task, @NotNull String command, - Region region, int times, InjectedValueAccess context) throws RegionOperationException; - - void checkConfirmationRegion(@NotNull Runnable task, @NotNull String command, - Region region, InjectedValueAccess context) throws RegionOperationException; - - void setConfirmTask(@NotNull Runnable task, InjectedValueAccess context, - @NotNull String command); - public Region[] getCurrentRegions(); Region[] getCurrentRegions(FaweMaskManager.MaskType type); @@ -386,36 +372,6 @@ public interface Player extends Entity, Actor { return WorldEdit.getInstance().getPlatformManager().getWorldForEditing(getWorld()); } - void checkConfirmation(@NotNull Runnable task, @NotNull String command, int times, - int limit, InjectedValueAccess context) throws RegionOperationException; - - default void checkConfirmationRadius(@NotNull Runnable task, String command, int radius, - InjectedValueAccess context) throws RegionOperationException { - if (command != null && !getMeta("cmdConfirmRunning", false)) { - if (radius > 0) { - if (radius > 448) { - setConfirmTask(task, context, command); - long volume = (long) (Math.PI * ((double) radius * radius)); - throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM - .format(0, radius, command, - NumberFormat.getNumberInstance().format(volume))); - } - } - } - task.run(); - } - - boolean confirm(); - - /** - * Queue an action to run async - * - * @param run - */ - default void queueAction(Runnable run) { - runAction(run, false, true); - } - default boolean runAsyncIfFree(Runnable r) { return runAction(r, true, true); } @@ -424,13 +380,6 @@ public interface Player extends Entity, Actor { return runAction(r, true, false); } - default boolean checkAction() { - long time = getMeta("faweActionTick", Long.MIN_VALUE); - long tick = Fawe.get().getTimer().getTick(); - setMeta("faweActionTick", tick); - return tick > time; - } - /** * Unregister this player (deletes all metadata etc) - Usually called on logout */ diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java index abc72d2d4..3bf4cc037 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java @@ -19,7 +19,6 @@ package com.sk89q.worldedit.extension.platform; -import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.object.task.SimpleAsyncNotifyQueue; import com.boydti.fawe.regions.FaweMaskManager; @@ -30,7 +29,6 @@ import com.sk89q.worldedit.MaxChangedBlocksException; 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.extent.Extent; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.internal.cui.CUIEvent; @@ -41,7 +39,6 @@ import com.sk89q.worldedit.regions.ConvexPolyhedralRegion; import com.sk89q.worldedit.regions.CylinderRegion; import com.sk89q.worldedit.regions.Polygonal2DRegion; import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.regions.RegionOperationException; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; @@ -65,12 +62,9 @@ import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.registry.BlockMaterial; import java.io.File; -import java.text.NumberFormat; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Nullable; -import org.enginehub.piston.inject.InjectedValueAccess; -import org.jetbrains.annotations.NotNull; /** * An abstract implementation of both a {@link Actor} and a {@link Player} @@ -716,57 +710,6 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { return true; } - public void checkConfirmationStack(@NotNull Runnable task, @NotNull String command, - Region region, int times, InjectedValueAccess context) throws RegionOperationException { - if (!getMeta("cmdConfirmRunning", false)) { - if (region != null) { - BlockVector3 min = region.getMinimumPoint(); - BlockVector3 max = region.getMaximumPoint(); - long area = - (long) ((max.getX() - min.getX()) * (max.getZ() - min.getZ() + 1)) * times; - if (area > 2 << 18) { - setConfirmTask(task, context, command); - BlockVector3 base = max.subtract(min).add(BlockVector3.ONE); - long volume = (long) base.getX() * base.getZ() * base.getY() * times; - throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM - .format(min, max, command, - NumberFormat.getNumberInstance().format(volume))); - } - } - } - task.run(); - } - - public void checkConfirmationRegion(@NotNull Runnable task, @NotNull String command, - Region region, InjectedValueAccess context) throws RegionOperationException { - if (!getMeta("cmdConfirmRunning", false)) { - if (region != null) { - BlockVector3 min = region.getMinimumPoint(); - BlockVector3 max = region.getMaximumPoint(); - long area = (max.getX() - min.getX()) * (max.getZ() - min.getZ() + 1); - if (area > 2 << 18) { - setConfirmTask(task, context, command); - BlockVector3 base = max.subtract(min).add(BlockVector3.ONE); - long volume = (long) base.getX() * base.getZ() * base.getY(); - throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM - .format(min, max, command, - NumberFormat.getNumberInstance().format(volume))); - } - } - } - task.run(); - } - - public void setConfirmTask(@NotNull Runnable task, InjectedValueAccess context, - @NotNull String command) { - CommandEvent event = new CommandEvent(this, command); - Runnable newTask = () -> PlatformCommandManager.getInstance().handleCommandTask(() -> { - task.run(); - return null; - }, context, getSession(), event); - setMeta("cmdConfirm", newTask); - } - /** * Get the player's current allowed WorldEdit regions * @@ -817,33 +760,4 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { getSession().setRegionSelector(getWorld(), selector); } - public void checkConfirmation(@NotNull Runnable task, @NotNull String command, int times, - int limit, InjectedValueAccess context) throws RegionOperationException { - if (!getMeta("cmdConfirmRunning", false)) { - if (times > limit) { - setConfirmTask(task, context, command); - String volume = ""; - throw new RegionOperationException( - BBC.WORLDEDIT_CANCEL_REASON_CONFIRM.format(0, times, command, volume)); - } - } - task.run(); - } - - public synchronized boolean confirm() { - Runnable confirm = deleteMeta("cmdConfirm"); - if (confirm == null) { - return false; - } - queueAction(() -> { - setMeta("cmdConfirmRunning", true); - try { - confirm.run(); - } finally { - setMeta("cmdConfirmRunning", false); - } - }); - return true; - } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Actor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Actor.java index b6139a4ca..09f95f3aa 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Actor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Actor.java @@ -19,14 +19,23 @@ package com.sk89q.worldedit.extension.platform; +import com.boydti.fawe.Fawe; +import com.boydti.fawe.config.BBC; import com.sk89q.worldedit.entity.Metadatable; +import com.sk89q.worldedit.event.platform.CommandEvent; import com.sk89q.worldedit.internal.cui.CUIEvent; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.regions.RegionOperationException; import com.sk89q.worldedit.session.SessionOwner; import com.sk89q.worldedit.util.Identifiable; import com.sk89q.worldedit.util.auth.Subject; import com.sk89q.worldedit.util.formatting.text.Component; import java.io.File; +import java.text.NumberFormat; +import org.enginehub.piston.inject.InjectedValueAccess; +import org.jetbrains.annotations.NotNull; /** * An object that can perform actions in WorldEdit. @@ -123,4 +132,115 @@ public interface Actor extends Identifiable, SessionOwner, Subject, Metadatable boolean runAction(Runnable ifFree, boolean checkFree, boolean async); + default void checkConfirmationStack(@NotNull Runnable task, @NotNull String command, + Region region, int times, InjectedValueAccess context) throws RegionOperationException { + if (!getMeta("cmdConfirmRunning", false)) { + if (region != null) { + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); + long area = + (long) ((max.getX() - min.getX()) * (max.getZ() - min.getZ() + 1)) * times; + if (area > 2 << 18) { + setConfirmTask(task, context, command); + BlockVector3 base = max.subtract(min).add(BlockVector3.ONE); + long volume = (long) base.getX() * base.getZ() * base.getY() * times; + throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM + .format(min, max, command, + NumberFormat.getNumberInstance().format(volume))); + } + } + } + task.run(); + } + + default void checkConfirmationRegion(@NotNull Runnable task, @NotNull String command, + Region region, InjectedValueAccess context) throws RegionOperationException { + if (!getMeta("cmdConfirmRunning", false)) { + if (region != null) { + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); + long area = (max.getX() - min.getX()) * (max.getZ() - min.getZ() + 1); + if (area > 2 << 18) { + setConfirmTask(task, context, command); + BlockVector3 base = max.subtract(min).add(BlockVector3.ONE); + long volume = (long) base.getX() * base.getZ() * base.getY(); + throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM + .format(min, max, command, + NumberFormat.getNumberInstance().format(volume))); + } + } + } + task.run(); + } + + default void setConfirmTask(@NotNull Runnable task, InjectedValueAccess context, + @NotNull String command) { + CommandEvent event = new CommandEvent(this, command); + Runnable newTask = () -> PlatformCommandManager.getInstance().handleCommandTask(() -> { + task.run(); + return null; + }, context, getSession(), event); + setMeta("cmdConfirm", newTask); + } + + default void checkConfirmation(@NotNull Runnable task, @NotNull String command, int times, + int limit, InjectedValueAccess context) throws RegionOperationException { + if (!getMeta("cmdConfirmRunning", false)) { + if (times > limit) { + setConfirmTask(task, context, command); + String volume = ""; + throw new RegionOperationException( + BBC.WORLDEDIT_CANCEL_REASON_CONFIRM.format(0, times, command, volume)); + } + } + task.run(); + } + + default void checkConfirmationRadius(@NotNull Runnable task, String command, int radius, + InjectedValueAccess context) throws RegionOperationException { + if (command != null && !getMeta("cmdConfirmRunning", false)) { + if (radius > 0) { + if (radius > 448) { + setConfirmTask(task, context, command); + long volume = (long) (Math.PI * ((double) radius * radius)); + throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM + .format(0, radius, command, + NumberFormat.getNumberInstance().format(volume))); + } + } + } + task.run(); + } + + default boolean confirm() { + Runnable confirm = deleteMeta("cmdConfirm"); + if (confirm == null) { + return false; + } + queueAction(() -> { + setMeta("cmdConfirmRunning", true); + try { + confirm.run(); + } finally { + setMeta("cmdConfirmRunning", false); + } + }); + return true; + } + + /** + * Queue an action to run async + * + * @param run + */ + default void queueAction(Runnable run) { + runAction(run, false, true); + } + + default boolean checkAction() { + long time = getMeta("faweActionTick", Long.MIN_VALUE); + long tick = Fawe.get().getTimer().getTick(); + setMeta("faweActionTick", tick); + return tick > time; + } }