From a69b2398482756376b6af1d34daa1b7a601e7f48 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Tue, 25 Jun 2019 13:07:47 -0400 Subject: [PATCH] Upstream --- .../worldedit/bukkit/BukkitItemRegistry.java | 12 - .../sk89q/worldedit/bukkit/BukkitPlayer.java | 12 +- .../boydti/fawe/jnbt/SchematicStreamer.java | 9 +- .../fawe/jnbt/anvil/WritableMCAChunk.java | 24 +- .../object/clipboard/LazyClipboardHolder.java | 3 +- .../collection/LocalBlockVectorSet.java | 37 +- .../regions/selector/FuzzyRegionSelector.java | 5 - .../selector/PolyhedralRegionSelector.java | 5 - .../main/java/com/sk89q/jnbt/CompoundTag.java | 9 - .../com/sk89q/jnbt/CompoundTagBuilder.java | 4 +- .../src/main/java/com/sk89q/jnbt/ListTag.java | 4 +- .../java/com/sk89q/jnbt/NBTInputStream.java | 46 +- .../java/com/sk89q/jnbt/NBTOutputStream.java | 64 +- .../src/main/java/com/sk89q/jnbt/Tag.java | 7 +- .../util/commands/SuggestedRange.java | 21 - .../java/com/sk89q/util/ReflectionUtil.java | 5 +- .../com/sk89q/worldedit/CuboidClipboard.java | 477 --------------- .../com/sk89q/worldedit/blocks/Blocks.java | 3 - .../worldedit/command/BiomeCommands.java | 58 +- .../command/composition/SelectionCommand.java | 2 - .../composition/ShapedBrushCommand.java | 2 - .../worldedit/command/tool/AreaPickaxe.java | 39 +- .../command/tool/BlockDataCyler.java | 68 +-- .../worldedit/command/tool/BlockReplacer.java | 13 +- .../worldedit/command/tool/BrushTool.java | 58 +- .../worldedit/command/tool/DistanceWand.java | 4 +- .../command/tool/FloatingTreeRemover.java | 8 +- .../worldedit/command/tool/FloodFillTool.java | 9 +- .../command/tool/LongRangeBuildTool.java | 10 +- .../worldedit/command/tool/QueryTool.java | 4 +- .../command/tool/RecursivePickaxe.java | 22 +- .../command/tool/brush/GravityBrush.java | 35 +- .../tool/brush/HollowCylinderBrush.java | 2 +- .../command/tool/brush/HollowSphereBrush.java | 2 +- .../command/tool/brush/SmoothBrush.java | 2 +- .../command/tool/brush/SphereBrush.java | 2 +- .../factory/parser/DefaultBlockParser.java | 9 +- .../extent/AbstractDelegateExtent.java | 5 +- .../worldedit/extent/ChangeSetExtent.java | 6 +- .../com/sk89q/worldedit/extent/Extent.java | 50 +- .../sk89q/worldedit/extent/MaskingExtent.java | 7 +- .../extent/clipboard/BlockArrayClipboard.java | 2 +- .../worldedit/extent/clipboard/Clipboard.java | 12 - .../extent/clipboard/io/ClipboardFormat.java | 48 +- .../extent/clipboard/io/ClipboardFormats.java | 1 - .../extent/clipboard/io/ClipboardReader.java | 2 +- .../clipboard/io/MCEditSchematicReader.java | 1 - .../extent/clipboard/io/SchematicReader.java | 41 +- .../clipboard/io/SpongeSchematicReader.java | 5 +- .../clipboard/io/SpongeSchematicWriter.java | 85 +-- .../extent/clipboard/io/WavefrontReader.java | 557 ------------------ .../legacycompat/NBTCompatibilityHandler.java | 1 - .../SignCompatibilityHandler.java | 10 +- .../extent/inventory/BlockBagExtent.java | 65 +- .../extent/logging/AbstractLoggingExtent.java | 58 -- .../extent/reorder/MultiStageReorder.java | 2 +- .../transform/BlockTransformExtent.java | 111 ++-- .../worldedit/function/mask/BlockMask.java | 2 - .../function/mask/BlockTypeMask.java | 32 +- .../sk89q/worldedit/function/mask/Mask.java | 3 - .../function/mask/MaskIntersection.java | 5 +- .../sk89q/worldedit/function/mask/Masks.java | 1 + .../function/mask/SingleBlockStateMask.java | 1 - .../function/mask/SingleBlockTypeMask.java | 1 - .../operation/BackwardsExtentBlockCopy.java | 8 +- .../function/operation/ForwardExtentCopy.java | 2 +- .../function/pattern/FawePattern.java | 6 +- .../function/visitor/DownwardVisitor.java | 3 +- .../history/change/EntityCreate.java | 4 +- .../history/change/EntityRemove.java | 4 +- .../history/changeset/ArrayListHistory.java | 2 +- .../history/changeset/ChangeSet.java | 2 +- .../command/CommandLoggingHandler.java | 10 +- .../internal/command/WorldEditBinding.java | 25 +- .../internal/expression/Expression.java | 23 +- .../internal/expression/runtime/For.java | 72 ++- .../internal/expression/runtime/Function.java | 5 +- .../expression/runtime/Functions.java | 50 +- .../internal/registry/InputParser.java | 1 - .../com/sk89q/worldedit/math/MathUtils.java | 32 +- .../worldedit/math/MutableBlockVector2.java | 7 +- .../worldedit/math/MutableBlockVector3.java | 7 +- .../sk89q/worldedit/math/MutableVector3.java | 2 - .../worldedit/math/convolution/HeightMap.java | 7 +- .../KochanekBartelsInterpolation.java | 66 +-- .../worldedit/math/interpolation/Node.java | 2 +- .../math/transform/AffineTransform.java | 35 +- .../math/transform/RoundedTransform.java | 5 - .../worldedit/math/transform/Transforms.java | 2 +- .../worldedit/regions/CylinderRegion.java | 3 +- .../sk89q/worldedit/regions/NullRegion.java | 6 +- .../worldedit/regions/RegionSelector.java | 29 +- .../ConvexPolyhedralRegionSelector.java | 18 +- .../selector/CuboidRegionSelector.java | 24 +- .../selector/CylinderRegionSelector.java | 8 +- .../selector/EllipsoidRegionSelector.java | 9 +- .../ExtendingCuboidRegionSelector.java | 1 - .../selector/Polygonal2DRegionSelector.java | 10 +- .../regions/shape/ArbitraryBiomeShape.java | 28 +- .../shape/WorldEditExpressionEnvironment.java | 3 +- .../sk89q/worldedit/registry/Registry.java | 1 + .../worldedit/session/ClipboardHolder.java | 1 + .../session/DelegateClipboardHolder.java | 39 -- .../sk89q/worldedit/session/PasteBuilder.java | 14 +- .../com/sk89q/worldedit/util/Direction.java | 12 +- .../com/sk89q/worldedit/util/TargetBlock.java | 11 +- .../util/command/SimpleCommandMapping.java | 2 - .../util/command/SimpleDispatcher.java | 9 +- .../util/command/fluent/DispatcherNode.java | 21 +- .../parametric/AParametricCallable.java | 3 +- .../command/parametric/ArgumentStack.java | 6 +- .../command/parametric/BindingHelper.java | 55 +- .../util/command/parametric/BindingMatch.java | 18 +- .../parametric/ContextArgumentStack.java | 4 - .../command/parametric/FaweParanamer.java | 4 +- .../FunctionParametricCallable.java | 94 +-- .../command/parametric/ParameterData.java | 20 +- .../command/parametric/ParametricBuilder.java | 74 +-- .../parametric/ParametricCallable.java | 38 +- .../parametric/StringArgumentStack.java | 2 +- .../worldedit/util/formatting/Fragment.java | 8 +- .../formatting/component/CommandListBox.java | 3 +- .../formatting/component/CommandUsageBox.java | 24 +- .../util/formatting/component/MessageBox.java | 9 +- .../sk89q/worldedit/world/AbstractWorld.java | 2 +- .../com/sk89q/worldedit/world/NullWorld.java | 4 +- .../worldedit/world/biome/BiomeTypes.java | 4 - .../worldedit/world/block/BaseBlock.java | 120 ++-- .../worldedit/world/block/BlockTypeEnum.java | 5 - .../world/block/FuzzyBlockState.java | 6 +- .../worldedit/world/chunk/AnvilChunk.java | 25 +- .../worldedit/world/chunk/AnvilChunk13.java | 6 +- .../sk89q/worldedit/world/chunk/Chunk.java | 1 - .../sk89q/worldedit/world/chunk/OldChunk.java | 3 +- .../worldedit/world/item/ItemCategory.java | 2 - .../sk89q/worldedit/world/item/ItemType.java | 10 +- .../sk89q/worldedit/world/item/ItemTypes.java | 14 +- .../world/registry/BundledBlockData.java | 17 +- .../world/registry/BundledItemRegistry.java | 7 - .../world/registry/ItemRegistry.java | 9 - .../world/registry/LegacyMapper.java | 7 +- .../worldedit/world/storage/ChunkStore.java | 1 - .../worldedit/world/weather/WeatherTypes.java | 1 - 143 files changed, 1042 insertions(+), 2405 deletions(-) delete mode 100644 worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/SuggestedRange.java delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/WavefrontReader.java delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/extent/logging/AbstractLoggingExtent.java delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/session/DelegateClipboardHolder.java delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypeEnum.java diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitItemRegistry.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitItemRegistry.java index 9d7d68d08..d2d2cb1d7 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitItemRegistry.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitItemRegistry.java @@ -1,18 +1,6 @@ package com.sk89q.worldedit.bukkit; import com.sk89q.worldedit.world.registry.BundledItemRegistry; -import org.bukkit.Material; - -import java.util.ArrayList; -import java.util.Collection; public class BukkitItemRegistry extends BundledItemRegistry { - @Override - public Collection registerItems() { - ArrayList items = new ArrayList<>(); - for (Material m : Material.values()) { - if (!m.isLegacy() && m.isItem()) items.add(m.getKey().getNamespace() + ":" + m.getKey().getKey()); - } - return items; - } } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index e9cbeb07f..9b25740c6 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.bukkit; import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.util.TaskManager; + import com.sk89q.util.StringUtil; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; @@ -41,7 +42,6 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameModes; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -51,12 +51,11 @@ import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import javax.annotation.Nullable; import java.util.HashMap; import java.util.Map; import java.util.UUID; -import javax.annotation.Nullable; - public class BukkitPlayer extends AbstractPlayerActor { private Player player; @@ -168,13 +167,10 @@ public class BukkitPlayer extends AbstractPlayerActor { Extent extent = loc.getExtent(); if (extent instanceof World) { org.bukkit.World world = Bukkit.getWorld(((World) extent).getName()); - // System.out.println("Teleport to world " + world); - player.teleport(new Location(world, pos.getX(), pos.getY(), - pos.getZ(), yaw, pitch)); + player.teleport(new Location(world, pos.getX(), pos.getY(), pos.getZ(), yaw, pitch)); } } - player.teleport(new Location(player.getWorld(), pos.getX(), pos.getY(), - pos.getZ(), yaw, pitch)); + player.teleport(new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ(), yaw, pitch)); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java index 5845de303..dc31b5989 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java @@ -10,6 +10,7 @@ import com.boydti.fawe.object.clipboard.FaweClipboard; import com.boydti.fawe.object.clipboard.MemoryOptimizedClipboard; import com.boydti.fawe.object.io.FastByteArrayOutputStream; import com.boydti.fawe.object.io.FastByteArraysInputStream; + import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.NBTInputStream; @@ -18,15 +19,17 @@ import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.registry.state.PropertyKey; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.world.biome.BiomeTypes; -import com.sk89q.worldedit.world.block.*; +import com.sk89q.worldedit.world.block.BlockID; +import com.sk89q.worldedit.world.block.BlockStateHolder; +import com.sk89q.worldedit.world.block.BlockType; +import com.sk89q.worldedit.world.block.BlockTypeSwitch; +import com.sk89q.worldedit.world.block.BlockTypeSwitchBuilder; import com.sk89q.worldedit.world.entity.EntityType; import com.sk89q.worldedit.world.entity.EntityTypes; -import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.LegacyMapper; import net.jpountz.lz4.LZ4BlockInputStream; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/WritableMCAChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/WritableMCAChunk.java index 60dbdd7b3..9a5cbe717 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/WritableMCAChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/WritableMCAChunk.java @@ -4,6 +4,7 @@ import com.boydti.fawe.FaweCache; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.io.FastByteArrayOutputStream; import com.boydti.fawe.util.MathMan; + import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.NBTConstants; @@ -91,7 +92,6 @@ public class WritableMCAChunk extends FaweChunk { nbtOut.writeNamedTagName("", NBTConstants.TYPE_COMPOUND); nbtOut.writeNamedTag("DataVersion", 1631); nbtOut.writeLazyCompoundTag("Level", out -> { -// out.writeNamedTag("V", (byte) 1); out.writeNamedTag("Status", "decorated"); out.writeNamedTag("xPos", getX()); out.writeNamedTag("zPos", getZ()); @@ -104,21 +104,25 @@ public class WritableMCAChunk extends FaweChunk { out.writeNamedEmptyList("TileEntities"); } else { out.writeNamedTag("TileEntities", new ListTag(CompoundTag.class, - new ArrayList<>(tiles.values()))); + new ArrayList<>(tiles.values()))); } out.writeNamedTag("InhabitedTime", inhabitedTime); out.writeNamedTag("LastUpdate", lastUpdate); out.writeNamedTag("Biomes", biomes); int len = 0; for (boolean hasSection : hasSections) { - if (hasSection) len++; + if (hasSection) { + len++; + } } out.writeNamedTagName("Sections", NBTConstants.TYPE_LIST); nbtOut.writeByte(NBTConstants.TYPE_COMPOUND); nbtOut.writeInt(len); for (int layer = 0; layer < hasSections.length; layer++) { - if (!hasSections[layer]) continue; + if (!hasSections[layer]) { + continue; + } out.writeNamedTag("Y", (byte) layer); int blockIndexStart = layer << 12; @@ -186,7 +190,9 @@ public class WritableMCAChunk extends FaweChunk { out.writeNamedTagName("BlockStates", NBTConstants.TYPE_LONG_ARRAY); out.writeInt(blockBitArrayEnd); - for (int i = 0; i < blockBitArrayEnd; i++) out.writeLong(blockstates[i]); + for (int i = 0; i < blockBitArrayEnd; i++) { + out.writeLong(blockstates[i]); + } out.writeNamedTagName("BlockLight", NBTConstants.TYPE_BYTE_ARRAY); @@ -337,12 +343,16 @@ public class WritableMCAChunk extends FaweChunk { } public int getSkyLight(int x, int y, int z) { - if (!hasSections[y >> 4]) return 0; + if (!hasSections[y >> 4]) { + return 0; + } return getNibble(getIndex(x, y, z), skyLight); } public int getBlockLight(int x, int y, int z) { - if (!hasSections[y >> 4]) return 0; + if (!hasSections[y >> 4]) { + return 0; + } return getNibble(getIndex(x, y, z), blockLight); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/LazyClipboardHolder.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/LazyClipboardHolder.java index 79701662c..9542f5fc3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/LazyClipboardHolder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/LazyClipboardHolder.java @@ -1,12 +1,11 @@ package com.boydti.fawe.object.clipboard; -import com.boydti.fawe.object.schematic.StructureFormat; import com.google.common.io.ByteSource; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; -import com.sk89q.worldedit.extent.clipboard.io.SchematicReader; + import java.io.InputStream; import java.net.URI; import java.util.UUID; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVectorSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVectorSet.java index 863de2781..15abd874c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVectorSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVectorSet.java @@ -3,6 +3,7 @@ package com.boydti.fawe.object.collection; import com.boydti.fawe.util.MathMan; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; +import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.Iterator; @@ -115,14 +116,13 @@ public class LocalBlockVectorSet implements Set { int b3 = ((byte) (index >> 15)) & 0xFF; int b4 = ((byte) (index >> 23)) & 0xFF; int x = offsetX + (((b3 + ((MathMan.unpair8x(b2)) << 8)) << 21) >> 21); - int y = b1; int z = offsetZ + (((b4 + ((MathMan.unpair8y(b2)) << 8)) << 21) >> 21); - return MutableBlockVector3.get(x, y, z); + return MutableBlockVector3.get(x, b1, z); } return null; } - @Override + @NotNull @Override public Iterator iterator() { return new Iterator() { int index = set.nextSetBit(0); @@ -158,12 +158,12 @@ public class LocalBlockVectorSet implements Set { }; } - @Override + @NotNull @Override public Object[] toArray() { return toArray(null); } - @Override + @NotNull @Override public T[] toArray(T[] array) { int size = size(); if (array == null || array.length < size) { @@ -177,9 +177,8 @@ public class LocalBlockVectorSet implements Set { int b3 = ((byte) (index >> 15)) & 0xFF; int b4 = ((byte) (index >> 23)) & 0xFF; int x = offsetX + (((b3 + ((MathMan.unpair8x(b2)) << 8)) << 21) >> 21); - int y = b1; int z = offsetZ + (((b4 + ((MathMan.unpair8y(b2)) << 8)) << 21) >> 21); - array[i] = (T) BlockVector3.at(x, y, z); + array[i] = (T) BlockVector3.at(x, b1, z); index++; } return array; @@ -258,25 +257,16 @@ public class LocalBlockVectorSet implements Set { @Override public boolean containsAll(Collection c) { - for (Object o : c) { - if (!contains(o)) { - return false; - } - } - return true; + return c.stream().allMatch(this::contains); } @Override public boolean addAll(Collection c) { - boolean result = false; - for (BlockVector3 v : c) { - result |= add(v); - } - return result; + return c.stream().map(this::add).reduce(false, (a, b) -> a || b); } @Override - public boolean retainAll(Collection c) { + public boolean retainAll(@NotNull Collection c) { boolean result = false; int size = size(); int index = -1; @@ -300,11 +290,7 @@ public class LocalBlockVectorSet implements Set { @Override public boolean removeAll(Collection c) { - boolean result = false; - for (Object o : c) { - result |= remove(o); - } - return result; + return c.stream().map(this::remove).reduce(false, (a, b) -> a || b); } public void forEach(BlockVectorSetVisitor visitor) { @@ -318,9 +304,8 @@ public class LocalBlockVectorSet implements Set { int b3 = ((byte) (index >> 15)) & 0xFF; int b4 = ((byte) (index >> 23)) & 0xFF; int x = offsetX + (((b3 + ((MathMan.unpair8x(b2)) << 8)) << 21) >> 21); - int y = b1; int z = offsetZ + (((b4 + ((MathMan.unpair8y(b2)) << 8)) << 21) >> 21); - visitor.run(x, y, z, index); + visitor.run(x, b1, z, index); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/FuzzyRegionSelector.java b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/FuzzyRegionSelector.java index ff398e776..054ea31e5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/FuzzyRegionSelector.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/FuzzyRegionSelector.java @@ -41,11 +41,6 @@ public class FuzzyRegionSelector extends AbstractDelegateExtent implements Regio new MaskTraverser(mask).reset(getExtent()); } - @Override - public List getVerticies() { - return positions; - } - @Nullable @Override public World getWorld() { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/PolyhedralRegionSelector.java b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/PolyhedralRegionSelector.java index b8815126a..29094ed38 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/PolyhedralRegionSelector.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/PolyhedralRegionSelector.java @@ -63,11 +63,6 @@ public class PolyhedralRegionSelector implements RegionSelector, CUIRegion { region = new PolyhedralRegion(world); } - @Override - public List getVerticies() { - return new ArrayList<>(region.getVertices()); - } - @Nullable @Override public World getWorld() { diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java index a6b90ecb1..04649bd5f 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java @@ -41,15 +41,6 @@ public class CompoundTag extends Tag { this.value = value; } - @Override - public Map getRaw() { - HashMap raw = new HashMap<>(); - for (Map.Entry entry : value.entrySet()) { - raw.put(entry.getKey(), entry.getValue().getRaw()); - } - return raw; - } - /** * Returns whether this compound tag contains the given key. * diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTagBuilder.java b/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTagBuilder.java index 2e701ddf3..b0e873c0d 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTagBuilder.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTagBuilder.java @@ -34,7 +34,7 @@ public class CompoundTagBuilder { /** * Create a new instance. */ - public CompoundTagBuilder() { + CompoundTagBuilder() { this.entries = new HashMap<>(); } @@ -43,7 +43,7 @@ public class CompoundTagBuilder { * * @param value the value */ - public CompoundTagBuilder(Map value) { + CompoundTagBuilder(Map value) { checkNotNull(value); this.entries = value; } diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/ListTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/ListTag.java index 13b7f1235..e29da1c0a 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/ListTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/ListTag.java @@ -73,7 +73,7 @@ public final class ListTag extends Tag { /** * Get the tag if it exists at the given index. - * + * * @param index the index * @return the tag or null */ @@ -82,7 +82,7 @@ public final class ListTag extends Tag { if (index >= value.size()) { return null; } - return value.get(index); + return value.get(index); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTInputStream.java b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTInputStream.java index 03c708844..f7541d72d 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTInputStream.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTInputStream.java @@ -20,16 +20,12 @@ package com.sk89q.jnbt; import com.boydti.fawe.jnbt.NBTStreamer; -import com.boydti.fawe.object.RunnableVal2; -import com.boydti.fawe.util.StringMan; import java.io.Closeable; -import java.io.DataInput; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -40,7 +36,7 @@ import java.util.function.Function; * This class reads NBT, or Named Binary Tag * streams, and produces an object graph of subclasses of the {@code Tag} * object. - * + * *

The NBT format was created by Markus Persson, and the specification may be * found at * http://www.minecraft.net/docs/NBT.txt.

@@ -52,7 +48,7 @@ public final class NBTInputStream implements Closeable { /** * Creates a new {@code NBTInputStream}, which will source its data * from the specified input stream. - * + * * @param is the input stream * @throws IOException if an I/O error occurs */ @@ -64,13 +60,9 @@ public final class NBTInputStream implements Closeable { this.is = dis; } - public DataInputStream getInputStream() { - return is; - } - /** * Reads an NBT tag from the stream. - * + * * @return The tag that was read. * @throws IOException if an I/O error occurs. */ @@ -78,19 +70,9 @@ public final class NBTInputStream implements Closeable { return readNamedTag(0); } - /** - * Reads an NBT map from the stream. - * - * @return The map that was read. - * @throws IOException if an I/O error occurs. - */ - public NamedData readNamedData() throws IOException { - return readNamedData(0); - } - /** * Reads an NBT from the stream. - * + * * @param depth the depth of this tag * @return The tag that was read. * @throws IOException if an I/O error occurs. @@ -100,21 +82,11 @@ public final class NBTInputStream implements Closeable { return new NamedTag(readNamedTagName(type), readTagPayload(type, depth)); } - private NamedData readNamedData(int depth) throws IOException { - int type = is.readByte(); - return new NamedData(readNamedTagName(type), readDataPayload(type, depth)); - } - public Tag readTag() throws IOException { int type = is.readByte(); return readTagPayload(type, 0); } - public Object readData() throws IOException { - int type = is.readByte(); - return readDataPayload(type, 0); - } - public void readNamedTagLazy(Function getReader) throws IOException { int type = is.readByte(); String name = readNamedTagName(type); @@ -522,13 +494,13 @@ public final class NBTInputStream implements Closeable { /** * Reads the payload of a tag given the type. - * + * * @param type the type * @param depth the depth * @return the tag * @throws IOException if an I/O error occurs. */ - public Tag readTagPayload(int type, int depth) throws IOException { + private Tag readTagPayload(int type, int depth) throws IOException { switch (type) { case NBTConstants.TYPE_END: if (depth == 0) { @@ -598,11 +570,11 @@ public final class NBTInputStream implements Closeable { } case NBTConstants.TYPE_LONG_ARRAY: { length = is.readInt(); - long[] data = new long[length]; + long[] longData = new long[length]; for (int i = 0; i < length; i++) { - data[i] = is.readLong(); + longData[i] = is.readLong(); } - return new LongArrayTag(data); + return new LongArrayTag(longData); } default: throw new IOException("Invalid tag type: " + type + "."); diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java index 7ad1a8142..0a2b3353e 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java @@ -21,7 +21,6 @@ package com.sk89q.jnbt; import static com.google.common.base.Preconditions.checkNotNull; -import com.boydti.fawe.object.io.LittleEndianOutputStream; import java.io.Closeable; import java.io.DataOutput; import java.io.DataOutputStream; @@ -34,7 +33,7 @@ import java.util.Map; /** * This class writes NBT, or Named Binary Tag * {@code Tag} objects to an underlying {@code OutputStream}. - * + * *

The NBT format was created by Markus Persson, and the specification may be * found at * http://www.minecraft.net/docs/NBT.txt.

@@ -49,7 +48,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da /** * Creates a new {@code NBTOutputStream}, which will write data to the * specified underlying output stream. - * + * * @param os * The output stream. * @throws IOException @@ -67,15 +66,9 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da return os; } - public void setLittleEndian() { - if (!(os instanceof LittleEndianOutputStream)) { - this.os = new LittleEndianOutputStream((OutputStream) os); - } - } - /** * Writes a tag. - * + * * @param tag * The tag to write. * @throws IOException @@ -86,10 +79,16 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da checkNotNull(tag); int type = NBTUtils.getTypeCode(tag.getClass()); - writeNamedTagName(name, type); + byte[] nameBytes = name.getBytes(NBTConstants.CHARSET); + + os.writeByte(type); + os.writeShort(nameBytes.length); + os.write(nameBytes); + if (type == NBTConstants.TYPE_END) { throw new IOException("Named TAG_End not permitted."); } + writeTagPayload(tag); } @@ -149,16 +148,6 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da } } - public void writeNamedTag(String name, long[] data) throws IOException { - checkNotNull(name); - int type = NBTConstants.TYPE_LONG_ARRAY; - writeNamedTagName(name, type); - os.writeInt(data.length); - for (long aData : data) { - os.writeLong(aData); - } - } - public void writeNamedEmptyList(String name) throws IOException { writeNamedEmptyList(name, NBTConstants.TYPE_COMPOUND); } @@ -171,6 +160,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da public void writeNamedTagName(String name, int type) throws IOException { byte[] nameBytes = name.getBytes(NBTConstants.CHARSET); + os.writeByte(type); os.writeShort(nameBytes.length); os.write(nameBytes); @@ -201,7 +191,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da /** * Writes tag payload. - * + * * @param tag * The tag. * @throws IOException @@ -256,7 +246,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da /** * Writes a {@code TAG_Byte} tag. - * + * * @param tag * The tag. * @throws IOException @@ -268,7 +258,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da /** * Writes a {@code TAG_Byte_Array} tag. - * + * * @param tag * The tag. * @throws IOException @@ -282,7 +272,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da /** * Writes a {@code TAG_Compound} tag. - * + * * @param tag * The tag. * @throws IOException @@ -292,12 +282,12 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da for (Map.Entry entry : tag.getValue().entrySet()) { writeNamedTag(entry.getKey(), entry.getValue()); } - os.writeByte(NBTConstants.TYPE_END); // end tag - better way? + os.writeByte((byte) 0); // end tag - better way? } /** * Writes a {@code TAG_List} tag. - * + * * @param tag * The tag. * @throws IOException @@ -324,7 +314,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da /** * Writes a {@code TAG_String} tag. - * + * * @param tag * The tag. * @throws IOException @@ -338,7 +328,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da /** * Writes a {@code TAG_Double} tag. - * + * * @param tag * The tag. * @throws IOException @@ -350,7 +340,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da /** * Writes a {@code TAG_Float} tag. - * + * * @param tag * The tag. * @throws IOException @@ -362,7 +352,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da /** * Writes a {@code TAG_Long} tag. - * + * * @param tag * The tag. * @throws IOException @@ -374,7 +364,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da /** * Writes a {@code TAG_Int} tag. - * + * * @param tag * The tag. * @throws IOException @@ -386,7 +376,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da /** * Writes a {@code TAG_Short} tag. - * + * * @param tag * The tag. * @throws IOException @@ -398,19 +388,19 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da /** * Writes a {@code TAG_Empty} tag. - * + * * @param tag the tag */ private void writeEndTagPayload(EndTag tag) { /* empty */ } - + private void writeIntArrayTagPayload(IntArrayTag tag) throws IOException { int[] data = tag.getValue(); os.writeInt(data.length); for (int aData : data) { os.writeInt(aData); - } + } } private void writeLongArrayTagPayload(LongArrayTag tag) throws IOException { @@ -505,4 +495,4 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da public void flush() throws IOException { if (os instanceof Flushable) ((Flushable) os).flush(); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/Tag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/Tag.java index 6ff25faa7..47d501f09 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/Tag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/Tag.java @@ -26,12 +26,9 @@ public abstract class Tag { /** * Gets the value of this tag. - * + * * @return the value */ public abstract Object getValue(); - public Object getRaw() { - return getValue(); - } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/SuggestedRange.java b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/SuggestedRange.java deleted file mode 100644 index 98aa1f63e..000000000 --- a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/SuggestedRange.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.sk89q.minecraft.util.commands; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -@Retention(RetentionPolicy.RUNTIME) -public @interface SuggestedRange { - /** - * The minimum value that the number can be at, inclusive. - * - * @return the minimum value - */ - double min() default Double.MIN_VALUE; - - /** - * The maximum value that the number can be at, inclusive. - * - * @return the maximum value - */ - double max() default Double.MAX_VALUE; -} diff --git a/worldedit-core/src/main/java/com/sk89q/util/ReflectionUtil.java b/worldedit-core/src/main/java/com/sk89q/util/ReflectionUtil.java index 1cabccdb5..e9f0e3401 100644 --- a/worldedit-core/src/main/java/com/sk89q/util/ReflectionUtil.java +++ b/worldedit-core/src/main/java/com/sk89q/util/ReflectionUtil.java @@ -26,6 +26,7 @@ public final class ReflectionUtil { private ReflectionUtil() { } + @SuppressWarnings("unchecked") public static T getField(Object from, String name) { if (from instanceof Class) return getField((Class) from, null, name); @@ -34,12 +35,12 @@ public final class ReflectionUtil { } @SuppressWarnings("unchecked") - public static T getField(Class checkClass, Object obj, String name) { + public static T getField(Class checkClass, Object from, String name) { do { try { Field field = checkClass.getDeclaredField(name); field.setAccessible(true); - return (T) field.get(obj); + return (T) field.get(from); } catch (NoSuchFieldException | IllegalAccessException ignored) { } } while (checkClass.getSuperclass() != Object.class && ((checkClass = checkClass.getSuperclass()) != null)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java deleted file mode 100644 index e27c6be2a..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java +++ /dev/null @@ -1,477 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit; - -import com.boydti.fawe.object.schematic.Schematic; -import com.sk89q.worldedit.command.ClipboardCommands; -import com.sk89q.worldedit.command.FlattenedClipboardTransform; -import com.sk89q.worldedit.command.SchematicCommands; -import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat; -import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; -import com.sk89q.worldedit.function.operation.ForwardExtentCopy; -import com.sk89q.worldedit.function.operation.Operations; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.math.transform.AffineTransform; -import com.sk89q.worldedit.regions.CuboidRegion; -import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.util.Countable; -import com.sk89q.worldedit.util.Direction; -import com.sk89q.worldedit.world.DataException; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockStateHolder; -import com.sk89q.worldedit.world.block.BlockTypes; -import com.sk89q.worldedit.world.registry.LegacyMapper; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * The clipboard remembers the state of a cuboid region. - * - * @deprecated This is slowly being replaced with {@link Clipboard}, which is - * far more versatile. Transforms are supported using affine - * transformations and full entity support is provided because - * the clipboard properly implements {@link Extent}. However, - * the new clipboard class is only available in WorldEdit 6.x and - * beyond. We intend on keeping this deprecated class in WorldEdit - * for an extended amount of time so there is no rush to - * switch (but new features will not be supported). To copy between - * a clipboard and a world (or between any two {@code Extent}s), - * one can use {@link ForwardExtentCopy}. See - * {@link ClipboardCommands} and {@link SchematicCommands} for - * more information. - */ -@Deprecated -public class CuboidClipboard { - - /** - * An enum of possible flip directions. - */ - public enum FlipDirection { - NORTH_SOUTH(Direction.NORTH), - WEST_EAST(Direction.WEST), - UP_DOWN(Direction.UP), - ; - private final Direction direction; - FlipDirection(Direction direction) { - this.direction = direction; - } - } - - private BlockArrayClipboard clipboard; - private AffineTransform transform; - public BlockVector3 size; - - /** - * Constructs the clipboard. - * - * @param size the dimensions of the clipboard (should be at least 1 on every dimension) - */ - public CuboidClipboard(BlockVector3 size) { - checkNotNull(size); - this.size = size; - this.clipboard = this.init(BlockVector3.ZERO, BlockVector3.ZERO); - } - - public CuboidClipboard(BlockArrayClipboard clipboard) { - this.clipboard = clipboard; - this.size = clipboard.getDimensions(); - } - - /** - * Constructs the clipboard. - * - * @param size the dimensions of the clipboard (should be at least 1 on every dimension) - * @param origin the origin point where the copy was made, which must be the - * {@link CuboidRegion#getMinimumPoint()} relative to the copy - */ - public CuboidClipboard(BlockVector3 size, BlockVector3 origin) { - checkNotNull(size); - checkNotNull(origin); - this.size = size; - this.clipboard = init(BlockVector3.ZERO, origin); - } - - /** - * Constructs the clipboard. - * - * @param size the dimensions of the clipboard (should be at least 1 on every dimension) - * @param origin the origin point where the copy was made, which must be the - * {@link CuboidRegion#getMinimumPoint()} relative to the copy - * @param offset the offset from the minimum point of the copy where the user was - */ - public CuboidClipboard(BlockVector3 size, BlockVector3 origin, BlockVector3 offset) { - checkNotNull(size); - checkNotNull(origin); - checkNotNull(offset); - this.size = size; - this.clipboard = this.init(offset, origin); - } - - /* ------------------------------------------------------------------------------------------------------------- */ - - private BlockArrayClipboard init(BlockVector3 offset, BlockVector3 min) { - BlockVector3 origin = min.subtract(offset); - CuboidRegion region = new CuboidRegion(min, min.add(size).subtract(BlockVector3.ONE)); - BlockArrayClipboard clipboard = new BlockArrayClipboard(region); - clipboard.setOrigin(origin); - return clipboard; - } - - /* ------------------------------------------------------------------------------------------------------------- */ - - public BaseBlock getBlock(BlockVector3 position) { - return getBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ()); - } - - - public BaseBlock getBlock(int x, int y, int z) { -// return adapt(clipboard.IMP.getBlock(x, y, z)); - return clipboard.IMP.getBlock(x, y, z); - } - - public BaseBlock getLazyBlock(BlockVector3 position) { - return getBlock(position); - } - - public void setBlock(BlockVector3 location, BaseBlock block) { - setBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block); - } - - public boolean setBlock(int x, int y, int z, BaseBlock block) { - return setBlock(x, y, z, block); - } - - public boolean setBlock(int x, int y, int z, BlockState block) { - return clipboard.IMP.setBlock(x, y, z, block); - } - - /** - * Get the width (X-direction) of the clipboard. - * - * @return width - */ - public int getWidth() { - return size.getBlockX(); - } - - /** - * Get the length (Z-direction) of the clipboard. - * - * @return length - */ - public int getLength() { - return size.getBlockZ(); - } - - /** - * Get the height (Y-direction) of the clipboard. - * - * @return height - */ - public int getHeight() { - return size.getBlockY(); - } - - /** - * Rotate the clipboard in 2D. It can only rotate by angles divisible by 90. - * - * @param angle in degrees - */ - @SuppressWarnings("deprecation") - public void rotate2D(int angle) { - AffineTransform newTransform = new AffineTransform().rotateY(-angle); - this.transform = transform == null ? newTransform : newTransform.combine(transform); - } - - /** - * Flip the clipboard. - * - * @param dir direction to flip - */ - public void flip(FlipDirection dir) { - flip(dir, false); - } - - /** - * Flip the clipboard. - * - * @param dir direction to flip - * @param aroundPlayer flip the offset around the player - */ - @SuppressWarnings("deprecation") - public void flip(FlipDirection dir, boolean aroundPlayer) { - checkNotNull(dir); - Direction direction = dir.direction; - AffineTransform newTransform = new AffineTransform().scale(direction.toVector().abs().multiply(-2).add(1, 1, 1)); - this.transform = transform == null ? newTransform : newTransform.combine(transform); - } - - /** - * Copies blocks to the clipboard. - * - * @param editSession the EditSession from which to take the blocks - */ - public void copy(EditSession editSession) { - for (int x = 0; x < size.getBlockX(); ++x) { - for (int y = 0; y < size.getBlockY(); ++y) { - for (int z = 0; z < size.getBlockZ(); ++z) { - setBlock(x, y, z, editSession.getBlock(BlockVector3.at(x, y, z).add(getOrigin()))); - } - } - } - } - - /** - * Copies blocks to the clipboard. - * - * @param editSession The EditSession from which to take the blocks - * @param region A region that further constrains which blocks to take. - */ - public void copy(EditSession editSession, Region region) { - for (int x = 0; x < size.getBlockX(); ++x) { - for (int y = 0; y < size.getBlockY(); ++y) { - for (int z = 0; z < size.getBlockZ(); ++z) { - final BlockVector3 pt = BlockVector3.at(x, y, z).add(getOrigin()); - if (region.contains(pt)) { - setBlock(x, y, z, editSession.getBlock(pt)); - } else { - setBlock(x, y, z, (BlockState)null); - } - } - } - } - } - - /** - * Paste the clipboard at the given location using the given {@code EditSession}. - *

- *

This method blocks the server/game until the entire clipboard is - * pasted. In the future, {@link ForwardExtentCopy} will be recommended, - * which, if combined with the proposed operation scheduler framework, - * will not freeze the game/server.

- * - * @param editSession the EditSession to which blocks are to be copied to - * @param newOrigin the new origin point (must correspond to the minimum point of the cuboid) - * @param noAir true to not copy air blocks in the source - * @throws MaxChangedBlocksException thrown if too many blocks were changed - */ - public void paste(EditSession editSession, BlockVector3 newOrigin, boolean noAir) throws MaxChangedBlocksException { - paste(editSession, newOrigin, noAir, false); - } - - /** - * Paste the clipboard at the given location using the given {@code EditSession}. - *

- *

This method blocks the server/game until the entire clipboard is - * pasted. In the future, {@link ForwardExtentCopy} will be recommended, - * which, if combined with the proposed operation scheduler framework, - * will not freeze the game/server.

- * - * @param editSession the EditSession to which blocks are to be copied to - * @param newOrigin the new origin point (must correspond to the minimum point of the cuboid) - * @param noAir true to not copy air blocks in the source - * @param entities true to copy entities - * @throws MaxChangedBlocksException thrown if too many blocks were changed - */ - public void paste(EditSession editSession, BlockVector3 newOrigin, boolean noAir, boolean entities) throws MaxChangedBlocksException { - new Schematic(clipboard).paste(editSession, newOrigin, false, !noAir, entities, transform); - editSession.flushQueue(); - } - - /** - * Paste the clipboard at the given location using the given {@code EditSession}. - *

- *

This method blocks the server/game until the entire clipboard is - * pasted. In the future, {@link ForwardExtentCopy} will be recommended, - * which, if combined with the proposed operation scheduler framework, - * will not freeze the game/server.

- * - * @param editSession the EditSession to which blocks are to be copied to - * @param newOrigin the new origin point (must correspond to the minimum point of the cuboid) - * @param noAir true to not copy air blocks in the source - * @throws MaxChangedBlocksException thrown if too many blocks were changed - */ - public void place(EditSession editSession, BlockVector3 newOrigin, boolean noAir) throws MaxChangedBlocksException { - paste(editSession, newOrigin, noAir, false); - } - - /** - * Get the block at the given position. - *

- *

If the position is out of bounds, air will be returned.

- * - * @param position the point, relative to the origin of the copy (0, 0, 0) and not to the actual copy origin - * @return air, if this block was outside the (non-cuboid) selection while copying - * @throws ArrayIndexOutOfBoundsException if the position is outside the bounds of the CuboidClipboard - * @deprecated use {@link #getBlock(Vector)} instead - */ - @Deprecated - public BaseBlock getPoint(BlockVector3 position) throws ArrayIndexOutOfBoundsException { - final BaseBlock block = getBlock(position); - if (block == null) { - return BlockTypes.AIR.getDefaultState().toBaseBlock(); - } - - return block; - } - - /** - * Get the origin point, which corresponds to where the copy was - * originally copied from. The origin is the lowest possible X, Y, and - * Z components of the cuboid region that was copied. - * - * @return the origin - */ - public BlockVector3 getOrigin() { - return clipboard.getMinimumPoint(); - } - - /** - * Set the origin point, which corresponds to where the copy was - * originally copied from. The origin is the lowest possible X, Y, and - * Z components of the cuboid region that was copied. - * - * @param origin the origin to set - */ - public void setOrigin(BlockVector3 origin) { - checkNotNull(origin); - setOriginAndOffset(getOffset(), origin); - } - - public void setOriginAndOffset(BlockVector3 offset, BlockVector3 min) { - BlockVector3 origin = min.subtract(offset); - CuboidRegion region = new CuboidRegion(min, min.add(size).subtract(BlockVector3.ONE)); - clipboard.setRegion(region); - clipboard.setOrigin(origin); - } - - /** - * Get the offset of the player to the clipboard's minimum point - * (minimum X, Y, Z coordinates). - *

- *

The offset is inverse (multiplied by -1).

- * - * @return the offset the offset - */ - public BlockVector3 getOffset() { - BlockVector3 min = clipboard.getMinimumPoint(); - BlockVector3 origin = clipboard.getOrigin(); - BlockVector3 offset = min.subtract(origin); - return offset; - } - - /** - * Set the offset of the player to the clipboard's minimum point - * (minimum X, Y, Z coordinates). - *

- *

The offset is inverse (multiplied by -1).

- * - * @param offset the new offset - */ - public void setOffset(BlockVector3 offset) { - checkNotNull(offset); - setOriginAndOffset(offset, getOrigin()); - } - - /** - * Get the dimensions of the clipboard. - * - * @return the dimensions, where (1, 1, 1) is 1 wide, 1 across, 1 deep - */ - public BlockVector3 getSize() { - return size; - } - - /** - * Saves the clipboard data to a .schematic-format file. - * - * @param path the path to the file to save - * @throws IOException thrown on I/O error - * @throws DataException thrown on error writing the data for other reasons - * @deprecated use {@link ClipboardFormat#SCHEMATIC} - */ - @Deprecated - public void saveSchematic(File path) throws IOException, DataException { - checkNotNull(path); - if (transform != null && !transform.isIdentity()) { - final FlattenedClipboardTransform result = FlattenedClipboardTransform.transform(clipboard, transform); - BlockArrayClipboard target = new BlockArrayClipboard(result.getTransformedRegion(), UUID.randomUUID()); - target.setOrigin(clipboard.getOrigin()); - Operations.completeLegacy(result.copyTo(target)); - this.clipboard = target; - } - new Schematic(clipboard).save(path, BuiltInClipboardFormat.SPONGE_SCHEMATIC); - } - - /** - * Load a .schematic file into a clipboard. - * - * @param path the path to the file to load - * @return a clipboard - * @throws IOException thrown on I/O error - * @throws DataException thrown on error writing the data for other reasons - * @deprecated use {@link ClipboardFormat#SCHEMATIC} - */ - @Deprecated - public static CuboidClipboard loadSchematic(File path) throws DataException, IOException { - checkNotNull(path); - return new CuboidClipboard((BlockVector3) BuiltInClipboardFormat.MCEDIT_SCHEMATIC.load(path).getClipboard()); - } - - /** - * Get the block distribution inside a clipboard. - * - * @return a block distribution - */ - public List> getBlockDistribution() { - List> distribution = new ArrayList<>(); - List> distr = clipboard.getBlockDistributionWithData(clipboard.getRegion()); - for (Countable item : distr) { - BlockStateHolder state = item.getID(); - int[] legacyId = LegacyMapper.getInstance().getLegacyFromBlock(state.toImmutableState()); - if (legacyId[0] != 0) distribution.add(new Countable<>(legacyId[0], item.getAmount())); - } - return distribution; - } - - /** - * Get the block distribution inside a clipboard with data values. - * - * @return a block distribution - */ - public List> getBlockDistributionWithData() { - List> distribution = new ArrayList<>(); - List> distr = clipboard.getBlockDistributionWithData(clipboard.getRegion()); - for (Countable item : distr) { - distribution.add(new Countable<>(item.getID().toBaseBlock(), item.getAmount())); - } - return distribution; - } -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/Blocks.java b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/Blocks.java index c0776f995..1f65c6a19 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/Blocks.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/Blocks.java @@ -21,14 +21,11 @@ package com.sk89q.worldedit.blocks; import com.google.common.collect.Maps; import com.sk89q.worldedit.registry.state.Property; -import com.sk89q.worldedit.world.block.BlockCategories; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import java.util.Collection; -import java.util.HashSet; import java.util.Map; -import java.util.Set; /** * Block-related utility methods. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java index c4921a110..74dd69885 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java @@ -23,10 +23,12 @@ import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.Commands; import com.boydti.fawe.object.visitor.Fast2DIterator; import com.boydti.fawe.util.chat.Message; + import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.Logging; +import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; @@ -62,8 +64,6 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; - /** * Implements biome-related commands such as "/biomelist". */ @@ -84,10 +84,10 @@ public class BiomeCommands extends MethodCommands { } @Command( - aliases = {"biomelist", "biomels"}, - usage = "[page]", - desc = "Gets all biomes available.", - max = 1 + aliases = { "biomelist", "biomels" }, + usage = "[page]", + desc = "Gets all biomes available.", + max = 1 ) @CommandPermissions("worldedit.biome.list") public void biomeList(Player player, CommandContext args) throws WorldEditException { @@ -127,15 +127,15 @@ public class BiomeCommands extends MethodCommands { } @Command( - aliases = {"biomeinfo"}, - flags = "pt", - desc = "Get the biome of the targeted block.", - help = - "Get the biome of the block.\n" + - "By default use all the blocks contained in your selection.\n" + - "-t use the block you are looking at.\n" + - "-p use the block you are currently in", - max = 0 + aliases = { "biomeinfo" }, + flags = "pt", + desc = "Get the biome of the targeted block.", + help = + "Get the biome of the block.\n" + + "By default use all the blocks contained in your selection.\n" + + "-t use the block you are looking at.\n" + + "-p use the block you are currently in", + max = 0 ) @CommandPermissions("worldedit.biome.info") public void biomeInfo(Player player, LocalSession session, final EditSession editSession, CommandContext args) throws WorldEditException { @@ -192,24 +192,33 @@ public class BiomeCommands extends MethodCommands { Collections.sort(distribution); for (Countable c : distribution) { BiomeData data = biomeRegistry.getData(c.getID()); - String str = String.format("%-7s (%.3f%%) %s #%d", - String.valueOf(c.getAmount()), - c.getAmount() / (double) size * 100, - data == null ? "Unknown" : data.getName(), - c.getID().getInternalId()); + String str; + if (data == null) { + str = String.format("%-7s (%.3f%%) %s #%d", + String.valueOf(c.getAmount()), + c.getAmount() / (double) size * 100, + "Unknown", + c.getID().getInternalId()); + } else { + str = String.format("%-7s (%.3f%%) %s #%d", + String.valueOf(c.getAmount()), + c.getAmount() / (double) size * 100, + data.getName(), + c.getID().getInternalId()); + } player.print(str); } } @Command( - aliases = {"/setbiome"}, + aliases = { "/setbiome" }, usage = "", flags = "p", desc = "Sets the biome of the player's current block or region.", help = "Set the biome of the region.\n" + - "By default use all the blocks contained in your selection.\n" + - "-p use the block you are currently in" + "By default use all the blocks contained in your selection.\n" + + "-p use the block you are currently in" ) @Logging(REGION) @CommandPermissions("worldedit.biome.set") @@ -220,7 +229,7 @@ public class BiomeCommands extends MethodCommands { Mask2D mask2d = mask != null ? mask.toMask2D() : null; if (atPosition) { - region = new CuboidRegion(player.getLocation().toBlockPoint(), player.getLocation().toBlockPoint()); + region = new CuboidRegion(player.getLocation().toVector().toBlockPoint(), player.getLocation().toVector().toBlockPoint()); } else { region = session.getSelection(world); } @@ -236,4 +245,5 @@ public class BiomeCommands extends MethodCommands { if (!player.hasPermission("fawe.tips")) BBC.TIP_BIOME_PATTERN.or(BBC.TIP_BIOME_MASK).send(player); } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/SelectionCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/SelectionCommand.java index abc20a451..77c94a3d6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/SelectionCommand.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/SelectionCommand.java @@ -183,6 +183,4 @@ public class SelectionCommand extends SimpleCommand { return locals.get(Actor.class).hasPermission(permission); } - - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ShapedBrushCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ShapedBrushCommand.java index 3de5dc6ed..98daedde2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ShapedBrushCommand.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ShapedBrushCommand.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.command.composition; -import com.boydti.fawe.config.BBC; - import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.minecraft.util.commands.CommandException; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java index b6d7c7838..5e644fd86 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java @@ -1,15 +1,32 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + package com.sk89q.worldedit.command.tool; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; -import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -30,11 +47,11 @@ public class AreaPickaxe implements BlockTool { } @Override - public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) { + public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { int ox = clicked.getBlockX(); int oy = clicked.getBlockY(); int oz = clicked.getBlockZ(); - BlockType initialType = clicked.getExtent().getBlock(clicked.toBlockPoint()).getBlockType(); + BlockType initialType = clicked.getExtent().getBlock(clicked.toVector().toBlockPoint()).getBlockType(); if (initialType.getMaterial().isAir()) { return true; @@ -45,23 +62,29 @@ public class AreaPickaxe implements BlockTool { } try (EditSession editSession = session.createEditSession(player)) { + editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop); + try { - editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop); for (int x = ox - range; x <= ox + range; ++x) { for (int z = oz - range; z <= oz + range; ++z) { for (int y = oy + range; y >= oy - range; --y) { - if (initialType.equals(editSession.getLazyBlock(x, y, z))) { + BlockVector3 pos = BlockVector3.at(x, y, z); + if (editSession.getLazyBlock(pos).getBlockType() != initialType) { continue; } - editSession.setBlock(x, y, z, BlockTypes.AIR.getDefaultState()); + editSession.setBlock(pos, BlockTypes.AIR.getDefaultState()); } } } editSession.flushQueue(); + } catch (MaxChangedBlocksException e) { + player.printError("Max blocks change limit reached."); } finally { session.remember(editSession); } } + return true; } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java index d4405fe55..5f87f9097 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java @@ -56,8 +56,7 @@ public class BlockDataCyler implements DoubleActionBlockTool { World world = (World) clicked.getExtent(); -// BlockStateHolder block = world.getBlock(clicked); - BlockVector3 blockPoint = clicked.toBlockPoint(); + BlockVector3 blockPoint = clicked.toVector().toBlockPoint(); BlockState block = world.getBlock(blockPoint); if (!config.allowedDataCycleBlocks.isEmpty() @@ -68,42 +67,43 @@ public class BlockDataCyler implements DoubleActionBlockTool { } if (block.getStates().keySet().isEmpty()) { - BBC.BLOCK_CYCLER_CANNOT_CYCLE.send(player); + BBC.BLOCK_CYCLER_CANNOT_CYCLE.send(player); } else { - Property currentProperty = selectedProperties.get(player.getUniqueId()); + Property currentProperty = selectedProperties.get(player.getUniqueId()); - if (currentProperty == null || (forward && block.getState(currentProperty) == null)) { - currentProperty = block.getStates().keySet().stream().findFirst().get(); - selectedProperties.put(player.getUniqueId(), currentProperty); - } + if (currentProperty == null || (forward && block.getState(currentProperty) == null)) { + currentProperty = block.getStates().keySet().stream().findFirst().get(); + selectedProperties.put(player.getUniqueId(), currentProperty); + } - if (forward) { - block.getState(currentProperty); - int index = currentProperty.getValues().indexOf(block.getState(currentProperty)); - index = (index + 1) % currentProperty.getValues().size(); - @SuppressWarnings("unchecked") - Property objProp = (Property) currentProperty; - BlockState newBlock = block.with(objProp, currentProperty.getValues().get(index)); + if (forward) { + block.getState(currentProperty); + int index = currentProperty.getValues().indexOf(block.getState(currentProperty)); + index = (index + 1) % currentProperty.getValues().size(); + @SuppressWarnings("unchecked") + Property objProp = (Property) currentProperty; + BlockState newBlock = block.with(objProp, currentProperty.getValues().get(index)); - try { - EditSession editSession = session.createEditSession(player); - try { - editSession.setBlock(blockPoint, newBlock); - player.print("Value of " + currentProperty.getName() + " is now " + currentProperty.getValues().get(index).toString()); - } catch (MaxChangedBlocksException e) { - BBC.BLOCK_CYCLER_LIMIT.send(player); - } finally { - session.remember(editSession); - } - }catch (Exception e) {} - } else { - List> properties = Lists.newArrayList(block.getStates().keySet()); - int index = properties.indexOf(currentProperty); - index = (index + 1) % properties.size(); - currentProperty = properties.get(index); - selectedProperties.put(player.getUniqueId(), currentProperty); - player.print("Now cycling " + currentProperty.getName()); - } + try (EditSession editSession = session.createEditSession(player)) { + editSession.disableBuffering(); + + try { + editSession.setBlock(blockPoint, newBlock); + player.print("Value of " + currentProperty.getName() + " is now " + currentProperty.getValues().get(index).toString()); + } catch (MaxChangedBlocksException e) { + BBC.BLOCK_CYCLER_LIMIT.send(player); + } finally { + session.remember(editSession); + } + } + } else { + List> properties = Lists.newArrayList(block.getStates().keySet()); + int index = properties.indexOf(currentProperty); + index = (index + 1) % properties.size(); + currentProperty = properties.get(index); + selectedProperties.put(player.getUniqueId(), currentProperty); + player.print("Now cycling " + currentProperty.getName()); + } } return true; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java index 0375729e8..10b5790ec 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java @@ -19,7 +19,6 @@ package com.sk89q.worldedit.command.tool; -import com.boydti.fawe.config.BBC; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; @@ -32,10 +31,9 @@ import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockStateHolder; -import com.sk89q.worldedit.world.block.BlockType; /** + * A mode that replaces one block. */ public class BlockReplacer implements DoubleActionBlockTool { @@ -75,12 +73,11 @@ public class BlockReplacer implements DoubleActionBlockTool { @Override public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { EditSession editSession = session.createEditSession(player); - BlockStateHolder targetBlock = (editSession).getBlock(clicked.toBlockPoint()); - BlockType type = targetBlock.getBlockType(); + BlockState targetBlock = editSession.getBlock(clicked.toVector().toBlockPoint()); - if (type != null) { - this.pattern = targetBlock; - player.print("Replacer tool switched to: " + type.getName()); + if (targetBlock != null) { + pattern = new BlockPattern(targetBlock); + player.print("Replacer tool switched to: " + targetBlock.getBlockType().getName()); } return true; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java index 5e5274b90..783a6a402 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java @@ -1,3 +1,22 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + package com.sk89q.worldedit.command.tool; import com.boydti.fawe.Fawe; @@ -16,15 +35,21 @@ import com.boydti.fawe.object.brush.visualization.VisualMode; import com.boydti.fawe.object.extent.ResettableExtent; import com.boydti.fawe.object.mask.MaskedTargetBlock; import com.boydti.fawe.object.pattern.PatternTraverser; -import com.boydti.fawe.util.*; +import com.boydti.fawe.util.BrushCache; +import com.boydti.fawe.util.EditSessionBuilder; +import com.boydti.fawe.util.MaskTraverser; +import com.boydti.fawe.util.StringMan; +import com.boydti.fawe.util.TaskManager; + +import static com.google.common.base.Preconditions.checkNotNull; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.sk89q.minecraft.util.commands.CommandException; -import com.sk89q.worldedit.*; - -import com.sk89q.worldedit.internal.expression.Expression; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.math.Vector3; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalConfiguration; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.entity.Player; @@ -36,10 +61,14 @@ import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.MaskIntersection; import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.internal.expression.Expression; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.block.BlockType; +import javax.annotation.Nullable; import java.io.IOException; import java.io.Serializable; import java.lang.reflect.Type; @@ -47,11 +76,10 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; -import javax.annotation.Nullable; - - -import static com.google.common.base.Preconditions.checkNotNull; +/** + * Builds a shape at the place being looked at. + */ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool, ResettableTool, Serializable { // TODO: // Serialize methods @@ -79,7 +107,13 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool private transient BaseItem holder; + /** + * Construct the tool. + * + * @param permission the permission to check before use is allowed + */ public BrushTool(String permission) { + checkNotNull(permission); getContext().addPermission(permission); } @@ -285,10 +319,9 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool /** * Set the brush. * - * @param brush tbe brush + * @param brush tbe brush * @param permission the permission */ - @Deprecated public void setBrush(Brush brush, String permission) { setBrush(brush, permission, null); update(); @@ -388,7 +421,6 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool pitch = 23 - (pitch / 4); d += (int) (Math.sin(Math.toRadians(pitch)) * 50); final Vector3 vector = loc.getDirection().withY(0).normalize().multiply(d).add(loc.getX(), loc.getY(), loc.getZ()); -// vector = vector.add(loc.getX(), loc.getY(), loc.getZ()); return offset(vector, loc).toBlockPoint(); } case TARGET_POINT_HEIGHT: { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java index 8f43fce0e..d1635da8c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java @@ -51,7 +51,7 @@ public class DistanceWand extends BrushTool implements DoubleActionTraceTool { if (target == null) return true; RegionSelector selector = session.getRegionSelector(player.getWorld()); - BlockVector3 blockPoint = target.toBlockPoint(); + BlockVector3 blockPoint = target.toVector().toBlockPoint(); if (selector.selectPrimary(blockPoint, ActorSelectorLimits.forActor(player))) { selector.explainPrimarySelection(player, session, blockPoint); } @@ -69,7 +69,7 @@ public class DistanceWand extends BrushTool implements DoubleActionTraceTool { if (target == null) return true; RegionSelector selector = session.getRegionSelector(player.getWorld()); - BlockVector3 blockPoint = target.toBlockPoint(); + BlockVector3 blockPoint = target.toVector().toBlockPoint(); if (selector.selectSecondary(blockPoint, ActorSelectorLimits.forActor(player))) { selector.explainSecondarySelection(player, session, blockPoint); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java index 39c27845d..a85ea8d10 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java @@ -19,9 +19,9 @@ package com.sk89q.worldedit.command.tool; -import com.boydti.fawe.object.collection.BlockVectorSet; import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.collection.LocalBlockVectorSet; + import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; @@ -38,9 +38,7 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; -import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedList; import java.util.Set; /** @@ -70,7 +68,7 @@ public class FloatingTreeRemover implements BlockTool { @Override public boolean actPrimary(Platform server, LocalConfiguration config, - Player player, LocalSession session, Location clicked) { + Player player, LocalSession session, Location clicked) { final World world = (World) clicked.getExtent(); final BlockState state = world.getBlock(clicked.toVector().toBlockPoint()); @@ -161,4 +159,4 @@ public class FloatingTreeRemover implements BlockTool { return visited; } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java index 594beb60b..bb9974b75 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java @@ -19,7 +19,6 @@ package com.sk89q.worldedit.command.tool; -import com.boydti.fawe.object.mask.IdMask; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; @@ -28,7 +27,6 @@ import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.function.block.BlockReplace; -import com.sk89q.worldedit.function.mask.BlockTypeMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; @@ -39,7 +37,6 @@ import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; -import java.util.HashSet; import java.util.Set; /** @@ -64,7 +61,7 @@ public class FloodFillTool implements BlockTool { public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) { World world = (World) clicked.getExtent(); - BlockVector3 origin = clicked.toBlockPoint(); + BlockVector3 origin = clicked.toVector().toBlockPoint(); BlockType initialType = world.getBlock(origin).getBlockType(); if (initialType.getMaterial().isAir()) { @@ -88,6 +85,7 @@ public class FloodFillTool implements BlockTool { session.remember(editSession); } } + return true; } @@ -120,5 +118,4 @@ public class FloodFillTool implements BlockTool { origin, size, initialType, visited); } - -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java index 3c45185ef..c868ff99e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java @@ -61,25 +61,27 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo if (applied.getBlockType().getMaterial().isAir()) { eS.setBlock(blockPoint, secondary); } else { - eS.setBlock(pos.subtract(pos.getDirection()).toBlockPoint(), secondary); + eS.setBlock(pos.toVector().subtract(pos.getDirection()).toBlockPoint(), secondary); } return true; } catch (MaxChangedBlocksException e) { // one block? eat it } return false; + } @Override public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session) { Location pos = getTargetFace(player); + if (pos == null) return false; try (EditSession eS = session.createEditSession(player)) { - BlockVector3 blockPoint = pos.toBlockPoint(); + BlockVector3 blockPoint = pos.toVector().toBlockPoint(); BaseBlock applied = primary.apply(blockPoint); if (applied.getBlockType().getMaterial().isAir()) { eS.setBlock(blockPoint, primary); } else { - eS.setBlock(pos.subtract(pos.getDirection()).toBlockPoint(), primary); + eS.setBlock(pos.toVector().subtract(pos.getDirection()).toBlockPoint(), primary); } return true; } catch (MaxChangedBlocksException e) { @@ -99,4 +101,4 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo return target; } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java index 8ae0302f3..ef71569f4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java @@ -45,10 +45,10 @@ public class QueryTool implements BlockTool { World world = (World) clicked.getExtent(); EditSession editSession = session.createEditSession(player); - BlockVector3 blockPoint = clicked.toBlockPoint(); + BlockVector3 blockPoint = clicked.toVector().toBlockPoint(); BaseBlock block = editSession.getFullBlock(blockPoint); - player.print("\u00A79@" + blockPoint + ": " + "\u00A7e" + player.print("\u00A79@" + clicked.toVector() + ": " + "\u00A7e" + block.getBlockType().getName() + "\u00A77" + " (" + block.toString() + ") " + "\u00A7f" diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java index ce74b6285..2f182db33 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java @@ -1,3 +1,22 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + package com.sk89q.worldedit.command.tool; import com.boydti.fawe.object.mask.IdMask; @@ -22,6 +41,7 @@ import com.sk89q.worldedit.world.block.BlockTypes; * an initial block and of the same type. */ public class RecursivePickaxe implements BlockTool { + private double range; public RecursivePickaxe(double range) { @@ -39,7 +59,7 @@ public class RecursivePickaxe implements BlockTool { final BlockVector3 pos = clicked.toBlockPoint(); EditSession editSession = session.createEditSession(player); - BlockVector3 origin = clicked.toBlockPoint(); + BlockVector3 origin = clicked.toVector().toBlockPoint(); BlockType initialType = world.getBlock(origin).getBlockType(); BlockStateHolder block = editSession.getBlock(pos); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java index 13fc1ee71..173dd7936 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java @@ -21,11 +21,9 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.function.mask.Mask; -import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BlockStateHolder; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; public class GravityBrush implements Brush { @@ -37,24 +35,21 @@ public class GravityBrush implements Brush { } @Override - public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException { - Mask mask = editSession.getMask(); - if (mask == Masks.alwaysTrue() || mask == Masks.alwaysTrue2D()) { - mask = null; - } - int size = (int) sizeDouble; - int endY = position.getBlockY() + size; - int startPerformY = Math.max(0, position.getBlockY() - size); - int startCheckY = fullHeight ? 0 : startPerformY; - for (int x = position.getBlockX() + size; x > position.getBlockX() - size; --x) { - for (int z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) { - int freeSpot = startCheckY; - for (int y = startCheckY; y <= endY; y++) { - BlockStateHolder block = editSession.getLazyBlock(x, y, z); + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { + double endY = position.getBlockY() + size; + double startPerformY = Math.max(0, position.getBlockY() - size); + double startCheckY = fullHeight ? 0 : startPerformY; + for (double x = position.getBlockX() + size; x > position.getBlockX() - size; --x) { + for (double z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) { + double freeSpot = startCheckY; + for (double y = startCheckY; y <= endY; ++y) { + final BlockVector3 pt = BlockVector3.at(x, y, z); + final BlockState block = editSession.getLazyBlock(pt); if (!block.getBlockType().getMaterial().isAir()) { if (y != freeSpot) { - editSession.setBlock(x, y, z, BlockTypes.AIR.getDefaultState()); - editSession.setBlock(x, freeSpot, z, block); + editSession.setBlock(pt, BlockTypes.AIR.getDefaultState()); + final BlockVector3 pt2 = BlockVector3.at(x, freeSpot, z); + editSession.setBlock(pt2, block); } freeSpot = y + 1; } @@ -63,6 +58,4 @@ public class GravityBrush implements Brush { } } - - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java index d96a44819..dbf959e1b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java @@ -37,7 +37,7 @@ public class HollowCylinderBrush implements Brush { @Override public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { if (pattern == null) { - pattern = (BlockTypes.COBBLESTONE.getDefaultState()); + pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); } editSession.makeCylinder(position, pattern, size, size, height, false); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java index bbba333b3..0e89b3c16 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java @@ -31,7 +31,7 @@ public class HollowSphereBrush implements Brush { @Override public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { if (pattern == null) { - pattern = (BlockTypes.COBBLESTONE.getDefaultState()); + pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); } editSession.makeSphere(position, pattern, size, size, size, false); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SmoothBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SmoothBrush.java index 66a73112b..2ecf245d1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SmoothBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SmoothBrush.java @@ -53,7 +53,7 @@ public class SmoothBrush implements Brush { Vector3 posDouble = position.toVector3(); Location min = new Location(editSession.getWorld(), posDouble.subtract(size, size, size)); BlockVector3 max = posDouble.add(size, size + 10, size).toBlockPoint(); - Region region = new CuboidRegion(editSession.getWorld(), min.toBlockPoint(), max); + Region region = new CuboidRegion(editSession.getWorld(), min.toVector().toBlockPoint(), max); HeightMap heightMap = new HeightMap(editSession, region, mask); HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0)); heightMap.applyFilter(filter, iterations); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java index 07e852da6..d8028f2ae 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java @@ -31,7 +31,7 @@ public class SphereBrush implements Brush { @Override public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { if (pattern == null) { - pattern = (BlockTypes.COBBLESTONE.getDefaultState()); + pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); } editSession.makeSphere(position, pattern, size, size, size, true); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java index ca73e5975..460b22f10 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.extension.factory.parser; +import com.boydti.fawe.Fawe; import com.boydti.fawe.config.BBC; import com.boydti.fawe.jnbt.JSON2NBT; import com.boydti.fawe.jnbt.NBTException; @@ -229,7 +230,13 @@ public class DefaultBlockParser extends InputParser { throw new NoMatchException("Does not match a valid block type: '" + input + "'"); } } - nbt = state.getNbtData(); + if (state != null) { + nbt = state.getNbtData(); + } else { + Fawe.debug("State was null."); + Fawe.debug("Input was: " + input); + Fawe.debug("typestring was: " + typeString); + } if (stateString != null) { state = BlockState.get(state.getBlockType(), "[" + stateString + "]", state); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java index be54386b0..fb3bbe620 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java @@ -22,8 +22,8 @@ package com.sk89q.worldedit.extent; import com.boydti.fawe.jnbt.anvil.generator.GenBase; import com.boydti.fawe.jnbt.anvil.generator.Resource; import com.boydti.fawe.object.extent.LightingExtent; -import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; @@ -41,10 +41,9 @@ import com.sk89q.worldedit.world.block.BaseBlock; 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.registry.BundledBlockData; -import java.util.List; import javax.annotation.Nullable; +import java.util.List; /** * A base class for {@link Extent}s that merely passes extents onto another. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/ChangeSetExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/ChangeSetExtent.java index 5a8f771f8..0c3de3d4f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/ChangeSetExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/ChangeSetExtent.java @@ -19,9 +19,6 @@ package com.sk89q.worldedit.extent; -import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BlockStateHolder; -import com.sk89q.worldedit.world.block.BlockState; import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.WorldEditException; @@ -40,11 +37,10 @@ import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; -import javax.annotation.Nullable; - /** * Stores changes to a {@link ChangeSet}. */ diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java index ccdcb61e2..01c1e5240 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java @@ -19,12 +19,15 @@ package com.sk89q.worldedit.extent; -import com.boydti.fawe.jnbt.anvil.generator.*; -import com.boydti.fawe.object.clipboard.WorldCopyClipboard; +import com.boydti.fawe.jnbt.anvil.generator.CavesGen; +import com.boydti.fawe.jnbt.anvil.generator.GenBase; +import com.boydti.fawe.jnbt.anvil.generator.OreGen; +import com.boydti.fawe.jnbt.anvil.generator.Resource; +import com.boydti.fawe.jnbt.anvil.generator.SchemGen; + import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; -import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.pattern.Pattern; @@ -173,13 +176,13 @@ public interface Extent extends InputExtent, OutputExtent { for (int d = 0; d <= clearance; d++) { int y1 = y + d; block = getLazyBlock(x, y1, z); - if (!block.getBlockType().getMaterial().isMovementBlocker() != state) { + if (block.getBlockType().getMaterial().isMovementBlocker() == state) { return ((y1 - offset) << 4) - (15 - (state ? PropertyGroup.LEVEL.get(block) : data1)); } data1 = PropertyGroup.LEVEL.get(block); int y2 = y - d; block = getLazyBlock(x, y2, z); - if (!block.getBlockType().getMaterial().isMovementBlocker() != state) { + if (block.getBlockType().getMaterial().isMovementBlocker() == state) { return ((y2 + offset) << 4) - (15 - (state ? PropertyGroup.LEVEL.get(block) : data2)); } data2 = PropertyGroup.LEVEL.get(block); @@ -188,16 +191,15 @@ public interface Extent extends InputExtent, OutputExtent { if (clearanceAbove < clearanceBelow) { for (int layer = y - clearance - 1; layer >= minY; layer--) { block = getLazyBlock(x, layer, z); - if (!block.getBlockType().getMaterial().isMovementBlocker() != state) { - int data = (state ? PropertyGroup.LEVEL.get(block) : data1); - return ((layer + offset) << 4) + 0; + if (block.getBlockType().getMaterial().isMovementBlocker() == state) { + return layer + offset << 4; } data1 = PropertyGroup.LEVEL.get(block); } } else { for (int layer = y + clearance + 1; layer <= maxY; layer++) { block = getLazyBlock(x, layer, z); - if (!block.getBlockType().getMaterial().isMovementBlocker() != state) { + if (block.getBlockType().getMaterial().isMovementBlocker() == state) { return ((layer - offset) << 4) - (15 - (state ? PropertyGroup.LEVEL.get(block) : data2)); } data2 = PropertyGroup.LEVEL.get(block); @@ -243,8 +245,7 @@ public interface Extent extends InputExtent, OutputExtent { } } } - int result = state ? failedMin : failedMax; - return result; + return state ? failedMin : failedMax; } default int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, boolean ignoreAir) { @@ -258,21 +259,21 @@ public interface Extent extends InputExtent, OutputExtent { for (int d = 0; d <= clearance; d++) { int y1 = y + d; block = getLazyBlock(x, y1, z); - if (!block.getMaterial().isMovementBlocker() != state && block.getBlockType() != BlockTypes.__RESERVED__) return y1 - offset; + if (block.getMaterial().isMovementBlocker() == state && block.getBlockType() != BlockTypes.__RESERVED__) return y1 - offset; int y2 = y - d; block = getLazyBlock(x, y2, z); - if (!block.getMaterial().isMovementBlocker() != state && block.getBlockType() != BlockTypes.__RESERVED__) return y2 + offset; + if (block.getMaterial().isMovementBlocker() == state && block.getBlockType() != BlockTypes.__RESERVED__) return y2 + offset; } if (clearanceAbove != clearanceBelow) { if (clearanceAbove < clearanceBelow) { for (int layer = y - clearance - 1; layer >= minY; layer--) { block = getLazyBlock(x, layer, z); - if (!block.getMaterial().isMovementBlocker() != state && block.getBlockType() != BlockTypes.__RESERVED__) return layer + offset; + if (block.getMaterial().isMovementBlocker() == state && block.getBlockType() != BlockTypes.__RESERVED__) return layer + offset; } } else { for (int layer = y + clearance + 1; layer <= maxY; layer++) { block = getLazyBlock(x, layer, z); - if (!block.getMaterial().isMovementBlocker() != state && block.getBlockType() != BlockTypes.__RESERVED__) return layer - offset; + if (block.getMaterial().isMovementBlocker() == state && block.getBlockType() != BlockTypes.__RESERVED__) return layer - offset; } } } @@ -294,7 +295,7 @@ public interface Extent extends InputExtent, OutputExtent { } } - default public void addSchems(Region region, Mask mask, List clipboards, int rarity, boolean rotate) throws WorldEditException { + default void addSchems(Region region, Mask mask, List clipboards, int rarity, boolean rotate) throws WorldEditException { spawnResource(region, new SchemGen(mask, this, clipboards, rotate), rarity, 1); } @@ -318,11 +319,11 @@ public interface Extent extends InputExtent, OutputExtent { return (pt.containedWithin(min, max)); } - default public void addOre(Region region, Mask mask, Pattern material, int size, int frequency, int rarity, int minY, int maxY) throws WorldEditException { + default void addOre(Region region, Mask mask, Pattern material, int size, int frequency, int rarity, int minY, int maxY) throws WorldEditException { spawnResource(region, new OreGen(this, mask, material, size, minY, maxY), rarity, frequency); } - default public void addOres(Region region, Mask mask) throws WorldEditException { + default void addOres(Region region, Mask mask) throws WorldEditException { addOre(region, mask, BlockTypes.DIRT.getDefaultState(), 33, 10, 100, 0, 255); addOre(region, mask, BlockTypes.GRAVEL.getDefaultState(), 33, 8, 100, 0, 255); addOre(region, mask, BlockTypes.ANDESITE.getDefaultState(), 33, 10, 100, 0, 79); @@ -398,19 +399,6 @@ public interface Extent extends InputExtent, OutputExtent { return distribution; } - /** - * Lazily copy a region - * - * @param region - * @return - */ - default BlockArrayClipboard lazyCopy(Region region) { - WorldCopyClipboard faweClipboard = new WorldCopyClipboard(this, region); - BlockArrayClipboard weClipboard = new BlockArrayClipboard(region, faweClipboard); - weClipboard.setOrigin(region.getMinimumPoint()); - return weClipboard; - } - @Nullable @Override default Operation commit() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java index b92caaa5f..5af7a9405 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java @@ -20,14 +20,11 @@ package com.sk89q.worldedit.extent; import static com.google.common.base.Preconditions.checkNotNull; - import com.sk89q.worldedit.WorldEditException; - -import com.sk89q.worldedit.math.BlockVector2; -import com.sk89q.worldedit.world.biome.BiomeType; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockStateHolder; /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java index 0359c51b8..df7d4dde4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java @@ -58,9 +58,9 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable private Region region; private BlockVector3 origin; + private BlockStateHolder[][][] blocks; public FaweClipboard IMP; private BlockVector3 size; - private BlockStateHolder[][][] blocks; private final List entities = new ArrayList<>(); public BlockArrayClipboard(Region region) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java index aeaf07e85..e0022d480 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java @@ -20,7 +20,6 @@ package com.sk89q.worldedit.extent.clipboard; import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; @@ -59,15 +58,4 @@ public interface Clipboard extends Extent { */ void setOrigin(BlockVector3 origin); - /** - * Returns true if the clipboard has biome data. This can be checked since {@link Extent#getBiome(BlockVector2)} - * strongly suggests returning {@link com.sk89q.worldedit.world.biome.BiomeTypes.OCEAN} instead of {@code null} - * if biomes aren't present. However, it might not be desired to set areas to ocean if the clipboard is defaulting - * to ocean, instead of having biomes explicitly set. - * - * @return true if the clipboard has biome data set - */ - default boolean hasBiomes() { - return false; - } } 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 bb2729a09..025bb76d9 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,6 +19,21 @@ package com.sk89q.worldedit.extent.clipboard.io; +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.extent.clipboard.Clipboard; +import com.sk89q.worldedit.math.BlockVector3; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -29,23 +44,6 @@ import java.net.URL; import java.util.HashMap; import java.util.Set; -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 com.google.gson.Gson; -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.entity.Player; -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.session.ClipboardHolder; - /** * A collection of supported clipboard formats. */ @@ -105,16 +103,15 @@ public interface ClipboardFormat { * @return The file extensions this format might be known by */ Set getFileExtensions(); - + /** * Set the player's clipboard * @param player * @param uri * @param in - * @return the held clipboard * @throws IOException */ - default ClipboardHolder hold(Player player, URI uri, InputStream in) throws IOException { + default void hold(Player player, URI uri, InputStream in) throws IOException { checkNotNull(player); checkNotNull(uri); checkNotNull(in); @@ -128,9 +125,8 @@ public interface ClipboardFormat { clipboard = reader.read(player.getUniqueId()); URIClipboardHolder holder = new URIClipboardHolder(uri, clipboard); session.setClipboard(holder); - return holder; } - + default Schematic load(File file) throws IOException { return load(new FileInputStream(file)); } @@ -138,8 +134,8 @@ public interface ClipboardFormat { default Schematic load(InputStream stream) throws IOException { return new Schematic(getReader(stream).read()); } - - + + default URL uploadPublic(final Clipboard clipboard, String category, String user) { // summary // blocks @@ -158,7 +154,7 @@ public interface ClipboardFormat { } }); } - + default URL uploadAnonymous(final Clipboard clipboard) { return MainUtil.upload(null, null, getPrimaryFileExtension(), new RunnableVal() { @Override @@ -167,7 +163,7 @@ public interface ClipboardFormat { } }); } - + default void write(OutputStream value, Clipboard clipboard) { try { try (PGZIPOutputStream gzip = new PGZIPOutputStream(value)) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java index 70cd9045b..375f4c2dc 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java @@ -284,7 +284,6 @@ public class ClipboardFormats { byte[] buffer = new byte[8192]; while ((entry = zip.getNextEntry()) != null) { String filename = entry.getName(); - String extension = filename.substring(filename.lastIndexOf('.') + 1, filename.length()); ClipboardFormat format = findByExtension(filename); if (format != null) { FastByteArrayOutputStream out = new FastByteArrayOutputStream(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardReader.java index 016984032..07ff96593 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardReader.java @@ -43,4 +43,4 @@ public interface ClipboardReader extends Closeable { default Clipboard read(UUID uuid) throws IOException { return read(); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/MCEditSchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/MCEditSchematicReader.java index 00e52e902..3997f28c7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/MCEditSchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/MCEditSchematicReader.java @@ -29,7 +29,6 @@ import com.sk89q.jnbt.ShortTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java index e4ac175f9..a95844c29 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java @@ -22,21 +22,14 @@ package com.sk89q.worldedit.extent.clipboard.io; import com.boydti.fawe.Fawe; import com.boydti.fawe.jnbt.CorruptSchematicStreamer; import com.boydti.fawe.jnbt.SchematicStreamer; -import com.sk89q.jnbt.CompoundTag; + +import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.jnbt.NBTInputStream; -import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.extent.clipboard.Clipboard; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStream; -import java.util.Map; import java.util.UUID; -import javax.annotation.Nullable; - - -import static com.google.common.base.Preconditions.checkNotNull; /** * Reads schematic files based that are compatible with MCEdit and other editors. @@ -75,36 +68,6 @@ public class SchematicReader implements ClipboardReader { } } - private static T requireTag(Map items, String key, Class expected) throws IOException { - if (!items.containsKey(key)) { - throw new IOException("Schematic file is missing a \"" + key + "\" tag"); - } - - Tag tag = items.get(key); - if (!expected.isInstance(tag)) { - throw new IOException(key + " tag is not of tag type " + expected.getName()); - } - - return expected.cast(tag); - } - - @Nullable - private static T getTag(CompoundTag tag, Class expected, String key) { - Map items = tag.getValue(); - - if (!items.containsKey(key)) { - return null; - } - - Tag test = items.get(key); - if (!expected.isInstance(test)) { - return null; - } - - return expected.cast(test); - } - - @Override public void close() throws IOException { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java index e759af00a..c6649a0c9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java @@ -110,7 +110,7 @@ public class SpongeSchematicReader extends NBTSchematicReader { public Clipboard read(UUID uuid) throws IOException { return readVersion1(uuid); } - + private int width, height, length; private int offsetX, offsetY, offsetZ; private char[] palette; @@ -132,7 +132,7 @@ public class SpongeSchematicReader extends NBTSchematicReader { return fc = new MemoryOptimizedClipboard(size, 1, 1); } } - + private Clipboard readVersion1(UUID uuid) throws IOException { width = height = length = offsetX = offsetY = offsetZ = Integer.MIN_VALUE; @@ -249,7 +249,6 @@ public class SpongeSchematicReader extends NBTSchematicReader { return clipboard; } - @Override public void close() throws IOException { inputStream.close(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java index 372c545a9..9322bc50a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java @@ -21,6 +21,8 @@ package com.sk89q.worldedit.extent.clipboard.io; import com.boydti.fawe.object.clipboard.FaweClipboard; import com.boydti.fawe.util.IOUtil; + +import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.DoubleTag; import com.sk89q.jnbt.FloatTag; @@ -33,12 +35,12 @@ import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; -import com.sk89q.worldedit.math.Vector3; -import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -55,9 +57,6 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Vector; - -import static com.google.common.base.Preconditions.checkNotNull; /** * Writes schematic files using the Sponge schematic format. @@ -82,8 +81,13 @@ public class SpongeSchematicWriter implements ClipboardWriter { write1(clipboard); } - public void write1(Clipboard clipboard) throws IOException { - // metadata + /** + * Writes a version 1 schematic file. + * + * @param clipboard The clipboard + * @throws IOException If an error occurs + */ + private void write1(Clipboard clipboard) throws IOException { Region region = clipboard.getRegion(); BlockVector3 origin = clipboard.getOrigin(); BlockVector3 min = region.getMinimumPoint(); @@ -91,6 +95,7 @@ public class SpongeSchematicWriter implements ClipboardWriter { int width = region.getWidth(); int height = region.getHeight(); int length = region.getLength(); + if (width > MAX_SIZE) { throw new IllegalArgumentException("Width of region too large for a .schematic"); } @@ -100,13 +105,15 @@ public class SpongeSchematicWriter implements ClipboardWriter { if (length > MAX_SIZE) { throw new IllegalArgumentException("Length of region too large for a .schematic"); } - // output + final DataOutput rawStream = outputStream.getOutputStream(); outputStream.writeLazyCompoundTag("Schematic", out -> { out.writeNamedTag("Version", 1); out.writeNamedTag("Width", (short) width); out.writeNamedTag("Height", (short) height); out.writeNamedTag("Length", (short) length); + + // The Sponge format Offset refers to the 'min' points location in the world. That's our 'Origin' out.writeNamedTag("Offset", new int[]{ min.getBlockX(), min.getBlockY(), @@ -124,7 +131,6 @@ public class SpongeSchematicWriter implements ClipboardWriter { ByteArrayOutputStream tilesCompressed = new ByteArrayOutputStream(); NBTOutputStream tilesOut = new NBTOutputStream(new LZ4BlockOutputStream(tilesCompressed)); - int[] numTiles = {0}; List paletteList = new ArrayList<>(); char[] palette = new char[BlockTypes.states.length]; @@ -132,27 +138,34 @@ public class SpongeSchematicWriter implements ClipboardWriter { int[] paletteMax = {0}; + int[] numTiles = {0}; FaweClipboard.BlockReader reader = new FaweClipboard.BlockReader() { @Override public > void run(int x, int y, int z, B block) { try { - boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData(); + boolean hasNbt = block instanceof BaseBlock && block.hasNbtData(); if (hasNbt) { - BaseBlock localBlock = (BaseBlock)block; - Map values = localBlock.getNbtData().getValue(); - values.remove("id"); // Remove 'id' if it exists. We want 'Id' - // Positions are kept in NBT, we don't want that. - values.remove("x"); - values.remove("y"); - values.remove("z"); - if (!values.containsKey("Id")) values.put("Id", new StringTag(localBlock.getNbtId())); - values.put("Pos", new IntArrayTag(new int[]{ - x, - y, - z - })); - numTiles[0]++; - tilesOut.writeTagPayload(localBlock.getNbtData()); + if (block.getNbtData() != null) { + BaseBlock localBlock = (BaseBlock) block; + Map values = localBlock.getNbtData().getValue(); + + values.remove("id"); // Remove 'id' if it exists. We want 'Id' + + // Positions are kept in NBT, we don't want that. + values.remove("x"); + values.remove("y"); + values.remove("z"); + if (!values.containsKey("Id")) { + values.put("Id", new StringTag(block.getNbtId())); + } + values.put("Pos", new IntArrayTag(new int[]{ + x, + y, + z + })); + numTiles[0]++; + tilesOut.writeTagPayload(localBlock.getNbtData()); + } } int ordinal = block.getOrdinal(); char value = palette[ordinal]; @@ -185,9 +198,9 @@ public class SpongeSchematicWriter implements ClipboardWriter { // close tilesOut.close(); blocksOut.close(); - // palette max + out.writeNamedTag("PaletteMax", paletteMax[0]); - // palette + out.writeLazyCompoundTag("Palette", out12 -> { for (int i = 0; i < paletteList.size(); i++) { int stateOrdinal = paletteList.get(i); @@ -195,13 +208,13 @@ public class SpongeSchematicWriter implements ClipboardWriter { out12.writeNamedTag(state.getAsString(), i); } }); - // Block data + out.writeNamedTagName("BlockData", NBTConstants.TYPE_BYTE_ARRAY); rawStream.writeInt(blocksOut.size()); try (LZ4BlockInputStream in = new LZ4BlockInputStream(new ByteArrayInputStream(blocksCompressed.toByteArray()))) { IOUtil.copy(in, rawStream); } - // tiles + if (numTiles[0] != 0) { out.writeNamedTagName("TileEntities", NBTConstants.TYPE_LIST); rawStream.write(NBTConstants.TYPE_COMPOUND); @@ -213,14 +226,12 @@ public class SpongeSchematicWriter implements ClipboardWriter { out.writeNamedEmptyList("TileEntities"); } - - // Entities - List entities = new ArrayList(); + List entities = new ArrayList<>(); for (Entity entity : clipboard.getEntities()) { BaseEntity state = entity.getState(); if (state != null) { - Map values = new HashMap(); + Map values = new HashMap<>(); // Put NBT provided data CompoundTag rawTag = state.getNbtData(); @@ -246,7 +257,7 @@ public class SpongeSchematicWriter implements ClipboardWriter { } private static Tag writeVector(Vector3 vector, String name) { - List list = new ArrayList(); + List list = new ArrayList<>(); list.add(new DoubleTag(vector.getX())); list.add(new DoubleTag(vector.getY())); list.add(new DoubleTag(vector.getZ())); @@ -254,7 +265,7 @@ public class SpongeSchematicWriter implements ClipboardWriter { } private static Tag writeRotation(Location location, String name) { - List list = new ArrayList(); + List list = new ArrayList<>(); list.add(new FloatTag(location.getYaw())); list.add(new FloatTag(location.getPitch())); return new ListTag(FloatTag.class, list); @@ -264,4 +275,4 @@ public class SpongeSchematicWriter implements ClipboardWriter { public void close() throws IOException { outputStream.close(); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/WavefrontReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/WavefrontReader.java deleted file mode 100644 index 7b9f8d167..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/WavefrontReader.java +++ /dev/null @@ -1,557 +0,0 @@ -package com.sk89q.worldedit.extent.clipboard.io; - -import com.boydti.fawe.Fawe; -import com.boydti.fawe.object.collection.SoftHashMap; -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import java.awt.image.BufferedImage; -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Consumer; -import javax.imageio.ImageIO; - -public class WavefrontReader implements ClipboardReader { - private final InputStream inputStream; - private final File root; - - private final Map textures = new SoftHashMap<>(); - private final Map> materialFiles = new HashMap<>(); - private final Map materials = new HashMap<>(); - - public WavefrontReader(File file) throws FileNotFoundException { - this.inputStream = new BufferedInputStream(new FileInputStream(file)); - File parent = file.getParentFile(); - this.root = parent == null ? new File(".") : parent; - } - - private final static double parse(String s) { - int len = s.length(); - int index; - int numIndex = 1; - - double neg; - - if (s.charAt(0) == '-') { - neg = -1; - index = 1; - } else { - index = 0; - neg = 1; - } - double val = 0; - outer: - for (; index < len; index++) { - char c = s.charAt(index); - switch (c) { - case ' ': break outer; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - val = val * 10 + (c - 48); - continue; - case '.': { - double factor = 0.1; - for (; index < len; index++) { - c = s.charAt(index); - switch (c) { - case ' ': break outer; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - val += ((c - 48) * factor); - factor *= 0.1; - } - } - } - break; - } - } - return val * neg; - } - - @Override - public Clipboard read() throws IOException { - try (InputStream finalStream = inputStream) { - load(finalStream); - } - return null; - } - - private final BufferedImage getTexture(String file) throws IOException { - BufferedImage texture = textures.get(file); - if (texture == null) { - texture = ImageIO.read(new File(root, file)); - textures.put(file, texture); - } - return texture; - } - - private void readLines(InputStream stream, Consumer onEachLine, boolean nullTerminate) throws IOException { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) { - for (String line = reader.readLine(); line != null; line = reader.readLine()) { - if (line.isEmpty() || line.charAt(0) == '#') continue; - onEachLine.accept(line); - } - if (nullTerminate) onEachLine.accept(null); - } - } - - private final int toIntColor(float color) { - return (int) (color * 256 + 0.5); - } - - private String getFileName(String arg) { - String[] pathSplit = arg.split("[/|\\\\]"); - return pathSplit[pathSplit.length - 1]; - } - - @Override - public void close() throws IOException { - - } - - private class Material { - private double dissolve = 1; - private int color = Integer.MIN_VALUE; - private String texture; - } - - private final void loadMaterials(String fileName) throws IOException { - File file = new File(root, fileName); - if (!file.exists()) { - Fawe.debug(".mtl not found: " + fileName); - return; - } - Map mtl = materialFiles.get(fileName); - if (mtl == null) { - final Map tmp = mtl = new HashMap<>(); - materialFiles.put(fileName, tmp); - readLines(new FileInputStream(file), new Consumer() { - - private String name; - private Material material; - private int index; - - private void add() { - if (material != null) { - if (material.color == Integer.MIN_VALUE) { - material.color = -1; - } - tmp.put(name, material); - material = null; - name = null; - } - } - - @Override - public void accept(String s) { - if (s == null) { - add(); - return; - } - String[] args = s.split("[ ]+"); - switch (args[0]) { - // Name - case "newmtl": { - add(); - material = new Material(); - name = args[1]; - break; - } - // Color - case "Ka": - if (material.color != Integer.MIN_VALUE) break; - case "Kd": { - float r = Float.parseFloat(args[1]); - float g = Float.parseFloat(args[2]); - float b = Float.parseFloat(args[3]); - material.color = (toIntColor(r) << 16) + (toIntColor(g) << 8) + toIntColor(b); - break; - } - // Density - case "d": { - material.dissolve = Double.parseDouble(args[1]); - break; - } - case "Tr": { - material.dissolve = 1.0 - Double.parseDouble(args[1]); - break; - } - case "map_Ka": - if (material.texture != null) break; - case "map_Kd": { - material.texture = getFileName(args[1]); - break; - } - - } - } - }, true); - } - materials.putAll(mtl); - } - - private final Material getMaterial(String name) { - Material mtl = materials.get(name); - return mtl != null ? mtl : new Material(); - } - - private void load(InputStream in) throws IOException { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { - for (String line = reader.readLine(); line != null; line = reader.readLine()) { - if (line.isEmpty()) continue; - char char0 = line.charAt(0); - switch (char0) { - case '#': continue; - case 'v': - switch (line.charAt(1)) { - case ' ': - case 'n': { - Double.parseDouble(""); - break; - } - case 't': { - - } - } - break; - case 'f': { - - break; - } - case 'l': - case 's': - case 'o': - case 'g': - // Ignore - break; - default: - String[] args = line.split(" "); - switch (args[0]) { - case "mtllib": { - String[] pathSplit = args[1].split("[/|\\\\]"); - String fileName = pathSplit[pathSplit.length - 1]; - loadMaterials(fileName); - break; - } - } - } - } - } - -// -// final File directory = file.getParentFile(); -// final Map materials = new HashMap(); -// final Map textures = new HashMap(); -// final Map colors = new HashMap(); -// final List v = new LinkedList(); -// final List vt = new LinkedList(); -// final List vn = new LinkedList(); -// final List f = new LinkedList(); -// final List obj = new LinkedList(); -// for (final String[] entry : obj) { -// if (entry[0].equals("v") || entry[0].equals("vn")) { -// if (entry.length == 1) { -// VLogger.log("[ERROR] Invalid vertex or vertex normal entry found (no data)"); -// return null; -// } -// double x; -// double y; -// double z; -// try { -// x = Double.parseDouble(entry[1]); -// y = Double.parseDouble(entry[2]); -// z = Double.parseDouble(entry[3]); -// } -// catch (NumberFormatException | ArrayIndexOutOfBoundsException ex8) { -// final RuntimeException ex5; -// final RuntimeException ex = ex5; -// VLogger.log("[ERROR] Invalid vertex or vertex normal entry found (not parseable data)"); -// return null; -// } -// if (entry[0].equals("v")) { -// if (entry.length >= 6) { -// try { -// final float r = Float.parseFloat(entry[4]); -// final float g = Float.parseFloat(entry[5]); -// final float b = Float.parseFloat(entry[6]); -// final Color c = new Color(r, g, b); -// v.add(new Vertex(x, y, z, v.size() + 1, c)); -// continue; -// } -// catch (NumberFormatException | ArrayIndexOutOfBoundsException ex9) { -// final RuntimeException ex6; -// final RuntimeException ex = ex6; -// VLogger.log("[ERROR] Invalid vertex color (not parseable data)"); -// return null; -// } -// } -// v.add(new Vertex(x, y, z, v.size() + 1)); -// } -// else { -// vn.add(new Vertex(x, y, z, vn.size() + 1)); -// } -// } -// else { -// if (!entry[0].equals("vt")) { -// continue; -// } -// if (entry.length == 1) { -// VLogger.log("[ERROR] Invalid vertex texture entry found (no data)"); -// return null; -// } -// double vt_u; -// double vt_v; -// try { -// vt_u = Double.parseDouble(entry[1]); -// vt_v = Double.parseDouble(entry[2]); -// if (vt_u < 0.0 || vt_v < 0.0 || vt_u > 1.0 || vt_v > 1.0) { -// VLogger.log("[ERROR] UV of vertex texture out of bounds"); -// return null; -// } -// } -// catch (NumberFormatException | ArrayIndexOutOfBoundsException ex10) { -// final RuntimeException ex7; -// final RuntimeException ex2 = ex7; -// VLogger.log("[ERROR] Invalid vertex texture entry found (not parseable data)"); -// return null; -// } -// vt.add(new VertexTexture(vt_u, vt_v, vn.size() + 1)); -// } -// } -// VLogger.log("[IMPORT] Loaded " + v.size() + " vertexes"); -// VLogger.log("[IMPORT] Loaded " + vt.size() + " vertex textures"); -// VLogger.log("[IMPORT] Loaded " + vn.size() + " vertex normals"); -// BufferedImage usemtl_texture = null; -// Color usemtl_color = null; -// for (final String[] entry2 : obj) { -// if (entry2[0].equals("usemtl")) { -// if (entry2.length == 1) { -// VLogger.log("[ERROR] Invalid usemtl entry"); -// return null; -// } -// SimpleMaterial material = (SimpleMaterial)materials.get(entry2[1]); -// if (material == null) { -// VLogger.log("[WARN] Material '" + entry2[1] + "' does not exist"); -// material = getFallbackMaterial(); -// VLogger.log("[WARN] Replacing with fallback material"); -// } -// usemtl_texture = material.texture; -// usemtl_color = material.color; -// VLogger.log("[IMPORT] Now using material '" + entry2[1] + "'"); -// } -// else { -// if (!entry2[0].equals("f")) { -// continue; -// } -// if (entry2.length == 1) { -// VLogger.log("[ERROR] Invalid face entry (no arguments)"); -// return null; -// } -// if (usemtl_texture == null && usemtl_color == null) { -// VLogger.log("[WARN] Current Material has neither a texture nor a color"); -// usemtl_color = Colors.getGray(1.0f); -// VLogger.log("[WARN] Using fallback color"); -// } -// final Collection points = new LinkedList(); -// for (int i = 1; i < entry2.length; ++i) { -// final String[] comp = entry2[i].split("/"); -// Integer comp_v; -// Integer comp_vt; -// Integer comp_vn; -// try { -// comp_v = Integer.parseInt(comp[0]); -// comp_vt = ((comp.length <= 1 || comp[1].isEmpty()) ? null : Integer.parseInt(comp[1])); -// comp_vn = ((comp.length <= 2 || comp[2].isEmpty()) ? null : Integer.parseInt(comp[2])); -// } -// catch (NumberFormatException ex3) { -// final StringBuilder debug = new StringBuilder(); -// String[] array; -// for (int length = (array = comp).length, j = 0; j < length; ++j) { -// final String segment = array[j]; -// debug.append(segment); -// debug.append("/"); -// } -// VLogger.log("[ERROR] Face point failed to load (" + (Object)debug + ")"); -// return null; -// } -// try { -// final FacePoint point = new FacePoint(); -// point.v = v.get((int)comp_v - 1); -// point.vt = ((comp_vt == null) ? null : ((VertexTexture)vt.get((int)comp_vt - 1))); -// point.vn = ((comp_vn == null) ? null : ((Vertex)vn.get((int)comp_vn - 1))); -// points.add(point); -// } -// catch (IndexOutOfBoundsException ex4) { -// VLogger.log("[ERROR] Face point reference to missing vertex"); -// return null; -// } -// } -// final Face face = new Face(points); -// f.add(face); -// if (usemtl_texture != null) { -// textures.put(face, usemtl_texture); -// } -// if (usemtl_color == null) { -// continue; -// } -// colors.put(face, usemtl_color); -// } -// } -// double minX = Double.MAX_VALUE; -// double minY = Double.MAX_VALUE; -// double minZ = Double.MAX_VALUE; -// double maxX = -1.7976931348623157E308; -// double maxY = -1.7976931348623157E308; -// double maxZ = -1.7976931348623157E308; -// for (final Face face2 : f) { -// for (final FacePoint point2 : face2.points) { -// final double x2 = point2.v.getX(); -// final double y2 = point2.v.getY(); -// final double z2 = point2.v.getZ(); -// if (x2 < minX) { -// minX = x2; -// } -// else if (x2 > maxX) { -// maxX = x2; -// } -// if (y2 < minY) { -// minY = y2; -// } -// else if (y2 > maxY) { -// maxY = y2; -// } -// if (z2 < minZ) { -// minZ = z2; -// } -// else { -// if (z2 <= maxZ) { -// continue; -// } -// maxZ = z2; -// } -// } -// } -// final double size = Math.max(maxX - minX, Math.max(maxY - minY, maxZ - minZ)); -// final double scale = size / (resolution - 1.0); -// final List polygons = new LinkedList(); -// for (final Face face3 : f) { -// polygons.addAll(shatterFace(face3, colors, textures)); -// } -// VLogger.log("[IMPORT] " + f.size() + " faces -> " + polygons.size() + " polygons"); -// final Map colormap = new HashMap(); -// for (final Face poly : polygons) { -// final FacePoint a = (FacePoint)poly.points.get(0); -// final FacePoint b2 = (FacePoint)poly.points.get(1); -// final FacePoint c2 = (FacePoint)poly.points.get(2); -// final Vector3D vAB = new Vector3D((Point3D)a.v, (Point3D)b2.v); -// final Vector3D vAC = new Vector3D((Point3D)a.v, (Point3D)c2.v); -// final float lAB = (float)vAB.length(); -// final float lAC = (float)vAC.length(); -// double[] array3; -// if (a.vt == null || b2.vt == null) { -// final double[] array2 = array3 = new double[2]; -// array2[1] = (array2[0] = 0.0); -// } -// else { -// final double[] array4 = array3 = new double[2]; -// array4[0] = b2.vt.u - a.vt.u; -// array4[1] = b2.vt.v - a.vt.v; -// } -// final double[] uvAB = array3; -// double[] array6; -// if (a.vt == null || c2.vt == null) { -// final double[] array5 = array6 = new double[2]; -// array5[1] = (array5[0] = 0.0); -// } -// else { -// final double[] array7 = array6 = new double[2]; -// array7[0] = c2.vt.u - a.vt.u; -// array7[1] = c2.vt.v - a.vt.v; -// } -// final double[] uvAC = array6; -// double[] array9; -// if (a.vt == null) { -// final double[] array8 = array9 = new double[2]; -// array8[1] = (array8[0] = 0.0); -// } -// else { -// final double[] array10 = array9 = new double[2]; -// array10[0] = a.vt.u; -// array10[1] = a.vt.v; -// } -// final double[] uvA = array9; -// final Vector3D i2 = vAB.clone(); -// i2.normalize(); -// i2.multiply(scale); -// final Vector3D i3 = vAC.clone(); -// i3.normalize(); -// i3.multiply(scale); -// final BufferedImage texture = (BufferedImage)textures.get(poly); -// final Color poly_color = (Color)colors.get(poly); -// final int maxW = (texture == null) ? 0 : (texture.getWidth() - 1); -// final int maxH = (texture == null) ? 0 : (texture.getHeight() - 1); -// final double l = scale / 2.0; -// for (float aloop = 0.0f; aloop < lAB; aloop += l) { -// for (float bloop = 0.0f; bloop < lAC; bloop += l) { -// final float ratio1 = aloop / lAB; -// final float ratio2 = bloop / lAC; -// if (ratio1 + ratio2 > 1.0f) { -// break; -// } -// final Point3D point3 = a.v.clone(); -// point3.add(vAB.clone().multiply((double)ratio1)); -// point3.add(vAC.clone().multiply((double)ratio2)); -// final double colorU = uvA[0] + uvAB[0] * ratio1 + uvAC[0] * ratio2; -// final double colorV = uvA[1] + uvAB[1] * ratio1 + uvAC[1] * ratio2; -// Color pointcolor = null; -// if (texture == null) { -// if (poly.hasVertexColors()) { -// final WeightedColor cA = new WeightedColor(a.v.getColor().getRGB(), 1.0f - ratio1 - ratio2); -// final WeightedColor cB = new WeightedColor(b2.v.getColor().getRGB(), ratio1); -// final WeightedColor cC = new WeightedColor(c2.v.getColor().getRGB(), ratio2); -// pointcolor = Colors.blendColors(new WeightedColor[] { cA, cB, cC }); -// } -// else { -// pointcolor = poly_color; -// } -// } -// else { -// pointcolor = new Color(texture.getRGB((int)Math.floor((double)maxW * colorU), (int)Math.floor((double)maxH - maxH * colorV)), true); -// } -// if (pointcolor.getAlpha() != 0) { -// point3.divide(scale); -// colormap.put(point3.toPositionRound(), pointcolor); -// colormap.put(point3.toPositionFloor(), pointcolor); -// } -// } -// } -// } -// VLogger.log("[IMPORT] Import complete, loaded " + f.size() + " faces"); -// VLogger.log("[IMPORT] Import complete, created " + colormap.size() + " voxels"); -// return new VoxelBox(colormap); - } - - -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/NBTCompatibilityHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/NBTCompatibilityHandler.java index ede6aaaac..88c344566 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/NBTCompatibilityHandler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/NBTCompatibilityHandler.java @@ -20,7 +20,6 @@ package com.sk89q.worldedit.extent.clipboard.io.legacycompat; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.util.Map; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/SignCompatibilityHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/SignCompatibilityHandler.java index 791b46495..ad75ed911 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/SignCompatibilityHandler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/SignCompatibilityHandler.java @@ -26,8 +26,6 @@ import com.google.gson.JsonPrimitive; import com.google.gson.JsonSyntaxException; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.world.block.BlockID; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -37,13 +35,7 @@ public class SignCompatibilityHandler implements NBTCompatibilityHandler { @Override public > boolean isAffectedBlock(B block) { - switch (block.getBlockType().getInternalId()) { - case BlockID.SIGN: - case BlockID.WALL_SIGN: - return true; - default: - return false; - } + return block.getBlockType() == BlockTypes.SIGN || block.getBlockType() == BlockTypes.WALL_SIGN; } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java index fb7d038e4..22900c012 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java @@ -19,7 +19,6 @@ package com.sk89q.worldedit.extent.inventory; -import com.boydti.fawe.object.exception.FaweException; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; @@ -27,23 +26,17 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; -import com.sk89q.worldedit.world.block.BlockTypes; -import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Applies a {@link BlockBag} to operations. */ public class BlockBagExtent extends AbstractDelegateExtent { - private final boolean mine; - private int[] missingBlocks = new int[BlockTypes.size()]; + private Map missingBlocks = new HashMap<>(); private BlockBag blockBag; /** @@ -52,15 +45,9 @@ public class BlockBagExtent extends AbstractDelegateExtent { * @param extent the extent * @param blockBag the block bag */ - public BlockBagExtent(Extent extent, @Nonnull BlockBag blockBag) { - this(extent, blockBag, false); - } - - public BlockBagExtent(Extent extent, @Nonnull BlockBag blockBag, boolean mine) { + public BlockBagExtent(Extent extent, @Nullable BlockBag blockBag) { super(extent); - checkNotNull(blockBag); this.blockBag = blockBag; - this.mine = mine; } /** @@ -88,50 +75,46 @@ public class BlockBagExtent extends AbstractDelegateExtent { * @return a map of missing blocks */ public Map popMissing() { - HashMap map = new HashMap<>(); - for (int i = 0; i < missingBlocks.length; i++) { - int count = missingBlocks[i]; - if (count > 0) { - map.put(BlockTypes.get(i), count); - } - } - Arrays.fill(missingBlocks, 0); - return map; + Map missingBlocks = this.missingBlocks; + this.missingBlocks = new HashMap<>(); + return missingBlocks; } @Override - public > boolean setBlock(BlockVector3 pos, B block) throws WorldEditException { - return setBlock(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), block); - } - - @Override - public > boolean setBlock(int x, int y, int z, B block) throws WorldEditException { + public > boolean setBlock(BlockVector3 position, B block) throws WorldEditException { if (blockBag != null) { - BlockState existing = getExtent().getBlock(BlockVector3.at(x,y,z)); + BlockState existing = getExtent().getBlock(position); if (!block.getBlockType().equals(existing.getBlockType())) { if (!block.getBlockType().getMaterial().isAir()) { try { blockBag.fetchPlacedBlock(block.toImmutableState()); } catch (UnplaceableBlockException e) { - throw new FaweException.FaweBlockBagException(); + return false; } catch (BlockBagException e) { - missingBlocks[block.getBlockType().getInternalId()]++; - throw new FaweException.FaweBlockBagException(); + if (!missingBlocks.containsKey(block.getBlockType())) { + missingBlocks.put(block.getBlockType(), 1); + } else { + missingBlocks.put(block.getBlockType(), missingBlocks.get(block.getBlockType()) + 1); + } + return false; } } - if (mine) { - if (!existing.getBlockType().getMaterial().isAir()) { - try { - blockBag.storeDroppedBlock(existing); - } catch (BlockBagException ignored) { - } + if (!existing.getBlockType().getMaterial().isAir()) { + try { + blockBag.storeDroppedBlock(existing); + } catch (BlockBagException ignored) { } } } } - return super.setBlock(x, y, z, block); + return super.setBlock(position, block); + } + + @Override + public > boolean setBlock(int x, int y, int z, B block) throws WorldEditException { + return setBlock(BlockVector3.at(x,y,z),block); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/logging/AbstractLoggingExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/logging/AbstractLoggingExtent.java deleted file mode 100644 index 83bc2a9e3..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/logging/AbstractLoggingExtent.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.extent.logging; - -import com.sk89q.worldedit.WorldEditException; - -import com.sk89q.worldedit.extent.AbstractDelegateExtent; -import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockStateHolder; - -/** - * An abstract class to implement block loggers and so on with. - */ -public abstract class AbstractLoggingExtent extends AbstractDelegateExtent { - - /** - * Create a new instance. - * - * @param extent the extent - */ - public AbstractLoggingExtent(Extent extent) { - super(extent); - } - - /** - * Called when a block is being changed. - * - * @param position the position - * @param newBlock the new block to replace the old one - */ - protected void onBlockChange(BlockVector3 position, BlockStateHolder newBlock) { - } - - @Override - public > boolean setBlock(BlockVector3 position, B block) throws WorldEditException { - onBlockChange(position, block); - return super.setBlock(position, block); - } -} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java index 1d4fe4d8d..3e1a7d4fa 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java @@ -252,4 +252,4 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder return new OperationQueue(operations); } -} \ No newline at end of file +} 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 0958c1341..043c3345f 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 @@ -21,6 +21,8 @@ package com.sk89q.worldedit.extent.transform; import com.boydti.fawe.object.extent.ResettableExtent; import com.boydti.fawe.util.ReflectionUtils; + +import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.jnbt.ByteTag; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.Tag; @@ -37,6 +39,7 @@ import com.sk89q.worldedit.registry.state.DirectionalProperty; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.PropertyKey; import com.sk89q.worldedit.util.Direction; +import static com.sk89q.worldedit.util.Direction.*; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -51,9 +54,10 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.sk89q.worldedit.util.Direction.*; - +/** + * Transforms blocks themselves (but not their position) according to a + * given transform. + */ public class BlockTransformExtent extends ResettableExtent { private Transform transform; private Transform transformInverse; @@ -81,27 +85,17 @@ public class BlockTransformExtent extends ResettableExtent { private static long combine(Direction... directions) { - long mask = 0; - for (Direction dir : directions) { - mask = mask | (1L << dir.ordinal()); - } - return mask; + return Arrays.stream(directions).mapToLong(dir -> (1L << dir.ordinal())).reduce(0, (a, b) -> a | b); } private static long[] adapt(Direction... dirs) { long[] arr = new long[dirs.length]; - for (int i = 0; i < arr.length; i++) { - arr[i] = 1L << dirs[i].ordinal(); - } + Arrays.setAll(arr, i -> 1L << dirs[i].ordinal()); return arr; } private static long[] adapt(Long... dirs) { - long[] arr = new long[dirs.length]; - for (int i = 0; i < arr.length; i++) { - arr[i] = dirs[i]; - } - return arr; + return Arrays.stream(dirs).mapToLong(dir -> dir).toArray(); } private static long[] getDirections(AbstractProperty property) { @@ -215,9 +209,7 @@ public class BlockTransformExtent extends ResettableExtent { } private static long notIndex(long mask, int... indexes) { - for (int index : indexes) { - mask = mask | (1L << (index + values().length)); - } + mask |= Arrays.stream(indexes).mapToLong(index -> (1L << (index + values().length))).reduce(0, (a, b) -> a | b); return mask; } @@ -271,7 +263,7 @@ public class BlockTransformExtent extends ResettableExtent { } if (newIndex != null) return newIndex; } - return newIndex != null ? newIndex : null; + return newIndex; } private static boolean isDirectional(Property property) { @@ -361,24 +353,6 @@ public class BlockTransformExtent extends ResettableExtent { return newMaskedId; } - /** - * @deprecated Slow - does not cache results - * @param block - * @param transform - * @param - * @return - */ - @Deprecated - public static > B transform(B block, Transform transform) { - BlockState state = block.toImmutableState(); - - int transformedId = transformState(state, transform); - BlockState transformed = BlockState.getFromInternalId(transformedId); - if (block.hasNbtData()) { - return (B) transformBaseBlockNBT(transformed, block.getNbtData(), transform); - } - return (B) (block instanceof BaseBlock ? transformed.toBaseBlock() : transformed); - } private void cache() { BLOCK_ROTATION_BITMASK = new int[BlockTypes.size()]; @@ -407,16 +381,58 @@ public class BlockTransformExtent extends ResettableExtent { return super.setExtent(extent); } + /** + * Get the transform. + * + * @return the transform + */ public Transform getTransform() { return transform; } + @Override + public BlockState getBlock(BlockVector3 position) { + return transform(super.getBlock(position)); + } + + @Override + public BaseBlock getFullBlock(BlockVector3 position) { + return transform(super.getFullBlock(position)); + } + + @Override + public > boolean setBlock(BlockVector3 location, B block) throws WorldEditException { + return super.setBlock(location, transformInverse(block)); + } + public void setTransform(Transform affine) { this.transform = affine; this.transformInverse = this.transform.inverse(); cache(); } + /** + * Transform the given block using the given transform. + * + *

The provided block is not modified.

+ * + * @param block the block + * @param transform the transform + * @return the same block + */ + public static > B transform(B block, Transform transform) { + checkNotNull(block); + checkNotNull(transform); + BlockState state = block.toImmutableState(); + + int transformedId = transformState(state, transform); + BlockState transformed = BlockState.getFromInternalId(transformedId); + if (block.hasNbtData()) { + return (B) transformBaseBlockNBT(transformed, block.getNbtData(), transform); + } + return (B) (block instanceof BaseBlock ? transformed.toBaseBlock() : transformed); + } + private BlockState transform(BlockState state, int[][] transformArray, Transform transform) { int typeId = state.getInternalBlockTypeId(); int[] arr = transformArray[typeId]; @@ -450,7 +466,7 @@ public class BlockTransformExtent extends ResettableExtent { return transformed.toBaseBlock(); } - public final BlockStateHolder transformInverse(BlockStateHolder block) { + protected final BlockStateHolder transformInverse(BlockStateHolder block) { BlockState transformed = transformInverse(block.toImmutableState()); if (block.hasNbtData()) { return transformBaseBlockNBT(transformed, block.getNbtData(), transformInverse); @@ -462,7 +478,7 @@ public class BlockTransformExtent extends ResettableExtent { return transform(block, BLOCK_TRANSFORM, transform); } - public final BlockState transformInverse(BlockState block) { + private BlockState transformInverse(BlockState block) { return transform(block, BLOCK_TRANSFORM_INVERSE, transformInverse); } @@ -471,21 +487,11 @@ public class BlockTransformExtent extends ResettableExtent { return transform(super.getLazyBlock(x, y, z)); } - @Override - public BaseBlock getFullBlock(BlockVector3 position) { - return transform(super.getFullBlock(position)); - } - @Override public BlockState getLazyBlock(BlockVector3 position) { return transform(super.getLazyBlock(position)); } - @Override - public BlockState getBlock(BlockVector3 position) { - return transform(super.getBlock(position)); - } - @Override public BiomeType getBiome(BlockVector2 position) { return super.getBiome(position); @@ -497,10 +503,5 @@ public class BlockTransformExtent extends ResettableExtent { } - @Override - public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { - return super.setBlock(location, transformInverse(block)); - } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java index dad5848f8..ddc92cec0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java @@ -60,7 +60,6 @@ public class BlockMask extends AbstractExtentMask { * @param extent the extent * @param blocks a list of blocks to match */ - @Deprecated public BlockMask(Extent extent, Collection blocks) { super(extent); checkNotNull(blocks); @@ -73,7 +72,6 @@ public class BlockMask extends AbstractExtentMask { * @param extent the extent * @param block an array of blocks to match */ - @Deprecated public BlockMask(Extent extent, BaseBlock... block) { super(extent); checkNotNull(block); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockTypeMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockTypeMask.java index 2bb4cf68c..91f8c6fbf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockTypeMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockTypeMask.java @@ -20,6 +20,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockType; @@ -39,19 +40,9 @@ import java.util.Set; * use {@link BlockMask}.

*/ public class BlockTypeMask extends AbstractExtentMask { + private final boolean[] types; - protected BlockTypeMask(Extent extent, boolean[] types) { - super(extent); - this.types = types; - } - - public BlockTypeMask(Extent extent, BlockType... types) { - super(extent); - this.types = new boolean[BlockTypes.size()]; - for (BlockType type : types) this.types[type.getInternalId()] = true; - } - /** * Create a new block mask. * @@ -59,7 +50,24 @@ public class BlockTypeMask extends AbstractExtentMask { * @param blocks a list of blocks to match */ public BlockTypeMask(Extent extent, Collection blocks) { - this(extent, blocks.toArray(new BlockType[blocks.size()])); + this(extent, blocks.toArray(new BlockType[0])); + } + + /** + * Create a new block mask. + * + * @param extent the extent + * @param block an array of blocks to match + */ + public BlockTypeMask(Extent extent, BlockType... block) { + super(extent); + this.types = new boolean[BlockTypes.size()]; + for (BlockType type : block) this.types[type.getInternalId()] = true; + } + + protected BlockTypeMask(Extent extent, boolean[] types) { + super(extent); + this.types = types; } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java index 38b3783b1..1283b0bb2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java @@ -25,9 +25,6 @@ import com.sk89q.worldedit.math.BlockVector3; import javax.annotation.Nullable; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.sk89q.worldedit.function.mask.Masks.negate; - /** * Tests whether a given vector meets a criteria. */ diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java index c1e1f0623..051f904f8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java @@ -104,7 +104,8 @@ public class MaskIntersection extends AbstractMask { Set optimized = new HashSet<>(); Set> failedCombines = new HashSet<>(); // Combine the masks - while (combine(pairingFunction(), failedCombines)); + while (combine(pairingFunction(), failedCombines)) { + } // Optimize / combine do optimizeMasks(optimized); while (combine(pairingFunction(), failedCombines)); @@ -122,7 +123,7 @@ public class MaskIntersection extends AbstractMask { outer: for (Mask mask : masks) { for (Mask other : masks) { - AbstractMap.SimpleEntry pair = new AbstractMap.SimpleEntry(mask, other); + AbstractMap.SimpleEntry pair = new AbstractMap.SimpleEntry<>(mask, other); if (failedCombines.contains(pair)) continue; Mask combined = pairing.apply(pair); if (combined != null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java index eace7259c..3023c62ce 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java @@ -16,6 +16,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ + package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockStateMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockStateMask.java index e8514dafc..ea5fd15b3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockStateMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockStateMask.java @@ -2,7 +2,6 @@ package com.sk89q.worldedit.function.mask; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; public class SingleBlockStateMask extends AbstractExtentMask { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockTypeMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockTypeMask.java index 2f26b1aed..a16c0109a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockTypeMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockTypeMask.java @@ -2,7 +2,6 @@ package com.sk89q.worldedit.function.mask; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/BackwardsExtentBlockCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/BackwardsExtentBlockCopy.java index 464c892ba..28bd3a04a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/BackwardsExtentBlockCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/BackwardsExtentBlockCopy.java @@ -1,29 +1,25 @@ package com.sk89q.worldedit.function.operation; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; + import java.util.List; public class BackwardsExtentBlockCopy implements Operation { private final Region region; private final Transform transform; - private final Extent destination; - private final Extent source; private final RegionFunction function; private final BlockVector3 origin; // private Vector mutable = new MutableBlockVector3(); - public BackwardsExtentBlockCopy(Extent source, Region region, Extent destination, BlockVector3 origin, Transform transform, RegionFunction function) { - this.source = source; + BackwardsExtentBlockCopy(Region region, BlockVector3 origin, Transform transform, RegionFunction function) { this.region = region; - this.destination = destination; this.transform = transform; this.function = function; this.origin = origin; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java index 5f62a6f8d..8836187b6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java @@ -299,7 +299,7 @@ public class ForwardExtentCopy implements Operation { if (copyBiomes && (!(source instanceof BlockArrayClipboard) || ((BlockArrayClipboard) source).IMP.hasBiomes())) { copy = CombinedRegionFunction.combine(copy, new BiomeCopy(source, finalDest)); } - blockCopy = new BackwardsExtentBlockCopy(transExt, region, finalDest, from, transform, copy); + blockCopy = new BackwardsExtentBlockCopy(region, from, transform, copy); } else { transExt = new PositionTransformExtent(finalDest, currentTransform); transExt.setOrigin(from); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/FawePattern.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/FawePattern.java index 8a797f5cd..8edd7942c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/FawePattern.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/FawePattern.java @@ -4,11 +4,9 @@ import com.sk89q.minecraft.util.commands.Link; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.command.UtilityCommands; import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.extent.NullExtent; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockStateHolder; /** * Returns a {@link BlockStateHolder} for a given position. @@ -29,4 +27,4 @@ public interface FawePattern extends Pattern { */ @Override boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException; -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java index d20eb733d..e20007841 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java @@ -20,8 +20,7 @@ package com.sk89q.worldedit.function.visitor; import com.boydti.fawe.object.HasFaweQueue; -import com.sk89q.worldedit.function.RegionFunction; -import com.sk89q.worldedit.function.mask.Mask; + import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.function.RegionFunction; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/EntityCreate.java b/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/EntityCreate.java index 8aeecfbeb..583887f19 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/EntityCreate.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/EntityCreate.java @@ -19,14 +19,14 @@ package com.sk89q.worldedit.history.change; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.history.UndoContext; import com.sk89q.worldedit.util.Location; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Logs the creation of an entity and removes the entity upon undo. */ diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/EntityRemove.java b/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/EntityRemove.java index 08b1ea21c..076023794 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/EntityRemove.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/EntityRemove.java @@ -19,14 +19,14 @@ package com.sk89q.worldedit.history.change; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.history.UndoContext; import com.sk89q.worldedit.util.Location; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Tracks the removal of an entity. */ diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ArrayListHistory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ArrayListHistory.java index ec06c27b5..d014835d3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ArrayListHistory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ArrayListHistory.java @@ -70,4 +70,4 @@ public class ArrayListHistory implements ChangeSet { return changes.size(); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ChangeSet.java b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ChangeSet.java index 24c4c3fe0..003a007b6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ChangeSet.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ChangeSet.java @@ -77,4 +77,4 @@ public interface ChangeSet { */ int size(); -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java index ed65dc8fb..63945769e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java @@ -70,7 +70,7 @@ public class CommandLoggingHandler extends AbstractInvokeListener implements Inv Logging loggingAnnotation = method.getAnnotation(Logging.class); Logging.LogMode logMode; StringBuilder builder = new StringBuilder(); - + if (loggingAnnotation == null) { logMode = null; } else { @@ -96,15 +96,15 @@ public class CommandLoggingHandler extends AbstractInvokeListener implements Inv } builder.append(": ").append(context.getCommand()); - + if (context.argsLength() > 0) { builder.append(" ").append(context.getJoinedStrings(0)); } - + if (logMode != null && sender.isPlayer()) { - Vector3 position = player.getLocation(); + Vector3 position = player.getLocation().toVector(); LocalSession session = worldEdit.getSessionManager().get(player); - + switch (logMode) { case PLACEMENT: try { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java index 061bfab72..2656039ce 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java @@ -20,6 +20,7 @@ package com.sk89q.worldedit.internal.command; import com.boydti.fawe.util.MathMan; + import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; @@ -36,14 +37,12 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.internal.annotation.Direction; -import com.sk89q.worldedit.internal.annotation.Selection; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.TreeGenerator.TreeType; import com.sk89q.worldedit.util.command.parametric.ArgumentStack; import com.sk89q.worldedit.util.command.parametric.BindingBehavior; -import com.sk89q.worldedit.util.command.parametric.BindingHelper; import com.sk89q.worldedit.util.command.parametric.BindingMatch; import com.sk89q.worldedit.util.command.parametric.ParameterException; import com.sk89q.worldedit.world.World; @@ -99,7 +98,7 @@ public class WorldEditBinding { * @throws ParameterException on other error */ @BindingMatch(type = EditSession.class, - behavior = BindingBehavior.PROVIDES) + behavior = BindingBehavior.PROVIDES) public EditSession getEditSession(ArgumentStack context) throws ParameterException { Player sender = getPlayer(context); LocalSession session = worldEdit.getSessionManager().get(sender); @@ -118,7 +117,7 @@ public class WorldEditBinding { * @throws ParameterException on error */ @BindingMatch(type = LocalSession.class, - behavior = BindingBehavior.PROVIDES) + behavior = BindingBehavior.PROVIDES) public LocalSession getLocalSession(ArgumentStack context) throws ParameterException { Player sender = getPlayer(context); return worldEdit.getSessionManager().get(sender); @@ -150,7 +149,7 @@ public class WorldEditBinding { * @throws ParameterException on error */ @BindingMatch(type = Player.class, - behavior = BindingBehavior.PROVIDES) + behavior = BindingBehavior.PROVIDES) public Player getPlayer(ArgumentStack context) throws ParameterException { Actor sender = context.getContext().getLocals().get(Actor.class); if (sender == null) { @@ -166,7 +165,7 @@ public class WorldEditBinding { * Gets an {@link BaseBlock} from a {@link ArgumentStack}. * * @param context the context - * @return a block state + * @return a pattern * @throws ParameterException on error * @throws WorldEditException on error */ @@ -200,8 +199,8 @@ public class WorldEditBinding { } @BindingMatch(type = {BaseBlock.class, BlockState.class, BlockStateHolder.class}, - behavior = BindingBehavior.CONSUMES, - consumedCount = 1) + behavior = BindingBehavior.CONSUMES, + consumedCount = 1) public BaseBlock getBaseBlock(ArgumentStack context) throws ParameterException, WorldEditException { return getBlockState(context).toBaseBlock(); } @@ -244,8 +243,8 @@ public class WorldEditBinding { * @throws WorldEditException on error */ @BindingMatch(type = Pattern.class, - behavior = BindingBehavior.CONSUMES, - consumedCount = 1) + behavior = BindingBehavior.CONSUMES, + consumedCount = 1) public Pattern getPattern(ArgumentStack context) throws ParameterException, WorldEditException { Actor actor = context.getContext().getLocals().get(Actor.class); ParserContext parserContext = new ParserContext(); @@ -273,8 +272,8 @@ public class WorldEditBinding { * @throws WorldEditException on error */ @BindingMatch(type = Mask.class, - behavior = BindingBehavior.CONSUMES, - consumedCount = 1) + behavior = BindingBehavior.CONSUMES, + consumedCount = 1) public Mask getMask(ArgumentStack context) throws ParameterException, WorldEditException { Actor actor = context.getContext().getLocals().get(Actor.class); ParserContext parserContext = new ParserContext(); @@ -377,6 +376,4 @@ public class WorldEditBinding { } } - - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java index 3237eb686..85b401c09 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java @@ -45,22 +45,22 @@ import java.util.concurrent.TimeoutException; /** * Compiles and evaluates expressions. - *

+ * *

Supported operators:

- *

+ * *

    - *
  • Logical: &&, ||, ! (unary)
  • - *
  • Bitwise: ~ (unary), >>, <<
  • - *
  • Arithmetic: +, -, *, /, % (modulo), ^ (power), - (unary), --, ++ (prefix only)
  • - *
  • Comparison: <=, >=, >, <, ==, !=, ~= (near)
  • + *
  • Logical: &&, ||, ! (unary)
  • + *
  • Bitwise: ~ (unary), >>, <<
  • + *
  • Arithmetic: +, -, *, /, % (modulo), ^ (power), - (unary), --, ++ (prefix only)
  • + *
  • Comparison: <=, >=, >, <, ==, !=, ~= (near)
  • *
- *

+ * *

Supported functions: abs, acos, asin, atan, atan2, cbrt, ceil, cos, cosh, * exp, floor, ln, log, log10, max, max, min, min, rint, round, sin, sinh, * sqrt, tan, tanh and more. (See the Functions class or the wiki)

- *

+ * *

Constants: e, pi

- *

+ * *

To compile an equation, run * {@code Expression.compile("expression here", "var1", "var2"...)}. * If you wish to run the equation multiple times, you can then optimize it, @@ -70,7 +70,7 @@ import java.util.concurrent.TimeoutException; * To query variables after evaluation, you can use * {@link #getVariable(String, boolean)}. To get a value out of these, use * {@link Variable#getValue()}.

- *

+ * *

Variables are also supported and can be set either by passing values * to {@link #evaluate(double...)}.

*/ @@ -146,6 +146,7 @@ public class Expression { ((Variable) invokable).value = values[i]; } + try { if (timeout < 0) { return evaluateRoot(); @@ -236,6 +237,4 @@ public class Expression { this.environment = environment; } - - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/For.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/For.java index e660daacd..6334a7350 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/For.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/For.java @@ -1,9 +1,32 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + package com.sk89q.worldedit.internal.expression.runtime; import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.parser.ParserException; +/** + * A Java/C-style for loop. + */ public class For extends Node { + RValue init; RValue condition; RValue increment; @@ -11,34 +34,35 @@ public class For extends Node { public For(int position, RValue init, RValue condition, RValue increment, RValue body) { super(position); + this.init = init; this.condition = condition; this.increment = increment; this.body = body; } + @Override public double getValue() throws EvaluationException { - int iterations = 0; - double ret = 0.0D; - this.init.getValue(); + double ret = 0.0; - for(; this.condition.getValue() > 0.0D; this.increment.getValue()) { - - if(iterations > 256) { - throw new EvaluationException(this.getPosition(), "Loop exceeded 256 iterations."); + for (init.getValue(); condition.getValue() > 0; increment.getValue()) { + if (iterations > 256) { + throw new EvaluationException(getPosition(), "Loop exceeded 256 iterations."); } - - if(Thread.interrupted()){ - throw new EvaluationException(this.getPosition(), "Thread has been interrupted."); + if (Thread.interrupted()) { + throw new EvaluationException(getPosition(), "Calculations exceeded time limit."); } ++iterations; try { - ret = this.body.getValue(); - } catch (BreakException var5) { - if(!var5.doContinue) { - return ret; + ret = body.getValue(); + } catch (BreakException e) { + if (e.doContinue) { + //noinspection UnnecessaryContinue + continue; + } else { + break; } } } @@ -46,30 +70,38 @@ public class For extends Node { return ret; } + @Override public char id() { return 'F'; } + @Override public String toString() { - return "for (" + this.init + "; " + this.condition + "; " + this.increment + ") { " + this.body + " }"; + return "for (" + init + "; " + condition + "; " + increment + ") { " + body + " }"; } + @Override public RValue optimize() throws EvaluationException { final RValue newCondition = condition.optimize(); + if (newCondition instanceof Constant && newCondition.getValue() <= 0) { // If the condition is always false, the loop can be flattened. // So we run the init part and then return 0.0. return new Sequence(getPosition(), init, new Constant(getPosition(), 0.0)).optimize(); } + + //return new Sequence(getPosition(), init.optimize(), new While(getPosition(), condition, new Sequence(getPosition(), body, increment), false)).optimize(); return new For(getPosition(), init.optimize(), newCondition, increment.optimize(), body.optimize()); } + @Override public RValue bindVariables(Expression expression, boolean preferLValue) throws ParserException { - this.init = this.init.bindVariables(expression, false); - this.condition = this.condition.bindVariables(expression, false); - this.increment = this.increment.bindVariables(expression, false); - this.body = this.body.bindVariables(expression, false); + init = init.bindVariables(expression, false); + condition = condition.bindVariables(expression, false); + increment = increment.bindVariables(expression, false); + body = body.bindVariables(expression, false); + return this; } -} +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Function.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Function.java index f2d9090e0..f94eba3cd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Function.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Function.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.internal.expression.runtime; import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.parser.ParserException; + import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.reflect.InvocationTargetException; @@ -36,8 +37,7 @@ public class Function extends Node { * for the same inputs and on functions with side-effects. */ @Retention(RetentionPolicy.RUNTIME) - public @interface Dynamic { - } + public @interface Dynamic { } public final Method method; public final RValue[] args; @@ -121,5 +121,4 @@ public class Function extends Node { return this; } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Functions.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Functions.java index 088cef4c2..d2aede416 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Functions.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Functions.java @@ -19,14 +19,13 @@ package com.sk89q.worldedit.internal.expression.runtime; - -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.runtime.Function.Dynamic; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.noise.PerlinNoise; import com.sk89q.worldedit.math.noise.RidgedMultiFractalNoise; import com.sk89q.worldedit.math.noise.VoronoiNoise; + import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; @@ -125,13 +124,11 @@ public final class Functions { } private static final Map> functions = new HashMap<>(); - static { for (Method method : Functions.class.getMethods()) { try { addFunction(method); - } catch (IllegalArgumentException ignored) { - } + } catch (IllegalArgumentException ignored) { } } } @@ -141,10 +138,7 @@ public final class Functions { Overload overload = new Overload(method); - List overloads = functions.get(methodName); - if (overloads == null) { - functions.put(methodName, overloads = new ArrayList<>()); - } + List overloads = functions.computeIfAbsent(methodName, k -> new ArrayList<>()); overloads.add(overload); } @@ -256,6 +250,7 @@ public final class Functions { return Math.log10(x.getValue()); } + public static double rotate(LValue x, LValue y, RValue angle) throws EvaluationException { final double f = angle.getValue(); @@ -327,26 +322,26 @@ public final class Functions { @Dynamic public static double closest(RValue x, RValue y, RValue z, RValue index, RValue count, RValue stride) throws EvaluationException { return findClosest( - Expression.getInstance().getFunctions().megabuf, - x.getValue(), - y.getValue(), - z.getValue(), - (int) index.getValue(), - (int) count.getValue(), - (int) stride.getValue() + Expression.getInstance().getFunctions().megabuf, + x.getValue(), + y.getValue(), + z.getValue(), + (int) index.getValue(), + (int) count.getValue(), + (int) stride.getValue() ); } @Dynamic public static double gclosest(RValue x, RValue y, RValue z, RValue index, RValue count, RValue stride) throws EvaluationException { return findClosest( - gmegabuf, - x.getValue(), - y.getValue(), - z.getValue(), - (int) index.getValue(), - (int) count.getValue(), - (int) stride.getValue() + gmegabuf, + x.getValue(), + y.getValue(), + z.getValue(), + (int) index.getValue(), + (int) count.getValue(), + (int) stride.getValue() ); } @@ -355,11 +350,11 @@ public final class Functions { double minDistanceSquared = Double.MAX_VALUE; for (int i = 0; i < count; ++i) { - double currentX = getBufferItem(megabuf, index + 0) - x; - double currentY = getBufferItem(megabuf, index + 1) - y; - double currentZ = getBufferItem(megabuf, index + 2) - z; + double currentX = getBufferItem(megabuf, index+0) - x; + double currentY = getBufferItem(megabuf, index+1) - y; + double currentZ = getBufferItem(megabuf, index+2) - z; - double currentDistanceSquared = currentX * currentX + currentY * currentY + currentZ * currentZ; + double currentDistanceSquared = currentX*currentX + currentY*currentY + currentZ*currentZ; if (currentDistanceSquared < minDistanceSquared) { minDistanceSquared = currentDistanceSquared; @@ -489,5 +484,4 @@ public final class Functions { return queryInternal(type, data, typeId, dataValue); } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/registry/InputParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/registry/InputParser.java index c96a1d183..575bb9550 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/registry/InputParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/registry/InputParser.java @@ -19,7 +19,6 @@ package com.sk89q.worldedit.internal.registry; -import com.google.common.collect.Lists; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.ParserContext; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/MathUtils.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MathUtils.java index f0f7b67fb..3a2e3af39 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/MathUtils.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MathUtils.java @@ -117,34 +117,4 @@ public final class MathUtils { public static double roundHalfUp(double value) { return Math.signum(value) * Math.round(Math.abs(value)); } - - /** - * Returns the midpoint Vector3 of the two given Vector3's. - * - * @param first Vector3 - * @param second Vector3 - * @return midpoint Vector3 - */ - public static Vector3 midpoint(Vector3 v1, Vector3 v2) { - return Vector3.at( - (v1.getX() + v2.getX()) / 2, - (v1.getY() + v2.getY()) / 2, - (v1.getZ() + v2.getZ()) / 2 - ); - } - - /** - * Returns the midpoint BlockVector3 of the two given BlockVector3's. - * - * @param first BlockVector3 - * @param second BlockVector3 - * @return midpoint BlockVector3 - */ - public static BlockVector3 midpoint(BlockVector3 v1, BlockVector3 v2) { - return BlockVector3.at( - (v1.getBlockX() + v2.getBlockX()) / 2, - (v1.getBlockY() + v2.getBlockY()) / 2, - (v1.getBlockZ() + v2.getBlockZ()) / 2 - ); - } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableBlockVector2.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableBlockVector2.java index 13bcb5cd4..bc71607c2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableBlockVector2.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableBlockVector2.java @@ -2,12 +2,7 @@ package com.sk89q.worldedit.math; public class MutableBlockVector2 extends BlockVector2 { - private static ThreadLocal MUTABLE_CACHE = new ThreadLocal() { - @Override - protected MutableBlockVector2 initialValue() { - return new MutableBlockVector2(); - } - }; + private static ThreadLocal MUTABLE_CACHE = ThreadLocal.withInitial(() -> new MutableBlockVector2()); public static MutableBlockVector2 get(int x, int z) { return MUTABLE_CACHE.get().setComponents(x, z); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableBlockVector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableBlockVector3.java index 89ee154f5..88eb28a71 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableBlockVector3.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableBlockVector3.java @@ -2,12 +2,7 @@ package com.sk89q.worldedit.math; public class MutableBlockVector3 extends BlockVector3 { - private static ThreadLocal MUTABLE_CACHE = new ThreadLocal() { - @Override - protected MutableBlockVector3 initialValue() { - return new MutableBlockVector3(); - } - }; + private static ThreadLocal MUTABLE_CACHE = ThreadLocal.withInitial(() -> new MutableBlockVector3()); public static MutableBlockVector3 get(int x, int y, int z) { return MUTABLE_CACHE.get().setComponents(x, y, z); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableVector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableVector3.java index e1810a4b6..27edc3437 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableVector3.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableVector3.java @@ -1,7 +1,5 @@ package com.sk89q.worldedit.math; -import javax.annotation.Nullable; - public class MutableVector3 extends Vector3 { public MutableVector3() {} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java index d6ace915e..83399b20a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java @@ -20,6 +20,8 @@ package com.sk89q.worldedit.math.convolution; import com.boydti.fawe.object.visitor.Fast2DIterator; + +import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.function.mask.Mask; @@ -34,8 +36,6 @@ import com.sk89q.worldedit.world.block.BlockTypes; import java.util.Iterator; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Allows applications of Kernels onto the region's height map. * @@ -167,7 +167,6 @@ public class HeightMap { BlockVector3 minY = region.getMinimumPoint(); int originX = minY.getBlockX(); - int originY = minY.getBlockY(); int originZ = minY.getBlockZ(); int maxY = region.getMaximumPoint().getBlockY(); @@ -177,10 +176,10 @@ public class HeightMap { BlockStateHolder tmpBlock = BlockTypes.AIR.getDefaultState(); - // Apply heightmap int maxY4 = maxY << 4; int index = 0; + // Apply heightmap for (int z = 0; z < height; ++z) { int zr = z + originZ; for (int x = 0; x < width; ++x) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/KochanekBartelsInterpolation.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/KochanekBartelsInterpolation.java index b5447ed5e..772e18616 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/KochanekBartelsInterpolation.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/KochanekBartelsInterpolation.java @@ -22,21 +22,17 @@ package com.sk89q.worldedit.math.interpolation; import static com.google.common.base.Preconditions.checkNotNull; - import com.sk89q.worldedit.math.MutableBlockVector3; import com.sk89q.worldedit.math.Vector3; import java.util.Collections; import java.util.List; - -import static com.google.common.base.Preconditions.checkNotNull; - /** * A Kochanek-Bartels interpolation; continuous in the 2nd derivative. - *

- *

Supports {@link Node#tension tension}, {@link Node#bias bias} and - * {@link Node#continuity continuity} parameters per {@link Node}.

+ * + *

Supports Node#tension tension, Node#bias bias and + * Node#continuity continuity parameters per {@link Node}.

*/ public class KochanekBartelsInterpolation implements Interpolation { @@ -48,7 +44,7 @@ public class KochanekBartelsInterpolation implements Interpolation { private double scaling; public KochanekBartelsInterpolation() { - setNodes(Collections.emptyList()); + setNodes(Collections.emptyList()); } @Override @@ -86,14 +82,14 @@ public class KochanekBartelsInterpolation implements Interpolation { } // Kochanek-Bartels tangent coefficients - final double ta = (1 - tensionA) * (1 + biasA) * (1 + continuityA) / 2; // Factor for lhs of d[i] - final double tb = (1 - tensionA) * (1 - biasA) * (1 - continuityA) / 2; // Factor for rhs of d[i] - final double tc = (1 - tensionB) * (1 + biasB) * (1 - continuityB) / 2; // Factor for lhs of d[i+1] - final double td = (1 - tensionB) * (1 - biasB) * (1 + continuityB) / 2; // Factor for rhs of d[i+1] + final double ta = (1-tensionA)*(1+biasA)*(1+continuityA)/2; // Factor for lhs of d[i] + final double tb = (1-tensionA)*(1-biasA)*(1-continuityA)/2; // Factor for rhs of d[i] + final double tc = (1-tensionB)*(1+biasB)*(1-continuityB)/2; // Factor for lhs of d[i+1] + final double td = (1-tensionB)*(1-biasB)*(1+continuityB)/2; // Factor for rhs of d[i+1] - coeffA[i] = linearCombination(i, -ta, ta - tb - tc + 2, tb + tc - td - 2, td); - coeffB[i] = linearCombination(i, 2 * ta, -2 * ta + 2 * tb + tc - 3, -2 * tb - tc + td + 3, -td); - coeffC[i] = linearCombination(i, -ta, ta - tb, tb, 0); + coeffA[i] = linearCombination(i, -ta, ta- tb-tc+2, tb+tc-td-2, td); + coeffB[i] = linearCombination(i, 2*ta, -2*ta+2*tb+tc-3, -2*tb-tc+td+3, -td); + coeffC[i] = linearCombination(i, -ta, ta- tb , tb , 0); //coeffD[i] = linearCombination(i, 0, 1, 0, 0); coeffD[i] = retrieve(i); // this is an optimization } @@ -105,10 +101,10 @@ public class KochanekBartelsInterpolation implements Interpolation { * Returns the linear combination of the given coefficients with the nodes adjacent to baseIndex. * * @param baseIndex node index - * @param f1 coefficient for baseIndex-1 - * @param f2 coefficient for baseIndex - * @param f3 coefficient for baseIndex+1 - * @param f4 coefficient for baseIndex+2 + * @param f1 coefficient for baseIndex-1 + * @param f2 coefficient for baseIndex + * @param f3 coefficient for baseIndex+1 + * @param f4 coefficient for baseIndex+2 * @return linear combination of nodes[n-1..n+2] with f1..4 */ private Vector3 linearCombination(int baseIndex, double f1, double f2, double f3, double f4) { @@ -116,6 +112,7 @@ public class KochanekBartelsInterpolation implements Interpolation { final Vector3 r2 = retrieve(baseIndex ).multiply(f2); final Vector3 r3 = retrieve(baseIndex + 1).multiply(f3); final Vector3 r4 = retrieve(baseIndex + 2).multiply(f4); + return r1.add(r2).add(r3).add(r4); } @@ -130,7 +127,7 @@ public class KochanekBartelsInterpolation implements Interpolation { return fastRetrieve(0); if (index >= nodes.size()) - return fastRetrieve(nodes.size() - 1); + return fastRetrieve(nodes.size()-1); return fastRetrieve(index); } @@ -184,7 +181,7 @@ public class KochanekBartelsInterpolation implements Interpolation { final Vector3 b = coeffB[index]; final Vector3 c = coeffC[index]; - return a.multiply(1.5 * position - 3.0 * index).add(b).multiply(2.0 * position).add(a.multiply(1.5 * index).subtract(b).multiply(2.0 * index)).add(c).multiply(scaling); + return a.multiply(1.5*position - 3.0*index).add(b).multiply(2.0*position).add(a.multiply(1.5*index).subtract(b).multiply(2.0*index)).add(c).multiply(scaling); } @Override @@ -212,19 +209,19 @@ public class KochanekBartelsInterpolation implements Interpolation { */ private double arcLengthRecursive(int indexLeft, double remainderLeft, int indexRight, double remainderRight) { switch (indexRight - indexLeft) { - case 0: - return arcLengthRecursive(indexLeft, remainderLeft, remainderRight); + case 0: + return arcLengthRecursive(indexLeft, remainderLeft, remainderRight); - case 1: - // This case is merely a speed-up for a very common case - return - arcLengthRecursive(indexLeft, remainderLeft, 1.0) + - arcLengthRecursive(indexRight, 0.0, remainderRight); + case 1: + // This case is merely a speed-up for a very common case + return + arcLengthRecursive(indexLeft, remainderLeft, 1.0) + + arcLengthRecursive(indexRight, 0.0, remainderRight); - default: - return - arcLengthRecursive(indexLeft, remainderLeft, indexRight - 1, 1.0) + - arcLengthRecursive(indexRight, 0.0, remainderRight); + default: + return + arcLengthRecursive(indexLeft, remainderLeft, indexRight - 1, 1.0) + + arcLengthRecursive(indexRight, 0.0, remainderRight); } } @@ -236,9 +233,9 @@ public class KochanekBartelsInterpolation implements Interpolation { final int nPoints = 8; double accum = a.multiply(remainderLeft).add(b).multiply(remainderLeft).add(c).length() / 2.0; - for (int i = 1; i < nPoints - 1; ++i) { + for (int i = 1; i < nPoints-1; ++i) { double t = ((double) i) / nPoints; - t = (remainderRight - remainderLeft) * t + remainderLeft; + t = (remainderRight-remainderLeft)*t + remainderLeft; accum += a.multiply(t).add(b).multiply(t).add(c).length(); } @@ -259,5 +256,4 @@ public class KochanekBartelsInterpolation implements Interpolation { return (int) Math.floor(position); } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Node.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Node.java index c29190b77..3a020653e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Node.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Node.java @@ -38,7 +38,7 @@ public class Node { private double continuity; public Node() { - this(Vector3.at(0, 0, 0)); + this(Vector3.ZERO); } public Node(Node other) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java index d51436598..b4810b98c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java @@ -1,17 +1,34 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + package com.sk89q.worldedit.math.transform; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MathUtils; +import com.sk89q.worldedit.math.Vector3; + import java.io.IOException; import java.io.Serializable; -import com.sk89q.worldedit.math.MutableBlockVector3; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.math.MathUtils; -import com.sk89q.worldedit.math.MutableVector3; -import com.sk89q.worldedit.math.Vector3; - /** * An affine transform. - *

+ * *

This class is from the * JavaGeom project, * which is licensed under LGPL v2.1.

@@ -153,7 +170,7 @@ public class AffineTransform implements Transform, Serializable { * * @return the determinant of the transform. */ - public double determinant() { + private double determinant() { return m00 * (m11 * m22 - m12 * m21) - m01 * (m10 * m22 - m20 * m12) + m02 * (m10 * m21 - m20 * m11); } @@ -336,4 +353,4 @@ public class AffineTransform implements Transform, Serializable { } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/RoundedTransform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/RoundedTransform.java index 7ba7abb25..91d347f7c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/RoundedTransform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/RoundedTransform.java @@ -1,11 +1,9 @@ package com.sk89q.worldedit.math.transform; -import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; public class RoundedTransform implements Transform{ private final Transform transform; -// private MutableBlockVector3 mutable = new MutableBlockVector3(); public RoundedTransform(Transform transform) { this.transform = transform; @@ -19,9 +17,6 @@ public class RoundedTransform implements Transform{ @Override public Vector3 apply(Vector3 input) { Vector3 val = transform.apply(input); -// mutable.mutX((int) Math.floor(val.getX() + 0.5)); -// mutable.mutY((int) Math.floor(val.getY() + 0.5)); -// mutable.mutZ((int) Math.floor(val.getZ() + 0.5)); return Vector3.at(Math.floor(val.getX() + 0.5), Math.floor(val.getY() + 0.5), Math.floor(val.getY() + 0.5)); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Transforms.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Transforms.java index 828f8b7ea..5d0412259 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Transforms.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Transforms.java @@ -43,7 +43,7 @@ public final class Transforms { public static Location transform(Location location, Transform transform) { checkNotNull(location); checkNotNull(transform); - return new Location(location.getExtent(), transform.apply(location), location.getDirection()); + return new Location(location.getExtent(), transform.apply(location.toVector()), location.getDirection()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java index 90892ed12..2a22a9669 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java @@ -166,7 +166,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { hasY = true; maxY = y; } - + @Override public BlockVector3 getMinimumPoint() { return center.toVector2().subtract(getRadius()).toVector3(minY).toBlockPoint(); @@ -381,4 +381,5 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { int maxY = extent.getMaximumPoint().getBlockY(); return new CylinderRegion(center, radiusVec, minY, maxY); } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/NullRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/NullRegion.java index de2a3dea0..58e1d2197 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/NullRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/NullRegion.java @@ -24,7 +24,11 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.world.World; -import java.util.*; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Set; /** * A region that contains no points. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java index 051731cdc..e0524774b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java @@ -54,7 +54,7 @@ public interface RegionSelector { /** * Called when the first point is selected. - * + * * @param position the position * @return true if something changed */ @@ -62,7 +62,7 @@ public interface RegionSelector { /** * Called when the second point is selected. - * + * * @param position the position * @return true if something changed */ @@ -70,7 +70,7 @@ public interface RegionSelector { /** * Tell the player information about his/her primary selection. - * + * * @param actor the actor * @param session the session * @param position position @@ -97,7 +97,7 @@ public interface RegionSelector { /** * Get the primary position. - * + * * @return the primary position * @throws IncompleteRegionException thrown if a region has not been fully defined */ @@ -105,7 +105,7 @@ public interface RegionSelector { /** * Get the selection. - * + * * @return the created region * @throws IncompleteRegionException thrown if a region has not been fully defined */ @@ -113,21 +113,21 @@ public interface RegionSelector { /** * Get the region even if it's not fully defined. - * + * * @return an incomplete region object that is incomplete */ Region getIncompleteRegion(); /** * Returns whether the region has been fully defined. - * + * * @return true if a selection is available */ boolean isDefined(); /** * Get the number of blocks inside the region. - * + * * @return number of blocks, or -1 if undefined */ int getArea(); @@ -144,25 +144,16 @@ public interface RegionSelector { /** * Get a lowercase name of this region selector type. - * + * * @return a lower case name of the type */ String getTypeName(); /** * Get lines of information about the selection. - * + * * @return a list of lines describing the region */ List getInformationLines(); - /** - * Get the verticies - * @return - * @throws IncompleteRegionException - */ - default List getVerticies() throws IncompleteRegionException { - return Collections.singletonList(getPrimaryPosition()); - } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java index 92242baa0..3adbf9444 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java @@ -20,8 +20,8 @@ package com.sk89q.worldedit.regions.selector; import com.boydti.fawe.config.BBC; -import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.extension.platform.Actor; @@ -37,11 +37,13 @@ import com.sk89q.worldedit.regions.polyhedron.Triangle; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; import com.sk89q.worldedit.world.World; -import java.util.*; import javax.annotation.Nullable; - - -import static com.google.common.base.Preconditions.checkNotNull; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; /** * Creates a {@code ConvexPolyhedralRegion} from a user's selections. @@ -108,11 +110,6 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion } } - @Override - public List getVerticies() { - return new ArrayList<>(region.getVertices()); - } - @Nullable @Override public World getWorld() { @@ -279,5 +276,4 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion } } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java index c98a118c0..99b7027af 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java @@ -22,14 +22,12 @@ package com.sk89q.worldedit.regions.selector; import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.Commands; import com.boydti.fawe.util.chat.Message; + +import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.command.SelectionCommands; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.sk89q.worldedit.IncompleteRegionException; -import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.internal.cui.CUIRegion; import com.sk89q.worldedit.internal.cui.SelectionPointEvent; @@ -39,13 +37,10 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; import com.sk89q.worldedit.world.World; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; + import javax.annotation.Nullable; - - -import static com.google.common.base.Preconditions.checkNotNull; +import java.util.ArrayList; +import java.util.List; /** * Creates a {@code CuboidRegion} from a user's selections. @@ -96,6 +91,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { position1 = oldRegion.getMinimumPoint(); position2 = oldRegion.getMaximumPoint(); } + region.setPos1(position1); region.setPos2(position2); } @@ -103,7 +99,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { /** * Create a new region selector with the given two positions. * - * @param world the world + * @param world the world * @param position1 position 1 * @param position2 position 2 */ @@ -117,11 +113,6 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { region.setPos2(position2); } - @Override - public List getVerticies() { - return Arrays.asList(position1, position2); - } - @Nullable @Override public World getWorld() { @@ -317,5 +308,4 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { return "cuboid"; } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java index aa6f48da3..8394e8d54 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java @@ -20,8 +20,8 @@ package com.sk89q.worldedit.regions.selector; import com.boydti.fawe.config.BBC; -import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.extension.platform.Actor; @@ -38,13 +38,11 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; import com.sk89q.worldedit.world.World; + +import javax.annotation.Nullable; import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; -import javax.annotation.Nullable; - - -import static com.google.common.base.Preconditions.checkNotNull; /** * Creates a {@code CylinderRegionSelector} from a user's selections. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java index 31b7d5077..5d1215dac 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java @@ -20,8 +20,8 @@ package com.sk89q.worldedit.regions.selector; import com.boydti.fawe.config.BBC; -import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.extension.platform.Actor; @@ -35,12 +35,10 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; import com.sk89q.worldedit.world.World; + +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; -import javax.annotation.Nullable; - - -import static com.google.common.base.Preconditions.checkNotNull; /** * Creates a {@code EllipsoidRegionSelector} from a user's selections. @@ -251,5 +249,4 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion { return region.getCenter().toBlockPoint(); } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ExtendingCuboidRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ExtendingCuboidRegionSelector.java index 79f2fcbba..8e7898990 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ExtendingCuboidRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ExtendingCuboidRegionSelector.java @@ -142,5 +142,4 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector { explainRegionAdjust(player, session); } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/Polygonal2DRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/Polygonal2DRegionSelector.java index 70ac199a2..deaeafb10 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/Polygonal2DRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/Polygonal2DRegionSelector.java @@ -20,8 +20,8 @@ package com.sk89q.worldedit.regions.selector; import com.boydti.fawe.config.BBC; -import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.extension.platform.Actor; @@ -36,13 +36,11 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; import com.sk89q.worldedit.world.World; + +import javax.annotation.Nullable; import java.util.Collections; import java.util.List; import java.util.Optional; -import javax.annotation.Nullable; - - -import static com.google.common.base.Preconditions.checkNotNull; /** * Creates a {@code Polygonal2DRegion} from a user's selections. @@ -114,7 +112,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { */ public Polygonal2DRegionSelector(@Nullable World world, List points, int minY, int maxY) { checkNotNull(points); - + final BlockVector2 pos2D = points.get(0); pos1 = BlockVector3.at(pos2D.getX(), minY, pos2D.getZ()); region = new Polygonal2DRegion(world, points, minY, maxY); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/ArbitraryBiomeShape.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/ArbitraryBiomeShape.java index 3c3316af9..de1324852 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/ArbitraryBiomeShape.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/ArbitraryBiomeShape.java @@ -79,17 +79,17 @@ public abstract class ArbitraryBiomeShape { * * @param x X coordinate to be queried * @param z Z coordinate to be queried - * @param defaultBiomeType The default biome for the current column. + * @param defaultBaseBiome The default biome for the current column. * @return material to place or null to not place anything. */ - protected abstract BiomeType getBiome(int x, int z, BiomeType defaultBiomeType); + protected abstract BiomeType getBiome(int x, int z, BiomeType defaultBaseBiome); - private BiomeType getBiomeCached(int x, int z, BiomeType biomeType) { + private BiomeType getBiomeCached(int x, int z, BiomeType baseBiome) { final int index = (z - cacheOffsetZ) + (x - cacheOffsetX) * cacheSizeZ; final BiomeType cacheEntry = cache[index]; if (cacheEntry == null) {// unknown, fetch material - final BiomeType material = getBiome(x, z, biomeType); + final BiomeType material = getBiome(x, z, baseBiome); if (material == null) { // outside cache[index] = BiomeTypes.THE_VOID; @@ -108,13 +108,13 @@ public abstract class ArbitraryBiomeShape { return cacheEntry; } - private boolean isInsideCached(int x, int z, BiomeType biomeType) { + private boolean isInsideCached(int x, int z, BiomeType baseBiome) { final int index = (z - cacheOffsetZ) + (x - cacheOffsetX) * cacheSizeZ; final BiomeType cacheEntry = cache[index]; if (cacheEntry == null) { // unknown block, meaning they must be outside the extent at this stage, but might still be inside the shape - return getBiomeCached(x, z, biomeType) != null; + return getBiomeCached(x, z, baseBiome) != null; } return cacheEntry != BiomeTypes.THE_VOID; @@ -124,11 +124,11 @@ public abstract class ArbitraryBiomeShape { * Generates the shape. * * @param editSession The EditSession to use. - * @param biomeType The default biome type. + * @param baseBiome The default biome type. * @param hollow Specifies whether to generate a hollow shape. * @return number of affected blocks. */ - public int generate(EditSession editSession, BiomeType biomeType, boolean hollow) { + public int generate(EditSession editSession, BiomeType baseBiome, boolean hollow) { int affected = 0; for (BlockVector2 position : getExtent()) { @@ -136,7 +136,7 @@ public abstract class ArbitraryBiomeShape { int z = position.getBlockZ(); if (!hollow) { - final BiomeType material = getBiome(x, z, biomeType); + final BiomeType material = getBiome(x, z, baseBiome); if (material != null && material != BiomeTypes.THE_VOID) { editSession.getWorld().setBiome(position, material); ++affected; @@ -145,26 +145,26 @@ public abstract class ArbitraryBiomeShape { continue; } - final BiomeType material = getBiomeCached(x, z, biomeType); + final BiomeType material = getBiomeCached(x, z, baseBiome); if (material == null) { continue; } boolean draw = false; do { - if (!isInsideCached(x + 1, z, biomeType)) { + if (!isInsideCached(x + 1, z, baseBiome)) { draw = true; break; } - if (!isInsideCached(x - 1, z, biomeType)) { + if (!isInsideCached(x - 1, z, baseBiome)) { draw = true; break; } - if (!isInsideCached(x, z + 1, biomeType)) { + if (!isInsideCached(x, z + 1, baseBiome)) { draw = true; break; } - if (!isInsideCached(x, z - 1, biomeType)) { + if (!isInsideCached(x, z - 1, baseBiome)) { draw = true; break; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/WorldEditExpressionEnvironment.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/WorldEditExpressionEnvironment.java index ed3d1f6af..49a6486a4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/WorldEditExpressionEnvironment.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/WorldEditExpressionEnvironment.java @@ -27,10 +27,10 @@ import com.sk89q.worldedit.math.MutableVector3; import com.sk89q.worldedit.math.Vector3; public class WorldEditExpressionEnvironment implements ExpressionEnvironment { + private final Vector3 unit; private final Vector3 zero2; private Vector3 current = new MutableVector3(Vector3.ZERO); - private EditSession editSession; private Extent extent; public WorldEditExpressionEnvironment(EditSession editSession, Vector3 unit, Vector3 zero) { @@ -90,5 +90,4 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment { this.current = current; } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Registry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Registry.java index 295fff2b0..f9edfc255 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Registry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Registry.java @@ -65,4 +65,5 @@ public class Registry implements Iterable { public Iterator iterator() { return this.map.values().iterator(); } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/ClipboardHolder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/ClipboardHolder.java index 17296b717..a4d6b5631 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/session/ClipboardHolder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/ClipboardHolder.java @@ -33,6 +33,7 @@ import java.util.List; * Holds the clipboard and the current transform on the clipboard. */ public class ClipboardHolder { + private Clipboard clipboard; private Transform transform = new Identity(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/DelegateClipboardHolder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/DelegateClipboardHolder.java deleted file mode 100644 index 622e3313f..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/session/DelegateClipboardHolder.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.sk89q.worldedit.session; - -import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.math.transform.Transform; - -public class DelegateClipboardHolder extends ClipboardHolder { - private final ClipboardHolder parent; - - public DelegateClipboardHolder(ClipboardHolder holder) { - super(holder.getClipboard()); - this.parent = holder; - } - - @Override - public Clipboard getClipboard() { - return parent.getClipboard(); - } - - @Override - public void setTransform(Transform transform) { - parent.setTransform(transform); - } - - @Override - public Transform getTransform() { - return parent.getTransform(); - } - - @Override - public PasteBuilder createPaste(Extent targetExtent) { - return parent.createPaste(targetExtent); - } - - @Override - public void close() { - parent.close(); - } -} 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 bfc82f5c6..9e0e25f84 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 @@ -20,9 +20,9 @@ package com.sk89q.worldedit.session; import com.boydti.fawe.util.MaskTraverser; -import com.sk89q.worldedit.EditSession; -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.extent.Extent; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; @@ -35,9 +35,6 @@ import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.transform.Transform; - -import static com.google.common.base.Preconditions.checkNotNull; - /** * Builds an operation to paste the contents of a clipboard. */ @@ -56,10 +53,10 @@ public class PasteBuilder { /** * Create a new instance. * - * @param holder the clipboard holder - * @param targetExtent an extent + * @param holder the clipboard holder + * @param targetExtent an extent */ - public PasteBuilder(ClipboardHolder holder, Extent targetExtent) { + PasteBuilder(ClipboardHolder holder, Extent targetExtent) { checkNotNull(holder); checkNotNull(targetExtent); this.clipboard = holder.getClipboard(); @@ -134,5 +131,4 @@ public class PasteBuilder { return copy; } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java index 9948350fd..a29b48d59 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java @@ -23,7 +23,11 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; import javax.annotation.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; +import java.util.OptionalInt; /** * A collection of cardinal, ordinal, and secondary-ordinal directions. @@ -65,7 +69,7 @@ public enum Direction { private final BlockVector3 blockPoint; private static HashMap map = new HashMap<>(); - + static { for (Direction dir : Direction.values()) { map.put(dir.name(), dir); @@ -80,11 +84,11 @@ public enum Direction { this.left = left; this.right = right; } - + public static Direction get(CharSequence sequence) { return map.get(sequence.toString()); } - + public Direction getLeft() { return left != -1 ? values()[left] : null; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java index 820d813d3..73a2efe88 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java @@ -38,8 +38,7 @@ import javax.annotation.Nullable; */ public class TargetBlock { - private final World world; - + private World world; private int maxDistance; private double checkDistance, curDistance; private BlockVector3 targetPos = BlockVector3.ZERO; @@ -122,7 +121,7 @@ public class TargetBlock { this.checkDistance = checkDistance; this.curDistance = 0; xRotation = (xRotation + 90) % 360; - yRotation *= -1; + yRotation = yRotation * -1; double h = (checkDistance * Math.cos(Math.toRadians(yRotation))); @@ -145,15 +144,15 @@ public class TargetBlock { boolean searchForLastBlock = true; Location lastBlock = null; while (getNextBlock() != null) { - if (stopMask.test(targetPos)) { - break; - } else { + if (!stopMask.test(targetPos)) { if (searchForLastBlock) { lastBlock = getCurrentBlock(); if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= world.getMaxY()) { searchForLastBlock = false; } } + } else { + break; } } Location currentBlock = getCurrentBlock(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleCommandMapping.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleCommandMapping.java index d3ca796a6..a468eea05 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleCommandMapping.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleCommandMapping.java @@ -95,6 +95,4 @@ public class SimpleCommandMapping implements CommandMapping { '}'; } - - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleDispatcher.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleDispatcher.java index 6f6c32048..949869cdd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleDispatcher.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleDispatcher.java @@ -20,13 +20,15 @@ package com.sk89q.worldedit.util.command; import com.boydti.fawe.Fawe; -import com.boydti.fawe.config.BBC; import com.boydti.fawe.util.StringMan; + import com.google.common.base.Joiner; +import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandLocals; import com.sk89q.minecraft.util.commands.CommandPermissionsException; import com.sk89q.minecraft.util.commands.WrappedCommandException; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -117,7 +119,7 @@ public class SimpleDispatcher implements Dispatcher { throw new CommandPermissionsException(); } - String[] split = arguments.split(" ", -1); + String[] split = CommandContext.split(arguments); Set aliases = getPrimaryAliases(); if (aliases.isEmpty()) { @@ -147,7 +149,7 @@ public class SimpleDispatcher implements Dispatcher { @Override public List getSuggestions(String arguments, CommandLocals locals) throws CommandException { - String[] split = arguments.split(" ", -1); + String[] split = CommandContext.split(arguments); if (split.length <= 1) { String prefix = split.length > 0 ? split[0] : ""; @@ -189,4 +191,5 @@ public class SimpleDispatcher implements Dispatcher { // Checking every perm in the class here was unnecessarily stupid return true; } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/fluent/DispatcherNode.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/fluent/DispatcherNode.java index 6725a0283..4786e5f3e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/fluent/DispatcherNode.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/fluent/DispatcherNode.java @@ -20,14 +20,15 @@ package com.sk89q.worldedit.util.command.fluent; import com.boydti.fawe.config.Commands; + import com.sk89q.minecraft.util.commands.Command; import com.sk89q.worldedit.util.command.CallableProcessor; import com.sk89q.worldedit.util.command.CommandCallable; import com.sk89q.worldedit.util.command.Dispatcher; import com.sk89q.worldedit.util.command.SimpleDispatcher; import com.sk89q.worldedit.util.command.parametric.ParametricBuilder; + import javax.annotation.Nullable; -import java.lang.annotation.Annotation; /** * A collection of commands. @@ -41,12 +42,12 @@ public class DispatcherNode { /** * Create a new instance. * - * @param graph the root fluent graph object - * @param parent the parent node, or null + * @param graph the root fluent graph object + * @param parent the parent node, or null * @param dispatcher the dispatcher for this node */ - public DispatcherNode(CommandGraph graph, DispatcherNode parent, - SimpleDispatcher dispatcher) { + DispatcherNode(CommandGraph graph, DispatcherNode parent, + SimpleDispatcher dispatcher) { this.graph = graph; this.parent = parent; this.dispatcher = dispatcher; @@ -54,7 +55,7 @@ public class DispatcherNode { /** * Set the description. - *

+ * *

This can only be used on {@link DispatcherNode}s returned by * {@link #group(String...)}.

* @@ -70,7 +71,7 @@ public class DispatcherNode { * Register a command with this dispatcher. * * @param callable the executor - * @param alias the list of aliases, where the first alias is the primary one + * @param alias the list of aliases, where the first alias is the primary one */ public DispatcherNode register(CommandCallable callable, String... alias) { dispatcher.registerCommand(callable, alias); @@ -145,7 +146,7 @@ public class DispatcherNode { /** * Create a new command that will contain sub-commands. - *

+ * *

The object returned by this method can be used to add sub-commands. To * return to this "parent" context, use {@link DispatcherNode#graph()}.

* @@ -155,8 +156,7 @@ public class DispatcherNode { public DispatcherNode group(String... alias) { SimpleDispatcher command = new SimpleDispatcher(); getDispatcher().registerCommand(command, alias); - DispatcherNode res = new DispatcherNode(graph, this, command); - return res; + return new DispatcherNode(graph, this, command); } /** @@ -191,5 +191,4 @@ public class DispatcherNode { return dispatcher; } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/AParametricCallable.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/AParametricCallable.java index 91abf5dff..2fe586e81 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/AParametricCallable.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/AParametricCallable.java @@ -40,7 +40,7 @@ public abstract class AParametricCallable implements CommandCallable { * @param existing the existing scoped context * @return the context to use */ - public static ArgumentStack getScopedContext(Parameter parameter, ArgumentStack existing) { + static ArgumentStack getScopedContext(Parameter parameter, ArgumentStack existing) { if (parameter.getFlag() != null) { CommandContext context = existing.getContext(); @@ -213,7 +213,6 @@ public abstract class AParametricCallable implements CommandCallable { CommandContext context = new CommandContext(split, getValueFlags(), !arguments.endsWith(" "), locals); ContextArgumentStack scoped = new ContextArgumentStack(context); - SuggestionContext suggestable = context.getSuggestionContext(); List suggestions = new ArrayList<>(2); ParameterData parameter = null; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ArgumentStack.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ArgumentStack.java index fbcc9ec3c..b3345f3a4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ArgumentStack.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ArgumentStack.java @@ -91,8 +91,4 @@ public interface ArgumentStack { * @return the consumed arguments */ String reset(); - - static Class inject0() { - return ArgumentStack.class; - } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/BindingHelper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/BindingHelper.java index 1d45d0b32..c37839c72 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/BindingHelper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/BindingHelper.java @@ -20,6 +20,7 @@ package com.sk89q.worldedit.util.command.parametric; import com.boydti.fawe.util.StringMan; + import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.worldedit.util.command.binding.Range; import com.sk89q.worldedit.util.command.binding.Validate; @@ -29,53 +30,51 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; /** * A binding helper that uses the {@link BindingMatch} annotation to make * writing bindings extremely easy. - * + * *

Methods must have the following and only the following parameters:

- * + * *
    *
  • A {@link ArgumentStack}
  • *
  • A {@link Annotation} if there is a classifier set
  • - *
  • A {@link Annotation}[] + *
  • A {@link Annotation}[] * if there {@link BindingMatch#provideModifiers()} is true
  • *
- * + * *

Methods may throw any exception. Exceptions may be converted using a * {@link ExceptionConverter} registered with the {@link ParametricBuilder}.

*/ -@Deprecated public class BindingHelper implements Binding { - + private final List bindings; private final Type[] types; - + /** * Create a new instance. */ public BindingHelper() { List bindings = new ArrayList<>(); List types = new ArrayList<>(); - + for (Method method : this.getClass().getMethods()) { BindingMatch info = method.getAnnotation(BindingMatch.class); if (info != null) { Class classifier = null; - + // Set classifier if (!info.classifier().equals(Annotation.class)) { classifier = info.classifier(); types.add(classifier); } - + for (Type t : info.type()) { Type type = null; - + // Set type if (!t.equals(Class.class)) { type = t; @@ -83,32 +82,32 @@ public class BindingHelper implements Binding { types.add(type); // Only if there is no classifier set! } } - + // Check to see if at least one is set if (type == null && classifier == null) { throw new RuntimeException( "A @BindingMatch needs either a type or classifier set"); } - + BindingMap.BoundMethod handler = new BindingMap.BoundMethod(info, type, classifier, method, this); bindings.add(handler); } } } - + Collections.sort(bindings); - + this.bindings = bindings; - + Type[] typesArray = new Type[types.size()]; types.toArray(typesArray); this.types = typesArray; - + } - + /** * Match a {@link BindingMatch} according to the given parameter. - * + * * @param parameter the parameter * @return a binding */ @@ -116,7 +115,7 @@ public class BindingHelper implements Binding { for (BindingMap.BoundMethod binding : bindings) { Annotation classifer = parameter.getClassifier(); Type type = parameter.getType(); - + if (binding.classifier != null) { if (classifer != null && classifer.annotationType().equals(binding.classifier)) { if (binding.type == null || binding.type.equals(type)) { @@ -127,7 +126,7 @@ public class BindingHelper implements Binding { return binding; } } - + throw new RuntimeException("Unknown type"); } @@ -152,27 +151,27 @@ public class BindingHelper implements Binding { BindingMap.BoundMethod binding = match(parameter); List args = new ArrayList<>(); args.add(scoped); - + if (binding.classifier != null) { args.add(parameter.getClassifier()); } - + if (binding.annotation.provideModifiers()) { args.add(parameter.getModifiers()); } - + if (onlyConsume && binding.annotation.behavior() == BindingBehavior.PROVIDES) { return null; // Nothing to consume, nothing to do } - + Object[] argsArray = new Object[args.size()]; args.toArray(argsArray); - + try { return binding.method.invoke(this, argsArray); } catch (IllegalArgumentException e) { throw new RuntimeException( - "Processing of classifier " + parameter.getClassifier() + + "Processing of classifier " + parameter.getClassifier() + " and type " + parameter.getType() + " failed for method\n" + binding.method + "\nbecause the parameters for that method are wrong", e); } catch (IllegalAccessException e) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/BindingMatch.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/BindingMatch.java index a76be395b..cc89f3c74 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/BindingMatch.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/BindingMatch.java @@ -31,39 +31,39 @@ import java.lang.annotation.Target; @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface BindingMatch { - + /** * The classifier. - * + * * @return the classifier, or {@link Annotation} if not set */ Class classifier() default Annotation.class; - + /** * The type. - * + * * @return the type, or {@link Class} if not set */ Class[] type() default Class.class; /** * The binding behavior. - * + * * @return the behavior */ BindingBehavior behavior(); - + /** * Get the number of arguments that this binding consumes. - * + * * @return -1 if unknown or irrelevant */ int consumedCount() default -1; - + /** * Set whether an array of modifier annotations is provided in the list of * arguments. - * + * * @return true to provide modifiers */ boolean provideModifiers() default false; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ContextArgumentStack.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ContextArgumentStack.java index b963c6cfe..4f5b9986d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ContextArgumentStack.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ContextArgumentStack.java @@ -124,7 +124,6 @@ public class ContextArgumentStack implements ArgumentStack { * *

The marked position initially starts at 0.

*/ - @Override public void mark() { markedIndex = index; } @@ -137,7 +136,6 @@ public class ContextArgumentStack implements ArgumentStack { * * @return the consumed arguments */ - @Override public String reset() { String value = (index - 1 > markedIndex) ? context.getString(markedIndex, index - 1) : ""; index = markedIndex; @@ -177,6 +175,4 @@ public class ContextArgumentStack implements ArgumentStack { return context; } - - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/FaweParanamer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/FaweParanamer.java index 4dbcd491a..7c69e59bd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/FaweParanamer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/FaweParanamer.java @@ -32,11 +32,9 @@ package com.sk89q.worldedit.util.command.parametric; import com.thoughtworks.paranamer.CachingParanamer; +import java.lang.reflect.AccessibleObject; import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.lang.reflect.AccessibleObject; import java.lang.reflect.Parameter; /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/FunctionParametricCallable.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/FunctionParametricCallable.java index dff7acf2d..3a062d2cf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/FunctionParametricCallable.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/FunctionParametricCallable.java @@ -1,15 +1,31 @@ package com.sk89q.worldedit.util.command.parametric; -import com.boydti.fawe.config.BBC; import com.boydti.fawe.util.StringMan; + import com.google.common.primitives.Chars; -import com.sk89q.minecraft.util.commands.*; -import com.sk89q.worldedit.util.command.*; +import com.sk89q.minecraft.util.commands.Command; +import com.sk89q.minecraft.util.commands.CommandContext; +import com.sk89q.minecraft.util.commands.CommandException; +import com.sk89q.minecraft.util.commands.CommandLocals; +import com.sk89q.minecraft.util.commands.CommandPermissionsException; +import com.sk89q.minecraft.util.commands.WrappedCommandException; +import com.sk89q.worldedit.util.command.CommandCallable; +import com.sk89q.worldedit.util.command.InvalidUsageException; +import com.sk89q.worldedit.util.command.MissingParameterException; +import com.sk89q.worldedit.util.command.Parameter; +import com.sk89q.worldedit.util.command.SimpleDescription; +import com.sk89q.worldedit.util.command.UnconsumedParameterException; import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Type; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.function.Function; public class FunctionParametricCallable extends AParametricCallable { @@ -33,48 +49,46 @@ public class FunctionParametricCallable extends AParametricCallable { this.group = group; List paramParsables = new ArrayList<>(); + Map unqualified = new HashMap<>(); + for (Type type : builder.getBindings().getTypes()) { + String typeStr = type.getTypeName(); + unqualified.put(typeStr, type); + unqualified.put(typeStr.substring(typeStr.lastIndexOf('.') + 1), type); + } { - Map unqualified = new HashMap<>(); - for (Type type : builder.getBindings().getTypes()) { - String typeStr = type.getTypeName(); - unqualified.put(typeStr, type); - unqualified.put(typeStr.substring(typeStr.lastIndexOf('.') + 1), type); - } - { - Object[] param = null; // name | type | optional value - boolean checkEq = false; - int checkEqI = 0; - for (String arg : arguments) { - if (arg.equals("=")) { - checkEqI++; - checkEq = true; - } else if (param == null || !checkEq) { - if (param != null) paramParsables.add(param); - param = new Object[3]; - param[0] = arg; - if (arg.length() == 1 && command.flags().contains(arg)) { - param[1] = Boolean.class; - } else { - param[1] = String.class; - } - param[2] = null; + Object[] param = null; // name | type | optional value + boolean checkEq = false; + int checkEqI = 0; + for (String arg : arguments) { + if (arg.equals("=")) { + checkEqI++; + checkEq = true; + } else if (param == null || !checkEq) { + if (param != null) paramParsables.add(param); + param = new Object[3]; + param[0] = arg; + if (arg.length() == 1 && command.flags().contains(arg)) { + param[1] = Boolean.class; + } else { + param[1] = String.class; + } + param[2] = null; + checkEqI = 0; + checkEq = false; + } else { + if (checkEqI == 1) { + param[1] = unqualified.getOrDefault(arg, String.class); + checkEq = false; + } else if (checkEqI == 2) { + char c = arg.charAt(0); + if (c == '\'' || c == '"') arg = arg.substring(1, arg.length() - 1); + param[2] = arg; checkEqI = 0; checkEq = false; - } else { - if (checkEqI == 1) { - param[1] = unqualified.getOrDefault(arg, String.class); - checkEq = false; - } else if (checkEqI == 2) { - char c = arg.charAt(0); - if (c == '\'' || c == '"') arg = arg.substring(1, arg.length() - 1); - param[2] = arg; - checkEqI = 0; - checkEq = false; - } } } - if (param != null) paramParsables.add(param); } + if (param != null) paramParsables.add(param); } parameters = new ParameterData[paramParsables.size()]; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParameterData.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParameterData.java index f902ae4bd..67d5025b3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParameterData.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParameterData.java @@ -24,12 +24,9 @@ import com.sk89q.worldedit.util.command.binding.PrimitiveBindings; import com.sk89q.worldedit.util.command.binding.Range; import com.sk89q.worldedit.util.command.binding.Text; -import javax.xml.ws.Provider; import java.lang.annotation.Annotation; -import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Type; -import java.util.concurrent.Callable; import java.util.function.Supplier; /** @@ -62,7 +59,7 @@ public class ParameterData extends SimpleParameter { /** * Set the main type of this parameter. - *

+ * *

The type is normally that is used to determine which binding is used * for a particular method's parameter.

* @@ -84,7 +81,7 @@ public class ParameterData extends SimpleParameter { /** * Get the classifier annotation. - *

+ * *

Normally, the type determines what binding is called, but classifiers * take precedence if one is found (and registered with * {@link ParametricBuilder#addBinding(Binding, Type...)}). @@ -107,7 +104,7 @@ public class ParameterData extends SimpleParameter { /** * Get a list of modifier annotations. - *

+ * *

Modifier annotations are not considered in the process of choosing a binding * for a method parameter, but they can be used to modify the behavior of a binding. * An example of a modifier annotation is {@link Range}, which can restrict @@ -120,7 +117,7 @@ public class ParameterData extends SimpleParameter { return modifiers; } - public T getModifier(Class annotatedType) { + T getModifier(Class annotatedType) { for (Annotation annotation : getModifiers()) { if (annotation.getClass() == annotatedType) return (T) annotation; } @@ -141,7 +138,7 @@ public class ParameterData extends SimpleParameter { * * @return -1 if unknown or unavailable */ - public int getConsumedCount() { + int getConsumedCount() { return getBinding().getConsumedCount(this); } @@ -150,7 +147,7 @@ public class ParameterData extends SimpleParameter { * * @return true if this parameter is entered by the user. */ - public boolean isUserInput() { + boolean isUserInput() { return getBinding().getBehavior(this) != BindingBehavior.PROVIDES; } @@ -159,7 +156,7 @@ public class ParameterData extends SimpleParameter { * * @return true if this parameter consumes non-flag arguments */ - public boolean isNonFlagConsumer() { + boolean isNonFlagConsumer() { return getBinding().getBehavior(this) != BindingBehavior.PROVIDES && !isValueFlag(); } @@ -167,7 +164,7 @@ public class ParameterData extends SimpleParameter { * Validate this parameter and its binding. */ public void validate(Method method, int parameterIndex) throws ParametricException { - validate(() -> method.toGenericString(), parameterIndex); + validate(method::toGenericString, parameterIndex); } public void validate(Supplier method, int parameterIndex) throws ParametricException { @@ -206,5 +203,4 @@ public class ParameterData extends SimpleParameter { } } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricBuilder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricBuilder.java index 43f809dd5..e2bd3f99a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricBuilder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricBuilder.java @@ -20,20 +20,16 @@ package com.sk89q.worldedit.util.command.parametric; import com.boydti.fawe.command.FawePrimitiveBinding; -import com.boydti.fawe.command.MaskBinding; -import com.boydti.fawe.command.PatternBinding; import com.boydti.fawe.config.Commands; + +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableBiMap.Builder; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandPermissions; -import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.command.MethodCommands; -import com.sk89q.worldedit.internal.command.ActorAuthorizer; -import com.sk89q.worldedit.internal.command.CommandLoggingHandler; -import com.sk89q.worldedit.internal.command.UserCommandCompleter; -import com.sk89q.worldedit.internal.command.WorldEditBinding; import com.sk89q.worldedit.util.auth.Authorizer; import com.sk89q.worldedit.util.auth.NullAuthorizer; import com.sk89q.worldedit.util.command.CallableProcessor; @@ -46,15 +42,11 @@ import com.sk89q.worldedit.util.command.binding.PrimitiveBindings; import com.sk89q.worldedit.util.command.binding.StandardBindings; import com.sk89q.worldedit.util.command.binding.Switch; import com.thoughtworks.paranamer.Paranamer; + import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; - - -import static com.google.common.base.Preconditions.checkNotNull; /** * Creates commands using annotations placed on methods and individual parameters of @@ -68,13 +60,12 @@ public class ParametricBuilder { private final BindingMap bindings; private final Paranamer paranamer = new FaweParanamer(); private final List invokeListeners = new ArrayList<>(); - private final List exceptionConverters = new ArrayList<>(); private Authorizer authorizer = new NullAuthorizer(); private CommandCompleter defaultCompleter = new NullCompleter(); /** * Create a new builder. - *

+ * *

This method will install {@link PrimitiveBindings} and * {@link StandardBindings} and default bindings.

*/ @@ -86,12 +77,12 @@ public class ParametricBuilder { /** * Add a binding for a given type or classifier (annotation). - *

+ * *

Whenever a method parameter is encountered, a binding must be found for it * so that it can be called later to consume the stack of arguments provided by * the user and return an object that is later passed to * {@link Method#invoke(Object, Object...)}.

- *

+ * *

Normally, a {@link Type} is used to discern between different bindings, but * if this is not specific enough, an annotation can be defined and used. This * makes it a "classifier" and it will take precedence over the base type. For @@ -102,9 +93,8 @@ public class ParametricBuilder { * the {@link String} type.

* * @param binding the binding - * @param type a list of types (if specified) to override the binding's types + * @param type a list of types (if specified) to override the binding's types */ - @Deprecated public void addBinding(Binding binding, Type... type) { this.bindings.add(binding); } @@ -119,50 +109,37 @@ public class ParametricBuilder { /** * Attach an invocation listener. - *

+ * *

Invocation handlers are called in order that their listeners are * registered with a {@link ParametricBuilder}. It is not guaranteed that * a listener may be called, in the case of a {@link CommandException} being * thrown at any time before the appropriate listener or handler is called. * It is possible for a - * {@link com.sk89q.worldedit.util.command.parametric.InvokeHandler#preInvoke(Object, Method, com.sk89q.worldedit.util.command.parametric.ParameterData[], Object[], CommandContext)} to + * {@link InvokeHandler#preInvoke(Object, Method, ParameterData[], Object[], CommandContext)} to * be called for a invocation handler, but not the associated - * {@link com.sk89q.worldedit.util.command.parametric.InvokeHandler#postInvoke(Object, Method, com.sk89q.worldedit.util.command.parametric.ParameterData[], Object[], CommandContext)}.

- *

+ * {@link InvokeHandler#postInvoke(Object, Method, ParameterData[], Object[], CommandContext)}.

+ * *

An example of an invocation listener is one to handle * {@link CommandPermissions}, by first checking to see if permission is available - * in a {@link com.sk89q.worldedit.util.command.parametric.InvokeHandler#preInvoke(Object, Method, com.sk89q.worldedit.util.command.parametric.ParameterData[], Object[], CommandContext)} + * in a {@link InvokeHandler#preInvoke(Object, Method, ParameterData[], Object[], CommandContext)} * call. If permission is not found, then an appropriate {@link CommandException} * can be thrown to cease invocation.

* * @param listener the listener - * @see com.sk89q.worldedit.util.command.parametric.InvokeHandler the handler + * @see InvokeHandler the handler */ public void addInvokeListener(InvokeListener listener) { invokeListeners.add(listener); } - /** - * Attach an exception converter to this builder in order to wrap unknown - * {@link Throwable}s into known {@link CommandException}s. - *

- *

Exception converters are called in order that they are registered.

- * - * @param converter the converter - * @see ExceptionConverter for an explanation - */ - public void addExceptionConverter(ExceptionConverter converter) { - exceptionConverters.add(converter); - } - /** * Build a list of commands from methods specially annotated with {@link Command} * (and other relevant annotations) and register them all with the given * {@link Dispatcher}. * * @param dispatcher the dispatcher to register commands with - * @param object the object contain the methods - * @throws com.sk89q.worldedit.util.command.parametric.ParametricException thrown if the commands cannot be registered + * @param object the object contain the methods + * @throws ParametricException thrown if the commands cannot be registered */ public void registerMethodsAsCommands(Dispatcher dispatcher, Object object) throws ParametricException { registerMethodsAsCommands(dispatcher, object, null); @@ -204,8 +181,8 @@ public class ParametricBuilder { /** * Build a {@link CommandCallable} for the given method. * - * @param object the object to be invoked on - * @param method the method to invoke + * @param object the object to be invoked on + * @param method the method to invoke * @param definition the command definition annotation * @return the command executor * @throws ParametricException thrown on an error @@ -229,7 +206,7 @@ public class ParametricBuilder { * * @return the paranamer */ - public Paranamer getParanamer() { + Paranamer getParanamer() { return paranamer; } @@ -247,19 +224,10 @@ public class ParametricBuilder { * * @return a list of invocation listeners */ - public List getInvokeListeners() { + List getInvokeListeners() { return invokeListeners; } - /** - * Get the list of exception converters. - * - * @return a list of exception converters - */ - public List getExceptionConverters() { - return exceptionConverters; - } - /** * Get the authorizer. * @@ -300,6 +268,4 @@ public class ParametricBuilder { this.defaultCompleter = defaultCompleter; } - - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java index 493d5f1d8..c5bc616b4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.util.command.parametric; -import com.boydti.fawe.command.SuggestInputParseException; -import com.boydti.fawe.config.BBC; import com.google.common.primitives.Chars; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; @@ -28,7 +26,6 @@ import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandLocals; import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissionsException; -import com.sk89q.minecraft.util.commands.SuggestionContext; import com.sk89q.minecraft.util.commands.WrappedCommandException; import com.sk89q.worldedit.util.command.CommandCallable; import com.sk89q.worldedit.util.command.InvalidUsageException; @@ -37,6 +34,7 @@ import com.sk89q.worldedit.util.command.Parameter; import com.sk89q.worldedit.util.command.SimpleDescription; import com.sk89q.worldedit.util.command.UnconsumedParameterException; import com.sk89q.worldedit.util.command.binding.Switch; + import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -66,13 +64,13 @@ public class ParametricCallable extends AParametricCallable { /** * Create a new instance. * - * @param builder the parametric builder - * @param object the object to invoke on - * @param method the method to invoke + * @param builder the parametric builder + * @param object the object to invoke on + * @param method the method to invoke * @param definition the command definition annotation * @throws ParametricException thrown on an error */ - public ParametricCallable(ParametricBuilder builder, Object object, Method method, Command definition) throws ParametricException { + ParametricCallable(ParametricBuilder builder, Object object, Method method, Command definition) throws ParametricException { this.builder = builder; this.object = object; this.method = method; @@ -80,7 +78,6 @@ public class ParametricCallable extends AParametricCallable { Annotation[][] annotations = method.getParameterAnnotations(); String[] names = builder.getParanamer().lookupParameterNames(method, false); Type[] types = method.getGenericParameterTypes(); - parameters = new ParameterData[types.length]; List userParameters = new ArrayList<>(); @@ -112,7 +109,7 @@ public class ParametricCallable extends AParametricCallable { if (value.length > 0) { parameter.setDefaultValue(value); } - // Special annotation bindings + // Special annotation bindings } else if (parameter.getBinding() == null) { parameter.setBinding(builder.getBindings()); parameter.setClassifier(annotation); @@ -147,10 +144,10 @@ public class ParametricCallable extends AParametricCallable { if (parameter.getConsumedCount() < 0) { throw new ParametricException( "Found an parameter using the binding " + - parameter.getBinding().getClass().getCanonicalName() + - "\nthat does not know how many arguments it consumes, but " + - "it follows an optional parameter\nMethod: " + - method.toGenericString()); + parameter.getBinding().getClass().getCanonicalName() + + "\nthat does not know how many arguments it consumes, but " + + "it follows an optional parameter\nMethod: " + + method.toGenericString()); } } } @@ -208,7 +205,7 @@ public class ParametricCallable extends AParametricCallable { locals.putIfAbsent(CommandCallable.class, this); String calledCommand = parentCommands.length > 0 ? parentCommands[parentCommands.length - 1] : "_"; - String[] split = (calledCommand + " " + stringArguments).split(" ", -1); + String[] split = CommandContext.split(calledCommand + " " + stringArguments); CommandContext context = new CommandContext(split, getValueFlags(), false, locals); // Provide help if -? is specified @@ -271,14 +268,14 @@ public class ParametricCallable extends AParametricCallable { } return result; } catch (MissingParameterException e) { - throw new InvalidUsageException("Too few parameters!", this, true); + throw new InvalidUsageException("Too few parameters!", this); } catch (UnconsumedParameterException e) { - throw new InvalidUsageException("Too many parameters! Unused parameters: " + e.getUnconsumed(), this, true); + throw new InvalidUsageException("Too many parameters! Unused parameters: " + e.getUnconsumed(), this); } catch (ParameterException e) { assert parameter != null; String name = parameter.getName(); - throw new InvalidUsageException("For parameter '" + name + "': " + e.getMessage(), this, true); + throw new InvalidUsageException("For parameter '" + name + "': " + e.getMessage(), this); } catch (InvocationTargetException e) { if (e.getCause() instanceof CommandException) { throw (CommandException) e.getCause(); @@ -344,12 +341,12 @@ public class ParametricCallable extends AParametricCallable { /** * Generate a name for a parameter. * - * @param type the type + * @param type the type * @param classifier the classifier - * @param index the index + * @param index the index * @return a generated name */ - public static String generateName(Type type, Annotation classifier, int index) { + private static String generateName(Type type, Annotation classifier, int index) { if (classifier != null) { return classifier.annotationType().getSimpleName().toLowerCase(); } else { @@ -361,5 +358,4 @@ public class ParametricCallable extends AParametricCallable { } } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/StringArgumentStack.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/StringArgumentStack.java index 0b6524aa3..894aeb329 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/StringArgumentStack.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/StringArgumentStack.java @@ -20,8 +20,8 @@ package com.sk89q.worldedit.util.command.parametric; import com.sk89q.minecraft.util.commands.CommandContext; -import com.sk89q.worldedit.util.command.MissingParameterException; import com.sk89q.util.StringUtil; +import com.sk89q.worldedit.util.command.MissingParameterException; /** * A virtual scope that does not actually read from the underlying diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Fragment.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Fragment.java index f7034093e..94ba7f20a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Fragment.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Fragment.java @@ -25,12 +25,12 @@ package com.sk89q.worldedit.util.formatting; public class Fragment { private final StringBuilder builder = new StringBuilder(); - - public Fragment() { + + Fragment() { } public Fragment append(String str) { - builder.append(str); + builder.append(Style.stripColor(str)); return this; } @@ -88,5 +88,5 @@ public class Fragment { public String toString() { return builder.toString(); } - + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandListBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandListBox.java index b2dbac493..9df10e637 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandListBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandListBox.java @@ -38,7 +38,7 @@ public class CommandListBox extends MessageBox { return appendCommand(alias, description, true); } - public CommandListBox appendCommand(String alias, String description, boolean allowed) { + CommandListBox appendCommand(String alias, String description, boolean allowed) { if (!first) { getContents().newLine(); } @@ -47,5 +47,4 @@ public class CommandListBox extends MessageBox { return this; } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java index e4935cb16..7f350edf4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java @@ -20,6 +20,8 @@ package com.sk89q.worldedit.util.formatting.component; import com.boydti.fawe.config.BBC; + +import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.minecraft.util.commands.CommandLocals; import com.sk89q.worldedit.extension.platform.CommandManager; import com.sk89q.worldedit.util.command.CommandCallable; @@ -27,15 +29,11 @@ import com.sk89q.worldedit.util.command.CommandMapping; import com.sk89q.worldedit.util.command.Description; import com.sk89q.worldedit.util.command.Dispatcher; import com.sk89q.worldedit.util.command.PrimaryAliasComparator; -import com.sk89q.worldedit.util.formatting.Style; import com.sk89q.worldedit.util.formatting.StyledFragment; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; + import javax.annotation.Nullable; - - -import static com.google.common.base.Preconditions.checkNotNull; +import java.util.ArrayList; +import java.util.List; /** * A box to describe usage of a command. @@ -45,7 +43,7 @@ public class CommandUsageBox extends StyledFragment { /** * Create a new usage box. * - * @param command the command to describe + * @param command the command to describe * @param commandString the command that was used, such as "/we" or "/brush sphere" */ public CommandUsageBox(CommandCallable command, String commandString) { @@ -55,9 +53,9 @@ public class CommandUsageBox extends StyledFragment { /** * Create a new usage box. * - * @param command the command to describe + * @param command the command to describe * @param commandString the command that was used, such as "/we" or "/brush sphere" - * @param locals list of locals to use + * @param locals list of locals to use */ public CommandUsageBox(CommandCallable command, String commandString, @Nullable CommandLocals locals) { checkNotNull(command); @@ -74,7 +72,7 @@ public class CommandUsageBox extends StyledFragment { String prefix = !commandString.isEmpty() ? commandString + " " : ""; List list = new ArrayList<>(dispatcher.getCommands()); - Collections.sort(list, new PrimaryAliasComparator(CommandManager.COMMAND_CLEAN_PATTERN)); + list.sort(new PrimaryAliasComparator(CommandManager.COMMAND_CLEAN_PATTERN)); for (CommandMapping mapping : list) { boolean perm = locals == null || mapping.getCallable().testPermission(locals); @@ -91,13 +89,11 @@ public class CommandUsageBox extends StyledFragment { if (description.getUsage() != null) { contents.append(new Label().append(BBC.COMMAND_SYNTAX.f(description.getUsage()))); } else { - contents.createFragment(Style.GRAY); contents.append(new Subtle().append("Usage information is not available.")); } contents.newLine(); - contents.createFragment(Style.GRAY); if (description.getHelp() != null) { contents.append(description.getHelp()); } else if (description.getDescription() != null) { @@ -109,6 +105,4 @@ public class CommandUsageBox extends StyledFragment { append(box); } - - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/MessageBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/MessageBox.java index 65bbde07a..dd8694590 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/MessageBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/MessageBox.java @@ -41,6 +41,14 @@ public class MessageBox extends StyledFragment { append(contents); } + private String createBorder(int count) { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < count; i++) { + builder.append("-"); + } + return builder.toString(); + } + /** * Get the internal contents. * @@ -50,5 +58,4 @@ public class MessageBox extends StyledFragment { return contents; } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java index cd18a3489..e24b8a677 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java @@ -36,7 +36,6 @@ import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import javax.annotation.Nullable; -import java.util.PriorityQueue; /** * An abstract implementation of {@link World}. @@ -143,6 +142,7 @@ public abstract class AbstractWorld implements World { this.priority = priority; } + @SuppressWarnings("deprecation") public void play() { playEffect(position, 2001, blockType.getLegacyCombinedId() >> 4); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java index fa27b3d17..c3ef611d8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java @@ -19,11 +19,9 @@ package com.sk89q.worldedit.world; -import com.sk89q.worldedit.*; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; @@ -54,7 +52,7 @@ public class NullWorld extends AbstractWorld { private static final NullWorld INSTANCE = new NullWorld(); - public NullWorld() { + protected NullWorld() { } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java index 400acd517..d8eec08be 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java @@ -20,11 +20,7 @@ package com.sk89q.worldedit.world.biome; import javax.annotation.Nullable; -import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; /** * Stores a list of common Biome String IDs. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java index 38285926c..c5af9a99d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java @@ -20,21 +20,18 @@ package com.sk89q.worldedit.world.block; import static com.google.common.base.Preconditions.checkNotNull; - import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.world.registry.BlockMaterial; -import com.sk89q.worldedit.world.registry.LegacyMapper; -import com.sk89q.worldedit.blocks.TileEntityBlock; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.PropertyKey; +import com.sk89q.worldedit.world.registry.BlockMaterial; +import com.sk89q.worldedit.world.registry.LegacyMapper; import javax.annotation.Nullable; - import java.util.Map; import java.util.Objects; @@ -48,10 +45,10 @@ import java.util.Objects; * may be missing.

*/ public class BaseBlock implements BlockStateHolder { + private final BlockState blockState; - @Nullable - protected CompoundTag nbtData; + @Nullable protected CompoundTag nbtData; @Deprecated public BaseBlock() { @@ -82,9 +79,7 @@ public class BaseBlock implements BlockStateHolder { * * @param blockState The blockstate */ - public BaseBlock(BlockState blockState) { -// this(blockState, blockState.getNbtData()); this.blockState = blockState; } @@ -111,7 +106,7 @@ public class BaseBlock implements BlockStateHolder { this(getState(id, data)); } - public static final BlockState getState(int id, int data) { + public static BlockState getState(int id, int data) { BlockState blockState = LegacyMapper.getInstance().getBlockFromLegacy(id, data); if (blockState == null) { blockState = BlockTypes.AIR.getDefaultState(); @@ -138,6 +133,42 @@ public class BaseBlock implements BlockStateHolder { this(other.toImmutableState(), other.getNbtData()); } + /** + * Gets a map of state to statevalue + * + * @return The state map + */ + @Override + public Map, Object> getStates() { + return toImmutableState().getStates(); + } + + @Override + public BlockType getBlockType() { + return this.blockState.getBlockType(); + } + + @Override + public BaseBlock with(Property property, V value) { + return toImmutableState().with(property, value).toBaseBlock(getNbtData()); + } + + /** + * Gets the State for this Block. + * + * @param property The state to get the value for + * @return The state value + */ + @Override + public V getState(Property property) { + return toImmutableState().getState(property); + } + + @Override + public boolean hasNbtData() { + return getNbtData() != null; + } + @Override public String getNbtId() { CompoundTag nbtData = getNbtData(); @@ -180,11 +211,6 @@ public class BaseBlock implements BlockStateHolder { return this.blockState.equalsFuzzy(otherBlock.blockState) && Objects.equals(getNbtData(), otherBlock.getNbtData()); } - @Override - public final BlockState toImmutableState() { - return blockState; - } - @Override public int getInternalId() { return blockState.getInternalId(); @@ -196,17 +222,24 @@ public class BaseBlock implements BlockStateHolder { } @Override - public BlockType getBlockType() { - return blockState.getBlockType(); + public int getOrdinal() { + return blockState.getOrdinal(); } - public BlockType getType() { - return getBlockType(); + /** + * Checks if the type is the same, and if the matched states are the same. + * + * @param o other block + * @return true if equal + */ + @Override + public boolean equalsFuzzy(BlockStateHolder o) { + return this.blockState.equalsFuzzy(o); } @Override - public int getOrdinal() { - return blockState.getOrdinal(); + public BlockState toImmutableState() { + return this.blockState; } @Override @@ -227,16 +260,11 @@ public class BaseBlock implements BlockStateHolder { @Override public int hashCode() { - return getOrdinal(); - } - - @Override - public String toString() { - if (this.getNbtData() != null) { - return getAsString() + " {" + String.valueOf(getNbtData()) + "}"; - } else { - return getAsString(); + int ret = toImmutableState().hashCode() << 3; + if (hasNbtData()) { + ret += getNbtData().hashCode(); } + return ret; } @Override @@ -244,11 +272,6 @@ public class BaseBlock implements BlockStateHolder { return extent.setBlock(set, this); } - @Override - public boolean hasNbtData() { - return this.nbtData != null; - } - @Override public BaseBlock withPropertyId(int propertyId) { return getBlockType().withPropertyId(propertyId).toBaseBlock(getNbtData()); @@ -264,34 +287,23 @@ public class BaseBlock implements BlockStateHolder { return toImmutableState().getInternalPropertiesId(); } - @Override - public BaseBlock with(Property property, V value) { - return toImmutableState().with(property, value).toBaseBlock(getNbtData()); - } - @Override public BaseBlock with(PropertyKey property, V value) { return toImmutableState().with(property, value).toBaseBlock(getNbtData()); } - @Override - public V getState(Property property) { - return toImmutableState().getState(property); - } - @Override public V getState(PropertyKey property) { return toImmutableState().getState(property); } - @Override - public Map, Object> getStates() { - return toImmutableState().getStates(); - } - - @Override - public boolean equalsFuzzy(BlockStateHolder o) { - return toImmutableState().equalsFuzzy(o); - } + @Override + public String toString() { + if (getNbtData() != null) { + return getAsString() + " {" + String.valueOf(getNbtData()) + "}"; + } else { + return getAsString(); + } + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypeEnum.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypeEnum.java deleted file mode 100644 index 8e7b46314..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypeEnum.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.sk89q.worldedit.world.block; - -public enum BlockTypeEnum { - -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/FuzzyBlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/FuzzyBlockState.java index 230b479ad..cb2d43167 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/FuzzyBlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/FuzzyBlockState.java @@ -20,8 +20,6 @@ package com.sk89q.worldedit.world.block; import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.collect.Maps; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.PropertyKey; @@ -39,7 +37,7 @@ public class FuzzyBlockState extends BlockState { private final Map props; - public FuzzyBlockState(BlockType blockType) { + FuzzyBlockState(BlockType blockType) { this(blockType.getDefaultState(), null); } @@ -181,4 +179,4 @@ public class FuzzyBlockState extends BlockState { return this; } } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk.java index 9d854a7af..3a2336754 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk.java @@ -28,7 +28,6 @@ import com.sk89q.jnbt.NBTUtils; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; @@ -55,7 +54,7 @@ public class AnvilChunk implements Chunk { /** * Construct the chunk with a compound tag. - * + * * @param world the world to construct the chunk for * @param tag the tag to read * @throws DataException on a data error @@ -69,19 +68,19 @@ public class AnvilChunk implements Chunk { blocks = new byte[16][16 * 16 * 16]; blocksAdd = new byte[16][16 * 16 * 8]; data = new byte[16][16 * 16 * 8]; - + List sections = NBTUtils.getChildTag(rootTag.getValue(), "Sections", ListTag.class).getValue(); - + for (Tag rawSectionTag : sections) { if (!(rawSectionTag instanceof CompoundTag)) { continue; } - + CompoundTag sectionTag = (CompoundTag) rawSectionTag; if (!sectionTag.getValue().containsKey("Y")) { continue; // Empty section. } - + int y = NBTUtils.getChildTag(sectionTag.getValue(), "Y", ByteTag.class).getValue(); if (y < 0 || y >= 16) { continue; @@ -117,7 +116,7 @@ public class AnvilChunk implements Chunk { } } } - + private int getBlockID(BlockVector3 position) throws DataException { int x = position.getX() - rootX * 16; int y = position.getY(); @@ -127,14 +126,14 @@ public class AnvilChunk implements Chunk { if (section < 0 || section >= blocks.length) { throw new DataException("Chunk does not contain position " + position); } - + int yindex = y & 0x0F; int index = x + (z * 16 + (yindex * 16 * 16)); - + try { int addId = 0; - + // The block ID is the combination of the Blocks byte array with the // Add byte array. 'Blocks' stores the lowest 8 bits of a block's ID, and // 'Add' stores the highest 4 bits of the ID. The first block is stored @@ -144,7 +143,7 @@ public class AnvilChunk implements Chunk { } else { addId = (blocksAdd[section][index >> 1] & 0xF0) << 4; } - + return (blocks[section][index] & 0xFF) + addId; } catch (IndexOutOfBoundsException e) { throw new DataException("Chunk does not contain position " + position); @@ -158,7 +157,7 @@ public class AnvilChunk implements Chunk { int section = y >> 4; int yIndex = y & 0x0F; - + if (section < 0 || section >= blocks.length) { throw new DataException("Chunk does not contain position " + position); } @@ -264,10 +263,12 @@ public class AnvilChunk implements Chunk { } if (state.getMaterial().hasContainer()) { CompoundTag tileEntity = getBlockTileEntity(position); + if (tileEntity != null) { return state.toBaseBlock(tileEntity); } } + return state.toBaseBlock(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk13.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk13.java index ba5473839..c9e52424e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk13.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk13.java @@ -54,7 +54,7 @@ public class AnvilChunk13 implements Chunk { /** * Construct the chunk with a compound tag. - * + * * @param tag the tag to read * @throws DataException on a data error */ @@ -159,13 +159,14 @@ public class AnvilChunk13 implements Chunk { * @throws DataException */ private void populateTileEntities() throws DataException { - tileEntities = new HashMap<>(); if (!rootTag.getValue().containsKey("TileEntities")) { return; } List tags = NBTUtils.getChildTag(rootTag.getValue(), "TileEntities", ListTag.class).getValue(); + tileEntities = new HashMap<>(); + for (Tag tag : tags) { if (!(tag instanceof CompoundTag)) { throw new InvalidFormatException("CompoundTag expected in TileEntities"); @@ -221,6 +222,7 @@ public class AnvilChunk13 implements Chunk { BlockState[] sectionBlocks = blocks[section]; BlockState state = sectionBlocks != null ? sectionBlocks[(yIndex << 8) | (z << 4) | x] : BlockTypes.AIR.getDefaultState(); + if (state.getMaterial().hasContainer()) { CompoundTag tileEntity = getBlockTileEntity(position); return state.toBaseBlock(tileEntity); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/Chunk.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/Chunk.java index 6987622d3..01c721bc2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/Chunk.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/Chunk.java @@ -20,7 +20,6 @@ package com.sk89q.worldedit.world.chunk; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.block.BaseBlock; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java index 04f90411a..dfeeccca9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java @@ -61,7 +61,7 @@ public class OldChunk implements Chunk { */ public OldChunk(World world, CompoundTag tag) throws DataException { rootTag = tag; - + blocks = NBTUtils.getChildTag(rootTag.getValue(), "Blocks", ByteArrayTag.class).getValue(); data = NBTUtils.getChildTag(rootTag.getValue(), "Data", ByteArrayTag.class).getValue(); rootX = NBTUtils.getChildTag(rootTag.getValue(), "xPos", IntTag.class).getValue(); @@ -191,6 +191,7 @@ public class OldChunk implements Chunk { return state.toBaseBlock(tileEntity); } } + return state.toBaseBlock(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemCategory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemCategory.java index 1b0e4bd1e..c5efdb4b9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemCategory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemCategory.java @@ -34,7 +34,6 @@ import java.util.Set; public class ItemCategory extends Category { public static final NamespacedRegistry REGISTRY = new NamespacedRegistry<>("item tag"); - private int internalId; public ItemCategory(final String id) { super(id); @@ -57,5 +56,4 @@ public class ItemCategory extends Category { public boolean contains(BaseItem baseItem) { return this.getAll().contains(baseItem.getType()); } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java index a599d6a38..48170fe3f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java @@ -100,21 +100,17 @@ public class ItemType implements RegistryItem { } return this.blockType; } - + public void setBlockType(BlockType blockType) { this.blockType = blockType; } - + public BaseItem getDefaultState() { if (defaultState == null) { this.defaultState = new BaseItemStack(this); } return this.defaultState; } - - public void setDefaultState(BaseItem defaultState) { - this.defaultState = defaultState; - } @Override public String toString() { @@ -130,4 +126,4 @@ public class ItemType implements RegistryItem { public boolean equals(Object obj) { return obj instanceof ItemType && this.id.equals(((ItemType) obj).id); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java index 2b29803b0..64f24acc7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java @@ -834,24 +834,16 @@ public final class ItemTypes { } if (!input.split("\\[", 2)[0].contains(":")) input = "minecraft:" + input; - ItemType result = get(input); - return result; + return get(input); } - public static final @Nullable ItemType get(String id) { + public static @Nullable ItemType get(final String id) { return ItemType.REGISTRY.get(id); } @Deprecated - public static final ItemType get(final int ordinal) { + public static ItemType get(final int ordinal) { return ItemType.REGISTRY.getByInternalId(ordinal); } - public static int size() { - return ItemType.REGISTRY.size(); - } - - public static Collection values() { - return ItemType.REGISTRY.values(); - } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java index f7b2d5837..3d318ef01 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java @@ -73,17 +73,14 @@ public class BundledBlockData { private void loadFromResource() throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter()); - gsonBuilder.registerTypeAdapter(int.class, new JsonDeserializer() { - @Override - public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - JsonPrimitive primitive = (JsonPrimitive) json; - if (primitive.isString()) { - String value = primitive.getAsString(); - if (value.charAt(0) == '#') return Integer.parseInt(value.substring(1), 16); - return Integer.parseInt(value); - } - return primitive.getAsInt(); + gsonBuilder.registerTypeAdapter(int.class, (JsonDeserializer) (json, typeOfT, context) -> { + JsonPrimitive primitive = (JsonPrimitive) json; + if (primitive.isString()) { + String value = primitive.getAsString(); + if (value.charAt(0) == '#') return Integer.parseInt(value.substring(1), 16); + return Integer.parseInt(value); } + return primitive.getAsInt(); }); Gson gson = gsonBuilder.create(); URL url = BundledBlockData.class.getResource("blocks.json"); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java index ae7cb2b2b..1ab788e42 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java @@ -22,8 +22,6 @@ package com.sk89q.worldedit.world.registry; import com.sk89q.worldedit.world.item.ItemType; import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Collections; /** * A item registry that uses {@link BundledItemRegistry} to serve information @@ -46,9 +44,4 @@ public class BundledItemRegistry implements ItemRegistry { } return null; } - - @Override - public Collection registerItems() { - return Collections.emptyList(); - } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemRegistry.java index bc25c7cb1..c44be9b8c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemRegistry.java @@ -22,18 +22,9 @@ package com.sk89q.worldedit.world.registry; import com.sk89q.worldedit.world.item.ItemType; import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Collections; public interface ItemRegistry { - /** - * Register all items - */ - default Collection registerItems() { - return Collections.emptyList(); - } - /** * Gets the name for the given item. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java index d0c3f3d3a..fb7b9a83b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java @@ -94,7 +94,6 @@ public class LegacyMapper { for (Map.Entry blockEntry : dataFile.blocks.entrySet()) { try { BlockStateHolder blockState = BlockState.get(null, blockEntry.getValue()); -// BlockState blockState = WorldEdit.getInstance().getBlockFactory().parseFromInput(blockEntry.getValue(), parserContext).toImmutableState(); BlockType type = blockState.getBlockType(); if (type.hasProperty(PropertyKey.WATERLOGGED)) { blockState = blockState.with(PropertyKey.WATERLOGGED, false); @@ -160,7 +159,11 @@ public class LegacyMapper { @Nullable public int[] getLegacyFromItem(ItemType itemType) { Integer combinedId = getLegacyCombined(itemType); - return combinedId == null ? null : new int[] { combinedId >> 4, combinedId & 0xF }; + if (combinedId == null) { + return null; + } else { + return new int[]{combinedId >> 4, combinedId & 0xF}; + } } @Nullable diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ChunkStore.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ChunkStore.java index 871e4fb15..319503740 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ChunkStore.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ChunkStore.java @@ -114,7 +114,6 @@ public abstract class ChunkStore implements Closeable { return new OldChunk(world, tag); } - @Override public void close() throws IOException { } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherTypes.java index 7d8cfc4b3..d7450610d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherTypes.java @@ -37,7 +37,6 @@ public class WeatherTypes { private WeatherTypes() { } - public static @Nullable WeatherType get(final String id) { return WeatherType.REGISTRY.get(id); }