This commit is contained in:
Jesse Boyd 2019-08-07 01:29:49 +10:00
parent a3c58a187e
commit a476ab1ea0
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
27 changed files with 461 additions and 485 deletions

View File

@ -19,6 +19,10 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT;
import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION;
import com.boydti.fawe.FaweAPI; import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
@ -35,10 +39,6 @@ import com.boydti.fawe.object.schematic.Schematic;
import com.boydti.fawe.util.ImgurUtility; import com.boydti.fawe.util.ImgurUtility;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MaskTraverser; import com.boydti.fawe.util.MaskTraverser;
import static com.google.common.base.Preconditions.checkNotNull;
import org.enginehub.piston.inject.InjectedValueAccess;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
@ -47,8 +47,6 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.command.util.Logging;
import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT;
import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.extent.PasteEvent; import com.sk89q.worldedit.event.extent.PasteEvent;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
@ -74,12 +72,6 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.session.ClipboardHolder;
import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg;
import org.enginehub.piston.annotation.param.ArgFlag;
import org.enginehub.piston.annotation.param.Switch;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
@ -91,6 +83,12 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg;
import org.enginehub.piston.annotation.param.ArgFlag;
import org.enginehub.piston.annotation.param.Switch;
import org.enginehub.piston.inject.InjectedValueAccess;
/** /**
@ -128,7 +126,8 @@ public class ClipboardCommands {
BlockVector3 min = region.getMinimumPoint(); BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint(); BlockVector3 max = region.getMaximumPoint();
long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1)); long volume =
((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1);
FaweLimit limit = FawePlayer.wrap(player).getLimit(); FaweLimit limit = FawePlayer.wrap(player).getLimit();
if (volume >= limit.MAX_CHECKS) { if (volume >= limit.MAX_CHECKS) {
throw FaweException.MAX_CHECKS; throw FaweException.MAX_CHECKS;
@ -159,7 +158,7 @@ public class ClipboardCommands {
if (!player.hasPermission("fawe.tips")) { if (!player.hasPermission("fawe.tips")) {
BBC.TIP_PASTE.or(BBC.TIP_DOWNLOAD, BBC.TIP_ROTATE, BBC.TIP_COPYPASTE, BBC.TIP_REPLACE_MARKER, BBC.TIP_COPY_PATTERN).send(player); BBC.TIP_PASTE.or(BBC.TIP_DOWNLOAD, BBC.TIP_ROTATE, BBC.TIP_COPYPASTE, BBC.TIP_REPLACE_MARKER, BBC.TIP_COPY_PATTERN).send(player);
} }
}, getArguments(context), region, context); }, "/copy", region, context);
} }
@Command( @Command(
@ -283,7 +282,7 @@ public class ClipboardCommands {
if (!player.hasPermission("fawe.tips")) { if (!player.hasPermission("fawe.tips")) {
BBC.TIP_LAZYCUT.send(player); BBC.TIP_LAZYCUT.send(player);
} }
}, getArguments(context), region, context); }, "cut", region, context);
} }

View File

@ -93,7 +93,7 @@ public class GenerationCommands {
@CommandPermissions("worldedit.generation.caves") @CommandPermissions("worldedit.generation.caves")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void caves(FawePlayer fp, LocalSession session, EditSession editSession, @Selection Region region, public void caves(FawePlayer fp, LocalSession session, EditSession editSession, @Selection Region region,
@Arg(desc = "TODO", def = "8") int size, @Arg(name = "size", desc = "TODO", def = "8") int sizeOpt,
@Arg(desc = "TODO", def = "40") int frequency, @Arg(desc = "TODO", def = "40") int frequency,
@Arg(desc = "TODO", def = "7") int rarity, @Arg(desc = "TODO", def = "7") int rarity,
@Arg(desc = "TODO", def = "8") int minY, @Arg(desc = "TODO", def = "8") int minY,
@ -104,10 +104,10 @@ public class GenerationCommands {
@Arg(desc = "TODO", def = "0") int pocketMin, @Arg(desc = "TODO", def = "0") int pocketMin,
@Arg(desc = "TODO", def = "3") int pocketMax, InjectedValueAccess context) throws WorldEditException { @Arg(desc = "TODO", def = "3") int pocketMax, InjectedValueAccess context) throws WorldEditException {
fp.checkConfirmationRegion(() -> { fp.checkConfirmationRegion(() -> {
CavesGen gen = new CavesGen(size, frequency, rarity, minY, maxY, systemFrequency, individualRarity, pocketChance, pocketMin, pocketMax); CavesGen gen = new CavesGen(sizeOpt, frequency, rarity, minY, maxY, systemFrequency, individualRarity, pocketChance, pocketMin, pocketMax);
editSession.generate(region, gen); editSession.generate(region, gen);
BBC.VISITOR_BLOCK.send(fp, editSession.getBlockChangeCount()); BBC.VISITOR_BLOCK.send(fp, editSession.getBlockChangeCount());
}, getArguments(context), region, context); }, "/caves", region, context);
} }
@ -117,11 +117,11 @@ public class GenerationCommands {
) )
@CommandPermissions("worldedit.generation.ore") @CommandPermissions("worldedit.generation.ore")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void ores(FawePlayer player, LocalSession session, EditSession editSession, @Selection Region region, Mask mask, InjectedValueAccess context) throws WorldEditException { public void ores(FawePlayer fp, LocalSession session, EditSession editSession, @Selection Region region, Mask mask, InjectedValueAccess context) throws WorldEditException {
player.checkConfirmationRegion(() -> { fp.checkConfirmationRegion(() -> {
editSession.addOres(region, mask); editSession.addOres(region, mask);
BBC.VISITOR_BLOCK.send(player, editSession.getBlockChangeCount()); BBC.VISITOR_BLOCK.send(fp, editSession.getBlockChangeCount());
}, getArguments(context), region, context); }, "/ores", region, context);
} }
@Command( @Command(
@ -171,11 +171,11 @@ public class GenerationCommands {
) )
@CommandPermissions("worldedit.generation.ore") @CommandPermissions("worldedit.generation.ore")
@Logging(PLACEMENT) @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, InjectedValueAccess context) throws WorldEditException { public void ore(FawePlayer fp, 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, InjectedValueAccess context) throws WorldEditException {
player.checkConfirmationRegion(() -> { fp.checkConfirmationRegion(() -> {
editSession.addOre(region, mask, material, size, freq, rarity, minY, maxY); editSession.addOre(region, mask, material, size, freq, rarity, minY, maxY);
BBC.VISITOR_BLOCK.send(player, editSession.getBlockChangeCount()); BBC.VISITOR_BLOCK.send(fp, editSession.getBlockChangeCount());
}, getArguments(context), region, context); }, "/ore", region, context);
} }
@Command( @Command(
@ -197,7 +197,7 @@ public class GenerationCommands {
fp.checkConfirmationRadius(() -> { fp.checkConfirmationRadius(() -> {
int affected = editSession.makeHollowCylinder(pos, pattern, radius.getX(), radius.getZ(), Math.min(256, height), thickness - 1); int affected = editSession.makeHollowCylinder(pos, pattern, radius.getX(), radius.getZ(), Math.min(256, height), thickness - 1);
BBC.VISITOR_BLOCK.send(fp, affected); BBC.VISITOR_BLOCK.send(fp, affected);
}, getArguments(context), (int) max, context); }, "/hcyl", (int) max, context);
} }
@Command( @Command(
@ -220,7 +220,7 @@ public class GenerationCommands {
fp.checkConfirmationRadius(() -> { fp.checkConfirmationRadius(() -> {
int affected = editSession.makeCylinder(pos, pattern, radius.getX(), radius.getZ(), Math.min(256, height), !hollow); int affected = editSession.makeCylinder(pos, pattern, radius.getX(), radius.getZ(), Math.min(256, height), !hollow);
BBC.VISITOR_BLOCK.send(fp, affected); BBC.VISITOR_BLOCK.send(fp, affected);
}, getArguments(context), (int) max, context); }, "/cyl", (int) max, context);
} }
@Command( @Command(
@ -262,7 +262,7 @@ public class GenerationCommands {
int affected = editSession.makeSphere(finalPos, pattern, radii.getX(), radii.getY(), radii.getZ(), !hollow); int affected = editSession.makeSphere(finalPos, pattern, radii.getX(), radii.getY(), radii.getZ(), !hollow);
player.findFreePosition(); player.findFreePosition();
BBC.VISITOR_BLOCK.send(fp, affected); BBC.VISITOR_BLOCK.send(fp, affected);
}, getArguments(context), (int) max, context); }, "sphere", (int) max, context);
} }
@Command( @Command(
@ -272,15 +272,15 @@ public class GenerationCommands {
@CommandPermissions("worldedit.generation.forest") @CommandPermissions("worldedit.generation.forest")
@Logging(POSITION) @Logging(POSITION)
public int forestGen(Player player, LocalSession session, EditSession editSession, public int forestGen(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The size of the forest, in blocks", def = "10") @Arg(name = "size", desc = "The size of the forest, in blocks", def = "10")
int size, int sizeOpt,
@Arg(desc = "The type of forest", def = "tree") @Arg(desc = "The type of forest", def = "tree")
TreeType type, TreeType type,
@Range(min = 0, max = 100) @Arg(desc = "The density of the forest, between 0 and 100", def = "5") @Range(min = 0, max = 100) @Arg(desc = "The density of the forest, between 0 and 100", def = "5")
double density) throws WorldEditException { double density) throws WorldEditException {
checkCommandArgument(0 <= density && density <= 100, "Density must be between 0 and 100"); checkCommandArgument(0 <= density && density <= 100, "Density must be between 0 and 100");
density /= 100; density /= 100;
int affected = editSession.makeForest(session.getPlacementPosition(player), size, density, type); int affected = editSession.makeForest(session.getPlacementPosition(player), sizeOpt, density, type);
player.print(affected + " trees created."); player.print(affected + " trees created.");
return affected; return affected;
} }
@ -292,12 +292,13 @@ public class GenerationCommands {
@CommandPermissions("worldedit.generation.pumpkins") @CommandPermissions("worldedit.generation.pumpkins")
@Logging(POSITION) @Logging(POSITION)
public int pumpkins(Player player, LocalSession session, EditSession editSession, public int pumpkins(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The size of the patch", def = "10") @Arg(name = "size", desc = "The size of the patch", def = "10")
int size, int sizeOpt,
@Arg(desc = "//TODO", def = "10") @Arg(desc = "//TODO", def = "10")
int apothem, int apothem,
@Range(min = 0, max = 100) @Arg(desc = "//TODO ", def = "0.02") @Arg(desc = "//TODO ", def = "0.02")
double density) throws WorldEditException { double density) throws WorldEditException {
checkCommandArgument(0 <= density && density <= 100, "Density must be between 0 and 100");
int affected = editSession.makePumpkinPatches(session.getPlacementPosition(player), apothem, density); int affected = editSession.makePumpkinPatches(session.getPlacementPosition(player), apothem, density);
BBC.COMMAND_PUMPKIN.send(player, affected); BBC.COMMAND_PUMPKIN.send(player, affected);
return affected; return affected;
@ -401,7 +402,7 @@ public class GenerationCommands {
} catch (ExpressionException e) { } catch (ExpressionException e) {
player.printError(e.getMessage()); player.printError(e.getMessage());
} }
}, getArguments(context), region, context); }, "/generate", region, context);
} }
@Command( @Command(
@ -464,7 +465,7 @@ public class GenerationCommands {
} catch (ExpressionException e) { } catch (ExpressionException e) {
fp.printError(e.getMessage()); fp.printError(e.getMessage());
} }
}, getArguments(context), region, context); }, "/generatebiome", region, context);
} }
} }

View File

@ -257,7 +257,7 @@ public class HistoryCommands {
if (undone == null) { if (undone == null) {
BBC.COMMAND_UNDO_ERROR.send(player); BBC.COMMAND_UNDO_ERROR.send(player);
} }
}, getArguments(context), times, 50, context); }, "undo", times, 50, context);
} }
@Command( @Command(

View File

@ -10,11 +10,10 @@ import java.util.UUID;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException; import java.util.regex.PatternSyntaxException;
import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.exception.StopExecutionException; import org.enginehub.piston.exception.StopExecutionException;
//TODO This class breaks compilation //TODO This class breaks compilation
@CommandContainer //@CommandContainer
public class ListFilters { public class ListFilters {
public class Filter { public class Filter {
public boolean listPrivate() { public boolean listPrivate() {

View File

@ -72,7 +72,7 @@ public class MaskCommands {
name = "#simplex", name = "#simplex",
desc = "Use simplex noise as the mask" desc = "Use simplex noise as the mask"
) )
public Mask simplex(double scale, double min, double max) { public Mask simplex(double scale, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) {
scale = 1d / Math.max(1, scale); scale = 1d / Math.max(1, scale);
min = (min - 50) / 50; min = (min - 50) / 50;
max = (max - 50) / 50; max = (max - 50) / 50;
@ -83,13 +83,12 @@ public class MaskCommands {
name = "#light", name = "#light",
desc = "Restrict to specific light levels" desc = "Restrict to specific light levels"
) )
public Mask light(Extent extent, double min, double max) { public Mask light(Extent extent, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) {
return new LightMask(extent, (int) min, (int) max); return new LightMask(extent, (int) min, (int) max);
} }
@Command( @Command(
name = "#false", name = "#false",
aliases = {"false"},
desc = "Always false" desc = "Always false"
) )
public Mask falseMask(Extent extent) { public Mask falseMask(Extent extent) {
@ -98,7 +97,6 @@ public class MaskCommands {
@Command( @Command(
name = "#true", name = "#true",
aliases = {"true"},
desc = "Always true" desc = "Always true"
) )
public Mask trueMask(Extent extent) { public Mask trueMask(Extent extent) {
@ -109,8 +107,8 @@ public class MaskCommands {
name = "#skylight", name = "#skylight",
desc = "Restrict to specific sky light levels" desc = "Restrict to specific sky light levels"
) )
public Mask skylight(Extent extent, double min, double max) { public Mask skylight(Extent extent, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) {
return new SkyLightMask(extent, (int) min, (int) max); return new SkyLightMask(extent, (int) minInt, (int) maxInt);
} }
@Command( @Command(
@ -118,24 +116,24 @@ public class MaskCommands {
aliases = {"#emittedlight"}, aliases = {"#emittedlight"},
desc = "Restrict to specific block light levels" desc = "Restrict to specific block light levels"
) )
public Mask blocklight(Extent extent, double min, double max) { public Mask blocklight(Extent extent, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) {
return new BlockLightMask(extent, (int) min, (int) max); return new BlockLightMask(extent, (int) minInt, (int) maxInt);
} }
@Command( @Command(
name = "#opacity", name = "#opacity",
desc = "Restrict to specific opacity levels" desc = "Restrict to specific opacity levels"
) )
public Mask opacity(Extent extent, double min, double max) { public Mask opacity(Extent extent, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) {
return new OpacityMask(extent, (int) min, (int) max); return new OpacityMask(extent, (int) minInt, (int) maxInt);
} }
@Command( @Command(
name = "#brightness", name = "#brightness",
desc = "Restrict to specific block brightness" desc = "Restrict to specific block brightness"
) )
public Mask brightness(Extent extent, double min, double max) { public Mask brightness(Extent extent, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) {
return new BrightnessMask(extent, (int) min, (int) max); return new BrightnessMask(extent, (int) minInt, (int) maxInt);
} }
@Command( @Command(
@ -288,17 +286,17 @@ public class MaskCommands {
"Example: /[3][20]\n" + "Example: /[3][20]\n" +
"Explanation: Allows any block where the adjacent block is between 3 and 20 blocks below" "Explanation: Allows any block where the adjacent block is between 3 and 20 blocks below"
) )
public Mask angle(Extent extent, String min, String max, @Switch(name = 'o', desc = "TODO") boolean overlay, @Arg(name = "distance", desc = "int", def = "1") int distance) throws ExpressionException { public Mask angle(Extent extent, String minStr, String maxStr, @Switch(name = 'o', desc = "TODO") boolean overlay, @Arg(name = "distance", desc = "int", def = "1") int distance) throws ExpressionException {
double y1, y2; double y1, y2;
boolean override; boolean override;
if (max.endsWith("d")) { if (maxStr.endsWith("d")) {
double y1d = Expression.compile(min.substring(0, min.length() - 1)).evaluate(); double y1d = Expression.compile(minStr.substring(0, minStr.length() - 1)).evaluate();
double y2d = Expression.compile(max.substring(0, max.length() - 1)).evaluate(); double y2d = Expression.compile(maxStr.substring(0, maxStr.length() - 1)).evaluate();
y1 = Math.tan(y1d * (Math.PI / 180)); y1 = Math.tan(y1d * (Math.PI / 180));
y2 = Math.tan(y2d * (Math.PI / 180)); y2 = Math.tan(y2d * (Math.PI / 180));
} else { } else {
y1 = Expression.compile(min).evaluate(); y1 = Expression.compile(minStr).evaluate();
y2 = Expression.compile(max).evaluate(); y2 = Expression.compile(maxStr).evaluate();
} }
return new AngleMask(extent, y1, y2, overlay, distance); return new AngleMask(extent, y1, y2, overlay, distance);
} }
@ -313,17 +311,17 @@ public class MaskCommands {
"Explanation: Restrict near where the angle changes between 0-45 degrees within 5 blocks\n" + "Explanation: Restrict near where the angle changes between 0-45 degrees within 5 blocks\n" +
"Note: Use negatives for decreasing slope" "Note: Use negatives for decreasing slope"
) )
public Mask roc(Extent extent, String min, String max, @Switch(name = 'o', desc = "TODO") boolean overlay, @Arg(name = "distance", desc = "int", def = "4") int distance) throws ExpressionException { public Mask roc(Extent extent, String minStr, String maxStr, @Switch(name = 'o', desc = "TODO") boolean overlay, @Arg(name = "distance", desc = "int", def = "4") int distance) throws ExpressionException {
double y1, y2; double y1, y2;
boolean override; boolean override;
if (max.endsWith("d")) { if (maxStr.endsWith("d")) {
double y1d = Expression.compile(min.substring(0, min.length() - 1)).evaluate(); double y1d = Expression.compile(minStr.substring(0, minStr.length() - 1)).evaluate();
double y2d = Expression.compile(max.substring(0, max.length() - 1)).evaluate(); double y2d = Expression.compile(maxStr.substring(0, maxStr.length() - 1)).evaluate();
y1 = Math.tan(y1d * (Math.PI / 180)); y1 = Math.tan(y1d * (Math.PI / 180));
y2 = Math.tan(y2d * (Math.PI / 180)); y2 = Math.tan(y2d * (Math.PI / 180));
} else { } else {
y1 = Expression.compile(min).evaluate(); y1 = Expression.compile(minStr).evaluate();
y2 = Expression.compile(max).evaluate(); y2 = Expression.compile(maxStr).evaluate();
} }
return new ROCAngleMask(extent, y1, y2, overlay, distance); return new ROCAngleMask(extent, y1, y2, overlay, distance);
} }
@ -358,8 +356,8 @@ public class MaskCommands {
aliases = {"#{"}, aliases = {"#{"},
desc = "Restricts blocks to within a specific radius range of the initial block" desc = "Restricts blocks to within a specific radius range of the initial block"
) )
public Mask radius(double min, double max) throws ExpressionException { public Mask radius(@Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) throws ExpressionException {
return new RadiusMask((int) min, (int) max); return new RadiusMask((int) minInt, (int) maxInt);
} }
@Command( @Command(
@ -367,8 +365,8 @@ public class MaskCommands {
aliases = {"#|", "#side"}, aliases = {"#|", "#side"},
desc = "sides with a specific number of other blocks" desc = "sides with a specific number of other blocks"
) )
public Mask wall(Mask mask, double min, double max) throws ExpressionException { public Mask wall(Mask mask, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) throws ExpressionException {
return new WallMask(mask, (int) min, (int) max); return new WallMask(mask, (int) minInt, (int) maxInt);
} }
@Command( @Command(

View File

@ -292,7 +292,7 @@ public class SchematicCommands {
desc = "Save a schematic into your clipboard" desc = "Save a schematic into your clipboard"
) )
@CommandPermissions({"worldedit.clipboard.save", "worldedit.schematic.save", "worldedit.schematic.save.other"}) @CommandPermissions({"worldedit.clipboard.save", "worldedit.schematic.save", "worldedit.schematic.save.other"})
public void save(Player player, LocalSession session, public void save(Actor actor, LocalSession session,
@Arg(desc = "File name.") @Arg(desc = "File name.")
String filename, String filename,
@Arg(desc = "Format name.", def = "sponge") @Arg(desc = "Format name.", def = "sponge")
@ -307,20 +307,20 @@ public class SchematicCommands {
File dir = worldEdit.getWorkingDirectoryFile(config.saveDir); File dir = worldEdit.getWorkingDirectoryFile(config.saveDir);
if (!global && Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS) { if (!global && Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS) {
dir = new File(dir, player.getUniqueId().toString()); dir = new File(dir, actor.getUniqueId().toString());
} }
ClipboardFormat format = ClipboardFormats.findByAlias(formatName); ClipboardFormat format = ClipboardFormats.findByAlias(formatName);
if (format == null) { if (format == null) {
player.printError("Unknown schematic format: " + formatName); actor.printError("Unknown schematic format: " + formatName);
return; return;
} }
boolean other = false; boolean other = false;
if (filename.contains("../")) { if (filename.contains("../")) {
other = true; other = true;
if (!player.hasPermission("worldedit.schematic.save.other")) { if (!actor.hasPermission("worldedit.schematic.save.other")) {
BBC.NO_PERM.send(player, "worldedit.schematic.save.other"); BBC.NO_PERM.send(actor, "worldedit.schematic.save.other");
return; return;
} }
if (filename.startsWith("../")) { if (filename.startsWith("../")) {
@ -329,21 +329,21 @@ public class SchematicCommands {
} }
} }
File f = worldEdit.getSafeSaveFile(player, dir, filename, format.getPrimaryFileExtension()); File f = worldEdit.getSafeSaveFile(actor, dir, filename, format.getPrimaryFileExtension());
boolean overwrite = f.exists(); boolean overwrite = f.exists();
if (overwrite) { if (overwrite) {
if (!player.hasPermission("worldedit.schematic.delete")) { if (!actor.hasPermission("worldedit.schematic.delete")) {
throw new StopExecutionException(TextComponent.of("That schematic already exists!")); throw new StopExecutionException(TextComponent.of("That schematic already exists!"));
} }
if (other) { if (other) {
if (!player.hasPermission("worldedit.schematic.delete.other")) { if (!actor.hasPermission("worldedit.schematic.delete.other")) {
BBC.NO_PERM.send(player, "worldedit.schematic.delete.other"); BBC.NO_PERM.send(player, "worldedit.schematic.delete.other");
return; return;
} }
} }
if (!allowOverwrite) { if (!allowOverwrite) {
player.printError("That schematic already exists. Use the -f flag to overwrite it."); actor.printError("That schematic already exists. Use the -f flag to overwrite it.");
return; return;
} }
} }
@ -359,8 +359,8 @@ public class SchematicCommands {
ClipboardHolder holder = session.getClipboard(); ClipboardHolder holder = session.getClipboard();
SchematicSaveTask task = new SchematicSaveTask(player, f, format, holder, overwrite); SchematicSaveTask task = new SchematicSaveTask(actor, f, format, holder, overwrite);
AsyncCommandBuilder.wrap(task, player) AsyncCommandBuilder.wrap(task, actor)
.registerWithSupervisor(worldEdit.getSupervisor(), "Saving schematic " + filename) .registerWithSupervisor(worldEdit.getSupervisor(), "Saving schematic " + filename)
.sendMessageAfterDelay("(Please wait... saving schematic.)") .sendMessageAfterDelay("(Please wait... saving schematic.)")
.onSuccess(filename + " saved" + (overwrite ? " (overwriting previous file)." : "."), null) .onSuccess(filename + " saved" + (overwrite ? " (overwriting previous file)." : "."), null)
@ -577,7 +577,7 @@ public class SchematicCommands {
boolean oldFirst, boolean oldFirst,
@Switch(name = 'n', desc = "Sort by date, newest first") @Switch(name = 'n', desc = "Sort by date, newest first")
boolean newFirst, boolean newFirst,
@Switch(name = 'f', desc = "Restricts by format.") @ArgFlag(name = 'f', desc = "Restricts by format.")
String formatName, String formatName,
@Arg(name = "filter", desc = "Filter for schematics", def = "all") @Arg(name = "filter", desc = "Filter for schematics", def = "all")
String filter) throws WorldEditException { String filter) throws WorldEditException {
@ -635,12 +635,12 @@ public class SchematicCommands {
} }
private static class SchematicLoadTask implements Callable<ClipboardHolder> { private static class SchematicLoadTask implements Callable<ClipboardHolder> {
private final Player player; private final Actor actor;
private final File file; private final File file;
private final ClipboardFormat format; private final ClipboardFormat format;
SchematicLoadTask(Player player, File file, ClipboardFormat format) { SchematicLoadTask(Actor actor, File file, ClipboardFormat format) {
this.player = player; this.actor = actor;
this.file = file; this.file = file;
this.format = format; this.format = format;
} }
@ -653,21 +653,21 @@ public class SchematicCommands {
ClipboardReader reader = closer.register(format.getReader(bis)); ClipboardReader reader = closer.register(format.getReader(bis));
Clipboard clipboard = reader.read(); Clipboard clipboard = reader.read();
log.info(player.getName() + " loaded " + file.getCanonicalPath()); log.info(actor.getName() + " loaded " + file.getCanonicalPath());
return new ClipboardHolder(clipboard); return new ClipboardHolder(clipboard);
} }
} }
} }
private static class SchematicSaveTask implements Callable<Void> { private static class SchematicSaveTask implements Callable<Void> {
private final Player player; private final Actor actor;
private final File file; private final File file;
private final ClipboardFormat format; private final ClipboardFormat format;
private final ClipboardHolder holder; private final ClipboardHolder holder;
private final boolean overwrite; private final boolean overwrite;
SchematicSaveTask(Player player, File file, ClipboardFormat format, ClipboardHolder holder, boolean overwrite) { SchematicSaveTask(Actor actor, File file, ClipboardFormat format, ClipboardHolder holder, boolean overwrite) {
this.player = player; this.actor = actor;
this.file = file; this.file = file;
this.format = format; this.format = format;
this.holder = holder; this.holder = holder;
@ -700,14 +700,14 @@ public class SchematicCommands {
} }
if (new PlayerSaveClipboardEvent(player, clipboard, uri, file.toURI()).call()) { if (new PlayerSaveClipboardEvent(player, clipboard, uri, file.toURI()).call()) {
if (writer instanceof MinecraftStructure) { if (writer instanceof MinecraftStructure) {
((MinecraftStructure) writer).write(target, player.getName()); ((MinecraftStructure) writer).write(target, actor.getName());
} else { } else {
writer.write(target); writer.write(target);
} }
log.info(player.getName() + " saved " + file.getCanonicalPath()); log.info(actor.getName() + " saved " + file.getCanonicalPath());
BBC.SCHEMATIC_SAVED.send(player, file.getName()); BBC.SCHEMATIC_SAVED.send(actor, file.getName());
} else { } else {
BBC.WORLDEDIT_CANCEL_REASON_MANUAL.send(player); BBC.WORLDEDIT_CANCEL_REASON_MANUAL.send(actor);
} }
} }
return null; return null;

View File

@ -40,6 +40,8 @@ import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.command.util.Logging;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Locatable;
import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits; import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits;
import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
@ -61,6 +63,7 @@ import com.sk89q.worldedit.regions.selector.RegionSelectorType;
import com.sk89q.worldedit.regions.selector.SphereRegionSelector; import com.sk89q.worldedit.regions.selector.SphereRegionSelector;
import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.Countable; import com.sk89q.worldedit.util.Countable;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.component.CommandListBox; import com.sk89q.worldedit.util.formatting.component.CommandListBox;
import com.sk89q.worldedit.util.formatting.component.SubtleFormat; import com.sk89q.worldedit.util.formatting.component.SubtleFormat;
import com.sk89q.worldedit.util.formatting.component.TextComponentProducer; import com.sk89q.worldedit.util.formatting.component.TextComponentProducer;
@ -99,23 +102,26 @@ public class SelectionCommands {
) )
@Logging(POSITION) @Logging(POSITION)
@CommandPermissions("worldedit.selection.pos") @CommandPermissions("worldedit.selection.pos")
public void pos1(Player player, LocalSession session, public void pos1(Actor actor, World world, LocalSession session,
@Arg(desc = "Coordinates to set position 1 to", def = "") @Arg(desc = "Coordinates to set position 1 to", def = "")
BlockVector3 coordinates) throws WorldEditException { BlockVector3 coordinates) throws WorldEditException {
BlockVector3 pos; Location pos;
if (coordinates != null) { if (coordinates != null) {
pos = coordinates; pos = new Location(world, coordinates.toVector3());
} else if (actor instanceof Locatable) {
pos = ((Locatable) actor).getBlockLocation();
} else { } else {
pos = player.getBlockIn().toBlockPoint(); actor.printError("You must provide coordinates as console.");
}
pos = pos.clampY(0, player.getWorld().getMaximumPoint().getBlockY());
if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos, ActorSelectorLimits.forActor(player))) {
BBC.SELECTOR_ALREADY_SET.send(player);
return; return;
} }
session.getRegionSelector(player.getWorld()) if (!session.getRegionSelector(world).selectPrimary(pos.toBlockPoint(), ActorSelectorLimits.forActor(actor))) {
.explainPrimarySelection(player, session, pos); BBC.SELECTOR_ALREADY_SET.send(actor);
return;
}
session.getRegionSelector(world)
.explainPrimarySelection(actor, session, pos.toBlockPoint());
} }
@Command( @Command(
@ -124,23 +130,25 @@ public class SelectionCommands {
) )
@Logging(POSITION) @Logging(POSITION)
@CommandPermissions("worldedit.selection.pos") @CommandPermissions("worldedit.selection.pos")
public void pos2(Player player, LocalSession session, public void pos2(Actor actor, World world, LocalSession session,
@Arg(desc = "Coordinates to set position 2 to", def = "") @Arg(desc = "Coordinates to set position 2 to", def = "")
BlockVector3 coordinates) throws WorldEditException { BlockVector3 coordinates) throws WorldEditException {
BlockVector3 pos; Location pos;
if (coordinates != null) { if (coordinates != null) {
pos = coordinates; pos = new Location(world, coordinates.toVector3());
} else if (actor instanceof Locatable) {
pos = ((Locatable) actor).getBlockLocation();
} else { } else {
pos = player.getBlockIn().toBlockPoint(); actor.printError("You must provide coordinates as console.");
return;
} }
pos = pos.clampY(0, player.getWorld().getMaximumPoint().getBlockY()); if (!session.getRegionSelector(world).selectSecondary(pos.toBlockPoint(), ActorSelectorLimits.forActor(actor))) {
if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos, ActorSelectorLimits.forActor(player))) { BBC.SELECTOR_ALREADY_SET.send(actor);
BBC.SELECTOR_ALREADY_SET.send(player);
return; return;
} }
session.getRegionSelector(player.getWorld()) session.getRegionSelector(world)
.explainSecondarySelection(player, session, pos); .explainSecondarySelection(actor, session, pos.toBlockPoint());
} }
@Command( @Command(
@ -222,7 +230,7 @@ public class SelectionCommands {
: ChunkStore.toChunk(coordinates.toBlockVector3()); : ChunkStore.toChunk(coordinates.toBlockVector3());
} else { } else {
// use player loc // use player loc
min2D = ChunkStore.toChunk(player.getBlockIn().toBlockPoint()); min2D = ChunkStore.toChunk(player.getBlockLocation().toBlockPoint());
} }
min = BlockVector3.at(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16); min = BlockVector3.at(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16);
@ -296,7 +304,7 @@ public class SelectionCommands {
) )
@Logging(REGION) @Logging(REGION)
@CommandPermissions("worldedit.selection.contract") @CommandPermissions("worldedit.selection.contract")
public void contract(Player player, LocalSession session, public void contract(Actor actor, World world, LocalSession session,
@Arg(desc = "Amount to contract the selection by") @Arg(desc = "Amount to contract the selection by")
int amount, int amount,
@Arg(desc = "Amount to contract the selection by in the other direction", def = "0") @Arg(desc = "Amount to contract the selection by in the other direction", def = "0")
@ -305,7 +313,7 @@ public class SelectionCommands {
@MultiDirection @MultiDirection
List<BlockVector3> direction) throws WorldEditException { List<BlockVector3> direction) throws WorldEditException {
try { try {
Region region = session.getSelection(player.getWorld()); Region region = session.getSelection(world);
int oldSize = region.getArea(); int oldSize = region.getArea();
if (reverseAmount == 0) { if (reverseAmount == 0) {
for (BlockVector3 dir : direction) { for (BlockVector3 dir : direction) {
@ -316,15 +324,15 @@ public class SelectionCommands {
region.contract(dir.multiply(amount), dir.multiply(-reverseAmount)); region.contract(dir.multiply(amount), dir.multiply(-reverseAmount));
} }
} }
session.getRegionSelector(player.getWorld()).learnChanges(); session.getRegionSelector(world).learnChanges();
int newSize = region.getArea(); int newSize = region.getArea();
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session); session.getRegionSelector(world).explainRegionAdjust(actor, session);
BBC.SELECTION_CONTRACT.send(player, (oldSize - newSize)); BBC.SELECTION_CONTRACT.send(actor, (oldSize - newSize));
} catch (RegionOperationException e) { } catch (RegionOperationException e) {
player.printError(e.getMessage()); actor.printError(e.getMessage());
} }
} }
@ -334,26 +342,26 @@ public class SelectionCommands {
) )
@Logging(REGION) @Logging(REGION)
@CommandPermissions("worldedit.selection.shift") @CommandPermissions("worldedit.selection.shift")
public void shift(Player player, LocalSession session, public void shift(Actor actor, World world, LocalSession session,
@Arg(desc = "Amount to shift the selection by") @Arg(desc = "Amount to shift the selection by")
int amount, int amount,
@Arg(desc = "Direction to contract", def = Direction.AIM) @Arg(desc = "Direction to contract", def = Direction.AIM)
@MultiDirection @MultiDirection
List<BlockVector3> direction) throws WorldEditException { List<BlockVector3> direction) throws WorldEditException {
try { try {
Region region = session.getSelection(player.getWorld()); Region region = session.getSelection(world);
for (BlockVector3 dir : direction) { for (BlockVector3 dir : direction) {
region.shift(dir.multiply(amount)); region.shift(dir.multiply(amount));
} }
session.getRegionSelector(player.getWorld()).learnChanges(); session.getRegionSelector(world).learnChanges();
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session); session.getRegionSelector(world).explainRegionAdjust(actor, session);
BBC.SELECTION_SHIFT.send(player); BBC.SELECTION_SHIFT.send(actor);
} catch (RegionOperationException e) { } catch (RegionOperationException e) {
player.printError(e.getMessage()); actor.printError(e.getMessage());
} }
} }
@ -363,18 +371,18 @@ public class SelectionCommands {
) )
@Logging(REGION) @Logging(REGION)
@CommandPermissions("worldedit.selection.outset") @CommandPermissions("worldedit.selection.outset")
public void outset(Player player, LocalSession session, public void outset(Actor actor, World world, LocalSession session,
@Arg(desc = "Amount to expand the selection by in all directions") @Arg(desc = "Amount to expand the selection by in all directions")
int amount, int amount,
@Switch(name = 'h', desc = "Only expand horizontally") @Switch(name = 'h', desc = "Only expand horizontally")
boolean onlyHorizontal, boolean onlyHorizontal,
@Switch(name = 'v', desc = "Only expand vertically") @Switch(name = 'v', desc = "Only expand vertically")
boolean onlyVertical) throws WorldEditException { boolean onlyVertical) throws WorldEditException {
Region region = session.getSelection(player.getWorld()); Region region = session.getSelection(world);
region.expand(getChangesForEachDir(amount, onlyHorizontal, onlyVertical)); region.expand(getChangesForEachDir(amount, onlyHorizontal, onlyVertical));
session.getRegionSelector(player.getWorld()).learnChanges(); session.getRegionSelector(world).learnChanges();
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session); session.getRegionSelector(world).explainRegionAdjust(actor, session);
BBC.SELECTION_OUTSET.send(player); BBC.SELECTION_OUTSET.send(actor);
} }
@Command( @Command(
@ -383,18 +391,18 @@ public class SelectionCommands {
) )
@Logging(REGION) @Logging(REGION)
@CommandPermissions("worldedit.selection.inset") @CommandPermissions("worldedit.selection.inset")
public void inset(Player player, LocalSession session, public void inset(Actor actor, World world, LocalSession session,
@Arg(desc = "Amount to contract the selection by in all directions") @Arg(desc = "Amount to contract the selection by in all directions")
int amount, int amount,
@Switch(name = 'h', desc = "Only contract horizontally") @Switch(name = 'h', desc = "Only contract horizontally")
boolean onlyHorizontal, boolean onlyHorizontal,
@Switch(name = 'v', desc = "Only contract vertically") @Switch(name = 'v', desc = "Only contract vertically")
boolean onlyVertical) throws WorldEditException { boolean onlyVertical) throws WorldEditException {
Region region = session.getSelection(player.getWorld()); Region region = session.getSelection(world);
region.contract(getChangesForEachDir(amount, onlyHorizontal, onlyVertical)); region.contract(getChangesForEachDir(amount, onlyHorizontal, onlyVertical));
session.getRegionSelector(player.getWorld()).learnChanges(); session.getRegionSelector(world).learnChanges();
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session); session.getRegionSelector(world).explainRegionAdjust(actor, session);
BBC.SELECTION_INSET.send(player); actor.print("Region inset.");
} }
private BlockVector3[] getChangesForEachDir(int amount, boolean onlyHorizontal, boolean onlyVertical) { private BlockVector3[] getChangesForEachDir(int amount, boolean onlyHorizontal, boolean onlyVertical) {
@ -544,17 +552,16 @@ public class SelectionCommands {
aliases = { ";", "/desel", "/deselect" }, aliases = { ";", "/desel", "/deselect" },
desc = "Choose a region selector" desc = "Choose a region selector"
) )
public void select(Player player, LocalSession session, EditSession editSession, public void select(Actor actor, World world, LocalSession session, EditSession editSession,
@Arg(desc = "Selector to switch to", def = "") @Arg(desc = "Selector to switch to", def = "")
SelectorChoice selector, SelectorChoice selector,
@Arg(desc = "Selector mask", def = "") Mask mask, @Arg(desc = "Selector mask", def = "") Mask mask,
@Switch(name = 'd', desc = "Set default selector") @Switch(name = 'd', desc = "Set default selector")
boolean setDefaultSelector) throws WorldEditException { boolean setDefaultSelector) throws WorldEditException {
final World world = player.getWorld();
if (selector == null) { if (selector == null) {
session.getRegionSelector(world).clear(); session.getRegionSelector(world).clear();
session.dispatchCUISelection(player); session.dispatchCUISelection(actor);
BBC.SELECTION_CLEARED.send(player); BBC.SELECTION_CLEARED.send(actor);
return; return;
} }
@ -564,55 +571,56 @@ public class SelectionCommands {
switch (selector) { switch (selector) {
case CUBOID: case CUBOID:
newSelector = new CuboidRegionSelector(oldSelector); newSelector = new CuboidRegionSelector(oldSelector);
player.print(BBC.SEL_CUBOID.s()); actor.print(BBC.SEL_CUBOID.s());
break; break;
case EXTEND: case EXTEND:
newSelector = new ExtendingCuboidRegionSelector(oldSelector); newSelector = new ExtendingCuboidRegionSelector(oldSelector);
player.print(BBC.SEL_CUBOID_EXTEND.s()); actor.print(BBC.SEL_CUBOID_EXTEND.s());
break; break;
case POLY: { case POLY: {
newSelector = new Polygonal2DRegionSelector(oldSelector); newSelector = new Polygonal2DRegionSelector(oldSelector);
player.print(BBC.SEL_2D_POLYGON.s()); actor.print(BBC.SEL_2D_POLYGON.s());
Optional<Integer> limit = ActorSelectorLimits.forActor(player).getPolygonVertexLimit(); Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolygonVertexLimit();
limit.ifPresent(integer -> player.print(BBC.SEL_MAX.format(integer))); limit.ifPresent(integer -> actor.print(BBC.SEL_MAX.format(integer)));
break; break;
} }
case ELLIPSOID: case ELLIPSOID:
newSelector = new EllipsoidRegionSelector(oldSelector); newSelector = new EllipsoidRegionSelector(oldSelector);
player.print(BBC.SEL_ELLIPSIOD.s()); actor.print(BBC.SAL_ELLIPSOID.s());
break; break;
case SPHERE: case SPHERE:
newSelector = new SphereRegionSelector(oldSelector); newSelector = new SphereRegionSelector(oldSelector);
player.print(BBC.SEL_SPHERE.s()); actor.print(BBC.SEL_SPHERE.s());
break; break;
case CYL: case CYL:
newSelector = new CylinderRegionSelector(oldSelector); newSelector = new CylinderRegionSelector(oldSelector);
player.print(BBC.SEL_CYLINDRICAL.s()); actor.print(BBC.SEL_CYLINDRICAL.s());
break; break;
case CONVEX: case CONVEX:
case HULL: case HULL:
case POLYHEDRON: { case POLYHEDRON: {
newSelector = new ConvexPolyhedralRegionSelector(oldSelector); newSelector = new ConvexPolyhedralRegionSelector(oldSelector);
player.print(BBC.SEL_CONVEX_POLYHEDRAL.s()); actor.print(BBC.SEL_CONVEX_POLYHEDRAL.s());
Optional<Integer> limit = ActorSelectorLimits.forActor(player).getPolyhedronVertexLimit(); Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolyhedronVertexLimit();
limit.ifPresent(integer -> player.print(BBC.SEL_MAX.format(integer))); limit.ifPresent(integer -> actor.print(BBC.SEL_MAX.format(integer)));
break; break;
} }
case POLYHEDRAL: case POLYHEDRAL:
newSelector = new PolyhedralRegionSelector(player.getWorld()); newSelector = new PolyhedralRegionSelector(world);
player.print(BBC.SEL_CONVEX_POLYHEDRAL.s()); actor.print(BBC.SEL_CONVEX_POLYHEDRAL.s());
Optional<Integer> limit = ActorSelectorLimits.forActor(player).getPolyhedronVertexLimit(); Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolyhedronVertexLimit();
limit.ifPresent(integer -> player.print(BBC.SEL_MAX.format(integer))); limit.ifPresent(integer -> actor.print(BBC.SEL_MAX.format(integer)));
player.print(BBC.SEL_LIST.s()); actor.print(BBC.SEL_LIST.s());
break; break;
case FUZZY: case FUZZY:
case MAGIC: case MAGIC:
if (mask == null) { if (mask == null) {
mask = new IdMask(world); mask = new IdMask(world);
} }
newSelector = new FuzzyRegionSelector(player, editSession, mask); //TODO Make FuzzyRegionSelector accept actors
player.print(BBC.SEL_FUZZY.s()); newSelector = new FuzzyRegionSelector((Player) actor, editSession, mask);
player.print(BBC.SEL_LIST.s()); actor.print(BBC.SEL_FUZZY.s());
actor.print(BBC.SEL_LIST.s());
break; break;
case LIST: case LIST:
default: default:
@ -631,7 +639,7 @@ public class SelectionCommands {
box.appendCommand("polyhedral", "Select a hollow polyhedral", "//sel polyhedral"); box.appendCommand("polyhedral", "Select a hollow polyhedral", "//sel polyhedral");
box.appendCommand("fuzzy[=<mask>]", "Select all connected blocks (magic wand)", "//sel fuzzy[=<mask>]"); box.appendCommand("fuzzy[=<mask>]", "Select all connected blocks (magic wand)", "//sel fuzzy[=<mask>]");
player.print(box.create(1)); actor.print(box.create(1));
return; return;
} }
@ -646,14 +654,14 @@ public class SelectionCommands {
if (found != null) { if (found != null) {
session.setDefaultRegionSelector(found); session.setDefaultRegionSelector(found);
BBC.SELECTOR_SET_DEFAULT.send(player, found.name()); BBC.SELECTOR_SET_DEFAULT.send(actor, found.name());
} else { } else {
throw new RuntimeException("Something unexpected happened. Please report this."); throw new RuntimeException("Something unexpected happened. Please report this.");
} }
} }
session.setRegionSelector(world, newSelector); session.setRegionSelector(world, newSelector);
session.dispatchCUISelection(player); session.dispatchCUISelection(actor);
} }
} }

View File

@ -29,12 +29,14 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.formatting.component.PaginationBox; import com.sk89q.worldedit.util.formatting.component.PaginationBox;
import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.snapshot.InvalidSnapshotException; import com.sk89q.worldedit.world.snapshot.InvalidSnapshotException;
import com.sk89q.worldedit.world.snapshot.Snapshot; import com.sk89q.worldedit.world.snapshot.Snapshot;
import com.sk89q.worldedit.world.storage.MissingWorldException; import com.sk89q.worldedit.world.storage.MissingWorldException;
@ -67,24 +69,24 @@ public class SnapshotCommands {
desc = "List snapshots" desc = "List snapshots"
) )
@CommandPermissions("worldedit.snapshots.list") @CommandPermissions("worldedit.snapshots.list")
public void list(Player player, public void list(Actor actor, World world,
@ArgFlag(name = 'p', desc = "Page of results to return", def = "1") @ArgFlag(name = 'p', desc = "Page of results to return", def = "1")
int page) throws WorldEditException { int page) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
if (config.snapshotRepo == null) { if (config.snapshotRepo == null) {
BBC.SNAPSHOT_NOT_CONFIGURED.send(player); BBC.SNAPSHOT_NOT_CONFIGURED.send(actor);
return; return;
} }
try { try {
List<Snapshot> snapshots = config.snapshotRepo.getSnapshots(true, player.getWorld().getName()); List<Snapshot> snapshots = config.snapshotRepo.getSnapshots(true, world.getName());
if (!snapshots.isEmpty()) { if (!snapshots.isEmpty()) {
player.print(new SnapshotListBox(player.getWorld().getName(), snapshots).create(page)); actor.print(new SnapshotListBox(world.getName(), snapshots).create(page));
} else { } else {
BBC.SNAPSHOT_NOT_AVAILABLE.send(player); BBC.SNAPSHOT_NOT_AVAILABLE.send(actor);
// Okay, let's toss some debugging information! // Okay, let's toss some debugging information!
File dir = config.snapshotRepo.getDirectory(); File dir = config.snapshotRepo.getDirectory();
@ -99,7 +101,7 @@ public class SnapshotCommands {
} }
} }
} catch (MissingWorldException ex) { } catch (MissingWorldException ex) {
BBC.SNAPSHOT_NOT_FOUND_WORLD.send(player); BBC.SNAPSHOT_NOT_FOUND_WORLD.send(actor);
} }
} }
@ -108,37 +110,37 @@ public class SnapshotCommands {
desc = "Choose a snapshot to use" desc = "Choose a snapshot to use"
) )
@CommandPermissions("worldedit.snapshots.restore") @CommandPermissions("worldedit.snapshots.restore")
public void use(Player player, LocalSession session, public void use(Actor actor, World world, LocalSession session,
@Arg(desc = "Snapeshot to use") @Arg(desc = "Snapshot to use")
String name) throws WorldEditException { String name) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
if (config.snapshotRepo == null) { if (config.snapshotRepo == null) {
BBC.SNAPSHOT_NOT_CONFIGURED.send(player); BBC.SNAPSHOT_NOT_CONFIGURED.send(actor);
return; return;
} }
// Want the latest snapshot? // Want the latest snapshot?
if (name.equalsIgnoreCase("latest")) { if (name.equalsIgnoreCase("latest")) {
try { try {
Snapshot snapshot = config.snapshotRepo.getDefaultSnapshot(player.getWorld().getName()); Snapshot snapshot = config.snapshotRepo.getDefaultSnapshot(world.getName());
if (snapshot != null) { if (snapshot != null) {
session.setSnapshot(null); session.setSnapshot(null);
BBC.SNAPSHOT_NEWEST.send(player); BBC.SNAPSHOT_NEWEST.send(actor);
} else { } else {
BBC.SNAPSHOT_NOT_FOUND.send(player); BBC.SNAPSHOT_NOT_FOUND.send(actor);
} }
} catch (MissingWorldException ex) { } catch (MissingWorldException ex) {
BBC.SNAPSHOT_NOT_FOUND_WORLD.send(player); BBC.SNAPSHOT_NOT_FOUND_WORLD.send(actor);
} }
} else { } else {
try { try {
session.setSnapshot(config.snapshotRepo.getSnapshot(name)); session.setSnapshot(config.snapshotRepo.getSnapshot(name));
BBC.SNAPSHOT_SET.send(player, name); BBC.SNAPSHOT_SET.send(actor, name);
} catch (InvalidSnapshotException e) { } catch (InvalidSnapshotException e) {
BBC.SNAPSHOT_NOT_AVAILABLE.send(player); BBC.SNAPSHOT_NOT_AVAILABLE.send(actor);
} }
} }
} }

View File

@ -30,9 +30,10 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.command.util.Logging;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.snapshot.InvalidSnapshotException; import com.sk89q.worldedit.world.snapshot.InvalidSnapshotException;
import com.sk89q.worldedit.world.snapshot.Snapshot; import com.sk89q.worldedit.world.snapshot.Snapshot;
import com.sk89q.worldedit.world.snapshot.SnapshotRestore; import com.sk89q.worldedit.world.snapshot.SnapshotRestore;
@ -60,25 +61,25 @@ public class SnapshotUtilCommands {
) )
@Logging(REGION) @Logging(REGION)
@CommandPermissions("worldedit.snapshots.restore") @CommandPermissions("worldedit.snapshots.restore")
public void restore(Player player, LocalSession session, EditSession editSession, public void restore(Actor actor, World world, LocalSession session, EditSession editSession,
@Arg(name = "snapshot", desc = "The snapshot to restore", def = "") @Arg(name = "snapshot", desc = "The snapshot to restore", def = "")
String snapshotName) throws WorldEditException { String snapshotName) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
if (config.snapshotRepo == null) { if (config.snapshotRepo == null) {
BBC.SNAPSHOT_NOT_CONFIGURED.send(player); BBC.SNAPSHOT_NOT_CONFIGURED.send(actor);
return; return;
} }
Region region = session.getSelection(player.getWorld()); Region region = session.getSelection(world);
Snapshot snapshot; Snapshot snapshot;
if (snapshotName != null) { if (snapshotName != null) {
try { try {
snapshot = config.snapshotRepo.getSnapshot(snapshotName); snapshot = config.snapshotRepo.getSnapshot(snapshotName);
} catch (InvalidSnapshotException e) { } catch (InvalidSnapshotException e) {
BBC.SNAPSHOT_NOT_AVAILABLE.send(player); BBC.SNAPSHOT_NOT_AVAILABLE.send(actor);
return; return;
} }
} else { } else {
@ -88,10 +89,10 @@ public class SnapshotUtilCommands {
// No snapshot set? // No snapshot set?
if (snapshot == null) { if (snapshot == null) {
try { try {
snapshot = config.snapshotRepo.getDefaultSnapshot(player.getWorld().getName()); snapshot = config.snapshotRepo.getDefaultSnapshot(world.getName());
if (snapshot == null) { if (snapshot == null) {
BBC.SNAPSHOT_NOT_AVAILABLE.send(player); BBC.SNAPSHOT_NOT_AVAILABLE.send(actor);
// Okay, let's toss some debugging information! // Okay, let's toss some debugging information!
File dir = config.snapshotRepo.getDirectory(); File dir = config.snapshotRepo.getDirectory();
@ -108,7 +109,7 @@ public class SnapshotUtilCommands {
return; return;
} }
} catch (MissingWorldException ex) { } catch (MissingWorldException ex) {
BBC.SNAPSHOT_NOT_FOUND_WORLD.send(player); BBC.SNAPSHOT_NOT_FOUND_WORLD.send(actor);
return; return;
} }
} }
@ -116,7 +117,7 @@ public class SnapshotUtilCommands {
// Load chunk store // Load chunk store
try (ChunkStore chunkStore = snapshot.getChunkStore()) { try (ChunkStore chunkStore = snapshot.getChunkStore()) {
BBC.SNAPSHOT_LOADED.send(player, snapshot.getName()); BBC.SNAPSHOT_LOADED.send(actor, snapshot.getName());
// Restore snapshot // Restore snapshot
SnapshotRestore restore = new SnapshotRestore(chunkStore, editSession, region); SnapshotRestore restore = new SnapshotRestore(chunkStore, editSession, region);
@ -127,21 +128,20 @@ public class SnapshotUtilCommands {
if (restore.hadTotalFailure()) { if (restore.hadTotalFailure()) {
String error = restore.getLastErrorMessage(); String error = restore.getLastErrorMessage();
if (!restore.getMissingChunks().isEmpty()) { if (!restore.getMissingChunks().isEmpty()) {
BBC.SNAPSHOT_ERROR_RESTORE.send(player); BBC.SNAPSHOT_ERROR_RESTORE.send(actor);
} else if (error != null) { } else if (error != null) {
player.printError("Errors prevented any blocks from being restored."); actor.printError("Errors prevented any blocks from being restored.");
player.printError("Last error: " + error); actor.printError("Last error: " + error);
} else { } else {
BBC.SNAPSHOT_ERROR_RESTORE_CHUNKS.send(player); BBC.SNAPSHOT_ERROR_RESTORE_CHUNKS.send(actor);
} }
} else { } else {
player.print(String.format("Restored; %d " actor.print(String.format("Restored; %d missing chunks and %d other errors.",
+ "missing chunks and %d other errors.",
restore.getMissingChunks().size(), restore.getMissingChunks().size(),
restore.getErrorChunks().size())); restore.getErrorChunks().size()));
} }
} catch (DataException | IOException e) { } catch (DataException | IOException e) {
player.printError("Failed to load snapshot: " + e.getMessage()); actor.printError("Failed to load snapshot: " + e.getMessage());
} }
} }
} }

View File

@ -36,6 +36,7 @@ import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.ConfigurationLoadEvent; import com.sk89q.worldedit.event.platform.ConfigurationLoadEvent;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.NoCapablePlatformException;
import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extension.platform.PlatformManager; import com.sk89q.worldedit.extension.platform.PlatformManager;
import java.io.IOException; import java.io.IOException;
@ -98,8 +99,13 @@ public class WorldEditCommands {
actor.printDebug("----------- Capabilities -----------"); actor.printDebug("----------- Capabilities -----------");
for (Capability capability : Capability.values()) { for (Capability capability : Capability.values()) {
Platform platform = pm.queryCapability(capability); try {
actor.printDebug(String.format("%s: %s", capability.name(), platform != null ? platform.getPlatformName() : "NONE")); Platform platform = pm.queryCapability(capability);
actor.printDebug(String.format("%s: %s", capability.name(),
platform != null ? platform.getPlatformName() : "NONE"));
} catch (NoCapablePlatformException e) {
actor.printDebug(String.format("%s: %s", capability.name(), "NONE"));
}
} }
actor.printDebug(""); actor.printDebug("");
actor.printDebug("Wiki: " + "https://github.com/boy0001/FastAsyncWorldedit/wiki"); actor.printDebug("Wiki: " + "https://github.com/boy0001/FastAsyncWorldedit/wiki");
@ -120,7 +126,7 @@ public class WorldEditCommands {
@Command( @Command(
name = "report", name = "report",
aliases = { "debugpaste" }, aliases = { "debugpaste" },
desc = "Writes a report of latest.log, config.yml, message.yml and your commands.yml to https://athion.net/ISPaster/paste" desc = "Writes a report of latest.log, config.yml, message.yml https://athion.net/ISPaster/paste"
) )
@CommandQueued(false) @CommandQueued(false)
@CommandPermissions({"worldedit.report", "worldedit.debugpaste"}) @CommandPermissions({"worldedit.report", "worldedit.debugpaste"})
@ -162,19 +168,19 @@ public class WorldEditCommands {
name = "tz", name = "tz",
desc = "Set your timezone for snapshots" desc = "Set your timezone for snapshots"
) )
public void tz(Player player, LocalSession session, public void tz(Actor actor, LocalSession session,
@Arg(desc = "The timezone to set") @Arg(desc = "The timezone to set")
String timezone) { String timezone) {
try { try {
ZoneId tz = ZoneId.of(timezone); ZoneId tz = ZoneId.of(timezone);
session.setTimezone(tz); session.setTimezone(tz);
BBC.TIMEZONE_SET.send(player, tz.getDisplayName( BBC.TIMEZONE_SET.send(actor, tz.getDisplayName(
TextStyle.FULL, Locale.ENGLISH TextStyle.FULL, Locale.ENGLISH
)); ));
BBC.TIMEZONE_DISPLAY BBC.TIMEZONE_DISPLAY
.send(player, dateFormat.format(ZonedDateTime.now(tz))); .send(actor, dateFormat.format(ZonedDateTime.now(tz)));
} catch (ZoneRulesException e) { } catch (ZoneRulesException e) {
player.printError("Invalid timezone"); actor.printError("Invalid timezone");
} }
} }

View File

@ -19,11 +19,10 @@
package com.sk89q.worldedit.entity; package com.sk89q.worldedit.entity;
import com.sk89q.worldedit.extension.platform.Locatable;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Faceted; import com.sk89q.worldedit.util.Faceted;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.entity.EntityType; import com.sk89q.worldedit.world.entity.EntityType;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/** /**
@ -34,7 +33,7 @@ import javax.annotation.Nullable;
* instance of an entity, but a {@link BaseEntity} can be created from * instance of an entity, but a {@link BaseEntity} can be created from
* this entity by calling {@link #getState()}.</p> * this entity by calling {@link #getState()}.</p>
*/ */
public interface Entity extends Faceted { public interface Entity extends Faceted, Locatable {
/** /**
* Get a copy of the entity's state. * Get a copy of the entity's state.
@ -48,33 +47,11 @@ public interface Entity extends Faceted {
@Nullable @Nullable
BaseEntity getState(); BaseEntity getState();
/**
* Get the location of this entity.
*
* @return the location of the entity
*/
Location getLocation();
/**
* Sets the location of this entity.
*
* @param location the new location of the entity
* @return if the teleport worked
*/
boolean setLocation(Location location);
default EntityType getType() { default EntityType getType() {
BaseEntity state = getState(); BaseEntity state = getState();
return state != null ? state.getType() : null; return state != null ? state.getType() : null;
} }
/**
* Get the extent that this entity is on.
*
* @return the extent
*/
Extent getExtent();
/** /**
* Remove this entity from it container. * Remove this entity from it container.
* *

View File

@ -191,8 +191,12 @@ public interface Player extends Entity, Actor {
* Get the point of the block that is being stood in. * Get the point of the block that is being stood in.
* *
* @return point * @return point
* @deprecated Use Locatable#getBlockLocation
*/ */
Location getBlockIn(); @Deprecated
default Location getBlockIn() {
return getBlockLocation();
}
/** /**
* Get the point of the block that is being stood upon. * Get the point of the block that is being stood upon.

View File

@ -23,71 +23,33 @@ import com.boydti.fawe.command.FaweParser;
import com.boydti.fawe.command.SuggestInputParseException; import com.boydti.fawe.command.SuggestInputParseException;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
import com.boydti.fawe.util.StringMan; import com.boydti.fawe.util.StringMan;
import com.google.common.collect.Iterables;
import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandLocals; import com.sk89q.minecraft.util.commands.CommandLocals;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.command.MaskCommands;
import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.NoMatchException; import com.sk89q.worldedit.extension.input.NoMatchException;
import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.BlockMaskBuilder; import com.sk89q.worldedit.function.mask.BlockMaskBuilder;
import com.sk89q.worldedit.function.mask.BiomeMask2D;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.ExpressionMask;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.MaskIntersection; import com.sk89q.worldedit.function.mask.MaskIntersection;
import com.sk89q.worldedit.function.mask.MaskUnion; import com.sk89q.worldedit.function.mask.MaskUnion;
import com.sk89q.worldedit.internal.command.ActorAuthorizer;
import com.sk89q.worldedit.internal.command.WorldEditBinding;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.function.mask.OffsetMask;
import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment;
import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.command.Dispatcher;
import com.sk89q.worldedit.util.command.SimpleDispatcher;
import com.sk89q.worldedit.util.command.parametric.ParametricBuilder;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.ArrayList; import java.util.ArrayList;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.Biomes;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
public class DefaultMaskParser extends FaweParser<Mask> { public class DefaultMaskParser extends FaweParser<Mask> {
private final Dispatcher dispatcher; public DefaultMaskParser(WorldEdit worldEdit, PlatformCommandManager manager) {
private final Pattern INTERSECTION_PATTERN = Pattern.compile("[&|;]+(?![^\\[]*\\])"); super(worldEdit, manager, Mask.class);
public DefaultMaskParser(WorldEdit worldEdit) {
super(worldEdit);
this.dispatcher = new SimpleDispatcher();
this.register(new MaskCommands(worldEdit));
}
@Override
public Dispatcher getDispatcher() {
return dispatcher;
}
public void register(Object clazz) {
ParametricBuilder builder = new ParametricBuilder();
builder.setAuthorizer(new ActorAuthorizer());
builder.addBinding(new WorldEditBinding(worldEdit));
builder.registerMethodsAsCommands(dispatcher, clazz);
} }
@Override @Override
@ -111,53 +73,58 @@ public class DefaultMaskParser extends FaweParser<Mask> {
ParseEntry pe = entry.getKey(); ParseEntry pe = entry.getKey();
final String command = pe.input; final String command = pe.input;
String full = pe.full; String full = pe.full;
Mask mask = null; Mask mask;
if (command.isEmpty()) { if (command.isEmpty()) {
mask = parseFromInput(StringMan.join(entry.getValue(), ','), context); mask = parseFromInput(StringMan.join(entry.getValue(), ','), context);
} else if (dispatcher.get(command) == null) { } else {
// Legacy patterns mask = Iterables.getFirst(parse(input, actor), null);
char char0 = command.charAt(0); SuggestInputParseException suggestion = null; // TODO NOT IMPLEMENTED suggestion
boolean charMask = input.length() > 1 && input.charAt(1) != '['; if (mask == null) {
if (charMask && input.charAt(0) == '=') { // Legacy patterns
return parseFromInput(char0 + "[" + input.substring(1) + "]", context); char char0 = command.charAt(0);
} boolean charMask = input.length() > 1 && input.charAt(1) != '[';
if (char0 == '#' || char0 == '?') { if (charMask && input.charAt(0) == '=') {
throw new SuggestInputParseException(new NoMatchException("Unknown mask: " + full + ", See: //masks"), full, return parseFromInput(char0 + "[" + input.substring(1) + "]", context);
() -> { }
if (full.length() == 1) return new ArrayList<>(dispatcher.getPrimaryAliases()); if (char0 == '#' || char0 == '?') {
return dispatcher.getAliases().stream().filter( throw suggestion;
s -> s.startsWith(command.toLowerCase()) // throw new SuggestInputParseException(new NoMatchException("Unknown mask: " + full + ", See: //masks"), full,
).collect(Collectors.toList()); // () -> {
// if (full.length() == 1) return new ArrayList<>(dispatcher.getPrimaryAliases());
// return dispatcher.getAliases().stream().filter(
// s -> s.startsWith(command.toLowerCase())
// ).collect(Collectors.toList());
// }
// );
}
// Legacy syntax
if (charMask) {
switch (char0) {
case '\\': //
case '/': //
case '{': //
case '$': //
case '%': {
String value = command.substring(1) + ((entry.getValue().isEmpty()) ? "" : "[" + StringMan.join(entry.getValue(), "][") + "]");
if (value.contains(":")) {
if (value.charAt(0) == ':') value.replaceFirst(":", "");
value = value.replaceAll(":", "][");
}
mask = parseFromInput("#" + char0 + "[" + value + "]", context);
break;
} }
); case '|':
} case '~':
// Legacy syntax case '<':
if (charMask) { case '>':
switch (char0) { case '!':
case '\\': // input = input.substring(input.indexOf(char0) + 1);
case '/': // mask = parseFromInput(char0 + "[" + input + "]", context);
case '{': // if (actor != null) {
case '$': // BBC.COMMAND_CLARIFYING_BRACKET.send(actor, char0 + "[" + input + "]");
case '%': { }
String value = command.substring(1) + ((entry.getValue().isEmpty()) ? "" : "[" + StringMan.join(entry.getValue(), "][") + "]"); return mask;
if (value.contains(":")) {
if (value.charAt(0) == ':') value.replaceFirst(":", "");
value = value.replaceAll(":", "][");
}
mask = parseFromInput("#" + char0 + "[" + value + "]", context);
break;
} }
case '|':
case '~':
case '<':
case '>':
case '!':
input = input.substring(input.indexOf(char0) + 1);
mask = parseFromInput(char0 + "[" + input + "]", context);
if (actor != null) {
BBC.COMMAND_CLARIFYING_BRACKET.send(actor, char0 + "[" + input + "]");
}
return mask;
} }
} }
if (mask == null) { if (mask == null) {
@ -182,37 +149,38 @@ public class DefaultMaskParser extends FaweParser<Mask> {
} }
} }
} }
} else {
List<String> args = entry.getValue();
String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
try {
mask = (Mask) dispatcher.call(command + cmdArgs, locals, new String[0]);
} catch (SuggestInputParseException rethrow) {
throw rethrow;
} catch (Throwable e) {
throw SuggestInputParseException.of(e, full, () -> {
try {
List<String> suggestions = dispatcher.get(command).getCallable().getSuggestions(cmdArgs, locals);
if (suggestions.size() <= 2) {
for (int i = 0; i < suggestions.size(); i++) {
String suggestion = suggestions.get(i);
if (suggestion.indexOf(' ') != 0) {
String[] split = suggestion.split(" ");
suggestion = BBC.color("[" + StringMan.join(split, "][") + "]");
suggestions.set(i, suggestion);
}
}
}
return suggestions;
} catch (CommandException e1) {
throw new InputParseException(e1.getMessage());
} catch (Throwable e2) {
e2.printStackTrace();
throw new InputParseException(e2.getMessage());
}
});
}
} }
// else {
// List<String> args = entry.getValue();
// String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
// try {
// mask = (Mask) dispatcher.call(command + cmdArgs, locals, new String[0]);
// } catch (SuggestInputParseException rethrow) {
// throw rethrow;
// } catch (Throwable e) {
// throw SuggestInputParseException.of(e, full, () -> {
// try {
// List<String> suggestions = dispatcher.get(command).getCallable().getSuggestions(cmdArgs, locals);
// if (suggestions.size() <= 2) {
// for (int i = 0; i < suggestions.size(); i++) {
// String suggestion = suggestions.get(i);
// if (suggestion.indexOf(' ') != 0) {
// String[] split = suggestion.split(" ");
// suggestion = "[" + StringMan.join(split, "][") + "]";
// suggestions.set(i, suggestion);
// }
// }
// }
// return suggestions;
// } catch (CommandException e1) {
// throw new InputParseException(e1.getMessage());
// } catch (Throwable e2) {
// e2.printStackTrace();
// throw new InputParseException(e2.getMessage());
// }
// });
// }
// }
if (pe.and) { if (pe.and) {
masks.add(new ArrayList<>()); masks.add(new ArrayList<>());
} }

View File

@ -32,14 +32,11 @@ import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.NoMatchException; import com.sk89q.worldedit.extension.input.NoMatchException;
import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.function.pattern.RandomPattern; import com.sk89q.worldedit.function.pattern.RandomPattern;
import com.sk89q.worldedit.internal.command.ActorAuthorizer; import com.sk89q.worldedit.internal.command.ActorAuthorizer;
import com.sk89q.worldedit.internal.command.WorldEditBinding;
import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.util.command.Dispatcher;
import com.sk89q.worldedit.util.command.SimpleDispatcher;
import com.sk89q.worldedit.util.command.parametric.ParametricBuilder;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -49,24 +46,9 @@ import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
public class DefaultPatternParser extends FaweParser<Pattern> { public class DefaultPatternParser extends FaweParser<Pattern> {
private final Dispatcher dispatcher;
public DefaultPatternParser(WorldEdit worldEdit) { public DefaultPatternParser(WorldEdit worldEdit, PlatformCommandManager commandManager) {
super(worldEdit); super(worldEdit, commandManager, Pattern.class);
this.dispatcher = new SimpleDispatcher();
this.register(new PatternCommands());
}
@Override
public Dispatcher getDispatcher() {
return dispatcher;
}
public void register(Object clazz) {
ParametricBuilder builder = new ParametricBuilder();
builder.setAuthorizer(new ActorAuthorizer());
builder.addBinding(new WorldEditBinding(worldEdit));
builder.registerMethodsAsCommands(dispatcher, clazz);
} }
@Override @Override
@ -161,7 +143,7 @@ public class DefaultPatternParser extends FaweParser<Pattern> {
String suggestion = suggestions.get(i); String suggestion = suggestions.get(i);
if (suggestion.indexOf(' ') != 0) { if (suggestion.indexOf(' ') != 0) {
String[] split = suggestion.split(" "); String[] split = suggestion.split(" ");
suggestion = BBC.color("[" + StringMan.join(split, "][") + "]"); suggestion = "[" + StringMan.join(split, "][") + "]";
suggestions.set(i, suggestion); suggestions.set(i, suggestion);
} }
} }

View File

@ -19,7 +19,10 @@
package com.sk89q.worldedit.extension.platform; package com.sk89q.worldedit.extension.platform;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.NotABlockException; import com.sk89q.worldedit.NotABlockException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
@ -33,6 +36,7 @@ import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.TargetBlock; import com.sk89q.worldedit.util.TargetBlock;
import com.sk89q.worldedit.util.auth.AuthorizationException; import com.sk89q.worldedit.util.auth.AuthorizationException;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
@ -44,13 +48,13 @@ import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import java.io.File; import java.io.File;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/** /**
* An abstract implementation of both a {@link Actor} and a {@link Player} that is intended for * An abstract implementation of both a {@link Actor} and a {@link Player}
* implementations of WorldEdit to use to wrap players that make use of WorldEdit. * that is intended for implementations of WorldEdit to use to wrap
* players that make use of WorldEdit.
*/ */
public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@ -151,12 +155,12 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override @Override
public void findFreePosition() { public void findFreePosition() {
findFreePosition(getBlockIn()); findFreePosition(getBlockLocation());
} }
@Override @Override
public boolean ascendLevel() { public boolean ascendLevel() {
final Location pos = getBlockIn(); final Location pos = getBlockLocation();
final int x = pos.getBlockX(); final int x = pos.getBlockX();
int y = Math.max(0, pos.getBlockY()); int y = Math.max(0, pos.getBlockY());
final int z = pos.getBlockZ(); final int z = pos.getBlockZ();
@ -214,7 +218,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override @Override
public boolean descendLevel() { public boolean descendLevel() {
final Location pos = getBlockIn(); final Location pos = getBlockLocation();
final int x = pos.getBlockX(); final int x = pos.getBlockX();
int y = Math.max(0, pos.getBlockY()); int y = Math.max(0, pos.getBlockY());
final int z = pos.getBlockZ(); final int z = pos.getBlockZ();
@ -277,7 +281,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override @Override
public boolean ascendToCeiling(int clearance, boolean alwaysGlass) { public boolean ascendToCeiling(int clearance, boolean alwaysGlass) {
Location pos = getBlockIn(); Location pos = getBlockLocation();
int x = pos.getBlockX(); int x = pos.getBlockX();
int initialY = Math.max(0, pos.getBlockY()); int initialY = Math.max(0, pos.getBlockY());
int y = Math.max(0, pos.getBlockY() + 2); int y = Math.max(0, pos.getBlockY() + 2);
@ -294,6 +298,13 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
if (world.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial() if (world.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial()
.isMovementBlocker()) { .isMovementBlocker()) {
int platformY = Math.max(initialY, y - 3 - clearance); int platformY = Math.max(initialY, y - 3 - clearance);
if (platformY < initialY) { // if ==, they already have the given clearance, if <, clearance is too large
printError("Not enough space above you!");
return false;
} else if (platformY == initialY) {
printError("You're already at the ceiling.");
return false;
}
floatAt(x, platformY + 1, z, alwaysGlass); floatAt(x, platformY + 1, z, alwaysGlass);
return true; return true;
} }
@ -311,7 +322,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override @Override
public boolean ascendUpwards(int distance, boolean alwaysGlass) { public boolean ascendUpwards(int distance, boolean alwaysGlass) {
final Location pos = getBlockIn(); final Location pos = getBlockLocation();
final int x = pos.getBlockX(); final int x = pos.getBlockX();
final int initialY = Math.max(0, pos.getBlockY()); final int initialY = Math.max(0, pos.getBlockY());
int y = Math.max(0, pos.getBlockY() + 1); int y = Math.max(0, pos.getBlockY() + 1);
@ -338,27 +349,41 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override @Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) { public void floatAt(int x, int y, int z, boolean alwaysGlass) {
try { if (alwaysGlass || !isAllowedToFly()) {
BlockVector3 spot = BlockVector3.at(x, y - 1, z); BlockVector3 spot = BlockVector3.at(x, y - 1, z);
if (!getLocation().getExtent().getBlock(spot).getBlockType().getMaterial() final World world = getWorld();
.isMovementBlocker()) { if (!world.getBlock(spot).getBlockType().getMaterial().isMovementBlocker()) {
getLocation().getExtent().setBlock(spot, BlockTypes.GLASS.getDefaultState()); try (EditSession session = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, 1, this)) {
session.setBlock(spot, BlockTypes.GLASS.getDefaultState());
} catch (MaxChangedBlocksException ignored) {
} }
} catch (WorldEditException e) { }
e.printStackTrace(); } else {
setFlying(true);
} }
setPosition(Vector3.at(x + 0.5, y, z + 0.5)); setPosition(Vector3.at(x + 0.5, y, z + 0.5));
} }
@Override /**
public Location getBlockIn() { * Check whether the player is allowed to fly.
return getLocation().setPosition(getLocation().toVector().floor()); *
* @return true if allowed flight
*/
protected boolean isAllowedToFly() {
return false;
}
/**
* Set whether the player is currently flying.
*
* @param flying true to fly
*/
protected void setFlying(boolean flying) {
} }
@Override @Override
public Location getBlockOn() { public Location getBlockOn() {
return getLocation() return getLocation().setPosition(getLocation().setY(getLocation().getY() - 1).toVector().floor());
.setPosition(getLocation().setY(getLocation().getY() - 1).toVector().floor());
} }
@Override @Override
@ -407,15 +432,16 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override @Override
public Direction getCardinalDirection(int yawOffset) { public Direction getCardinalDirection(int yawOffset) {
if (getLocation().getPitch() > 67.5) { final Location location = getLocation();
if (location.getPitch() > 67.5) {
return Direction.DOWN; return Direction.DOWN;
} }
if (getLocation().getPitch() < -67.5) { if (location.getPitch() < -67.5) {
return Direction.UP; return Direction.UP;
} }
// From hey0's code // From hey0's code
double rot = (getLocation().getYaw() + yawOffset) % 360; //let's use real yaw now double rot = (location.getYaw() + yawOffset) % 360; //let's use real yaw now
if (rot < 0) { if (rot < 0) {
rot += 360.0; rot += 360.0;
} }
@ -435,56 +461,66 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
} }
} }
private boolean canPassThroughBlock(Location curBlock) {
BlockVector3 blockPos = curBlock.toVector().toBlockPoint();
BlockState block = curBlock.getExtent().getBlock(blockPos);
return !block.getBlockType().getMaterial().isMovementBlocker();
}
/** /**
* Get the player's view yaw. * Advances the block target block until the current block is a wall
* * @return true if a wall is found
* @return yaw
*/ */
private boolean advanceToWall(TargetBlock hitBlox) {
@Override Location curBlock;
public boolean passThroughForwardWall(int range) { while ((curBlock = hitBlox.getCurrentBlock()) != null) {
int searchDist = 0; if (!canPassThroughBlock(curBlock)) {
TargetBlock hitBlox = new TargetBlock(this, range, 0.2);
Extent world = getLocation().getExtent();
Location block;
boolean firstBlock = true;
int freeToFind = 2;
boolean inFree = false;
while ((block = hitBlox.getNextBlock()) != null) {
boolean free = !world.getBlock(block.toVector().toBlockPoint()).getBlockType()
.getMaterial().isMovementBlocker();
if (firstBlock) {
firstBlock = false;
if (!free) {
--freeToFind;
continue;
}
}
++searchDist;
if (searchDist > 20) {
return false;
}
if (inFree != free) {
if (free) {
--freeToFind;
}
}
if (freeToFind == 0) {
setOnGround(block);
return true; return true;
} }
inFree = free; hitBlox.getNextBlock();
} }
return false; return false;
} }
/**
* Advances the block target block until the current block is a free
* @return true if a free spot is found
*/
private boolean advanceToFree(TargetBlock hitBlox) {
Location curBlock;
while ((curBlock = hitBlox.getCurrentBlock()) != null) {
if (canPassThroughBlock(curBlock)) {
return true;
}
hitBlox.getNextBlock();
}
return false;
}
@Override
public boolean passThroughForwardWall(int range) {
TargetBlock hitBlox = new TargetBlock(this, range, 0.2);
if (!advanceToWall(hitBlox)) {
return false;
}
if (!advanceToFree(hitBlox)) {
return false;
}
Location foundBlock = hitBlox.getCurrentBlock();
if (foundBlock != null) {
setOnGround(foundBlock);
return true;
}
return false;
}
@Override @Override
public void setPosition(Vector3 pos) { public void setPosition(Vector3 pos) {

View File

@ -83,7 +83,7 @@ public interface Actor extends Identifiable, SessionOwner, Subject {
*/ */
void print(Component component); void print(Component component);
/** /**F
* Returns true if the actor can destroy bedrock. * Returns true if the actor can destroy bedrock.
* *
* @return true if bedrock can be broken by the actor * @return true if bedrock can be broken by the actor

View File

@ -232,7 +232,7 @@ public class BlockMaskBuilder {
private void suggest(String input, String property, Collection<BlockType> finalTypes) throws InputParseException { private void suggest(String input, String property, Collection<BlockType> finalTypes) throws InputParseException {
throw new SuggestInputParseException(input + " does not have: " + property, input, () -> { throw new SuggestInputParseException(input + " does not have: " + property, input, () -> {
Set<PropertyKey> keys = new HashSet<>(); Set<PropertyKey> keys = new HashSet<>();
finalTypes.forEach(t -> t.getProperties().stream().forEach(p -> keys.add(p.getKey()))); finalTypes.forEach(t -> t.getProperties().forEach(p -> keys.add(p.getKey())));
return keys.stream().map(PropertyKey::getId) return keys.stream().map(PropertyKey::getId)
.filter(p -> StringMan.blockStateMatches(property, p)) .filter(p -> StringMan.blockStateMatches(property, p))
.sorted(StringMan.blockStateComparator(property)) .sorted(StringMan.blockStateComparator(property))

View File

@ -22,20 +22,20 @@ package com.sk89q.worldedit.function.mask;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.google.common.base.Function;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import javax.annotation.Nullable;
import java.util.AbstractMap; import java.util.AbstractMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
import javax.annotation.Nullable;
/** /**
@ -100,7 +100,7 @@ public class MaskIntersection extends AbstractMask {
} }
} }
public Function<Map.Entry<Mask, Mask>, Mask> pairingFunction() { public Function<Entry<Mask, Mask>, Mask> pairingFunction() {
return input -> input.getKey().tryCombine(input.getValue()); return input -> input.getKey().tryCombine(input.getValue());
} }
@ -120,12 +120,11 @@ public class MaskIntersection extends AbstractMask {
} }
if (changed) { if (changed) {
masks.clear(); masks.clear();
for (Mask mask : masksArray) masks.add(mask); Collections.addAll(masks, masksArray);
} }
// Optimize this // Optimize this
boolean formArray = false; boolean formArray = false;
for (int i = 0; i < masksArray.length; i++) { for (Mask mask : masksArray) {
Mask mask = masksArray[i];
if (mask.getClass() == this.getClass()) { if (mask.getClass() == this.getClass()) {
this.masks.remove(mask); this.masks.remove(mask);
this.masks.addAll(((MaskIntersection) mask).getMasks()); this.masks.addAll(((MaskIntersection) mask).getMasks());
@ -162,7 +161,7 @@ public class MaskIntersection extends AbstractMask {
return changed ? this : null; return changed ? this : null;
} }
private boolean combineMasks(Function<Map.Entry<Mask, Mask>, Mask> pairing, Set<Map.Entry<Mask, Mask>> failedCombines) { private boolean combineMasks(Function<Entry<Mask, Mask>, Mask> pairing, Set<Map.Entry<Mask, Mask>> failedCombines) {
boolean hasOptimized = false; boolean hasOptimized = false;
while (true) { while (true) {
Mask[] result = null; Mask[] result = null;

View File

@ -19,16 +19,14 @@
package com.sk89q.worldedit.function.mask; package com.sk89q.worldedit.function.mask;
import com.google.common.base.Function;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/** /**
@ -81,7 +79,7 @@ public class MaskUnion extends MaskIntersection {
} }
@Override @Override
public Function<Map.Entry<Mask, Mask>, Mask> pairingFunction() { public Function<Entry<Mask, Mask>, Mask> pairingFunction() {
return input -> input.getKey().tryOr(input.getValue()); return input -> input.getKey().tryOr(input.getValue());
} }

View File

@ -21,13 +21,14 @@ package com.sk89q.worldedit.function.pattern;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.beta.FilterBlock;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
/** /**
* A pattern that returns the same {@link BaseBlock} each time. * A pattern that returns the same {@link BaseBlock} each time.
*
* @deprecated all BlockStateHolders can be used directly as a pattern
*/ */
@Deprecated @Deprecated
public class BlockPattern extends AbstractPattern { public class BlockPattern extends AbstractPattern {
@ -39,7 +40,6 @@ public class BlockPattern extends AbstractPattern {
* *
* @param block the block * @param block the block
*/ */
@Deprecated
public BlockPattern(BlockStateHolder<?> block) { public BlockPattern(BlockStateHolder<?> block) {
setBlock(block); setBlock(block);
} }

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.function.visitor; package com.sk89q.worldedit.function.visitor;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.Operation;
@ -58,6 +59,9 @@ public class RegionVisitor implements Operation {
this.iterable = iterable; this.iterable = iterable;
} }
public RegionVisitor(Region region, RegionFunction regionFunction, EditSession editSession) {
}
/** /**
* Get the number of affected objects. * Get the number of affected objects.
* *

View File

@ -1,17 +1,10 @@
package com.sk89q.worldedit.function.visitor; package com.sk89q.worldedit.function.visitor;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.longs.LongArraySet; import it.unimi.dsi.fastutil.longs.LongArraySet;
import it.unimi.dsi.fastutil.objects.ObjectIterator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
@ -24,12 +17,12 @@ public class ScanChunk {
public static final BlockVector3[] DIAGONAL_DIRECTIONS; public static final BlockVector3[] DIAGONAL_DIRECTIONS;
static { static {
DEFAULT_DIRECTIONS[0] = (BlockVector3.at(0, -1, 0)); DEFAULT_DIRECTIONS[0] = BlockVector3.at(0, -1, 0);
DEFAULT_DIRECTIONS[1] = (BlockVector3.at(0, 1, 0)); DEFAULT_DIRECTIONS[1] = BlockVector3.at(0, 1, 0);
DEFAULT_DIRECTIONS[2] = (BlockVector3.at(-1, 0, 0)); DEFAULT_DIRECTIONS[2] = BlockVector3.at(-1, 0, 0);
DEFAULT_DIRECTIONS[3] = (BlockVector3.at(1, 0, 0)); DEFAULT_DIRECTIONS[3] = BlockVector3.at(1, 0, 0);
DEFAULT_DIRECTIONS[4] = (BlockVector3.at(0, 0, -1)); DEFAULT_DIRECTIONS[4] = BlockVector3.at(0, 0, -1);
DEFAULT_DIRECTIONS[5] = (BlockVector3.at(0, 0, 1)); DEFAULT_DIRECTIONS[5] = BlockVector3.at(0, 0, 1);
List<BlockVector3> list = new ArrayList<>(); List<BlockVector3> list = new ArrayList<>();
for (int x = -1; x <= 1; x++) { for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) { for (int y = -1; y <= 1; y++) {
@ -43,13 +36,8 @@ public class ScanChunk {
} }
} }
} }
Collections.sort(list, new Comparator<BlockVector3>() { list.sort((o1, o2) -> (int) Math.signum(o1.lengthSq() - o2.lengthSq()));
@Override DIAGONAL_DIRECTIONS = list.toArray(new BlockVector3[0]);
public int compare(BlockVector3 o1, BlockVector3 o2) {
return (int) Math.signum(o1.lengthSq() - o2.lengthSq());
}
});
DIAGONAL_DIRECTIONS = list.toArray(new BlockVector3[list.size()]);
} }
private final RegionFunction function; private final RegionFunction function;
@ -57,7 +45,7 @@ public class ScanChunk {
private final Long2ObjectOpenHashMap<long[][]> visits; private final Long2ObjectOpenHashMap<long[][]> visits;
private final Long2ObjectOpenHashMap<char[][]> queues; private final Long2ObjectOpenHashMap<char[][]> queues;
public ScanChunk(final RegionFunction function) { public ScanChunk(RegionFunction function) {
this.function = function; this.function = function;
this.directions = DEFAULT_DIRECTIONS; this.directions = DEFAULT_DIRECTIONS;
@ -65,8 +53,8 @@ public class ScanChunk {
this.visits = new Long2ObjectOpenHashMap<>(); this.visits = new Long2ObjectOpenHashMap<>();
} }
public static final long pairInt(int x, int y) { public static long pairInt(int x, int y) {
return (((long) x) << 32) | (y & 0xffffffffL); return (long) x << 32 | y & 0xffffffffL;
} }
public boolean isVisited(int x, int y, int z) { public boolean isVisited(int x, int y, int z) {
@ -180,7 +168,7 @@ public class ScanChunk {
char triple = queue[index]; char triple = queue[index];
int x = index & 15; int x = index & 15;
int z = (index >> 4) & 15; int z = index >> 4 & 15;
int y = index >> 8; int y = index >> 8;
int absX = xx + x; int absX = xx + x;
@ -249,7 +237,7 @@ public class ScanChunk {
char triple = queue[index]; char triple = queue[index];
int x = index & 15; int x = index & 15;
int z = (index >> 4) & 15; int z = index >> 4 & 15;
int y = index >> 8; int y = index >> 8;
} }
queuePool.add(queue); queuePool.add(queue);
@ -327,11 +315,11 @@ public class ScanChunk {
} }
public void set(long[] bits, int i) { public void set(long[] bits, int i) {
bits[i >> 6] |= (1L << (i & 0x3F)); bits[i >> 6] |= 1L << (i & 0x3F);
} }
public boolean get(long[] bits, final int i) { public boolean get(long[] bits, int i) {
return (bits[i >> 6] & (1L << (i & 0x3F))) != 0; return (bits[i >> 6] & 1L << (i & 0x3F)) != 0;
} }
public char getLocalIndex(int x, int y, int z) { public char getLocalIndex(int x, int y, int z) {

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.internal.command.exception; package com.sk89q.worldedit.internal.command.exception;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.DisallowedItemException; import com.sk89q.worldedit.DisallowedItemException;
import com.sk89q.worldedit.EmptyClipboardException; import com.sk89q.worldedit.EmptyClipboardException;
@ -40,11 +41,11 @@ import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException; import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException;
import com.sk89q.worldedit.util.io.file.FilenameResolutionException; import com.sk89q.worldedit.util.io.file.FilenameResolutionException;
import com.sk89q.worldedit.util.io.file.InvalidFilenameException; import com.sk89q.worldedit.util.io.file.InvalidFilenameException;
import org.enginehub.piston.exception.CommandException; import com.sk89q.worldedit.world.storage.MissingWorldException;
import org.enginehub.piston.exception.UsageException;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.enginehub.piston.exception.CommandException;
import org.enginehub.piston.exception.UsageException;
/** /**
* converts WorldEdit exceptions and converts them into {@link CommandException}s. * converts WorldEdit exceptions and converts them into {@link CommandException}s.
@ -80,6 +81,10 @@ public class WorldEditExceptionConverter extends ExceptionConverterHelper {
throw newCommandException("Make a region selection first.", e); throw newCommandException("Make a region selection first.", e);
} }
@ExceptionMatch
public void convert(MissingWorldException e) throws CommandException {
throw newCommandException("You need to provide a world (Try //world)", e);
}
@ExceptionMatch @ExceptionMatch
public void convert(UnknownItemException e) throws CommandException { public void convert(UnknownItemException e) throws CommandException {
throw newCommandException("Block name '" + e.getID() + "' was not recognized.", e); throw newCommandException("Block name '" + e.getID() + "' was not recognized.", e);

View File

@ -19,8 +19,6 @@
package com.sk89q.worldedit.math.convolution; package com.sk89q.worldedit.math.convolution;
import com.boydti.fawe.object.visitor.Fast2DIterator;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
@ -34,7 +32,6 @@ import com.sk89q.worldedit.registry.state.PropertyGroup;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.Iterator; import java.util.Iterator;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -93,11 +90,10 @@ public class HeightMap {
BlockVector3 min = region.getMinimumPoint(); BlockVector3 min = region.getMinimumPoint();
int bx = min.getBlockX(); int bx = min.getBlockX();
int bz = min.getBlockZ(); int bz = min.getBlockZ();
Iterable<BlockVector2> flat = Regions.asFlatRegion(region).asFlatRegion(); Iterator<BlockVector2> flat = Regions.asFlatRegion(region).asFlatRegion().iterator();
Iterator<BlockVector2> iter = new Fast2DIterator(flat, session).iterator();
int layer = 0; int layer = 0;
while (iter.hasNext()) { while (flat.hasNext()) {
BlockVector2 pos = iter.next(); BlockVector2 pos = flat.next();
int x = pos.getBlockX(); int x = pos.getBlockX();
int z = pos.getBlockZ(); int z = pos.getBlockZ();
layer = session.getNearestSurfaceLayer(x, z, (layer + 7) >> 3, 0, maxY); layer = session.getNearestSurfaceLayer(x, z, (layer + 7) >> 3, 0, maxY);

View File

@ -32,6 +32,7 @@ import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.registry.Keyed;
import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
@ -41,11 +42,12 @@ import com.sk89q.worldedit.world.weather.WeatherType;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Locale;
/** /**
* Represents a world (dimension). * Represents a world (dimension).
*/ */
public interface World extends Extent { public interface World extends Extent, Keyed {
/** /**
* Get the name of the world. * Get the name of the world.
@ -284,4 +286,8 @@ public interface World extends Extent {
return true; return true;
} }
@Override
default String getId() {
return getName().replace(" ", "_").toLowerCase(Locale.ROOT);
}
} }

View File

@ -182,7 +182,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
@Override @Override
public void setNbtData(@Nullable CompoundTag nbtData) { public void setNbtData(@Nullable CompoundTag nbtData) {
throw new UnsupportedOperationException("Immutable"); throw new UnsupportedOperationException("This class is immutable.");
} }
/** /**
@ -239,7 +239,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
} }
@Override @Override
public final BaseBlock toBaseBlock() { public BaseBlock toBaseBlock() {
return this; return this;
} }

View File

@ -301,6 +301,9 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
@Override @Override
public boolean equalsFuzzy(BlockStateHolder<?> o) { public boolean equalsFuzzy(BlockStateHolder<?> o) {
if (null == o) {
return false;
}
if (this == o) { if (this == o) {
// Added a reference equality check for speediness // Added a reference equality check for speediness
return true; return true;
@ -308,9 +311,6 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
if (o.getClass() == BlockState.class) { if (o.getClass() == BlockState.class) {
return o.getOrdinal() == this.getOrdinal(); return o.getOrdinal() == this.getOrdinal();
} }
if (null == o) {
return false;
}
return o.equalsFuzzy(this); return o.equalsFuzzy(this);
} }