From 65420af09e5f71b1b1e8d42bdb0940b58f711559 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Sun, 22 Jul 2018 15:36:50 +1000 Subject: [PATCH] Fixed //fill and //rotate --- .../sk89q/worldedit/bukkit/BukkitAdapter.java | 45 ++++++++++++++++++- .../java/com/sk89q/worldedit/BlockVector.java | 6 +-- .../com/sk89q/worldedit/BlockVector2D.java | 6 +-- .../worldedit/command/ClipboardCommands.java | 14 +++--- .../worldedit/command/UtilityCommands.java | 7 +-- .../transform/BlockTransformExtent.java | 9 ++-- .../sk89q/worldedit/session/PasteBuilder.java | 7 +-- 7 files changed, 65 insertions(+), 29 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java index edfbb9c7e..4f41c7e94 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java @@ -19,6 +19,8 @@ package com.sk89q.worldedit.bukkit; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.base.Function; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; @@ -32,6 +34,8 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; +import com.sk89q.worldedit.world.gamemode.GameMode; +import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; import org.bukkit.Bukkit; @@ -39,8 +43,6 @@ import org.bukkit.Material; import org.bukkit.block.data.BlockData; import org.bukkit.inventory.ItemStack; -import static com.google.common.base.Preconditions.checkNotNull; - import java.util.HashMap; import java.util.Map; import java.util.Objects; @@ -238,6 +240,45 @@ public class BukkitAdapter { return Material.getMaterial(blockType.getId().replace("minecraft:", "").toUpperCase()); } + /** + * Create a WorldEdit GameMode from a Bukkit one. + * + * @param gameMode Bukkit GameMode + * @return WorldEdit GameMode + */ + public static GameMode adapt(org.bukkit.GameMode gameMode) { + checkNotNull(gameMode); + return GameModes.get(gameMode.name().toLowerCase()); + } + + /** + * Converts a Material to a BlockType + * + * @param material The material + * @return The blocktype + */ + public static BlockType asBlockType(Material material) { + checkNotNull(material); + if (!material.isBlock()) { + throw new IllegalArgumentException(material.getKey().toString() + " is not a block!"); + } + return BlockTypes.get(material.getKey().toString()); + } + + /** + * Converts a Material to a ItemType + * + * @param material The material + * @return The itemtype + */ + public static ItemType asItemType(Material material) { + checkNotNull(material); + if (!material.isItem()) { + throw new IllegalArgumentException(material.getKey().toString() + " is not an item!"); + } + return ItemTypes.get(material.getKey().toString()); + } + private static Map blockStateCache = new HashMap<>(); /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector.java index c444d80d1..633bab3eb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector.java @@ -37,7 +37,7 @@ public class BlockVector extends Vector { * @param position the other position */ public BlockVector(Vector position) { - super(position); + this(position.getBlockX(), position.getBlockY(), position.getBlockZ()); } /** @@ -59,7 +59,7 @@ public class BlockVector extends Vector { * @param z the Z coordinate */ public BlockVector(float x, float y, float z) { - super(x, y, z); + this((int) x, (int) y, (int) z); } /** @@ -70,7 +70,7 @@ public class BlockVector extends Vector { * @param z the Z coordinate */ public BlockVector(double x, double y, double z) { - super(x, y, z); + this((int) x, (int) y, (int) z); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector2D.java index 07d54430b..cdf0cb36a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector2D.java @@ -36,7 +36,7 @@ public class BlockVector2D extends Vector2D { * @param position the position to copy */ public BlockVector2D(Vector2D position) { - super(position); + this(position.getBlockX(), position.getBlockZ()); } /** @@ -56,7 +56,7 @@ public class BlockVector2D extends Vector2D { * @param z the Z coordinate */ public BlockVector2D(float x, float z) { - super(x, z); + this((int) x, (int) z); } /** @@ -66,7 +66,7 @@ public class BlockVector2D extends Vector2D { * @param z the Z coordinate */ public BlockVector2D(double x, double z) { - super(x, z); + this((int) x, (int) z); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java index 3feca48b5..284550e93 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java @@ -19,10 +19,18 @@ package com.sk89q.worldedit.command; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT; +import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; + import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.Logging; -import com.sk89q.worldedit.*; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; @@ -43,10 +51,6 @@ import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.util.command.binding.Switch; import com.sk89q.worldedit.util.command.parametric.Optional; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; - /** * Clipboard commands. */ diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java index 8230d1e87..3fa96d9d8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java @@ -104,12 +104,7 @@ public class UtilityCommands { int depth = args.argsLength() > 2 ? Math.max(1, args.getInteger(2)) : 1; Vector pos = session.getPlacementPosition(player); - int affected; - if (pattern instanceof BlockPattern) { - affected = editSession.fillXZ(pos, ((BlockPattern) pattern).getBlock(), radius, depth, false); - } else { - affected = editSession.fillXZ(pos, pattern, radius, depth, false); - } + int affected = editSession.fillXZ(pos, pattern, radius, depth, false); player.print(affected + " block(s) have been created."); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java index 4ff6771c4..06f36079f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java @@ -74,8 +74,7 @@ public class BlockTransformExtent extends AbstractDelegateExtent { * @return the same block */ private T transformBlock(T block, boolean reverse) { - transform(block, reverse ? transform.inverse() : transform); - return block; + return transform(block, reverse ? transform.inverse() : transform); } @Override @@ -126,11 +125,11 @@ public class BlockTransformExtent extends AbstractDelegateExtent { for (Property property : block.getBlockType().getProperties()) { if (property instanceof DirectionalProperty) { - Vector value = (Vector) block.getState(property); + Direction value = (Direction) block.getState(property); if (value != null) { - Vector newValue = getNewStateValue((DirectionalProperty) property, transform, value); + Vector newValue = getNewStateValue((DirectionalProperty) property, transform, value.toVector()); if (newValue != null) { - changedBlock.with(property, newValue); + changedBlock = (T) changedBlock.with(property, Direction.findClosest(newValue, Direction.Flag.ALL)); } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/PasteBuilder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/PasteBuilder.java index 3fcce7100..e4a9ade5a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/session/PasteBuilder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/PasteBuilder.java @@ -19,9 +19,9 @@ package com.sk89q.worldedit.session; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.transform.BlockTransformExtent; @@ -29,9 +29,6 @@ import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.math.transform.Transform; -import com.sk89q.worldedit.world.registry.Registries; - -import static com.google.common.base.Preconditions.checkNotNull; /** * Builds an operation to paste the contents of a clipboard.