mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 10:56:42 +00:00
More file moving.
This commit is contained in:
233
src/main/java/com/sk89q/worldedit/commands/BrushCommands.java
Normal file
233
src/main/java/com/sk89q/worldedit/commands/BrushCommands.java
Normal file
@ -0,0 +1,233 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.commands;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.CuboidClipboard;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.masks.BlockTypeMask;
|
||||
import com.sk89q.worldedit.patterns.Pattern;
|
||||
import com.sk89q.worldedit.patterns.SingleBlockPattern;
|
||||
import com.sk89q.worldedit.tools.BrushTool;
|
||||
import com.sk89q.worldedit.tools.brushes.ClipboardBrush;
|
||||
import com.sk89q.worldedit.tools.brushes.CylinderBrush;
|
||||
import com.sk89q.worldedit.tools.brushes.HollowCylinderBrush;
|
||||
import com.sk89q.worldedit.tools.brushes.HollowSphereBrush;
|
||||
import com.sk89q.worldedit.tools.brushes.SmoothBrush;
|
||||
import com.sk89q.worldedit.tools.brushes.SphereBrush;
|
||||
|
||||
/**
|
||||
* Brush shape commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class BrushCommands {
|
||||
@Command(
|
||||
aliases = {"sphere", "s"},
|
||||
usage = "<block> [radius]",
|
||||
flags = "h",
|
||||
desc = "Choose the sphere brush",
|
||||
min = 1,
|
||||
max = 2
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.sphere"})
|
||||
public static void sphereBrush(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
int radius = args.argsLength() > 1 ? args.getInteger(1) : 2;
|
||||
if (radius > config.maxBrushRadius) {
|
||||
player.printError("Maximum allowed brush radius: "
|
||||
+ config.maxBrushRadius);
|
||||
return;
|
||||
}
|
||||
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
Pattern fill = we.getBlockPattern(player, args.getString(0));
|
||||
tool.setFill(fill);
|
||||
tool.setSize(radius);
|
||||
|
||||
if (args.hasFlag('h')) {
|
||||
tool.setBrush(new HollowSphereBrush());
|
||||
} else {
|
||||
tool.setBrush(new SphereBrush());
|
||||
}
|
||||
|
||||
player.print(String.format("Sphere brush shape equipped (%d).",
|
||||
radius));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"cylinder", "cyl", "c"},
|
||||
usage = "<block> [radius] [height]",
|
||||
flags = "h",
|
||||
desc = "Choose the cylinder brush",
|
||||
min = 1,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.cylinder"})
|
||||
public static void cylinderBrush(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
int radius = args.argsLength() > 1 ? args.getInteger(1) : 2;
|
||||
if (radius > config.maxBrushRadius) {
|
||||
player.printError("Maximum allowed brush radius: "
|
||||
+ config.maxBrushRadius);
|
||||
return;
|
||||
}
|
||||
|
||||
int height = args.argsLength() > 2 ? args.getInteger(2) : 1;
|
||||
if (height > config.maxBrushRadius) {
|
||||
player.printError("Maximum allowed brush radius/height: "
|
||||
+ config.maxBrushRadius);
|
||||
return;
|
||||
}
|
||||
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
Pattern fill = we.getBlockPattern(player, args.getString(0));
|
||||
tool.setFill(fill);
|
||||
tool.setSize(radius);
|
||||
|
||||
if (args.hasFlag('h')) {
|
||||
tool.setBrush(new HollowCylinderBrush(height));
|
||||
} else {
|
||||
tool.setBrush(new CylinderBrush(height));
|
||||
}
|
||||
|
||||
player.print(String.format("Cylinder brush shape equipped (%d by %d).",
|
||||
radius, height));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"clipboard", "copy"},
|
||||
usage = "",
|
||||
flags = "a",
|
||||
desc = "Choose the clipboard brush",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.clipboard"})
|
||||
public static void clipboardBrush(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
CuboidClipboard clipboard = session.getClipboard();
|
||||
|
||||
if (clipboard == null) {
|
||||
player.printError("Copy something first.");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector size = clipboard.getSize();
|
||||
|
||||
if (size.getBlockX() > config.maxBrushRadius
|
||||
|| size.getBlockY() > config.maxBrushRadius
|
||||
|| size.getBlockZ() > config.maxBrushRadius) {
|
||||
player.printError("Maximum allowed brush radius/height: "
|
||||
+ config.maxBrushRadius);
|
||||
return;
|
||||
}
|
||||
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
tool.setBrush(new ClipboardBrush(clipboard, args.hasFlag('a')));
|
||||
|
||||
player.print("Clipboard brush shape equipped.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"smooth"},
|
||||
usage = "[size] [iterations]",
|
||||
desc = "Choose the terrain softener brush",
|
||||
min = 0,
|
||||
max = 2
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.smooth"})
|
||||
public static void smoothBrush(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
int radius = args.argsLength() > 0 ? args.getInteger(0) : 2;
|
||||
if (radius > config.maxBrushRadius) {
|
||||
player.printError("Maximum allowed brush radius: "
|
||||
+ config.maxBrushRadius);
|
||||
return;
|
||||
}
|
||||
|
||||
int iterations = args.argsLength() > 1 ? args.getInteger(1) : 4;
|
||||
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
tool.setSize(radius);
|
||||
tool.setBrush(new SmoothBrush(iterations));
|
||||
|
||||
player.print(String.format("Smooth brush equipped (%d x %dx).",
|
||||
radius, iterations));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"ex", "extinguish"},
|
||||
usage = "[radius]",
|
||||
desc = "Shortcut fire extinguisher brush",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.ex"})
|
||||
public static void extinguishBrush(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
int radius = args.argsLength() > 1 ? args.getInteger(1) : 5;
|
||||
if (radius > config.maxBrushRadius) {
|
||||
player.printError("Maximum allowed brush radius: "
|
||||
+ config.maxBrushRadius);
|
||||
return;
|
||||
}
|
||||
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
Pattern fill = new SingleBlockPattern(new BaseBlock(0));
|
||||
tool.setFill(fill);
|
||||
tool.setSize(radius);
|
||||
tool.setMask(new BlockTypeMask(BlockID.FIRE));
|
||||
tool.setBrush(new SphereBrush());
|
||||
|
||||
player.print(String.format("Extinguisher equipped (%d).",
|
||||
radius));
|
||||
}
|
||||
}
|
165
src/main/java/com/sk89q/worldedit/commands/ChunkCommands.java
Normal file
165
src/main/java/com/sk89q/worldedit/commands/ChunkCommands.java
Normal file
@ -0,0 +1,165 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.commands;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Set;
|
||||
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.data.LegacyChunkStore;
|
||||
import com.sk89q.worldedit.data.McRegionChunkStore;
|
||||
|
||||
/**
|
||||
* Chunk tools.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ChunkCommands {
|
||||
@Command(
|
||||
aliases = {"chunkinfo"},
|
||||
usage = "",
|
||||
desc = "Get information about the chunk that you are inside",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.chunkinfo"})
|
||||
public static void chunkInfo(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Vector pos = player.getBlockIn();
|
||||
int chunkX = (int)Math.floor(pos.getBlockX() / 16.0);
|
||||
int chunkZ = (int)Math.floor(pos.getBlockZ() / 16.0);
|
||||
|
||||
String folder1 = Integer.toString(WorldEdit.divisorMod(chunkX, 64), 36);
|
||||
String folder2 = Integer.toString(WorldEdit.divisorMod(chunkZ, 64), 36);
|
||||
String filename = "c." + Integer.toString(chunkX, 36)
|
||||
+ "." + Integer.toString(chunkZ, 36) + ".dat";
|
||||
|
||||
player.print("Chunk: " + chunkX + ", " + chunkZ);
|
||||
player.print("Old format: " + folder1 + "/" + folder2 + "/" + filename);
|
||||
player.print("McRegion: region/" + McRegionChunkStore.getFilename(
|
||||
new Vector2D(chunkX, chunkZ)));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"listchunks"},
|
||||
usage = "",
|
||||
desc = "List chunks that your selection includes",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.listchunks"})
|
||||
public static void listChunks(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Set<Vector2D> chunks = session.getSelection(player.getWorld()).getChunks();
|
||||
|
||||
for (Vector2D chunk : chunks) {
|
||||
player.print(LegacyChunkStore.getFilename(chunk));
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"delchunks"},
|
||||
usage = "",
|
||||
desc = "Delete chunks that your selection includes",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.delchunks"})
|
||||
public static void deleteChunks(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
Set<Vector2D> chunks = session.getSelection(player.getWorld()).getChunks();
|
||||
FileOutputStream out = null;
|
||||
|
||||
if (config.shellSaveType == null) {
|
||||
player.printError("Shell script type must be configured: 'bat' or 'bash' expected.");
|
||||
} else if (config.shellSaveType.equalsIgnoreCase("bat")) {
|
||||
try {
|
||||
out = new FileOutputStream("worldedit-delchunks.bat");
|
||||
OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
|
||||
writer.write("@ECHO off\r\n");
|
||||
writer.write("ECHO This batch file was generated by WorldEdit.\r\n");
|
||||
writer.write("ECHO It contains a list of chunks that were in the selected region\r\n");
|
||||
writer.write("ECHO at the time that the /delchunks command was used. Run this file\r\n");
|
||||
writer.write("ECHO in order to delete the chunk files listed in this file.\r\n");
|
||||
writer.write("ECHO.\r\n");
|
||||
writer.write("PAUSE\r\n");
|
||||
|
||||
for (Vector2D chunk : chunks) {
|
||||
String filename = LegacyChunkStore.getFilename(chunk);
|
||||
writer.write("ECHO " + filename + "\r\n");
|
||||
writer.write("DEL \"world/" + filename + "\"\r\n");
|
||||
}
|
||||
|
||||
writer.write("ECHO Complete.\r\n");
|
||||
writer.write("PAUSE\r\n");
|
||||
writer.close();
|
||||
player.print("worldedit-delchunks.bat written. Run it when no one is near the region.");
|
||||
} catch (IOException e) {
|
||||
player.printError("Error occurred: " + e.getMessage());
|
||||
} finally {
|
||||
if (out != null) {
|
||||
try { out.close(); } catch (IOException ie) {}
|
||||
}
|
||||
}
|
||||
} else if (config.shellSaveType.equalsIgnoreCase("bash")) {
|
||||
try {
|
||||
out = new FileOutputStream("worldedit-delchunks.sh");
|
||||
OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
|
||||
writer.write("#!/bin/bash\n");
|
||||
writer.write("echo This shell file was generated by WorldEdit.\n");
|
||||
writer.write("echo It contains a list of chunks that were in the selected region\n");
|
||||
writer.write("echo at the time that the /delchunks command was used. Run this file\n");
|
||||
writer.write("echo in order to delete the chunk files listed in this file.\n");
|
||||
writer.write("echo\n");
|
||||
writer.write("read -p \"Press any key to continue...\"\n");
|
||||
|
||||
for (Vector2D chunk : chunks) {
|
||||
String filename = LegacyChunkStore.getFilename(chunk);
|
||||
writer.write("echo " + filename + "\n");
|
||||
writer.write("rm \"world/" + filename + "\"\n");
|
||||
}
|
||||
|
||||
writer.write("echo Complete.\n");
|
||||
writer.write("read -p \"Press any key to continue...\"\n");
|
||||
writer.close();
|
||||
player.print("worldedit-delchunks.sh written. Run it when no one is near the region.");
|
||||
player.print("You will have to chmod it to be executable.");
|
||||
} catch (IOException e) {
|
||||
player.printError("Error occurred: " + e.getMessage());
|
||||
} finally {
|
||||
if (out != null) {
|
||||
try { out.close(); } catch (IOException ie) {}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player.printError("Shell script type must be configured: 'bat' or 'bash' expected.");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,265 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.data.DataException;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
/**
|
||||
* Clipboard commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ClipboardCommands {
|
||||
@Command(
|
||||
aliases = {"/copy"},
|
||||
usage = "",
|
||||
desc = "Copy the selection to the clipboard",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.clipboard.copy"})
|
||||
public static void copy(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
Vector min = region.getMinimumPoint();
|
||||
Vector max = region.getMaximumPoint();
|
||||
Vector pos = player.getBlockIn();
|
||||
|
||||
CuboidClipboard clipboard = new CuboidClipboard(
|
||||
max.subtract(min).add(new Vector(1, 1, 1)),
|
||||
min, min.subtract(pos));
|
||||
clipboard.copy(editSession);
|
||||
session.setClipboard(clipboard);
|
||||
|
||||
player.print("Block(s) copied.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/cut"},
|
||||
usage = "[leave-id]",
|
||||
desc = "Cut the selection to the clipboard",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.clipboard.cut"})
|
||||
public static void cut(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
BaseBlock block = new BaseBlock(0);
|
||||
|
||||
if (args.argsLength() > 0) {
|
||||
block = we.getBlock(player, args.getString(0));
|
||||
}
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
Vector min = region.getMinimumPoint();
|
||||
Vector max = region.getMaximumPoint();
|
||||
Vector pos = player.getBlockIn();
|
||||
|
||||
CuboidClipboard clipboard = new CuboidClipboard(
|
||||
max.subtract(min).add(new Vector(1, 1, 1)),
|
||||
min, min.subtract(pos));
|
||||
clipboard.copy(editSession);
|
||||
session.setClipboard(clipboard);
|
||||
|
||||
editSession.setBlocks(session.getSelection(player.getWorld()), block);
|
||||
player.print("Block(s) cut.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/paste"},
|
||||
usage = "",
|
||||
flags = "ao",
|
||||
desc = "Paste the clipboard's contents",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.clipboard.paste"})
|
||||
public static void paste(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
boolean atOrigin = args.hasFlag('o');
|
||||
boolean pasteNoAir = args.hasFlag('a');
|
||||
|
||||
if (atOrigin) {
|
||||
Vector pos = session.getClipboard().getOrigin();
|
||||
session.getClipboard().place(editSession, pos, pasteNoAir);
|
||||
player.findFreePosition();
|
||||
player.print("Pasted to copy origin. Undo with //undo");
|
||||
} else {
|
||||
Vector pos = session.getPlacementPosition(player);
|
||||
session.getClipboard().paste(editSession, pos, pasteNoAir);
|
||||
player.findFreePosition();
|
||||
player.print("Pasted relative to you. Undo with //undo");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/rotate"},
|
||||
usage = "<angle-in-degrees>",
|
||||
desc = "Rotate the contents of the clipboard",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.clipboard.rotate"})
|
||||
public static void rotate(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int angle = args.getInteger(0);
|
||||
|
||||
if (angle % 90 == 0) {
|
||||
CuboidClipboard clipboard = session.getClipboard();
|
||||
clipboard.rotate2D(angle);
|
||||
player.print("Clipboard rotated by " + angle + " degrees.");
|
||||
} else {
|
||||
player.printError("Angles must be divisible by 90 degrees.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/flip"},
|
||||
usage = "[dir]",
|
||||
desc = "Flip the contents of the clipboard",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.clipboard.flip"})
|
||||
public static void flip(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
CuboidClipboard.FlipDirection dir = we.getFlipDirection(player,
|
||||
args.argsLength() > 0 ? args.getString(0).toLowerCase() : "me");
|
||||
|
||||
CuboidClipboard clipboard = session.getClipboard();
|
||||
clipboard.flip(dir);
|
||||
player.print("Clipboard flipped.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/load"},
|
||||
usage = "<filename>",
|
||||
desc = "Load a schematic into your clipboard",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.clipboard.load"})
|
||||
public static void load(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
String filename = args.getString(0);
|
||||
File dir = we.getWorkingDirectoryFile(config.saveDir);
|
||||
File f = we.getSafeOpenFile(player, dir, filename, "schematic",
|
||||
new String[] {"schematic"});
|
||||
|
||||
try {
|
||||
String filePath = f.getCanonicalPath();
|
||||
String dirPath = dir.getCanonicalPath();
|
||||
|
||||
if (!filePath.substring(0, dirPath.length()).equals(dirPath)) {
|
||||
player.printError("Schematic could not read or it does not exist.");
|
||||
} else {
|
||||
session.setClipboard(CuboidClipboard.loadSchematic(f));
|
||||
WorldEdit.logger.info(player.getName() + " loaded " + filePath);
|
||||
player.print(filename + " loaded. Paste it with //paste");
|
||||
}
|
||||
} catch (DataException e) {
|
||||
player.printError("Load error: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
player.printError("Schematic could not read or it does not exist: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/save"},
|
||||
usage = "<filename>",
|
||||
desc = "Save a schematic into your clipboard",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.clipboard.save"})
|
||||
public static void save(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
String filename = args.getString(0);
|
||||
|
||||
File dir = we.getWorkingDirectoryFile(config.saveDir);
|
||||
File f = we.getSafeSaveFile(player, dir, filename, "schematic",
|
||||
new String[] {"schematic"});
|
||||
|
||||
if (!dir.exists()) {
|
||||
if (!dir.mkdir()) {
|
||||
player.printError("The storage folder could not be created.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Create parent directories
|
||||
File parent = f.getParentFile();
|
||||
if (parent != null && !parent.exists()) {
|
||||
parent.mkdirs();
|
||||
}
|
||||
|
||||
session.getClipboard().saveSchematic(f);
|
||||
WorldEdit.logger.info(player.getName() + " saved " + f.getCanonicalPath());
|
||||
player.print(filename + " saved.");
|
||||
} catch (DataException se) {
|
||||
player.printError("Save error: " + se.getMessage());
|
||||
} catch (IOException e) {
|
||||
player.printError("Schematic could not written: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"clearclipboard"},
|
||||
usage = "",
|
||||
desc = "Clear your clipboard",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.clipboard.clear"})
|
||||
public static void clearClipboard(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
session.setClipboard(null);
|
||||
player.print("Clipboard cleared.");
|
||||
}
|
||||
}
|
167
src/main/java/com/sk89q/worldedit/commands/GeneralCommands.java
Normal file
167
src/main/java/com/sk89q/worldedit/commands/GeneralCommands.java
Normal file
@ -0,0 +1,167 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.commands;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.minecraft.util.commands.NestedCommand;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
|
||||
/**
|
||||
* General WorldEdit commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class GeneralCommands {
|
||||
@Command(
|
||||
aliases = {"/limit"},
|
||||
usage = "<limit>",
|
||||
desc = "Modify block change limit",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.limit"})
|
||||
public static void limit(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
int limit = Math.max(-1, args.getInteger(0));
|
||||
if (!player.hasPermission("worldedit.limit.unrestricted")
|
||||
&& config.maxChangeLimit > -1) {
|
||||
if (limit > config.maxChangeLimit) {
|
||||
player.printError("Your maximum allowable limit is "
|
||||
+ config.maxChangeLimit + ".");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
session.setBlockChangeLimit(limit);
|
||||
player.print("Block change limit set to " + limit + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"toggleplace"},
|
||||
usage = "",
|
||||
desc = "",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
public static void togglePlace(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
if (session.togglePlacementPosition()) {
|
||||
player.print("Now placing at pos #1.");
|
||||
} else {
|
||||
player.print("Now placing at the block you stand in.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"searchitem", "/l", "search"},
|
||||
usage = "<query>",
|
||||
flags = "bi",
|
||||
desc = "Search for an item",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
public static void searchItem(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
String query = args.getString(0).trim().toLowerCase();
|
||||
boolean blocksOnly = args.hasFlag('b');
|
||||
boolean itemsOnly = args.hasFlag('i');
|
||||
|
||||
try {
|
||||
int id = Integer.parseInt(query);
|
||||
|
||||
ItemType type = ItemType.fromID(id);
|
||||
|
||||
if (type != null) {
|
||||
player.print("#" + type.getID() + " (" + type.getName() + ")");
|
||||
} else {
|
||||
player.printError("No item found by ID " + id);
|
||||
}
|
||||
|
||||
return;
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
|
||||
if (query.length() <= 2) {
|
||||
player.printError("Enter a longer search string (len > 2).");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!blocksOnly && !itemsOnly) {
|
||||
player.print("Searching for: " + query);
|
||||
} else if (blocksOnly && itemsOnly) {
|
||||
player.printError("You cannot use both the 'b' and 'i' flags simultaneously.");
|
||||
return;
|
||||
} else if (blocksOnly) {
|
||||
player.print("Searching for blocks: " + query);
|
||||
} else {
|
||||
player.print("Searching for items: " + query);
|
||||
}
|
||||
|
||||
int found = 0;
|
||||
|
||||
for (ItemType type : ItemType.values()) {
|
||||
if (found >= 15) {
|
||||
player.print("Too many results!");
|
||||
break;
|
||||
}
|
||||
|
||||
if (blocksOnly && type.getID() > 255) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (itemsOnly && type.getID() <= 255) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (String alias : type.getAliases()) {
|
||||
if (alias.contains(query)) {
|
||||
player.print("#" + type.getID() + " (" + type.getName() + ")");
|
||||
found++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (found == 0) {
|
||||
player.printError("No items found.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"we", "worldedit"},
|
||||
desc = "WorldEdit commands"
|
||||
)
|
||||
@NestedCommand({WorldEditCommands.class})
|
||||
public static void we(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
}
|
||||
}
|
@ -0,0 +1,181 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.commands;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.patterns.Pattern;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
|
||||
/**
|
||||
* Generation commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class GenerationCommands {
|
||||
@Command(
|
||||
aliases = {"/hcyl"},
|
||||
usage = "<block> <radius> [height] ",
|
||||
desc = "Generate a hollow cylinder",
|
||||
min = 2,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.generation.cylinder"})
|
||||
public static void hcyl(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Pattern block = we.getBlockPattern(player, args.getString(0));
|
||||
int radius = Math.max(1, args.getInteger(1));
|
||||
int height = args.argsLength() > 2 ? args.getInteger(2) : 1;
|
||||
|
||||
Vector pos = session.getPlacementPosition(player);
|
||||
int affected = editSession.makeHollowCylinder(pos, block, radius, height);
|
||||
player.print(affected + " block(s) have been created.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/cyl"},
|
||||
usage = "<block> <radius> [height] ",
|
||||
desc = "Generate a cylinder",
|
||||
min = 2,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.generation.cylinder"})
|
||||
public static void cyl(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Pattern block = we.getBlockPattern(player, args.getString(0));
|
||||
int radius = Math.max(1, args.getInteger(1));
|
||||
int height = args.argsLength() > 2 ? args.getInteger(2) : 1;
|
||||
|
||||
Vector pos = session.getPlacementPosition(player);
|
||||
int affected = editSession.makeCylinder(pos, block, radius, height);
|
||||
player.print(affected + " block(s) have been created.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/hsphere"},
|
||||
usage = "<block> <radius> [raised?] ",
|
||||
desc = "Generate a hollow sphere",
|
||||
min = 2,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.generation.sphere"})
|
||||
public static void hsphere(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Pattern block = we.getBlockPattern(player, args.getString(0));
|
||||
int radius = Math.max(1, args.getInteger(1));
|
||||
boolean raised = args.argsLength() > 2
|
||||
? (args.getString(2).equalsIgnoreCase("true")
|
||||
|| args.getString(2).equalsIgnoreCase("yes"))
|
||||
: false;
|
||||
|
||||
Vector pos = session.getPlacementPosition(player);
|
||||
if (raised) {
|
||||
pos = pos.add(0, radius, 0);
|
||||
}
|
||||
|
||||
int affected = editSession.makeSphere(pos, block, radius, false);
|
||||
player.findFreePosition();
|
||||
player.print(affected + " block(s) have been created.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/sphere"},
|
||||
usage = "<block> <radius> [raised?] ",
|
||||
desc = "Generate a filled sphere",
|
||||
min = 2,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.generation.sphere"})
|
||||
public static void sphere(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Pattern block = we.getBlockPattern(player, args.getString(0));
|
||||
int radius = Math.max(1, args.getInteger(1));
|
||||
boolean raised = args.argsLength() > 2
|
||||
? (args.getString(2).equalsIgnoreCase("true")
|
||||
|| args.getString(2).equalsIgnoreCase("yes"))
|
||||
: false;
|
||||
|
||||
Vector pos = session.getPlacementPosition(player);
|
||||
if (raised) {
|
||||
pos = pos.add(0, radius, 0);
|
||||
}
|
||||
|
||||
int affected = editSession.makeSphere(pos, block, radius, true);
|
||||
player.findFreePosition();
|
||||
player.print(affected + " block(s) have been created.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"forestgen"},
|
||||
usage = "[size] [type] [density]",
|
||||
desc = "Generate a forest",
|
||||
min = 0,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.generation.forest"})
|
||||
public static void forestGen(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
|
||||
TreeGenerator.TreeType type = args.argsLength() > 1 ?
|
||||
type = 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;
|
||||
} else {
|
||||
}
|
||||
|
||||
int affected = editSession.makeForest(player.getPosition(),
|
||||
size, density, new TreeGenerator(type));
|
||||
player.print(affected + " trees created.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"pumpkins"},
|
||||
usage = "[size]",
|
||||
desc = "Generate pumpkin patches",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.generation.pumpkins"})
|
||||
public static void pumpkins(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
|
||||
|
||||
int affected = editSession.makePumpkinPatches(player.getPosition(), size);
|
||||
player.print(affected + " pumpkin patches created.");
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.commands;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
|
||||
/**
|
||||
* History little commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class HistoryCommands {
|
||||
@Command(
|
||||
aliases = {"/undo", "undo"},
|
||||
usage = "[times]",
|
||||
desc = "Undoes the last action",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.history.undo"})
|
||||
public static void undo(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int times = Math.max(1, args.getInteger(0, 1));
|
||||
|
||||
for (int i = 0; i < times; i++) {
|
||||
EditSession undone = session.undo(session.getBlockBag(player));
|
||||
if (undone != null) {
|
||||
player.print("Undo successful.");
|
||||
we.flushBlockBag(player, undone);
|
||||
} else {
|
||||
player.printError("Nothing left to undo.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/redo", "redo"},
|
||||
usage = "[times]",
|
||||
desc = "Redoes the last action (from history)",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.history.redo"})
|
||||
public static void redo(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int times = Math.max(1, args.getInteger(0, 1));
|
||||
|
||||
for (int i = 0; i < times; i++) {
|
||||
EditSession redone = session.redo(session.getBlockBag(player));
|
||||
if (redone != null) {
|
||||
player.print("Redo successful.");
|
||||
we.flushBlockBag(player, redone);
|
||||
} else {
|
||||
player.printError("Nothing left to redo.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"clearhistory"},
|
||||
usage = "",
|
||||
desc = "Clear your history",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.history.clear"})
|
||||
public static void clearHistory(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
session.clearHistory();
|
||||
player.print("History cleared.");
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.commands;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class InsufficientArgumentsException extends WorldEditException {
|
||||
private static final long serialVersionUID = 995264804658899764L;
|
||||
|
||||
public InsufficientArgumentsException(String error) {
|
||||
super(error);
|
||||
}
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.commands;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
|
||||
/**
|
||||
* Navigation commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class NavigationCommands {
|
||||
@Command(
|
||||
aliases = {"unstuck"},
|
||||
usage = "",
|
||||
desc = "Escape from being stuck inside a block",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.navigation.unstuck"})
|
||||
public static void unstuck(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
player.print("There you go!");
|
||||
player.findFreePosition();
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"ascend"},
|
||||
usage = "",
|
||||
desc = "Go up a floor",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.navigation.ascend"})
|
||||
public static void ascend(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
if (player.ascendLevel()) {
|
||||
player.print("Ascended a level.");
|
||||
} else {
|
||||
player.printError("No free spot above you found.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"descend"},
|
||||
usage = "",
|
||||
desc = "Go down a floor",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.navigation.descend"})
|
||||
public static void descend(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
if (player.descendLevel()) {
|
||||
player.print("Descended a level.");
|
||||
} else {
|
||||
player.printError("No free spot below you found.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"ceil"},
|
||||
usage = "[clearance]",
|
||||
desc = "Go to the celing",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.navigation.ceiling"})
|
||||
public static void ceiling(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int clearence = args.argsLength() > 0 ?
|
||||
Math.max(0, args.getInteger(0)) : 0;
|
||||
|
||||
if (player.ascendToCeiling(clearence)) {
|
||||
player.print("Whoosh!");
|
||||
} else {
|
||||
player.printError("No free spot above you found.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"thru"},
|
||||
usage = "",
|
||||
desc = "Passthrough walls",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.navigation.thru"})
|
||||
public static void thru(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
if (player.passThroughForwardWall(6)) {
|
||||
player.print("Whoosh!");
|
||||
} else {
|
||||
player.printError("No free spot ahead of you found.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"jumpto"},
|
||||
usage = "",
|
||||
desc = "Teleport to a location",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.navigation.jumpto"})
|
||||
public static void jumpTo(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
WorldVector pos = player.getSolidBlockTrace(300);
|
||||
if (pos != null) {
|
||||
player.findFreePosition(pos);
|
||||
player.print("Poof!");
|
||||
} else {
|
||||
player.printError("No block in sight!");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"up"},
|
||||
usage = "<block>",
|
||||
desc = "Go upwards some distance",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.navigation.up"})
|
||||
public static void up(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int distance = args.getInteger(0);
|
||||
|
||||
if (player.ascendUpwards(distance)) {
|
||||
player.print("Whoosh!");
|
||||
} else {
|
||||
player.printError("You would hit something above you.");
|
||||
}
|
||||
}
|
||||
}
|
250
src/main/java/com/sk89q/worldedit/commands/RegionCommands.java
Normal file
250
src/main/java/com/sk89q/worldedit/commands/RegionCommands.java
Normal file
@ -0,0 +1,250 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.commands;
|
||||
|
||||
import java.util.Set;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.filtering.GaussianKernel;
|
||||
import com.sk89q.worldedit.filtering.HeightMapFilter;
|
||||
import com.sk89q.worldedit.patterns.*;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
/**
|
||||
* Region related commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class RegionCommands {
|
||||
@Command(
|
||||
aliases = {"/set"},
|
||||
usage = "<block>",
|
||||
desc = "Set all the blocks inside the selection to a block",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.region.set"})
|
||||
public static void set(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/replace"},
|
||||
usage = "[from-block] <to-block>",
|
||||
desc = "Replace all blocks in the selection with another",
|
||||
min = 1,
|
||||
max = 2
|
||||
)
|
||||
@CommandPermissions({"worldedit.region.replace"})
|
||||
public static void replace(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Set<Integer> from;
|
||||
Pattern to;
|
||||
if (args.argsLength() == 1) {
|
||||
from = null;
|
||||
to = we.getBlockPattern(player, args.getString(0));
|
||||
} else {
|
||||
from = we.getBlockIDs(player, args.getString(0), true);
|
||||
to = we.getBlockPattern(player, args.getString(1));
|
||||
}
|
||||
|
||||
int affected = 0;
|
||||
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.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/overlay"},
|
||||
usage = "<block>",
|
||||
desc = "Set a block on top of blocks in the region",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.region.overlay"})
|
||||
public static void overlay(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
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(
|
||||
aliases = {"/walls"},
|
||||
usage = "<block>",
|
||||
desc = "Build the four sides of the selection",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.region.walls"})
|
||||
public static void walls(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
BaseBlock block = we.getBlock(player, args.getString(0));
|
||||
int affected = editSession.makeCuboidWalls(session.getSelection(player.getWorld()), block);
|
||||
|
||||
player.print(affected + " block(s) have been changed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/faces", "/outline"},
|
||||
usage = "<block>",
|
||||
desc = "Build the walls, ceiling, and roof of a selection",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.region.faces"})
|
||||
public static void faces(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
BaseBlock block = we.getBlock(player, args.getString(0));
|
||||
int affected = editSession.makeCuboidFaces(session.getSelection(player.getWorld()), block);
|
||||
player.print(affected + " block(s) have been changed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/smooth"},
|
||||
usage = "[iterations]",
|
||||
desc = "Smooth the elevation in the selection",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.region.smooth"})
|
||||
public static void smooth(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int iterations = 1;
|
||||
if (args.argsLength() > 0) {
|
||||
iterations = args.getInteger(0);
|
||||
}
|
||||
|
||||
HeightMap heightMap = new HeightMap(editSession, session.getSelection(player.getWorld()));
|
||||
HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
|
||||
int affected = heightMap.applyFilter(filter, iterations);
|
||||
player.print("Terrain's height map smoothed. " + affected + " block(s) changed.");
|
||||
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/move"},
|
||||
usage = "[count] [direction] [leave-id]",
|
||||
desc = "Move the contents of the selection",
|
||||
min = 0,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.region.move"})
|
||||
public static void move(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int count = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
|
||||
Vector dir = we.getDirection(player,
|
||||
args.argsLength() > 1 ? args.getString(1).toLowerCase() : "me");
|
||||
BaseBlock replace;
|
||||
|
||||
// Replacement block argument
|
||||
if (args.argsLength() > 2) {
|
||||
replace = we.getBlock(player, args.getString(2));
|
||||
} else {
|
||||
replace = new BaseBlock(0);
|
||||
}
|
||||
|
||||
int affected = editSession.moveCuboidRegion(session.getSelection(player.getWorld()),
|
||||
dir, count, true, replace);
|
||||
player.print(affected + " blocks moved.");
|
||||
}
|
||||
|
||||
|
||||
@Command(
|
||||
aliases = {"/stack"},
|
||||
usage = "[count] [direction]",
|
||||
flags = "a",
|
||||
desc = "Repeat the contents of the selection",
|
||||
min = 0,
|
||||
max = 2
|
||||
)
|
||||
@CommandPermissions({"worldedit.region.stack"})
|
||||
public static void stack(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int count = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
|
||||
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'));
|
||||
player.print(affected + " blocks changed. Undo with //undo");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/regen"},
|
||||
usage = "",
|
||||
desc = "Regenerates the contents of the selection",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.regen"})
|
||||
public static void regenerateChunk(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
player.getWorld().regenerate(region, editSession);
|
||||
player.print("Region regenerated.");
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.commands;
|
||||
|
||||
import java.io.File;
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* Scripting commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ScriptingCommands {
|
||||
@Command(
|
||||
aliases = {"cs"},
|
||||
usage = "<filename> [args...]",
|
||||
desc = "Execute a CraftScript",
|
||||
min = 1,
|
||||
max = -1
|
||||
)
|
||||
@CommandPermissions({"worldedit.scripting.execute"})
|
||||
public static void execute(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
// @TODO: Check for worldedit.scripting.execute.<script> permission
|
||||
|
||||
String[] scriptArgs = args.getSlice(1);
|
||||
|
||||
session.setLastScript(args.getString(0));
|
||||
|
||||
File dir = we.getWorkingDirectoryFile(we.getConfiguration().scriptsDir);
|
||||
File f = we.getSafeOpenFile(player, dir, args.getString(0), "js",
|
||||
new String[] {"js"});
|
||||
|
||||
we.runScript(player, f, scriptArgs);
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {".s"},
|
||||
usage = "[args...]",
|
||||
desc = "Execute last CraftScript",
|
||||
min = 0,
|
||||
max = -1
|
||||
)
|
||||
@CommandPermissions({"worldedit.scripting.execute"})
|
||||
public static void executeLast(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
// @TODO: Check for worldedit.scripting.execute.<script> permission
|
||||
|
||||
String lastScript = session.getLastScript();
|
||||
|
||||
if (lastScript == null) {
|
||||
player.printError("Use /cs with a script name first.");
|
||||
return;
|
||||
}
|
||||
|
||||
String[] scriptArgs = args.getSlice(0);
|
||||
|
||||
File dir = we.getWorkingDirectoryFile(we.getConfiguration().scriptsDir);
|
||||
File f = we.getSafeOpenFile(player, dir, lastScript, "js",
|
||||
new String[] {"js"});
|
||||
|
||||
we.runScript(player, f, scriptArgs);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,553 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.commands;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
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.data.ChunkStore;
|
||||
import com.sk89q.worldedit.regions.CuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.Polygonal2DRegionSelector;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionOperationException;
|
||||
import com.sk89q.worldedit.blocks.*;
|
||||
|
||||
/**
|
||||
* Selection commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class SelectionCommands {
|
||||
@Command(
|
||||
aliases = {"/pos1"},
|
||||
usage = "",
|
||||
desc = "Set position 1",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.pos"})
|
||||
public static void pos1(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
if (!session.getRegionSelector(player.getWorld())
|
||||
.selectPrimary(player.getBlockIn())) {
|
||||
player.printError("Position already set.");
|
||||
return;
|
||||
}
|
||||
|
||||
session.getRegionSelector(player.getWorld())
|
||||
.explainPrimarySelection(player, session, player.getBlockIn());
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/pos2"},
|
||||
usage = "",
|
||||
desc = "Set position 2",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.pos"})
|
||||
public static void pos2(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
if (!session.getRegionSelector(player.getWorld())
|
||||
.selectSecondary(player.getBlockIn())) {
|
||||
player.printError("Position already set.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
session.getRegionSelector(player.getWorld())
|
||||
.explainSecondarySelection(player, session, player.getBlockIn());
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/hpos1"},
|
||||
usage = "",
|
||||
desc = "Set position 1 to targeted block",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.hpos"})
|
||||
public static void hpos1(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Vector pos = player.getBlockTrace(300);
|
||||
|
||||
if (pos != null) {
|
||||
if (!session.getRegionSelector(player.getWorld())
|
||||
.selectPrimary(pos)) {
|
||||
player.printError("Position already set.");
|
||||
return;
|
||||
}
|
||||
|
||||
session.getRegionSelector(player.getWorld())
|
||||
.explainPrimarySelection(player, session, pos);
|
||||
} else {
|
||||
player.printError("No block in sight!");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/hpos2"},
|
||||
usage = "",
|
||||
desc = "Set position 2 to targeted block",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.hpos"})
|
||||
public static void hpos2(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Vector pos = player.getBlockTrace(300);
|
||||
|
||||
if (pos != null) {
|
||||
if (!session.getRegionSelector(player.getWorld())
|
||||
.selectSecondary(pos)) {
|
||||
player.printError("Position already set.");
|
||||
return;
|
||||
}
|
||||
|
||||
session.getRegionSelector(player.getWorld())
|
||||
.explainSecondarySelection(player, session, pos);
|
||||
} else {
|
||||
player.printError("No block in sight!");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/chunk"},
|
||||
usage = "",
|
||||
desc = "Set the selection to your current chunk",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.chunk"})
|
||||
public static void chunk(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Vector2D min2D = ChunkStore.toChunk(player.getBlockIn());
|
||||
Vector min = new Vector(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16);
|
||||
Vector max = min.add(15, 127, 15);
|
||||
|
||||
CuboidRegionSelector selector = new CuboidRegionSelector();
|
||||
selector.selectPrimary(min);
|
||||
selector.selectSecondary(max);
|
||||
session.setRegionSelector(player.getWorld(), selector);
|
||||
|
||||
session.dispatchCUISelection(player);
|
||||
|
||||
player.print("Chunk selected: "
|
||||
+ min2D.getBlockX() + ", " + min2D.getBlockZ());
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/wand"},
|
||||
usage = "",
|
||||
desc = "Get the wand object",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.wand"})
|
||||
public static void wand(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
player.giveItem(we.getConfiguration().wandItem, 1);
|
||||
player.print("Left click: select pos #1; Right click: select pos #2");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"toggleeditwand"},
|
||||
usage = "",
|
||||
desc = "Toggle functionality of the edit wand",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.wand.toggle"})
|
||||
public static void toggleWand(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
session.setToolControl(!session.isToolControlEnabled());
|
||||
|
||||
if (session.isToolControlEnabled()) {
|
||||
player.print("Edit wand enabled.");
|
||||
} else {
|
||||
player.print("Edit wand disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/expand"},
|
||||
usage = "<amount> [reverse-amount] <direction>",
|
||||
desc = "Expand the selection area",
|
||||
min = 1,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.expand"})
|
||||
public static void expand(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Vector dir;
|
||||
|
||||
// Special syntax (//expand vert) to expand the selection between
|
||||
// sky and bedrock.
|
||||
if (args.getString(0).equalsIgnoreCase("vert")
|
||||
|| args.getString(0).equalsIgnoreCase("vertical")) {
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
try {
|
||||
int oldSize = region.getArea();
|
||||
region.expand(new Vector(0, 128, 0));
|
||||
region.expand(new Vector(0, -128, 0));
|
||||
session.getRegionSelector().learnChanges();
|
||||
int newSize = region.getArea();
|
||||
player.print("Region expanded " + (newSize - oldSize)
|
||||
+ " blocks [top-to-bottom].");
|
||||
} catch (RegionOperationException e) {
|
||||
player.printError(e.getMessage());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int change = args.getInteger(0);
|
||||
int reverseChange = 0;
|
||||
|
||||
// Specifying a direction
|
||||
if (args.argsLength() == 2) {
|
||||
try {
|
||||
reverseChange = args.getInteger(1) * -1;
|
||||
dir = we.getDirection(player, "me");
|
||||
} catch (NumberFormatException e) {
|
||||
dir = we.getDirection(player,
|
||||
args.getString(1).toLowerCase());
|
||||
}
|
||||
// Specifying a direction and a reverse amount
|
||||
} else if (args.argsLength() == 3) {
|
||||
reverseChange = args.getInteger(1) * -1;
|
||||
dir = we.getDirection(player,
|
||||
args.getString(2).toLowerCase());
|
||||
} else {
|
||||
dir = we.getDirection(player, "me");
|
||||
}
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
int oldSize = region.getArea();
|
||||
region.expand(dir.multiply(change));
|
||||
|
||||
if (reverseChange != 0) {
|
||||
region.expand(dir.multiply(reverseChange));
|
||||
}
|
||||
|
||||
session.getRegionSelector().learnChanges();
|
||||
int newSize = region.getArea();
|
||||
|
||||
session.getRegionSelector().explainRegionAdjust(player, session);
|
||||
|
||||
player.print("Region expanded " + (newSize - oldSize) + " blocks.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/contract"},
|
||||
usage = "<amount> [reverse-amount] [direction]",
|
||||
desc = "Contract the selection area",
|
||||
min = 1,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.contract"})
|
||||
public static void contract(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Vector dir;
|
||||
int change = args.getInteger(0);
|
||||
int reverseChange = 0;
|
||||
|
||||
// Either a reverse amount or a direction
|
||||
if (args.argsLength() == 2) {
|
||||
try {
|
||||
reverseChange = args.getInteger(1) * -1;
|
||||
dir = we.getDirection(player, "me");
|
||||
} catch (NumberFormatException e) {
|
||||
dir = we.getDirection(player,
|
||||
args.getString(1).toLowerCase());
|
||||
}
|
||||
// Both reverse amount and direction
|
||||
} else if (args.argsLength() == 3) {
|
||||
reverseChange = args.getInteger(1) * -1;
|
||||
dir = we.getDirection(player,
|
||||
args.getString(2).toLowerCase());
|
||||
} else {
|
||||
dir = we.getDirection(player, "me");
|
||||
}
|
||||
|
||||
try {
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
int oldSize = region.getArea();
|
||||
region.contract(dir.multiply(change));
|
||||
if (reverseChange != 0) {
|
||||
region.contract(dir.multiply(reverseChange));
|
||||
}
|
||||
session.getRegionSelector().learnChanges();
|
||||
int newSize = region.getArea();
|
||||
|
||||
session.getRegionSelector().explainRegionAdjust(player, session);
|
||||
|
||||
player.print("Region contracted " + (oldSize - newSize) + " blocks.");
|
||||
} catch (RegionOperationException e) {
|
||||
player.printError(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/shift"},
|
||||
usage = "<amount> [direction]",
|
||||
desc = "Shift the selection area",
|
||||
min = 1,
|
||||
max = 2
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.shift"})
|
||||
public static void shift(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
Vector dir;
|
||||
|
||||
int change = args.getInteger(0);
|
||||
if (args.argsLength() == 2) {
|
||||
dir = we.getDirection(player,
|
||||
args.getString(1).toLowerCase());
|
||||
} else {
|
||||
dir = we.getDirection(player, "me");
|
||||
}
|
||||
|
||||
try {
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
region.expand(dir.multiply(change));
|
||||
region.contract(dir.multiply(change));
|
||||
session.getRegionSelector().learnChanges();
|
||||
|
||||
session.getRegionSelector().explainRegionAdjust(player, session);
|
||||
|
||||
player.print("Region shifted.");
|
||||
} catch (RegionOperationException e) {
|
||||
player.printError(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/outset"},
|
||||
usage = "<amount>",
|
||||
desc = "Outset the selection area",
|
||||
flags = "hv",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.outset"})
|
||||
public static void outset(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
int change = args.getInteger(0);
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
|
||||
try {
|
||||
if (!args.hasFlag('h')) {
|
||||
region.expand((new Vector(0, 1, 0)).multiply(change));
|
||||
region.expand((new Vector(0, -1, 0)).multiply(change));
|
||||
}
|
||||
|
||||
if (!args.hasFlag('v')) {
|
||||
region.expand((new Vector(1, 0, 0)).multiply(change));
|
||||
region.expand((new Vector(-1, 0, 0)).multiply(change));
|
||||
region.expand((new Vector(0, 0, 1)).multiply(change));
|
||||
region.expand((new Vector(0, 0, -1)).multiply(change));
|
||||
}
|
||||
|
||||
session.getRegionSelector().learnChanges();
|
||||
|
||||
session.getRegionSelector().explainRegionAdjust(player, session);
|
||||
|
||||
player.print("Region outset.");
|
||||
} catch (RegionOperationException e) {
|
||||
player.printError(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/inset"},
|
||||
usage = "<amount>",
|
||||
desc = "Inset the selection area",
|
||||
flags = "hv",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.inset"})
|
||||
public static void inset(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
int change = args.getInteger(0);
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
|
||||
if (!args.hasFlag('h')) {
|
||||
region.contract((new Vector(0, 1, 0)).multiply(change));
|
||||
region.contract((new Vector(0, -1, 0)).multiply(change));
|
||||
}
|
||||
|
||||
if (!args.hasFlag('v')) {
|
||||
region.contract((new Vector(1, 0, 0)).multiply(change));
|
||||
region.contract((new Vector(-1, 0, 0)).multiply(change));
|
||||
region.contract((new Vector(0, 0, 1)).multiply(change));
|
||||
region.contract((new Vector(0, 0, -1)).multiply(change));
|
||||
}
|
||||
|
||||
session.getRegionSelector().learnChanges();
|
||||
|
||||
session.getRegionSelector().explainRegionAdjust(player, session);
|
||||
|
||||
player.print("Region inset.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/size"},
|
||||
usage = "",
|
||||
desc = "Get information about the selection",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.size"})
|
||||
public static void size(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
Vector size = region.getMaximumPoint()
|
||||
.subtract(region.getMinimumPoint())
|
||||
.add(1, 1, 1);
|
||||
|
||||
player.print("Type: " + session.getRegionSelector().getTypeName());
|
||||
|
||||
for (String line : session.getRegionSelector().getInformationLines()) {
|
||||
player.print(line);
|
||||
}
|
||||
|
||||
player.print("Size: " + size);
|
||||
player.print("Cuboid distance: " + region.getMaximumPoint().distance(region.getMinimumPoint()));
|
||||
player.print("# of blocks: " + region.getArea());
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/count"},
|
||||
usage = "<block>",
|
||||
desc = "Counts the number of a certain type of block",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.analysis.count"})
|
||||
public static void count(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Set<Integer> searchIDs = we.getBlockIDs(player,
|
||||
args.getString(0), true);
|
||||
player.print("Counted: " +
|
||||
editSession.countBlocks(session.getSelection(player.getWorld()), searchIDs));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/distr"},
|
||||
usage = "",
|
||||
desc = "Get the distribution of blocks in the selection",
|
||||
flags = "c",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.analysis.distr"})
|
||||
public static void distr(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
List<Countable<Integer>> distribution =
|
||||
editSession.getBlockDistribution(session.getSelection(player.getWorld()));
|
||||
|
||||
Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
||||
|
||||
if (distribution.size() > 0) { // *Should* always be true
|
||||
int size = session.getSelection(player.getWorld()).getArea();
|
||||
|
||||
player.print("# total blocks: " + size);
|
||||
|
||||
if (args.hasFlag('c')) {
|
||||
logger.info("Block distribution (req. by " + player.getName() + "):");
|
||||
logger.info("# total blocks: " + size);
|
||||
}
|
||||
|
||||
for (Countable<Integer> c : distribution) {
|
||||
String str = String.format("%-7s (%.3f%%) %s #%d",
|
||||
String.valueOf(c.getAmount()),
|
||||
c.getAmount() / (double)size * 100,
|
||||
BlockType.fromID(c.getID()).getName(), c.getID());
|
||||
player.print(str);
|
||||
|
||||
if (args.hasFlag('c')) {
|
||||
logger.info(str);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player.printError("No blocks counted.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/sel", ","},
|
||||
usage = "[type]",
|
||||
desc = "Choose a region selector",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
public static void select(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
String typeName = args.getString(0);
|
||||
if (typeName.equalsIgnoreCase("cuboid")) {
|
||||
session.setRegionSelector(player.getWorld(), new CuboidRegionSelector());
|
||||
session.dispatchCUISelection(player);
|
||||
player.print("Cuboid: left click for point 1, right click for point 2");
|
||||
} else if (typeName.equalsIgnoreCase("poly")) {
|
||||
session.setRegionSelector(player.getWorld(), new Polygonal2DRegionSelector());
|
||||
session.dispatchCUISelection(player);
|
||||
player.print("2D polygon selector: Left/right click to add a point.");
|
||||
} else {
|
||||
player.printError("Only 'cuboid' and 'poly' are accepted.");
|
||||
}
|
||||
}
|
||||
}
|
205
src/main/java/com/sk89q/worldedit/commands/SnapshotCommands.java
Normal file
205
src/main/java/com/sk89q/worldedit/commands/SnapshotCommands.java
Normal file
@ -0,0 +1,205 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
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.snapshots.InvalidSnapshotException;
|
||||
import com.sk89q.worldedit.snapshots.Snapshot;
|
||||
|
||||
/**
|
||||
* Snapshot commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class SnapshotCommands {
|
||||
private static Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
||||
private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
|
||||
|
||||
@Command(
|
||||
aliases = {"list"},
|
||||
usage = "[num]",
|
||||
desc = "List snapshots",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.snapshots.list"})
|
||||
public static void list(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
int num = args.argsLength() > 0 ?
|
||||
Math.min(40, Math.max(5, args.getInteger(0))) : 5;
|
||||
|
||||
if (config.snapshotRepo != null) {
|
||||
List<Snapshot> snapshots = config.snapshotRepo.getSnapshots(true);
|
||||
|
||||
if (snapshots.size() > 0) {
|
||||
for (byte i = 0; i < Math.min(num, snapshots.size()); i++) {
|
||||
player.print((i + 1) + ". " + snapshots.get(i).getName());
|
||||
}
|
||||
|
||||
player.print("Use /snap use [snapshot] or /snap use latest.");
|
||||
} else {
|
||||
player.printError("No snapshots are available. See console for details.");
|
||||
|
||||
// Okay, let's toss some debugging information!
|
||||
File dir = config.snapshotRepo.getDirectory();
|
||||
|
||||
try {
|
||||
logger.info("WorldEdit found no snapshots: looked in: " +
|
||||
dir.getCanonicalPath());
|
||||
} catch (IOException e) {
|
||||
logger.info("WorldEdit found no snapshots: looked in "
|
||||
+ "(NON-RESOLVABLE PATH - does it exist?): " +
|
||||
dir.getPath());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player.printError("Snapshot/backup restore is not configured.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"use"},
|
||||
usage = "<snapshot>",
|
||||
desc = "Choose a snapshot to use",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.snapshots.restore"})
|
||||
public static void use(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
if (config.snapshotRepo == null) {
|
||||
player.printError("Snapshot/backup restore is not configured.");
|
||||
return;
|
||||
}
|
||||
|
||||
String name = args.getString(0);
|
||||
|
||||
// Want the latest snapshot?
|
||||
if (name.equalsIgnoreCase("latest")) {
|
||||
Snapshot snapshot = config.snapshotRepo.getDefaultSnapshot();
|
||||
|
||||
if (snapshot != null) {
|
||||
session.setSnapshot(null);
|
||||
player.print("Now using newest snapshot.");
|
||||
} else {
|
||||
player.printError("No snapshots were found.");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
session.setSnapshot(config.snapshotRepo.getSnapshot(name));
|
||||
player.print("Snapshot set to: " + name);
|
||||
} catch (InvalidSnapshotException e) {
|
||||
player.printError("That snapshot does not exist or is not available.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"before"},
|
||||
usage = "<date>",
|
||||
desc = "Choose the nearest snapshot before a date",
|
||||
min = 1,
|
||||
max = -1
|
||||
)
|
||||
@CommandPermissions({"worldedit.snapshots.restore"})
|
||||
public static void before(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
if (config.snapshotRepo == null) {
|
||||
player.printError("Snapshot/backup restore is not configured.");
|
||||
return;
|
||||
}
|
||||
|
||||
Calendar date = session.detectDate(args.getJoinedStrings(0));
|
||||
|
||||
if (date == null) {
|
||||
player.printError("Could not detect the date inputted.");
|
||||
} else {
|
||||
dateFormat.setTimeZone(session.getTimeZone());
|
||||
|
||||
Snapshot snapshot = config.snapshotRepo.getSnapshotBefore(date);
|
||||
if (snapshot == null) {
|
||||
player.printError("Couldn't find a snapshot before "
|
||||
+ dateFormat.format(date.getTime()) + ".");
|
||||
} else {
|
||||
session.setSnapshot(snapshot);
|
||||
player.print("Snapshot set to: " + snapshot.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"after"},
|
||||
usage = "<date>",
|
||||
desc = "Choose the nearest snapshot after a date",
|
||||
min = 1,
|
||||
max = -1
|
||||
)
|
||||
@CommandPermissions({"worldedit.snapshots.restore"})
|
||||
public static void after(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
if (config.snapshotRepo == null) {
|
||||
player.printError("Snapshot/backup restore is not configured.");
|
||||
return;
|
||||
}
|
||||
|
||||
Calendar date = session.detectDate(args.getJoinedStrings(0));
|
||||
|
||||
if (date == null) {
|
||||
player.printError("Could not detect the date inputted.");
|
||||
} else {
|
||||
dateFormat.setTimeZone(session.getTimeZone());
|
||||
|
||||
Snapshot snapshot = config.snapshotRepo.getSnapshotAfter(date);
|
||||
if (snapshot == null) {
|
||||
player.printError("Couldn't find a snapshot after "
|
||||
+ dateFormat.format(date.getTime()) + ".");
|
||||
} else {
|
||||
session.setSnapshot(snapshot);
|
||||
player.print("Snapshot set to: " + snapshot.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,153 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
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.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.data.ChunkStore;
|
||||
import com.sk89q.worldedit.data.DataException;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.snapshots.InvalidSnapshotException;
|
||||
import com.sk89q.worldedit.snapshots.Snapshot;
|
||||
import com.sk89q.worldedit.snapshots.SnapshotRestore;
|
||||
|
||||
public class SnapshotUtilCommands {
|
||||
private static Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
||||
|
||||
@Command(
|
||||
aliases = {"snapshot", "snap"},
|
||||
desc = "Snapshot commands"
|
||||
)
|
||||
@NestedCommand({SnapshotCommands.class})
|
||||
public static void snapshot(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"restore", "/restore"},
|
||||
usage = "[snapshot]",
|
||||
desc = "Restore the selection from a snapshot",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.snapshots.restore"})
|
||||
public static void restore(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
if (config.snapshotRepo == null) {
|
||||
player.printError("Snapshot/backup restore is not configured.");
|
||||
return;
|
||||
}
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
Snapshot snapshot;
|
||||
|
||||
if (args.argsLength() > 0) {
|
||||
try {
|
||||
snapshot = config.snapshotRepo.getSnapshot(args.getString(0));
|
||||
} catch (InvalidSnapshotException e) {
|
||||
player.printError("That snapshot does not exist or is not available.");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
snapshot = session.getSnapshot();
|
||||
}
|
||||
|
||||
ChunkStore chunkStore = null;
|
||||
|
||||
// No snapshot set?
|
||||
if (snapshot == null) {
|
||||
snapshot = config.snapshotRepo.getDefaultSnapshot();
|
||||
|
||||
if (snapshot == null) {
|
||||
player.printError("No snapshots were found. See console for details.");
|
||||
|
||||
// Okay, let's toss some debugging information!
|
||||
File dir = config.snapshotRepo.getDirectory();
|
||||
|
||||
try {
|
||||
logger.info("WorldEdit found no snapshots: looked in: " +
|
||||
dir.getCanonicalPath());
|
||||
} catch (IOException e) {
|
||||
logger.info("WorldEdit found no snapshots: looked in "
|
||||
+ "(NON-RESOLVABLE PATH - does it exist?): " +
|
||||
dir.getPath());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Load chunk store
|
||||
try {
|
||||
chunkStore = snapshot.getChunkStore();
|
||||
player.print("Snapshot '" + snapshot.getName() + "' loaded; now restoring...");
|
||||
} catch (DataException e) {
|
||||
player.printError("Failed to load snapshot: " + e.getMessage());
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
player.printError("Failed to load snapshot: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Restore snapshot
|
||||
SnapshotRestore restore = new SnapshotRestore(chunkStore, region);
|
||||
//player.print(restore.getChunksAffected() + " chunk(s) will be loaded.");
|
||||
|
||||
restore.restore(editSession);
|
||||
|
||||
if (restore.hadTotalFailure()) {
|
||||
String error = restore.getLastErrorMessage();
|
||||
if (error != null) {
|
||||
player.printError("Errors prevented any blocks from being restored.");
|
||||
player.printError("Last error: " + error);
|
||||
} else {
|
||||
player.printError("No chunks could be loaded. (Bad archive?)");
|
||||
}
|
||||
} else {
|
||||
player.print(String.format("Restored; %d "
|
||||
+ "missing chunks and %d other errors.",
|
||||
restore.getMissingChunks().size(),
|
||||
restore.getErrorChunks().size()));
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
chunkStore.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.commands;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.tools.AreaPickaxe;
|
||||
import com.sk89q.worldedit.tools.RecursivePickaxe;
|
||||
import com.sk89q.worldedit.tools.SinglePickaxe;
|
||||
|
||||
public class SuperPickaxeCommands {
|
||||
@Command(
|
||||
aliases = {"single"},
|
||||
usage = "",
|
||||
desc = "Enable the single block super pickaxe mode",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.superpickaxe"})
|
||||
public static void single(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
session.setSuperPickaxe(new SinglePickaxe());
|
||||
session.enableSuperPickAxe();
|
||||
player.print("Mode changed. Left click with a pickaxe. // to disable.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"area"},
|
||||
usage = "<radius>",
|
||||
desc = "Enable the area super pickaxe pickaxe mode",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.superpickaxe.area"})
|
||||
public static void area(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
int range = args.getInteger(0);
|
||||
|
||||
if (range > config.maxSuperPickaxeSize) {
|
||||
player.printError("Maximum range: " + config.maxSuperPickaxeSize);
|
||||
return;
|
||||
}
|
||||
|
||||
session.setSuperPickaxe(new AreaPickaxe(range));
|
||||
session.enableSuperPickAxe();
|
||||
player.print("Mode changed. Left click with a pickaxe. // to disable.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"recur", "recursive"},
|
||||
usage = "<radius>",
|
||||
desc = "Enable the recursive super pickaxe pickaxe mode",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.superpickaxe.recursive"})
|
||||
public static void recursive(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
int range = args.getInteger(0);
|
||||
|
||||
if (range > config.maxSuperPickaxeSize) {
|
||||
player.printError("Maximum range: " + config.maxSuperPickaxeSize);
|
||||
return;
|
||||
}
|
||||
|
||||
session.setSuperPickaxe(new RecursivePickaxe(range));
|
||||
session.enableSuperPickAxe();
|
||||
player.print("Mode changed. Left click with a pickaxe. // to disable.");
|
||||
}
|
||||
}
|
135
src/main/java/com/sk89q/worldedit/commands/ToolCommands.java
Normal file
135
src/main/java/com/sk89q/worldedit/commands/ToolCommands.java
Normal file
@ -0,0 +1,135 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.commands;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.minecraft.util.commands.NestedCommand;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
import com.sk89q.worldedit.tools.*;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
|
||||
public class ToolCommands {
|
||||
@Command(
|
||||
aliases = {"none"},
|
||||
usage = "",
|
||||
desc = "Turn off all superpickaxe alternate modes",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
public static void none(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
session.setTool(player.getItemInHand(), null);
|
||||
player.print("Tool unbound from your current item.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"info"},
|
||||
usage = "",
|
||||
desc = "Block information tool",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.tool.info"})
|
||||
public static void info(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
session.setTool(player.getItemInHand(), new QueryTool());
|
||||
player.print("Info tool bound to "
|
||||
+ ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"tree"},
|
||||
usage = "[type]",
|
||||
desc = "Tree generator tool",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.tool.tree"})
|
||||
public static void tree(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
TreeGenerator.TreeType type = args.argsLength() > 0 ?
|
||||
type = TreeGenerator.lookup(args.getString(0))
|
||||
: TreeGenerator.TreeType.TREE;
|
||||
|
||||
if (type == null) {
|
||||
player.printError("Tree type '" + args.getString(0) + "' is unknown.");
|
||||
return;
|
||||
}
|
||||
|
||||
session.setTool(player.getItemInHand(), new TreePlanter(new TreeGenerator(type)));
|
||||
player.print("Tree tool bound to "
|
||||
+ ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"repl"},
|
||||
usage = "<block>",
|
||||
desc = "Block replacer tool",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.tool.replacer"})
|
||||
public static void repl(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
BaseBlock targetBlock = we.getBlock(player, args.getString(0));
|
||||
session.setTool(player.getItemInHand(), new BlockReplacer(targetBlock));
|
||||
player.print("Block replacer tool bound to "
|
||||
+ ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"cycler"},
|
||||
usage = "",
|
||||
desc = "Block data cycler tool",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.tool.data-cycler"})
|
||||
public static void cycler(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
session.setTool(player.getItemInHand(), new BlockDataCyler());
|
||||
player.print("Block data cycler tool bound to "
|
||||
+ ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"brush", "br"},
|
||||
desc = "Brush tool"
|
||||
)
|
||||
@NestedCommand({BrushCommands.class})
|
||||
public static void brush(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
}
|
||||
}
|
136
src/main/java/com/sk89q/worldedit/commands/ToolUtilCommands.java
Normal file
136
src/main/java/com/sk89q/worldedit/commands/ToolUtilCommands.java
Normal file
@ -0,0 +1,136 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.commands;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.minecraft.util.commands.NestedCommand;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.masks.Mask;
|
||||
import com.sk89q.worldedit.patterns.Pattern;
|
||||
|
||||
/**
|
||||
* Tool commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ToolUtilCommands {
|
||||
@Command(
|
||||
aliases = {"/", ","},
|
||||
usage = "",
|
||||
desc = "Toggle the super pickaxe pickaxe function",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.superpickaxe"})
|
||||
public static void togglePickaxe(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
if (session.toggleSuperPickAxe()) {
|
||||
player.print("Super pick axe enabled.");
|
||||
} else {
|
||||
player.print("Super pick axe disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"superpickaxe", "pickaxe", "sp"},
|
||||
desc = "Select super pickaxe mode"
|
||||
)
|
||||
@NestedCommand({SuperPickaxeCommands.class})
|
||||
public static void pickaxe(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"tool"},
|
||||
desc = "Select a tool to bind"
|
||||
)
|
||||
@NestedCommand({ToolCommands.class})
|
||||
public static void tool(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"mask"},
|
||||
usage = "[mask]",
|
||||
desc = "Set the brush mask",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.options.mask"})
|
||||
public static void mask(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
if (args.argsLength() == 0) {
|
||||
session.getBrushTool(player.getItemInHand()).setMask(null);
|
||||
player.print("Brush mask disabled.");
|
||||
} else {
|
||||
Mask mask = we.getBlockMask(player, args.getString(0));
|
||||
session.getBrushTool(player.getItemInHand()).setMask(mask);
|
||||
player.print("Brush mask set.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"mat", "material", "fill"},
|
||||
usage = "[pattern]",
|
||||
desc = "Set the brush material",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.options.material"})
|
||||
public static void material(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
Pattern pattern = we.getBlockPattern(player, args.getString(0));
|
||||
session.getBrushTool(player.getItemInHand()).setFill(pattern);
|
||||
player.print("Brush material set.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"size"},
|
||||
usage = "[pattern]",
|
||||
desc = "Set the brush size",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.options.size"})
|
||||
public static void size(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
int radius = args.getInteger(0);
|
||||
if (radius > config.maxBrushRadius) {
|
||||
player.printError("Maximum allowed brush radius: "
|
||||
+ config.maxBrushRadius);
|
||||
return;
|
||||
}
|
||||
|
||||
session.getBrushTool(player.getItemInHand()).setSize(radius);
|
||||
player.print("Brush size set.");
|
||||
}
|
||||
}
|
374
src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java
Normal file
374
src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java
Normal file
@ -0,0 +1,374 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.commands;
|
||||
|
||||
import java.util.Set;
|
||||
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.LocalWorld.EntityType;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.patterns.*;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
/**
|
||||
* Utility commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class UtilityCommands {
|
||||
@Command(
|
||||
aliases = {"/fill"},
|
||||
usage = " <block> <radius> [depth] ",
|
||||
desc = "Fill a hole",
|
||||
min = 2,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.fill"})
|
||||
public static void fill(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Pattern pattern = we.getBlockPattern(player, args.getString(0));
|
||||
int radius = Math.max(1, args.getInteger(1));
|
||||
we.checkMaxRadius(radius);
|
||||
int depth = args.argsLength() > 2 ? Math.max(1, args.getInteger(2)) : 1;
|
||||
|
||||
Vector pos = session.getPlacementPosition(player);
|
||||
int affected = 0;
|
||||
if (pattern instanceof SingleBlockPattern) {
|
||||
affected = editSession.fillXZ(pos,
|
||||
((SingleBlockPattern)pattern).getBlock(),
|
||||
radius, depth, false);
|
||||
} else {
|
||||
affected = editSession.fillXZ(pos, pattern, radius, depth, false);
|
||||
}
|
||||
player.print(affected + " block(s) have been created.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/fillr"},
|
||||
usage = " <block> <radius> [depth] ",
|
||||
desc = "Fill a hole recursively",
|
||||
min = 2,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.fill.recursive"})
|
||||
public static void fillr(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Pattern pattern = we.getBlockPattern(player, args.getString(0));
|
||||
int radius = Math.max(1, args.getInteger(1));
|
||||
we.checkMaxRadius(radius);
|
||||
int depth = args.argsLength() > 2 ? Math.max(1, args.getInteger(2)) : 1;
|
||||
|
||||
Vector pos = session.getPlacementPosition(player);
|
||||
int affected = 0;
|
||||
if (pattern instanceof SingleBlockPattern) {
|
||||
affected = editSession.fillXZ(pos,
|
||||
((SingleBlockPattern)pattern).getBlock(),
|
||||
radius, depth, true);
|
||||
} else {
|
||||
affected = editSession.fillXZ(pos, pattern, radius, depth, true);
|
||||
}
|
||||
player.print(affected + " block(s) have been created.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/drain"},
|
||||
usage = "<radius>",
|
||||
desc = "Drain a pool",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.drain"})
|
||||
public static void drain(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int radius = Math.max(0, args.getInteger(0));
|
||||
we.checkMaxRadius(radius);
|
||||
int affected = editSession.drainArea(
|
||||
session.getPlacementPosition(player), radius);
|
||||
player.print(affected + " block(s) have been changed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"fixlava"},
|
||||
usage = "<radius>",
|
||||
desc = "Fix lava to be stationary",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.fixlava"})
|
||||
public static void fixLava(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int radius = Math.max(0, args.getInteger(0));
|
||||
we.checkMaxRadius(radius);
|
||||
int affected = editSession.fixLiquid(
|
||||
session.getPlacementPosition(player), radius, 10, 11);
|
||||
player.print(affected + " block(s) have been changed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"fixwater"},
|
||||
usage = "<radius>",
|
||||
desc = "Fix water to be stationary",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.fixwater"})
|
||||
public static void fixWater(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int radius = Math.max(0, args.getInteger(0));
|
||||
we.checkMaxRadius(radius);
|
||||
int affected = editSession.fixLiquid(
|
||||
session.getPlacementPosition(player), radius, 8, 9);
|
||||
player.print(affected + " block(s) have been changed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"removeabove"},
|
||||
usage = "[size] [height] ",
|
||||
desc = "Remove blocks above your head. ",
|
||||
min = 0,
|
||||
max = 2
|
||||
)
|
||||
@CommandPermissions({"worldedit.removeabove"})
|
||||
public static void removeAbove(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
|
||||
we.checkMaxRadius(size);
|
||||
int height = args.argsLength() > 1 ? Math.min(128, args.getInteger(1) + 2) : 128;
|
||||
|
||||
int affected = editSession.removeAbove(
|
||||
session.getPlacementPosition(player), size, height);
|
||||
player.print(affected + " block(s) have been removed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"removebelow"},
|
||||
usage = "[size] [height] ",
|
||||
desc = "Remove blocks below your head. ",
|
||||
min = 0,
|
||||
max = 2
|
||||
)
|
||||
@CommandPermissions({"worldedit.removebelow"})
|
||||
public static void removeBelow(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
|
||||
we.checkMaxRadius(size);
|
||||
int height = args.argsLength() > 1 ? Math.min(128, args.getInteger(1) + 2) : 128;
|
||||
|
||||
int affected = editSession.removeBelow(
|
||||
session.getPlacementPosition(player), size, height);
|
||||
player.print(affected + " block(s) have been removed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"removenear"},
|
||||
usage = "<block> [size] ",
|
||||
desc = "Remove blocks near you.",
|
||||
min = 1,
|
||||
max = 2
|
||||
)
|
||||
@CommandPermissions({"worldedit.removenear"})
|
||||
public static void removeNear(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
BaseBlock block = we.getBlock(player, args.getString(0), true);
|
||||
int size = Math.max(1, args.getInteger(1, 50));
|
||||
we.checkMaxRadius(size);
|
||||
|
||||
int affected = editSession.removeNear(
|
||||
session.getPlacementPosition(player), block.getType(), size);
|
||||
player.print(affected + " block(s) have been removed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"replacenear"},
|
||||
usage = "<size> <from-id> <to-id> ",
|
||||
desc = "Replace nearby blocks",
|
||||
min = 3,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.replacenear"})
|
||||
public static void replaceNear(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int size = Math.max(1, args.getInteger(0));
|
||||
Set<Integer> from;
|
||||
BaseBlock to;
|
||||
if (args.argsLength() == 2) {
|
||||
from = null;
|
||||
to = we.getBlock(player, args.getString(1));
|
||||
} else {
|
||||
from = we.getBlockIDs(player, args.getString(1), true);
|
||||
to = we.getBlock(player, args.getString(2));
|
||||
}
|
||||
|
||||
Vector min = player.getBlockIn().subtract(size, size, size);
|
||||
Vector max = player.getBlockIn().add(size, size, size);
|
||||
Region region = new CuboidRegion(min, max);
|
||||
|
||||
int affected = editSession.replaceBlocks(region, from, to);
|
||||
player.print(affected + " block(s) have been replaced.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"snow"},
|
||||
usage = "[radius]",
|
||||
desc = "Simulates snow",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.snow"})
|
||||
public static void snow(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
|
||||
|
||||
int affected = editSession.simulateSnow(player.getBlockIn(), size);
|
||||
player.print(affected + " surfaces covered. Let it snow~");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"thaw"},
|
||||
usage = "[radius]",
|
||||
desc = "Thaws the area",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.thaw"})
|
||||
public static void thaw(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
|
||||
|
||||
int affected = editSession.thaw(player.getBlockIn(), size);
|
||||
player.print(affected + " surfaces thawed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"ex", "ext", "extinguish"},
|
||||
usage = "[radius]",
|
||||
desc = "Extinguish nearby fire",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.extinguish"})
|
||||
public static void extinguish(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
int defaultRadius = config.maxRadius != -1 ? Math.min(40, config.maxRadius) : 40;
|
||||
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0))
|
||||
: defaultRadius;
|
||||
we.checkMaxRadius(size);
|
||||
|
||||
int affected = editSession.removeNear(
|
||||
session.getPlacementPosition(player), 51, size);
|
||||
player.print(affected + " block(s) have been removed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"butcher"},
|
||||
usage = "[radius]",
|
||||
desc = "Kill all or nearby mobs",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.butcher"})
|
||||
public static void butcher(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int radius = args.argsLength() > 0 ?
|
||||
Math.max(1, args.getInteger(0)) : -1;
|
||||
|
||||
Vector origin = session.getPlacementPosition(player);
|
||||
int killed = player.getWorld().killMobs(origin, radius);
|
||||
player.print("Killed " + killed + " mobs.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"remove", "rem", "rement"},
|
||||
usage = "<type> <radius>",
|
||||
desc = "Remove all entities of a type",
|
||||
min = 2,
|
||||
max = 2
|
||||
)
|
||||
@CommandPermissions({"worldedit.remove"})
|
||||
public static void remove(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
String typeStr = args.getString(0);
|
||||
int radius = args.getInteger(1);
|
||||
|
||||
if (radius < -1) {
|
||||
player.printError("Use -1 to remove all entities in loaded chunks");
|
||||
return;
|
||||
}
|
||||
|
||||
EntityType type = null;
|
||||
|
||||
if (typeStr.matches("arrows?")) {
|
||||
type = EntityType.ARROWS;
|
||||
} else if (typeStr.matches("items?")
|
||||
|| typeStr.matches("drops?")) {
|
||||
type = EntityType.ITEMS;
|
||||
} else if (typeStr.matches("paintings?")
|
||||
|| typeStr.matches("art")) {
|
||||
type = EntityType.PAINTINGS;
|
||||
} else if (typeStr.matches("boats?")) {
|
||||
type = EntityType.BOATS;
|
||||
} else if (typeStr.matches("minecarts?")
|
||||
|| typeStr.matches("carts?")) {
|
||||
type = EntityType.MINECARTS;
|
||||
} else if (typeStr.matches("tnt")) {
|
||||
type = EntityType.TNT;
|
||||
} else {
|
||||
player.printError("Acceptable types: arrows, items, paintings, boats, minecarts, tnt");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector origin = session.getPlacementPosition(player);
|
||||
int removed = player.getWorld().removeEntities(type, origin, radius);
|
||||
player.print("Marked " + removed + " entit(ies) for removal.");
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.commands;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
|
||||
public class WorldEditCommands {
|
||||
private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
|
||||
|
||||
@Command(
|
||||
aliases = {"version", "ver"},
|
||||
usage = "",
|
||||
desc = "Get WorldEdit version",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
public static void version(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
player.print("WorldEdit version " + WorldEdit.getVersion());
|
||||
player.print("http://www.sk89q.com/projects/worldedit/");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"reload"},
|
||||
usage = "",
|
||||
desc = "Reload WorldEdit",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.reload"})
|
||||
public static void reload(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
we.getServer().reload();
|
||||
player.print("Configuration reloaded!");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"cui"},
|
||||
usage = "",
|
||||
desc = "Complete CUI handshake",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
public static void cui(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
session.setCUISupport(true);
|
||||
session.dispatchCUISetup(player);
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"tz"},
|
||||
usage = "[timezone]",
|
||||
desc = "Set your timezone",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
public static void tz(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
TimeZone tz = TimeZone.getTimeZone(args.getString(0));
|
||||
session.setTimezone(tz);
|
||||
player.print("Timezone set for this session to: " + tz.getDisplayName());
|
||||
player.print("The current time in that timezone is: "
|
||||
+ dateFormat.format(Calendar.getInstance(tz).getTime()));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user