From b311b0b88a18d34ca1d33b9a3cfa14250bad178c Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 18 Feb 2011 15:14:43 -0800 Subject: [PATCH] Overhauled the tool system. All tools can now be bound to any held item so you can have multiple tools out a time. New masks framework allows making a filter of blocks to change. Brushes are now powerful as well. --- plugin.yml | 64 +++--- src/com/sk89q/worldedit/EditSession.java | 45 +++-- src/com/sk89q/worldedit/HeightMap.java | 2 +- src/com/sk89q/worldedit/LocalSession.java | 151 ++++++++------ .../sk89q/worldedit/ReplacingEditSession.java | 52 ++--- .../ReplacingExistingEditSession.java | 102 ---------- src/com/sk89q/worldedit/WorldEdit.java | 88 +++++--- ...hShapeCommands.java => BrushCommands.java} | 66 +++--- .../worldedit/commands/BrushModeCommands.java | 67 ++++++ .../commands/GenerationCommands.java | 10 +- .../worldedit/commands/RegionCommands.java | 4 +- .../commands/SuperPickaxeCommands.java | 191 ++---------------- .../worldedit/commands/ToolCommands.java | 130 ++++++++++++ .../worldedit/commands/ToolUtilCommands.java | 93 +++++++++ .../GaussianKernel.java | 2 +- .../HeightMapFilter.java | 2 +- .../{filters => filtering}/LinearKernel.java | 2 +- .../BlockTypeMask.java} | 42 ++-- .../worldedit/masks/ExistingBlockMask.java | 29 +++ src/com/sk89q/worldedit/masks/Mask.java | 42 ++++ .../scripting/CraftScriptContext.java | 2 +- .../sk89q/worldedit/superpickaxe/Brush.java | 79 -------- .../{superpickaxe => tools}/AreaPickaxe.java | 10 +- .../BlockDataCyler.java | 4 +- .../BlockReplacer.java | 8 +- .../BlockTool.java} | 8 +- src/com/sk89q/worldedit/tools/Brush.java | 159 +++++++++++++++ .../{superpickaxe => tools}/QueryTool.java | 6 +- .../RecursivePickaxe.java | 8 +- .../ReplacingBrush.java | 6 +- .../SinglePickaxe.java | 4 +- src/com/sk89q/worldedit/tools/Tool.java | 29 +++ src/com/sk89q/worldedit/tools/TraceTool.java | 45 +++++ .../{superpickaxe => tools}/TreePlanter.java | 6 +- .../brushes/BrushShape.java | 7 +- .../brushes/ClipboardBrush.java} | 9 +- .../brushes/CylinderBrush.java} | 16 +- .../brushes/HollowCylinderBrush.java} | 18 +- .../brushes/HollowSphereBrush.java} | 17 +- .../worldedit/tools/brushes/SphereBrush.java | 35 ++++ 40 files changed, 1024 insertions(+), 636 deletions(-) delete mode 100644 src/com/sk89q/worldedit/ReplacingExistingEditSession.java rename src/com/sk89q/worldedit/commands/{BrushShapeCommands.java => BrushCommands.java} (68%) create mode 100644 src/com/sk89q/worldedit/commands/BrushModeCommands.java create mode 100644 src/com/sk89q/worldedit/commands/ToolCommands.java create mode 100644 src/com/sk89q/worldedit/commands/ToolUtilCommands.java rename src/com/sk89q/worldedit/{filters => filtering}/GaussianKernel.java (94%) mode change 100755 => 100644 rename src/com/sk89q/worldedit/{filters => filtering}/HeightMapFilter.java (95%) mode change 100755 => 100644 rename src/com/sk89q/worldedit/{filters => filtering}/LinearKernel.java (93%) mode change 100755 => 100644 rename src/com/sk89q/worldedit/{superpickaxe/brushes/HollowCylinderBrushShape.java => masks/BlockTypeMask.java} (53%) create mode 100644 src/com/sk89q/worldedit/masks/ExistingBlockMask.java create mode 100644 src/com/sk89q/worldedit/masks/Mask.java delete mode 100644 src/com/sk89q/worldedit/superpickaxe/Brush.java rename src/com/sk89q/worldedit/{superpickaxe => tools}/AreaPickaxe.java (89%) rename src/com/sk89q/worldedit/{superpickaxe => tools}/BlockDataCyler.java (94%) rename src/com/sk89q/worldedit/{superpickaxe => tools}/BlockReplacer.java (85%) rename src/com/sk89q/worldedit/{superpickaxe/SuperPickaxeMode.java => tools/BlockTool.java} (84%) create mode 100644 src/com/sk89q/worldedit/tools/Brush.java rename src/com/sk89q/worldedit/{superpickaxe => tools}/QueryTool.java (88%) rename src/com/sk89q/worldedit/{superpickaxe => tools}/RecursivePickaxe.java (91%) rename src/com/sk89q/worldedit/{superpickaxe => tools}/ReplacingBrush.java (90%) rename src/com/sk89q/worldedit/{superpickaxe => tools}/SinglePickaxe.java (90%) create mode 100644 src/com/sk89q/worldedit/tools/Tool.java create mode 100644 src/com/sk89q/worldedit/tools/TraceTool.java rename src/com/sk89q/worldedit/{superpickaxe => tools}/TreePlanter.java (87%) rename src/com/sk89q/worldedit/{superpickaxe => tools}/brushes/BrushShape.java (81%) rename src/com/sk89q/worldedit/{superpickaxe/brushes/ClipboardBrushShape.java => tools/brushes/ClipboardBrush.java} (78%) rename src/com/sk89q/worldedit/{superpickaxe/brushes/CylinderBrushShape.java => tools/brushes/CylinderBrush.java} (65%) rename src/com/sk89q/worldedit/{superpickaxe/brushes/SphereBrushShape.java => tools/brushes/HollowCylinderBrush.java} (64%) rename src/com/sk89q/worldedit/{superpickaxe/brushes/HollowSphereBrushShape.java => tools/brushes/HollowSphereBrush.java} (63%) create mode 100644 src/com/sk89q/worldedit/tools/brushes/SphereBrush.java diff --git a/plugin.yml b/plugin.yml index 7fd381c74..1b102bfb4 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,18 +2,18 @@ name: WorldEdit main: com.sk89q.worldedit.bukkit.WorldEditPlugin version: "WEVERSIONMACRO" commands: - /sb: + sphere: description: Choose the sphere brush usage: / [-h] [radius] - aliases: ['/sphereb'] - /cb: + aliases: ['s'] + cylinder: description: Choose the cylinder brush usage: / [-h] [radius] [height] - aliases: ['/cylb'] - /cbb: + aliases: ['cyl', 'c'] + clipboard: description: Choose the clipboard brush usage: / [-a] - aliases: ['/copyb'] + aliases: ['copy'] chunkinfo: description: Get information about the chunk that you are inside usage: / @@ -57,18 +57,18 @@ commands: /limit: description: Modify block change limit usage: / - /hcyl: - description: Generate a hollow cylinder - usage: / [height] + /sphere: + description: Generate a filled sphere + usage: / [raised?] /cyl: description: Generate a cylinder usage: / [height] + /hcyl: + description: Generate a hollow cylinder + usage: / [height] /hsphere: description: Generate a hollow sphere usage: / [raised?] - /sphere: - description: Generate a filled sphere - usage: / [raised?] forestgen: description: Generate a forest usage: / [size] [type] [density] @@ -184,13 +184,16 @@ commands: /restore: description: Restore the selection from a snapshot usage: / [snapshot] - /: - description: Toggle the super pickaxe pickaxe function - usage: / - aliases: [','] area: description: Enable the area super pickaxe pickaxe mode usage: / + recur: + description: Enable the recursive super pickaxe pickaxe mode + usage: / + aliases: ['recursive'] + single: + description: Enable the single block super pickaxe mode + usage: / none: description: Turn off all superpickaxe alternate modes usage: / @@ -200,24 +203,31 @@ commands: cycler: description: Block data cycler tool usage: / - /brush: - description: Build from far away - usage: / [-r] - /rbrush: - description: Brush tool that will only replace blocks + brush: + description: Brush tool usage: / - recur: - description: Enable the recursive super pickaxe pickaxe mode - usage: / + aliases: ['b'] info: description: Block information tool usage: / - single: - description: Enable the single block super pickaxe mode - usage: / tree: description: Tree generator tool usage: / [type] + tool: + description: Select a tool to bind + usage: / + aliases: ['t'] + /: + description: Toggle the super pickaxe pickaxe function + usage: / + aliases: [','] + pickaxe: + description: Select super pickaxe mode + usage: / + aliases: ['pa', 'spa'] + mask: + description: Set the brush mask + usage: / [mask] /fillr: description: Fill a hole recursively usage: / [depth] diff --git a/src/com/sk89q/worldedit/EditSession.java b/src/com/sk89q/worldedit/EditSession.java index b43f99524..be0954430 100755 --- a/src/com/sk89q/worldedit/EditSession.java +++ b/src/com/sk89q/worldedit/EditSession.java @@ -104,11 +104,10 @@ public class EditSession { /** * Construct the object with a maximum number of blocks. * - * @param server * @param world * @param maxBlocks */ - public EditSession(ServerInterface server, LocalWorld world, int maxBlocks) { + public EditSession(LocalWorld world, int maxBlocks) { if (maxBlocks < -1) { throw new IllegalArgumentException("Max blocks must be >= -1"); } @@ -120,12 +119,12 @@ public class EditSession { /** * Construct the object with a maximum number of blocks and a block bag. * - * @param server + * @param world * @param maxBlocks + * @param blockBag * @blockBag */ - public EditSession(ServerInterface server, LocalWorld world, int maxBlocks, - BlockBag blockBag) { + public EditSession(LocalWorld world, int maxBlocks, BlockBag blockBag) { if (maxBlocks < -1) { throw new IllegalArgumentException("Max blocks must be >= -1"); } @@ -231,6 +230,7 @@ public class EditSession { * @param pt * @param block * @return Whether the block changed -- not entirely dependable + * @throws MaxChangedBlocksException */ public boolean setBlock(Vector pt, BaseBlock block) throws MaxChangedBlocksException { @@ -249,6 +249,19 @@ public class EditSession { return smartSetBlock(pt, block); } + /** + * Set a block with a pattern. + * + * @param pt + * @param pat + * @return Whether the block changed -- not entirely dependable + * @throws MaxChangedBlocksException + */ + public boolean setBlock(Vector pt, Pattern pat) + throws MaxChangedBlocksException { + return setBlock(pt, pat.next(pt)); + } + /** * Set a block only if there's no block already there. * @@ -381,23 +394,23 @@ public class EditSession { /** * Restores all blocks to their initial state. */ - public void undo() { + public void undo(EditSession sess) { for (Map.Entry entry : original) { BlockVector pt = (BlockVector) entry.getKey(); - smartSetBlock(pt, (BaseBlock) entry.getValue()); + sess.smartSetBlock(pt, (BaseBlock) entry.getValue()); } - flushQueue(); + sess.flushQueue(); } /** * Sets to new state. */ - public void redo() { + public void redo(EditSession sess) { for (Map.Entry entry : current) { BlockVector pt = (BlockVector) entry.getKey(); - smartSetBlock(pt, (BaseBlock) entry.getValue()); + sess.smartSetBlock(pt, (BaseBlock) entry.getValue()); } - flushQueue(); + sess.flushQueue(); } /** @@ -1453,7 +1466,7 @@ public class EditSession { * @throws MaxChangedBlocksException */ private int makeHCylinderPoints(Vector center, int x, int z, int height, - BaseBlock block) throws MaxChangedBlocksException { + Pattern block) throws MaxChangedBlocksException { int affected = 0; if (x == 0) { @@ -1499,7 +1512,7 @@ public class EditSession { * @return number of blocks set * @throws MaxChangedBlocksException */ - public int makeHollowCylinder(Vector pos, BaseBlock block, int radius, + public int makeHollowCylinder(Vector pos, Pattern block, int radius, int height) throws MaxChangedBlocksException { int x = 0; int z = radius; @@ -1548,7 +1561,7 @@ public class EditSession { * @throws MaxChangedBlocksException */ private int makeCylinderPoints(Vector center, int x, int z, int height, - BaseBlock block) throws MaxChangedBlocksException { + Pattern block) throws MaxChangedBlocksException { int affected = 0; if (x == z) { @@ -1586,7 +1599,7 @@ public class EditSession { * @return number of blocks set * @throws MaxChangedBlocksException */ - public int makeCylinder(Vector pos, BaseBlock block, int radius, int height) + public int makeCylinder(Vector pos, Pattern block, int radius, int height) throws MaxChangedBlocksException { int x = 0; int z = radius; @@ -1634,7 +1647,7 @@ public class EditSession { * @return number of blocks changed * @throws MaxChangedBlocksException */ - public int makeSphere(Vector pos, BaseBlock block, int radius, + public int makeSphere(Vector pos, Pattern block, int radius, boolean filled) throws MaxChangedBlocksException { int affected = 0; diff --git a/src/com/sk89q/worldedit/HeightMap.java b/src/com/sk89q/worldedit/HeightMap.java index 212593295..d477d2eb1 100755 --- a/src/com/sk89q/worldedit/HeightMap.java +++ b/src/com/sk89q/worldedit/HeightMap.java @@ -19,7 +19,7 @@ package com.sk89q.worldedit; */ import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.filters.HeightMapFilter; +import com.sk89q.worldedit.filtering.HeightMapFilter; import com.sk89q.worldedit.regions.Region; /** diff --git a/src/com/sk89q/worldedit/LocalSession.java b/src/com/sk89q/worldedit/LocalSession.java index 40b340f1e..337a392fe 100644 --- a/src/com/sk89q/worldedit/LocalSession.java +++ b/src/com/sk89q/worldedit/LocalSession.java @@ -19,20 +19,29 @@ package com.sk89q.worldedit; +import java.util.HashMap; import java.util.LinkedList; +import java.util.Map; import com.sk89q.worldedit.snapshots.Snapshot; -import com.sk89q.worldedit.superpickaxe.SinglePickaxe; -import com.sk89q.worldedit.superpickaxe.SuperPickaxeMode; -import com.sk89q.worldedit.superpickaxe.brushes.BrushShape; +import com.sk89q.worldedit.tools.Brush; +import com.sk89q.worldedit.tools.SinglePickaxe; +import com.sk89q.worldedit.tools.BlockTool; +import com.sk89q.worldedit.tools.Tool; import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.CuboidRegion; /** + * An instance of this represents the WorldEdit session of a user. A session + * stores history and settings. Sessions are not tied particularly to any + * player and can be shuffled between players, saved, and loaded. * * @author sk89q */ public class LocalSession { + /** + * List of compass modes. + */ public enum CompassMode { JUMPTO, THRU @@ -50,15 +59,14 @@ public class LocalSession { private CuboidClipboard clipboard; private boolean toolControl = true; private boolean superPickaxe = false; - private SuperPickaxeMode leftClickMode = new SinglePickaxe(); - private SuperPickaxeMode armSwingMode; - private SuperPickaxeMode rightClickMode; + private BlockTool pickaxeMode = new SinglePickaxe(); + private Map tools + = new HashMap(); private int maxBlocksChanged = -1; private boolean useInventory; private Snapshot snapshot; private String lastScript; private CompassMode compassMode = CompassMode.JUMPTO; - private BrushShape brushShape = null; private boolean beenToldVersion = false; /** @@ -79,7 +87,10 @@ public class LocalSession { } /** - * Get the edit session. + * Remember an edit session for the undo history. If the history maximum + * size is reached, old edit sessions will be discarded. + * + * @param editSession */ public void remember(EditSession editSession) { // Don't store anything if no changes were made @@ -97,16 +108,18 @@ public class LocalSession { } /** - * Undo. + * Performs an undo. * + * @param newBlockBag * @return whether anything was undone */ public EditSession undo(BlockBag newBlockBag) { historyPointer--; if (historyPointer >= 0) { EditSession editSession = history.get(historyPointer); - editSession.setBlockBag(newBlockBag); - editSession.undo(); + EditSession newEditSession = + new EditSession(editSession.getWorld(), -1, newBlockBag); + editSession.undo(newEditSession); return editSession; } else { historyPointer = 0; @@ -115,15 +128,17 @@ public class LocalSession { } /** - * Redo. + * Performs a redo * + * @param newBlockBag * @return whether anything was redone */ public EditSession redo(BlockBag newBlockBag) { if (historyPointer < history.size()) { EditSession editSession = history.get(historyPointer); - editSession.setBlockBag(newBlockBag); - editSession.redo(); + EditSession newEditSession = + new EditSession(editSession.getWorld(), -1, newBlockBag); + editSession.redo(newEditSession); historyPointer++; return editSession; } @@ -155,8 +170,8 @@ public class LocalSession { /** * Returns true if the region is fully defined. - * - * @throws IncompleteRegionException + * + * @return */ public boolean isRegionDefined() { return pos1 != null && pos2 != null; @@ -303,8 +318,6 @@ public class LocalSession { /** * Enable super pick axe. - * - * @param superPickaxe */ public void enableSuperPickAxe() { superPickaxe = true; @@ -312,8 +325,6 @@ public class LocalSession { /** * Disable super pick axe. - * - * @param superPickaxe */ public void disableSuperPickAxe() { superPickaxe = false; @@ -330,6 +341,9 @@ public class LocalSession { } /** + * Get the placement position. + * + * @param player * @return position * @throws IncompleteRegionException */ @@ -344,7 +358,9 @@ public class LocalSession { } /** - * Toggle placement position; + * Toggle placement position. + * + * @return */ public boolean togglePlacementPosition() { placeAtPos1 = !placeAtPos1; @@ -365,13 +381,17 @@ public class LocalSession { } /** - * @return the snapshotName + * Get the snapshot that has been selected. + * + * @return the snapshot */ public Snapshot getSnapshot() { return snapshot; } /** + * Select a snapshot. + * * @param snapshot */ public void setSnapshot(Snapshot snapshot) { @@ -381,46 +401,61 @@ public class LocalSession { /** * @return the superPickaxeMode */ - public SuperPickaxeMode getLeftClickMode() { - return leftClickMode; + public BlockTool getSuperPickaxe() { + return pickaxeMode; } /** - * @param superPickaxeMode the superPickaxeMode to set + * Set the super pickaxe tool. + * + * @param tool */ - public void setLeftClickMode(SuperPickaxeMode leftClickMode) { - this.leftClickMode = leftClickMode; + public void setSuperPickaxe(BlockTool tool) { + this.pickaxeMode = tool; } /** + * Get the tool assigned to the item. + * + * @param item * @return the tool */ - public SuperPickaxeMode getRightClickMode() { - return rightClickMode; + public Tool getTool(int item) { + return tools.get(item); } /** + * Get the brush tool assigned to the item. If there is no tool assigned + * or the tool is not assigned, the slot will be replaced with the + * brush tool. + * + * @param item + * @return the tool + */ + public Brush getBrushTool(int item) { + Tool tool = getTool(item); + + if (tool == null || !(tool instanceof Brush)) { + tool = new Brush(); + setTool(item, tool); + } + + return (Brush)tool; + } + + /** + * Set the tool. + * + * @param item * @param tool the tool to set */ - public void setRightClickMode(SuperPickaxeMode rightClickMode) { - this.rightClickMode = rightClickMode; - } - - /** - * @return the arm swing mode - */ - public SuperPickaxeMode getArmSwingMode() { - return armSwingMode; - } - - /** - * @param rightClickMode the tool to set - */ - public void setArmSwingMode(SuperPickaxeMode armSwingMode) { - this.armSwingMode = armSwingMode; + public void setTool(int item, Tool tool) { + this.tools.put(item, tool); } /** + * Returns whether inventory usage is enabled for this session. + * * @return the useInventory */ public boolean isUsingInventory() { @@ -428,6 +463,8 @@ public class LocalSession { } /** + * Set the state of inventory usage. + * * @param useInventory the useInventory to set */ public void setUseInventory(boolean useInventory) { @@ -435,6 +472,8 @@ public class LocalSession { } /** + * Get the last script used. + * * @return the lastScript */ public String getLastScript() { @@ -442,6 +481,8 @@ public class LocalSession { } /** + * Set the last script used. + * * @param lastScript the lastScript to set */ public void setLastScript(String lastScript) { @@ -449,6 +490,8 @@ public class LocalSession { } /** + * Get the compass mode. + * * @return the compassMode */ public CompassMode getCompassMode() { @@ -456,28 +499,18 @@ public class LocalSession { } /** + * Set the compass mode. + * * @param compassMode the compassMode to set */ public void setCompassMode(CompassMode compassMode) { this.compassMode = compassMode; } - - /** - * @return the brushShape - */ - public BrushShape getBrushShape() { - return brushShape; - } - - /** - * @param brushShape the brushShape to set - */ - public void setBrushShape(BrushShape brushShape) { - this.brushShape = brushShape; - } /** * Tell the player the WorldEdit version. + * + * @param player */ public void tellVersion(LocalPlayer player) { if (config.showFirstUseVersion) { diff --git a/src/com/sk89q/worldedit/ReplacingEditSession.java b/src/com/sk89q/worldedit/ReplacingEditSession.java index 11c97ddbc..983e74195 100644 --- a/src/com/sk89q/worldedit/ReplacingEditSession.java +++ b/src/com/sk89q/worldedit/ReplacingEditSession.java @@ -21,78 +21,62 @@ package com.sk89q.worldedit; import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.masks.Mask; /** - * An edit session that can be set to not replace existing blocks. + * An edit session that will only replace blocks as specified. * * @author sk89q */ public class ReplacingEditSession extends EditSession { /** - * True to prevent replacing. + * Filter to use to filter blocks. */ - private boolean noReplace = false; + private Mask mask; /** * Construct the object. * - * @param server * @param world * @param maxBlocks + * @param mask */ - public ReplacingEditSession(ServerInterface server, LocalWorld world, - int maxBlocks) { - super(server, world, maxBlocks); + public ReplacingEditSession(LocalWorld world, + int maxBlocks, Mask mask) { + super(world, maxBlocks); + this.mask = mask; } /** * Construct the object. * - * @param server * @param world * @param maxBlocks * @param blockBag + * @param mask */ - public ReplacingEditSession(ServerInterface server, LocalWorld world, - int maxBlocks, BlockBag blockBag) { - super(server, world, maxBlocks, blockBag); - } - - /** - * Enables block replacing. - */ - public void enableReplacing() { - noReplace = false; - } - - /** - * Disables block replacing. - */ - public void disableReplacing() { - noReplace = true; + public ReplacingEditSession(LocalWorld world, int maxBlocks, + BlockBag blockBag, Mask mask) { + super(world, maxBlocks, blockBag); + this.mask = mask; } /** * Sets a block without changing history. * * @param pt - * @param blockType + * @param block * @return Whether the block changed */ - public boolean rawSetBlock(Vector pt, BaseBlock block) { - if (!noReplace) { - return super.rawSetBlock(pt, block); - } - + @Override + public boolean rawSetBlock(Vector pt, BaseBlock block) { int y = pt.getBlockY(); if (y < 0 || y > 127) { return false; } - int existing = world.getBlockType(pt); - - if (existing != 0) { + if (!mask.matches(this, pt)) { return false; } diff --git a/src/com/sk89q/worldedit/ReplacingExistingEditSession.java b/src/com/sk89q/worldedit/ReplacingExistingEditSession.java deleted file mode 100644 index 0dba5becf..000000000 --- a/src/com/sk89q/worldedit/ReplacingExistingEditSession.java +++ /dev/null @@ -1,102 +0,0 @@ -// $Id$ -/* - * WorldEdit - * Copyright (C) 2010 sk89q - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . -*/ - -package com.sk89q.worldedit; - -import com.sk89q.worldedit.bags.BlockBag; -import com.sk89q.worldedit.blocks.BaseBlock; - -/** - * An edit session that can be set to only replace existing blocks. - * - * @author sk89q - */ -public class ReplacingExistingEditSession extends EditSession { - /** - * True to replace existing. - */ - private boolean replaceExisting = false; - - /** - * Construct the object. - * - * @param server - * @param world - * @param maxBlocks - */ - public ReplacingExistingEditSession(ServerInterface server, LocalWorld world, - int maxBlocks) { - super(server, world, maxBlocks); - } - - /** - * Construct the object. - * - * @param server - * @param world - * @param maxBlocks - * @param blockBag - */ - public ReplacingExistingEditSession(ServerInterface server, LocalWorld world, - int maxBlocks, BlockBag blockBag) { - super(server, world, maxBlocks, blockBag); - } - - /** - * Enables block replacing. - */ - public void enableReplacing() { - replaceExisting = true; - } - - /** - * Disables block replacing. - */ - public void disableReplacing() { - replaceExisting = false; - } - - /** - * Sets a block without changing history. - * - * @param pt - * @param blockType - * @return Whether the block changed - */ - public boolean rawSetBlock(Vector pt, BaseBlock block) { - if (!replaceExisting) { - return super.rawSetBlock(pt, block); - } - - int y = pt.getBlockY(); - - if (y < 0 || y > 127) { - return false; - } - - int existing = world.getBlockType(pt); - - if (existing == 0) { - return false; - } - - return super.rawSetBlock(pt, block); - } - -} diff --git a/src/com/sk89q/worldedit/WorldEdit.java b/src/com/sk89q/worldedit/WorldEdit.java index 0d8203fff..31fc33926 100644 --- a/src/com/sk89q/worldedit/WorldEdit.java +++ b/src/com/sk89q/worldedit/WorldEdit.java @@ -29,7 +29,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.io.*; import javax.script.ScriptException; -import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandsManager; import com.sk89q.util.StringUtil; import com.sk89q.worldedit.LocalSession.CompassMode; @@ -37,6 +36,12 @@ import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.blocks.*; import com.sk89q.worldedit.commands.*; import com.sk89q.worldedit.scripting.*; +import com.sk89q.worldedit.tools.BlockTool; +import com.sk89q.worldedit.tools.Tool; +import com.sk89q.worldedit.tools.TraceTool; +import com.sk89q.worldedit.masks.BlockTypeMask; +import com.sk89q.worldedit.masks.ExistingBlockMask; +import com.sk89q.worldedit.masks.Mask; import com.sk89q.worldedit.patterns.*; /** @@ -105,8 +110,8 @@ public class WorldEdit { commands.register(ScriptingCommands.class); commands.register(SelectionCommands.class); commands.register(SnapshotCommands.class); - commands.register(SuperPickaxeCommands.class); - commands.register(BrushShapeCommands.class); + commands.register(ToolUtilCommands.class); + commands.register(ToolCommands.class); commands.register(UtilityCommands.class); } @@ -290,6 +295,8 @@ public class WorldEdit { * @param player * @param list * @return pattern + * @throws UnknownItemException + * @throws DisallowedItemException */ public Pattern getBlockPattern(LocalPlayer player, String list) throws UnknownItemException, DisallowedItemException { @@ -334,6 +341,29 @@ public class WorldEdit { return new RandomFillPattern(blockChances); } + + /** + * Get a block mask. Block masks are used to determine which + * blocks to include when replacing. + * + * @param player + * @param list + * @return + * @throws UnknownItemException + * @throws DisallowedItemException + */ + public Mask getBlockMask(LocalPlayer player, String list) + throws UnknownItemException, DisallowedItemException { + if (list.charAt(0) == '#') { + if (list.equalsIgnoreCase("#existing")) { + return new ExistingBlockMask(); + } else { + throw new UnknownItemException(list); + } + } else { + return new BlockTypeMask(getBlockIDs(player, list, true)); + } + } /** * Get a list of blocks as a set. @@ -342,6 +372,8 @@ public class WorldEdit { * @param list * @param allBlocksAllowed * @return set + * @throws UnknownItemException + * @throws DisallowedItemException */ public Set getBlockIDs(LocalPlayer player, String list, boolean allBlocksAllowed) @@ -361,6 +393,7 @@ public class WorldEdit { * traversal exploits by checking the root directory and the file directory. * On success, a java.io.File object will be returned. * + * @param player * @param dir sub-directory to look in * @param filename filename (user-submitted) * @param defaultExt append an extension if missing one, null to not use @@ -380,6 +413,7 @@ public class WorldEdit { * traversal exploits by checking the root directory and the file directory. * On success, a java.io.File object will be returned. * + * @param player * @param dir sub-directory to look in * @param filename filename (user-submitted) * @param defaultExt append an extension if missing one, null to not use @@ -493,8 +527,9 @@ public class WorldEdit { * null if a direction could not be found. * * @param player - * @param dir + * @param dirStr * @return + * @throws UnknownDirectionException */ public Vector getDirection(LocalPlayer player, String dirStr) throws UnknownDirectionException { @@ -540,8 +575,9 @@ public class WorldEdit { * null if a direction could not be found. * * @param player - * @param dir + * @param dirStr * @return + * @throws UnknownDirectionException */ public CuboidClipboard.FlipDirection getFlipDirection( LocalPlayer player, String dirStr) @@ -589,7 +625,6 @@ public class WorldEdit { * Flush a block bag's changes to a player. * * @param player - * @param blockBag * @param editSession */ public void flushBlockBag(LocalPlayer player, @@ -651,13 +686,7 @@ public class WorldEdit { public boolean handleArmSwing(LocalPlayer player) { LocalSession session = getSession(player); - if (player.isHoldingPickAxe()) { - if (session.getArmSwingMode() != null) { - session.getArmSwingMode().act(server, config, - player, session, null); - return true; - } - } else if (player.getItemInHand() == config.navigationWand + if (player.getItemInHand() == config.navigationWand && config.navigationWandMaxDistance > 0) { CompassMode mode = session.getCompassMode(); @@ -687,13 +716,7 @@ public class WorldEdit { public boolean handleRightClick(LocalPlayer player) { LocalSession session = getSession(player); - if (player.isHoldingPickAxe()) { - if (session.getArmSwingMode() != null) { - session.getArmSwingMode().act(server, config, - player, session, null); - return true; - } - } else if (player.getItemInHand() == config.navigationWand) { + if (player.getItemInHand() == config.navigationWand) { CompassMode mode = session.getCompassMode(); if (mode == CompassMode.JUMPTO) { @@ -715,6 +738,13 @@ public class WorldEdit { return true; } + Tool tool = session.getTool(player.getItemInHand()); + + if (tool != null && tool instanceof TraceTool) { + ((TraceTool)tool).act(server, config, player, session); + return true; + } + return false; } @@ -733,6 +763,7 @@ public class WorldEdit { if (itemInHand == config.wandItem && session.isToolControlEnabled() && player.hasPermission("worldedit.selection.pos")) { session.setPos2(clicked); + try { player.print("Second position set to " + clicked + " (" + session.getRegion().getSize() + ")."); @@ -741,8 +772,13 @@ public class WorldEdit { } return true; - } else if (player.isHoldingPickAxe() && session.getRightClickMode() != null) { - return session.getRightClickMode().act(server, config, player, session, clicked); + } + + Tool tool = session.getTool(player.getItemInHand()); + + if (tool != null && tool instanceof BlockTool) { + ((BlockTool)tool).act(server, config, player, session, clicked); + return true; } return false; @@ -785,8 +821,8 @@ public class WorldEdit { return true; } } else if (player.isHoldingPickAxe() && session.hasSuperPickAxe()) { - if (session.getLeftClickMode() != null) { - return session.getLeftClickMode().act(server, config, + if (session.getSuperPickaxe() != null) { + return session.getSuperPickaxe().act(server, config, player, session, clicked); } } @@ -830,7 +866,7 @@ public class WorldEdit { session.tellVersion(player); EditSession editSession = - new EditSession(server, player.getWorld(), + new EditSession(player.getWorld(), session.getBlockChangeLimit(), blockBag); editSession.enableQueue(); @@ -913,7 +949,7 @@ public class WorldEdit { * Executes a WorldEdit script. * * @param player - * @param filename + * @param f * @param args * @throws WorldEditException */ diff --git a/src/com/sk89q/worldedit/commands/BrushShapeCommands.java b/src/com/sk89q/worldedit/commands/BrushCommands.java similarity index 68% rename from src/com/sk89q/worldedit/commands/BrushShapeCommands.java rename to src/com/sk89q/worldedit/commands/BrushCommands.java index 00b1da5e9..1918d1ac7 100644 --- a/src/com/sk89q/worldedit/commands/BrushShapeCommands.java +++ b/src/com/sk89q/worldedit/commands/BrushCommands.java @@ -30,28 +30,29 @@ import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.superpickaxe.brushes.ClipboardBrushShape; -import com.sk89q.worldedit.superpickaxe.brushes.CylinderBrushShape; -import com.sk89q.worldedit.superpickaxe.brushes.HollowCylinderBrushShape; -import com.sk89q.worldedit.superpickaxe.brushes.SphereBrushShape; -import com.sk89q.worldedit.superpickaxe.brushes.HollowSphereBrushShape; +import com.sk89q.worldedit.patterns.Pattern; +import com.sk89q.worldedit.tools.Brush; +import com.sk89q.worldedit.tools.brushes.ClipboardBrush; +import com.sk89q.worldedit.tools.brushes.CylinderBrush; +import com.sk89q.worldedit.tools.brushes.HollowCylinderBrush; +import com.sk89q.worldedit.tools.brushes.HollowSphereBrush; +import com.sk89q.worldedit.tools.brushes.SphereBrush; /** * Brush shape commands. * * @author sk89q */ -public class BrushShapeCommands { +public class BrushCommands { @Command( - aliases = {"/sb", "/sphereb"}, + aliases = {"sphere", "s"}, usage = " [radius]", flags = "h", desc = "Choose the sphere brush", min = 1, max = 2 ) - @CommandPermissions({"worldedit.superpickaxe.drawing.brush.sphere"}) + @CommandPermissions({"worldedit.brush.sphere"}) public static void sphereBrush(CommandContext args, WorldEdit we, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { @@ -64,27 +65,31 @@ public class BrushShapeCommands { + config.maxBrushRadius); return; } - - BaseBlock targetBlock = we.getBlock(player, args.getString(0)); + + Brush tool = session.getBrushTool(player.getItemInHand()); + Pattern fill = we.getBlockPattern(player, args.getString(0)); + tool.setFill(fill); + tool.setSize(radius); if (args.hasFlag('h')) { - session.setBrushShape(new HollowSphereBrushShape(targetBlock, radius)); + tool.setBrush(new HollowSphereBrush()); } else { - session.setBrushShape(new SphereBrushShape(targetBlock, radius)); + tool.setBrush(new SphereBrush()); } - - player.print("Sphere brush shape equipped."); + + player.print(String.format("Sphere brush shape equipped (%d).", + radius)); } @Command( - aliases = {"/cb", "/cylb"}, + aliases = {"cylinder", "cyl", "c"}, usage = " [radius] [height]", flags = "h", desc = "Choose the cylinder brush", min = 1, - max = 2 + max = 3 ) - @CommandPermissions({"worldedit.superpickaxe.drawing.brush.cylinder"}) + @CommandPermissions({"worldedit.brush.cylinder"}) public static void cylinderBrush(CommandContext args, WorldEdit we, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { @@ -98,33 +103,37 @@ public class BrushShapeCommands { return; } - int height = args.argsLength() > 1 ? args.getInteger(1) : 1; + int height = args.argsLength() > 2 ? args.getInteger(2) : 1; if (height > config.maxBrushRadius) { player.printError("Maximum allowed brush radius/height: " + config.maxBrushRadius); return; } - - BaseBlock targetBlock = we.getBlock(player, args.getString(0)); + + Brush tool = session.getBrushTool(player.getItemInHand()); + Pattern fill = we.getBlockPattern(player, args.getString(0)); + tool.setFill(fill); + tool.setSize(radius); if (args.hasFlag('h')) { - session.setBrushShape(new HollowCylinderBrushShape(targetBlock, radius, height)); + tool.setBrush(new HollowCylinderBrush(height)); } else { - session.setBrushShape(new CylinderBrushShape(targetBlock, radius, height)); + tool.setBrush(new CylinderBrush(height)); } - player.print("Cylinder brush shape equipped."); + player.print(String.format("Cylinder brush shape equipped (%d by %d).", + radius, height)); } @Command( - aliases = {"/cbb", "/copyb"}, + aliases = {"clipboard", "copy"}, usage = "", flags = "a", desc = "Choose the clipboard brush", min = 0, max = 0 ) - @CommandPermissions({"worldedit.superpickaxe.drawing.brush.clipboard"}) + @CommandPermissions({"worldedit.brush.clipboard"}) public static void clipboardBrush(CommandContext args, WorldEdit we, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { @@ -147,8 +156,9 @@ public class BrushShapeCommands { + config.maxBrushRadius); return; } - - session.setBrushShape(new ClipboardBrushShape(clipboard, args.hasFlag('a'))); + + Brush tool = session.getBrushTool(player.getItemInHand()); + tool.setBrush(new ClipboardBrush(clipboard, args.hasFlag('a'))); player.print("Clipboard brush shape equipped."); } diff --git a/src/com/sk89q/worldedit/commands/BrushModeCommands.java b/src/com/sk89q/worldedit/commands/BrushModeCommands.java new file mode 100644 index 000000000..ab40770c3 --- /dev/null +++ b/src/com/sk89q/worldedit/commands/BrushModeCommands.java @@ -0,0 +1,67 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010, 2011 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.commands; + +import com.sk89q.minecraft.util.commands.Command; +import com.sk89q.minecraft.util.commands.CommandContext; +import com.sk89q.minecraft.util.commands.CommandPermissions; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalPlayer; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.tools.Brush; +import com.sk89q.worldedit.tools.ReplacingBrush; + +public class BrushModeCommands { + @Command( + aliases = {"normal", "s"}, + usage = "", + desc = "Normal brush mode", + min = 0, + max = 0 + ) + @CommandPermissions({"worldedit.brush.mode.normal"}) + public static void normal(CommandContext args, WorldEdit we, + LocalSession session, LocalPlayer player, EditSession editSession) + throws WorldEditException { + + session.setRightClickMode(null); + session.setArmSwingMode(new Brush(true)); + player.print("Normal brush mode set."); + } + + @Command( + aliases = {"replace", "r"}, + usage = "", + desc = "Replace existing blocks only", + min = 0, + max = 0 + ) + @CommandPermissions({"worldedit.brush.mode.replace"}) + public static void replace(CommandContext args, WorldEdit we, + LocalSession session, LocalPlayer player, EditSession editSession) + throws WorldEditException { + + session.setRightClickMode(null); + session.setArmSwingMode(new ReplacingBrush()); + player.print("Replacing brush mode equipped."); + } +} diff --git a/src/com/sk89q/worldedit/commands/GenerationCommands.java b/src/com/sk89q/worldedit/commands/GenerationCommands.java index e827bb639..e6b44e0d1 100644 --- a/src/com/sk89q/worldedit/commands/GenerationCommands.java +++ b/src/com/sk89q/worldedit/commands/GenerationCommands.java @@ -23,7 +23,7 @@ import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.worldedit.*; -import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.patterns.Pattern; import com.sk89q.worldedit.util.TreeGenerator; /** @@ -44,7 +44,7 @@ public class GenerationCommands { LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - BaseBlock block = we.getBlock(player, args.getString(0)); + Pattern block = we.getBlockPattern(player, args.getString(0)); int radius = Math.max(1, args.getInteger(1)); int height = args.argsLength() > 2 ? args.getInteger(2) : 1; @@ -65,7 +65,7 @@ public class GenerationCommands { LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - BaseBlock block = we.getBlock(player, args.getString(0)); + Pattern block = we.getBlockPattern(player, args.getString(0)); int radius = Math.max(1, args.getInteger(1)); int height = args.argsLength() > 2 ? args.getInteger(2) : 1; @@ -86,7 +86,7 @@ public class GenerationCommands { LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - BaseBlock block = we.getBlock(player, args.getString(0)); + Pattern block = we.getBlockPattern(player, args.getString(0)); int radius = Math.max(1, args.getInteger(1)); boolean raised = args.argsLength() > 2 ? (args.getString(2).equalsIgnoreCase("true") @@ -115,7 +115,7 @@ public class GenerationCommands { LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - BaseBlock block = we.getBlock(player, args.getString(0)); + Pattern block = we.getBlockPattern(player, args.getString(0)); int radius = Math.max(1, args.getInteger(1)); boolean raised = args.argsLength() > 2 ? (args.getString(2).equalsIgnoreCase("true") diff --git a/src/com/sk89q/worldedit/commands/RegionCommands.java b/src/com/sk89q/worldedit/commands/RegionCommands.java index 1f12f2645..089179f1c 100644 --- a/src/com/sk89q/worldedit/commands/RegionCommands.java +++ b/src/com/sk89q/worldedit/commands/RegionCommands.java @@ -25,8 +25,8 @@ import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.worldedit.*; import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.filters.GaussianKernel; -import com.sk89q.worldedit.filters.HeightMapFilter; +import com.sk89q.worldedit.filtering.GaussianKernel; +import com.sk89q.worldedit.filtering.HeightMapFilter; import com.sk89q.worldedit.patterns.*; import com.sk89q.worldedit.regions.Region; diff --git a/src/com/sk89q/worldedit/commands/SuperPickaxeCommands.java b/src/com/sk89q/worldedit/commands/SuperPickaxeCommands.java index 2831512a1..903d7c5c8 100644 --- a/src/com/sk89q/worldedit/commands/SuperPickaxeCommands.java +++ b/src/com/sk89q/worldedit/commands/SuperPickaxeCommands.java @@ -1,7 +1,7 @@ // $Id$ /* * WorldEdit - * Copyright (C) 2010 sk89q + * Copyright (C) 2010, 2011 sk89q * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,37 +22,17 @@ package com.sk89q.worldedit.commands; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandPermissions; -import com.sk89q.minecraft.util.commands.NestedCommand; -import com.sk89q.worldedit.*; -import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.superpickaxe.*; -import com.sk89q.worldedit.util.TreeGenerator; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalConfiguration; +import com.sk89q.worldedit.LocalPlayer; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.tools.AreaPickaxe; +import com.sk89q.worldedit.tools.RecursivePickaxe; +import com.sk89q.worldedit.tools.SinglePickaxe; -/** - * Super pickaxe commands. - * - * @author sk89q - */ -public class SuperPickaxeCommands { - @Command( - aliases = {"/", ","}, - usage = "", - desc = "Toggle the super pickaxe pickaxe function", - min = 0, - max = 0 - ) - @CommandPermissions({"worldedit.superpickaxe.pickaxe"}) - public static void togglePickaxe(CommandContext args, WorldEdit we, - LocalSession session, LocalPlayer player, EditSession editSession) - throws WorldEditException { - - if (session.toggleSuperPickAxe()) { - player.print("Super pick axe enabled."); - } else { - player.print("Super pick axe disabled."); - } - } - +public class SuperPickaxeCommands { @Command( aliases = {"single"}, usage = "", @@ -60,12 +40,12 @@ public class SuperPickaxeCommands { min = 0, max = 0 ) - @CommandPermissions({"worldedit.superpickaxe.pickaxe"}) + @CommandPermissions({"worldedit.superpickaxe"}) public static void single(CommandContext args, WorldEdit we, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - session.setLeftClickMode(new SinglePickaxe()); + session.setSuperPickaxe(new SinglePickaxe()); session.enableSuperPickAxe(); player.print("Mode changed. Left click with a pickaxe. // to disable."); } @@ -77,7 +57,7 @@ public class SuperPickaxeCommands { min = 1, max = 1 ) - @CommandPermissions({"worldedit.superpickaxe.pickaxe.area"}) + @CommandPermissions({"worldedit.superpickaxe.area"}) public static void area(CommandContext args, WorldEdit we, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { @@ -90,19 +70,19 @@ public class SuperPickaxeCommands { return; } - session.setLeftClickMode(new AreaPickaxe(range)); + session.setSuperPickaxe(new AreaPickaxe(range)); session.enableSuperPickAxe(); player.print("Mode changed. Left click with a pickaxe. // to disable."); } @Command( - aliases = {"recur"}, + aliases = {"recur", "recursive"}, usage = "", desc = "Enable the recursive super pickaxe pickaxe mode", min = 1, max = 1 ) - @CommandPermissions({"worldedit.superpickaxe.pickaxe.recursive"}) + @CommandPermissions({"worldedit.superpickaxe.recursive"}) public static void recursive(CommandContext args, WorldEdit we, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { @@ -115,143 +95,8 @@ public class SuperPickaxeCommands { return; } - session.setLeftClickMode(new RecursivePickaxe(range)); + session.setSuperPickaxe(new RecursivePickaxe(range)); session.enableSuperPickAxe(); player.print("Mode changed. Left click with a pickaxe. // to disable."); } - - @Command( - aliases = {"none"}, - usage = "", - desc = "Turn off all superpickaxe alternate modes", - min = 0, - max = 0 - ) - public static void none(CommandContext args, WorldEdit we, - LocalSession session, LocalPlayer player, EditSession editSession) - throws WorldEditException { - - session.setArmSwingMode(null); - session.setRightClickMode(null); - player.print("Now no longer equipping a tool."); - } - - @Command( - aliases = {"info"}, - usage = "", - desc = "Block information tool", - min = 0, - max = 0 - ) - @CommandPermissions({"worldedit.superpickaxe.info"}) - public static void info(CommandContext args, WorldEdit we, - LocalSession session, LocalPlayer player, EditSession editSession) - throws WorldEditException { - - session.setArmSwingMode(null); - session.setRightClickMode(new QueryTool()); - player.print("Info tool equipped. Right click with a pickaxe."); - } - - @Command( - aliases = {"tree"}, - usage = "[type]", - desc = "Tree generator tool", - min = 0, - max = 1 - ) - @CommandPermissions({"worldedit.superpickaxe.tree"}) - public static void tree(CommandContext args, WorldEdit we, - LocalSession session, LocalPlayer player, EditSession editSession) - throws WorldEditException { - - TreeGenerator.TreeType type = args.argsLength() > 0 ? - type = TreeGenerator.lookup(args.getString(0)) - : TreeGenerator.TreeType.TREE; - - if (type == null) { - player.printError("Tree type '" + args.getString(0) + "' is unknown."); - return; - } - - session.setArmSwingMode(null); - session.setRightClickMode(new TreePlanter(new TreeGenerator(type))); - player.print("Tree tool equipped. Right click grass with a pickaxe."); - } - - @Command( - aliases = {"repl"}, - usage = "", - desc = "Block replacer tool", - min = 1, - max = 1 - ) - @CommandPermissions({"worldedit.superpickaxe.replacer"}) - public static void repl(CommandContext args, WorldEdit we, - LocalSession session, LocalPlayer player, EditSession editSession) - throws WorldEditException { - - BaseBlock targetBlock = we.getBlock(player, args.getString(0)); - session.setArmSwingMode(null); - session.setRightClickMode(new BlockReplacer(targetBlock)); - player.print("Block replacer tool equipped. Right click with a pickaxe."); - } - - @Command( - aliases = {"cycler"}, - usage = "", - desc = "Block data cycler tool", - min = 0, - max = 0 - ) - @CommandPermissions({"worldedit.superpickaxe.data-cycler"}) - public static void cycler(CommandContext args, WorldEdit we, - LocalSession session, LocalPlayer player, EditSession editSession) - throws WorldEditException { - - session.setArmSwingMode(null); - session.setRightClickMode(new BlockDataCyler()); - player.print("Block cycler tool equipped. Right click with a pickaxe."); - } - - @Command( - aliases = {"/brush"}, - usage = "", - flags = "r", - desc = "Build from far away", - min = 0, - max = 0 - ) - @CommandPermissions({"worldedit.superpickaxe.drawing.brush"}) - public static void brush(CommandContext args, WorldEdit we, - LocalSession session, LocalPlayer player, EditSession editSession) - throws WorldEditException { - - boolean nonReplacing = args.hasFlag('r'); - - session.setRightClickMode(null); - session.setArmSwingMode(new Brush(nonReplacing)); - if (nonReplacing) { - player.print("Non-replacing brush tool equipped."); - } else { - player.print("Brush tool equipped. Swing with a pickaxe."); - } - } - - @Command( - aliases = {"/rbrush"}, - usage = "", - desc = "Brush tool that will only replace blocks", - min = 0, - max = 0 - ) - @CommandPermissions({"worldedit.superpickaxe.drawing.brush"}) - public static void rbrush(CommandContext args, WorldEdit we, - LocalSession session, LocalPlayer player, EditSession editSession) - throws WorldEditException { - - session.setRightClickMode(null); - session.setArmSwingMode(new ReplacingBrush()); - player.print("Replacing brush tool equipped. Swing with a pickaxe."); - } } diff --git a/src/com/sk89q/worldedit/commands/ToolCommands.java b/src/com/sk89q/worldedit/commands/ToolCommands.java new file mode 100644 index 000000000..ad19c4064 --- /dev/null +++ b/src/com/sk89q/worldedit/commands/ToolCommands.java @@ -0,0 +1,130 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010, 2011 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.commands; + +import com.sk89q.minecraft.util.commands.Command; +import com.sk89q.minecraft.util.commands.CommandContext; +import com.sk89q.minecraft.util.commands.CommandPermissions; +import com.sk89q.minecraft.util.commands.NestedCommand; +import com.sk89q.worldedit.*; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.tools.*; +import com.sk89q.worldedit.util.TreeGenerator; + +public class ToolCommands { + @Command( + aliases = {"none"}, + usage = "", + desc = "Turn off all superpickaxe alternate modes", + min = 0, + max = 0 + ) + public static void none(CommandContext args, WorldEdit we, + LocalSession session, LocalPlayer player, EditSession editSession) + throws WorldEditException { + + session.setTool(player.getItemInHand(), null); + player.print("Now no longer equipping a tool."); + } + + @Command( + aliases = {"info"}, + usage = "", + desc = "Block information tool", + min = 0, + max = 0 + ) + @CommandPermissions({"worldedit.tool.info"}) + public static void info(CommandContext args, WorldEdit we, + LocalSession session, LocalPlayer player, EditSession editSession) + throws WorldEditException { + + session.setTool(player.getItemInHand(), new QueryTool()); + player.print("Info tool equipped. Right click with a pickaxe."); + } + + @Command( + aliases = {"tree"}, + usage = "[type]", + desc = "Tree generator tool", + min = 0, + max = 1 + ) + @CommandPermissions({"worldedit.tool.tree"}) + public static void tree(CommandContext args, WorldEdit we, + LocalSession session, LocalPlayer player, EditSession editSession) + throws WorldEditException { + + TreeGenerator.TreeType type = args.argsLength() > 0 ? + type = TreeGenerator.lookup(args.getString(0)) + : TreeGenerator.TreeType.TREE; + + if (type == null) { + player.printError("Tree type '" + args.getString(0) + "' is unknown."); + return; + } + + session.setTool(player.getItemInHand(), new TreePlanter(new TreeGenerator(type))); + player.print("Tree tool equipped. Right click grass with a pickaxe."); + } + + @Command( + aliases = {"repl"}, + usage = "", + desc = "Block replacer tool", + min = 1, + max = 1 + ) + @CommandPermissions({"worldedit.tool.replacer"}) + public static void repl(CommandContext args, WorldEdit we, + LocalSession session, LocalPlayer player, EditSession editSession) + throws WorldEditException { + + BaseBlock targetBlock = we.getBlock(player, args.getString(0)); + session.setTool(player.getItemInHand(), new BlockReplacer(targetBlock)); + player.print("Block replacer tool equipped. Right click with a pickaxe."); + } + + @Command( + aliases = {"cycler"}, + usage = "", + desc = "Block data cycler tool", + min = 0, + max = 0 + ) + @CommandPermissions({"worldedit.tool.data-cycler"}) + public static void cycler(CommandContext args, WorldEdit we, + LocalSession session, LocalPlayer player, EditSession editSession) + throws WorldEditException { + + session.setTool(player.getItemInHand(), new BlockDataCyler()); + player.print("Block cycler tool equipped. Right click with a pickaxe."); + } + + @Command( + aliases = {"brush", "b"}, + desc = "Brush tool" + ) + @NestedCommand({BrushCommands.class}) + public static void brush(CommandContext args, WorldEdit we, + LocalSession session, LocalPlayer player, EditSession editSession) + throws WorldEditException { + } +} diff --git a/src/com/sk89q/worldedit/commands/ToolUtilCommands.java b/src/com/sk89q/worldedit/commands/ToolUtilCommands.java new file mode 100644 index 000000000..0894913d0 --- /dev/null +++ b/src/com/sk89q/worldedit/commands/ToolUtilCommands.java @@ -0,0 +1,93 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.commands; + +import com.sk89q.minecraft.util.commands.Command; +import com.sk89q.minecraft.util.commands.CommandContext; +import com.sk89q.minecraft.util.commands.CommandPermissions; +import com.sk89q.minecraft.util.commands.NestedCommand; +import com.sk89q.worldedit.*; +import com.sk89q.worldedit.masks.Mask; + +/** + * Tool commands. + * + * @author sk89q + */ +public class ToolUtilCommands { + @Command( + aliases = {"/", ","}, + usage = "", + desc = "Toggle the super pickaxe pickaxe function", + min = 0, + max = 0 + ) + @CommandPermissions({"worldedit.superpickaxe"}) + public static void togglePickaxe(CommandContext args, WorldEdit we, + LocalSession session, LocalPlayer player, EditSession editSession) + throws WorldEditException { + + if (session.toggleSuperPickAxe()) { + player.print("Super pick axe enabled."); + } else { + player.print("Super pick axe disabled."); + } + } + + @Command( + aliases = {"pickaxe", "pa", "spa"}, + desc = "Select super pickaxe mode" + ) + @NestedCommand({SuperPickaxeCommands.class}) + public static void pickaxe(CommandContext args, WorldEdit we, + LocalSession session, LocalPlayer player, EditSession editSession) + throws WorldEditException { + } + + @Command( + aliases = {"tool", "t"}, + desc = "Select a tool to bind" + ) + @NestedCommand({ToolCommands.class}) + public static void tool(CommandContext args, WorldEdit we, + LocalSession session, LocalPlayer player, EditSession editSession) + throws WorldEditException { + } + + @Command( + aliases = {"mask"}, + usage = "[mask]", + desc = "Set the brush mask", + min = 0, + max = 1 + ) + public static void mask(CommandContext args, WorldEdit we, + LocalSession session, LocalPlayer player, EditSession editSession) + throws WorldEditException { + if (args.argsLength() == 0) { + session.getBrushTool(player.getItemInHand()).setMask(null); + player.print("Brush mask disabled."); + } else { + Mask mask = we.getBlockMask(player, args.getString(0)); + session.getBrushTool(player.getItemInHand()).setMask(mask); + player.print("Brush mask set."); + } + } +} diff --git a/src/com/sk89q/worldedit/filters/GaussianKernel.java b/src/com/sk89q/worldedit/filtering/GaussianKernel.java old mode 100755 new mode 100644 similarity index 94% rename from src/com/sk89q/worldedit/filters/GaussianKernel.java rename to src/com/sk89q/worldedit/filtering/GaussianKernel.java index 4241f8b95..47bf03bda --- a/src/com/sk89q/worldedit/filters/GaussianKernel.java +++ b/src/com/sk89q/worldedit/filtering/GaussianKernel.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.filters; +package com.sk89q.worldedit.filtering; import java.awt.image.Kernel; diff --git a/src/com/sk89q/worldedit/filters/HeightMapFilter.java b/src/com/sk89q/worldedit/filtering/HeightMapFilter.java old mode 100755 new mode 100644 similarity index 95% rename from src/com/sk89q/worldedit/filters/HeightMapFilter.java rename to src/com/sk89q/worldedit/filtering/HeightMapFilter.java index 124dab288..986be98a1 --- a/src/com/sk89q/worldedit/filters/HeightMapFilter.java +++ b/src/com/sk89q/worldedit/filtering/HeightMapFilter.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.filters; +package com.sk89q.worldedit.filtering; import java.awt.image.Kernel; diff --git a/src/com/sk89q/worldedit/filters/LinearKernel.java b/src/com/sk89q/worldedit/filtering/LinearKernel.java old mode 100755 new mode 100644 similarity index 93% rename from src/com/sk89q/worldedit/filters/LinearKernel.java rename to src/com/sk89q/worldedit/filtering/LinearKernel.java index 021514b61..77b01432d --- a/src/com/sk89q/worldedit/filters/LinearKernel.java +++ b/src/com/sk89q/worldedit/filtering/LinearKernel.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.filters; +package com.sk89q.worldedit.filtering; import java.awt.image.Kernel; diff --git a/src/com/sk89q/worldedit/superpickaxe/brushes/HollowCylinderBrushShape.java b/src/com/sk89q/worldedit/masks/BlockTypeMask.java similarity index 53% rename from src/com/sk89q/worldedit/superpickaxe/brushes/HollowCylinderBrushShape.java rename to src/com/sk89q/worldedit/masks/BlockTypeMask.java index 07f3319e8..52c52d0b1 100644 --- a/src/com/sk89q/worldedit/superpickaxe/brushes/HollowCylinderBrushShape.java +++ b/src/com/sk89q/worldedit/masks/BlockTypeMask.java @@ -17,26 +17,40 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.superpickaxe.brushes; +package com.sk89q.worldedit.masks; +import java.util.HashSet; +import java.util.Set; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.blocks.BaseBlock; -public class HollowCylinderBrushShape implements BrushShape { - private BaseBlock targetBlock; - private int radius; - private int height; +/** + * A filter that matches blocks based on block types. + * + * @author sk89q + */ +public class BlockTypeMask implements Mask { + private Set types; - public HollowCylinderBrushShape(BaseBlock targetBlock, int radius, int height) { - this.targetBlock = targetBlock; - this.radius = radius; - this.height = height; + public BlockTypeMask() { + types = new HashSet(); } - public void build(EditSession editSession, Vector pos) - throws MaxChangedBlocksException { - editSession.makeHollowCylinder(pos, targetBlock, radius, height); + public BlockTypeMask(Set types) { + this.types = types; } + + public BlockTypeMask(int type) { + this(); + add(type); + } + + public void add(int type) { + types.add(type); + } + + public boolean matches(EditSession editSession, Vector pos) { + return types.contains(editSession.getBlockType(pos)); + } + } diff --git a/src/com/sk89q/worldedit/masks/ExistingBlockMask.java b/src/com/sk89q/worldedit/masks/ExistingBlockMask.java new file mode 100644 index 000000000..05ac66585 --- /dev/null +++ b/src/com/sk89q/worldedit/masks/ExistingBlockMask.java @@ -0,0 +1,29 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010, 2011 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.masks; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.Vector; + +public class ExistingBlockMask implements Mask { + public boolean matches(EditSession editSession, Vector pos) { + return editSession.getBlockType(pos) != 0; + } +} diff --git a/src/com/sk89q/worldedit/masks/Mask.java b/src/com/sk89q/worldedit/masks/Mask.java new file mode 100644 index 000000000..3384cdb75 --- /dev/null +++ b/src/com/sk89q/worldedit/masks/Mask.java @@ -0,0 +1,42 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010, 2011 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.masks; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.Vector; + +/** + * Base matcher for the block filtering framework. Implementing classes + * can be used to filter blocks to set or replace + * + * @author sk89q + */ +public interface Mask { + /** + * Given a block position, this method returns true if the block at + * that position matches the filter. Block information is not provided + * as getting a BaseBlock has unneeded overhead in most block querying + * situations (enumerating a chest's contents is a waste, for example). + * + * @param pos + * @return + */ + public boolean matches(EditSession editSession, Vector pos); +} diff --git a/src/com/sk89q/worldedit/scripting/CraftScriptContext.java b/src/com/sk89q/worldedit/scripting/CraftScriptContext.java index 138730af4..25463883e 100644 --- a/src/com/sk89q/worldedit/scripting/CraftScriptContext.java +++ b/src/com/sk89q/worldedit/scripting/CraftScriptContext.java @@ -61,7 +61,7 @@ public class CraftScriptContext extends CraftScriptEnvironment { */ public EditSession remember() { EditSession editSession = - new EditSession(server, player.getWorld(), + new EditSession(player.getWorld(), session.getBlockChangeLimit(), session.getBlockBag(player)); editSession.enableQueue(); editSessions.add(editSession); diff --git a/src/com/sk89q/worldedit/superpickaxe/Brush.java b/src/com/sk89q/worldedit/superpickaxe/Brush.java deleted file mode 100644 index 2f8ee30db..000000000 --- a/src/com/sk89q/worldedit/superpickaxe/Brush.java +++ /dev/null @@ -1,79 +0,0 @@ -// $Id$ -/* - * WorldEdit - * Copyright (C) 2010 sk89q - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . -*/ - -package com.sk89q.worldedit.superpickaxe; - -import com.sk89q.worldedit.*; -import com.sk89q.worldedit.bags.BlockBag; -import com.sk89q.worldedit.superpickaxe.brushes.BrushShape; - -/** - * Builds a shape at the place being looked at. - * - * @author sk89q - */ -public class Brush implements SuperPickaxeMode { - private boolean nonReplacing; - - public Brush(boolean nonReplacing) { - this.nonReplacing = nonReplacing; - } - - @Override - public boolean act(ServerInterface server, LocalConfiguration config, - LocalPlayer player, LocalSession session, WorldVector clicked) { - WorldVector target = player.getBlockTrace(500); - - if (target == null) { - player.printError("No block in sight!"); - return true; - } - - BlockBag bag = session.getBlockBag(player); - - BrushShape shape = session.getBrushShape(); - - if (shape == null) { - player.printError("Select a brush first."); - return true; - } - - ReplacingEditSession editSession = new ReplacingEditSession(server, target.getWorld(), - session.getBlockChangeLimit(), bag); - - if (nonReplacing) { - editSession.disableReplacing(); - } - - try { - shape.build(editSession, target); - } catch (MaxChangedBlocksException e) { - player.printError("Max blocks change limit reached."); - } finally { - if (bag != null) { - bag.flushChanges(); - } - editSession.enableReplacing(); - session.remember(editSession); - } - - return true; - } - -} diff --git a/src/com/sk89q/worldedit/superpickaxe/AreaPickaxe.java b/src/com/sk89q/worldedit/tools/AreaPickaxe.java similarity index 89% rename from src/com/sk89q/worldedit/superpickaxe/AreaPickaxe.java rename to src/com/sk89q/worldedit/tools/AreaPickaxe.java index fa5af2980..c51292a97 100644 --- a/src/com/sk89q/worldedit/superpickaxe/AreaPickaxe.java +++ b/src/com/sk89q/worldedit/tools/AreaPickaxe.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.superpickaxe; +package com.sk89q.worldedit.tools; import com.sk89q.worldedit.*; import com.sk89q.worldedit.blocks.BaseBlock; @@ -28,7 +28,7 @@ import com.sk89q.worldedit.blocks.BlockID; * * @author sk89q */ -public class AreaPickaxe implements SuperPickaxeMode { +public class AreaPickaxe implements BlockTool { private static final BaseBlock air = new BaseBlock(0); private int range; @@ -52,9 +52,9 @@ public class AreaPickaxe implements SuperPickaxeMode { if (initialType == BlockID.BEDROCK && !player.canDestroyBedrock()) { return true; } - - EditSession editSession = new EditSession(server, world, - session.getBlockChangeLimit()); + + EditSession editSession = + new EditSession(world, session.getBlockChangeLimit()); try { for (int x = ox - range; x <= ox + range; x++) { diff --git a/src/com/sk89q/worldedit/superpickaxe/BlockDataCyler.java b/src/com/sk89q/worldedit/tools/BlockDataCyler.java similarity index 94% rename from src/com/sk89q/worldedit/superpickaxe/BlockDataCyler.java rename to src/com/sk89q/worldedit/tools/BlockDataCyler.java index 5f8b1576b..b8616e037 100644 --- a/src/com/sk89q/worldedit/superpickaxe/BlockDataCyler.java +++ b/src/com/sk89q/worldedit/tools/BlockDataCyler.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.superpickaxe; +package com.sk89q.worldedit.tools; import com.sk89q.worldedit.*; import com.sk89q.worldedit.blocks.BlockID; @@ -27,7 +27,7 @@ import com.sk89q.worldedit.blocks.BlockID; * * @author sk89q */ -public class BlockDataCyler implements SuperPickaxeMode { +public class BlockDataCyler implements BlockTool { @Override public boolean act(ServerInterface server, LocalConfiguration config, LocalPlayer player, LocalSession session, WorldVector clicked) { diff --git a/src/com/sk89q/worldedit/superpickaxe/BlockReplacer.java b/src/com/sk89q/worldedit/tools/BlockReplacer.java similarity index 85% rename from src/com/sk89q/worldedit/superpickaxe/BlockReplacer.java rename to src/com/sk89q/worldedit/tools/BlockReplacer.java index 9016e704e..4f00e71d5 100644 --- a/src/com/sk89q/worldedit/superpickaxe/BlockReplacer.java +++ b/src/com/sk89q/worldedit/tools/BlockReplacer.java @@ -17,18 +17,18 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.superpickaxe; +package com.sk89q.worldedit.tools; import com.sk89q.worldedit.*; import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.blocks.BaseBlock; /** - * A smode that replaces one block. + * A mode that replaces one block. * * @author sk89q */ -public class BlockReplacer implements SuperPickaxeMode { +public class BlockReplacer implements BlockTool { private BaseBlock targetBlock; public BlockReplacer(BaseBlock targetBlock) { @@ -42,7 +42,7 @@ public class BlockReplacer implements SuperPickaxeMode { BlockBag bag = session.getBlockBag(player); LocalWorld world = clicked.getWorld(); - EditSession editSession = new EditSession(server, world, -1, bag); + EditSession editSession = new EditSession(world, -1, bag); try { editSession.setBlock(clicked, targetBlock); diff --git a/src/com/sk89q/worldedit/superpickaxe/SuperPickaxeMode.java b/src/com/sk89q/worldedit/tools/BlockTool.java similarity index 84% rename from src/com/sk89q/worldedit/superpickaxe/SuperPickaxeMode.java rename to src/com/sk89q/worldedit/tools/BlockTool.java index 7919022b3..0af87a2c1 100644 --- a/src/com/sk89q/worldedit/superpickaxe/SuperPickaxeMode.java +++ b/src/com/sk89q/worldedit/tools/BlockTool.java @@ -17,20 +17,22 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.superpickaxe; +package com.sk89q.worldedit.tools; import com.sk89q.worldedit.*; /** - * Represents a super pickaxe mode. + * Represents a tool that uses a block.. * * @author sk89q */ -public interface SuperPickaxeMode { +public interface BlockTool extends Tool { /** * Perform the action. Should return true to deny the default * action. * + * @param server + * @param config * @param player * @param session * @param clicked diff --git a/src/com/sk89q/worldedit/tools/Brush.java b/src/com/sk89q/worldedit/tools/Brush.java new file mode 100644 index 000000000..2c27197bc --- /dev/null +++ b/src/com/sk89q/worldedit/tools/Brush.java @@ -0,0 +1,159 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.tools; + +import com.sk89q.worldedit.*; +import com.sk89q.worldedit.bags.BlockBag; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.blocks.BlockID; +import com.sk89q.worldedit.masks.Mask; +import com.sk89q.worldedit.patterns.Pattern; +import com.sk89q.worldedit.patterns.SingleBlockPattern; +import com.sk89q.worldedit.tools.brushes.BrushShape; +import com.sk89q.worldedit.tools.brushes.SphereBrush; + +/** + * Builds a shape at the place being looked at. + * + * @author sk89q + */ +public class Brush implements TraceTool { + private Mask mask = null; + private BrushShape brush = new SphereBrush(); + private Pattern material = new SingleBlockPattern(new BaseBlock(BlockID.COBBLESTONE)); + private int size = 1; + + /** + * Get the filter. + * + * @return the filter + */ + public Mask getMask() { + return mask; + } + + /** + * Set the block filter used for identifying blocks to replace. + * + * @param filter the filter to set + */ + public void setMask(Mask filter) { + this.mask = filter; + } + + /** + * Set the brush. + * + * @param brush + */ + public void setBrush(BrushShape brush) { + this.brush = brush; + } + + /** + * Get the current brush. + * + * @return + */ + public BrushShape getBrush() { + return brush; + } + + /** + * Set the material. + * + * @param material + */ + public void setFill(Pattern material) { + this.material = material; + } + + /** + * Get the material. + * + * @return + */ + public Pattern getMaterial() { + return material; + } + + /** + * Get the set brush size. + * + * @return + */ + public int getSize() { + return size; + } + + /** + * Set the set brush size. + * + * @param size + */ + public void setSize(int size) { + this.size = size; + } + + /** + * Perform the action. Should return true to deny the default + * action. + * + * @param player + * @param session + * @return true to deny + */ + @Override + public boolean act(ServerInterface server, LocalConfiguration config, + LocalPlayer player, LocalSession session) { + WorldVector target = player.getBlockTrace(500); + + if (target == null) { + player.printError("No block in sight!"); + return true; + } + + BlockBag bag = session.getBlockBag(player); + + EditSession editSession; + + if (mask == null) { + editSession = new EditSession(target.getWorld(), + session.getBlockChangeLimit(), bag); + } else { + editSession = new ReplacingEditSession(target.getWorld(), + session.getBlockChangeLimit(), bag, mask); + } + + try { + brush.build(editSession, target, material, size); + } catch (MaxChangedBlocksException e) { + player.printError("Max blocks change limit reached."); + } finally { + if (bag != null) { + bag.flushChanges(); + } + session.remember(editSession); + } + + return true; + } + +} diff --git a/src/com/sk89q/worldedit/superpickaxe/QueryTool.java b/src/com/sk89q/worldedit/tools/QueryTool.java similarity index 88% rename from src/com/sk89q/worldedit/superpickaxe/QueryTool.java rename to src/com/sk89q/worldedit/tools/QueryTool.java index d0bd2de43..f8ad88313 100644 --- a/src/com/sk89q/worldedit/superpickaxe/QueryTool.java +++ b/src/com/sk89q/worldedit/tools/QueryTool.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.superpickaxe; +package com.sk89q.worldedit.tools; import com.sk89q.worldedit.*; import com.sk89q.worldedit.blocks.*; @@ -27,14 +27,14 @@ import com.sk89q.worldedit.blocks.*; * * @author sk89q */ -public class QueryTool implements SuperPickaxeMode { +public class QueryTool implements BlockTool { @Override public boolean act(ServerInterface server, LocalConfiguration config, LocalPlayer player, LocalSession session, WorldVector clicked) { LocalWorld world = clicked.getWorld(); - BaseBlock block = (new EditSession(server, world, 0)).rawGetBlock(clicked); + BaseBlock block = (new EditSession(world, 0)).rawGetBlock(clicked); player.print("\u00A79@" + clicked + ": " + "\u00A7e" + "Type: " + block.getType() + "\u00A77" + " (" diff --git a/src/com/sk89q/worldedit/superpickaxe/RecursivePickaxe.java b/src/com/sk89q/worldedit/tools/RecursivePickaxe.java similarity index 91% rename from src/com/sk89q/worldedit/superpickaxe/RecursivePickaxe.java rename to src/com/sk89q/worldedit/tools/RecursivePickaxe.java index 65ea2b8eb..63db01620 100644 --- a/src/com/sk89q/worldedit/superpickaxe/RecursivePickaxe.java +++ b/src/com/sk89q/worldedit/tools/RecursivePickaxe.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.superpickaxe; +package com.sk89q.worldedit.tools; import java.util.HashSet; import java.util.Set; @@ -31,7 +31,7 @@ import com.sk89q.worldedit.blocks.BlockID; * * @author sk89q */ -public class RecursivePickaxe implements SuperPickaxeMode { +public class RecursivePickaxe implements BlockTool { private static final BaseBlock air = new BaseBlock(0); private int range; @@ -54,8 +54,8 @@ public class RecursivePickaxe implements SuperPickaxeMode { return true; } - EditSession editSession = new EditSession(server, world, - session.getBlockChangeLimit()); + EditSession editSession = + new EditSession(world, session.getBlockChangeLimit()); try { recurse(server, editSession, world, clicked.toBlockVector(), diff --git a/src/com/sk89q/worldedit/superpickaxe/ReplacingBrush.java b/src/com/sk89q/worldedit/tools/ReplacingBrush.java similarity index 90% rename from src/com/sk89q/worldedit/superpickaxe/ReplacingBrush.java rename to src/com/sk89q/worldedit/tools/ReplacingBrush.java index c3ba719ac..ceaca760b 100644 --- a/src/com/sk89q/worldedit/superpickaxe/ReplacingBrush.java +++ b/src/com/sk89q/worldedit/tools/ReplacingBrush.java @@ -17,18 +17,18 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.superpickaxe; +package com.sk89q.worldedit.tools; import com.sk89q.worldedit.*; import com.sk89q.worldedit.bags.BlockBag; -import com.sk89q.worldedit.superpickaxe.brushes.BrushShape; +import com.sk89q.worldedit.tools.brushes.BrushShape; /** * Builds a sphere at the place being looked at. * * @author sk89q */ -public class ReplacingBrush implements SuperPickaxeMode { +public class ReplacingBrush implements Tool { public boolean act(ServerInterface server, LocalConfiguration config, LocalPlayer player, LocalSession session, WorldVector clicked) { WorldVector target = player.getBlockTrace(500); diff --git a/src/com/sk89q/worldedit/superpickaxe/SinglePickaxe.java b/src/com/sk89q/worldedit/tools/SinglePickaxe.java similarity index 90% rename from src/com/sk89q/worldedit/superpickaxe/SinglePickaxe.java rename to src/com/sk89q/worldedit/tools/SinglePickaxe.java index 1d15ef531..2ccacdb8e 100644 --- a/src/com/sk89q/worldedit/superpickaxe/SinglePickaxe.java +++ b/src/com/sk89q/worldedit/tools/SinglePickaxe.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.superpickaxe; +package com.sk89q.worldedit.tools; import com.sk89q.worldedit.*; import com.sk89q.worldedit.blocks.BlockID; @@ -27,7 +27,7 @@ import com.sk89q.worldedit.blocks.BlockID; * * @author sk89q */ -public class SinglePickaxe implements SuperPickaxeMode { +public class SinglePickaxe implements BlockTool { @Override public boolean act(ServerInterface server, LocalConfiguration config, LocalPlayer player, LocalSession session, WorldVector clicked) { diff --git a/src/com/sk89q/worldedit/tools/Tool.java b/src/com/sk89q/worldedit/tools/Tool.java new file mode 100644 index 000000000..5d4e02071 --- /dev/null +++ b/src/com/sk89q/worldedit/tools/Tool.java @@ -0,0 +1,29 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010, 2011 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.tools; + +/** + * Represents a tool. This interface alone defines nothing. A tool also + * has to implement BlockTool or TraceTool. + * + * @author sk89q + */ +public abstract interface Tool { +} diff --git a/src/com/sk89q/worldedit/tools/TraceTool.java b/src/com/sk89q/worldedit/tools/TraceTool.java new file mode 100644 index 000000000..661e0dafb --- /dev/null +++ b/src/com/sk89q/worldedit/tools/TraceTool.java @@ -0,0 +1,45 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010, 2011 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.tools; + +import com.sk89q.worldedit.LocalConfiguration; +import com.sk89q.worldedit.LocalPlayer; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.ServerInterface; + +/** + * Represents a tool that does not require a block. + * + * @author sk89q + */ +public interface TraceTool extends Tool { + /** + * Perform the action. Should return true to deny the default + * action. + * + * @param server + * @param config + * @param player + * @param session + * @return true to deny + */ + public boolean act(ServerInterface server, LocalConfiguration config, + LocalPlayer player, LocalSession session); +} diff --git a/src/com/sk89q/worldedit/superpickaxe/TreePlanter.java b/src/com/sk89q/worldedit/tools/TreePlanter.java similarity index 87% rename from src/com/sk89q/worldedit/superpickaxe/TreePlanter.java rename to src/com/sk89q/worldedit/tools/TreePlanter.java index ec5017634..e36129078 100644 --- a/src/com/sk89q/worldedit/superpickaxe/TreePlanter.java +++ b/src/com/sk89q/worldedit/tools/TreePlanter.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.superpickaxe; +package com.sk89q.worldedit.tools; import com.sk89q.worldedit.*; import com.sk89q.worldedit.util.TreeGenerator; @@ -27,7 +27,7 @@ import com.sk89q.worldedit.util.TreeGenerator; * * @author sk89q */ -public class TreePlanter implements SuperPickaxeMode { +public class TreePlanter implements BlockTool { private TreeGenerator gen; public TreePlanter(TreeGenerator gen) { @@ -40,7 +40,7 @@ public class TreePlanter implements SuperPickaxeMode { LocalWorld world = clicked.getWorld(); EditSession editSession = - new EditSession(server, world, session.getBlockChangeLimit()); + new EditSession(world, session.getBlockChangeLimit()); try { if (!gen.generate(editSession, clicked.add(0, 1, 0))) { diff --git a/src/com/sk89q/worldedit/superpickaxe/brushes/BrushShape.java b/src/com/sk89q/worldedit/tools/brushes/BrushShape.java similarity index 81% rename from src/com/sk89q/worldedit/superpickaxe/brushes/BrushShape.java rename to src/com/sk89q/worldedit/tools/brushes/BrushShape.java index 9e2e4281b..eeee909c6 100644 --- a/src/com/sk89q/worldedit/superpickaxe/brushes/BrushShape.java +++ b/src/com/sk89q/worldedit/tools/brushes/BrushShape.java @@ -17,11 +17,12 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.superpickaxe.brushes; +package com.sk89q.worldedit.tools.brushes; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.patterns.Pattern; /** * Represents a shape. @@ -34,8 +35,10 @@ public interface BrushShape { * * @param build * @param pos + * @param mat + * @param size * @throws MaxChangedBlocksException */ - public void build(EditSession editSession, Vector pos) + public void build(EditSession editSession, Vector pos, Pattern mat, int size) throws MaxChangedBlocksException; } diff --git a/src/com/sk89q/worldedit/superpickaxe/brushes/ClipboardBrushShape.java b/src/com/sk89q/worldedit/tools/brushes/ClipboardBrush.java similarity index 78% rename from src/com/sk89q/worldedit/superpickaxe/brushes/ClipboardBrushShape.java rename to src/com/sk89q/worldedit/tools/brushes/ClipboardBrush.java index d72b9f8af..9dddc9323 100644 --- a/src/com/sk89q/worldedit/superpickaxe/brushes/ClipboardBrushShape.java +++ b/src/com/sk89q/worldedit/tools/brushes/ClipboardBrush.java @@ -17,23 +17,24 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.superpickaxe.brushes; +package com.sk89q.worldedit.tools.brushes; import com.sk89q.worldedit.CuboidClipboard; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.patterns.Pattern; -public class ClipboardBrushShape implements BrushShape { +public class ClipboardBrush implements BrushShape { private CuboidClipboard clipboard; private boolean noAir; - public ClipboardBrushShape(CuboidClipboard clipboard, boolean noAir) { + public ClipboardBrush(CuboidClipboard clipboard, boolean noAir) { this.clipboard = clipboard; this.noAir = noAir; } - public void build(EditSession editSession, Vector pos) + public void build(EditSession editSession, Vector pos, Pattern mat, int size) throws MaxChangedBlocksException { clipboard.place(editSession, pos.subtract(clipboard.getSize().divide(2)), noAir); diff --git a/src/com/sk89q/worldedit/superpickaxe/brushes/CylinderBrushShape.java b/src/com/sk89q/worldedit/tools/brushes/CylinderBrush.java similarity index 65% rename from src/com/sk89q/worldedit/superpickaxe/brushes/CylinderBrushShape.java rename to src/com/sk89q/worldedit/tools/brushes/CylinderBrush.java index 6dadd99a0..cfc80e4d6 100644 --- a/src/com/sk89q/worldedit/superpickaxe/brushes/CylinderBrushShape.java +++ b/src/com/sk89q/worldedit/tools/brushes/CylinderBrush.java @@ -17,26 +17,22 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.superpickaxe.brushes; +package com.sk89q.worldedit.tools.brushes; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.patterns.Pattern; -public class CylinderBrushShape implements BrushShape { - private BaseBlock targetBlock; - private int radius; +public class CylinderBrush implements BrushShape { private int height; - public CylinderBrushShape(BaseBlock targetBlock, int radius, int height) { - this.targetBlock = targetBlock; - this.radius = radius; + public CylinderBrush(int height) { this.height = height; } - public void build(EditSession editSession, Vector pos) + public void build(EditSession editSession, Vector pos, Pattern mat, int size) throws MaxChangedBlocksException { - editSession.makeCylinder(pos, targetBlock, radius, height); + editSession.makeCylinder(pos, mat, size, height); } } diff --git a/src/com/sk89q/worldedit/superpickaxe/brushes/SphereBrushShape.java b/src/com/sk89q/worldedit/tools/brushes/HollowCylinderBrush.java similarity index 64% rename from src/com/sk89q/worldedit/superpickaxe/brushes/SphereBrushShape.java rename to src/com/sk89q/worldedit/tools/brushes/HollowCylinderBrush.java index 0b3422535..e7ddaa685 100644 --- a/src/com/sk89q/worldedit/superpickaxe/brushes/SphereBrushShape.java +++ b/src/com/sk89q/worldedit/tools/brushes/HollowCylinderBrush.java @@ -17,24 +17,22 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.superpickaxe.brushes; +package com.sk89q.worldedit.tools.brushes; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.patterns.Pattern; -public class SphereBrushShape implements BrushShape { - private BaseBlock targetBlock; - private int radius; +public class HollowCylinderBrush implements BrushShape { + private int height; - public SphereBrushShape(BaseBlock targetBlock, int radius) { - this.targetBlock = targetBlock; - this.radius = radius; + public HollowCylinderBrush(int height) { + this.height = height; } - public void build(EditSession editSession, Vector pos) + public void build(EditSession editSession, Vector pos, Pattern mat, int size) throws MaxChangedBlocksException { - editSession.makeSphere(pos, targetBlock, radius, true); + editSession.makeHollowCylinder(pos, mat, size, height); } } diff --git a/src/com/sk89q/worldedit/superpickaxe/brushes/HollowSphereBrushShape.java b/src/com/sk89q/worldedit/tools/brushes/HollowSphereBrush.java similarity index 63% rename from src/com/sk89q/worldedit/superpickaxe/brushes/HollowSphereBrushShape.java rename to src/com/sk89q/worldedit/tools/brushes/HollowSphereBrush.java index e9e55205e..576f12192 100644 --- a/src/com/sk89q/worldedit/superpickaxe/brushes/HollowSphereBrushShape.java +++ b/src/com/sk89q/worldedit/tools/brushes/HollowSphereBrush.java @@ -17,24 +17,19 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.superpickaxe.brushes; +package com.sk89q.worldedit.tools.brushes; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.patterns.Pattern; -public class HollowSphereBrushShape implements BrushShape { - private BaseBlock targetBlock; - private int radius; - - public HollowSphereBrushShape(BaseBlock targetBlock, int radius) { - this.targetBlock = targetBlock; - this.radius = radius; +public class HollowSphereBrush implements BrushShape { + public HollowSphereBrush() { } - public void build(EditSession editSession, Vector pos) + public void build(EditSession editSession, Vector pos, Pattern mat, int size) throws MaxChangedBlocksException { - editSession.makeSphere(pos, targetBlock, radius, false); + editSession.makeSphere(pos, mat, size, false); } } diff --git a/src/com/sk89q/worldedit/tools/brushes/SphereBrush.java b/src/com/sk89q/worldedit/tools/brushes/SphereBrush.java new file mode 100644 index 000000000..82f9af81a --- /dev/null +++ b/src/com/sk89q/worldedit/tools/brushes/SphereBrush.java @@ -0,0 +1,35 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010, 2011 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.tools.brushes; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.patterns.Pattern; + +public class SphereBrush implements BrushShape { + public SphereBrush() { + } + + public void build(EditSession editSession, Vector pos, Pattern mat, int size) + throws MaxChangedBlocksException { + editSession.makeSphere(pos, mat, size, true); + } +}