From 01c371df9c57bb79ca3bb3c9b2b984f5d149845b Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Tue, 23 Jul 2019 19:17:38 -0400 Subject: [PATCH] Minor upstream changes and obviously more command work --- .../worldedit/blocks/MobSpawnerBlock.java | 64 +++++++++------- .../com/sk89q/worldedit/blocks/SignBlock.java | 14 ++-- .../sk89q/worldedit/blocks/SkullBlock.java | 17 +++-- .../boydti/fawe/command/AnvilCommands.java | 11 ++- .../com/boydti/fawe/command/CFICommand.java | 17 +++-- .../command/SuggestInputParseException.java | 13 +--- .../worldedit/command/ApplyBrushCommands.java | 11 +-- .../command/BrushOptionsCommands.java | 8 +- .../worldedit/command/RegionCommands.java | 76 +++++++++---------- .../worldedit/command/SchematicCommands.java | 28 +++---- .../extent/clipboard/io/ClipboardFormat.java | 15 ++-- .../scripting/RhinoCraftScriptEngine.java | 2 +- .../scripting/java/RhinoScriptEngine.java | 6 +- 13 files changed, 144 insertions(+), 138 deletions(-) diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java index eb0c2e382..17a62781d 100644 --- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java +++ b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java @@ -19,7 +19,10 @@ package com.sk89q.worldedit.blocks; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.NBTUtils; import com.sk89q.jnbt.ShortTag; @@ -28,7 +31,6 @@ import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.storage.InvalidFormatException; - import java.util.HashMap; import java.util.Map; @@ -38,17 +40,17 @@ import java.util.Map; public class MobSpawnerBlock extends BaseBlock { private String mobType; - private short delay; + private short delay = -1; // advanced mob spawner features - private short spawnCount; - private short spawnRange; + private short spawnCount = 4; + private short spawnRange = 4; private CompoundTag spawnData; private ListTag spawnPotentials; - private short minSpawnDelay; - private short maxSpawnDelay; - private short maxNearbyEntities; - private short requiredPlayerRange; + private short minSpawnDelay = 200; + private short maxSpawnDelay = 800; + private short maxNearbyEntities = 6; + private short requiredPlayerRange = 16; /** * Construct the mob spawner block with a specified data value. @@ -113,7 +115,7 @@ public class MobSpawnerBlock extends BaseBlock { @Override public String getNbtId() { - return "MobSpawner"; + return "minecraft:mob_spawner"; } @Override @@ -127,10 +129,16 @@ public class MobSpawnerBlock extends BaseBlock { values.put("MaxSpawnDelay", new ShortTag(maxSpawnDelay)); values.put("MaxNearbyEntities", new ShortTag(maxNearbyEntities)); values.put("RequiredPlayerRange", new ShortTag(requiredPlayerRange)); - if (spawnData != null) { + if (spawnData == null) { + values.put("SpawnData", new CompoundTag(ImmutableMap.of("id", new StringTag(mobType)))); + } else { values.put("SpawnData", new CompoundTag(spawnData.getValue())); } - if (spawnPotentials != null) { + if (spawnPotentials == null) { + values.put("SpawnPotentials", new ListTag(CompoundTag.class, ImmutableList.of( + new CompoundTag(ImmutableMap.of("Weight", new IntTag(1), "Entity", + new CompoundTag(ImmutableMap.of("id", new StringTag(mobType)))))))); + } else { values.put("SpawnPotentials", new ListTag(CompoundTag.class, spawnPotentials.getValue())); } @@ -146,22 +154,32 @@ public class MobSpawnerBlock extends BaseBlock { Map values = rootTag.getValue(); Tag t = values.get("id"); - if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("MobSpawner")) { - throw new RuntimeException("'MobSpawner' tile entity expected"); + if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals(getNbtId())) { + throw new RuntimeException(String.format("'%s' tile entity expected", getNbtId())); } - StringTag mobTypeTag; + CompoundTag spawnDataTag; + String mobType; ShortTag delayTag; try { - mobTypeTag = NBTUtils.getChildTag(values, "EntityId", StringTag.class); - delayTag = NBTUtils.getChildTag(values, "Delay", ShortTag.class); + spawnDataTag = NBTUtils.getChildTag(values, "SpawnData", CompoundTag.class); + mobType = spawnDataTag.getString("id"); + if (mobType.equals("")) { + throw new InvalidFormatException("No spawn id."); + } + this.mobType = mobType; + this.spawnData = spawnDataTag; } catch (InvalidFormatException ignored) { - throw new RuntimeException("Invalid mob spawner data: no EntityId and/or no Delay"); + throw new RuntimeException("Invalid mob spawner data: no SpawnData and/or no Delay"); + } + try { + delayTag = NBTUtils.getChildTag(values, "Delay", ShortTag.class); + this.delay = delayTag.getValue(); + } catch (InvalidFormatException ignored) { + this.delay = -1; } - this.mobType = mobTypeTag.getValue(); - this.delay = delayTag.getValue(); ShortTag spawnCountTag = null; ShortTag spawnRangeTag = null; @@ -170,7 +188,6 @@ public class MobSpawnerBlock extends BaseBlock { ShortTag maxNearbyEntitiesTag = null; ShortTag requiredPlayerRangeTag = null; ListTag spawnPotentialsTag = null; - CompoundTag spawnDataTag = null; try { spawnCountTag = NBTUtils.getChildTag(values, "SpawnCount", ShortTag.class); } catch (InvalidFormatException ignored) { @@ -199,10 +216,6 @@ public class MobSpawnerBlock extends BaseBlock { spawnPotentialsTag = NBTUtils.getChildTag(values, "SpawnPotentials", ListTag.class); } catch (InvalidFormatException ignored) { } - try { - spawnDataTag = NBTUtils.getChildTag(values, "SpawnData", CompoundTag.class); - } catch (InvalidFormatException ignored) { - } if (spawnCountTag != null) { this.spawnCount = spawnCountTag.getValue(); @@ -225,9 +238,6 @@ public class MobSpawnerBlock extends BaseBlock { if (spawnPotentialsTag != null) { this.spawnPotentials = new ListTag(CompoundTag.class, spawnPotentialsTag.getValue()); } - if (spawnDataTag != null) { - this.spawnData = new CompoundTag(spawnDataTag.getValue()); - } } } diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java index 4cc0e5bcb..8f8015a33 100644 --- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java +++ b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java @@ -40,7 +40,7 @@ public class SignBlock extends BaseBlock { /** * Construct the sign with text. - * + * * @param blockState The block state * @param text lines of text */ @@ -62,7 +62,7 @@ public class SignBlock extends BaseBlock { /** * Get the text. - * + * * @return the text */ public String[] getText() { @@ -71,7 +71,7 @@ public class SignBlock extends BaseBlock { /** * Set the text. - * + * * @param text the text to set */ public void setText(String[] text) { @@ -80,7 +80,7 @@ public class SignBlock extends BaseBlock { } this.text = text; } - + @Override public boolean hasNbtData() { return true; @@ -88,7 +88,7 @@ public class SignBlock extends BaseBlock { @Override public String getNbtId() { - return "Sign"; + return "minecraft:sign"; } @Override @@ -114,8 +114,8 @@ public class SignBlock extends BaseBlock { text = new String[] { EMPTY, EMPTY, EMPTY, EMPTY }; t = values.get("id"); - if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("Sign")) { - throw new RuntimeException("'Sign' tile entity expected"); + if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals(getNbtId())) { + throw new RuntimeException(String.format("'%s' tile entity expected", getNbtId())); } t = values.get("Text1"); diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SkullBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SkullBlock.java index e65ab3ec1..944b4ab42 100644 --- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SkullBlock.java +++ b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SkullBlock.java @@ -83,14 +83,15 @@ public class SkullBlock extends BaseBlock { @Override public String getNbtId() { - return "Skull"; + return "skull"; } @Override public CompoundTag getNbtData() { Map values = new HashMap<>(); - if (owner == null) owner = ""; - values.put("ExtraType", new StringTag(owner)); + Map inner = new HashMap<>(); + inner.put("Name", new StringTag(owner)); + values.put("Owner", new CompoundTag(inner)); return new CompoundTag(values); } @@ -105,13 +106,13 @@ public class SkullBlock extends BaseBlock { Tag t; t = values.get("id"); - if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("Skull")) { - throw new RuntimeException("'Skull' tile entity expected"); + if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals(getNbtId())) { + throw new RuntimeException(String.format("'%s' tile entity expected", getNbtId())); } - t = values.get("ExtraType"); - if (t instanceof StringTag) { - owner = ((StringTag) t).getValue(); + t = values.get("Owner"); + if (t instanceof CompoundTag) { + setOwner(((CompoundTag) t).getValue().get("Name").getValue().toString()); } } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/command/AnvilCommands.java b/worldedit-core/src/main/java/com/boydti/fawe/command/AnvilCommands.java index 0b256ff7b..db14faf32 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/command/AnvilCommands.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/command/AnvilCommands.java @@ -111,10 +111,14 @@ public class AnvilCommands { name = "replaceall", aliases = {"rea", "repall"}, desc = "Replace all blocks in the selection with another", - descFooter = "The -d flag disabled wildcard data matching\n" ) @CommandPermissions("worldedit.anvil.replaceall") - public void replaceAll(Player player, String folder, @Arg(name = "from", desc = "String", def = "") String from, String to, @Switch(name = 'd', desc = "TODO") boolean useData) throws WorldEditException { + public void replaceAll(Player player, String folder, + @Arg(name = "from", desc = "String", def = "") + String from, + String to, + @Switch(name = 'd', desc = "Disable wildcard data matching") + boolean useData) throws WorldEditException { // final FaweBlockMatcher matchFrom; TODO NOT IMPLEMENTED // if (from == null) { // matchFrom = FaweBlockMatcher.NOT_AIR; @@ -234,8 +238,7 @@ public class AnvilCommands { name = "trimallplots", desc = "Trim chunks in a Plot World", - descFooter = "Unclaimed chunks will be deleted\n" + - "Unmodified chunks will be deleted\n" + descFooter = "Unclaimed chunks will be deleted\nUnmodified chunks will be deleted\n" ) @CommandPermissions("worldedit.anvil.trimallplots") public void trimAllPlots(Player player, @Switch(name = 'v', desc = "Delete unvisited chunks") boolean deleteUnvisited) throws WorldEditException { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommand.java b/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommand.java index 7b3dfb6a5..02b85a89f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommand.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommand.java @@ -1,5 +1,7 @@ package com.boydti.fawe.command; +import static com.sk89q.worldedit.util.formatting.text.TextComponent.newline; + import com.boydti.fawe.config.Commands; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.brush.visualization.cfi.HeightMapMCAGenerator; @@ -56,13 +58,14 @@ public class CFICommand extends CommandProcessor { hmCmd = Commands.getAlias(CFICommands.class, "heightmap") + " " + settings.imageArg; } - TextComponent.of("What do you want to use as the base?").newline() - .text("[HeightMap]").cmdTip(hmCmd).text(" - A heightmap like ") - .text("[this]").linkTip("http://i.imgur.com/qCd30MR.jpg") - .newline() - .text("[Empty]").cmdTip(CFICommands.alias() + " empty") - .text("- An empty map of a specific size") - .send(fp); + TextComponent build = TextComponent.builder("What do you want to use as the base?") + .append(newline()) + .append("[HeightMap]")/* TODO .cmdTip(hmCmd).*/.append(" - A heightmap like ") + .append("[this]")//TODO .linkTip("http://i.imgur.com/qCd30MR.jpg") + .append(newline()) + .append("[Empty]")//TODO .cmdTip(CFICommands.alias() + " empty") + .append("- An empty map of a specific size").build(); + fp.toWorldEditPlayer().print(build); } else { args = new ArrayList<>(args); switch (args.size()) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/command/SuggestInputParseException.java b/worldedit-core/src/main/java/com/boydti/fawe/command/SuggestInputParseException.java index 595044844..7af1cd09b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/command/SuggestInputParseException.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/command/SuggestInputParseException.java @@ -1,20 +1,13 @@ package com.boydti.fawe.command; -import com.boydti.fawe.util.MainUtil; -import com.boydti.fawe.util.StringMan; -import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.extension.input.InputParseException; +import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.worldedit.extension.input.InputParseException; import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.List; import java.util.function.Supplier; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkNotNull; - public class SuggestInputParseException extends InputParseException { private final InputParseException cause; @@ -56,7 +49,7 @@ public class SuggestInputParseException extends InputParseException { public static SuggestInputParseException of(String input, List values) { throw new SuggestInputParseException("No value: " + input, input, () -> values.stream() - .map(v -> v.toString()) + .map(Object::toString) .filter(v -> v.startsWith(input)) .collect(Collectors.toList())); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java index 8a025f2f2..5a4dd3513 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java @@ -19,6 +19,9 @@ package com.sk89q.worldedit.command; +import static java.util.Objects.requireNonNull; +import static org.enginehub.piston.part.CommandParts.arg; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.sk89q.worldedit.LocalSession; @@ -29,8 +32,6 @@ import com.sk89q.worldedit.command.factory.ReplaceFactory; import com.sk89q.worldedit.command.factory.TreeGeneratorFactory; import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; -import com.sk89q.worldedit.command.util.CommandQueued; -import com.sk89q.worldedit.command.util.CommandQueuedConditionGenerator; import com.sk89q.worldedit.command.util.PermissionCondition; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.function.Contextual; @@ -45,6 +46,7 @@ import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.util.formatting.text.format.TextDecoration; +import java.util.stream.Collectors; import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandManagerService; import org.enginehub.piston.CommandParameters; @@ -55,11 +57,6 @@ import org.enginehub.piston.inject.Key; import org.enginehub.piston.part.CommandArgument; import org.enginehub.piston.part.SubCommandPart; -import java.util.stream.Collectors; - -import static java.util.Objects.requireNonNull; -import static org.enginehub.piston.part.CommandParts.arg; - @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) public class ApplyBrushCommands { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushOptionsCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushOptionsCommands.java index f01b507dd..379142e56 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushOptionsCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushOptionsCommands.java @@ -63,12 +63,11 @@ public class BrushOptionsCommands { @Command( name = "savebrush", aliases = {"save"}, - desc = "Save your current brush", - descFooter = "Save your current brush use the -g flag to save globally" + desc = "Save your current brush" ) @CommandPermissions("worldedit.brush.save") public void saveBrush(Player player, LocalSession session, String name, - @Switch(name = 'g', desc = "TODO") boolean root) throws WorldEditException, IOException { + @Switch(name = 'g', desc = "Save the brush globally") boolean root) throws WorldEditException, IOException { BrushTool tool = session.getBrushTool(player); if (tool != null) { root |= name.startsWith("../"); @@ -134,8 +133,7 @@ public class BrushOptionsCommands { @Command( name = "/listbrush", desc = "List saved brushes", - descFooter = "List all brushes in the brush directory\n" + - " -p prints the requested page\n" + descFooter = "List all brushes in the brush directory" ) @CommandPermissions("worldedit.brush.list") public void list(Actor actor, InjectedValueAccess args, diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java index 2420372bd..cce58e383 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java @@ -42,6 +42,7 @@ import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.function.GroundFunction; import com.sk89q.worldedit.function.generator.FloraGenerator; import com.sk89q.worldedit.function.mask.ExistingBlockMask; @@ -69,6 +70,7 @@ import com.sk89q.worldedit.regions.RegionOperationException; import com.sk89q.worldedit.regions.Regions; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.TreeGenerator.TreeType; +import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.util.ArrayList; @@ -84,7 +86,7 @@ import org.enginehub.piston.inject.InjectedValueAccess; * Commands that operate on regions. */ @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) -public class RegionCommands extends MethodCommands { +public class RegionCommands { private final WorldEdit worldEdit; @@ -103,7 +105,7 @@ public class RegionCommands extends MethodCommands { desc = "Get the light at a position" ) @CommandPermissions("worldedit.light.fix") - public void fixlighting(Player player) throws WorldEditException { + public void fixLighting(Player player) throws WorldEditException { FawePlayer fp = FawePlayer.wrap(player); final Location loc = player.getLocation(); Region selection = fp.getSelection(); @@ -121,7 +123,7 @@ public class RegionCommands extends MethodCommands { desc = "Get the light at a position" ) @CommandPermissions("worldedit.light.fix") - public void getlighting(Player player, EditSession editSession) throws WorldEditException { + public void getLighting(Player player, EditSession editSession) throws WorldEditException { FawePlayer fp = FawePlayer.wrap(player); final Location loc = player.getLocation(); int block = editSession.getBlockLight(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); @@ -134,7 +136,7 @@ public class RegionCommands extends MethodCommands { desc = "Removing lighting in a selection" ) @CommandPermissions("worldedit.light.remove") - public void removelighting(Player player) { + public void removeLighting(Player player) { FawePlayer fp = FawePlayer.wrap(player); Region selection = fp.getSelection(); if (selection == null) { @@ -190,7 +192,7 @@ public class RegionCommands extends MethodCommands { ) @CommandPermissions("worldedit.region.line") @Logging(REGION) - public int line(Player player, EditSession editSession, + public int line(Actor actor, EditSession editSession, @Selection Region region, @Arg(desc = "The pattern of blocks to place") Pattern pattern, @@ -199,7 +201,7 @@ public class RegionCommands extends MethodCommands { @Switch(name = 'h', desc = "Generate only a shell") boolean shell) throws WorldEditException { if (!(region instanceof CuboidRegion)) { - player.printError("//line only works with cuboid selections"); + actor.printError("//line only works with cuboid selections"); return 0; } checkCommandArgument(thickness >= 0, "Thickness must be >= 0"); @@ -209,7 +211,7 @@ public class RegionCommands extends MethodCommands { BlockVector3 pos2 = cuboidregion.getPos2(); int blocksChanged = editSession.drawLine(pattern, pos1, pos2, thickness, !shell); - BBC.VISITOR_BLOCK.send(player, blocksChanged); + BBC.VISITOR_BLOCK.send(actor, blocksChanged); return blocksChanged; } @@ -340,11 +342,11 @@ public class RegionCommands extends MethodCommands { ) @Logging(REGION) @CommandPermissions("worldedit.region.center") - public void center(Player player, EditSession editSession, @Selection Region region, + public void center(Actor actor, EditSession editSession, @Selection Region region, @Arg(desc = "The pattern of blocks to set") Pattern pattern) throws WorldEditException { int affected = editSession.center(region, pattern); - BBC.VISITOR_BLOCK.send(player, affected); + BBC.VISITOR_BLOCK.send(actor, affected); } @Command( @@ -458,18 +460,11 @@ public class RegionCommands extends MethodCommands { @Command( name = "/move", - desc = "Move the contents of the selection", - descFooter = - "Moves the contents of the selection.\n" + - "The -s flag shifts the selection to the target location.\n" + - "The -b also copies biomes\n" + - "The -e ignores entities\n" + - "The -a ignores air blocks.\n" + - "Optionally fills the old location with ." -) + desc = "Move the contents of the selection" + ) @CommandPermissions("worldedit.region.move") @Logging(ORIENTATION_REGION) - public void move(FawePlayer player, EditSession editSession, LocalSession session, + public void move(FawePlayer player, World world, EditSession editSession, LocalSession session, @Selection Region region, @Arg(desc = "# of blocks to move", def = "1") int count, @@ -482,23 +477,21 @@ public class RegionCommands extends MethodCommands { boolean moveSelection, @Switch(name = 'a', desc = "Ignore air blocks") boolean ignoreAirBlocks, - @Switch(name = 'b', desc = "TODO") + @Switch(name = 'b', desc = "Copy Biomes") boolean copyBiomes, - @Switch(name = 'e', desc = "TODO") + @Switch(name = 'e', desc = "Ignore entities") boolean skipEntities, - @Switch(name = 'a', desc = "TODO") - boolean skipAir, InjectedValueAccess context) throws WorldEditException { checkCommandArgument(count >= 1, "Count must be >= 1"); player.checkConfirmationRegion(() -> { - int affected = editSession.moveRegion(region, direction, count, !skipAir, !skipEntities, copyBiomes, replace); + int affected = editSession.moveRegion(region, direction, count, !ignoreAirBlocks, !skipEntities, copyBiomes, replace); if (moveSelection) { try { region.shift(direction.multiply(count)); - session.getRegionSelector(player.getWorld()).learnChanges(); - session.getRegionSelector(player.getWorld()).explainRegionAdjust(player.getPlayer(), session); + session.getRegionSelector(world).learnChanges(); + session.getRegionSelector(world).explainRegionAdjust(player.getPlayer(), session); } catch (RegionOperationException e) { player.printError(e.getMessage()); } @@ -533,7 +526,7 @@ public class RegionCommands extends MethodCommands { ) @CommandPermissions("worldedit.region.stack") @Logging(ORIENTATION_REGION) - public void stack(FawePlayer player, EditSession editSession, LocalSession session, + public void stack(FawePlayer player, World world, EditSession editSession, LocalSession session, @Selection Region region, @Arg(desc = "# of copies to stack", def = "1") int count, @@ -542,11 +535,15 @@ public class RegionCommands extends MethodCommands { BlockVector3 direction, @Switch(name = 's', desc = "Shift the selection to the last stacked copy") boolean moveSelection, - @Switch(name = 'b', desc = "//TODO") boolean copyBiomes, - @Switch(name = 'e', desc = "//TODO") boolean skipEntities, + @Switch(name = 'b', desc = "Copy Biomes") + boolean copyBiomes, + @Switch(name = 'e', desc = "Skip entities") + boolean skipEntities, @Switch(name = 'a', desc = "Ignore air blocks") boolean ignoreAirBlocks, - @Switch(name = 'm', desc = "TODO") Mask sourceMask, InjectedValueAccess context) throws WorldEditException { + @Switch(name = 'm', desc = "TODO") + Mask sourceMask, + InjectedValueAccess context) throws WorldEditException { player.checkConfirmationStack(() -> { if (sourceMask != null) { editSession.addSourceMask(sourceMask); @@ -555,14 +552,15 @@ public class RegionCommands extends MethodCommands { if (moveSelection) { try { - final BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1); - final BlockVector3 shiftVector = BlockVector3.at(direction.getX() * size.getX() * count, direction.getY() * size.getY() * count, direction.getZ() * size.getZ() * count); + final BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()); + + final BlockVector3 shiftVector = direction.toVector3().multiply(count * (Math.abs(direction.dot(size)) + 1)).toBlockPoint(); region.shift(shiftVector); - session.getRegionSelector(player.getWorld()).learnChanges(); - session.getRegionSelector(player.getWorld()).explainRegionAdjust(player.getPlayer(), session); + session.getRegionSelector(world).learnChanges(); + session.getRegionSelector(world).explainRegionAdjust(player.getPlayer(), session); } catch (RegionOperationException e) { - player.sendMessage(e.getMessage()); + player.toWorldEditPlayer().printError(e.getMessage()); } } @@ -670,11 +668,12 @@ public class RegionCommands extends MethodCommands { public void hollow(FawePlayer player, EditSession editSession, @Selection Region region, @Arg(desc = "Thickness of the shell to leave", def = "0") - @Range(min = 0) int thickness, + int thickness, @Arg(desc = "The pattern of blocks to replace the hollowed area with", def = "air") Pattern pattern, @Switch(name = 'm', desc = "Mask to hollow with") Mask mask, InjectedValueAccess context) throws WorldEditException { + checkCommandArgument(thickness >= 0, "Thickness must be >= 0"); Mask finalMask = mask == null ? new SolidBlockMask(editSession) : mask; player.checkConfirmationRegion(() -> { int affected = editSession.hollowOutRegion(region, thickness, pattern, finalMask); @@ -688,14 +687,15 @@ public class RegionCommands extends MethodCommands { ) @CommandPermissions("worldedit.region.forest") @Logging(REGION) - public void forest(Player player, EditSession editSession, @Selection Region region, + public int forest(Actor actor, EditSession editSession, @Selection Region region, @Arg(desc = "The type of tree to place", def = "tree") TreeType type, @Arg(desc = "The density of the forest", def = "5") double density) throws WorldEditException { checkCommandArgument(0 <= density && density <= 100, "Density must be in [0, 100]"); int affected = editSession.makeForest(region, density / 100, type); - BBC.COMMAND_TREE.send(player, affected); + BBC.COMMAND_TREE.send(actor, affected); + return affected; } @Command( diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index c474241f9..6cd085572 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -201,7 +201,7 @@ public class SchematicCommands { desc = "Load a schematic into your clipboard" ) @CommandPermissions({"worldedit.clipboard.load", "worldedit.schematic.load", "worldedit.schematic.load.asset", "worldedit.schematic.load.web", "worldedit.schematic.load.other"}) - public void load(Player player, LocalSession session, + public void load(Actor actor, LocalSession session, @Arg(desc = "File name.") String filename, @Arg(desc = "Format name.", def = "sponge") @@ -213,8 +213,8 @@ public class SchematicCommands { try { URI uri; if (filename.startsWith("url:")) { - if (!player.hasPermission("worldedit.schematic.load.web")) { - BBC.NO_PERM.send(player, "worldedit.schematic.load.web"); + if (!actor.hasPermission("worldedit.schematic.load.web")) { + BBC.NO_PERM.send(actor, "worldedit.schematic.load.web"); return; } UUID uuid = UUID.fromString(filename.substring(4)); @@ -225,7 +225,7 @@ public class SchematicCommands { uri = url.toURI(); } else { File saveDir = worldEdit.getWorkingDirectoryFile(config.saveDir); - File dir = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(saveDir, player.getUniqueId().toString()) : saveDir; + File dir = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(saveDir, actor.getUniqueId().toString()) : saveDir; File file; if (filename.startsWith("#")) { String[] extensions; @@ -234,14 +234,14 @@ public class SchematicCommands { } else { extensions = ClipboardFormats.getFileExtensionArray(); } - file = player.openFileOpenDialog(extensions); + file = actor.openFileOpenDialog(extensions); if (file == null || !file.exists()) { - player.printError("Schematic " + filename + " does not exist! (" + file + ")"); + actor.printError("Schematic " + filename + " does not exist! (" + file + ")"); return; } } else { - if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && !player.hasPermission("worldedit.schematic.load.other") && Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}").matcher(filename).find()) { - BBC.NO_PERM.send(player, "worldedit.schematic.load.other"); + if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && !actor.hasPermission("worldedit.schematic.load.other") && Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}").matcher(filename).find()) { + BBC.NO_PERM.send(actor, "worldedit.schematic.load.other"); return; } if (format == null && filename.matches(".*\\.[\\w].*")) { @@ -257,25 +257,25 @@ public class SchematicCommands { } } if (file == null || !file.exists() || !MainUtil.isInSubDirectory(saveDir, file)) { - player.printError("Schematic " + filename + " does not exist! (" + (file != null && file.exists()) + "|" + file + "|" + (file != null && !MainUtil.isInSubDirectory(saveDir, file)) + ")"); + actor.printError("Schematic " + filename + " does not exist! (" + (file != null && file.exists()) + "|" + file + "|" + (file != null && !MainUtil.isInSubDirectory(saveDir, file)) + ")"); return; } if (format == null) { format = ClipboardFormats.findByFile(file); if (format == null) { - BBC.CLIPBOARD_INVALID_FORMAT.send(player, file.getName()); + BBC.CLIPBOARD_INVALID_FORMAT.send(actor, file.getName()); return; } } in = new FileInputStream(file); uri = file.toURI(); } - format.hold(player, uri, in); - BBC.SCHEMATIC_LOADED.send(player, filename); + format.hold(actor, uri, in); + BBC.SCHEMATIC_LOADED.send(actor, filename); } catch (IllegalArgumentException e) { - player.printError("Unknown filename: " + filename); + actor.printError("Unknown filename: " + filename); } catch (URISyntaxException | IOException e) { - player.printError("File could not be read or it does not exist: " + e.getMessage()); + actor.printError("File could not be read or it does not exist: " + e.getMessage()); log.warn("Failed to load a saved clipboard", e); } finally { if (in != null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormat.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormat.java index fb1ca8334..9ce0c6740 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormat.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormat.java @@ -19,21 +19,20 @@ package com.sk89q.worldedit.extent.clipboard.io; +import static com.google.common.base.Preconditions.checkNotNull; + import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.clipboard.URIClipboardHolder; import com.boydti.fawe.object.io.PGZIPOutputStream; import com.boydti.fawe.object.schematic.Schematic; import com.boydti.fawe.util.MainUtil; - -import static com.google.common.base.Preconditions.checkNotNull; import com.google.gson.Gson; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.math.BlockVector3; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -111,8 +110,8 @@ public interface ClipboardFormat { * @param in * @throws IOException */ - default URIClipboardHolder hold(Player player, URI uri, InputStream in) throws IOException { - checkNotNull(player); + default URIClipboardHolder hold(Actor actor, URI uri, InputStream in) throws IOException { + checkNotNull(actor); checkNotNull(uri); checkNotNull(in); @@ -120,9 +119,9 @@ public interface ClipboardFormat { final Clipboard clipboard; - LocalSession session = WorldEdit.getInstance().getSessionManager().get(player); + LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor); session.setClipboard(null); - clipboard = reader.read(player.getUniqueId()); + clipboard = reader.read(actor.getUniqueId()); URIClipboardHolder holder = new URIClipboardHolder(uri, clipboard); session.setClipboard(holder); return holder; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java index c1bbc58f2..79d51cefb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java @@ -47,7 +47,7 @@ public class RhinoCraftScriptEngine implements CraftScriptEngine { @Override public Object evaluate(String script, String filename, Map args) - throws Throwable { + throws ScriptException, Throwable { RhinoContextFactory factory = new RhinoContextFactory(timeLimit); Context cx = factory.enterContext(); ScriptableObject scriptable = new ImporterTopLevel(cx); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/java/RhinoScriptEngine.java b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/java/RhinoScriptEngine.java index d621676af..bf64e4e12 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/java/RhinoScriptEngine.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/java/RhinoScriptEngine.java @@ -120,13 +120,15 @@ public class RhinoScriptEngine extends AbstractScriptEngine { public ScriptEngineFactory getFactory() { if (factory != null) { return factory; + } else { + return new RhinoScriptEngineFactory(); } - return new RhinoScriptEngineFactory(); } private Scriptable setupScope(Context cx, ScriptContext context) { ScriptableObject scriptable = new ImporterTopLevel(cx); + Scriptable scope = cx.initStandardObjects(scriptable); //ScriptableObject.putProperty(scope, "argv", Context.javaToJS(args, scope)); - return cx.initStandardObjects(scriptable); + return scope; } }