Revert "Upstream, generics, formatting"

This reverts commit cd88e513a8.
This commit is contained in:
NotMyFault
2019-06-12 15:45:41 +02:00
parent 6f9fa018b2
commit ec001b8d3b
126 changed files with 3093 additions and 2490 deletions

View File

@ -33,9 +33,12 @@ import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Helper class to 'bake' a transform into a clipboard.
*
* <p>
* <p>This class needs a better name and may need to be made more generic.</p>
*
* @see Clipboard
@ -49,7 +52,7 @@ public class FlattenedClipboardTransform {
/**
* Create a new instance.
*
* @param original the original clipboard
* @param original the original clipboard
* @param transform the transform
*/
private FlattenedClipboardTransform(Clipboard original, Transform transform) {
@ -91,10 +94,10 @@ public class FlattenedClipboardTransform {
Vector3 newMinimum = corners[0];
Vector3 newMaximum = corners[0];
for (int i = 1; i < corners.length; i++) {
newMinimum = newMinimum.getMinimum(corners[i]);
newMaximum = newMaximum.getMaximum(corners[i]);
Vector3 cbv = corners[i];
newMinimum = newMinimum.getMinimum(cbv);
newMaximum = newMaximum.getMaximum(cbv);
}
// After transformation, the points may not really sit on a block,
@ -122,7 +125,7 @@ public class FlattenedClipboardTransform {
/**
* Create a new instance to bake the transform with.
*
* @param original the original clipboard
* @param original the original clipboard
* @param transform the transform
* @return a builder
*/
@ -130,4 +133,5 @@ public class FlattenedClipboardTransform {
return new FlattenedClipboardTransform(original, transform);
}
}

View File

@ -31,6 +31,7 @@ import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
@ -43,16 +44,17 @@ import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.function.visitor.RegionVisitor;
import com.sk89q.worldedit.internal.annotation.Selection;
import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
import com.sk89q.worldedit.util.command.binding.Range;
import com.sk89q.worldedit.util.command.binding.Switch;
import com.sk89q.worldedit.util.command.binding.Text;
import com.sk89q.worldedit.util.command.parametric.Optional;
import com.sk89q.worldedit.util.command.parametric.ParameterException;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockType;
@ -61,9 +63,7 @@ import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.ALL;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.POSITION;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.*;
/**
@ -82,14 +82,14 @@ public class GenerationCommands extends MethodCommands {
}
@Command(
aliases = { "/caves" },
aliases = {"/caves"},
usage = "[size=8] [freq=40] [rarity=7] [minY=8] [maxY=127] [sysFreq=1] [sysRarity=25] [pocketRarity=0] [pocketMin=0] [pocketMax=3]",
desc = "Generates caves",
help = "Generates a cave network"
)
@CommandPermissions("worldedit.generation.caves")
@Logging(PLACEMENT)
public void caves(FawePlayer fp, LocalSession session, EditSession editSession, @Selection Region region, @Optional("8") int size, @Optional("40") int frequency, @Optional("7") int rarity, @Optional("8") int minY, @Optional("127") int maxY, @Optional("1") int systemFrequency, @Optional("25") int individualRarity, @Optional("0") int pocketChance, @Optional("0") int pocketMin, @Optional("3") int pocketMax, CommandContext context) throws WorldEditException {
public void caves(FawePlayer fp, LocalSession session, EditSession editSession, @Selection Region region, @Optional("8") int size, @Optional("40") int frequency, @Optional("7") int rarity, @Optional("8") int minY, @Optional("127") int maxY, @Optional("1") int systemFrequency, @Optional("25") int individualRarity, @Optional("0") int pocketChance, @Optional("0") int pocketMin, @Optional("3") int pocketMax, CommandContext context) throws WorldEditException, ParameterException {
fp.checkConfirmationRegion(() -> {
CavesGen gen = new CavesGen(size, frequency, rarity, minY, maxY, systemFrequency, individualRarity, pocketChance, pocketMin, pocketMax);
editSession.generate(region, gen);
@ -100,7 +100,7 @@ public class GenerationCommands extends MethodCommands {
// public void addOre(Mask mask, Pattern material, int size, int frequency, int rarity, int minY, int maxY) throws WorldEditException {
@Command(
aliases = { "/ores" },
aliases = {"/ores"},
desc = "Generates ores",
help = "Generates ores",
min = 1,
@ -108,7 +108,7 @@ public class GenerationCommands extends MethodCommands {
)
@CommandPermissions("worldedit.generation.ore")
@Logging(PLACEMENT)
public void ores(FawePlayer player, LocalSession session, EditSession editSession, @Selection Region region, Mask mask, CommandContext context) throws WorldEditException {
public void ores(FawePlayer player, LocalSession session, EditSession editSession, @Selection Region region, Mask mask, CommandContext context) throws WorldEditException, ParameterException {
player.checkConfirmationRegion(() -> {
editSession.addOres(region, mask);
BBC.VISITOR_BLOCK.send(player, editSession.getBlockChangeCount());
@ -116,7 +116,7 @@ public class GenerationCommands extends MethodCommands {
}
@Command(
aliases = { "/image", "/img" },
aliases = {"/image", "/img"},
desc = "Generate an image",
usage = "<imgur> [randomize=true] [complexity=100] [dimensions=100,100]",
min = 1,
@ -124,7 +124,7 @@ public class GenerationCommands extends MethodCommands {
)
@CommandPermissions("worldedit.generation.image")
@Logging(PLACEMENT)
public void image(Player player, LocalSession session, EditSession editSession, String arg, @Optional("true") boolean randomize, @Optional("100") int threshold, @Optional BlockVector2 dimensions) throws WorldEditException, IOException {
public void image(Player player, LocalSession session, EditSession editSession, String arg, @Optional("true") boolean randomize, @Optional("100") int threshold, @Optional BlockVector2 dimensions) throws WorldEditException, ParameterException, IOException {
TextureUtil tu = Fawe.get().getCachedTextureUtil(randomize, 0, threshold);
URL url = new URL(arg);
if (!url.getHost().equalsIgnoreCase("i.imgur.com") && !url.getHost().equalsIgnoreCase("empcraft.com")) {
@ -174,7 +174,7 @@ public class GenerationCommands extends MethodCommands {
)
@CommandPermissions("worldedit.generation.ore")
@Logging(PLACEMENT)
public void ore(FawePlayer player, LocalSession session, EditSession editSession, @Selection Region region, Mask mask, Pattern material, @Range(min = 0) int size, int freq, @Range(min = 0, max = 100) int rarity, @Range(min = 0, max = 255) int minY, @Range(min = 0, max = 255) int maxY, CommandContext context) throws WorldEditException {
public void ore(FawePlayer player, LocalSession session, EditSession editSession, @Selection Region region, Mask mask, Pattern material, @Range(min = 0) int size, int freq, @Range(min = 0, max = 100) int rarity, @Range(min = 0, max = 255) int minY, @Range(min = 0, max = 255) int maxY, CommandContext context) throws WorldEditException, ParameterException {
player.checkConfirmationRegion(() -> {
editSession.addOre(region, mask, material, size, freq, rarity, minY, maxY);
BBC.VISITOR_BLOCK.send(player, editSession.getBlockChangeCount());
@ -182,7 +182,7 @@ public class GenerationCommands extends MethodCommands {
}
@Command(
aliases = { "/hcyl" },
aliases = {"/hcyl"},
usage = "<pattern> <radius>[,<radius>] [height]",
desc = "Generates a hollow cylinder.",
help =
@ -195,18 +195,18 @@ public class GenerationCommands extends MethodCommands {
)
@CommandPermissions("worldedit.generation.cylinder")
@Logging(PLACEMENT)
public void hcyl(FawePlayer fp, Player player, LocalSession session, EditSession editSession, Pattern pattern, BlockVector2 radius, @Optional("1") int height, @Range(min = 1) @Optional("1") double thickness, CommandContext context) throws WorldEditException {
int max = Math.max(radius.getBlockX(), radius.getBlockZ());
public void hcyl(FawePlayer fp, Player player, LocalSession session, EditSession editSession, Pattern pattern, BlockVector2 radius, @Optional("1") int height, @Range(min = 1) @Optional("1") double thickness, CommandContext context) throws WorldEditException, ParameterException {
double max = MathMan.max(radius.getBlockX(), radius.getBlockZ());
worldEdit.checkMaxRadius(max);
BlockVector3 pos = session.getPlacementPosition(player);
fp.checkConfirmationRadius(() -> {
int affected = editSession.makeHollowCylinder(pos, pattern, radius.getX(), radius.getZ(), Math.min(256, height), thickness - 1);
BBC.VISITOR_BLOCK.send(fp, affected);
}, getArguments(context), max, context);
}, getArguments(context), (int) max, context);
}
@Command(
aliases = { "/cyl" },
aliases = {"/cyl"},
usage = "<pattern> <radius>[,<radius>] [height]",
flags = "h",
desc = "Generates a cylinder.",
@ -220,18 +220,18 @@ public class GenerationCommands extends MethodCommands {
)
@CommandPermissions("worldedit.generation.cylinder")
@Logging(PLACEMENT)
public void cyl(FawePlayer fp, Player player, LocalSession session, EditSession editSession, Pattern pattern, BlockVector2 radius, @Optional("1") int height, @Switch('h') boolean hollow, CommandContext context) throws WorldEditException {
int max = Math.max(radius.getBlockX(), radius.getBlockZ());
public void cyl(FawePlayer fp, Player player, LocalSession session, EditSession editSession, Pattern pattern, BlockVector2 radius, @Optional("1") int height, @Switch('h') boolean hollow, CommandContext context) throws WorldEditException, ParameterException {
double max = MathMan.max(radius.getBlockX(), radius.getBlockZ());
worldEdit.checkMaxRadius(max);
BlockVector3 pos = session.getPlacementPosition(player);
fp.checkConfirmationRadius(() -> {
int affected = editSession.makeCylinder(pos, pattern, radius.getX(), radius.getZ(), Math.min(256, height), !hollow);
BBC.VISITOR_BLOCK.send(fp, affected);
}, getArguments(context), max, context);
}, getArguments(context), (int) max, context);
}
@Command(
aliases = { "/hsphere" },
aliases = {"/hsphere"},
usage = "<pattern> <radius>[,<radius>,<radius>] [raised?]",
desc = "Generates a hollow sphere.",
help =
@ -244,12 +244,12 @@ public class GenerationCommands extends MethodCommands {
)
@CommandPermissions("worldedit.generation.sphere")
@Logging(PLACEMENT)
public void hsphere(FawePlayer fp, Player player, LocalSession session, EditSession editSession, Pattern pattern, BlockVector3 radius, @Optional("false") boolean raised, CommandContext context) throws WorldEditException {
public void hsphere(FawePlayer fp, Player player, LocalSession session, EditSession editSession, Pattern pattern, BlockVector3 radius, @Optional("false") boolean raised, CommandContext context) throws WorldEditException, ParameterException {
sphere(fp, player, session, editSession, pattern, radius, raised, true, context);
}
@Command(
aliases = { "/sphere" },
aliases = {"/sphere"},
usage = "<pattern> <radius>[,<radius>,<radius>] [raised?]",
flags = "h",
desc = "Generates a filled sphere.",
@ -263,7 +263,7 @@ public class GenerationCommands extends MethodCommands {
)
@CommandPermissions("worldedit.generation.sphere")
@Logging(PLACEMENT)
public void sphere(FawePlayer fp, Player player, LocalSession session, EditSession editSession, Pattern pattern, BlockVector3 radius, @Optional("false") boolean raised, @Switch('h') boolean hollow, CommandContext context) throws WorldEditException {
public void sphere(FawePlayer fp, Player player, LocalSession session, EditSession editSession, Pattern pattern, BlockVector3 radius, @Optional("false") boolean raised, @Switch('h') boolean hollow, CommandContext context) throws WorldEditException, ParameterException {
double max = MathMan.max(radius.getBlockX(), radius.getBlockY(), radius.getBlockZ());
worldEdit.checkMaxRadius(max);
BlockVector3 pos = session.getPlacementPosition(player);
@ -276,37 +276,36 @@ public class GenerationCommands extends MethodCommands {
}
@Command(
aliases = { "forestgen" },
usage = "[size] [type] [density]",
desc = "Generate a forest",
min = 0,
max = 3
aliases = {"forestgen"},
usage = "[size] [tree-type] [density]",
desc = "Generate a forest",
min = 0,
max = 3
)
@CommandPermissions("worldedit.generation.forest")
@Logging(POSITION)
public void forestGen(Player player, LocalSession session, EditSession editSession, @Optional("10") int size,
@Optional("tree") TreeType type, @Optional("5") @Range(min = 0, max = 100) double density) throws WorldEditException {
@SuppressWarnings("deprecation")
public void forestGen(Player player, LocalSession session, EditSession editSession, @Optional("10") int size, @Optional("tree") TreeType type, @Optional("5") @Range(min = 0, max = 100) double density) throws WorldEditException, ParameterException {
density = density / 100;
int affected = editSession.makeForest(session.getPlacementPosition(player), size, density, type);
player.print(affected + " trees created.");
player.print(BBC.getPrefix() + affected + " trees created.");
}
@Command(
aliases = { "pumpkins" },
usage = "[size]",
desc = "Generate pumpkin patches",
min = 0,
max = 1
aliases = {"pumpkins"},
usage = "[size=10]",
desc = "Generate pumpkin patches",
max = 2
)
@CommandPermissions("worldedit.generation.pumpkins")
@Logging(POSITION)
public void pumpkins(Player player, LocalSession session, EditSession editSession, @Optional("10") int apothem) throws WorldEditException {
public void pumpkins(Player player, LocalSession session, EditSession editSession, @Optional("10") int apothem) throws WorldEditException, ParameterException {
int affected = editSession.makePumpkinPatches(session.getPlacementPosition(player), apothem);
BBC.COMMAND_PUMPKIN.send(player, affected);
}
@Command(
aliases = { "/hpyramid" },
aliases = {"/hpyramid"},
usage = "<pattern> <size>",
desc = "Generate a hollow pyramid",
min = 2,
@ -314,21 +313,21 @@ public class GenerationCommands extends MethodCommands {
)
@CommandPermissions("worldedit.generation.pyramid")
@Logging(PLACEMENT)
public void hollowPyramid(FawePlayer fp, Player player, LocalSession session, EditSession editSession, Pattern pattern, @Range(min = 1) int size, CommandContext context) throws WorldEditException {
public void hollowPyramid(FawePlayer fp, Player player, LocalSession session, EditSession editSession, Pattern pattern, @Range(min = 1) int size, CommandContext context) throws WorldEditException, ParameterException {
pyramid(fp, player, session, editSession, pattern, size, true, context);
}
@Command(
aliases = { "/pyramid" },
usage = "<pattern> <size>",
flags = "h",
desc = "Generate a filled pyramid",
min = 2,
max = 2
aliases = {"/pyramid"},
usage = "<pattern> <size>",
flags = "h",
desc = "Generate a filled pyramid",
min = 2,
max = 2
)
@CommandPermissions("worldedit.generation.pyramid")
@Logging(PLACEMENT)
public void pyramid(FawePlayer fp, Player player, LocalSession session, EditSession editSession, Pattern pattern, @Range(min = 1) int size, @Switch('h') boolean hollow, CommandContext context) throws WorldEditException {
public void pyramid(FawePlayer fp, Player player, LocalSession session, EditSession editSession, Pattern pattern, @Range(min = 1) int size, @Switch('h') boolean hollow, CommandContext context) throws WorldEditException, ParameterException {
BlockVector3 pos = session.getPlacementPosition(player);
worldEdit.checkMaxRadius(size);
fp.checkConfirmationRadius(() -> {
@ -337,7 +336,7 @@ public class GenerationCommands extends MethodCommands {
BBC.VISITOR_BLOCK.send(fp, affected);
}, getArguments(context), size, context);
}
@Command(
aliases = {"/generate", "/gen", "/g"},
@ -395,7 +394,7 @@ public class GenerationCommands extends MethodCommands {
if (unit.getY() == 0) unit = unit.withY(1.0);
if (unit.getZ() == 0) unit = unit.withZ(1.0);
}
final Vector3 unit1 = unit;
fp.checkConfirmationRegion(() -> {
@ -465,9 +464,9 @@ public class GenerationCommands extends MethodCommands {
if (unit.getY() == 0) unit = unit.withY(1.0);
if (unit.getZ() == 0) unit = unit.withZ(1.0);
}
final Vector3 unit1 = unit;
fp.checkConfirmationRegion(() -> {
try {
final int affected = editSession.makeBiomeShape(region, zero, unit1, target, expression, hollow);

View File

@ -50,8 +50,6 @@ import java.io.File;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Commands to undo, redo, and clear history.
*/
@ -65,11 +63,10 @@ public class HistoryCommands extends MethodCommands {
*/
public HistoryCommands(WorldEdit worldEdit) {
super(worldEdit);
checkNotNull(worldEdit);
}
@Command(
aliases = { "/frb", "frb", "fawerollback", "/fawerollback", "/rollback" },
aliases = {"/frb", "frb", "fawerollback", "/fawerollback", "/rollback"},
usage = "<user=Empire92> <radius=5> <time=3d4h>",
desc = "Undo a specific edit. " +
" - The time uses s, m, h, d, y.\n" +
@ -83,72 +80,74 @@ public class HistoryCommands extends MethodCommands {
BBC.SETTING_DISABLE.send(player, "history.use-database (Import with /frb #import )");
return;
}
if (user.charAt(0) == '#') {
if (user.equals("#import")) {
if (!player.hasPermission("fawe.rollback.import")) {
BBC.NO_PERM.send(player, "fawe.rollback.import");
return;
}
File folder = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HISTORY);
if (!folder.exists()) {
return;
}
for (File worldFolder : folder.listFiles()) {
if (!worldFolder.isDirectory()) {
continue;
switch (user.charAt(0)) {
case '#': {
if (user.equals("#import")) {
if (!player.hasPermission("fawe.rollback.import")) {
BBC.NO_PERM.send(player, "fawe.rollback.import");
return;
}
String worldName = worldFolder.getName();
World world = FaweAPI.getWorld(worldName);
if (world != null) {
for (File userFolder : worldFolder.listFiles()) {
if (!userFolder.isDirectory()) {
continue;
}
String userUUID = userFolder.getName();
try {
UUID uuid = UUID.fromString(userUUID);
for (File historyFile : userFolder.listFiles()) {
String name = historyFile.getName();
if (!name.endsWith(".bd")) {
continue;
}
RollbackOptimizedHistory rollback = new RollbackOptimizedHistory(world, uuid, Integer.parseInt(name.substring(0, name.length() - 3)));
DiskStorageHistory.DiskStorageSummary summary = rollback.summarize(RegionWrapper.GLOBAL(), false);
if (summary != null) {
rollback.setDimensions(BlockVector3.at(summary.minX, 0, summary.minZ), BlockVector3.at(summary.maxX, 255, summary.maxZ));
rollback.setTime(historyFile.lastModified());
RollbackDatabase db = DBHandler.IMP.getDatabase(world);
db.logEdit(rollback);
player.print(BBC.getPrefix() + "Logging: " + historyFile);
}
File folder = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HISTORY);
if (!folder.exists()) {
return;
}
for (File worldFolder : folder.listFiles()) {
if (!worldFolder.isDirectory()) {
continue;
}
String worldName = worldFolder.getName();
World world = FaweAPI.getWorld(worldName);
if (world != null) {
for (File userFolder : worldFolder.listFiles()) {
if (!userFolder.isDirectory()) {
continue;
}
String userUUID = userFolder.getName();
try {
UUID uuid = UUID.fromString(userUUID);
for (File historyFile : userFolder.listFiles()) {
String name = historyFile.getName();
if (!name.endsWith(".bd")) {
continue;
}
RollbackOptimizedHistory rollback = new RollbackOptimizedHistory(world, uuid, Integer.parseInt(name.substring(0, name.length() - 3)));
DiskStorageHistory.DiskStorageSummary summary = rollback.summarize(RegionWrapper.GLOBAL(), false);
if (summary != null) {
rollback.setDimensions(BlockVector3.at(summary.minX, 0, summary.minZ), BlockVector3.at(summary.maxX, 255, summary.maxZ));
rollback.setTime(historyFile.lastModified());
RollbackDatabase db = DBHandler.IMP.getDatabase(world);
db.logEdit(rollback);
player.print(BBC.getPrefix() + "Logging: " + historyFile);
}
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
continue;
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
continue;
}
}
}
player.print(BBC.getPrefix() + "Done import!");
return;
}
String toParse = user.substring(1);
if (!MathMan.isInteger(toParse)) {
BBC.COMMAND_SYNTAX.send(player, "/frb #<index>");
return;
}
int index = Integer.parseInt(toParse);
final World world = player.getWorld();
UUID uuid = player.getUniqueId();
DiskStorageHistory file = new DiskStorageHistory(world, uuid, index);
if (file.getBDFile().exists()) {
if (restore) file.redo(FawePlayer.wrap(player));
else file.undo(FawePlayer.wrap(player));
BBC.ROLLBACK_ELEMENT.send(player, Fawe.imp().getWorldName(world) + "/" + user + "-" + index);
} else {
BBC.TOOL_INSPECT_INFO_FOOTER.send(player, 0);
}
player.print(BBC.getPrefix() + "Done import!");
return;
}
String toParse = user.substring(1);
if (!MathMan.isInteger(toParse)) {
BBC.COMMAND_SYNTAX.send(player, "/frb #<index>");
return;
}
int index = Integer.parseInt(toParse);
final World world = player.getWorld();
UUID uuid = player.getUniqueId();
DiskStorageHistory file = new DiskStorageHistory(world, uuid, index);
if (file.getBDFile().exists()) {
if (restore) file.redo(FawePlayer.wrap(player));
else file.undo(FawePlayer.wrap(player), null);
BBC.ROLLBACK_ELEMENT.send(player, Fawe.imp().getWorldName(world) + "/" + user + "-" + index);
} else {
BBC.TOOL_INSPECT_INFO_FOOTER.send(player, 0);
}
return;
}
UUID other = Fawe.imp().getUUID(user);
if (other == null) {
@ -197,11 +196,16 @@ public class HistoryCommands extends MethodCommands {
BBC.ROLLBACK_ELEMENT.send(player, Fawe.imp().getWorldName(edit.getWorld()) + "/" + user + "-" + edit.getIndex());
count.incrementAndGet();
}
}, () -> BBC.TOOL_INSPECT_INFO_FOOTER.send(player, count), true, restore);
}, new Runnable() {
@Override
public void run() {
BBC.TOOL_INSPECT_INFO_FOOTER.send(player, count);
}
}, true, restore);
}
@Command(
aliases = { "/fawerestore", "/frestore" },
aliases = {"/fawerestore", "/frestore"},
usage = "<user=Empire92|*> <radius=5> <time=3d4h>",
desc = "Redo a specific edit. " +
" - The time uses s, m, h, d, y.\n" +
@ -215,30 +219,30 @@ public class HistoryCommands extends MethodCommands {
}
@Command(
aliases = { "/undo", "undo" },
usage = "[times] [player]",
desc = "Undoes the last action",
min = 0,
max = 2
aliases = {"/undo", "undo"},
usage = "[times] [player]",
desc = "Undoes the last action",
min = 0,
max = 2
)
@CommandPermissions("worldedit.history.undo")
public void undo(Player player, LocalSession session, CommandContext args) throws WorldEditException {
public void undo(Player player, LocalSession session, CommandContext context) throws WorldEditException {
if (session.hasFastMode()) {
BBC.COMMAND_UNDO_DISABLED.send(player);
return;
}
int times = Math.max(1, args.getInteger(0, 1));
int times = Math.max(1, context.getInteger(0, 1));
FawePlayer.wrap(player).checkConfirmation(() -> {
EditSession undone = null;
int i = 0;
for (; i < times; ++i) {
if (args.argsLength() < 2) {
if (context.argsLength() < 2) {
undone = session.undo(session.getBlockBag(player), player);
} else {
player.checkPermission("worldedit.history.undo.other");
LocalSession sess = worldEdit.getSessionManager().findByName(args.getString(1));
LocalSession sess = worldEdit.getSessionManager().findByName(context.getString(1));
if (sess == null) {
BBC.COMMAND_HISTORY_OTHER_ERROR.send(player, args.getString(1));
BBC.COMMAND_HISTORY_OTHER_ERROR.send(player, context.getString(1));
break;
}
undone = sess.undo(session.getBlockBag(player), player);
@ -253,19 +257,18 @@ public class HistoryCommands extends MethodCommands {
if (undone == null) {
BBC.COMMAND_UNDO_ERROR.send(player);
}
}, getArguments(args), times, 50, args);
}, getArguments(context), times, 50, context);
}
@Command(
aliases = { "/redo", "redo" },
usage = "[times] [player]",
desc = "Redoes the last action (from history)",
min = 0,
max = 2
aliases = {"/redo", "redo"},
usage = "[times] [player]",
desc = "Redoes the last action (from history)",
min = 0,
max = 2
)
@CommandPermissions("worldedit.history.redo")
public void redo(Player player, LocalSession session, CommandContext args) throws WorldEditException {
int times = Math.max(1, args.getInteger(0, 1));
EditSession redone = null;
@ -295,11 +298,11 @@ public class HistoryCommands extends MethodCommands {
}
@Command(
aliases = { "/clearhistory", "clearhistory" },
usage = "",
desc = "Clear your history",
min = 0,
max = 0
aliases = {"/clearhistory", "clearhistory"},
usage = "",
desc = "Clear your history",
min = 0,
max = 0
)
@CommandPermissions("worldedit.history.clear")
public void clearHistory(Player player, LocalSession session) throws WorldEditException {
@ -308,4 +311,4 @@ public class HistoryCommands extends MethodCommands {
}
}
}

View File

@ -65,16 +65,16 @@ public class NavigationCommands {
)
@CommandPermissions("worldedit.navigation.unstuck")
public void unstuck(Player player) throws WorldEditException {
BBC.UNSTUCK.send(player);
player.findFreePosition();
BBC.UNSTUCK.send(player);
}
@Command(
aliases = { "ascend", "asc" },
usage = "[# of levels]",
desc = "Go up a floor",
min = 0,
max = 1
aliases = {"ascend", "asc"},
usage = "[# of levels]",
desc = "Go up a floor",
min = 0,
max = 1
)
@CommandPermissions("worldedit.navigation.ascend")
public void ascend(Player player, @Optional("1") int levelsToAscend) throws WorldEditException {
@ -97,11 +97,11 @@ public class NavigationCommands {
}
@Command(
aliases = { "descend", "desc" },
usage = "[# of floors]",
desc = "Go down a floor",
min = 0,
max = 1
aliases = {"descend", "desc"},
usage = "[# of floors]",
desc = "Go down a floor",
min = 0,
max = 1
)
@CommandPermissions("worldedit.navigation.descend")
public void descend(Player player, @Optional("1") int levelsToDescend) throws WorldEditException {
@ -124,19 +124,19 @@ public class NavigationCommands {
}
@Command(
aliases = { "ceil" },
usage = "[clearance]",
desc = "Go to the celing",
flags = "fg",
min = 0,
max = 1
aliases = {"ceil"},
usage = "[clearance]",
desc = "Go to the celing",
flags = "fg",
min = 0,
max = 1
)
@CommandPermissions("worldedit.navigation.ceiling")
@Logging(POSITION)
public void ceiling(Player player, CommandContext args) throws WorldEditException {
final int clearance = args.argsLength() > 0 ?
Math.max(0, args.getInteger(0)) : 0;
Math.max(0, args.getInteger(0)) : 0;
final boolean alwaysGlass = getAlwaysGlass(args);
if (player.ascendToCeiling(clearance, alwaysGlass)) {
@ -147,11 +147,11 @@ public class NavigationCommands {
}
@Command(
aliases = { "thru" },
usage = "",
desc = "Passthrough walls",
min = 0,
max = 0
aliases = {"thru"},
usage = "",
desc = "Passthrough walls",
min = 0,
max = 0
)
@CommandPermissions("worldedit.navigation.thru.command")
public void thru(Player player) throws WorldEditException {
@ -163,7 +163,7 @@ public class NavigationCommands {
}
@Command(
aliases = { "jumpto", "j" },
aliases = {"jumpto", "j"},
usage = "[world,x,y,z]",
desc = "Teleport to a location\n" +
"Flags:" +
@ -197,12 +197,12 @@ public class NavigationCommands {
}
@Command(
aliases = { "up" },
usage = "<block>",
desc = "Go upwards some distance",
flags = "fg",
min = 1,
max = 1
aliases = {"up"},
usage = "<number>",
desc = "Go upwards some distance",
flags = "fg",
min = 1,
max = 1
)
@CommandPermissions("worldedit.navigation.up")
@Logging(POSITION)
@ -231,4 +231,6 @@ public class NavigationCommands {
return forceGlass || (config.navigationUseGlass && !forceFlight);
}
}

View File

@ -220,14 +220,14 @@ public class RegionCommands extends MethodCommands {
}
@Command(
aliases = { "/line" },
aliases = {"/line"},
usage = "<pattern> [thickness]",
desc = "Draws a line segment between cuboid selection corners",
help =
"Draws a line segment between cuboid selection corners.\n" +
"Can only be used with cuboid selections.\n" +
"Flags:\n" +
" -h generates only a shell",
"Draws a line segment between cuboid selection corners.\n" +
"Can only be used with cuboid selections.\n" +
"Flags:\n" +
" -h generates only a shell",
flags = "h",
min = 1,
max = 2
@ -241,7 +241,7 @@ public class RegionCommands extends MethodCommands {
@Switch('h') boolean shell) throws WorldEditException {
if (!(region instanceof CuboidRegion)) {
player.printError("//line only works with cuboid selections");
player.printError(BBC.getPrefix() + "//line only works with cuboid selections");
return;
}
@ -254,14 +254,14 @@ public class RegionCommands extends MethodCommands {
}
@Command(
aliases = { "/curve", "/spline" },
aliases = {"/curve", "/spline"},
usage = "<pattern> [thickness]",
desc = "Draws a spline through selected points",
help =
"Draws a spline through selected points.\n" +
"Can only be used with convex polyhedral selections.\n" +
"Flags:\n" +
" -h generates only a shell",
"Draws a spline through selected points.\n" +
"Can only be used with convex polyhedral selections.\n" +
"Flags:\n" +
" -h generates only a shell",
flags = "h",
min = 1,
max = 2
@ -275,7 +275,7 @@ public class RegionCommands extends MethodCommands {
@Switch('h') boolean shell,
CommandContext context) throws WorldEditException {
if (!(region instanceof ConvexPolyhedralRegion)) {
player.toWorldEditPlayer().printError("//curve only works with convex polyhedral selections");
player.sendMessage(BBC.getPrefix() + "//curve only works with convex polyhedral selections");
return;
}
worldEdit.checkMaxRadius(thickness);
@ -293,10 +293,10 @@ public class RegionCommands extends MethodCommands {
@Command(
aliases = { "/replace", "/re", "/rep" },
usage = "[from-mask] <to-pattern>",
desc = "Replace all blocks in the selection with another",
flags = "f",
min = 1,
max = 2
desc = "Replace all blocks in the selection with another",
flags = "f",
min = 1,
max = 2
)
@CommandPermissions("worldedit.region.replace")
@Logging(REGION)
@ -336,11 +336,11 @@ public class RegionCommands extends MethodCommands {
}
@Command(
aliases = { "/overlay" },
usage = "<pattern>",
desc = "Set a block on top of blocks in the region",
min = 1,
max = 1
aliases = {"/overlay"},
usage = "<pattern>",
desc = "Set a block on top of blocks in the region",
min = 1,
max = 1
)
@CommandPermissions("worldedit.region.overlay")
@Logging(REGION)
@ -386,11 +386,11 @@ public class RegionCommands extends MethodCommands {
}
@Command(
aliases = { "/center", "/middle" },
usage = "<pattern>",
desc = "Set the center block(s)",
min = 1,
max = 1
aliases = {"/center", "/middle"},
usage = "<pattern>",
desc = "Set the center block(s)",
min = 1,
max = 1
)
@Logging(REGION)
@CommandPermissions("worldedit.region.center")
@ -400,11 +400,11 @@ public class RegionCommands extends MethodCommands {
}
@Command(
aliases = { "/naturalize" },
usage = "",
desc = "3 layers of dirt on top then rock below",
min = 0,
max = 0
aliases = {"/naturalize"},
usage = "",
desc = "3 layers of dirt on top then rock below",
min = 0,
max = 0
)
@CommandPermissions("worldedit.region.naturalize")
@Logging(REGION)
@ -416,11 +416,11 @@ public class RegionCommands extends MethodCommands {
}
@Command(
aliases = { "/walls" },
usage = "<pattern>",
desc = "Build the four sides of the selection",
min = 1,
max = 1
aliases = {"/walls"},
usage = "<pattern>",
desc = "Build the four sides of the selection",
min = 1,
max = 1
)
@CommandPermissions("worldedit.region.walls")
@Logging(REGION)
@ -432,11 +432,11 @@ public class RegionCommands extends MethodCommands {
}
@Command(
aliases = { "/faces", "/outline" },
usage = "<pattern>",
desc = "Build the walls, ceiling, and floor of a selection",
min = 1,
max = 1
aliases = {"/faces", "/outline"},
usage = "<pattern>",
desc = "Build the walls, ceiling, and floor of a selection",
min = 1,
max = 1
)
@CommandPermissions("worldedit.region.faces")
@Logging(REGION)
@ -458,7 +458,7 @@ public class RegionCommands extends MethodCommands {
min = 0,
max = 2
)
@CommandPermissions("worldedit.region.smooth")
@CommandPermissions("worldedit.region.smoothsnow")
@Logging(REGION)
public void smooth(FawePlayer player, EditSession editSession, @Selection Region region, @Optional("1") int iterations, @Optional Mask mask, @Switch('s') boolean snow, CommandContext context) throws WorldEditException {
BlockVector3 min = region.getMinimumPoint();
@ -514,23 +514,23 @@ public class RegionCommands extends MethodCommands {
@Command(
aliases = { "/move" },
usage = "[count] [direction] [leave-id]",
flags = "sabe",
desc = "Move the contents of the selection",
help =
"Moves the contents of the selection.\n" +
"The -s flag shifts the selection to the target location.\n" +
" -b also copies biomes\n" +
" -e ignores entities\n" +
"The -a flag skips air blocks.\n" +
"Optionally fills the old location with <leave-id>.",
min = 0,
max = 3
aliases = {"/move"},
usage = "[count] [direction] [leave-id]",
flags = "sbea",
desc = "Move the contents of the selection",
help =
"Moves the contents of the selection.\n" +
"The -s flag shifts the selection to the target location.\n" +
" -b also copies biomes\n" +
" -e ignores entities\n" +
" -a ignores air\n" +
"Optionally fills the old location with <leave-id>.",
min = 0,
max = 3
)
@CommandPermissions("worldedit.region.move")
@Logging(ORIENTATION_REGION)
public void move(FawePlayer player, EditSession editSession, LocalSession session,
public void move(FawePlayer player, LocalSession session, EditSession editSession,
@Selection Region region,
@Optional("1") @Range(min = 1) int count,
@Optional(Direction.AIM) @Direction(includeDiagonals = true) BlockVector3 direction,
@ -550,7 +550,7 @@ public class RegionCommands extends MethodCommands {
session.getRegionSelector(player.getWorld()).learnChanges();
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player.getPlayer(), session);
} catch (RegionOperationException e) {
player.toWorldEditPlayer().printError(e.getMessage());
player.sendMessage(BBC.getPrefix() + e.getMessage());
}
}
@ -583,21 +583,21 @@ public class RegionCommands extends MethodCommands {
}
@Command(
aliases = { "/stack" },
usage = "[count] [direction]",
flags = "sam",
desc = "Repeat the contents of the selection",
help =
"Repeats the contents of the selection.\n" +
"Flags:\n" +
" -s shifts the selection to the last stacked copy\n" +
" -a skips air blocks",
min = 0,
max = 2
aliases = {"/stack"},
usage = "[count] [direction]",
flags = "sam",
desc = "Repeat the contents of the selection",
help =
"Repeats the contents of the selection.\n" +
"Flags:\n" +
" -s shifts the selection to the last stacked copy\n" +
" -a skips air blocks",
min = 0,
max = 2
)
@CommandPermissions("worldedit.region.stack")
@Logging(ORIENTATION_REGION)
public void stack(FawePlayer player, EditSession editSession, LocalSession session,
public void stack(FawePlayer player, LocalSession session, EditSession editSession,
@Selection Region region,
@Optional("1") @Range(min = 1) int count,
@Optional(Direction.AIM) @Direction(includeDiagonals = true) BlockVector3 direction,
@ -620,7 +620,7 @@ public class RegionCommands extends MethodCommands {
session.getRegionSelector(player.getWorld()).learnChanges();
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player.getPlayer(), session);
} catch (RegionOperationException e) {
player.sendMessage(e.getMessage());
player.sendMessage(BBC.getPrefix() + e.getMessage());
}
}
@ -629,14 +629,14 @@ public class RegionCommands extends MethodCommands {
}
@Command(
aliases = { "/deform" },
aliases = {"/deform"},
usage = "<expression>",
desc = "Deforms a selected region with an expression",
help =
"Deforms a selected region with an expression\n" +
"The expression is executed for each block and is expected\n" +
"to modify the variables x, y and z to point to a new block\n" +
"to fetch. See also tinyurl.com/wesyntax.",
"Deforms a selected region with an expression\n" +
"The expression is executed for each block and is expected\n" +
"to modify the variables x, y and z to point to a new block\n" +
"to fetch. See also tinyurl.com/wesyntax.",
flags = "ro",
min = 1,
max = -1
@ -647,10 +647,10 @@ public class RegionCommands extends MethodCommands {
@Selection Region region,
@Text String expression,
@Switch('r') boolean useRawCoords,
@Switch('o') boolean offset, CommandContext context) throws WorldEditException {
@Switch('o') boolean offset,
CommandContext context) throws WorldEditException {
final Vector3 zero;
Vector3 unit;
if (useRawCoords) {
zero = Vector3.ZERO;
unit = Vector3.ONE;
@ -676,7 +676,7 @@ public class RegionCommands extends MethodCommands {
player.findFreePosition();
BBC.VISITOR_BLOCK.send(fp, affected);
} catch (ExpressionException e) {
fp.sendMessage(e.getMessage());
fp.sendMessage(BBC.getPrefix() + e.getMessage());
}
}, getArguments(context), region, context);
}
@ -727,15 +727,15 @@ public class RegionCommands extends MethodCommands {
}
@Command(
aliases = { "/hollow" },
usage = "[<thickness>[ <pattern>]]",
desc = "Hollows out the object contained in this selection",
help =
"Hollows out the object contained in this selection.\n" +
"Optionally fills the hollowed out part with the given block.\n" +
"Thickness is measured in manhattan distance.",
min = 0,
max = 2
aliases = {"/hollow"},
usage = "[<thickness>[ <pattern>]]",
desc = "Hollows out the object contained in this selection",
help =
"Hollows out the object contained in this selection.\n" +
"Optionally fills the hollowed out part with the given block.\n" +
"Thickness is measured in manhattan distance.",
min = 0,
max = 2
)
@CommandPermissions("worldedit.region.hollow")
@Logging(REGION)
@ -751,7 +751,7 @@ public class RegionCommands extends MethodCommands {
}
@Command(
aliases = { "/forest" },
aliases = {"/forest"},
usage = "[type] [density]",
desc = "Make a forest within the region",
min = 0,
@ -766,7 +766,7 @@ public class RegionCommands extends MethodCommands {
}
@Command(
aliases = { "/flora" },
aliases = {"/flora"},
usage = "[density]",
desc = "Make flora within the region",
min = 0,
@ -776,14 +776,15 @@ public class RegionCommands extends MethodCommands {
@Logging(REGION)
public void flora(FawePlayer player, EditSession editSession, @Selection Region region, @Optional("10") @Range(min = 0, max = 100) double density, CommandContext context) throws WorldEditException {
player.checkConfirmationRegion(() -> {
FloraGenerator generator = new FloraGenerator(editSession);
GroundFunction ground = new GroundFunction(new ExistingBlockMask(editSession), generator);
LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground);
visitor.setMask(new NoiseFilter2D(new RandomNoise(), density / 100));
Operations.completeLegacy(visitor);
FloraGenerator generator = new FloraGenerator(editSession);
GroundFunction ground = new GroundFunction(new ExistingBlockMask(editSession), generator);
LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground);
visitor.setMask(new NoiseFilter2D(new RandomNoise(), density / 100));
Operations.completeLegacy(visitor);
BBC.COMMAND_FLORA.send(player, ground.getAffected());
}, getArguments(context), region, context);
}
}

View File

@ -29,22 +29,21 @@ import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.CommandManager;
import com.sk89q.worldedit.scripting.CraftScriptContext;
import com.sk89q.worldedit.scripting.CraftScriptEngine;
import com.sk89q.worldedit.scripting.RhinoCraftScriptEngine;
import com.sk89q.worldedit.session.request.Request;
import org.mozilla.javascript.NativeJavaObject;
import javax.annotation.Nullable;
import javax.script.ScriptException;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.ALL;
@ -62,7 +61,7 @@ public class ScriptingCommands {
*
* @param worldEdit reference to WorldEdit
*/
public ScriptingCommands(WorldEdit worldEdit) {
public ScriptingCommands(final WorldEdit worldEdit) {
checkNotNull(worldEdit);
this.worldEdit = worldEdit;
}
@ -79,12 +78,16 @@ public class ScriptingCommands {
}
public static <T> T runScript(Player player, File f, String[] args) throws WorldEditException {
return runScript(player, f, args, null);
}
public static <T> T runScript(Actor actor, File f, String[] args, @Nullable Function<String, String> processor) throws WorldEditException {
String filename = f.getPath();
int index = filename.lastIndexOf(".");
String ext = filename.substring(index + 1);
String ext = filename.substring(index + 1, filename.length());
if (!ext.equalsIgnoreCase("js")) {
player.printError("Only .js scripts are currently supported");
actor.printError(BBC.getPrefix() + "Only .js scripts are currently supported");
return null;
}
@ -97,63 +100,69 @@ public class ScriptingCommands {
file = WorldEdit.class.getResourceAsStream("craftscripts/" + filename);
if (file == null) {
player.printError("Script does not exist: " + filename);
actor.printError(BBC.getPrefix() + "Script does not exist: " + filename);
return null;
}
} else {
file = new FileInputStream(f);
}
byte[] data;
try (DataInputStream in = new DataInputStream(file)) {
data = new byte[in.available()];
in.readFully(data);
}
script = new String(data, 0, data.length, StandardCharsets.UTF_8);
DataInputStream in = new DataInputStream(file);
byte[] data = new byte[in.available()];
in.readFully(data);
in.close();
script = new String(data, 0, data.length, "utf-8");
} catch (IOException e) {
player.printError("Script read error: " + e.getMessage());
actor.printError(BBC.getPrefix() + "Script read error: " + e.getMessage());
return null;
}
WorldEdit worldEdit1 = WorldEdit.getInstance();
LocalSession session = worldEdit1.getSessionManager().get(player);
if (processor != null) {
script = processor.apply(script);
}
CraftScriptEngine engine;
WorldEdit worldEdit = WorldEdit.getInstance();
LocalSession session = worldEdit.getSessionManager().get(actor);
CraftScriptEngine engine = null;
Object result = null;
try {
engine = new RhinoCraftScriptEngine();
} catch (NoClassDefFoundError e) {
player.printError("Failed to find an installed script engine.");
player.printError("Download: https://github.com/downloads/mozilla/rhino/rhino1_7R4.zip");
player.printError("Extract: `js.jar` to `plugins` or `mods` directory`");
player.printError("More info: https://github.com/boy0001/CraftScripts/");
actor.printError("Failed to find an installed script engine.");
actor.printError("Download: https://github.com/downloads/mozilla/rhino/rhino1_7R4.zip");
actor.printError("Extract: `js.jar` to `plugins` or `mods` directory`");
actor.printError("More info: https://github.com/boy0001/CraftScripts/");
return null;
}
engine.setTimeLimit(worldEdit1.getConfiguration().scriptTimeout);
engine.setTimeLimit(worldEdit.getConfiguration().scriptTimeout);
CraftScriptContext scriptContext = new CraftScriptContext(worldEdit1, worldEdit1.getPlatformManager().queryCapability(Capability.USER_COMMANDS),
worldEdit1.getConfiguration(), session, player, args);
Player player = actor instanceof Player ? (Player) actor : null;
CraftScriptContext scriptContext = new CraftScriptContext(worldEdit, WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.USER_COMMANDS),
WorldEdit.getInstance().getConfiguration(), session, player, args);
Map<String, Object> vars = new HashMap<>();
vars.put("argv", args);
vars.put("context", scriptContext);
vars.put("actor", player);
vars.put("actor", actor);
vars.put("player", player);
try {
result = engine.evaluate(script, filename, vars);
} catch (ScriptException e) {
e.printStackTrace();
player.printError(BBC.getPrefix() + "Failed to execute:");
player.printRaw(e.getMessage());
} catch (NumberFormatException | WorldEditException e) {
actor.printError(BBC.getPrefix() + "Failed to execute:");
actor.printRaw(e.getMessage());
} catch (NumberFormatException e) {
throw e;
} catch (WorldEditException e) {
throw e;
} catch (Throwable e) {
player.printError("Failed to execute (see console):");
player.printRaw(e.getClass().getCanonicalName());
actor.printError(BBC.getPrefix() + "Failed to execute (see console):");
actor.printRaw(e.getClass().getCanonicalName());
e.printStackTrace();
}
if (result instanceof NativeJavaObject) {
@ -162,19 +171,12 @@ public class ScriptingCommands {
return (T) result;
}
@Command(
aliases = { "cs" },
usage = "<filename> [args...]",
desc = "Execute a CraftScript",
min = 1,
max = -1
)
@Command(aliases = {"cs"}, usage = "<filename> [args...]", desc = "Execute a CraftScript", min = 1, max = -1)
@CommandPermissions("worldedit.scripting.execute")
@Logging(ALL)
public void execute(Player player, LocalSession session, CommandContext args) throws WorldEditException {
String[] scriptArgs = args.getSlice(1);
String name = args.getString(0);
public void execute(final Player player, final LocalSession session, final CommandContext args) throws WorldEditException {
final String[] scriptArgs = args.getSlice(1);
final String name = args.getString(0);
if (!player.hasPermission("worldedit.scripting.execute." + name)) {
BBC.SCRIPTING_NO_PERM.send(player);
@ -183,8 +185,8 @@ public class ScriptingCommands {
session.setLastScript(name);
File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir);
File f = worldEdit.getSafeOpenFile(player, dir, name, "js", "js");
final File dir = this.worldEdit.getWorkingDirectoryFile(this.worldEdit.getConfiguration().scriptsDir);
final File f = this.worldEdit.getSafeOpenFile(player, dir, name, "js", "js");
try {
new RhinoCraftScriptEngine();
} catch (NoClassDefFoundError e) {
@ -197,17 +199,11 @@ public class ScriptingCommands {
runScript(LocationMaskedPlayerWrapper.unwrap(player), f, scriptArgs);
}
@Command(
aliases = { ".s" },
usage = "[args...]",
desc = "Execute last CraftScript",
min = 0,
max = -1
)
@Command(aliases = {".s"}, usage = "[args...]", desc = "Execute last CraftScript", min = 0, max = -1)
@CommandPermissions("worldedit.scripting.execute")
@Logging(ALL)
public void executeLast(Player player, LocalSession session, CommandContext args) throws WorldEditException {
String lastScript = session.getLastScript();
if (!player.hasPermission("worldedit.scripting.execute." + lastScript)) {
@ -220,11 +216,17 @@ public class ScriptingCommands {
return;
}
String[] scriptArgs = args.getSlice(0);
final String[] scriptArgs = args.getSlice(0);
File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir);
File f = worldEdit.getSafeOpenFile(player, dir, lastScript, "js", "js");
final File dir = this.worldEdit.getWorkingDirectoryFile(this.worldEdit.getConfiguration().scriptsDir);
final File f = this.worldEdit.getSafeOpenFile(player, dir, lastScript, "js", "js");
worldEdit.runScript(player, f, scriptArgs);
try {
this.worldEdit.runScript(LocationMaskedPlayerWrapper.unwrap(player), f, scriptArgs);
} catch (final WorldEditException ex) {
BBC.SCRIPTING_ERROR.send(player);
}
}
}

View File

@ -94,11 +94,11 @@ public class SelectionCommands {
}
@Command(
aliases = { "/pos1", "posa", "/1" },
usage = "[coordinates]",
desc = "Set position 1",
min = 0,
max = 1
aliases = {"/pos1", "posa", "/1"},
usage = "[coordinates]",
desc = "Set position 1",
min = 0,
max = 1
)
@Logging(POSITION)
@CommandPermissions("worldedit.selection.pos")
@ -123,16 +123,15 @@ public class SelectionCommands {
return;
}
session.getRegionSelector(player.getWorld())
.explainPrimarySelection(player, session, pos);
session.getRegionSelector(player.getWorld()).explainPrimarySelection(player, session, pos);
}
@Command(
aliases = { "/pos2", "posb", "/2" },
usage = "[coordinates]",
desc = "Set position 2",
min = 0,
max = 1
aliases = {"/pos2", "posb", "/2"},
usage = "[coordinates]",
desc = "Set position 2",
min = 0,
max = 1
)
@Logging(POSITION)
@CommandPermissions("worldedit.selection.pos")
@ -163,40 +162,38 @@ public class SelectionCommands {
}
@Command(
aliases = { "/hpos1" },
usage = "",
desc = "Set position 1 to targeted block",
min = 0,
max = 0
aliases = {"/hpos1"},
usage = "",
desc = "Set position 1 to targeted block",
min = 0,
max = 0
)
@CommandPermissions("worldedit.selection.hpos")
public void hpos1(Player player, LocalSession session) throws WorldEditException {
Location pos = player.getBlockTrace(300);
public void hpos1(Player player, LocalSession session, CommandContext args) throws WorldEditException {
BlockVector3 pos = player.getBlockTrace(300).toBlockPoint();
if (pos != null) {
if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(player))) {
if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos, ActorSelectorLimits.forActor(player))) {
BBC.SELECTOR_ALREADY_SET.send(player);
return;
}
session.getRegionSelector(player.getWorld())
.explainPrimarySelection(player, session, pos.toVector().toBlockPoint());
.explainPrimarySelection(player, session, pos);
} else {
BBC.NO_BLOCK.send(player);
}
}
@Command(
aliases = { "/hpos2" },
usage = "",
desc = "Set position 2 to targeted block",
min = 0,
max = 0
aliases = {"/hpos2"},
usage = "",
desc = "Set position 2 to targeted block",
min = 0,
max = 0
)
@CommandPermissions("worldedit.selection.hpos")
public void hpos2(Player player, LocalSession session) throws WorldEditException {
public void hpos2(Player player, LocalSession session, CommandContext args) throws WorldEditException {
BlockVector3 pos = player.getBlockTrace(300).toBlockPoint();
if (pos != null) {
@ -213,20 +210,20 @@ public class SelectionCommands {
}
@Command(
aliases = { "/chunk" },
usage = "[x,z coordinates]",
flags = "sc",
desc = "Set the selection to your current chunk.",
help =
"Set the selection to the chunk you are currently in.\n" +
"With the -s flag, your current selection is expanded\n" +
"to encompass all chunks that are part of it.\n\n" +
"Specifying coordinates will use those instead of your\n"+
"current position. Use -c to specify chunk coordinates,\n" +
"otherwise full coordinates will be implied.\n" +
"(for example, the coordinates 5,5 are the same as -c 0,0)",
min = 0,
max = 1
aliases = {"/chunk"},
usage = "[x,z coordinates]",
flags = "sc",
desc = "Set the selection to your current chunk.",
help =
"Set the selection to the chunk you are currently in.\n" +
"With the -s flag, your current selection is expanded\n" +
"to encompass all chunks that are part of it.\n\n" +
"Specifying coordinates will use those instead of your\n" +
"current position. Use -c to specify chunk coordinates,\n" +
"otherwise full coordinates will be implied.\n" +
"(for example, the coordinates 5,5 are the same as -c 0,0)",
min = 0,
max = 1
)
@Logging(POSITION)
@CommandPermissions("worldedit.selection.chunk")
@ -282,15 +279,14 @@ public class SelectionCommands {
}
@Command(
aliases = { "/wand" },
usage = "",
desc = "Get the wand object",
min = 0,
max = 0
aliases = {"/wand", "/w"},
usage = "",
desc = "Get the wand object",
min = 0,
max = 0
)
@CommandPermissions("worldedit.wand")
public void wand(Player player) throws WorldEditException {
player.giveItem(new BaseItemStack(ItemTypes.parse(we.getConfiguration().wandItem), 1));
BBC.SELECTION_WAND.send(player);
if (!FawePlayer.wrap(player).hasPermission("fawe.tips"))
@ -298,11 +294,11 @@ public class SelectionCommands {
}
@Command(
aliases = { "toggleeditwand" },
usage = "",
desc = "Toggle functionality of the edit wand",
min = 0,
max = 0
aliases = {"toggleeditwand"},
usage = "",
desc = "Toggle functionality of the edit wand",
min = 0,
max = 0
)
@CommandPermissions("worldedit.wand.toggle")
public void toggleWand(Player player, LocalSession session, CommandContext args) throws WorldEditException {
@ -317,11 +313,11 @@ public class SelectionCommands {
}
@Command(
aliases = { "/expand" },
usage = "<amount> [reverse-amount] <direction>",
desc = "Expand the selection area",
min = 1,
max = 3
aliases = {"/expand"},
usage = "<amount> [reverse-amount] <direction>",
desc = "Expand the selection area",
min = 1,
max = 3
)
@Logging(REGION)
@CommandPermissions("worldedit.selection.expand")
@ -329,8 +325,7 @@ public class SelectionCommands {
// Special syntax (//expand vert) to expand the selection between
// sky and bedrock.
if (args.getString(0).equalsIgnoreCase("vert")
|| args.getString(0).equalsIgnoreCase("vertical")) {
if (args.getString(0).equalsIgnoreCase("vert") || args.getString(0).equalsIgnoreCase("vertical")) {
Region region = session.getSelection(player.getWorld());
try {
int oldSize = region.getArea();
@ -347,7 +342,6 @@ public class SelectionCommands {
return;
}
List<BlockVector3> dirs = new ArrayList<>();
int change = args.getInteger(0);
int reverseChange = 0;
@ -406,16 +400,15 @@ public class SelectionCommands {
int newSize = region.getArea();
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
BBC.SELECTION_EXPAND.send(player, (newSize - oldSize));
}
@Command(
aliases = { "/contract" },
usage = "<amount> [reverse-amount] [direction]",
desc = "Contract the selection area",
min = 1,
max = 3
aliases = {"/contract"},
usage = "<amount> [reverse-amount] [direction]",
desc = "Contract the selection area",
min = 1,
max = 3
)
@Logging(REGION)
@CommandPermissions("worldedit.selection.contract")
@ -485,11 +478,11 @@ public class SelectionCommands {
}
@Command(
aliases = { "/shift" },
usage = "<amount> [direction]",
desc = "Shift the selection area",
min = 1,
max = 2
aliases = {"/shift"},
usage = "<amount> [direction]",
desc = "Shift the selection area",
min = 1,
max = 2
)
@Logging(REGION)
@CommandPermissions("worldedit.selection.shift")
@ -519,7 +512,6 @@ public class SelectionCommands {
session.getRegionSelector(player.getWorld()).learnChanges();
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
BBC.SELECTION_SHIFT.send(player);
} catch (RegionOperationException e) {
player.printError(e.getMessage());
@ -527,17 +519,17 @@ public class SelectionCommands {
}
@Command(
aliases = { "/outset" },
usage = "<amount>",
desc = "Outset the selection area",
help =
"Expands the selection by the given amount in all directions.\n" +
"Flags:\n" +
" -h only expand horizontally\n" +
" -v only expand vertically\n",
flags = "hv",
min = 1,
max = 1
aliases = {"/outset"},
usage = "<amount>",
desc = "Outset the selection area",
help =
"Expands the selection by the given amount in all directions.\n" +
"Flags:\n" +
" -h only expand horizontally\n" +
" -v only expand vertically\n",
flags = "hv",
min = 1,
max = 1
)
@Logging(REGION)
@CommandPermissions("worldedit.selection.outset")
@ -550,17 +542,17 @@ public class SelectionCommands {
}
@Command(
aliases = { "/inset" },
usage = "<amount>",
desc = "Inset the selection area",
help =
"Contracts the selection by the given amount in all directions.\n" +
"Flags:\n" +
" -h only contract horizontally\n" +
" -v only contract vertically\n",
flags = "hv",
min = 1,
max = 1
aliases = {"/inset"},
usage = "<amount>",
desc = "Inset the selection area",
help =
"Contracts the selection by the given amount in all directions.\n" +
"Flags:\n" +
" -h only contract horizontally\n" +
" -v only contract vertically\n",
flags = "hv",
min = 1,
max = 1
)
@Logging(REGION)
@CommandPermissions("worldedit.selection.inset")
@ -577,32 +569,33 @@ public class SelectionCommands {
int change = args.getInteger(0);
if (!args.hasFlag('h')) {
changes.add((BlockVector3.UNIT_Y).multiply(change));
changes.add((BlockVector3.UNIT_MINUS_Y).multiply(change));
changes.add((BlockVector3.at(0, 1, 0)).multiply(change));
changes.add((BlockVector3.at(0, -1, 0)).multiply(change));
}
if (!args.hasFlag('v')) {
changes.add((BlockVector3.UNIT_X).multiply(change));
changes.add((BlockVector3.UNIT_MINUS_X).multiply(change));
changes.add((BlockVector3.UNIT_Z).multiply(change));
changes.add((BlockVector3.UNIT_MINUS_Z).multiply(change));
changes.add((BlockVector3.at(1, 0, 0)).multiply(change));
changes.add((BlockVector3.at(-1, 0, 0)).multiply(change));
changes.add((BlockVector3.at(0, 0, 1)).multiply(change));
changes.add((BlockVector3.at(0, 0, -1)).multiply(change));
}
return changes.toArray(new BlockVector3[0]);
}
@Command(
aliases = { "/size" },
flags = "c",
usage = "",
desc = "Get information about the selection",
min = 0,
max = 0
aliases = {"/size"},
flags = "c",
usage = "",
desc = "Get information about the selection",
min = 0,
max = 0
)
@CommandPermissions("worldedit.selection.size")
public void size(Player player, LocalSession session, CommandContext args) throws WorldEditException {
public void size(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
if (args.hasFlag('c')) {
ClipboardHolder root = session.getClipboard();
// Clipboard clipboard = holder.getClipboard();
int index = 0;
for (ClipboardHolder holder : root.getHolders()) {
Clipboard clipboard = holder.getClipboard();
@ -675,12 +668,12 @@ public class SelectionCommands {
@Command(
aliases = { "/count" },
usage = "<mask>",
flags = "d",
desc = "Counts the number of a certain type of block",
min = 1,
max = 1
aliases = {"/count"},
usage = "<mask>",
desc = "Counts the number of a certain type of block",
flags = "d",
min = 1,
max = 1
)
@CommandPermissions("worldedit.analysis.count")
public void count(Player player, LocalSession session, EditSession editSession, Mask mask) throws WorldEditException {
@ -689,25 +682,23 @@ public class SelectionCommands {
}
@Command(
aliases = { "/distr" },
usage = "",
desc = "Get the distribution of blocks in the selection",
help =
"Gets the distribution of blocks in the selection.\n" +
"The -c flag gets the distribution of your clipboard.\n" +
"The -d flag separates blocks by state",
flags = "cd",
min = 0,
max = 0
aliases = {"/distr"},
usage = "",
desc = "Get the distribution of blocks in the selection",
help =
"Gets the distribution of blocks in the selection.\n" +
"The -c flag gets the distribution of your clipboard.",
flags = "c",
min = 0,
max = 0
)
@CommandPermissions("worldedit.analysis.distr")
public void distr(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException, CommandException {
public void distr(Player player, LocalSession session, EditSession editSession, @Switch('c') boolean useClipboard, @Switch('d') boolean useData) throws WorldEditException, CommandException {
int size;
List<Countable> distributionData;
boolean separateStates = args.hasFlag('d');
Region region;
if (args.hasFlag('c')) {
if (useClipboard) {
// TODO multi clipboard distribution
Clipboard clipboard = session.getClipboard().getClipboard();
region = clipboard.getRegion();
@ -715,14 +706,13 @@ public class SelectionCommands {
} else {
region = session.getSelection(player.getWorld());
}
if (separateStates) {
if (useData)
distributionData = (List) editSession.getBlockDistributionWithData(region);
} else {
else
distributionData = (List) editSession.getBlockDistribution(region);
}
size = session.getSelection(player.getWorld()).getArea();
if (distributionData.isEmpty()) { // *Should* always be false
if (distributionData.size() <= 0) {
player.printError("No blocks counted.");
return;
}
@ -739,12 +729,12 @@ public class SelectionCommands {
}
@Command(
aliases = { "/sel", ";", "/desel", "/deselect" },
flags = "d",
usage = "[cuboid|extend|poly|ellipsoid|sphere|cyl|convex]",
desc = "Choose a region selector",
min = 0,
max = 1
aliases = {"/sel", ";", "/desel", "/deselect"},
flags = "d",
usage = "[cuboid|extend|poly|ellipsoid|sphere|cyl|convex]",
desc = "Choose a region selector",
min = 0,
max = 1
)
public void select(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
final World world = player.getWorld();
@ -848,4 +838,5 @@ public class SelectionCommands {
session.dispatchCUISelection(player);
}
}

View File

@ -56,7 +56,7 @@ public class SnapshotCommands {
}
@Command(
aliases = { "list" },
aliases = {"list"},
usage = "[num]",
desc = "List snapshots",
min = 0,
@ -81,7 +81,7 @@ public class SnapshotCommands {
BBC.SNAPSHOT_LIST_HEADER.send(player, player.getWorld().getName());
for (byte i = 0; i < Math.min(num, snapshots.size()); i++) {
player.print((i + 1) + ". " + snapshots.get(i).getName());
player.print(BBC.getPrefix() + (i + 1) + ". " + snapshots.get(i).getName());
}
BBC.SNAPSHOT_LIST_FOOTER.send(player);
@ -92,10 +92,10 @@ public class SnapshotCommands {
File dir = config.snapshotRepo.getDirectory();
try {
WorldEdit.logger.info("WorldEdit found no snapshots: looked in: "
WorldEdit.logger.info(BBC.getPrefix() + "WorldEdit found no snapshots: looked in: "
+ dir.getCanonicalPath());
} catch (IOException e) {
WorldEdit.logger.info("WorldEdit found no snapshots: looked in "
WorldEdit.logger.info(BBC.getPrefix() + "WorldEdit found no snapshots: looked in "
+ "(NON-RESOLVABLE PATH - does it exist?): "
+ dir.getPath());
}
@ -222,7 +222,7 @@ public class SnapshotCommands {
if (snapshot == null) {
dateFormat.setTimeZone(session.getTimeZone());
player.printError("Couldn't find a snapshot before "
player.printError(BBC.getPrefix() + "Couldn't find a snapshot before "
+ dateFormat.format(date.getTime()) + ".");
} else {
session.setSnapshot(snapshot);
@ -260,7 +260,7 @@ public class SnapshotCommands {
Snapshot snapshot = config.snapshotRepo.getSnapshotAfter(date, player.getWorld().getName());
if (snapshot == null) {
dateFormat.setTimeZone(session.getTimeZone());
player.printError("Couldn't find a snapshot after "
player.printError(BBC.getPrefix() + "Couldn't find a snapshot after "
+ dateFormat.format(date.getTime()) + ".");
} else {
session.setSnapshot(snapshot);

View File

@ -56,7 +56,6 @@ public class SnapshotUtilCommands {
aliases = { "restore", "/restore" },
usage = "[snapshot]",
desc = "Restore the selection from a snapshot",
min = 0,
max = 1
)
@Logging(REGION)
@ -112,20 +111,14 @@ public class SnapshotUtilCommands {
}
}
ChunkStore chunkStore = null;
// Load chunk store
try {
chunkStore = snapshot.getChunkStore();
SnapshotRestore restore;
try (ChunkStore chunkStore = snapshot.getChunkStore()) {
BBC.SNAPSHOT_LOADED.send(player, snapshot.getName());
} catch (DataException | IOException e) {
player.printError("Failed to load snapshot: " + e.getMessage());
return;
}
try {
// Restore snapshot
SnapshotRestore restore = new SnapshotRestore(chunkStore, editSession, region);
restore = new SnapshotRestore(chunkStore, editSession, region);
//player.print(restore.getChunksAffected() + " chunk(s) will be loaded.");
restore.restore();
@ -140,15 +133,12 @@ public class SnapshotUtilCommands {
}
} else {
player.print(String.format("Restored; %d "
+ "missing chunks and %d other errors.",
+ "missing chunks and %d other errors.",
restore.getMissingChunks().size(),
restore.getErrorChunks().size()));
}
} finally {
try {
chunkStore.close();
} catch (IOException ignored) {
}
} catch (DataException | IOException e) {
player.printError("Failed to load snapshot: " + e.getMessage());
}
}
}

View File

@ -41,11 +41,11 @@ public class SuperPickaxeCommands {
}
@Command(
aliases = { "single" },
usage = "",
desc = "Enable the single block super pickaxe mode",
min = 0,
max = 0
aliases = {"single"},
usage = "",
desc = "Enable the single block super pickaxe mode",
min = 0,
max = 0
)
@CommandPermissions("worldedit.superpickaxe")
public void single(Player player, LocalSession session) throws WorldEditException {
@ -56,11 +56,11 @@ public class SuperPickaxeCommands {
}
@Command(
aliases = { "area" },
usage = "<radius>",
desc = "Enable the area super pickaxe pickaxe mode",
min = 1,
max = 1
aliases = {"area"},
usage = "<radius>",
desc = "Enable the area super pickaxe pickaxe mode",
min = 1,
max = 1
)
@CommandPermissions("worldedit.superpickaxe.area")
public void area(Player player, LocalSession session, CommandContext args) throws WorldEditException {
@ -79,11 +79,11 @@ public class SuperPickaxeCommands {
}
@Command(
aliases = { "recur", "recursive" },
usage = "<radius>",
desc = "Enable the recursive super pickaxe pickaxe mode",
min = 1,
max = 1
aliases = {"recur", "recursive"},
usage = "<radius>",
desc = "Enable the recursive super pickaxe pickaxe mode",
min = 1,
max = 1
)
@CommandPermissions("worldedit.superpickaxe.recursive")
public void recursive(Player player, LocalSession session, CommandContext args) throws WorldEditException {

View File

@ -60,17 +60,16 @@ public class ToolCommands {
}
@Command(
aliases = { "info", "/info" },
usage = "",
desc = "Block information tool",
min = 0,
max = 0
aliases = {"info", "/info"},
usage = "",
desc = "Block information tool",
min = 0,
max = 0
)
@CommandPermissions("worldedit.tool.info")
public void info(Player player, LocalSession session) throws WorldEditException {
session.setTool(new QueryTool(), player);
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(itemStack.getType(), new QueryTool());
BBC.TOOL_INFO.send(player, itemStack.getType().getName());
}
@ -78,114 +77,104 @@ public class ToolCommands {
aliases = {"inspect"},
usage = "",
desc = "Inspect edits within a radius",
help = "Chooses the inspect brush",
help =
"Chooses the inspect brush",
min = 0,
max = 0
)
@CommandPermissions("worldedit.tool.inspect")
public void inspectBrush(Player player, LocalSession session, @Optional("1") double radius) throws WorldEditException {
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(itemStack.getType(), new InspectBrush());
BBC.TOOL_INSPECT.send(player, itemStack.getType().getName());
session.setTool(new InspectBrush(), player);
BBC.TOOL_INSPECT.send(player, player.getItemInHand(HandSide.MAIN_HAND).getType().getName());
}
@Command(
aliases = { "tree" },
usage = "[type]",
desc = "Tree generator tool",
min = 0,
max = 1
aliases = {"tree"},
usage = "[type]",
desc = "Tree generator tool",
min = 0,
max = 1
)
@CommandPermissions("worldedit.tool.tree")
@SuppressWarnings("deprecation")
public void tree(Player player, LocalSession session, @Optional("tree") TreeGenerator.TreeType type, CommandContext args) throws WorldEditException {
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(itemStack.getType(), new TreePlanter(type));
BBC.TOOL_TREE.send(player, itemStack.getType().getName());
session.setTool(new TreePlanter(type), player);
BBC.TOOL_TREE.send(player, player.getItemInHand(HandSide.MAIN_HAND).getType().getName());
}
@Command(
aliases = { "repl" },
usage = "<pattern>",
desc = "Block replacer tool",
min = 1,
max = 1
aliases = {"repl"},
usage = "<pattern>",
desc = "Block replacer tool",
min = 1,
max = 1
)
@CommandPermissions("worldedit.tool.replacer")
public void repl(Player player, LocalSession session, Pattern pattern) throws WorldEditException {
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(itemStack.getType(), new BlockReplacer(pattern));
BBC.TOOL_REPL.send(player, itemStack.getType().getName());
session.setTool(new BlockReplacer(pattern), player);
BBC.TOOL_REPL.send(player, player.getItemInHand(HandSide.MAIN_HAND).getType().getName());
}
@Command(
aliases = { "cycler" },
usage = "",
desc = "Block data cycler tool",
min = 0,
max = 0
aliases = {"cycler"},
usage = "",
desc = "Block data cycler tool",
min = 0,
max = 0
)
@CommandPermissions("worldedit.tool.data-cycler")
public void cycler(Player player, LocalSession session) throws WorldEditException {
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(itemStack.getType(), new BlockDataCyler());
BBC.TOOL_CYCLER.send(player, itemStack.getType().getName());
session.setTool(new BlockDataCyler(), player);
BBC.TOOL_CYCLER.send(player, player.getItemInHand(HandSide.MAIN_HAND).getType().getName());
}
@Command(
aliases = { "floodfill", "flood" },
usage = "<pattern> <range>",
desc = "Flood fill tool",
min = 2,
max = 2
aliases = {"floodfill", "flood"},
usage = "<pattern> <range>",
desc = "Flood fill tool",
min = 2,
max = 2
)
@CommandPermissions("worldedit.tool.flood-fill")
public void floodFill(Player player, LocalSession session, Pattern pattern, int range) throws WorldEditException {
public void floodFill(Player player, EditSession editSession, LocalSession session, Pattern pattern, int range) throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
if (range > config.maxSuperPickaxeSize) {
BBC.TOOL_RANGE_ERROR.send(player, config.maxSuperPickaxeSize);
return;
}
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(itemStack.getType(), new FloodFillTool(range, pattern));
BBC.TOOL_FLOOD_FILL.send(player, itemStack.getType().getName());
session.setTool(new FloodFillTool(range, pattern), player);
BBC.TOOL_FLOOD_FILL.send(player, player.getItemInHand(HandSide.MAIN_HAND).getType().getName());
}
@Command(
aliases = { "deltree" },
aliases = {"deltree"},
usage = "",
desc = "Floating tree remover tool",
min = 0,
max = 0
)
@CommandPermissions("worldedit.tool.deltree")
public void deltree(Player player, LocalSession session) throws WorldEditException {
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(itemStack.getType(), new FloatingTreeRemover());
public void deltree(Player player, LocalSession session, CommandContext args) throws WorldEditException {
session.setTool(new FloatingTreeRemover(), player);
BBC.TOOL_DELTREE.send(player, player.getItemInHand(HandSide.MAIN_HAND).getType().getName());
}
@Command(
aliases = { "farwand" },
aliases = {"farwand"},
usage = "",
desc = "Wand at a distance tool",
min = 0,
max = 0
)
@CommandPermissions("worldedit.tool.farwand")
public void farwand(Player player, LocalSession session) throws WorldEditException {
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(itemStack.getType(), new DistanceWand());
BBC.TOOL_FARWAND.send(player, itemStack.getType().getName());
public void farwand(Player player, LocalSession session, CommandContext args) throws WorldEditException {
session.setTool(new DistanceWand(), player);
BBC.TOOL_FARWAND.send(player, player.getItemInHand(HandSide.MAIN_HAND).getType().getName());
}
@Command(
aliases = { "lrbuild", "/lrbuild" },
aliases = {"lrbuild", "/lrbuild"},
usage = "<leftclick block> <rightclick block>",
desc = "Long-range building tool",
min = 2,
@ -193,10 +182,8 @@ public class ToolCommands {
)
@CommandPermissions("worldedit.tool.lrbuild")
public void longrangebuildtool(Player player, LocalSession session, Pattern secondary, Pattern primary) throws WorldEditException {
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(itemStack.getType(), new LongRangeBuildTool(primary, secondary));
BBC.TOOL_LRBUILD_BOUND.send(player, itemStack.getType().getName());
session.setTool(new LongRangeBuildTool(primary, secondary), player);
BBC.TOOL_LRBUILD_BOUND.send(player, player.getItemInHand(HandSide.MAIN_HAND).getType().getName());
BBC.TOOL_LRBUILD_INFO.send(player, secondary, primary);
}

View File

@ -56,7 +56,7 @@ public class ToolUtilCommands {
String newState = args.getString(0, null);
if (session.hasSuperPickAxe()) {
if ("on".equals(newState)) {
player.printError("Super pick axe already enabled.");
player.printError(BBC.getPrefix() + "Super pick axe already enabled.");
return;
}
@ -64,7 +64,7 @@ public class ToolUtilCommands {
player.print("Super pick axe disabled.");
} else {
if ("off".equals(newState)) {
player.printError("Super pick axe already disabled.");
player.printError(BBC.getPrefix() + "Super pick axe already disabled.");
return;
}
session.enableSuperPickAxe();
@ -130,7 +130,6 @@ public class ToolUtilCommands {
int radius = args.getInteger(0);
we.checkMaxBrushRadius(radius);
session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()).setSize(radius);
player.print("Brush size set.");
}

View File

@ -110,7 +110,7 @@ public class UtilityCommands extends MethodCommands {
}
@Command(
aliases = { "patterns" },
aliases = {"patterns"},
usage = "[page=1|search|pattern]",
desc = "View help about patterns",
help = "Patterns determine what blocks are placed\n" +
@ -125,7 +125,7 @@ public class UtilityCommands extends MethodCommands {
}
@Command(
aliases = { "masks" },
aliases = {"masks"},
usage = "[page=1|search|mask]",
desc = "View help about masks",
help = "Masks determine if a block can be placed\n" +
@ -141,7 +141,7 @@ public class UtilityCommands extends MethodCommands {
}
@Command(
aliases = { "transforms" },
aliases = {"transforms"},
usage = "[page=1|search|transform]",
desc = "View help about transforms",
help = "Transforms modify how a block is placed\n" +
@ -179,7 +179,7 @@ public class UtilityCommands extends MethodCommands {
}
@Command(
aliases = { "/heightmapinterface" },
aliases = {"/heightmapinterface"},
desc = "Generate the heightmap interface: https://github.com/boy0001/HeightMap"
)
@CommandPermissions("fawe.admin")
@ -237,7 +237,7 @@ public class UtilityCommands extends MethodCommands {
}
@Command(
aliases = { "/cancel", "fcancel" },
aliases = {"/cancel", "fcancel"},
desc = "Cancel your current command",
max = 0,
queued = false
@ -248,11 +248,11 @@ public class UtilityCommands extends MethodCommands {
}
@Command(
aliases = { "/fill" },
usage = "<pattern> <radius> [depth] [direction]",
desc = "Fill a hole",
min = 2,
max = 4
aliases = {"/fill"},
usage = "<pattern> <radius> [depth] [direction]",
desc = "Fill a hole",
min = 2,
max = 4
)
@CommandPermissions("worldedit.fill")
@Logging(PLACEMENT)
@ -261,15 +261,15 @@ public class UtilityCommands extends MethodCommands {
BlockVector3 pos = session.getPlacementPosition(player);
int affected;
affected = editSession.fillDirection(pos, pattern, radius, (int) depth, direction);
player.print(affected + " block(s) have been created.");
player.print(BBC.getPrefix() + affected + " block(s) have been created.");
}
@Command(
aliases = { "/fillr" },
usage = "<pattern> <radius> [depth]",
desc = "Fill a hole recursively",
min = 2,
max = 3
aliases = {"/fillr"},
usage = "<pattern> <radius> [depth]",
desc = "Fill a hole recursively",
min = 2,
max = 3
)
@CommandPermissions("worldedit.fill.recursive")
@Logging(PLACEMENT)
@ -278,11 +278,11 @@ public class UtilityCommands extends MethodCommands {
BlockVector3 pos = session.getPlacementPosition(player);
if (depth == -1) depth = Integer.MAX_VALUE;
int affected = editSession.fillXZ(pos, pattern, radius, (int) depth, true);
player.print(affected + " block(s) have been created.");
player.print(BBC.getPrefix() + affected + " block(s) have been created.");
}
@Command(
aliases = { "/drain" },
aliases = {"/drain"},
usage = "<radius>",
desc = "Drain a pool",
min = 1,
@ -294,31 +294,31 @@ public class UtilityCommands extends MethodCommands {
worldEdit.checkMaxRadius(radius);
int affected = editSession.drainArea(
session.getPlacementPosition(player), radius);
player.print(affected + " block(s) have been changed.");
player.print(BBC.getPrefix() + affected + " block(s) have been changed.");
}
@Command(
aliases = { "/fixlava", "fixlava" },
usage = "<radius>",
desc = "Fix lava to be stationary",
min = 1,
max = 1
aliases = {"/fixlava", "fixlava"},
usage = "<radius>",
desc = "Fix lava to be stationary",
min = 1,
max = 1
)
@CommandPermissions("worldedit.fixlava")
@Logging(PLACEMENT)
public void fixLava(Player player, LocalSession session, EditSession editSession, @Range(min = 0) double radius) throws WorldEditException {
worldEdit.checkMaxRadius(radius);
int affected = editSession.fixLiquid(session.getPlacementPosition(player), radius, BlockTypes.LAVA);
player.print(affected + " block(s) have been changed.");
int affected = editSession.fixLiquid(
session.getPlacementPosition(player), radius, BlockTypes.LAVA);
player.print(BBC.getPrefix() + affected + " block(s) have been changed.");
}
@Command(
aliases = { "/fixwater", "fixwater" },
usage = "<radius>",
desc = "Fix water to be stationary",
min = 1,
max = 1
aliases = {"/fixwater", "fixwater"},
usage = "<radius>",
desc = "Fix water to be stationary",
min = 1,
max = 1
)
@CommandPermissions("worldedit.fixwater")
@Logging(PLACEMENT)
@ -330,11 +330,11 @@ public class UtilityCommands extends MethodCommands {
}
@Command(
aliases = { "/removeabove", "removeabove" },
usage = "[size] [height]",
desc = "Remove blocks above your head.",
min = 0,
max = 2
aliases = {"/removeabove", "removeabove"},
usage = "[size] [height]",
desc = "Remove blocks above your head.",
min = 0,
max = 2
)
@CommandPermissions("worldedit.removeabove")
@Logging(PLACEMENT)
@ -345,11 +345,11 @@ public class UtilityCommands extends MethodCommands {
}
@Command(
aliases = { "/removebelow", "removebelow" },
usage = "[size] [height]",
desc = "Remove blocks below you.",
min = 0,
max = 2
aliases = {"/removebelow", "removebelow"},
usage = "[size] [height]",
desc = "Remove blocks below you.",
min = 0,
max = 2
)
@CommandPermissions("worldedit.removebelow")
@Logging(PLACEMENT)
@ -360,11 +360,11 @@ public class UtilityCommands extends MethodCommands {
}
@Command(
aliases = { "/removenear", "removenear" },
usage = "<mask> [size]",
desc = "Remove blocks near you.",
min = 1,
max = 2
aliases = {"/removenear", "removenear"},
usage = "<mask> [size]",
desc = "Remove blocks near you.",
min = 1,
max = 2
)
@CommandPermissions("worldedit.removenear")
@Logging(PLACEMENT)
@ -376,12 +376,12 @@ public class UtilityCommands extends MethodCommands {
}
@Command(
aliases = { "/replacenear", "replacenear" },
usage = "<size> <from-id> <to-id>",
desc = "Replace nearby blocks",
flags = "f",
min = 3,
max = 3
aliases = {"/replacenear", "replacenear"},
usage = "<size> <from-id> <to-id>",
desc = "Replace nearby blocks",
flags = "f",
min = 3,
max = 3
)
@CommandPermissions("worldedit.replacenear")
@Logging(PLACEMENT)
@ -400,11 +400,11 @@ public class UtilityCommands extends MethodCommands {
}
@Command(
aliases = { "/snow", "snow" },
usage = "[radius]",
desc = "Simulates snow",
min = 0,
max = 1
aliases = {"/snow", "snow"},
usage = "[radius]",
desc = "Simulates snow",
min = 0,
max = 1
)
@CommandPermissions("worldedit.snow")
@Logging(PLACEMENT)
@ -413,11 +413,11 @@ public class UtilityCommands extends MethodCommands {
we.checkMaxRadius(size);
int affected = editSession.simulateSnow(session.getPlacementPosition(player), size);
player.print(affected + " surfaces covered. Let it snow~");
player.print(BBC.getPrefix() + affected + " surfaces covered. Let it snow~");
}
@Command(
aliases = { "/thaw", "thaw" },
aliases = {"/thaw", "thaw"},
usage = "[radius]",
desc = "Thaws the area",
min = 0,
@ -430,11 +430,11 @@ public class UtilityCommands extends MethodCommands {
we.checkMaxRadius(size);
int affected = editSession.thaw(session.getPlacementPosition(player), size);
player.print(affected + " surfaces thawed.");
player.print(BBC.getPrefix() + affected + " surfaces thawed.");
}
@Command(
aliases = { "/green", "green" },
aliases = {"/green", "green"},
usage = "[radius]",
desc = "Greens the area",
help = "Converts dirt to grass blocks. -f also converts coarse dirt.",
@ -454,7 +454,7 @@ public class UtilityCommands extends MethodCommands {
}
@Command(
aliases = { "/ex", "/ext", "/extinguish", "ex", "ext", "extinguish" },
aliases = {"/ex", "/ext", "/extinguish", "ex", "ext", "extinguish"},
usage = "[radius]",
desc = "Extinguish nearby fire",
min = 0,
@ -476,7 +476,7 @@ public class UtilityCommands extends MethodCommands {
}
@Command(
aliases = { "butcher" },
aliases = {"butcher"},
usage = "[radius]",
flags = "plangbtfr",
desc = "Kill all or nearby mobs",
@ -562,7 +562,7 @@ public class UtilityCommands extends MethodCommands {
}
@Command(
aliases = { "remove", "rem", "rement" },
aliases = {"remove", "rem", "rement"},
usage = "<type> <radius>",
desc = "Remove all entities of a type",
min = 2,
@ -622,7 +622,7 @@ public class UtilityCommands extends MethodCommands {
}
@Command(
aliases = { "/calc", "/calculate", "/eval", "/evaluate", "/solve" },
aliases = {"/calc", "/calculate", "/eval", "/evaluate", "/solve"},
usage = "<expression>",
desc = "Evaluate a mathematical expression"
)
@ -646,7 +646,7 @@ public class UtilityCommands extends MethodCommands {
}
executor.shutdownNow();
actor.print("= " + result);
actor.print(BBC.getPrefix() + "= " + result);
} catch (EvaluationException e) {
actor.printError(String.format(
"'%s' could not be evaluated (error: %s)", input, e.getMessage()));
@ -657,7 +657,7 @@ public class UtilityCommands extends MethodCommands {
}
@Command(
aliases = { "/confirm" },
aliases = {"/confirm"},
desc = "Confirm a command"
)
public void confirm(FawePlayer fp) throws WorldEditException {
@ -667,14 +667,13 @@ public class UtilityCommands extends MethodCommands {
}
@Command(
aliases = { "/help" },
aliases = {"/help"},
usage = "[<command>]",
desc = "Displays help for WorldEdit commands",
min = 0,
max = -1,
queued = false
)
@CommandPermissions("worldedit.help")
public void help(Actor actor, CommandContext args) throws WorldEditException {
help(args, worldEdit, actor);
}

View File

@ -1,31 +1,12 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.command.tool;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
@ -49,11 +30,11 @@ public class AreaPickaxe implements BlockTool {
}
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
int ox = clicked.getBlockX();
int oy = clicked.getBlockY();
int oz = clicked.getBlockZ();
BlockType initialType = clicked.getExtent().getBlock(clicked.toVector().toBlockPoint()).getBlockType();
BlockType initialType = clicked.getExtent().getBlock(clicked.toBlockPoint()).getBlockType();
if (initialType.getMaterial().isAir()) {
return true;
@ -64,9 +45,8 @@ public class AreaPickaxe implements BlockTool {
}
try (EditSession editSession = session.createEditSession(player)) {
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
try {
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
for (int x = ox - range; x <= ox + range; ++x) {
for (int z = oz - range; z <= oz + range; ++z) {
for (int y = oy + range; y >= oy - range; --y) {
@ -78,14 +58,10 @@ public class AreaPickaxe implements BlockTool {
}
}
editSession.flushQueue();
} catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached.");
} finally {
session.remember(editSession);
}
}
return true;
}
}

View File

@ -56,7 +56,8 @@ public class BlockDataCyler implements DoubleActionBlockTool {
World world = (World) clicked.getExtent();
BlockVector3 blockPoint = clicked.toVector().toBlockPoint();
// BlockStateHolder block = world.getBlock(clicked);
BlockVector3 blockPoint = clicked.toBlockPoint();
BlockState block = world.getBlock(blockPoint);
if (!config.allowedDataCycleBlocks.isEmpty()
@ -67,42 +68,42 @@ public class BlockDataCyler implements DoubleActionBlockTool {
}
if (block.getStates().keySet().isEmpty()) {
BBC.BLOCK_CYCLER_CANNOT_CYCLE.send(player);
BBC.BLOCK_CYCLER_CANNOT_CYCLE.send(player);
} else {
Property<?> currentProperty = selectedProperties.get(player.getUniqueId());
if (currentProperty == null || (forward && block.getState(currentProperty) == null)) {
currentProperty = block.getStates().keySet().stream().findFirst().get();
selectedProperties.put(player.getUniqueId(), currentProperty);
}
if (forward) {
block.getState(currentProperty);
int index = currentProperty.getValues().indexOf(block.getState(currentProperty));
index = (index + 1) % currentProperty.getValues().size();
@SuppressWarnings("unchecked")
Property<Object> objProp = (Property<Object>) currentProperty;
BlockState newBlock = block.with(objProp, currentProperty.getValues().get(index));
try (EditSession editSession = session.createEditSession(player)) {
try {
editSession.setBlock(blockPoint, newBlock);
player.print("Value of " + currentProperty.getName() + " is now " + currentProperty.getValues().get(index).toString());
} catch (MaxChangedBlocksException e) {
BBC.BLOCK_CYCLER_LIMIT.send(player);
} finally {
session.remember(editSession);
}
} catch (Exception e) {
}
} else {
List<Property<?>> properties = Lists.newArrayList(block.getStates().keySet());
int index = properties.indexOf(currentProperty);
index = (index + 1) % properties.size();
currentProperty = properties.get(index);
selectedProperties.put(player.getUniqueId(), currentProperty);
player.print("Now cycling " + currentProperty.getName());
}
Property<?> currentProperty = selectedProperties.get(player.getUniqueId());
if (currentProperty == null || (forward && block.getState(currentProperty) == null)) {
currentProperty = block.getStates().keySet().stream().findFirst().get();
selectedProperties.put(player.getUniqueId(), currentProperty);
}
if (forward) {
block.getState(currentProperty);
int index = currentProperty.getValues().indexOf(block.getState(currentProperty));
index = (index + 1) % currentProperty.getValues().size();
@SuppressWarnings("unchecked")
Property<Object> objProp = (Property<Object>) currentProperty;
BlockState newBlock = block.with(objProp, currentProperty.getValues().get(index));
try {
EditSession editSession = session.createEditSession(player);
try {
editSession.setBlock(blockPoint, newBlock);
player.print(BBC.getPrefix() + "Value of " + currentProperty.getName() + " is now " + currentProperty.getValues().get(index).toString());
} catch (MaxChangedBlocksException e) {
BBC.BLOCK_CYCLER_LIMIT.send(player);
} finally {
session.remember(editSession);
}
}catch (Exception e) {}
} else {
List<Property<?>> properties = Lists.newArrayList(block.getStates().keySet());
int index = properties.indexOf(currentProperty);
index = (index + 1) % properties.size();
currentProperty = properties.get(index);
selectedProperties.put(player.getUniqueId(), currentProperty);
player.print(BBC.getPrefix() + "Now cycling " + currentProperty.getName());
}
}
return true;

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.command.tool;
import com.boydti.fawe.config.BBC;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
@ -31,9 +32,10 @@ import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
/**
* A mode that replaces one block.
*/
public class BlockReplacer implements DoubleActionBlockTool {
@ -72,11 +74,13 @@ public class BlockReplacer implements DoubleActionBlockTool {
@Override
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
BlockState targetBlock = player.getWorld().getBlock(clicked.toVector().toBlockPoint());
EditSession editSession = session.createEditSession(player);
BlockStateHolder targetBlock = (editSession).getBlock(clicked.toBlockPoint());
BlockType type = targetBlock.getBlockType();
if (targetBlock != null) {
pattern = new BlockPattern(targetBlock);
player.print("Replacer tool switched to: " + targetBlock.getBlockType().getName());
if (type != null) {
this.pattern = targetBlock;
player.print(BBC.getPrefix() + "Replacer tool switched to: " + type.getName());
}
return true;

View File

@ -1,22 +1,3 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.command.tool;
import com.boydti.fawe.Fawe;
@ -263,6 +244,15 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
return getContext().getMask();
}
/**
* Get the filter.
*
* @return the filter
*/
public Mask getSourceMask() {
return getContext().getSourceMask();
}
@Override
public boolean reset() {
Brush br = getBrush();
@ -295,7 +285,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
/**
* Set the brush.
*
* @param brush tbe brush
* @param brush tbe brush
* @param permission the permission
*/
@Deprecated
@ -337,7 +327,8 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
*
* @return the material
*/
@Nullable public Pattern getMaterial() {
@Nullable
public Pattern getMaterial() {
return getContext().getMaterial();
}
@ -433,7 +424,8 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
return TaskManager.IMP.sync(new RunnableVal<Vector3>() {
@Override
public void run(Vector3 value) {
this.value = tb.getMaskedTargetBlock(useLastBlock);
Location result = tb.getMaskedTargetBlock(useLastBlock);
this.value = result;
}
});
}
@ -466,7 +458,6 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
BBC.NO_BLOCK.send(player);
return false;
}
BlockBag bag = session.getBlockBag(player);
Request.request().setEditSession(editSession);
Mask mask = current.getMask();
@ -496,7 +487,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
double size = current.getSize();
WorldEdit.getInstance().checkMaxBrushRadius(size);
brush.build(editSession, target, current.getMaterial(), size);
} catch (MaxChangedBlocksException e) {
} catch (WorldEditException e) {
player.printError("Max blocks change limit reached."); // Never happens
} finally {
if (bag != null) {
@ -519,6 +510,12 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
}
public void setScrollAction(ScrollAction scrollAction) {
this.getContext().setScrollAction(scrollAction);
update();
}
public void setTargetOffset(int targetOffset) {
this.targetOffset = targetOffset;
update();
@ -560,6 +557,10 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
return targetOffset;
}
public Mask getTargetMask() {
return targetMask;
}
public VisualMode getVisualMode() {
return visualMode;
}

View File

@ -69,7 +69,7 @@ public class DistanceWand extends BrushTool implements DoubleActionTraceTool {
if (target == null) return true;
RegionSelector selector = session.getRegionSelector(player.getWorld());
BlockVector3 blockPoint = target.toVector().toBlockPoint();
BlockVector3 blockPoint = target.toBlockPoint();
if (selector.selectSecondary(blockPoint, ActorSelectorLimits.forActor(player))) {
selector.explainSecondarySelection(player, session, blockPoint);
}

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.command.tool;
import com.boydti.fawe.object.collection.BlockVectorSet;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.collection.LocalBlockVectorSet;
import com.sk89q.worldedit.EditSession;
@ -37,7 +38,9 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;
/**
@ -67,7 +70,7 @@ public class FloatingTreeRemover implements BlockTool {
@Override
public boolean actPrimary(Platform server, LocalConfiguration config,
Player player, LocalSession session, Location clicked) {
Player player, LocalSession session, Location clicked) {
final World world = (World) clicked.getExtent();
final BlockState state = world.getBlock(clicked.toVector().toBlockPoint());
@ -118,7 +121,7 @@ public class FloatingTreeRemover implements BlockTool {
* @return a set containing all blocks in the tree/shroom or null if this is not a floating tree/shroom.
*/
private Set<BlockVector3> bfs(World world, BlockVector3 origin) throws MaxChangedBlocksException {
final Set<BlockVector3> visited = new LocalBlockVectorSet();
final LocalBlockVectorSet visited = new LocalBlockVectorSet();
final LocalBlockVectorSet queue = new LocalBlockVectorSet();
queue.add(origin);
@ -158,4 +161,4 @@ public class FloatingTreeRemover implements BlockTool {
return visited;
}
}
}

View File

@ -64,7 +64,7 @@ public class FloodFillTool implements BlockTool {
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
World world = (World) clicked.getExtent();
BlockVector3 origin = clicked.toVector().toBlockPoint();
BlockVector3 origin = clicked.toBlockPoint();
BlockType initialType = world.getBlock(origin).getBlockType();
if (initialType.getMaterial().isAir()) {
@ -88,7 +88,6 @@ public class FloodFillTool implements BlockTool {
session.remember(editSession);
}
}
return true;
}
@ -121,4 +120,5 @@ public class FloodFillTool implements BlockTool {
origin, size, initialType, visited);
}
}
}

View File

@ -1,29 +1,9 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.command.tool;
import com.boydti.fawe.object.mask.IdMask;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform;
@ -37,14 +17,11 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.Set;
/**
* A pickaxe mode that recursively finds adjacent blocks within range of
* an initial block and of the same type.
*/
public class RecursivePickaxe implements BlockTool {
private double range;
public RecursivePickaxe(double range) {
@ -59,66 +36,32 @@ public class RecursivePickaxe implements BlockTool {
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
World world = (World) clicked.getExtent();
final BlockVector3 pos = clicked.toBlockPoint();
EditSession editSession = session.createEditSession(player);
BlockVector3 origin = clicked.toBlockPoint();
BlockType initialType = world.getBlock(origin).getBlockType();
if (initialType.getMaterial().isAir()) {
BlockStateHolder block = editSession.getBlock(pos);
if (block.getBlockType().getMaterial().isAir()) {
return true;
}
if (initialType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
if (block.getBlockType() == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
return true;
}
try (EditSession editSession = session.createEditSession(player)) {
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
final int radius = (int) range;
final BlockReplace replace = new BlockReplace(editSession, (editSession.nullBlock));
editSession.setMask((Mask) null);
RecursiveVisitor visitor = new RecursiveVisitor(new IdMask(editSession), replace, radius, editSession);
visitor.visit(clicked.toBlockPoint());
Operations.completeBlindly(visitor);
editSession.flushQueue();
session.remember(editSession);
player.printError("Max blocks change limit reached.");
}
final int radius = (int) range;
final BlockReplace replace = new BlockReplace(editSession, (editSession.nullBlock));
editSession.setMask((Mask) null);
RecursiveVisitor visitor = new RecursiveVisitor(new IdMask(editSession), replace, radius, editSession);
visitor.visit(pos);
Operations.completeBlindly(visitor);
editSession.flushQueue();
session.remember(editSession);
return true;
}
private static void recurse(Platform server, EditSession editSession, World world, BlockVector3 pos,
BlockVector3 origin, double size, BlockType initialType, Set<BlockVector3> visited) throws MaxChangedBlocksException {
final double distanceSq = origin.distanceSq(pos);
if (distanceSq > size*size || visited.contains(pos)) {
return;
}
visited.add(pos);
if (editSession.getBlock(pos).getBlockType() != initialType) {
return;
}
world.queueBlockBreakEffect(server, pos, initialType, distanceSq);
editSession.setBlock(pos, BlockTypes.AIR.getDefaultState());
recurse(server, editSession, world, pos.add(1, 0, 0),
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(-1, 0, 0),
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(0, 0, 1),
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(0, 0, -1),
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(0, 1, 0),
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(0, -1, 0),
origin, size, initialType, visited);
}
}
}

View File

@ -37,7 +37,7 @@ public class HollowCylinderBrush implements Brush {
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) {
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState());
pattern = (BlockTypes.COBBLESTONE.getDefaultState());
}
editSession.makeCylinder(position, pattern, size, size, height, false);
}

View File

@ -31,7 +31,7 @@ public class HollowSphereBrush implements Brush {
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) {
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState());
pattern = (BlockTypes.COBBLESTONE.getDefaultState());
}
editSession.makeSphere(position, pattern, size, size, size, false);
}

View File

@ -53,7 +53,7 @@ public class SmoothBrush implements Brush {
Vector3 posDouble = position.toVector3();
Location min = new Location(editSession.getWorld(), posDouble.subtract(size, size, size));
BlockVector3 max = posDouble.add(size, size + 10, size).toBlockPoint();
Region region = new CuboidRegion(editSession.getWorld(), min.toVector().toBlockPoint(), max);
Region region = new CuboidRegion(editSession.getWorld(), min.toBlockPoint(), max);
HeightMap heightMap = new HeightMap(editSession, region, mask);
HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
heightMap.applyFilter(filter, iterations);

View File

@ -31,7 +31,7 @@ public class SphereBrush implements Brush {
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) {
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState());
pattern = (BlockTypes.COBBLESTONE.getDefaultState());
}
editSession.makeSphere(position, pattern, size, size, size, true);
}