From aa17d2f0e0b00ce4b54554e04c3acbed1f74b5d9 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 4 Jun 2011 12:16:10 -0700 Subject: [PATCH] Added //gmask to set a *GLOBAL* mask that affects nearly ALL operations. Now you can confine //sphere to a region or create //walls that do not replace existing blocks. --- plugin.yml | 5 ++++ .../java/com/sk89q/worldedit/EditSession.java | 30 +++++++++++++++++++ .../com/sk89q/worldedit/LocalSession.java | 21 +++++++++++++ .../worldedit/commands/GeneralCommands.java | 22 ++++++++++++++ 4 files changed, 78 insertions(+) diff --git a/plugin.yml b/plugin.yml index d8c8e9aa9..7018c54fa 100644 --- a/plugin.yml +++ b/plugin.yml @@ -65,6 +65,11 @@ commands: description: Modify block change limit usage: / permissions: 'worldedit.limit' + /gmask: + description: Set the global mask + usage: / [mask] + aliases: ['gmask'] + permissions: 'worldedit.global-mask' /hcyl: description: Generate a hollow cylinder usage: / [height] diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index bdfb200b0..ed2bc0671 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -33,6 +33,7 @@ import com.sk89q.worldedit.regions.*; import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.bags.*; import com.sk89q.worldedit.blocks.*; +import com.sk89q.worldedit.masks.Mask; import com.sk89q.worldedit.patterns.*; /** @@ -108,6 +109,11 @@ public class EditSession { * List of missing blocks; */ private Set missingBlocks = new HashSet(); + + /** + * Mask to cover operations. + */ + private Mask mask; /** * Construct the object with a maximum number of blocks. @@ -162,6 +168,12 @@ public class EditSession { return false; } + if (mask != null) { + if (!mask.matches(this, pt)) { + return false; + } + } + int existing = world.getBlockType(pt); // Clear the container block so that it doesn't drop items @@ -2245,4 +2257,22 @@ public class EditSession { public int getBlockChangeCount() { return original.size(); } + + /** + * Get the mask. + * + * @return mask, may be null + */ + public Mask getMask() { + return mask; + } + + /** + * Set a mask. + * + * @param mask mask or null + */ + public void setMask(Mask mask) { + this.mask = mask; + } } diff --git a/src/main/java/com/sk89q/worldedit/LocalSession.java b/src/main/java/com/sk89q/worldedit/LocalSession.java index 3effd2c6f..477cc2021 100644 --- a/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -38,6 +38,7 @@ import com.sk89q.worldedit.cui.CUIPointBasedRegion; import com.sk89q.worldedit.cui.CUIEvent; import com.sk89q.worldedit.cui.SelectionPointEvent; import com.sk89q.worldedit.cui.SelectionShapeEvent; +import com.sk89q.worldedit.masks.Mask; import com.sk89q.worldedit.regions.CuboidRegionSelector; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; @@ -74,6 +75,7 @@ public class LocalSession { private boolean beenToldVersion = false; private boolean hasCUISupport = false; private boolean fastMode = false; + private Mask mask; private TimeZone timezone = TimeZone.getDefault(); /** @@ -660,6 +662,7 @@ public class LocalSession { new EditSession(player.getWorld(), getBlockChangeLimit(), blockBag); editSession.setFastMode(fastMode); + editSession.setMask(mask); return editSession; } @@ -681,4 +684,22 @@ public class LocalSession { public void setFastMode(boolean fastMode) { this.fastMode = fastMode; } + + /** + * Get the mask. + * + * @return mask, may be null + */ + public Mask getMask() { + return mask; + } + + /** + * Set a mask. + * + * @param mask mask or null + */ + public void setMask(Mask mask) { + this.mask = mask; + } } diff --git a/src/main/java/com/sk89q/worldedit/commands/GeneralCommands.java b/src/main/java/com/sk89q/worldedit/commands/GeneralCommands.java index 8f5ef4ae1..0dfc3c7a1 100644 --- a/src/main/java/com/sk89q/worldedit/commands/GeneralCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/GeneralCommands.java @@ -25,6 +25,7 @@ import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.NestedCommand; import com.sk89q.worldedit.*; import com.sk89q.worldedit.blocks.ItemType; +import com.sk89q.worldedit.masks.Mask; /** * General WorldEdit commands. @@ -81,6 +82,27 @@ public class GeneralCommands { } } + @Command( + aliases = {"/gmask", "gmask"}, + usage = "[mask]", + desc = "Set the global mask", + min = 0, + max = -1 + ) + @CommandPermissions({"worldedit.global-mask"}) + public static void mask(CommandContext args, WorldEdit we, + LocalSession session, LocalPlayer player, EditSession editSession) + throws WorldEditException { + if (args.argsLength() == 0) { + session.setMask(null); + player.print("Global mask disabled."); + } else { + Mask mask = we.getBlockMask(player, session, args.getJoinedStrings(0)); + session.setMask(mask); + player.print("Global mask set."); + } + } + @Command( aliases = {"toggleplace"}, usage = "",