Removed LocalPlayer from commands and removed various uses of old Mask and Pattern classes.

This commit is contained in:
sk89q 2014-06-28 01:01:49 -07:00
parent ec28cd626c
commit f64107c2c0
23 changed files with 622 additions and 800 deletions

View File

@ -30,13 +30,14 @@ import com.sk89q.worldedit.command.tool.Tool;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.internal.cui.CUIRegion; import com.sk89q.worldedit.internal.cui.CUIRegion;
import com.sk89q.worldedit.internal.cui.SelectionShapeEvent; import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
import com.sk89q.worldedit.masks.Mask;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.snapshot.Snapshot; import com.sk89q.worldedit.world.snapshot.Snapshot;
@ -141,6 +142,17 @@ public class LocalSession {
* @return whether anything was undone * @return whether anything was undone
*/ */
public EditSession undo(BlockBag newBlockBag, LocalPlayer player) { public EditSession undo(BlockBag newBlockBag, LocalPlayer player) {
return undo(newBlockBag, (Player) player);
}
/**
* Performs an undo.
*
* @param newBlockBag
* @param player
* @return whether anything was undone
*/
public EditSession undo(BlockBag newBlockBag, Player player) {
--historyPointer; --historyPointer;
if (historyPointer >= 0) { if (historyPointer >= 0) {
EditSession editSession = history.get(historyPointer); EditSession editSession = history.get(historyPointer);
@ -164,6 +176,17 @@ public class LocalSession {
* @return whether anything was redone * @return whether anything was redone
*/ */
public EditSession redo(BlockBag newBlockBag, LocalPlayer player) { public EditSession redo(BlockBag newBlockBag, LocalPlayer player) {
return redo(newBlockBag, (Player) player);
}
/**
* Performs a redo
*
* @param newBlockBag
* @param player
* @return whether anything was redone
*/
public EditSession redo(BlockBag newBlockBag, Player player) {
if (historyPointer < history.size()) { if (historyPointer < history.size()) {
EditSession editSession = history.get(historyPointer); EditSession editSession = history.get(historyPointer);
EditSession newEditSession = WorldEdit.getInstance().getEditSessionFactory() EditSession newEditSession = WorldEdit.getInstance().getEditSessionFactory()
@ -577,7 +600,7 @@ public class LocalSession {
* *
* @param player * @param player
*/ */
public void dispatchCUISetup(LocalPlayer player) { public void dispatchCUISetup(Player player) {
if (selector != null) { if (selector != null) {
dispatchCUISelection(player); dispatchCUISelection(player);
} }
@ -588,7 +611,7 @@ public class LocalSession {
* *
* @param player * @param player
*/ */
public void dispatchCUISelection(LocalPlayer player) { public void dispatchCUISelection(Player player) {
if (!hasCUISupport) { if (!hasCUISupport) {
return; return;
} }
@ -732,9 +755,6 @@ public class LocalSession {
getBlockChangeLimit(), blockBag, player); getBlockChangeLimit(), blockBag, player);
editSession.setFastMode(fastMode); editSession.setFastMode(fastMode);
Request.request().setEditSession(editSession); Request.request().setEditSession(editSession);
if (mask != null && player instanceof LocalPlayer) {
mask.prepare(this, (LocalPlayer) player, null);
}
editSession.setMask(mask); editSession.setMask(mask);
return editSession; return editSession;
@ -775,4 +795,15 @@ public class LocalSession {
public void setMask(Mask mask) { public void setMask(Mask mask) {
this.mask = mask; this.mask = mask;
} }
/**
* Set a mask.
*
* @param mask mask or null
*/
@SuppressWarnings("deprecation")
public void setMask(com.sk89q.worldedit.masks.Mask mask) {
setMask(mask != null ? Masks.wrap(mask) : null);
}
} }

View File

@ -183,7 +183,7 @@ public class WorldEdit {
* @deprecated use {@link #getSessionManager()} * @deprecated use {@link #getSessionManager()}
*/ */
@Deprecated @Deprecated
public LocalSession getSession(LocalPlayer player) { public LocalSession getSession(Player player) {
return sessions.get(player); return sessions.get(player);
} }
@ -191,7 +191,7 @@ public class WorldEdit {
* @deprecated use {@link #getSessionManager()} * @deprecated use {@link #getSessionManager()}
*/ */
@Deprecated @Deprecated
public void removeSession(LocalPlayer player) { public void removeSession(Player player) {
sessions.remove(player); sessions.remove(player);
} }
@ -207,7 +207,7 @@ public class WorldEdit {
* @deprecated use {@link #getSessionManager()} * @deprecated use {@link #getSessionManager()}
*/ */
@Deprecated @Deprecated
public boolean hasSession(LocalPlayer player) { public boolean hasSession(Player player) {
return sessions.contains(player); return sessions.contains(player);
} }
@ -216,7 +216,7 @@ public class WorldEdit {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Deprecated @Deprecated
public BaseBlock getBlock(LocalPlayer player, String arg, boolean allAllowed) throws WorldEditException { public BaseBlock getBlock(Player player, String arg, boolean allAllowed) throws WorldEditException {
return getBlock(player, arg, allAllowed, false); return getBlock(player, arg, allAllowed, false);
} }
@ -225,7 +225,7 @@ public class WorldEdit {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Deprecated @Deprecated
public BaseBlock getBlock(LocalPlayer player, String arg, boolean allAllowed, boolean allowNoData) throws WorldEditException { public BaseBlock getBlock(Player player, String arg, boolean allAllowed, boolean allowNoData) throws WorldEditException {
ParserContext context = new ParserContext(); ParserContext context = new ParserContext();
context.setActor(player); context.setActor(player);
context.setWorld(player.getWorld()); context.setWorld(player.getWorld());
@ -240,7 +240,7 @@ public class WorldEdit {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Deprecated @Deprecated
public BaseBlock getBlock(LocalPlayer player, String id) throws WorldEditException { public BaseBlock getBlock(Player player, String id) throws WorldEditException {
return getBlock(player, id, false); return getBlock(player, id, false);
} }
@ -249,7 +249,7 @@ public class WorldEdit {
*/ */
@Deprecated @Deprecated
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public Set<BaseBlock> getBlocks(LocalPlayer player, String list, boolean allAllowed, boolean allowNoData) throws WorldEditException { public Set<BaseBlock> getBlocks(Player player, String list, boolean allAllowed, boolean allowNoData) throws WorldEditException {
String[] items = list.split(","); String[] items = list.split(",");
Set<BaseBlock> blocks = new HashSet<BaseBlock>(); Set<BaseBlock> blocks = new HashSet<BaseBlock>();
for (String id : items) { for (String id : items) {
@ -263,7 +263,7 @@ public class WorldEdit {
*/ */
@Deprecated @Deprecated
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public Set<BaseBlock> getBlocks(LocalPlayer player, String list, boolean allAllowed) throws WorldEditException { public Set<BaseBlock> getBlocks(Player player, String list, boolean allAllowed) throws WorldEditException {
return getBlocks(player, list, allAllowed, false); return getBlocks(player, list, allAllowed, false);
} }
@ -272,7 +272,7 @@ public class WorldEdit {
*/ */
@Deprecated @Deprecated
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public Set<BaseBlock> getBlocks(LocalPlayer player, String list) throws WorldEditException { public Set<BaseBlock> getBlocks(Player player, String list) throws WorldEditException {
return getBlocks(player, list, false); return getBlocks(player, list, false);
} }
@ -281,7 +281,7 @@ public class WorldEdit {
*/ */
@Deprecated @Deprecated
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public Set<Integer> getBlockIDs(LocalPlayer player, String list, boolean allBlocksAllowed) throws WorldEditException { public Set<Integer> getBlockIDs(Player player, String list, boolean allBlocksAllowed) throws WorldEditException {
String[] items = list.split(","); String[] items = list.split(",");
Set<Integer> blocks = new HashSet<Integer>(); Set<Integer> blocks = new HashSet<Integer>();
for (String s : items) { for (String s : items) {
@ -295,7 +295,7 @@ public class WorldEdit {
*/ */
@Deprecated @Deprecated
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public Pattern getBlockPattern(LocalPlayer player, String input) throws WorldEditException { public Pattern getBlockPattern(Player player, String input) throws WorldEditException {
ParserContext context = new ParserContext(); ParserContext context = new ParserContext();
context.setActor(player); context.setActor(player);
context.setWorld(player.getWorld()); context.setWorld(player.getWorld());
@ -308,7 +308,7 @@ public class WorldEdit {
*/ */
@Deprecated @Deprecated
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public Mask getBlockMask(LocalPlayer player, LocalSession session, String input) throws WorldEditException { public Mask getBlockMask(Player player, LocalSession session, String input) throws WorldEditException {
ParserContext context = new ParserContext(); ParserContext context = new ParserContext();
context.setActor(player); context.setActor(player);
context.setWorld(player.getWorld()); context.setWorld(player.getWorld());
@ -330,8 +330,7 @@ public class WorldEdit {
* @return a file * @return a file
* @throws FilenameException thrown if the filename is invalid * @throws FilenameException thrown if the filename is invalid
*/ */
public File getSafeSaveFile(LocalPlayer player, File dir, String filename, String defaultExt, String... extensions) public File getSafeSaveFile(Player player, File dir, String filename, String defaultExt, String... extensions) throws FilenameException {
throws FilenameException {
return getSafeFile(player, dir, filename, defaultExt, extensions, true); return getSafeFile(player, dir, filename, defaultExt, extensions, true);
} }
@ -349,8 +348,7 @@ public class WorldEdit {
* @return a file * @return a file
* @throws FilenameException thrown if the filename is invalid * @throws FilenameException thrown if the filename is invalid
*/ */
public File getSafeOpenFile(LocalPlayer player, File dir, String filename, String defaultExt, String... extensions) public File getSafeOpenFile(Player player, File dir, String filename, String defaultExt, String... extensions) throws FilenameException {
throws FilenameException {
return getSafeFile(player, dir, filename, defaultExt, extensions, false); return getSafeFile(player, dir, filename, defaultExt, extensions, false);
} }
@ -366,9 +364,7 @@ public class WorldEdit {
* @return a file * @return a file
* @throws FilenameException thrown if the filename is invalid * @throws FilenameException thrown if the filename is invalid
*/ */
private File getSafeFile(LocalPlayer player, File dir, String filename, private File getSafeFile(Player player, File dir, String filename, String defaultExt, String[] extensions, boolean isSave) throws FilenameException {
String defaultExt, String[] extensions, boolean isSave)
throws FilenameException {
if (extensions != null && (extensions.length == 1 && extensions[0] == null)) extensions = null; if (extensions != null && (extensions.length == 1 && extensions[0] == null)) extensions = null;
File f; File f;
@ -411,7 +407,7 @@ public class WorldEdit {
} }
} }
public int getMaximumPolygonalPoints(LocalPlayer player) { public int getMaximumPolygonalPoints(Player player) {
if (player.hasPermission("worldedit.limit.unrestricted") || getConfiguration().maxPolygonalPoints < 0) { if (player.hasPermission("worldedit.limit.unrestricted") || getConfiguration().maxPolygonalPoints < 0) {
return getConfiguration().defaultMaxPolygonalPoints; return getConfiguration().defaultMaxPolygonalPoints;
} }
@ -423,7 +419,7 @@ public class WorldEdit {
return Math.min(getConfiguration().defaultMaxPolygonalPoints, getConfiguration().maxPolygonalPoints); return Math.min(getConfiguration().defaultMaxPolygonalPoints, getConfiguration().maxPolygonalPoints);
} }
public int getMaximumPolyhedronPoints(LocalPlayer player) { public int getMaximumPolyhedronPoints(Player player) {
if (player.hasPermission("worldedit.limit.unrestricted") || getConfiguration().maxPolyhedronPoints < 0) { if (player.hasPermission("worldedit.limit.unrestricted") || getConfiguration().maxPolyhedronPoints < 0) {
return getConfiguration().defaultMaxPolyhedronPoints; return getConfiguration().defaultMaxPolyhedronPoints;
} }
@ -586,9 +582,7 @@ public class WorldEdit {
* @return a direction vector * @return a direction vector
* @throws UnknownDirectionException thrown if the direction is not known * @throws UnknownDirectionException thrown if the direction is not known
*/ */
public Vector getDiagonalDirection(LocalPlayer player, String dirStr) public Vector getDiagonalDirection(Player player, String dirStr) throws UnknownDirectionException {
throws UnknownDirectionException {
return getPlayerDirection(player, dirStr.toLowerCase()).vector(); return getPlayerDirection(player, dirStr.toLowerCase()).vector();
} }
@ -600,8 +594,7 @@ public class WorldEdit {
* @return a direction vector * @return a direction vector
* @throws UnknownDirectionException thrown if the direction is not known * @throws UnknownDirectionException thrown if the direction is not known
*/ */
public FlipDirection getFlipDirection(LocalPlayer player, String dirStr) throws UnknownDirectionException { public FlipDirection getFlipDirection(Player player, String dirStr) throws UnknownDirectionException {
final PlayerDirection dir = getPlayerDirection(player, dirStr); final PlayerDirection dir = getPlayerDirection(player, dirStr);
switch (dir) { switch (dir) {
case WEST: case WEST:
@ -624,7 +617,7 @@ public class WorldEdit {
/** /**
* Flush a block bag's changes to a player. * Flush a block bag's changes to a player.
* *
* @param player the player * @param actor the actor
* @param editSession the edit session * @param editSession the edit session
*/ */
public void flushBlockBag(Actor actor, EditSession editSession) { public void flushBlockBag(Actor actor, EditSession editSession) {
@ -668,7 +661,7 @@ public class WorldEdit {
* @param player the player * @param player the player
*/ */
@Deprecated @Deprecated
public void handleDisconnect(LocalPlayer player) { public void handleDisconnect(Player player) {
forgetPlayer(player); forgetPlayer(player);
} }
@ -677,7 +670,7 @@ public class WorldEdit {
* *
* @param player the player * @param player the player
*/ */
public void markExpire(LocalPlayer player) { public void markExpire(Player player) {
sessions.markforExpiration(player); sessions.markforExpiration(player);
} }
@ -686,7 +679,7 @@ public class WorldEdit {
* *
* @param player the player * @param player the player
*/ */
public void forgetPlayer(LocalPlayer player) { public void forgetPlayer(Player player) {
sessions.remove(player); sessions.remove(player);
} }
@ -703,7 +696,7 @@ public class WorldEdit {
* @param player the player * @param player the player
* @return true if the swing was handled * @return true if the swing was handled
*/ */
public boolean handleArmSwing(LocalPlayer player) { public boolean handleArmSwing(Player player) {
PlayerInputEvent event = new PlayerInputEvent(player, InputType.PRIMARY); PlayerInputEvent event = new PlayerInputEvent(player, InputType.PRIMARY);
getEventBus().post(event); getEventBus().post(event);
return event.isCancelled(); return event.isCancelled();
@ -715,7 +708,7 @@ public class WorldEdit {
* @param player the player * @param player the player
* @return true if the right click was handled * @return true if the right click was handled
*/ */
public boolean handleRightClick(LocalPlayer player) { public boolean handleRightClick(Player player) {
PlayerInputEvent event = new PlayerInputEvent(player, InputType.SECONDARY); PlayerInputEvent event = new PlayerInputEvent(player, InputType.SECONDARY);
getEventBus().post(event); getEventBus().post(event);
return event.isCancelled(); return event.isCancelled();
@ -728,7 +721,7 @@ public class WorldEdit {
* @param clicked the clicked block * @param clicked the clicked block
* @return false if you want the action to go through * @return false if you want the action to go through
*/ */
public boolean handleBlockRightClick(LocalPlayer player, WorldVector clicked) { public boolean handleBlockRightClick(Player player, WorldVector clicked) {
BlockInteractEvent event = new BlockInteractEvent(player, clicked.toLocation(), OPEN); BlockInteractEvent event = new BlockInteractEvent(player, clicked.toLocation(), OPEN);
getEventBus().post(event); getEventBus().post(event);
return event.isCancelled(); return event.isCancelled();
@ -741,7 +734,7 @@ public class WorldEdit {
* @param clicked the clicked block * @param clicked the clicked block
* @return false if you want the action to go through * @return false if you want the action to go through
*/ */
public boolean handleBlockLeftClick(LocalPlayer player, WorldVector clicked) { public boolean handleBlockLeftClick(Player player, WorldVector clicked) {
BlockInteractEvent event = new BlockInteractEvent(player, clicked.toLocation(), HIT); BlockInteractEvent event = new BlockInteractEvent(player, clicked.toLocation(), HIT);
getEventBus().post(event); getEventBus().post(event);
return event.isCancelled(); return event.isCancelled();
@ -753,7 +746,7 @@ public class WorldEdit {
* @param split * @param split
* @return whether the command was processed * @return whether the command was processed
*/ */
public boolean handleCommand(LocalPlayer player, String[] split) { public boolean handleCommand(Player player, String[] split) {
CommandEvent event = new CommandEvent(player, split); CommandEvent event = new CommandEvent(player, split);
getEventBus().post(event); getEventBus().post(event);
return event.isCancelled(); return event.isCancelled();
@ -771,7 +764,7 @@ public class WorldEdit {
* @param args arguments for the script * @param args arguments for the script
* @throws WorldEditException * @throws WorldEditException
*/ */
public void runScript(LocalPlayer player, File f, String[] args) throws WorldEditException { public void runScript(Player player, File f, String[] args) throws WorldEditException {
Request.reset(); Request.reset();
String filename = f.getPath(); String filename = f.getPath();
@ -809,9 +802,8 @@ public class WorldEdit {
return; return;
} }
LocalSession session = getSession(player); LocalSession session = getSessionManager().get(player);
CraftScriptContext scriptContext = CraftScriptContext scriptContext = new CraftScriptContext(this, getServer(), getConfiguration(), session, player, args);
new CraftScriptContext(this, getServer(), getConfiguration(), session, player, args);
CraftScriptEngine engine = null; CraftScriptEngine engine = null;

View File

@ -160,7 +160,9 @@ public class BrushCommands {
) )
@CommandPermissions("worldedit.brush.smooth") @CommandPermissions("worldedit.brush.smooth")
public void smoothBrush(Player player, LocalSession session, EditSession editSession, public void smoothBrush(Player player, LocalSession session, EditSession editSession,
@Optional("2") double radius, @Optional("4") int iterations, @Switch('n') boolean naturalBlocksOnly) throws WorldEditException { @Optional("2") double radius, @Optional("4") int iterations, @Switch('n')
boolean naturalBlocksOnly) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(radius);
BrushTool tool = session.getBrushTool(player.getItemInHand()); BrushTool tool = session.getBrushTool(player.getItemInHand());
@ -227,8 +229,7 @@ public class BrushCommands {
max = 2 max = 2
) )
@CommandPermissions("worldedit.brush.butcher") @CommandPermissions("worldedit.brush.butcher")
public void butcherBrush(CommandContext args, LocalSession session, Player player, EditSession editSession) throws WorldEditException { public void butcherBrush(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
LocalConfiguration config = worldEdit.getConfiguration(); LocalConfiguration config = worldEdit.getConfiguration();
double radius = args.argsLength() > 0 ? args.getDouble(0) : 5; double radius = args.argsLength() > 0 ? args.getDouble(0) : 5;

View File

@ -24,6 +24,7 @@ import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.math.MathUtils; import com.sk89q.worldedit.math.MathUtils;
import com.sk89q.worldedit.world.storage.LegacyChunkStore; import com.sk89q.worldedit.world.storage.LegacyChunkStore;
import com.sk89q.worldedit.world.storage.McRegionChunkStore; import com.sk89q.worldedit.world.storage.McRegionChunkStore;
@ -33,18 +34,19 @@ import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.util.Set; import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION;
/** /**
* Chunk tools. * Commands for working with chunks.
*
* @author sk89q
*/ */
public class ChunkCommands { public class ChunkCommands {
private final WorldEdit we;
public ChunkCommands(WorldEdit we) { private final WorldEdit worldEdit;
this.we = we;
public ChunkCommands(WorldEdit worldEdit) {
checkNotNull(worldEdit);
this.worldEdit = worldEdit;
} }
@Command( @Command(
@ -55,9 +57,7 @@ public class ChunkCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.chunkinfo") @CommandPermissions("worldedit.chunkinfo")
public void chunkInfo(CommandContext args, LocalSession session, LocalPlayer player, public void chunkInfo(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
Vector pos = player.getBlockIn(); Vector pos = player.getBlockIn();
int chunkX = (int) Math.floor(pos.getBlockX() / 16.0); int chunkX = (int) Math.floor(pos.getBlockX() / 16.0);
int chunkZ = (int) Math.floor(pos.getBlockZ() / 16.0); int chunkZ = (int) Math.floor(pos.getBlockZ() / 16.0);
@ -81,9 +81,7 @@ public class ChunkCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.listchunks") @CommandPermissions("worldedit.listchunks")
public void listChunks(CommandContext args, LocalSession session, LocalPlayer player, public void listChunks(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
Set<Vector2D> chunks = session.getSelection(player.getWorld()).getChunks(); Set<Vector2D> chunks = session.getSelection(player.getWorld()).getChunks();
for (Vector2D chunk : chunks) { for (Vector2D chunk : chunks) {
@ -100,11 +98,9 @@ public class ChunkCommands {
) )
@CommandPermissions("worldedit.delchunks") @CommandPermissions("worldedit.delchunks")
@Logging(REGION) @Logging(REGION)
public void deleteChunks(CommandContext args, LocalSession session, LocalPlayer player, public void deleteChunks(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
player.print("Note that this command does not yet support the mcregion format."); player.print("Note that this command does not yet support the mcregion format.");
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = worldEdit.getConfiguration();
Set<Vector2D> chunks = session.getSelection(player.getWorld()).getChunks(); Set<Vector2D> chunks = session.getSelection(player.getWorld()).getChunks();
FileOutputStream out = null; FileOutputStream out = null;
@ -139,7 +135,7 @@ public class ChunkCommands {
if (out != null) { if (out != null) {
try { try {
out.close(); out.close();
} catch (IOException ie) { } } catch (IOException ignored) { }
} }
} }
} else if (config.shellSaveType.equalsIgnoreCase("bash")) { } else if (config.shellSaveType.equalsIgnoreCase("bash")) {
@ -171,7 +167,7 @@ public class ChunkCommands {
if (out != null) { if (out != null) {
try { try {
out.close(); out.close();
} catch (IOException ie) { } catch (IOException ignored) {
} }
} }
} }
@ -179,4 +175,5 @@ public class ChunkCommands {
player.printError("Shell script type must be configured: 'bat' or 'bash' expected."); player.printError("Shell script type must be configured: 'bat' or 'bash' expected.");
} }
} }
} }

View File

@ -19,28 +19,40 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import com.sk89q.minecraft.util.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.Logging;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.util.command.binding.Switch;
import com.sk89q.worldedit.util.command.parametric.Optional;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT; import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION;
/** /**
* Clipboard commands. * Clipboard commands.
*
* @author sk89q
*/ */
public class ClipboardCommands { public class ClipboardCommands {
private final WorldEdit we;
public ClipboardCommands(WorldEdit we) { private final WorldEdit worldEdit;
this.we = we;
/**
* Create a new instance.
*
* @param worldEdit reference to WorldEdit
*/
public ClipboardCommands(WorldEdit worldEdit) {
checkNotNull(worldEdit);
this.worldEdit = worldEdit;
} }
@Command( @Command(
@ -55,9 +67,7 @@ public class ClipboardCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.clipboard.copy") @CommandPermissions("worldedit.clipboard.copy")
public void copy(CommandContext args, LocalSession session, LocalPlayer player, public void copy(Player player, LocalSession session, EditSession editSession, @Switch('e') boolean copyEntities) throws WorldEditException {
EditSession editSession) throws WorldEditException {
Region region = session.getSelection(player.getWorld()); Region region = session.getSelection(player.getWorld());
Vector min = region.getMinimumPoint(); Vector min = region.getMinimumPoint();
Vector max = region.getMaximumPoint(); Vector max = region.getMaximumPoint();
@ -73,11 +83,12 @@ public class ClipboardCommands {
clipboard.copy(editSession, region); clipboard.copy(editSession, region);
} }
if (args.hasFlag('e')) { if (copyEntities) {
for (LocalEntity entity : player.getWorld().getEntities(region)) { for (LocalEntity entity : player.getWorld().getEntities(region)) {
clipboard.storeEntity(entity); clipboard.storeEntity(entity);
} }
} }
session.setClipboard(clipboard); session.setClipboard(clipboard);
player.print("Block(s) copied."); player.print("Block(s) copied.");
@ -97,16 +108,9 @@ public class ClipboardCommands {
) )
@CommandPermissions("worldedit.clipboard.cut") @CommandPermissions("worldedit.clipboard.cut")
@Logging(REGION) @Logging(REGION)
public void cut(CommandContext args, LocalSession session, LocalPlayer player, public void cut(Player player, LocalSession session, EditSession editSession, @Optional("air") BaseBlock block, @Switch('e') boolean copyEntities) throws WorldEditException {
EditSession editSession) throws WorldEditException {
BaseBlock block = new BaseBlock(BlockID.AIR);
World world = player.getWorld(); World world = player.getWorld();
if (args.argsLength() > 0) {
block = we.getBlock(player, args.getString(0));
}
Region region = session.getSelection(world); Region region = session.getSelection(world);
Vector min = region.getMinimumPoint(); Vector min = region.getMinimumPoint();
Vector max = region.getMaximumPoint(); Vector max = region.getMaximumPoint();
@ -122,13 +126,14 @@ public class ClipboardCommands {
clipboard.copy(editSession, region); clipboard.copy(editSession, region);
} }
if (args.hasFlag('e')) { if (copyEntities) {
LocalEntity[] entities = world.getEntities(region); LocalEntity[] entities = world.getEntities(region);
for (LocalEntity entity : entities) { for (LocalEntity entity : entities) {
clipboard.storeEntity(entity); clipboard.storeEntity(entity);
} }
world.killEntities(entities); world.killEntities(entities);
} }
session.setClipboard(clipboard); session.setClipboard(clipboard);
editSession.setBlocks(region, block); editSession.setBlocks(region, block);
@ -151,8 +156,7 @@ public class ClipboardCommands {
) )
@CommandPermissions("worldedit.clipboard.paste") @CommandPermissions("worldedit.clipboard.paste")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void paste(CommandContext args, LocalSession session, LocalPlayer player, public void paste(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
boolean atOrigin = args.hasFlag('o'); boolean atOrigin = args.hasFlag('o');
boolean pasteNoAir = args.hasFlag('a'); boolean pasteNoAir = args.hasFlag('a');
@ -194,8 +198,7 @@ public class ClipboardCommands {
max = 1 max = 1
) )
@CommandPermissions("worldedit.clipboard.rotate") @CommandPermissions("worldedit.clipboard.rotate")
public void rotate(CommandContext args, LocalSession session, LocalPlayer player, public void rotate(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
int angle = args.getInteger(0); int angle = args.getInteger(0);
@ -221,12 +224,8 @@ public class ClipboardCommands {
max = 1 max = 1
) )
@CommandPermissions("worldedit.clipboard.flip") @CommandPermissions("worldedit.clipboard.flip")
public void flip(CommandContext args, LocalSession session, LocalPlayer player, public void flip(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException { CuboidClipboard.FlipDirection dir = worldEdit.getFlipDirection(player, args.argsLength() > 0 ? args.getString(0).toLowerCase() : "me");
CuboidClipboard.FlipDirection dir = we.getFlipDirection(player,
args.argsLength() > 0 ? args.getString(0).toLowerCase() : "me");
CuboidClipboard clipboard = session.getClipboard(); CuboidClipboard clipboard = session.getClipboard();
clipboard.flip(dir, args.hasFlag('p')); clipboard.flip(dir, args.hasFlag('p'));
player.print("Clipboard flipped."); player.print("Clipboard flipped.");
@ -241,9 +240,8 @@ public class ClipboardCommands {
) )
@Deprecated @Deprecated
@CommandPermissions("worldedit.clipboard.load") @CommandPermissions("worldedit.clipboard.load")
public void load(CommandContext args, LocalSession session, LocalPlayer player, public void load(Actor actor) {
EditSession editSession) throws WorldEditException { actor.printError("This command is no longer used. See //schematic load.");
player.printError("This command is no longer used. See //schematic load.");
} }
@Command( @Command(
@ -255,9 +253,8 @@ public class ClipboardCommands {
) )
@Deprecated @Deprecated
@CommandPermissions("worldedit.clipboard.save") @CommandPermissions("worldedit.clipboard.save")
public void save(CommandContext args, LocalSession session, LocalPlayer player, public void save(Actor actor) {
EditSession editSession) throws WorldEditException { actor.printError("This command is no longer used. See //schematic save.");
player.printError("This command is no longer used. See //schematic save.");
} }
@Command( @Command(
@ -268,9 +265,7 @@ public class ClipboardCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.clipboard.clear") @CommandPermissions("worldedit.clipboard.clear")
public void clearClipboard(CommandContext args, LocalSession session, LocalPlayer player, public void clearClipboard(Player player, LocalSession session, EditSession editSession) throws WorldEditException {
EditSession editSession) throws WorldEditException {
session.setClipboard(null); session.setClipboard(null);
player.print("Clipboard cleared."); player.print("Clipboard cleared.");
} }

View File

@ -24,19 +24,28 @@ import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.ItemType; import com.sk89q.worldedit.blocks.ItemType;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.masks.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.util.command.parametric.Optional;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* General WorldEdit commands. * General WorldEdit commands.
*
* @author sk89q
*/ */
public class GeneralCommands { public class GeneralCommands {
private final WorldEdit we;
public GeneralCommands(WorldEdit we) { private final WorldEdit worldEdit;
this.we = we;
/**
* Create a new instance.
*
* @param worldEdit reference to WorldEdit
*/
public GeneralCommands(WorldEdit worldEdit) {
checkNotNull(worldEdit);
this.worldEdit = worldEdit;
} }
@Command( @Command(
@ -47,10 +56,9 @@ public class GeneralCommands {
max = 1 max = 1
) )
@CommandPermissions("worldedit.limit") @CommandPermissions("worldedit.limit")
public void limit(CommandContext args, LocalSession session, LocalPlayer player, public void limit(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = worldEdit.getConfiguration();
boolean mayDisable = player.hasPermission("worldedit.limit.unrestricted"); boolean mayDisable = player.hasPermission("worldedit.limit.unrestricted");
int limit = Math.max(-1, args.getInteger(0)); int limit = Math.max(-1, args.getInteger(0));
@ -78,8 +86,7 @@ public class GeneralCommands {
max = 1 max = 1
) )
@CommandPermissions("worldedit.fast") @CommandPermissions("worldedit.fast")
public void fast(CommandContext args, LocalSession session, LocalPlayer player, public void fast(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
String newState = args.getString(0, null); String newState = args.getString(0, null);
if (session.hasFastMode()) { if (session.hasFastMode()) {
@ -109,13 +116,11 @@ public class GeneralCommands {
max = -1 max = -1
) )
@CommandPermissions("worldedit.global-mask") @CommandPermissions("worldedit.global-mask")
public void gmask(CommandContext args, LocalSession session, LocalPlayer player, public void gmask(Player player, LocalSession session, EditSession editSession, @Optional Mask mask) throws WorldEditException {
EditSession editSession) throws WorldEditException { if (mask == null) {
if (args.argsLength() == 0) { session.setMask((Mask) null);
session.setMask(null);
player.print("Global mask disabled."); player.print("Global mask disabled.");
} else { } else {
Mask mask = we.getBlockMask(player, session, args.getJoinedStrings(0));
session.setMask(mask); session.setMask(mask);
player.print("Global mask set."); player.print("Global mask set.");
} }
@ -128,8 +133,7 @@ public class GeneralCommands {
min = 0, min = 0,
max = 0 max = 0
) )
public void togglePlace(CommandContext args, LocalSession session, LocalPlayer player, public void togglePlace(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
if (session.togglePlacementPosition()) { if (session.togglePlacementPosition()) {
player.print("Now placing at pos #1."); player.print("Now placing at pos #1.");

View File

@ -19,41 +19,46 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.ALL;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.POSITION;
import com.sk89q.minecraft.util.commands.Command; 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.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.BiomeType; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.LocalPlayer; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.function.pattern.Patterns;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.internal.annotation.Selection;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.internal.expression.ExpressionException; import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
import com.sk89q.worldedit.util.command.binding.Range;
import com.sk89q.worldedit.util.command.binding.Switch;
import com.sk89q.worldedit.util.command.binding.Text;
import com.sk89q.worldedit.util.command.parametric.Optional;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.*;
/** /**
* Generation commands. * Commands for the generation of shapes and other objects.
*
* @author sk89q
*/ */
public class GenerationCommands { public class GenerationCommands {
private final WorldEdit we;
public GenerationCommands(WorldEdit we) { private final WorldEdit worldEdit;
this.we = we;
/**
* Create a new instance.
*
* @param worldEdit reference to WorldEdit
*/
public GenerationCommands(WorldEdit worldEdit) {
checkNotNull(worldEdit);
this.worldEdit = worldEdit;
} }
@Command( @Command(
aliases = { "/hcyl" }, aliases = { "/hcyl" },
usage = "<block> <radius>[,<radius>] [height]", usage = "<pattern> <radius>[,<radius>] [height]",
desc = "Generates a hollow cylinder.", desc = "Generates a hollow cylinder.",
help = help =
"Generates a hollow cylinder.\n" + "Generates a hollow cylinder.\n" +
@ -65,40 +70,14 @@ public class GenerationCommands {
) )
@CommandPermissions("worldedit.generation.cylinder") @CommandPermissions("worldedit.generation.cylinder")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void hcyl(CommandContext args, LocalSession session, LocalPlayer player, public void hcyl(Player player, LocalSession session, EditSession editSession, Pattern pattern, String radiusString, @Optional("1") int height) throws WorldEditException {
EditSession editSession) throws WorldEditException { cyl(player, session, editSession, pattern, radiusString, height, true);
Pattern block = we.getBlockPattern(player, args.getString(0));
String[] radiuses = args.getString(1).split(",");
final double radiusX, radiusZ;
switch (radiuses.length) {
case 1:
radiusX = radiusZ = Math.max(1, Double.parseDouble(radiuses[0]));
break;
case 2:
radiusX = Math.max(1, Double.parseDouble(radiuses[0]));
radiusZ = Math.max(1, Double.parseDouble(radiuses[1]));
break;
default:
player.printError("You must either specify 1 or 2 radius values.");
return;
}
int height = args.argsLength() > 2 ? args.getInteger(2) : 1;
we.checkMaxRadius(radiusX);
we.checkMaxRadius(radiusZ);
we.checkMaxRadius(height);
Vector pos = session.getPlacementPosition(player);
int affected = editSession.makeCylinder(pos, block, radiusX, radiusZ, height, false);
player.print(affected + " block(s) have been created.");
} }
@Command( @Command(
aliases = { "/cyl" }, aliases = { "/cyl" },
usage = "<block> <radius>[,<radius>] [height]", usage = "<block> <radius>[,<radius>] [height]",
flags = "h",
desc = "Generates a cylinder.", desc = "Generates a cylinder.",
help = help =
"Generates a cylinder.\n" + "Generates a cylinder.\n" +
@ -110,34 +89,30 @@ public class GenerationCommands {
) )
@CommandPermissions("worldedit.generation.cylinder") @CommandPermissions("worldedit.generation.cylinder")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void cyl(CommandContext args, LocalSession session, LocalPlayer player, public void cyl(Player player, LocalSession session, EditSession editSession, Pattern pattern, String radiusString, @Optional("1") int height, @Switch('h') boolean hollow) throws WorldEditException {
EditSession editSession) throws WorldEditException { String[] radii = radiusString.split(",");
Pattern block = we.getBlockPattern(player, args.getString(0));
String[] radiuses = args.getString(1).split(",");
final double radiusX, radiusZ; final double radiusX, radiusZ;
switch (radiuses.length) { switch (radii.length) {
case 1: case 1:
radiusX = radiusZ = Math.max(1, Double.parseDouble(radiuses[0])); radiusX = radiusZ = Math.max(1, Double.parseDouble(radii[0]));
break; break;
case 2: case 2:
radiusX = Math.max(1, Double.parseDouble(radiuses[0])); radiusX = Math.max(1, Double.parseDouble(radii[0]));
radiusZ = Math.max(1, Double.parseDouble(radiuses[1])); radiusZ = Math.max(1, Double.parseDouble(radii[1]));
break; break;
default: default:
player.printError("You must either specify 1 or 2 radius values."); player.printError("You must either specify 1 or 2 radius values.");
return; return;
} }
int height = args.argsLength() > 2 ? args.getInteger(2) : 1;
we.checkMaxRadius(radiusX); worldEdit.checkMaxRadius(radiusX);
we.checkMaxRadius(radiusZ); worldEdit.checkMaxRadius(radiusZ);
we.checkMaxRadius(height); worldEdit.checkMaxRadius(height);
Vector pos = session.getPlacementPosition(player); Vector pos = session.getPlacementPosition(player);
int affected = editSession.makeCylinder(pos, block, radiusX, radiusZ, height, true); int affected = editSession.makeCylinder(pos, Patterns.wrap(pattern), radiusX, radiusZ, height, !hollow);
player.print(affected + " block(s) have been created."); player.print(affected + " block(s) have been created.");
} }
@ -155,52 +130,14 @@ public class GenerationCommands {
) )
@CommandPermissions("worldedit.generation.sphere") @CommandPermissions("worldedit.generation.sphere")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void hsphere(CommandContext args, LocalSession session, LocalPlayer player, public void hsphere(Player player, LocalSession session, EditSession editSession, Pattern pattern, String radiusString, @Optional("false") boolean raised) throws WorldEditException {
EditSession editSession) throws WorldEditException { sphere(player, session, editSession, pattern, radiusString, raised, true);
final Pattern block = we.getBlockPattern(player, args.getString(0));
String[] radiuses = args.getString(1).split(",");
final double radiusX, radiusY, radiusZ;
switch (radiuses.length) {
case 1:
radiusX = radiusY = radiusZ = Math.max(1, Double.parseDouble(radiuses[0]));
break;
case 3:
radiusX = Math.max(1, Double.parseDouble(radiuses[0]));
radiusY = Math.max(1, Double.parseDouble(radiuses[1]));
radiusZ = Math.max(1, Double.parseDouble(radiuses[2]));
break;
default:
player.printError("You must either specify 1 or 3 radius values.");
return;
}
we.checkMaxRadius(radiusX);
we.checkMaxRadius(radiusY);
we.checkMaxRadius(radiusZ);
final boolean raised;
if (args.argsLength() > 2) {
raised = args.getString(2).equalsIgnoreCase("true") || args.getString(2).equalsIgnoreCase("yes");
} else {
raised = false;
}
Vector pos = session.getPlacementPosition(player);
if (raised) {
pos = pos.add(0, radiusY, 0);
}
int affected = editSession.makeSphere(pos, block, radiusX, radiusY, radiusZ, false);
player.findFreePosition();
player.print(affected + " block(s) have been created.");
} }
@Command( @Command(
aliases = { "/sphere" }, aliases = { "/sphere" },
usage = "<block> <radius>[,<radius>,<radius>] [raised?]", usage = "<block> <radius>[,<radius>,<radius>] [raised?]",
flags = "h",
desc = "Generates a filled sphere.", desc = "Generates a filled sphere.",
help = help =
"Generates a filled sphere.\n" + "Generates a filled sphere.\n" +
@ -212,21 +149,18 @@ public class GenerationCommands {
) )
@CommandPermissions("worldedit.generation.sphere") @CommandPermissions("worldedit.generation.sphere")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void sphere(CommandContext args, LocalSession session, LocalPlayer player, public void sphere(Player player, LocalSession session, EditSession editSession, Pattern pattern, String radiusString, @Optional("false") boolean raised, @Switch('h') boolean hollow) throws WorldEditException {
EditSession editSession) throws WorldEditException { String[] radii = radiusString.split(",");
Pattern block = we.getBlockPattern(player, args.getString(0));
String[] radiuses = args.getString(1).split(",");
final double radiusX, radiusY, radiusZ; final double radiusX, radiusY, radiusZ;
switch (radiuses.length) { switch (radii.length) {
case 1: case 1:
radiusX = radiusY = radiusZ = Math.max(1, Double.parseDouble(radiuses[0])); radiusX = radiusY = radiusZ = Math.max(1, Double.parseDouble(radii[0]));
break; break;
case 3: case 3:
radiusX = Math.max(1, Double.parseDouble(radiuses[0])); radiusX = Math.max(1, Double.parseDouble(radii[0]));
radiusY = Math.max(1, Double.parseDouble(radiuses[1])); radiusY = Math.max(1, Double.parseDouble(radii[1]));
radiusZ = Math.max(1, Double.parseDouble(radiuses[2])); radiusZ = Math.max(1, Double.parseDouble(radii[2]));
break; break;
default: default:
@ -234,23 +168,16 @@ public class GenerationCommands {
return; return;
} }
we.checkMaxRadius(radiusX); worldEdit.checkMaxRadius(radiusX);
we.checkMaxRadius(radiusY); worldEdit.checkMaxRadius(radiusY);
we.checkMaxRadius(radiusZ); worldEdit.checkMaxRadius(radiusZ);
final boolean raised;
if (args.argsLength() > 2) {
raised = args.getString(2).equalsIgnoreCase("true") || args.getString(2).equalsIgnoreCase("yes");
} else {
raised = false;
}
Vector pos = session.getPlacementPosition(player); Vector pos = session.getPlacementPosition(player);
if (raised) { if (raised) {
pos = pos.add(0, radiusY, 0); pos = pos.add(0, radiusY, 0);
} }
int affected = editSession.makeSphere(pos, block, radiusX, radiusY, radiusZ, true); int affected = editSession.makeSphere(pos, Patterns.wrap(pattern), radiusX, radiusY, radiusZ, !hollow);
player.findFreePosition(); player.findFreePosition();
player.print(affected + " block(s) have been created."); player.print(affected + " block(s) have been created.");
} }
@ -265,22 +192,9 @@ public class GenerationCommands {
@CommandPermissions("worldedit.generation.forest") @CommandPermissions("worldedit.generation.forest")
@Logging(POSITION) @Logging(POSITION)
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void forestGen(CommandContext args, LocalSession session, LocalPlayer player, public void forestGen(Player player, LocalSession session, EditSession editSession, @Optional("10") int size, @Optional("tree") TreeType type, @Optional("5") double density) throws WorldEditException {
EditSession editSession) throws WorldEditException { density = density / 100;
int affected = editSession.makeForest(session.getPlacementPosition(player), size, density, new TreeGenerator(type));
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
TreeGenerator.TreeType type = args.argsLength() > 1 ?
TreeGenerator.lookup(args.getString(1))
: TreeGenerator.TreeType.TREE;
double density = args.argsLength() > 2 ? args.getDouble(2) / 100 : 0.05;
if (type == null) {
player.printError("Tree type '" + args.getString(1) + "' is unknown.");
return;
}
int affected = editSession.makeForest(session.getPlacementPosition(player),
size, density, new TreeGenerator(type));
player.print(affected + " trees created."); player.print(affected + " trees created.");
} }
@ -293,59 +207,38 @@ public class GenerationCommands {
) )
@CommandPermissions("worldedit.generation.pumpkins") @CommandPermissions("worldedit.generation.pumpkins")
@Logging(POSITION) @Logging(POSITION)
public void pumpkins(CommandContext args, LocalSession session, LocalPlayer player, public void pumpkins(Player player, LocalSession session, EditSession editSession, @Optional("10") int apothem) throws WorldEditException {
EditSession editSession) throws WorldEditException { int affected = editSession.makePumpkinPatches(session.getPlacementPosition(player), apothem);
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
int affected = editSession.makePumpkinPatches(session.getPlacementPosition(player), size);
player.print(affected + " pumpkin patches created."); player.print(affected + " pumpkin patches created.");
} }
@Command(
aliases = { "/hpyramid" },
usage = "<block> <size>",
desc = "Generate a hollow pyramid",
min = 2,
max = 2
)
@CommandPermissions("worldedit.generation.pyramid")
@Logging(PLACEMENT)
public void hollowPyramid(Player player, LocalSession session, EditSession editSession, Pattern pattern, @Range(min = 1) int size) throws WorldEditException {
pyramid(player, session, editSession, pattern, size, true);
}
@Command( @Command(
aliases = { "/pyramid" }, aliases = { "/pyramid" },
usage = "<block> <size>", usage = "<block> <size>",
flags = "h",
desc = "Generate a filled pyramid", desc = "Generate a filled pyramid",
min = 2, min = 2,
max = 2 max = 2
) )
@CommandPermissions("worldedit.generation.pyramid") @CommandPermissions("worldedit.generation.pyramid")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void pyramid(CommandContext args, LocalSession session, LocalPlayer player, public void pyramid(Player player, LocalSession session, EditSession editSession, Pattern pattern, @Range(min = 1) int size, @Switch('h') boolean hollow) throws WorldEditException {
EditSession editSession) throws WorldEditException {
Pattern block = we.getBlockPattern(player, args.getString(0));
int size = Math.max(1, args.getInteger(1));
Vector pos = session.getPlacementPosition(player); Vector pos = session.getPlacementPosition(player);
worldEdit.checkMaxRadius(size);
we.checkMaxRadius(size); int affected = editSession.makePyramid(pos, Patterns.wrap(pattern), size, !hollow);
int affected = editSession.makePyramid(pos, block, size, true);
player.findFreePosition();
player.print(affected + " block(s) have been created.");
}
@Command(
aliases = { "/hpyramid" },
usage = "<block> <size>",
desc = "Generate a hollow pyramid",
min = 2,
max = 2
)
@CommandPermissions("worldedit.generation.pyramid")
@Logging(PLACEMENT)
public void hpyramid(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {
Pattern block = we.getBlockPattern(player, args.getString(0));
int size = Math.max(1, args.getInteger(1));
Vector pos = session.getPlacementPosition(player);
we.checkMaxRadius(size);
int affected = editSession.makePyramid(pos, block, size, false);
player.findFreePosition(); player.findFreePosition();
player.print(affected + " block(s) have been created."); player.print(affected + " block(s) have been created.");
} }
@ -371,26 +264,25 @@ public class GenerationCommands {
) )
@CommandPermissions("worldedit.generation.shape") @CommandPermissions("worldedit.generation.shape")
@Logging(ALL) @Logging(ALL)
public void generate(CommandContext args, LocalSession session, LocalPlayer player, public void generate(Player player, LocalSession session, EditSession editSession,
EditSession editSession) throws WorldEditException { @Selection Region region,
Pattern pattern,
final Pattern pattern = we.getBlockPattern(player, args.getString(0)); @Text String expression,
final Region region = session.getSelection(player.getWorld()); @Switch('h') boolean hollow,
@Switch('r') boolean useRawCoords,
final boolean hollow = args.hasFlag('h'); @Switch('o') boolean offset,
@Switch('c') boolean offsetCenter) throws WorldEditException {
final String expression = args.getJoinedStrings(1);
final Vector zero; final Vector zero;
Vector unit; Vector unit;
if (args.hasFlag('r')) { if (useRawCoords) {
zero = Vector.ZERO; zero = Vector.ZERO;
unit = Vector.ONE; unit = Vector.ONE;
} else if (args.hasFlag('o')) { } else if (offset) {
zero = session.getPlacementPosition(player); zero = session.getPlacementPosition(player);
unit = Vector.ONE; unit = Vector.ONE;
} else if (args.hasFlag('c')) { } else if (offsetCenter) {
final Vector min = region.getMinimumPoint(); final Vector min = region.getMinimumPoint();
final Vector max = region.getMaximumPoint(); final Vector max = region.getMaximumPoint();
@ -409,7 +301,7 @@ public class GenerationCommands {
} }
try { try {
final int affected = editSession.makeShape(region, zero, unit, pattern, expression, hollow); final int affected = editSession.makeShape(region, zero, unit, Patterns.wrap(pattern), expression, hollow);
player.findFreePosition(); player.findFreePosition();
player.print(affected + " block(s) have been created."); player.print(affected + " block(s) have been created.");
} catch (ExpressionException e) { } catch (ExpressionException e) {
@ -438,26 +330,24 @@ public class GenerationCommands {
) )
@CommandPermissions({"worldedit.generation.shape", "worldedit.biome.set"}) @CommandPermissions({"worldedit.generation.shape", "worldedit.biome.set"})
@Logging(ALL) @Logging(ALL)
public void generateBiome(CommandContext args, LocalSession session, LocalPlayer player, public void generateBiome(Player player, LocalSession session, EditSession editSession,
EditSession editSession) throws WorldEditException { @Selection Region region,
BiomeType target,
final BiomeType target = we.getServer().getBiomes().get(args.getString(0)); @Text String expression,
final Region region = session.getSelection(player.getWorld()); @Switch('h') boolean hollow,
@Switch('r') boolean useRawCoords,
final boolean hollow = args.hasFlag('h'); @Switch('o') boolean offset,
@Switch('c') boolean offsetCenter) throws WorldEditException {
final String expression = args.getJoinedStrings(1);
final Vector zero; final Vector zero;
Vector unit; Vector unit;
if (args.hasFlag('r')) { if (useRawCoords) {
zero = Vector.ZERO; zero = Vector.ZERO;
unit = Vector.ONE; unit = Vector.ONE;
} else if (args.hasFlag('o')) { } else if (offset) {
zero = session.getPlacementPosition(player); zero = session.getPlacementPosition(player);
unit = Vector.ONE; unit = Vector.ONE;
} else if (args.hasFlag('c')) { } else if (offsetCenter) {
final Vector min = region.getMinimumPoint(); final Vector min = region.getMinimumPoint();
final Vector max = region.getMaximumPoint(); final Vector max = region.getMaximumPoint();
@ -483,4 +373,5 @@ public class GenerationCommands {
player.printError(e.getMessage()); player.printError(e.getMessage());
} }
} }
} }

View File

@ -23,17 +23,25 @@ import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.entity.Player;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* History little commands. * Commands to undo, redo, and clear history.
*
* @author sk89q
*/ */
public class HistoryCommands { public class HistoryCommands {
private final WorldEdit we;
public HistoryCommands(WorldEdit we) { private final WorldEdit worldEdit;
this.we = we;
/**
* Create a new instance.
*
* @param worldEdit reference to WorldEdit
*/
public HistoryCommands(WorldEdit worldEdit) {
checkNotNull(worldEdit);
this.worldEdit = worldEdit;
} }
@Command( @Command(
@ -44,9 +52,7 @@ public class HistoryCommands {
max = 2 max = 2
) )
@CommandPermissions("worldedit.history.undo") @CommandPermissions("worldedit.history.undo")
public void undo(CommandContext args, LocalSession session, LocalPlayer player, public void undo(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
int times = Math.max(1, args.getInteger(0, 1)); int times = Math.max(1, args.getInteger(0, 1));
for (int i = 0; i < times; ++i) { for (int i = 0; i < times; ++i) {
EditSession undone; EditSession undone;
@ -54,7 +60,7 @@ public class HistoryCommands {
undone = session.undo(session.getBlockBag(player), player); undone = session.undo(session.getBlockBag(player), player);
} else { } else {
player.checkPermission("worldedit.history.undo.other"); player.checkPermission("worldedit.history.undo.other");
LocalSession sess = we.getSession(args.getString(1)); LocalSession sess = worldEdit.getSession(args.getString(1));
if (sess == null) { if (sess == null) {
player.printError("Unable to find session for " + args.getString(1)); player.printError("Unable to find session for " + args.getString(1));
break; break;
@ -63,7 +69,7 @@ public class HistoryCommands {
} }
if (undone != null) { if (undone != null) {
player.print("Undo successful."); player.print("Undo successful.");
we.flushBlockBag(player, undone); worldEdit.flushBlockBag(player, undone);
} else { } else {
player.printError("Nothing left to undo."); player.printError("Nothing left to undo.");
break; break;
@ -79,8 +85,7 @@ public class HistoryCommands {
max = 2 max = 2
) )
@CommandPermissions("worldedit.history.redo") @CommandPermissions("worldedit.history.redo")
public void redo(CommandContext args, LocalSession session, LocalPlayer player, public void redo(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
int times = Math.max(1, args.getInteger(0, 1)); int times = Math.max(1, args.getInteger(0, 1));
@ -90,7 +95,7 @@ public class HistoryCommands {
redone = session.redo(session.getBlockBag(player), player); redone = session.redo(session.getBlockBag(player), player);
} else { } else {
player.checkPermission("worldedit.history.redo.other"); player.checkPermission("worldedit.history.redo.other");
LocalSession sess = we.getSession(args.getString(1)); LocalSession sess = worldEdit.getSession(args.getString(1));
if (sess == null) { if (sess == null) {
player.printError("Unable to find session for " + args.getString(1)); player.printError("Unable to find session for " + args.getString(1));
break; break;
@ -99,7 +104,7 @@ public class HistoryCommands {
} }
if (redone != null) { if (redone != null) {
player.print("Redo successful."); player.print("Redo successful.");
we.flushBlockBag(player, redone); worldEdit.flushBlockBag(player, redone);
} else { } else {
player.printError("Nothing left to redo."); player.printError("Nothing left to redo.");
} }
@ -114,10 +119,9 @@ public class HistoryCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.history.clear") @CommandPermissions("worldedit.history.clear")
public void clearHistory(CommandContext args, LocalSession session, LocalPlayer player, public void clearHistory(Player player, LocalSession session, EditSession editSession) throws WorldEditException {
EditSession editSession) throws WorldEditException {
session.clearHistory(); session.clearHistory();
player.print("History cleared."); player.print("History cleared.");
} }
} }

View File

@ -19,31 +19,32 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.POSITION;
import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession; import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.WorldEdit; import static com.sk89q.minecraft.util.commands.Logging.LogMode.POSITION;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.WorldVector;
/** /**
* Navigation commands. * Commands for moving the player around.
*
* @author sk89q
*/ */
public class NavigationCommands { public class NavigationCommands {
@SuppressWarnings("unused")
private final WorldEdit we;
public NavigationCommands(WorldEdit we) { @SuppressWarnings("unused")
this.we = we; private final WorldEdit worldEdit;
/**
* Create a new instance.
*
* @param worldEdit reference to WorldEdit
*/
public NavigationCommands(WorldEdit worldEdit) {
checkNotNull(worldEdit);
this.worldEdit = worldEdit;
} }
@Command( @Command(
@ -54,9 +55,7 @@ public class NavigationCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.navigation.unstuck") @CommandPermissions("worldedit.navigation.unstuck")
public void unstuck(CommandContext args, LocalSession session, LocalPlayer player, public void unstuck(Player player) throws WorldEditException {
EditSession editSession) throws WorldEditException {
player.print("There you go!"); player.print("There you go!");
player.findFreePosition(); player.findFreePosition();
} }
@ -69,8 +68,7 @@ public class NavigationCommands {
max = 1 max = 1
) )
@CommandPermissions("worldedit.navigation.ascend") @CommandPermissions("worldedit.navigation.ascend")
public void ascend(CommandContext args, LocalSession session, LocalPlayer player, public void ascend(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
int levelsToAscend = 0; int levelsToAscend = 0;
if (args.argsLength() == 0) { if (args.argsLength() == 0) {
levelsToAscend = 1; levelsToAscend = 1;
@ -96,8 +94,7 @@ public class NavigationCommands {
max = 1 max = 1
) )
@CommandPermissions("worldedit.navigation.descend") @CommandPermissions("worldedit.navigation.descend")
public void descend(CommandContext args, LocalSession session, LocalPlayer player, public void descend(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
int levelsToDescend = 0; int levelsToDescend = 0;
if (args.argsLength() == 0) { if (args.argsLength() == 0) {
levelsToDescend = 1; levelsToDescend = 1;
@ -125,8 +122,7 @@ public class NavigationCommands {
) )
@CommandPermissions("worldedit.navigation.ceiling") @CommandPermissions("worldedit.navigation.ceiling")
@Logging(POSITION) @Logging(POSITION)
public void ceiling(CommandContext args, LocalSession session, LocalPlayer player, public void ceiling(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
final int clearance = args.argsLength() > 0 ? final int clearance = args.argsLength() > 0 ?
Math.max(0, args.getInteger(0)) : 0; Math.max(0, args.getInteger(0)) : 0;
@ -147,8 +143,7 @@ public class NavigationCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.navigation.thru.command") @CommandPermissions("worldedit.navigation.thru.command")
public void thru(CommandContext args, LocalSession session, LocalPlayer player, public void thru(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
if (player.passThroughForwardWall(6)) { if (player.passThroughForwardWall(6)) {
player.print("Whoosh!"); player.print("Whoosh!");
} else { } else {
@ -164,8 +159,7 @@ public class NavigationCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.navigation.jumpto.command") @CommandPermissions("worldedit.navigation.jumpto.command")
public void jumpTo(CommandContext args, LocalSession session, LocalPlayer player, public void jumpTo(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
WorldVector pos = player.getSolidBlockTrace(300); WorldVector pos = player.getSolidBlockTrace(300);
if (pos != null) { if (pos != null) {
@ -186,8 +180,7 @@ public class NavigationCommands {
) )
@CommandPermissions("worldedit.navigation.up") @CommandPermissions("worldedit.navigation.up")
@Logging(POSITION) @Logging(POSITION)
public void up(CommandContext args, LocalSession session, LocalPlayer player, public void up(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
final int distance = args.getInteger(0); final int distance = args.getInteger(0);
@ -206,7 +199,7 @@ public class NavigationCommands {
* @return true, if glass should always be put under the player * @return true, if glass should always be put under the player
*/ */
private boolean getAlwaysGlass(CommandContext args) { private boolean getAlwaysGlass(CommandContext args) {
final LocalConfiguration config = we.getConfiguration(); final LocalConfiguration config = worldEdit.getConfiguration();
final boolean forceFlight = args.hasFlag('f'); final boolean forceFlight = args.hasFlag('f');
final boolean forceGlass = args.hasFlag('g'); final boolean forceGlass = args.hasFlag('g');

View File

@ -20,50 +20,61 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import com.sk89q.minecraft.util.commands.Command; 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.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.convolution.GaussianKernel;
import com.sk89q.worldedit.math.convolution.HeightMap;
import com.sk89q.worldedit.math.convolution.HeightMapFilter;
import com.sk89q.worldedit.function.GroundFunction; import com.sk89q.worldedit.function.GroundFunction;
import com.sk89q.worldedit.function.generator.FloraGenerator; import com.sk89q.worldedit.function.generator.FloraGenerator;
import com.sk89q.worldedit.function.generator.ForestGenerator; import com.sk89q.worldedit.function.generator.ForestGenerator;
import com.sk89q.worldedit.function.visitor.LayerVisitor; import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.masks.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.NoiseFilter2D; import com.sk89q.worldedit.function.mask.NoiseFilter2D;
import com.sk89q.worldedit.patterns.Pattern; import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.patterns.SingleBlockPattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.function.pattern.Patterns;
import com.sk89q.worldedit.function.visitor.LayerVisitor;
import com.sk89q.worldedit.internal.annotation.Direction;
import com.sk89q.worldedit.internal.annotation.Selection;
import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.math.convolution.GaussianKernel;
import com.sk89q.worldedit.math.convolution.HeightMap;
import com.sk89q.worldedit.math.convolution.HeightMapFilter;
import com.sk89q.worldedit.math.noise.RandomNoise;
import com.sk89q.worldedit.regions.ConvexPolyhedralRegion; import com.sk89q.worldedit.regions.ConvexPolyhedralRegion;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionOperationException; import com.sk89q.worldedit.regions.RegionOperationException;
import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.math.noise.RandomNoise; import com.sk89q.worldedit.util.TreeGenerator.TreeType;
import com.sk89q.worldedit.util.command.binding.Range;
import com.sk89q.worldedit.util.command.binding.Switch;
import com.sk89q.worldedit.util.command.binding.Text;
import com.sk89q.worldedit.util.command.parametric.Optional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.*; import static com.sk89q.minecraft.util.commands.Logging.LogMode.*;
import static com.sk89q.worldedit.regions.Regions.*; import static com.sk89q.worldedit.regions.Regions.*;
/** /**
* Region related commands. * Commands that operate on regions.
*
* @author sk89q
*/ */
public class RegionCommands { public class RegionCommands {
private final WorldEdit we;
public RegionCommands(WorldEdit we) { private final WorldEdit worldEdit;
this.we = we;
/**
* Create a new instance.
*
* @param worldEdit reference to WorldEdit
*/
public RegionCommands(WorldEdit worldEdit) {
checkNotNull(worldEdit);
this.worldEdit = worldEdit;
} }
@Command( @Command(
@ -75,20 +86,8 @@ public class RegionCommands {
) )
@CommandPermissions("worldedit.region.set") @CommandPermissions("worldedit.region.set")
@Logging(REGION) @Logging(REGION)
public void set(CommandContext args, LocalSession session, LocalPlayer player, public void set(Player player, LocalSession session, EditSession editSession, Pattern pattern) throws WorldEditException {
EditSession editSession) throws WorldEditException { int affected = editSession.setBlocks(session.getSelection(player.getWorld()), Patterns.wrap(pattern));
Pattern pattern = we.getBlockPattern(player, args.getString(0));
int affected;
if (pattern instanceof SingleBlockPattern) {
affected = editSession.setBlocks(session.getSelection(player.getWorld()),
((SingleBlockPattern) pattern).getBlock());
} else {
affected = editSession.setBlocks(session.getSelection(player.getWorld()), pattern);
}
player.print(affected + " block(s) have been changed."); player.print(affected + " block(s) have been changed.");
} }
@ -107,24 +106,21 @@ public class RegionCommands {
) )
@CommandPermissions("worldedit.region.line") @CommandPermissions("worldedit.region.line")
@Logging(REGION) @Logging(REGION)
public void line(CommandContext args, LocalSession session, LocalPlayer player, public void line(Player player, EditSession editSession,
EditSession editSession) throws WorldEditException { @Selection Region region,
Pattern pattern,
@Optional("0") @Range(min = 0) int thickness,
@Switch('h') boolean shell) throws WorldEditException {
Region region = session.getSelection(session.getSelectionWorld());
if (!(region instanceof CuboidRegion)) { if (!(region instanceof CuboidRegion)) {
player.printError("Invalid region type"); player.printError("//line only works with cuboid selections");
return;
}
if (args.argsLength() < 2 ? false : args.getDouble(1) < 0) {
player.printError("Invalid thickness. Must not be negative");
return; return;
} }
Pattern pattern = we.getBlockPattern(player, args.getString(0));
CuboidRegion cuboidregion = (CuboidRegion) region; CuboidRegion cuboidregion = (CuboidRegion) region;
Vector pos1 = cuboidregion.getPos1(); Vector pos1 = cuboidregion.getPos1();
Vector pos2 = cuboidregion.getPos2(); Vector pos2 = cuboidregion.getPos2();
int blocksChanged = editSession.drawLine(pattern, pos1, pos2, args.argsLength() < 2 ? 0 : args.getDouble(1), !args.hasFlag('h')); int blocksChanged = editSession.drawLine(Patterns.wrap(pattern), pos1, pos2, thickness, !shell);
player.print(blocksChanged + " block(s) have been changed."); player.print(blocksChanged + " block(s) have been changed.");
} }
@ -144,24 +140,20 @@ public class RegionCommands {
) )
@CommandPermissions("worldedit.region.curve") @CommandPermissions("worldedit.region.curve")
@Logging(REGION) @Logging(REGION)
public void curve(CommandContext args, LocalSession session, LocalPlayer player, public void curve(Player player, EditSession editSession,
EditSession editSession) throws WorldEditException { @Selection Region region,
Pattern pattern,
Region region = session.getSelection(session.getSelectionWorld()); @Optional("0") @Range(min = 0) int thickness,
@Switch('h') boolean shell) throws WorldEditException {
if (!(region instanceof ConvexPolyhedralRegion)) { if (!(region instanceof ConvexPolyhedralRegion)) {
player.printError("Invalid region type"); player.printError("//line only works with convex polyhedral selections");
return;
}
if (args.argsLength() < 2 ? false : args.getDouble(1) < 0) {
player.printError("Invalid thickness. Must not be negative");
return; return;
} }
Pattern pattern = we.getBlockPattern(player, args.getString(0));
ConvexPolyhedralRegion cpregion = (ConvexPolyhedralRegion) region; ConvexPolyhedralRegion cpregion = (ConvexPolyhedralRegion) region;
List<Vector> vectors = new ArrayList<Vector>(cpregion.getVertices()); List<Vector> vectors = new ArrayList<Vector>(cpregion.getVertices());
int blocksChanged = editSession.drawSpline(pattern, vectors, 0, 0, 0, 10, args.argsLength() < 2 ? 0 : args.getDouble(1), !args.hasFlag('h')); int blocksChanged = editSession.drawSpline(Patterns.wrap(pattern), vectors, 0, 0, 0, 10, thickness, !shell);
player.print(blocksChanged + " block(s) have been changed."); player.print(blocksChanged + " block(s) have been changed.");
} }
@ -176,27 +168,11 @@ public class RegionCommands {
) )
@CommandPermissions("worldedit.region.replace") @CommandPermissions("worldedit.region.replace")
@Logging(REGION) @Logging(REGION)
public void replace(CommandContext args, LocalSession session, LocalPlayer player, public void replace(Player player, EditSession editSession, @Selection Region region, @Optional Mask from, Pattern to) throws WorldEditException {
EditSession editSession) throws WorldEditException { if (from == null) {
from = new ExistingBlockMask(editSession);
Set<BaseBlock> from;
Pattern to;
if (args.argsLength() == 1) {
from = null;
to = we.getBlockPattern(player, args.getString(0));
} else {
from = we.getBlocks(player, args.getString(0), true, !args.hasFlag('f'));
to = we.getBlockPattern(player, args.getString(1));
} }
int affected = editSession.replaceBlocks(region, from, Patterns.wrap(to));
final int affected;
if (to instanceof SingleBlockPattern) {
affected = editSession.replaceBlocks(session.getSelection(player.getWorld()), from,
((SingleBlockPattern) to).getBlock());
} else {
affected = editSession.replaceBlocks(session.getSelection(player.getWorld()), from, to);
}
player.print(affected + " block(s) have been replaced."); player.print(affected + " block(s) have been replaced.");
} }
@ -209,20 +185,9 @@ public class RegionCommands {
) )
@CommandPermissions("worldedit.region.overlay") @CommandPermissions("worldedit.region.overlay")
@Logging(REGION) @Logging(REGION)
public void overlay(CommandContext args, LocalSession session, LocalPlayer player, public void overlay(Player player, EditSession editSession, @Selection Region region, Pattern pattern) throws WorldEditException {
EditSession editSession) throws WorldEditException { int affected = editSession.overlayCuboidBlocks(region, Patterns.wrap(pattern));
player.print(affected + " block(s) have been overlaid.");
Pattern pat = we.getBlockPattern(player, args.getString(0));
Region region = session.getSelection(player.getWorld());
int affected = 0;
if (pat instanceof SingleBlockPattern) {
affected = editSession.overlayCuboidBlocks(region,
((SingleBlockPattern) pat).getBlock());
} else {
affected = editSession.overlayCuboidBlocks(region, pat);
}
player.print(affected + " block(s) have been overlayed.");
} }
@Command( @Command(
@ -234,12 +199,8 @@ public class RegionCommands {
) )
@Logging(REGION) @Logging(REGION)
@CommandPermissions("worldedit.region.center") @CommandPermissions("worldedit.region.center")
public void center(CommandContext args, LocalSession session, LocalPlayer player, public void center(Player player, EditSession editSession, @Selection Region region, Pattern pattern) throws WorldEditException {
EditSession editSession) throws WorldEditException { int affected = editSession.center(region, Patterns.wrap(pattern));
Pattern pattern = we.getBlockPattern(player, args.getString(0));
Region region = session.getSelection(player.getWorld());
int affected = editSession.center(region, pattern);
player.print("Center set ("+ affected + " blocks changed)"); player.print("Center set ("+ affected + " blocks changed)");
} }
@ -252,12 +213,9 @@ public class RegionCommands {
) )
@CommandPermissions("worldedit.region.naturalize") @CommandPermissions("worldedit.region.naturalize")
@Logging(REGION) @Logging(REGION)
public void naturalize(CommandContext args, LocalSession session, LocalPlayer player, public void naturalize(Player player, EditSession editSession, @Selection Region region) throws WorldEditException {
EditSession editSession) throws WorldEditException {
Region region = session.getSelection(player.getWorld());
int affected = editSession.naturalizeCuboidBlocks(region); int affected = editSession.naturalizeCuboidBlocks(region);
player.print(affected + " block(s) have been naturalized."); player.print(affected + " block(s) have been made to look more natural.");
} }
@Command( @Command(
@ -269,20 +227,8 @@ public class RegionCommands {
) )
@CommandPermissions("worldedit.region.walls") @CommandPermissions("worldedit.region.walls")
@Logging(REGION) @Logging(REGION)
public void walls(CommandContext args, LocalSession session, LocalPlayer player, public void walls(Player player, EditSession editSession, @Selection Region region, Pattern pattern) throws WorldEditException {
EditSession editSession) throws WorldEditException { int affected = editSession.makeCuboidWalls(region, Patterns.wrap(pattern));
final Pattern pattern = we.getBlockPattern(player, args.getString(0));
final int affected;
final Region region = session.getSelection(player.getWorld());
if (!(region instanceof CuboidRegion)) {
affected = editSession.makeWalls(region, pattern);
} else if (pattern instanceof SingleBlockPattern) {
affected = editSession.makeCuboidWalls(region, ((SingleBlockPattern) pattern).getBlock());
} else {
affected = editSession.makeCuboidWalls(region, pattern);
}
player.print(affected + " block(s) have been changed."); player.print(affected + " block(s) have been changed.");
} }
@ -295,20 +241,8 @@ public class RegionCommands {
) )
@CommandPermissions("worldedit.region.faces") @CommandPermissions("worldedit.region.faces")
@Logging(REGION) @Logging(REGION)
public void faces(CommandContext args, LocalSession session, LocalPlayer player, public void faces(Player player, EditSession editSession, @Selection Region region, Pattern pattern) throws WorldEditException {
EditSession editSession) throws WorldEditException { int affected = editSession.makeCuboidFaces(region, Patterns.wrap(pattern));
final Pattern pattern = we.getBlockPattern(player, args.getString(0));
final int affected;
final Region region = session.getSelection(player.getWorld());
if (!(region instanceof CuboidRegion)) {
affected = editSession.makeFaces(region, pattern);
} else if (pattern instanceof SingleBlockPattern) {
affected = editSession.makeCuboidFaces(region, ((SingleBlockPattern) pattern).getBlock());
} else {
affected = editSession.makeCuboidFaces(region, pattern);
}
player.print(affected + " block(s) have been changed."); player.print(affected + " block(s) have been changed.");
} }
@ -325,15 +259,8 @@ public class RegionCommands {
) )
@CommandPermissions("worldedit.region.smooth") @CommandPermissions("worldedit.region.smooth")
@Logging(REGION) @Logging(REGION)
public void smooth(CommandContext args, LocalSession session, LocalPlayer player, public void smooth(Player player, EditSession editSession, @Selection Region region, @Optional("1") int iterations, @Switch('n') boolean affectNatural) throws WorldEditException {
EditSession editSession) throws WorldEditException { HeightMap heightMap = new HeightMap(editSession, region, affectNatural);
int iterations = 1;
if (args.argsLength() > 0) {
iterations = args.getInteger(0);
}
HeightMap heightMap = new HeightMap(editSession, session.getSelection(player.getWorld()), args.hasFlag('n'));
HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0)); HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
int affected = heightMap.applyFilter(filter, iterations); int affected = heightMap.applyFilter(filter, iterations);
player.print("Terrain's height map smoothed. " + affected + " block(s) changed."); player.print("Terrain's height map smoothed. " + affected + " block(s) changed.");
@ -354,28 +281,18 @@ public class RegionCommands {
) )
@CommandPermissions("worldedit.region.move") @CommandPermissions("worldedit.region.move")
@Logging(ORIENTATION_REGION) @Logging(ORIENTATION_REGION)
public void move(CommandContext args, LocalSession session, LocalPlayer player, public void move(Player player, EditSession editSession, LocalSession session,
EditSession editSession) throws WorldEditException { @Selection Region region,
@Optional("1") @Range(min = 1) int count,
@Optional(Direction.AIM) @Direction Vector direction,
@Optional("air") BaseBlock replace,
@Switch('s') boolean moveSelection) throws WorldEditException {
int count = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1; int affected = editSession.moveRegion(region, direction, count, true, replace);
Vector dir = we.getDirection(player,
args.argsLength() > 1 ? args.getString(1).toLowerCase() : "me");
BaseBlock replace;
// Replacement block argument if (moveSelection) {
if (args.argsLength() > 2) {
replace = we.getBlock(player, args.getString(2));
} else {
replace = new BaseBlock(BlockID.AIR);
}
int affected = editSession.moveRegion(session.getSelection(player.getWorld()),
dir, count, true, replace);
if (args.hasFlag('s')) {
try { try {
Region region = session.getSelection(player.getWorld()); region.shift(direction.multiply(count));
region.shift(dir.multiply(count));
session.getRegionSelector(player.getWorld()).learnChanges(); session.getRegionSelector(player.getWorld()).learnChanges();
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session); session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
@ -402,22 +319,19 @@ public class RegionCommands {
) )
@CommandPermissions("worldedit.region.stack") @CommandPermissions("worldedit.region.stack")
@Logging(ORIENTATION_REGION) @Logging(ORIENTATION_REGION)
public void stack(CommandContext args, LocalSession session, LocalPlayer player, public void stack(Player player, EditSession editSession, LocalSession session,
EditSession editSession) throws WorldEditException { @Selection Region region,
@Optional("1") @Range(min = 1) int count,
@Optional(Direction.AIM) @Direction Vector direction,
@Switch('s') boolean moveSelection,
@Switch('a') boolean ignoreAirBlocks) throws WorldEditException {
int affected = editSession.stackCuboidRegion(region, direction, count, !ignoreAirBlocks);
int count = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1; if (ignoreAirBlocks) {
Vector dir = we.getDiagonalDirection(player,
args.argsLength() > 1 ? args.getString(1).toLowerCase() : "me");
int affected = editSession.stackCuboidRegion(session.getSelection(player.getWorld()),
dir, count, !args.hasFlag('a'));
if (args.hasFlag('s')) {
try { try {
final Region region = session.getSelection(player.getWorld());
final Vector size = region.getMaximumPoint().subtract(region.getMinimumPoint()); final Vector size = region.getMaximumPoint().subtract(region.getMinimumPoint());
final Vector shiftVector = dir.multiply(count * (Math.abs(dir.dot(size)) + 1)); final Vector shiftVector = direction.multiply(count * (Math.abs(direction.dot(size)) + 1));
region.shift(shiftVector); region.shift(shiftVector);
session.getRegionSelector(player.getWorld()).learnChanges(); session.getRegionSelector(player.getWorld()).learnChanges();
@ -443,14 +357,14 @@ public class RegionCommands {
) )
@CommandPermissions("worldedit.regen") @CommandPermissions("worldedit.regen")
@Logging(REGION) @Logging(REGION)
public void regenerateChunk(CommandContext args, LocalSession session, LocalPlayer player, public void regenerateChunk(Player player, LocalSession session, EditSession editSession, @Selection Region region) throws WorldEditException {
EditSession editSession) throws WorldEditException {
Region region = session.getSelection(player.getWorld());
Mask mask = session.getMask(); Mask mask = session.getMask();
session.setMask(null); try {
player.getWorld().regenerate(region, editSession); session.setMask((Mask) null);
session.setMask(mask); player.getWorld().regenerate(region, editSession);
} finally {
session.setMask(mask);
}
player.print("Region regenerated."); player.print("Region regenerated.");
} }
@ -469,20 +383,18 @@ public class RegionCommands {
) )
@CommandPermissions("worldedit.region.deform") @CommandPermissions("worldedit.region.deform")
@Logging(ALL) @Logging(ALL)
public void deform(CommandContext args, LocalSession session, LocalPlayer player, public void deform(Player player, LocalSession session, EditSession editSession,
EditSession editSession) throws WorldEditException { @Selection Region region,
@Text String expression,
final Region region = session.getSelection(player.getWorld()); @Switch('r') boolean useRawCoords,
@Switch('o') boolean offset) throws WorldEditException {
final String expression = args.getJoinedStrings(0);
final Vector zero; final Vector zero;
Vector unit; Vector unit;
if (args.hasFlag('r')) { if (useRawCoords) {
zero = Vector.ZERO; zero = Vector.ZERO;
unit = Vector.ONE; unit = Vector.ONE;
} else if (args.hasFlag('o')) { } else if (offset) {
zero = session.getPlacementPosition(player); zero = session.getPlacementPosition(player);
unit = Vector.ONE; unit = Vector.ONE;
} else { } else {
@ -519,14 +431,12 @@ public class RegionCommands {
) )
@CommandPermissions("worldedit.region.hollow") @CommandPermissions("worldedit.region.hollow")
@Logging(REGION) @Logging(REGION)
public void hollow(CommandContext args, LocalSession session, LocalPlayer player, public void hollow(Player player, EditSession editSession,
EditSession editSession) throws WorldEditException { @Selection Region region,
@Optional("0") @Range(min = 0) int thickness,
final int thickness = args.argsLength() >= 1 ? Math.max(1, args.getInteger(0)) : 1; @Optional("air") Pattern pattern) throws WorldEditException {
final Pattern pattern = args.argsLength() >= 2 ? we.getBlockPattern(player, args.getString(1)) : new SingleBlockPattern(new BaseBlock(BlockID.AIR));
final int affected = editSession.hollowOutRegion(session.getSelection(player.getWorld()), thickness, pattern);
int affected = editSession.hollowOutRegion(region, thickness, Patterns.wrap(pattern));
player.print(affected + " block(s) have been changed."); player.print(affected + " block(s) have been changed.");
} }
@ -539,18 +449,8 @@ public class RegionCommands {
) )
@CommandPermissions("worldedit.region.forest") @CommandPermissions("worldedit.region.forest")
@Logging(REGION) @Logging(REGION)
public void forest(CommandContext args, LocalSession session, LocalPlayer player, public void forest(Player player, EditSession editSession, @Selection Region region, @Optional("tree") TreeType type, @Optional("5") double density) throws WorldEditException {
EditSession editSession) throws WorldEditException { density = density / 100;
TreeGenerator.TreeType type = args.argsLength() > 0 ? TreeGenerator.lookup(args.getString(0)) : TreeGenerator.TreeType.TREE;
double density = args.argsLength() > 1 ? args.getDouble(1) / 100 : 0.05;
if (type == null) {
player.printError("Tree type '" + args.getString(0) + "' is unknown.");
return;
}
Region region = session.getSelection(player.getWorld());
ForestGenerator generator = new ForestGenerator(editSession, new TreeGenerator(type)); ForestGenerator generator = new ForestGenerator(editSession, new TreeGenerator(type));
GroundFunction ground = new GroundFunction(new ExistingBlockMask(editSession), generator); GroundFunction ground = new GroundFunction(new ExistingBlockMask(editSession), generator);
LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground); LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground);
@ -569,10 +469,8 @@ public class RegionCommands {
) )
@CommandPermissions("worldedit.region.flora") @CommandPermissions("worldedit.region.flora")
@Logging(REGION) @Logging(REGION)
public void flora(CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { public void flora(Player player, EditSession editSession, @Selection Region region, @Optional("10") double density) throws WorldEditException {
double density = args.argsLength() > 0 ? args.getDouble(0) / 100 : 0.1; density = density / 100;
Region region = session.getSelection(player.getWorld());
FloraGenerator generator = new FloraGenerator(editSession); FloraGenerator generator = new FloraGenerator(editSession);
GroundFunction ground = new GroundFunction(new ExistingBlockMask(editSession), generator); GroundFunction ground = new GroundFunction(new ExistingBlockMask(editSession), generator);
LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground); LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground);

View File

@ -21,6 +21,7 @@ package com.sk89q.worldedit.command;
import com.sk89q.minecraft.util.commands.*; import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.schematic.SchematicFormat; import com.sk89q.worldedit.schematic.SchematicFormat;
import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.DataException;
@ -31,16 +32,23 @@ import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Commands related to schematics * Commands that work with schematic files.
*
* @see com.sk89q.worldedit.command.ClipboardCommands#schematic()
*/ */
public class SchematicCommands { public class SchematicCommands {
private final WorldEdit we;
public SchematicCommands(WorldEdit we) { private final WorldEdit worldEdit;
this.we = we;
/**
* Create a new instance.
*
* @param worldEdit reference to WorldEdit
*/
public SchematicCommands(WorldEdit worldEdit) {
checkNotNull(worldEdit);
this.worldEdit = worldEdit;
} }
@Command( @Command(
@ -56,10 +64,9 @@ public class SchematicCommands {
max = 2 max = 2
) )
@CommandPermissions({"worldedit.clipboard.load", "worldedit.schematic.load"}) // TODO: Remove 'clipboard' perm @CommandPermissions({"worldedit.clipboard.load", "worldedit.schematic.load"}) // TODO: Remove 'clipboard' perm
public void load(CommandContext args, LocalSession session, LocalPlayer player, public void load(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = worldEdit.getConfiguration();
String fileName; String fileName;
String formatName; String formatName;
@ -70,8 +77,8 @@ public class SchematicCommands {
formatName = args.getString(0); formatName = args.getString(0);
fileName = args.getString(1); fileName = args.getString(1);
} }
File dir = we.getWorkingDirectoryFile(config.saveDir); File dir = worldEdit.getWorkingDirectoryFile(config.saveDir);
File f = we.getSafeOpenFile(player, dir, fileName, "schematic", "schematic"); File f = worldEdit.getSafeOpenFile(player, dir, fileName, "schematic", "schematic");
if (!f.exists()) { if (!f.exists()) {
player.printError("Schematic " + fileName + " does not exist!"); player.printError("Schematic " + fileName + " does not exist!");
@ -121,10 +128,9 @@ public class SchematicCommands {
max = 2 max = 2
) )
@CommandPermissions({"worldedit.clipboard.save", "worldedit.schematic.save"}) // TODO: Remove 'clipboard' perm @CommandPermissions({"worldedit.clipboard.save", "worldedit.schematic.save"}) // TODO: Remove 'clipboard' perm
public void save(CommandContext args, LocalSession session, LocalPlayer player, public void save(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException, CommandException {
EditSession editSession) throws WorldEditException, CommandException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = worldEdit.getConfiguration();
SchematicFormat format; SchematicFormat format;
if (args.argsLength() == 1) { if (args.argsLength() == 1) {
if (SchematicFormat.getFormats().size() == 1) { if (SchematicFormat.getFormats().size() == 1) {
@ -143,8 +149,8 @@ public class SchematicCommands {
String filename = args.getString(args.argsLength() - 1); String filename = args.getString(args.argsLength() - 1);
File dir = we.getWorkingDirectoryFile(config.saveDir); File dir = worldEdit.getWorkingDirectoryFile(config.saveDir);
File f = we.getSafeSaveFile(player, dir, filename, "schematic", "schematic"); File f = worldEdit.getSafeSaveFile(player, dir, filename, "schematic", "schematic");
if (!dir.exists()) { if (!dir.exists()) {
if (!dir.mkdir()) { if (!dir.mkdir()) {
@ -181,14 +187,13 @@ public class SchematicCommands {
max = 1 max = 1
) )
@CommandPermissions("worldedit.schematic.delete") @CommandPermissions("worldedit.schematic.delete")
public void delete(CommandContext args, LocalSession session, LocalPlayer player, public void delete(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = worldEdit.getConfiguration();
String filename = args.getString(0); String filename = args.getString(0);
File dir = we.getWorkingDirectoryFile(config.saveDir); File dir = worldEdit.getWorkingDirectoryFile(config.saveDir);
File f = we.getSafeSaveFile(player, dir, filename, "schematic", "schematic"); File f = worldEdit.getSafeSaveFile(player, dir, filename, "schematic", "schematic");
if (!f.exists()) { if (!f.exists()) {
player.printError("Schematic " + filename + " does not exist!"); player.printError("Schematic " + filename + " does not exist!");
@ -239,7 +244,7 @@ public class SchematicCommands {
) )
@CommandPermissions("worldedit.schematic.list") @CommandPermissions("worldedit.schematic.list")
public void list(Actor actor, CommandContext args) throws WorldEditException { public void list(Actor actor, CommandContext args) throws WorldEditException {
File dir = we.getWorkingDirectoryFile(we.getConfiguration().saveDir); File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().saveDir);
File[] files = dir.listFiles(new FileFilter(){ File[] files = dir.listFiles(new FileFilter(){
@Override @Override
public boolean accept(File file) { public boolean accept(File file) {

View File

@ -19,24 +19,36 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import java.io.File;
import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.minecraft.util.commands.Logging;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.*; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.Player;
import java.io.File;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.ALL;
/** /**
* Scripting commands. * Commands related to scripting.
*
* @author sk89q
*/ */
public class ScriptingCommands { public class ScriptingCommands {
private final WorldEdit we;
public ScriptingCommands(WorldEdit we) { private final WorldEdit worldEdit;
this.we = we;
/**
* Create a new instance.
*
* @param worldEdit reference to WorldEdit
*/
public ScriptingCommands(WorldEdit worldEdit) {
checkNotNull(worldEdit);
this.worldEdit = worldEdit;
} }
@Command( @Command(
@ -48,8 +60,7 @@ public class ScriptingCommands {
) )
@CommandPermissions("worldedit.scripting.execute") @CommandPermissions("worldedit.scripting.execute")
@Logging(ALL) @Logging(ALL)
public void execute(CommandContext args, LocalSession session, LocalPlayer player, public void execute(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
String[] scriptArgs = args.getSlice(1); String[] scriptArgs = args.getSlice(1);
String name = args.getString(0); String name = args.getString(0);
@ -61,10 +72,10 @@ public class ScriptingCommands {
session.setLastScript(name); session.setLastScript(name);
File dir = we.getWorkingDirectoryFile(we.getConfiguration().scriptsDir); File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir);
File f = we.getSafeOpenFile(player, dir, name, "js", "js"); File f = worldEdit.getSafeOpenFile(player, dir, name, "js", "js");
we.runScript(player, f, scriptArgs); worldEdit.runScript(player, f, scriptArgs);
} }
@Command( @Command(
@ -76,8 +87,7 @@ public class ScriptingCommands {
) )
@CommandPermissions("worldedit.scripting.execute") @CommandPermissions("worldedit.scripting.execute")
@Logging(ALL) @Logging(ALL)
public void executeLast(CommandContext args, LocalSession session, LocalPlayer player, public void executeLast(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
String lastScript = session.getLastScript(); String lastScript = session.getLastScript();
@ -93,9 +103,9 @@ public class ScriptingCommands {
String[] scriptArgs = args.getSlice(0); String[] scriptArgs = args.getSlice(0);
File dir = we.getWorkingDirectoryFile(we.getConfiguration().scriptsDir); File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir);
File f = we.getSafeOpenFile(player, dir, lastScript, "js", "js"); File f = worldEdit.getSafeOpenFile(player, dir, lastScript, "js", "js");
we.runScript(player, f, scriptArgs); worldEdit.runScript(player, f, scriptArgs);
} }
} }

View File

@ -31,6 +31,7 @@ import com.sk89q.minecraft.util.commands.CommandAlias;
import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.util.Countable; import com.sk89q.worldedit.util.Countable;
import com.sk89q.worldedit.CuboidClipboard; import com.sk89q.worldedit.CuboidClipboard;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
@ -76,8 +77,7 @@ public class SelectionCommands {
) )
@Logging(POSITION) @Logging(POSITION)
@CommandPermissions("worldedit.selection.pos") @CommandPermissions("worldedit.selection.pos")
public void pos1(CommandContext args, LocalSession session, LocalPlayer player, public void pos1(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
Vector pos; Vector pos;
@ -111,8 +111,7 @@ public class SelectionCommands {
) )
@Logging(POSITION) @Logging(POSITION)
@CommandPermissions("worldedit.selection.pos") @CommandPermissions("worldedit.selection.pos")
public void pos2(CommandContext args, LocalSession session, LocalPlayer player, public void pos2(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
Vector pos; Vector pos;
if (args.argsLength() == 1) { if (args.argsLength() == 1) {
@ -146,8 +145,7 @@ public class SelectionCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.selection.hpos") @CommandPermissions("worldedit.selection.hpos")
public void hpos1(CommandContext args, LocalSession session, LocalPlayer player, public void hpos1(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
Vector pos = player.getBlockTrace(300); Vector pos = player.getBlockTrace(300);
@ -173,8 +171,7 @@ public class SelectionCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.selection.hpos") @CommandPermissions("worldedit.selection.hpos")
public void hpos2(CommandContext args, LocalSession session, LocalPlayer player, public void hpos2(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
Vector pos = player.getBlockTrace(300); Vector pos = player.getBlockTrace(300);
@ -210,8 +207,7 @@ public class SelectionCommands {
) )
@Logging(POSITION) @Logging(POSITION)
@CommandPermissions("worldedit.selection.chunk") @CommandPermissions("worldedit.selection.chunk")
public void chunk(CommandContext args, LocalSession session, LocalPlayer player, public void chunk(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
final Vector min; final Vector min;
final Vector max; final Vector max;
@ -274,8 +270,7 @@ public class SelectionCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.wand") @CommandPermissions("worldedit.wand")
public void wand(CommandContext args, LocalSession session, LocalPlayer player, public void wand(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
player.giveItem(we.getConfiguration().wandItem, 1); player.giveItem(we.getConfiguration().wandItem, 1);
player.print("Left click: select pos #1; Right click: select pos #2"); player.print("Left click: select pos #1; Right click: select pos #2");
@ -289,8 +284,7 @@ public class SelectionCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.wand.toggle") @CommandPermissions("worldedit.wand.toggle")
public void toggleWand(CommandContext args, LocalSession session, LocalPlayer player, public void toggleWand(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
session.setToolControl(!session.isToolControlEnabled()); session.setToolControl(!session.isToolControlEnabled());
@ -310,8 +304,7 @@ public class SelectionCommands {
) )
@Logging(REGION) @Logging(REGION)
@CommandPermissions("worldedit.selection.expand") @CommandPermissions("worldedit.selection.expand")
public void expand(CommandContext args, LocalSession session, LocalPlayer player, public void expand(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
// Special syntax (//expand vert) to expand the selection between // Special syntax (//expand vert) to expand the selection between
// sky and bedrock. // sky and bedrock.
@ -406,8 +399,7 @@ public class SelectionCommands {
) )
@Logging(REGION) @Logging(REGION)
@CommandPermissions("worldedit.selection.contract") @CommandPermissions("worldedit.selection.contract")
public void contract(CommandContext args, LocalSession session, LocalPlayer player, public void contract(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
List<Vector> dirs = new ArrayList<Vector>(); List<Vector> dirs = new ArrayList<Vector>();
int change = args.getInteger(0); int change = args.getInteger(0);
@ -482,8 +474,7 @@ public class SelectionCommands {
) )
@Logging(REGION) @Logging(REGION)
@CommandPermissions("worldedit.selection.shift") @CommandPermissions("worldedit.selection.shift")
public void shift(CommandContext args, LocalSession session, LocalPlayer player, public void shift(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
List<Vector> dirs = new ArrayList<Vector>(); List<Vector> dirs = new ArrayList<Vector>();
int change = args.getInteger(0); int change = args.getInteger(0);
@ -531,8 +522,7 @@ public class SelectionCommands {
) )
@Logging(REGION) @Logging(REGION)
@CommandPermissions("worldedit.selection.outset") @CommandPermissions("worldedit.selection.outset")
public void outset(CommandContext args, LocalSession session, LocalPlayer player, public void outset(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
Region region = session.getSelection(player.getWorld()); Region region = session.getSelection(player.getWorld());
region.expand(getChangesForEachDir(args)); region.expand(getChangesForEachDir(args));
session.getRegionSelector(player.getWorld()).learnChanges(); session.getRegionSelector(player.getWorld()).learnChanges();
@ -555,8 +545,7 @@ public class SelectionCommands {
) )
@Logging(REGION) @Logging(REGION)
@CommandPermissions("worldedit.selection.inset") @CommandPermissions("worldedit.selection.inset")
public void inset(CommandContext args, LocalSession session, LocalPlayer player, public void inset(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
Region region = session.getSelection(player.getWorld()); Region region = session.getSelection(player.getWorld());
region.contract(getChangesForEachDir(args)); region.contract(getChangesForEachDir(args));
session.getRegionSelector(player.getWorld()).learnChanges(); session.getRegionSelector(player.getWorld()).learnChanges();
@ -592,8 +581,7 @@ public class SelectionCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.selection.size") @CommandPermissions("worldedit.selection.size")
public void size(CommandContext args, LocalSession session, LocalPlayer player, public void size(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
if (args.hasFlag('c')) { if (args.hasFlag('c')) {
CuboidClipboard clipboard = session.getClipboard(); CuboidClipboard clipboard = session.getClipboard();
@ -637,8 +625,7 @@ public class SelectionCommands {
max = 1 max = 1
) )
@CommandPermissions("worldedit.analysis.count") @CommandPermissions("worldedit.analysis.count")
public void count(CommandContext args, LocalSession session, LocalPlayer player, public void count(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
boolean useData = args.hasFlag('d'); boolean useData = args.hasFlag('d');
if (args.getString(0).contains(":")) { if (args.getString(0).contains(":")) {
@ -668,8 +655,7 @@ public class SelectionCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.analysis.distr") @CommandPermissions("worldedit.analysis.distr")
public void distr(CommandContext args, LocalSession session, LocalPlayer player, public void distr(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
int size; int size;
boolean useData = args.hasFlag('d'); boolean useData = args.hasFlag('d');
@ -730,8 +716,7 @@ public class SelectionCommands {
min = 0, min = 0,
max = 1 max = 1
) )
public void select(CommandContext args, LocalSession session, LocalPlayer player, public void select(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
final World world = player.getWorld(); final World world = player.getWorld();
if (args.argsLength() == 0) { if (args.argsLength() == 0) {

View File

@ -21,6 +21,15 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
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.entity.Player;
import com.sk89q.worldedit.world.snapshot.InvalidSnapshotException;
import com.sk89q.worldedit.world.snapshot.Snapshot;
import com.sk89q.worldedit.world.storage.MissingWorldException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.text.DateFormat; import java.text.DateFormat;
@ -28,13 +37,6 @@ import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
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.world.storage.MissingWorldException;
import com.sk89q.worldedit.world.snapshot.InvalidSnapshotException;
import com.sk89q.worldedit.world.snapshot.Snapshot;
/** /**
* Snapshot commands. * Snapshot commands.
@ -59,8 +61,7 @@ public class SnapshotCommands {
max = 1 max = 1
) )
@CommandPermissions("worldedit.snapshots.list") @CommandPermissions("worldedit.snapshots.list")
public void list(CommandContext args, LocalSession session, LocalPlayer player, public void list(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
@ -110,8 +111,7 @@ public class SnapshotCommands {
max = 1 max = 1
) )
@CommandPermissions("worldedit.snapshots.restore") @CommandPermissions("worldedit.snapshots.restore")
public void use(CommandContext args, LocalSession session, LocalPlayer player, public void use(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
@ -154,8 +154,7 @@ public class SnapshotCommands {
max = 1 max = 1
) )
@CommandPermissions("worldedit.snapshots.restore") @CommandPermissions("worldedit.snapshots.restore")
public void sel(CommandContext args, LocalSession session, LocalPlayer player, public void sel(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
if (config.snapshotRepo == null) { if (config.snapshotRepo == null) {
@ -202,8 +201,7 @@ public class SnapshotCommands {
max = -1 max = -1
) )
@CommandPermissions("worldedit.snapshots.restore") @CommandPermissions("worldedit.snapshots.restore")
public void before(CommandContext args, LocalSession session, LocalPlayer player, public void before(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
@ -242,8 +240,7 @@ public class SnapshotCommands {
max = -1 max = -1
) )
@CommandPermissions("worldedit.snapshots.restore") @CommandPermissions("worldedit.snapshots.restore")
public void after(CommandContext args, LocalSession session, LocalPlayer player, public void after(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();

View File

@ -19,30 +19,25 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; 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.Logging;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.snapshot.InvalidSnapshotException;
import com.sk89q.worldedit.world.snapshot.Snapshot;
import com.sk89q.worldedit.world.snapshot.SnapshotRestore;
import com.sk89q.worldedit.world.storage.ChunkStore;
import com.sk89q.worldedit.world.storage.MissingWorldException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.sk89q.minecraft.util.commands.Command; import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.minecraft.util.commands.NestedCommand;
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.world.storage.ChunkStore;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.storage.MissingWorldException;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.snapshot.InvalidSnapshotException;
import com.sk89q.worldedit.world.snapshot.Snapshot;
import com.sk89q.worldedit.world.snapshot.SnapshotRestore;
public class SnapshotUtilCommands { public class SnapshotUtilCommands {
@ -63,8 +58,7 @@ public class SnapshotUtilCommands {
) )
@Logging(REGION) @Logging(REGION)
@CommandPermissions("worldedit.snapshots.restore") @CommandPermissions("worldedit.snapshots.restore")
public void restore(CommandContext args, LocalSession session, LocalPlayer player, public void restore(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();

View File

@ -22,15 +22,11 @@ package com.sk89q.worldedit.command;
import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.*;
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.command.tool.AreaPickaxe; import com.sk89q.worldedit.command.tool.AreaPickaxe;
import com.sk89q.worldedit.command.tool.RecursivePickaxe; import com.sk89q.worldedit.command.tool.RecursivePickaxe;
import com.sk89q.worldedit.command.tool.SinglePickaxe; import com.sk89q.worldedit.command.tool.SinglePickaxe;
import com.sk89q.worldedit.entity.Player;
public class SuperPickaxeCommands { public class SuperPickaxeCommands {
private final WorldEdit we; private final WorldEdit we;
@ -47,8 +43,7 @@ public class SuperPickaxeCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.superpickaxe") @CommandPermissions("worldedit.superpickaxe")
public void single(CommandContext args, LocalSession session, LocalPlayer player, public void single(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
session.setSuperPickaxe(new SinglePickaxe()); session.setSuperPickaxe(new SinglePickaxe());
session.enableSuperPickAxe(); session.enableSuperPickAxe();
@ -63,8 +58,7 @@ public class SuperPickaxeCommands {
max = 1 max = 1
) )
@CommandPermissions("worldedit.superpickaxe.area") @CommandPermissions("worldedit.superpickaxe.area")
public void area(CommandContext args, LocalSession session, LocalPlayer player, public void area(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
int range = args.getInteger(0); int range = args.getInteger(0);
@ -87,8 +81,7 @@ public class SuperPickaxeCommands {
max = 1 max = 1
) )
@CommandPermissions("worldedit.superpickaxe.recursive") @CommandPermissions("worldedit.superpickaxe.recursive")
public void recursive(CommandContext args, LocalSession session, LocalPlayer player, public void recursive(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
double range = args.getDouble(0); double range = args.getDouble(0);

View File

@ -26,6 +26,7 @@ import com.sk89q.minecraft.util.commands.NestedCommand;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.ItemType; import com.sk89q.worldedit.blocks.ItemType;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.patterns.Pattern; import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.command.tool.*; import com.sk89q.worldedit.command.tool.*;
import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.TreeGenerator;
@ -44,8 +45,7 @@ public class ToolCommands {
min = 0, min = 0,
max = 0 max = 0
) )
public void none(CommandContext args, LocalSession session, LocalPlayer player, public void none(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
session.setTool(player.getItemInHand(), null); session.setTool(player.getItemInHand(), null);
player.print("Tool unbound from your current item."); player.print("Tool unbound from your current item.");
@ -59,8 +59,7 @@ public class ToolCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.tool.info") @CommandPermissions("worldedit.tool.info")
public void info(CommandContext args, LocalSession session, LocalPlayer player, public void info(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
session.setTool(player.getItemInHand(), new QueryTool()); session.setTool(player.getItemInHand(), new QueryTool());
player.print("Info tool bound to " player.print("Info tool bound to "
@ -76,8 +75,7 @@ public class ToolCommands {
) )
@CommandPermissions("worldedit.tool.tree") @CommandPermissions("worldedit.tool.tree")
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void tree(CommandContext args, LocalSession session, LocalPlayer player, public void tree(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
TreeGenerator.TreeType type = args.argsLength() > 0 ? TreeGenerator.TreeType type = args.argsLength() > 0 ?
type = TreeGenerator.lookup(args.getString(0)) type = TreeGenerator.lookup(args.getString(0))
@ -101,8 +99,7 @@ public class ToolCommands {
max = 1 max = 1
) )
@CommandPermissions("worldedit.tool.replacer") @CommandPermissions("worldedit.tool.replacer")
public void repl(CommandContext args, LocalSession session, LocalPlayer player, public void repl(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
BaseBlock targetBlock = we.getBlock(player, args.getString(0)); BaseBlock targetBlock = we.getBlock(player, args.getString(0));
session.setTool(player.getItemInHand(), new BlockReplacer(targetBlock)); session.setTool(player.getItemInHand(), new BlockReplacer(targetBlock));
@ -118,8 +115,7 @@ public class ToolCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.tool.data-cycler") @CommandPermissions("worldedit.tool.data-cycler")
public void cycler(CommandContext args, LocalSession session, LocalPlayer player, public void cycler(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
session.setTool(player.getItemInHand(), new BlockDataCyler()); session.setTool(player.getItemInHand(), new BlockDataCyler());
player.print("Block data cycler tool bound to " player.print("Block data cycler tool bound to "
@ -134,8 +130,7 @@ public class ToolCommands {
max = 2 max = 2
) )
@CommandPermissions("worldedit.tool.flood-fill") @CommandPermissions("worldedit.tool.flood-fill")
public void floodFill(CommandContext args, LocalSession session, LocalPlayer player, public void floodFill(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
int range = args.getInteger(1); int range = args.getInteger(1);
@ -159,8 +154,7 @@ public class ToolCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.tool.deltree") @CommandPermissions("worldedit.tool.deltree")
public void deltree(CommandContext args, LocalSession session, LocalPlayer player, public void deltree(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
session.setTool(player.getItemInHand(), new FloatingTreeRemover()); session.setTool(player.getItemInHand(), new FloatingTreeRemover());
player.print("Floating tree remover tool bound to " player.print("Floating tree remover tool bound to "
@ -175,8 +169,7 @@ public class ToolCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.tool.farwand") @CommandPermissions("worldedit.tool.farwand")
public void farwand(CommandContext args, LocalSession session, LocalPlayer player, public void farwand(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
session.setTool(player.getItemInHand(), new DistanceWand()); session.setTool(player.getItemInHand(), new DistanceWand());
player.print("Far wand tool bound to " + ItemType.toHeldName(player.getItemInHand()) + "."); player.print("Far wand tool bound to " + ItemType.toHeldName(player.getItemInHand()) + ".");
@ -190,8 +183,7 @@ public class ToolCommands {
max = 2 max = 2
) )
@CommandPermissions("worldedit.tool.lrbuild") @CommandPermissions("worldedit.tool.lrbuild")
public void longrangebuildtool(CommandContext args, LocalSession session, LocalPlayer player, public void longrangebuildtool(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
BaseBlock secondary = we.getBlock(player, args.getString(0)); BaseBlock secondary = we.getBlock(player, args.getString(0));
BaseBlock primary = we.getBlock(player, args.getString(1)); BaseBlock primary = we.getBlock(player, args.getString(1));

View File

@ -46,8 +46,7 @@ public class ToolUtilCommands {
max = 1 max = 1
) )
@CommandPermissions("worldedit.superpickaxe") @CommandPermissions("worldedit.superpickaxe")
public void togglePickaxe(CommandContext args, LocalSession session, LocalPlayer player, public void togglePickaxe(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
String newState = args.getString(0, null); String newState = args.getString(0, null);
if (session.hasSuperPickAxe()) { if (session.hasSuperPickAxe()) {
@ -108,8 +107,7 @@ public class ToolUtilCommands {
max = 1 max = 1
) )
@CommandPermissions("worldedit.brush.options.range") @CommandPermissions("worldedit.brush.options.range")
public void range(CommandContext args, LocalSession session, LocalPlayer player, public void range(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
int range = args.getInteger(0); int range = args.getInteger(0);
session.getBrushTool(player.getItemInHand()).setRange(range); session.getBrushTool(player.getItemInHand()).setRange(range);
player.print("Brush range set."); player.print("Brush range set.");
@ -123,8 +121,7 @@ public class ToolUtilCommands {
max = 1 max = 1
) )
@CommandPermissions("worldedit.brush.options.size") @CommandPermissions("worldedit.brush.options.size")
public void size(CommandContext args, LocalSession session, LocalPlayer player, public void size(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
int radius = args.getInteger(0); int radius = args.getInteger(0);
we.checkMaxBrushRadius(radius); we.checkMaxBrushRadius(radius);

View File

@ -63,8 +63,7 @@ public class UtilityCommands {
) )
@CommandPermissions("worldedit.fill") @CommandPermissions("worldedit.fill")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void fill(CommandContext args, LocalSession session, LocalPlayer player, public void fill(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
Pattern pattern = we.getBlockPattern(player, args.getString(0)); Pattern pattern = we.getBlockPattern(player, args.getString(0));
double radius = Math.max(1, args.getDouble(1)); double radius = Math.max(1, args.getDouble(1));
@ -92,8 +91,7 @@ public class UtilityCommands {
) )
@CommandPermissions("worldedit.fill.recursive") @CommandPermissions("worldedit.fill.recursive")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void fillr(CommandContext args, LocalSession session, LocalPlayer player, public void fillr(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
Pattern pattern = we.getBlockPattern(player, args.getString(0)); Pattern pattern = we.getBlockPattern(player, args.getString(0));
double radius = Math.max(1, args.getDouble(1)); double radius = Math.max(1, args.getDouble(1));
@ -121,8 +119,7 @@ public class UtilityCommands {
) )
@CommandPermissions("worldedit.drain") @CommandPermissions("worldedit.drain")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void drain(CommandContext args, LocalSession session, LocalPlayer player, public void drain(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
double radius = Math.max(0, args.getDouble(0)); double radius = Math.max(0, args.getDouble(0));
we.checkMaxRadius(radius); we.checkMaxRadius(radius);
@ -140,8 +137,7 @@ public class UtilityCommands {
) )
@CommandPermissions("worldedit.fixlava") @CommandPermissions("worldedit.fixlava")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void fixLava(CommandContext args, LocalSession session, LocalPlayer player, public void fixLava(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
double radius = Math.max(0, args.getDouble(0)); double radius = Math.max(0, args.getDouble(0));
we.checkMaxRadius(radius); we.checkMaxRadius(radius);
@ -159,8 +155,7 @@ public class UtilityCommands {
) )
@CommandPermissions("worldedit.fixwater") @CommandPermissions("worldedit.fixwater")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void fixWater(CommandContext args, LocalSession session, LocalPlayer player, public void fixWater(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
double radius = Math.max(0, args.getDouble(0)); double radius = Math.max(0, args.getDouble(0));
we.checkMaxRadius(radius); we.checkMaxRadius(radius);
@ -178,8 +173,7 @@ public class UtilityCommands {
) )
@CommandPermissions("worldedit.removeabove") @CommandPermissions("worldedit.removeabove")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void removeAbove(CommandContext args, LocalSession session, LocalPlayer player, public void removeAbove(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1; int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
we.checkMaxRadius(size); we.checkMaxRadius(size);
@ -200,8 +194,7 @@ public class UtilityCommands {
) )
@CommandPermissions("worldedit.removebelow") @CommandPermissions("worldedit.removebelow")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void removeBelow(CommandContext args, LocalSession session, LocalPlayer player, public void removeBelow(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1; int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
we.checkMaxRadius(size); we.checkMaxRadius(size);
@ -221,8 +214,7 @@ public class UtilityCommands {
) )
@CommandPermissions("worldedit.removenear") @CommandPermissions("worldedit.removenear")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void removeNear(CommandContext args, LocalSession session, LocalPlayer player, public void removeNear(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
BaseBlock block = we.getBlock(player, args.getString(0), true); BaseBlock block = we.getBlock(player, args.getString(0), true);
int size = Math.max(1, args.getInteger(1, 50)); int size = Math.max(1, args.getInteger(1, 50));
@ -242,8 +234,7 @@ public class UtilityCommands {
) )
@CommandPermissions("worldedit.replacenear") @CommandPermissions("worldedit.replacenear")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void replaceNear(CommandContext args, LocalSession session, LocalPlayer player, public void replaceNear(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
int size = Math.max(1, args.getInteger(0)); int size = Math.max(1, args.getInteger(0));
int affected; int affected;
@ -279,8 +270,7 @@ public class UtilityCommands {
) )
@CommandPermissions("worldedit.snow") @CommandPermissions("worldedit.snow")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void snow(CommandContext args, LocalSession session, LocalPlayer player, public void snow(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
double size = args.argsLength() > 0 ? Math.max(1, args.getDouble(0)) : 10; double size = args.argsLength() > 0 ? Math.max(1, args.getDouble(0)) : 10;
@ -297,8 +287,7 @@ public class UtilityCommands {
) )
@CommandPermissions("worldedit.thaw") @CommandPermissions("worldedit.thaw")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void thaw(CommandContext args, LocalSession session, LocalPlayer player, public void thaw(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
double size = args.argsLength() > 0 ? Math.max(1, args.getDouble(0)) : 10; double size = args.argsLength() > 0 ? Math.max(1, args.getDouble(0)) : 10;
@ -316,8 +305,7 @@ public class UtilityCommands {
) )
@CommandPermissions("worldedit.green") @CommandPermissions("worldedit.green")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void green(CommandContext args, LocalSession session, LocalPlayer player, public void green(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
final double size = args.argsLength() > 0 ? Math.max(1, args.getDouble(0)) : 10; final double size = args.argsLength() > 0 ? Math.max(1, args.getDouble(0)) : 10;
final boolean onlyNormalDirt = !args.hasFlag('f'); final boolean onlyNormalDirt = !args.hasFlag('f');
@ -335,8 +323,7 @@ public class UtilityCommands {
) )
@CommandPermissions("worldedit.extinguish") @CommandPermissions("worldedit.extinguish")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void extinguish(CommandContext args, LocalSession session, LocalPlayer player, public void extinguish(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();

View File

@ -23,6 +23,7 @@ import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extension.platform.Platform;
@ -87,8 +88,7 @@ public class WorldEditCommands {
min = 0, min = 0,
max = 0 max = 0
) )
public void cui(CommandContext args, LocalSession session, LocalPlayer player, public void cui(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
session.setCUISupport(true); session.setCUISupport(true);
session.dispatchCUISetup(player); session.dispatchCUISetup(player);
} }
@ -100,8 +100,7 @@ public class WorldEditCommands {
min = 1, min = 1,
max = 1 max = 1
) )
public void tz(CommandContext args, LocalSession session, LocalPlayer player, public void tz(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
TimeZone tz = TimeZone.getTimeZone(args.getString(0)); TimeZone tz = TimeZone.getTimeZone(args.getString(0));
session.setTimezone(tz); session.setTimezone(tz);
player.print("Timezone set for this session to: " + tz.getDisplayName()); player.print("Timezone set for this session to: " + tz.getDisplayName());

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.internal.command; package com.sk89q.worldedit.internal.command;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.input.ParserContext;
@ -29,8 +30,12 @@ import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.annotation.Direction; import com.sk89q.worldedit.internal.annotation.Direction;
import com.sk89q.worldedit.internal.annotation.Selection; import com.sk89q.worldedit.internal.annotation.Selection;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
import com.sk89q.worldedit.util.command.parametric.*; import com.sk89q.worldedit.util.command.parametric.*;
import java.util.Arrays;
/** /**
* Binds standard WorldEdit classes such as {@link Player} and {@link LocalSession}. * Binds standard WorldEdit classes such as {@link Player} and {@link LocalSession}.
*/ */
@ -137,22 +142,25 @@ public class WorldEditBinding extends BindingHelper {
} }
/** /**
* Gets an {@link Player} from a {@link ArgumentStack}. * Gets an {@link BaseBlock} from a {@link ArgumentStack}.
* *
* @param context the context * @param context the context
* @return a local player * @return a pattern
* @throws ParameterException on error * @throws ParameterException on error
* @throws WorldEditException on error
*/ */
@SuppressWarnings("deprecation") @BindingMatch(type = BaseBlock.class,
@BindingMatch(type = LocalPlayer.class, behavior = BindingBehavior.CONSUMES,
behavior = BindingBehavior.PROVIDES) consumedCount = 1)
public Player getLocalPlayer(ArgumentStack context) throws ParameterException { public BaseBlock getBaseBlock(ArgumentStack context) throws ParameterException, WorldEditException {
Player player = getPlayer(context); Actor actor = context.getContext().getLocals().get(Actor.class);
if (player instanceof LocalPlayer) { ParserContext parserContext = new ParserContext();
return (LocalPlayer) player; parserContext.setActor(context.getContext().getLocals().get(Actor.class));
} else { if (actor instanceof Entity) {
throw new ParameterException("This command/function needs to be updated to take 'Player' rather than 'LocalPlayer'"); parserContext.setWorld(((Entity) actor).getWorld());
} }
parserContext.setSession(worldEdit.getSessionManager().get(actor));
return worldEdit.getBlockRegistry().parseFromInput(context.next(), parserContext);
} }
/** /**
@ -218,4 +226,58 @@ public class WorldEditBinding extends BindingHelper {
return worldEdit.getDirection(sender, context.next()); return worldEdit.getDirection(sender, context.next());
} }
/**
* Gets an {@link TreeType} from a {@link ArgumentStack}.
*
* @param context the context
* @return a pattern
* @throws ParameterException on error
* @throws WorldEditException on error
*/
@BindingMatch(type = TreeType.class,
behavior = BindingBehavior.CONSUMES,
consumedCount = 1)
public TreeType getTreeType(ArgumentStack context) throws ParameterException, WorldEditException {
String input = context.next();
if (input != null) {
TreeType type = TreeGenerator.lookup(input);
if (type != null) {
return type;
} else {
throw new ParameterException(
String.format("Can't recognize tree type '%s' -- choose from: %s", input, Arrays.toString(TreeType.values())));
}
} else {
return TreeType.TREE;
}
}
/**
* Gets an {@link BiomeType} from a {@link ArgumentStack}.
*
* @param context the context
* @return a pattern
* @throws ParameterException on error
* @throws WorldEditException on error
*/
@BindingMatch(type = BiomeType.class,
behavior = BindingBehavior.CONSUMES,
consumedCount = 1)
public BiomeType getBiomeType(ArgumentStack context) throws ParameterException, WorldEditException {
String input = context.next();
if (input != null) {
BiomeType type = worldEdit.getServer().getBiomes().get(input);
if (type != null) {
return type;
} else {
throw new ParameterException(
String.format("Can't recognize biome type '%s' -- use //biomelist to list available types", input));
}
} else {
throw new ParameterException(
"This command takes a 'default' biome if one is not set, except there is no particular " +
"biome that should be 'default', so the command should not be taking a default biome");
}
}
} }

View File

@ -19,24 +19,18 @@
package com.sk89q.worldedit.scripting; package com.sk89q.worldedit.scripting;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.command.InsufficientArgumentsException;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.patterns.Pattern;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import com.sk89q.worldedit.DisallowedItemException;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.FilenameException;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.UnknownItemException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.command.InsufficientArgumentsException;
import com.sk89q.worldedit.patterns.Pattern;
/** /**
* The context given to scripts. * The context given to scripts.
@ -48,8 +42,8 @@ public class CraftScriptContext extends CraftScriptEnvironment {
private String[] args; private String[] args;
public CraftScriptContext(WorldEdit controller, public CraftScriptContext(WorldEdit controller,
ServerInterface server, LocalConfiguration config, Platform server, LocalConfiguration config,
LocalSession session, LocalPlayer player, String[] args) { LocalSession session, Player player, String[] args) {
super(controller, server, config, session, player); super(controller, server, config, session, player);
this.args = args; this.args = args;
} }
@ -74,7 +68,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
* *
* @return * @return
*/ */
public LocalPlayer getPlayer() { public Player getPlayer() {
return player; return player;
} }

View File

@ -20,24 +20,25 @@
package com.sk89q.worldedit.scripting; package com.sk89q.worldedit.scripting;
import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Platform;
public abstract class CraftScriptEnvironment { public abstract class CraftScriptEnvironment {
protected WorldEdit controller; protected WorldEdit controller;
protected LocalPlayer player; protected Player player;
protected LocalConfiguration config; protected LocalConfiguration config;
protected LocalSession session; protected LocalSession session;
protected ServerInterface server; protected Platform server;
public CraftScriptEnvironment(WorldEdit controller, ServerInterface server, public CraftScriptEnvironment(WorldEdit controller, Platform server, LocalConfiguration config, LocalSession session, Player player) {
LocalConfiguration config, LocalSession session, LocalPlayer player) {
this.controller = controller; this.controller = controller;
this.player = player; this.player = player;
this.config = config; this.config = config;
this.server = server; this.server = server;
this.session = session; this.session = session;
} }
} }