From 24a147465dc90a8822b32bcbee787ed44e5fc124 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Sat, 21 Sep 2019 21:00:45 -0400 Subject: [PATCH] Fixed a bunch of extends and removed slottableblockbag --- .../bukkit/BukkitPlayerBlockBag.java | 17 +- .../com/boydti/fawe/command/CFICommands.java | 9 +- .../boydti/fawe/object/DataAnglePattern.java | 2 +- .../boydti/fawe/object/DelegateConsumer.java | 4 +- .../com/boydti/fawe/object/FaweCommand.java | 7 +- .../boydti/fawe/object/FaweInputStream.java | 7 +- .../com/boydti/fawe/object/FaweLimit.java | 6 - .../boydti/fawe/object/FaweOutputStream.java | 2 +- .../com/boydti/fawe/object/HistoryExtent.java | 23 +- .../fawe/object/brush/CopyPastaBrush.java | 14 +- .../cfi/HeightMapMCAGenerator.java | 112 ++++----- .../object/extent/MemoryCheckingExtent.java | 2 +- .../fawe/object/extent/MultiTransform.java | 22 +- .../boydti/fawe/object/extent/NullExtent.java | 18 +- .../fawe/object/extent/PatternTransform.java | 2 +- .../fawe/object/extent/ProcessedWEExtent.java | 10 +- .../object/extent/RandomOffsetTransform.java | 4 +- .../fawe/object/extent/ScaleTransform.java | 4 +- .../fawe/object/extent/SelectTransform.java | 7 +- .../fawe/object/extent/SourceMaskExtent.java | 10 +- .../fawe/object/function/block/BiomeCopy.java | 4 +- .../function/block/CombinedBlockCopy.java | 2 +- .../function/block/SimpleBlockCopy.java | 2 +- .../fawe/object/io/serialize/Serializer.java | 50 ---- .../fawe/object/io/zstd/FrameHeader.java | 32 --- .../io/zstd/MalformedInputException.java | 19 -- .../com/boydti/fawe/object/io/zstd/Util.java | 48 ---- .../object/pattern/AngleColorPattern.java | 7 +- .../pattern/SolidRandomOffsetPattern.java | 3 +- .../pattern/SurfaceRandomOffsetPattern.java | 5 +- .../object/schematic/MinecraftStructure.java | 3 +- .../fawe/object/schematic/PNGWriter.java | 12 +- .../fawe/object/schematic/Schematic.java | 3 +- .../boydti/fawe/util/CachedTextureUtil.java | 4 - .../boydti/fawe/util/DelegateTextureUtil.java | 7 - .../java/com/boydti/fawe/util/FaweTimer.java | 3 +- .../com/boydti/fawe/util/ImgurUtility.java | 27 --- .../com/boydti/fawe/util/TextureUtil.java | 8 +- .../java/com/boydti/fawe/util/WEManager.java | 21 -- .../com/boydti/fawe/util/image/Drawable.java | 2 +- .../boydti/fawe/util/image/ImageViewer.java | 2 +- .../com/boydti/fawe/util/terrain/Erosion.java | 35 --- .../boydti/fawe/wrappers/WorldWrapper.java | 19 +- .../java/com/sk89q/worldedit/EditSession.java | 83 ++++--- .../worldedit/command/ClipboardCommands.java | 10 +- .../factory/parser/DefaultBlockParser.java | 217 ++++++++++-------- .../platform/AbstractPlayerActor.java | 2 +- .../platform/binding/ProvideBindings.java | 5 - .../extent/AbstractDelegateExtent.java | 18 +- .../com/sk89q/worldedit/extent/Extent.java | 9 +- .../sk89q/worldedit/extent/NullExtent.java | 11 + .../worldedit/extent/PassthroughExtent.java | 1 + 52 files changed, 384 insertions(+), 572 deletions(-) delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/io/serialize/Serializer.java delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/io/zstd/FrameHeader.java delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/io/zstd/MalformedInputException.java delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/io/zstd/Util.java delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/util/terrain/Erosion.java diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java index 06bc2db4c..a32f11ac0 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java @@ -19,19 +19,17 @@ package com.sk89q.worldedit.bukkit; -import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.extent.inventory.BlockBagException; import com.sk89q.worldedit.extent.inventory.OutOfBlocksException; import com.sk89q.worldedit.extent.inventory.OutOfSpaceException; -import com.sk89q.worldedit.extent.inventory.SlottableBlockBag; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.block.BlockState; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -public class BukkitPlayerBlockBag extends BlockBag implements SlottableBlockBag { +public class BukkitPlayerBlockBag extends BlockBag { private Player player; private ItemStack[] items; @@ -63,19 +61,6 @@ public class BukkitPlayerBlockBag extends BlockBag implements SlottableBlockBag return player; } - @Override - public BaseItem getItem(int slot) { - loadInventory(); - return BukkitAdapter.adapt(items[slot]); - } - - @Override - public void setItem(int slot, BaseItem block) { - loadInventory(); - BaseItemStack stack = block instanceof BaseItemStack ? (BaseItemStack) block : new BaseItemStack(block.getType(), block.getNbtData(), 1); - items[slot] = BukkitAdapter.adapt(stack); - } - @Override public void fetchBlock(BlockState blockState) throws BlockBagException { if (blockState.getBlockType().getMaterial().isAir()) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java b/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java index 86bdcf8cd..dc97e6e68 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java @@ -19,6 +19,8 @@ import com.boydti.fawe.util.StringMan; import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TextureUtil; import com.boydti.fawe.util.image.ImageUtil; +import com.google.gson.Gson; +import com.google.gson.JsonObject; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.worldedit.EmptyClipboardException; import com.sk89q.worldedit.LocalSession; @@ -925,7 +927,12 @@ public class CFICommands { ImageIO.write(image, "jpg", baos); byte[] data = baos.toByteArray(); player.print("Please wait..."); - URL url = ImgurUtility.uploadImage(data); + String json = ImgurUtility.getImgurContent(ImgurUtility.CLIENT_ID, data); + Gson gson = new Gson(); + JsonObject obj = gson.fromJson(json, JsonObject.class); + JsonObject data1 = obj.get("data").getAsJsonObject(); + String link = data1.get("link").getAsString(); + URL url = new URL(link); BBC.DOWNLOAD_LINK.send(player, url); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/DataAnglePattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/DataAnglePattern.java index 9408c14b6..84a156c37 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/DataAnglePattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/DataAnglePattern.java @@ -22,7 +22,7 @@ public class DataAnglePattern extends AbstractPattern { this.factor = (1D / distance) * (1D / 255); } - public int getSlope(BlockStateHolder block, BlockVector3 vector, Extent extent) { + public > int getSlope(T block, BlockVector3 vector, Extent extent) { int x = vector.getBlockX(); int y = vector.getBlockY(); int z = vector.getBlockZ(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/DelegateConsumer.java b/worldedit-core/src/main/java/com/boydti/fawe/object/DelegateConsumer.java index 1414df181..f7f41de30 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/DelegateConsumer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/DelegateConsumer.java @@ -3,9 +3,9 @@ package com.boydti.fawe.object; import java.util.function.Consumer; public abstract class DelegateConsumer implements Consumer { - private final Consumer parent; + private final Consumer parent; - public DelegateConsumer(Consumer parent) { + public DelegateConsumer(Consumer parent) { this.parent = parent; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweCommand.java b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweCommand.java index 03dabd764..1031be0e4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweCommand.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweCommand.java @@ -2,7 +2,6 @@ package com.boydti.fawe.object; import com.boydti.fawe.config.BBC; import com.boydti.fawe.util.TaskManager; -import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; public abstract class FaweCommand { @@ -13,7 +12,7 @@ public abstract class FaweCommand { this(perm, true); } - public FaweCommand(final String perm, final boolean safe) { + public FaweCommand(String perm, boolean safe) { this.perm = perm; this.safe = safe; } @@ -22,7 +21,7 @@ public abstract class FaweCommand { return this.perm; } - public boolean executeSafe(final Actor player, final String... args) { + public boolean executeSafe(Actor player, String... args) { try { if (!safe) { execute(player, args); @@ -42,5 +41,5 @@ public abstract class FaweCommand { return false; } - public abstract boolean execute(final Actor actor, final String... args); + public abstract boolean execute(Actor actor, String... args); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweInputStream.java b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweInputStream.java index bee1c7bc6..5f9c2d11f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweInputStream.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweInputStream.java @@ -21,10 +21,7 @@ public class FaweInputStream extends DataInputStream { } public int readMedium() throws IOException { - return (int) ( - (read() << 16) + - (read() << 8) + - read()); + return (read() << 16) + (read() << 8) + read(); } private NBTInputStream nbtIn; @@ -76,4 +73,4 @@ public class FaweInputStream extends DataInputStream { } parent.close(); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweLimit.java b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweLimit.java index f5d161c56..bd8bec10b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweLimit.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweLimit.java @@ -1,13 +1,7 @@ package com.boydti.fawe.object; -import com.sk89q.worldedit.world.block.BlockState; - -import java.util.Collections; import java.util.Set; -/** - * Created by Jesse on 4/5/2016. - */ public class FaweLimit { public int MAX_ACTIONS = 0; public int MAX_CHANGES = 0; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweOutputStream.java b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweOutputStream.java index 67ce44a5f..12a1cd619 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweOutputStream.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweOutputStream.java @@ -37,7 +37,7 @@ public class FaweOutputStream extends DataOutputStream { } public void writeVarInt(int i) throws IOException { - while((i & -128) != 0) { + while ((i & -128) != 0) { this.writeByte(i & 127 | 128); i >>>= 7; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java index d9f47b0ee..b11cb3328 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java @@ -33,7 +33,7 @@ public class HistoryExtent extends AbstractDelegateExtent { * @param extent the extent * @param changeSet the change set */ - public HistoryExtent(final Extent extent, final FaweChangeSet changeSet) { + public HistoryExtent(Extent extent, FaweChangeSet changeSet) { super(extent); checkNotNull(changeSet); this.changeSet = changeSet; @@ -43,6 +43,7 @@ public class HistoryExtent extends AbstractDelegateExtent { return changeSet; } + @Override public void setChangeSet(FaweChangeSet fcs) { this.changeSet = fcs; } @@ -51,7 +52,7 @@ public class HistoryExtent extends AbstractDelegateExtent { public > boolean setBlock(int x, int y, int z, B block) throws WorldEditException { BaseBlock previous = getFullBlock(x, y, z); if (previous.getInternalId() == block.getInternalId()) { - if (!previous.hasNbtData() && (block instanceof BaseBlock && !block.hasNbtData())) { + if (!previous.hasNbtData() && block instanceof BaseBlock && !block.hasNbtData()) { return false; } } @@ -61,15 +62,15 @@ public class HistoryExtent extends AbstractDelegateExtent { @Override - public > boolean setBlock(final BlockVector3 location, final B block) throws WorldEditException { + public > boolean setBlock(BlockVector3 location, B block) throws WorldEditException { return setBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block); } @Nullable @Override - public Entity createEntity(final Location location, final BaseEntity state) { + public Entity createEntity(Location location, BaseEntity state) { final Entity entity = super.createEntity(location, state); - if ((state != null)) { + if (state != null) { this.changeSet.addEntityCreate(state.getNbtData()); } return entity; @@ -81,13 +82,13 @@ public class HistoryExtent extends AbstractDelegateExtent { } @Override - public List getEntities(final Region region) { + public List getEntities(Region region) { return this.wrapEntities(super.getEntities(region)); } - private List wrapEntities(final List entities) { + private List wrapEntities(List entities) { final List newList = new ArrayList<>(entities.size()); - for (final Entity entity : entities) { + for (Entity entity : entities) { newList.add(new TrackedEntity(entity)); } return newList; @@ -118,7 +119,7 @@ public class HistoryExtent extends AbstractDelegateExtent { public class TrackedEntity implements Entity { private final Entity entity; - private TrackedEntity(final Entity entity) { + private TrackedEntity(Entity entity) { this.entity = entity; } @@ -142,7 +143,7 @@ public class HistoryExtent extends AbstractDelegateExtent { final Location location = this.entity.getLocation(); final BaseEntity state = this.entity.getState(); final boolean success = this.entity.remove(); - if ((state != null) && success) { + if (state != null && success) { HistoryExtent.this.changeSet.addEntityRemove(state.getNbtData()); } return success; @@ -150,7 +151,7 @@ public class HistoryExtent extends AbstractDelegateExtent { @Nullable @Override - public T getFacet(final Class cls) { + public T getFacet(Class cls) { return this.entity.getFacet(cls); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java index c8c26c4ed..3b427d4ae 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java @@ -47,8 +47,11 @@ public class CopyPastaBrush implements Brush, ResettableTool { } @Override - public void build(final EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { - Player fp = editSession.getPlayer(); + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { + Player player = editSession.getPlayer(); + if (player == null) { + return; + } ClipboardHolder clipboard = session.getExistingClipboard(); if (clipboard == null) { if (editSession.getExtent() instanceof VisualExtent) { @@ -84,8 +87,7 @@ public class CopyPastaBrush implements Brush, ResettableTool { ClipboardHolder holder = new ClipboardHolder(newClipboard); session.setClipboard(holder); int blocks = builder.size(); - BBC.COMMAND_COPY.send(fp, blocks); - return; + BBC.COMMAND_COPY.send(player, blocks); } else { AffineTransform transform = null; if (randomRotate) { @@ -95,10 +97,10 @@ public class CopyPastaBrush implements Brush, ResettableTool { } if (autoRotate) { if (transform == null) transform = new AffineTransform(); - Location loc = fp.getLocation(); + Location loc = player.getLocation(); float yaw = loc.getYaw(); float pitch = loc.getPitch(); - transform = transform.rotateY((-yaw) % 360); + transform = transform.rotateY(-yaw % 360); transform = transform.rotateX(pitch - 90); } if (transform != null && !transform.isIdentity()) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java index 50955b40f..12f1eac59 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java @@ -78,14 +78,14 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr private CFIPrimitives oldPrimitives = new CFIPrimitives(); public final class CFIPrimitives implements Cloneable { - protected int waterHeight = 0; - protected int floorThickness = 0; - protected int worldThickness = 0; - protected boolean randomVariation = true; - protected int biomePriority = 0; - protected int waterId = BlockID.WATER; - protected int bedrockId = BlockID.BEDROCK; - protected boolean modifiedMain = false; + int waterHeight; + int floorThickness; + int worldThickness; + boolean randomVariation = true; + int biomePriority; + int waterId = BlockID.WATER; + int bedrockId = BlockID.BEDROCK; + boolean modifiedMain; @Override public boolean equals(Object obj) { @@ -143,7 +143,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr return blocks.isModified() || heights.isModified() || biomes.isModified() || - (overlay != null && overlay.isModified()) || + overlay != null && overlay.isModified() || !primitives.equals(oldPrimitives); } @@ -220,10 +220,10 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr super(width, length, regionFolder); blocks = new DifferentialBlockBuffer(width, length); - heights = new DifferentialArray(new byte[getArea()]); - biomes = new DifferentialArray(new byte[getArea()]); - floor = new DifferentialArray(new int[getArea()]); - main = new DifferentialArray(new int[getArea()]); + heights = new DifferentialArray<>(new byte[getArea()]); + biomes = new DifferentialArray<>(new byte[getArea()]); + floor = new DifferentialArray<>(new int[getArea()]); + main = new DifferentialArray<>(new int[getArea()]); int stone = BlockID.STONE; int grass = BlockTypes.GRASS_BLOCK.getDefaultState().with(PropertyKey.SNOWY, false).getInternalId(); @@ -402,8 +402,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr int maxX = max.getBlockX(); int maxZ = max.getBlockZ(); - int tableWidth = (maxX - minX + 1); - int tableLength = (maxZ - minZ + 1); + int tableWidth = maxX - minX + 1; + int tableLength = maxZ - minZ + 1; int smoothArea = tableWidth * tableLength; long[] copy = new long[smoothArea]; @@ -411,10 +411,9 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr SummedAreaTable table = new SummedAreaTable(copy, layers, tableWidth, radius); for (int j = 0; j < iterations; j++) { - { // Copy to table int localIndex = 0; - int zIndex = (minZ * getWidth()); + int zIndex = minZ * getWidth(); for (int z = minZ; z <= maxZ; z++, zIndex += getWidth()) { int index = zIndex + minX; for (int x = minX; x <= maxX; x++, index++, localIndex++) { @@ -422,7 +421,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr if (BlockTypes.getFromStateId(combined) == BlockTypes.SNOW) { layers[localIndex] = (char) (((heights[index] & 0xFF) << 3) + (floor[index] >> BlockTypes.BIT_OFFSET) - 7); } else { - layers[localIndex] = (char) (((heights[index] & 0xFF) << 3)); + layers[localIndex] = (char) ((heights[index] & 0xFF) << 3); } } } @@ -431,7 +430,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr table.processSummedAreaTable(); // Copy from table int localIndex = 0; - int zIndex = (minZ * getWidth()); + int zIndex = minZ * getWidth(); for (int z = minZ, localZ = 0; z <= maxZ; z++, localZ++, zIndex += getWidth()) { int index = zIndex + minX; for (int x = minX, localX = 0; x <= maxX; x++, localX++, index++, localIndex++) { @@ -444,8 +443,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } private final void setLayerHeight(int index, int height) { - int blockHeight = (height) >> 3; - int layerHeight = (height) & 0x7; + int blockHeight = height >> 3; + int layerHeight = height & 0x7; setLayerHeight(index, blockHeight, layerHeight); } @@ -457,21 +456,21 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr case BlockID.SNOW_BLOCK: if (layerHeight != 0) { this.heights.setByte(index, (byte) (blockHeight + 1)); - this.floor.setInt(index, (BlockTypes.SNOW.getInternalId() + layerHeight)); + this.floor.setInt(index, BlockTypes.SNOW.getInternalId() + layerHeight); } else { - this.heights.setByte(index, (byte) (blockHeight)); - this.floor.setInt(index, (BlockTypes.SNOW_BLOCK.getInternalId())); + this.heights.setByte(index, (byte) blockHeight); + this.floor.setInt(index, BlockTypes.SNOW_BLOCK.getInternalId()); } break; default: - this.heights.setByte(index, (byte) (blockHeight)); + this.heights.setByte(index, (byte) blockHeight); break; } } private final void setLayerHeightRaw(int index, int height) { - int blockHeight = (height) >> 3; - int layerHeight = (height) & 0x7; + int blockHeight = height >> 3; + int layerHeight = height & 0x7; setLayerHeightRaw(index, blockHeight, layerHeight); } @@ -483,14 +482,14 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr case BlockID.SNOW_BLOCK: if (layerHeight != 0) { this.heights.getByteArray()[index] = (byte) (blockHeight + 1); - this.floor.getIntArray()[index] = (BlockTypes.SNOW.getInternalId() + layerHeight); + this.floor.getIntArray()[index] = BlockTypes.SNOW.getInternalId() + layerHeight; } else { - this.heights.getByteArray()[index] = (byte) (blockHeight); - this.floor.getIntArray()[index] = (BlockTypes.SNOW_BLOCK.getInternalId()); + this.heights.getByteArray()[index] = (byte) blockHeight; + this.floor.getIntArray()[index] = BlockTypes.SNOW_BLOCK.getInternalId(); } break; default: - this.heights.getByteArray()[index] = (byte) (blockHeight); + this.heights.getByteArray()[index] = (byte) blockHeight; break; } } @@ -512,7 +511,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr if (BlockTypes.getFromStateId(combined) == BlockTypes.SNOW) { layers[i] = (char) (((heights[i] & 0xFF) << 3) + (floor[i] >> BlockTypes.BIT_OFFSET) - 7); } else { - layers[i] = (char) (((heights[i] & 0xFF) << 3)); + layers[i] = (char) ((heights[i] & 0xFF) << 3); } } int index = 0; @@ -625,7 +624,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } public void addSchems(Mask mask, List clipboards, int rarity, int distance, boolean randomRotate) throws WorldEditException { - int scaledRarity = (256 * rarity) / 100; + int scaledRarity = 256 * rarity / 100; int index = 0; AffineTransform identity = new AffineTransform(); LocalBlockVector2DSet placed = new LocalBlockVector2DSet(); @@ -851,8 +850,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr if (chunkOffset != null && player != null && update) { World world = player.getWorld(); - int lenCX = (getWidth() + 15) >> 4; - int lenCZ = (getLength() + 15) >> 4; + int lenCX = getWidth() + 15 >> 4; + int lenCZ = getLength() + 15 >> 4; int OX = chunkOffset.getBlockX(); int OZ = chunkOffset.getBlockZ(); @@ -1013,6 +1012,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr }); } + @Override public BufferedImage draw() { // TODO NOT IMPLEMENTED // return new HeightMapMCADrawer(this).draw(); @@ -1020,11 +1020,11 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } public void setBiomePriority(int value) { - this.primitives.biomePriority = ((value * 65536) / 100) - 32768; + this.primitives.biomePriority = value * 65536 / 100 - 32768; } public int getBiomePriority() { - return ((primitives.biomePriority + 32768) * 100) / 65536; + return (primitives.biomePriority + 32768) * 100 / 65536; } public void setBlockAndBiomeColor(BufferedImage img, Mask mask, BufferedImage imgMask, boolean whiteOnly) { @@ -1107,20 +1107,17 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr throw new IllegalArgumentException("Input image dimensions do not match the current height map!"); TextureUtil textureUtil = getTextureUtil(); - biomes.record(new Runnable() { - @Override - public void run() { - byte[] biomesArr = biomes.get(); - int index = 0; - for (int y = 0; y < img.getHeight(); y++) { - for (int x = 0; x < img.getWidth(); x++) { - int color = img.getRGB(x, y); - TextureUtil.BiomeColor biome = textureUtil.getNearestBiome(color); - if (biome != null) { - biomesArr[index] = (byte) biome.id; - } - index++; + biomes.record(() -> { + byte[] biomesArr = biomes.get(); + int index = 0; + for (int y = 0; y < img.getHeight(); y++) { + for (int x = 0; x < img.getWidth(); x++) { + int color = img.getRGB(x, y); + TextureUtil.BiomeColor biome = textureUtil.getNearestBiome(color); + if (biome != null) { + biomesArr[index] = (byte) biome.id; } + index++; } } }); @@ -1598,7 +1595,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr chunk.hasSections[layer] = true; } if (primitives.waterHeight != 0) { - int maxIndex = (primitives.waterHeight) << 8; + int maxIndex = primitives.waterHeight << 8; Arrays.fill(chunk.blocks, 0, maxIndex, primitives.waterId); } @@ -1620,7 +1617,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr final boolean hasFloorThickness = primitives.floorThickness != 0 || primitives.worldThickness != 0; if (primitives.worldThickness != 0) { - int endLayer = ((minY - primitives.worldThickness + 1) >> 4); + int endLayer = minY - primitives.worldThickness + 1 >> 4; for (int layer = 0; layer < endLayer; layer++) { chunk.hasSections[layer] = false; } @@ -1652,7 +1649,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } } else { - chunk.blocks[index + ((height) << 8)] = floorCombined; + chunk.blocks[index + (height << 8)] = floorCombined; } if (primitives.worldThickness != 0) { @@ -1663,7 +1660,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } } else { - chunk.blocks[index + ((height) << 8)] = floorCombined; + chunk.blocks[index + (height << 8)] = floorCombined; } for (int y = minMainY; y < maxMainY; y++) { @@ -1672,7 +1669,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr if (hasOverlay) { int overlayCombined = overlay[globalIndex]; - int overlayIndex = index + ((height + 1) << 8); + int overlayIndex = index + (height + 1 << 8); chunk.blocks[overlayIndex] = overlayCombined; } @@ -1929,6 +1926,11 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr return false; } + @Override + public boolean setBiome(BlockVector2 position, BiomeType biome) { + return setBiome(position.getX(), 0, position.getBlockZ(), biome); + } + @Override public int getBlockLightLevel(BlockVector3 position) { return 0; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java index b065a0a10..57fb64406 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java @@ -12,7 +12,7 @@ import com.sk89q.worldedit.extent.PassthroughExtent; public class MemoryCheckingExtent extends PassthroughExtent { private final Player player; - public MemoryCheckingExtent(final Player player, final Extent extent) { + public MemoryCheckingExtent(Player player, Extent extent) { super(extent); this.player = player; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiTransform.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiTransform.java index 475a18a07..b07269faf 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiTransform.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiTransform.java @@ -1,7 +1,6 @@ package com.boydti.fawe.object.extent; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.AbstractDelegateExtent; @@ -10,7 +9,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockStateHolder; - +import java.util.Arrays; import java.util.Collection; import javax.annotation.Nullable; @@ -32,24 +31,21 @@ public class MultiTransform extends RandomTransform { } @Override - public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { - boolean result = false; - for (AbstractDelegateExtent extent : extents) result |= extent.setBlock(x, y, z, block); - return result; + public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { + return Arrays.stream(extents).map(extent -> extent.setBlock(x, y, z, block)) + .reduce(false, (a, b) -> a || b); } @Override - public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { - boolean result = false; - for (AbstractDelegateExtent extent : extents) result |= extent.setBlock(location, block); - return result; + public > boolean setBlock(BlockVector3 location, T block) throws WorldEditException { + return Arrays.stream(extents).map(extent -> extent.setBlock(location, block)) + .reduce(false, (a, b) -> a || b); } @Override public boolean setBiome(BlockVector2 position, BiomeType biome) { - boolean result = false; - for (AbstractDelegateExtent extent : extents) result |= extent.setBiome(position, biome); - return result; + return Arrays.stream(extents).map(extent -> extent.setBiome(position, biome)) + .reduce(false, (a, b) -> a || b); } @Nullable diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java index 4b198098f..d4857bbb1 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java @@ -20,17 +20,15 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.util.Countable; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BiomeType; 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 javax.annotation.Nullable; import java.util.Collection; import java.util.List; import java.util.Set; +import javax.annotation.Nullable; public class NullExtent extends FaweRegionExtent { @@ -60,7 +58,7 @@ public class NullExtent extends FaweRegionExtent { } @Override - public BiomeType getBiome(final BlockVector2 arg0) { + public BiomeType getBiome(BlockVector2 arg0) { throw reason; } @@ -70,7 +68,7 @@ public class NullExtent extends FaweRegionExtent { } @Override - public BlockState getBlock(final BlockVector3 arg0) { + public BlockState getBlock(BlockVector3 arg0) { throw reason; } @@ -93,7 +91,7 @@ public class NullExtent extends FaweRegionExtent { } @Override - public boolean setBiome(final BlockVector2 arg0, final BiomeType arg1) { + public boolean setBiome(BlockVector2 arg0, BiomeType arg1) { throw reason; } @@ -103,18 +101,18 @@ public class NullExtent extends FaweRegionExtent { } @Override - public boolean setBlock(final BlockVector3 arg0, final BlockStateHolder arg1) throws WorldEditException { + public > boolean setBlock(BlockVector3 arg0, B arg1) throws WorldEditException { throw reason; } @Override - public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(int x, int y, int z, B block) throws WorldEditException { throw reason; } @Nullable @Override - public Entity createEntity(final Location arg0, final BaseEntity arg1) { + public Entity createEntity(Location arg0, BaseEntity arg1) { throw reason; } @@ -159,7 +157,7 @@ public class NullExtent extends FaweRegionExtent { } @Override - public List getEntities(final Region arg0) { + public List getEntities(Region arg0) { throw reason; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PatternTransform.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PatternTransform.java index e763bb5ac..664070641 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PatternTransform.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PatternTransform.java @@ -16,7 +16,7 @@ public class PatternTransform extends ResettableExtent { } @Override - public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(BlockVector3 location, B block) throws WorldEditException { return pattern.apply(getExtent(), location, location); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java index 8965d7d4d..01f3c66b4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java @@ -21,7 +21,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { private final FaweLimit limit; private final AbstractDelegateExtent extent; - public ProcessedWEExtent(final Extent parent, FaweLimit limit) { + public ProcessedWEExtent(Extent parent, FaweLimit limit) { super(parent); this.limit = limit; this.extent = (AbstractDelegateExtent) parent; @@ -32,7 +32,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { } @Override - public Entity createEntity(final Location location, final BaseEntity entity) { + public Entity createEntity(Location location, BaseEntity entity) { if (entity == null) { return null; } @@ -64,7 +64,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { } @Override - public > boolean setBlock(final BlockVector3 location, final B block) throws WorldEditException { + public > boolean setBlock(BlockVector3 location, B block) throws WorldEditException { return setBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block); } @@ -75,7 +75,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { @Override public > boolean setBlock(int x, int y, int z, B block) throws WorldEditException { - boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData(); + boolean hasNbt = block instanceof BaseBlock && block.hasNbtData(); if (hasNbt) { if (!limit.MAX_BLOCKSTATES()) { WEManager.IMP.cancelEdit(this, FaweException.MAX_TILES); @@ -97,7 +97,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { } @Override - public boolean setBiome(final BlockVector2 position, final BiomeType biome) { + public boolean setBiome(BlockVector2 position, BiomeType biome) { if (!limit.MAX_CHANGES()) { WEManager.IMP.cancelEditSafe(this, FaweException.MAX_CHANGES); return false; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/RandomOffsetTransform.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/RandomOffsetTransform.java index 95e485302..e4d3d0372 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/RandomOffsetTransform.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/RandomOffsetTransform.java @@ -33,7 +33,7 @@ public class RandomOffsetTransform extends ResettableExtent { } @Override - public boolean setBlock(BlockVector3 pos, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(BlockVector3 pos, T block) throws WorldEditException { int x = pos.getBlockX() + random.nextInt(1 + (dx << 1)) - dx; int y = pos.getBlockY() + random.nextInt(1 + (dy << 1)) - dy; int z = pos.getBlockZ() + random.nextInt(1 + (dz << 1)) - dz; @@ -41,7 +41,7 @@ public class RandomOffsetTransform extends ResettableExtent { } @Override - public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { x = x + random.nextInt(1 + (dx << 1)) - dx; y = y + random.nextInt(1 + (dy << 1)) - dy; z = z + random.nextInt(1 + (dz << 1)) - dz; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ScaleTransform.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ScaleTransform.java index 3af4ebf10..874b635f3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ScaleTransform.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ScaleTransform.java @@ -60,7 +60,7 @@ public class ScaleTransform extends ResettableExtent { @Override - public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(BlockVector3 location, B block) throws WorldEditException { boolean result = false; MutableBlockVector3 pos = new MutableBlockVector3(getPos(location)); double sx = pos.getX(); @@ -96,7 +96,7 @@ public class ScaleTransform extends ResettableExtent { } @Override - public boolean setBlock(int x1, int y1, int z1, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(int x1, int y1, int z1, B block) throws WorldEditException { boolean result = false; MutableBlockVector3 pos = new MutableBlockVector3(getPos(x1, y1, z1)); double sx = pos.getX(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SelectTransform.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SelectTransform.java index 2442db994..f9817c0d4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SelectTransform.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SelectTransform.java @@ -1,8 +1,6 @@ package com.boydti.fawe.object.extent; import com.sk89q.worldedit.WorldEditException; - -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.AbstractDelegateExtent; @@ -13,7 +11,6 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockStateHolder; - import javax.annotation.Nullable; public abstract class SelectTransform extends ResettableExtent { @@ -34,12 +31,12 @@ public abstract class SelectTransform extends ResettableExtent { } @Override - public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { return getExtent(x, y, z).setBlock(x, y, z, block); } @Override - public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(BlockVector3 position, T block) throws WorldEditException { return getExtent(position).setBlock(position, block); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SourceMaskExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SourceMaskExtent.java index d706294f0..8f64589c6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SourceMaskExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SourceMaskExtent.java @@ -1,16 +1,14 @@ package com.boydti.fawe.object.extent; -import com.sk89q.worldedit.WorldEditException; +import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; - -import static com.google.common.base.Preconditions.checkNotNull; - public class SourceMaskExtent extends TemporalExtent { private Mask mask; private MutableBlockVector3 mutable = new MutableBlockVector3(); @@ -42,13 +40,13 @@ public class SourceMaskExtent extends TemporalExtent { } @Override - public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(BlockVector3 location, T block) throws WorldEditException { set(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block); return mask.test(location) && super.setBlock(location, block); } @Override - public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { set(x, y, z, block); mutable.mutX(x); mutable.mutY(y); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/BiomeCopy.java b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/BiomeCopy.java index 87f533798..57ea2ff45 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/BiomeCopy.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/BiomeCopy.java @@ -26,8 +26,8 @@ public class BiomeCopy implements RegionFunction { if (x != mPos2d.getBlockX() || z != mPos2d.getBlockZ()) { mPos2d.setComponents(x, z); BlockVector2 bv = mPos2d; - return destination.setBiome( bv, source.getBiome(bv)); + return destination.setBiome(bv, source.getBiome(bv)); } return false; } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/CombinedBlockCopy.java b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/CombinedBlockCopy.java index c42f69fb8..4dc14588f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/CombinedBlockCopy.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/CombinedBlockCopy.java @@ -23,6 +23,6 @@ public class CombinedBlockCopy implements RegionFunction { // BlockStateHolder block = source.getBlock(position); BaseBlock block = source.getFullBlock(position); function.apply(position); - return destination.setBlock(position, block); + return destination.setBlock(position.getX(),position.getY(),position.getZ(), block); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/SimpleBlockCopy.java b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/SimpleBlockCopy.java index 9f3e40af5..1784ff852 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/SimpleBlockCopy.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/SimpleBlockCopy.java @@ -17,6 +17,6 @@ public class SimpleBlockCopy implements RegionFunction { @Override public boolean apply(BlockVector3 position) throws WorldEditException { - return destination.setBlock(position, source.getFullBlock(position)); + return destination.setBlock(position.getX(),position.getY(),position.getZ(), source.getFullBlock(position)); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/io/serialize/Serializer.java b/worldedit-core/src/main/java/com/boydti/fawe/object/io/serialize/Serializer.java deleted file mode 100644 index 735505bae..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/io/serialize/Serializer.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.boydti.fawe.object.io.serialize; - -import com.boydti.fawe.util.ReflectionUtils; -import java.io.IOException; -import java.io.Serializable; -import java.lang.reflect.Field; - -/** - * Call serialize(stream) to serialize any field with @Serialize
- * Call deserialize(stream) to deserialize any field with @Serialize
- */ -public interface Serializer extends Serializable { - default void serialize(java.io.ObjectOutputStream stream) throws IOException { - try { - for (Field field : getClass().getDeclaredFields()) { - field.setAccessible(true); - if (field.getDeclaredAnnotation(Serialize.class) != null) { - Class type = field.getType(); - boolean primitive = type.isPrimitive(); - Object value = field.get(this); - if (primitive) { - stream.writeObject(value); - } else if (value == null){ - stream.writeByte(0); - } else { - stream.writeByte(1); - stream.writeObject(value); - } - } - } - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - - default void deserialize(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException { - for (Field field : getClass().getDeclaredFields()) { - if (field.getDeclaredAnnotation(Serialize.class) != null) { - Class type = field.getType(); - boolean primitive = type.isPrimitive(); - - if (primitive) { - ReflectionUtils.setField(field, this, stream.readObject()); - } else if (stream.readByte() == 1) { - ReflectionUtils.setField(field, this, stream.readObject()); - } - } - } - } -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/io/zstd/FrameHeader.java b/worldedit-core/src/main/java/com/boydti/fawe/object/io/zstd/FrameHeader.java deleted file mode 100644 index f310ea510..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/io/zstd/FrameHeader.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.boydti.fawe.object.io.zstd; - -class FrameHeader -{ - final long headerSize; - final int windowSize; - final long contentSize; - final long dictionaryId; - final boolean hasChecksum; - - public FrameHeader(long headerSize, int windowSize, long contentSize, long dictionaryId, boolean hasChecksum) - { - this.headerSize = headerSize; - this.windowSize = windowSize; - this.contentSize = contentSize; - this.dictionaryId = dictionaryId; - this.hasChecksum = hasChecksum; - } -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/io/zstd/MalformedInputException.java b/worldedit-core/src/main/java/com/boydti/fawe/object/io/zstd/MalformedInputException.java deleted file mode 100644 index bef6eff06..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/io/zstd/MalformedInputException.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.boydti.fawe.object.io.zstd; - -public class MalformedInputException extends RuntimeException { - - private final long offset; - - public MalformedInputException(long offset) { - this(offset, "Malformed input"); - } - - public MalformedInputException(long offset, String reason) { - super(reason + ": offset=" + offset); - this.offset = offset; - } - - public long getOffset() { - return offset; - } -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/io/zstd/Util.java b/worldedit-core/src/main/java/com/boydti/fawe/object/io/zstd/Util.java deleted file mode 100644 index 48475665b..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/io/zstd/Util.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.boydti.fawe.object.io.zstd; - -class Util -{ - private Util() - { - } - - public static int highestBit(int value) - { - return 31 - Integer.numberOfLeadingZeros(value); - } - - public static boolean isPowerOf2(int value) - { - return (value & (value - 1)) == 0; - } - - public static int mask(int bits) - { - return (1 << bits) - 1; - } - - public static void verify(boolean condition, long offset, String reason) - { - if (!condition) { - throw new MalformedInputException(offset, reason); - } - } - - public static MalformedInputException fail(long offset, String reason) - { - throw new MalformedInputException(offset, reason); - } -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AngleColorPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AngleColorPattern.java index 68a45aeb6..485f18845 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AngleColorPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AngleColorPattern.java @@ -6,6 +6,7 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; 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; @@ -38,7 +39,7 @@ public class AngleColorPattern extends DataAnglePattern { } @Override - public int getSlope(BlockStateHolder block, BlockVector3 vector, Extent extent) { + public > int getSlope(T block, BlockVector3 vector, Extent extent) { int slope = super.getSlope(block, vector, extent); if (slope != -1) { int x = vector.getBlockX(); @@ -46,7 +47,7 @@ public class AngleColorPattern extends DataAnglePattern { int z = vector.getBlockZ(); int height = extent.getNearestSurfaceTerrainBlock(x, z, y, 0, maxY); if (height > 0) { - BlockStateHolder below = extent.getBlock(x, height - 1, z); + BlockState below = extent.getBlock(x, height - 1, z); if (!below.getBlockType().getMaterial().isMovementBlocker()) { return Integer.MAX_VALUE; } @@ -57,7 +58,7 @@ public class AngleColorPattern extends DataAnglePattern { @Override public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException { - BlockStateHolder block = get.getBlock(extent); + BlockState block = get.getBlock(extent); int slope = getSlope(block, get, extent); if (slope == -1) return false; int color = holder.getTextureUtil().getColor(block.getBlockType()); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SolidRandomOffsetPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SolidRandomOffsetPattern.java index f53b2dd87..d17295c68 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SolidRandomOffsetPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SolidRandomOffsetPattern.java @@ -7,7 +7,6 @@ import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import java.util.SplittableRandom; @@ -58,7 +57,7 @@ public class SolidRandomOffsetPattern extends AbstractPattern { mutable.mutX(set.getX() + r.nextInt(dx2) - dx); mutable.mutY(set.getY() + r.nextInt(dy2) - dy); mutable.mutZ(set.getZ() + r.nextInt(dz2) - dz); - BlockStateHolder block = pattern.apply(mutable); + BaseBlock block = pattern.apply(mutable); if (block.getMaterial().isSolid()) { return pattern.apply(extent, get, mutable); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SurfaceRandomOffsetPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SurfaceRandomOffsetPattern.java index 7af3cba67..f9f357a64 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SurfaceRandomOffsetPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SurfaceRandomOffsetPattern.java @@ -6,7 +6,6 @@ import com.sk89q.worldedit.function.visitor.BreadthFirstSearch; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockStateHolder; import java.util.concurrent.ThreadLocalRandom; public class SurfaceRandomOffsetPattern extends AbstractPattern { @@ -57,7 +56,7 @@ public class SurfaceRandomOffsetPattern extends AbstractPattern { private boolean allowed(BlockVector3 bv) { MutableBlockVector3 v = new MutableBlockVector3(bv); - BlockStateHolder block = pattern.apply(bv); + BaseBlock block = pattern.apply(bv); if (!block.getBlockType().getMaterial().isMovementBlocker()) { return false; } @@ -101,7 +100,7 @@ public class SurfaceRandomOffsetPattern extends AbstractPattern { } private boolean canPassthrough(BlockVector3 v) { - BlockStateHolder block = pattern.apply(v); + BaseBlock block = pattern.apply(v); return !block.getBlockType().getMaterial().isMovementBlocker(); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/MinecraftStructure.java b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/MinecraftStructure.java index 9bd1f5bc4..e207bea75 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/MinecraftStructure.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/MinecraftStructure.java @@ -26,7 +26,6 @@ import com.sk89q.worldedit.registry.state.Property; 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.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.entity.EntityTypes; @@ -170,7 +169,7 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter { // Palette ArrayList> palette = new ArrayList<>(); for (BlockVector3 point : region) { - BlockStateHolder block = clipboard.getBlock(point); + BlockState block = clipboard.getBlock(point); int combined = block.getInternalId(); BlockType type = block.getBlockType(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/PNGWriter.java b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/PNGWriter.java index 76efe9b9c..0e1f2f95e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/PNGWriter.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/PNGWriter.java @@ -7,14 +7,14 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.world.block.BlockStateHolder; - -import javax.imageio.ImageIO; -import javax.imageio.stream.ImageOutputStream; -import java.awt.*; +import com.sk89q.worldedit.world.block.BlockState; +import java.awt.Color; +import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.OutputStream; +import javax.imageio.ImageIO; +import javax.imageio.stream.ImageOutputStream; public class PNGWriter implements ClipboardWriter { @@ -92,7 +92,7 @@ public class PNGWriter implements ClipboardWriter { double cpy2 = cpy1 + dpyj[zz]; for (int y = y0; y < y0 + height; y++) { mutable.mutY(y); - BlockStateHolder block = clipboard.getBlock(mutable); + BlockState block = clipboard.getBlock(mutable); if (block.getBlockType().getMaterial().isAir()) { continue; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/Schematic.java b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/Schematic.java index 29a9ab528..3365342c1 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/Schematic.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/Schematic.java @@ -31,6 +31,7 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.World; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.io.File; import java.io.FileOutputStream; @@ -264,7 +265,7 @@ public class Schematic { @Override public boolean apply(BlockVector3 mutable) throws WorldEditException { - BlockStateHolder block = clipboard.getBlock(mutable); + BlockState block = clipboard.getBlock(mutable); int xx = mutable.getBlockX() + relx; int zz = mutable.getBlockZ() + relz; if (copyBiomes && xx != mpos2d.getBlockX() && zz != mpos2d.getBlockZ()) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/CachedTextureUtil.java b/worldedit-core/src/main/java/com/boydti/fawe/util/CachedTextureUtil.java index a9ae2f2cb..4c7213169 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/CachedTextureUtil.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/CachedTextureUtil.java @@ -1,10 +1,6 @@ package com.boydti.fawe.util; -import com.boydti.fawe.FaweCache; - -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; -import com.sk89q.worldedit.world.block.BlockTypes; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import java.io.FileNotFoundException; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/DelegateTextureUtil.java b/worldedit-core/src/main/java/com/boydti/fawe/util/DelegateTextureUtil.java index 5aa095f62..7a37a9a09 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/DelegateTextureUtil.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/DelegateTextureUtil.java @@ -1,10 +1,7 @@ package com.boydti.fawe.util; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; -import com.sk89q.worldedit.world.block.BlockTypes; - import java.awt.image.BufferedImage; import java.io.File; import java.io.FileNotFoundException; @@ -123,10 +120,6 @@ public class DelegateTextureUtil extends TextureUtil { return parent.colorDistance(red1, green1, blue1, c2); } - public static int hueDistance(int red1, int green1, int blue1, int red2, int green2, int blue2) { - return TextureUtil.hueDistance(red1, green1, blue1, red2, green2, blue2); - } - @Override public long getDistance(BufferedImage image, int c1) { return parent.getDistance(image, c1); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/FaweTimer.java b/worldedit-core/src/main/java/com/boydti/fawe/util/FaweTimer.java index 4b4a1b8f1..dd785ffac 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/FaweTimer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/FaweTimer.java @@ -41,8 +41,7 @@ public class FaweTimer implements Runnable { if (tick < lastGetTPSTick + tickInterval) { return lastGetTPSValue; } - double total = 0; - for (double v : history) total += v; + double total = Arrays.stream(history).sum(); lastGetTPSValue = total / history.length; lastGetTPSTick = tick; return lastGetTPSValue; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/ImgurUtility.java b/worldedit-core/src/main/java/com/boydti/fawe/util/ImgurUtility.java index 0f719b489..31f90f183 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/ImgurUtility.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/ImgurUtility.java @@ -1,8 +1,5 @@ package com.boydti.fawe.util; -import com.boydti.fawe.object.io.FastByteArrayOutputStream; -import com.google.gson.Gson; -import com.google.gson.JsonObject; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; @@ -13,30 +10,6 @@ import java.util.stream.Collectors; public class ImgurUtility { public static final String CLIENT_ID = "50e34b65351eb07"; - public static URL uploadImage(File file) throws IOException { - return uploadImage(new FileInputStream(file)); - } - - public static URL uploadImage(InputStream inputStream) throws IOException { - inputStream = new BufferedInputStream(inputStream); - FastByteArrayOutputStream baos = new FastByteArrayOutputStream(Short.MAX_VALUE); - int i; - while ((i = inputStream.read()) != -1) { - baos.write(i); - } - baos.flush(); - return uploadImage(baos.toByteArray()); - } - - public static URL uploadImage(byte[] image) throws IOException { - String json = getImgurContent(CLIENT_ID, image); - Gson gson = new Gson(); - JsonObject obj = gson.fromJson(json, JsonObject.class); - JsonObject data = obj.get("data").getAsJsonObject(); - String link = data.get("link").getAsString(); - return new URL(link); - } - public static String getImgurContent(String clientID, byte[] image) throws IOException { String imageString = Base64.getEncoder().encodeToString(image); URL url = new URL("https://api.imgur.com/3/image"); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java b/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java index ef3fa7a7a..14e9f84cc 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java @@ -69,10 +69,10 @@ public class TextureUtil implements TextureHolder { private BiomeColor[] biomes = new BiomeColor[]{ // ID Name Temperature, rainfall, grass, foliage colors // - note: the colors here are just placeholders, they are computed in the program - new BiomeColor(0, "ocean", 0.5f, 0.5f, 0x92BD59, 0x77AB2F), + new BiomeColor(0, "ocean", 0.5f, 0.5f, 0x92BD59, 7842607), // default values of temp and rain - new BiomeColor(1, "plains", 0.8f, 0.4f, 0x92BD59, 0x77AB2F), - new BiomeColor(2, "desert", 2.0f, 0.0f, 0x92BD59, 0x77AB2F), + new BiomeColor(1, "plains", 0.8f, 0.4f, 0x92BD59, 7842607), + new BiomeColor(2, "desert", 2.0f, 0.0f, 0x92BD59, 7842607), new BiomeColor(3, "mountains", 0.2f, 0.3f, 0x92BD59, 0x77AB2F), new BiomeColor(4, "forest", 0.7f, 0.8f, 0x92BD59, 0x77AB2F), new BiomeColor(5, "taiga", 0.25f, 0.8f, 0x92BD59, 0x77AB2F), @@ -97,7 +97,7 @@ public class TextureUtil implements TextureHolder { new BiomeColor(22, "jungle_hills", 0.95f, 0.9f, 0x92BD59, 0x77AB2F), new BiomeColor(23, "jungle_edge", 0.95f, 0.8f, 0x92BD59, 0x77AB2F), new BiomeColor(24, "deep_ocean", 0.5f, 0.5f, 0x92BD59, 0x77AB2F), - new BiomeColor(25, "stone_shore", 0.2f, 0.3f, 0x92BD59, 0x77AB2F), + new BiomeColor(25, "stone_shore", 0.2f, 0.3f, 9616729, 0x77AB2F), new BiomeColor(26, "snowy_beach", 0.05f, 0.3f, 0x92BD59, 0x77AB2F), new BiomeColor(27, "birch_forest", 0.6f, 0.6f, 0x92BD59, 0x77AB2F), new BiomeColor(28, "birch_forest_hills", 0.6f, 0.6f, 0x92BD59, 0x77AB2F), diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/WEManager.java b/worldedit-core/src/main/java/com/boydti/fawe/util/WEManager.java index e813f5a70..6183518f3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/WEManager.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/WEManager.java @@ -15,7 +15,6 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import java.lang.reflect.Field; import java.util.ArrayDeque; -import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -44,26 +43,6 @@ public class WEManager { cancelEditSafe(parent, reason); } - public boolean maskContains(HashSet mask, int x, int z) { - for (RegionWrapper region : mask) { - if (x >= region.minX && x <= region.maxX && z >= region.minZ && z <= region.maxZ) { - return true; - } - } - return false; - } - - public boolean maskContains(RegionWrapper[] mask, int x, int z) { - switch (mask.length) { - case 0: - return false; - case 1: - return mask[0].isIn(x, z); - default: - return Arrays.stream(mask).anyMatch(region -> region.isIn(x, z)); - } - } - @Deprecated public Region[] getMask(Player player) { return getMask(player, FaweMaskManager.MaskType.getDefaultMaskType()); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/image/Drawable.java b/worldedit-core/src/main/java/com/boydti/fawe/util/image/Drawable.java index 2d811558a..f7c5eb8ec 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/image/Drawable.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/image/Drawable.java @@ -3,5 +3,5 @@ package com.boydti.fawe.util.image; import java.awt.image.BufferedImage; public interface Drawable { - public BufferedImage draw(); + BufferedImage draw(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/image/ImageViewer.java b/worldedit-core/src/main/java/com/boydti/fawe/util/image/ImageViewer.java index ba3771651..7190a5780 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/image/ImageViewer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/image/ImageViewer.java @@ -3,5 +3,5 @@ package com.boydti.fawe.util.image; import java.io.Closeable; public interface ImageViewer extends Closeable{ - public void view(Drawable drawable); + void view(Drawable drawable); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/terrain/Erosion.java b/worldedit-core/src/main/java/com/boydti/fawe/util/terrain/Erosion.java deleted file mode 100644 index 698cb3dfd..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/terrain/Erosion.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.boydti.fawe.util.terrain; - -import java.util.Arrays; - - -import static com.boydti.fawe.util.MathMan.pairInt; - -public final class Erosion { - private final int area; - private float[][] terrainHeight; - private float[][] waterHeight; - - private long[] queue_2; - private long[] queue; - private int queueIndex; - - public Erosion(int width, int length) { - this.area = width * length; - queue = new long[area]; - Arrays.fill(queue, -1); - - } - - public void addWater(int x, int z, float amt) { - waterHeight[x][z] += amt; - queue[queueIndex++] = pairInt(x, z); - } - - public void propogateWater() { - - } - - - -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java b/worldedit-core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java index ed3245f05..9976e9579 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java @@ -87,10 +87,16 @@ public class WorldWrapper extends AbstractWorld { } @Override - public boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException { + public > boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException { return parent.setBlock(position, block, notifyAndLight); } + @Override + public > boolean setBlock(int x, int y, int z, T block) + throws WorldEditException { + return parent.setBlock(x, y, z, block); + } + @Override public boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException { return parent.setTile(x, y, z, tile); @@ -112,7 +118,7 @@ public class WorldWrapper extends AbstractWorld { } @Override - public void simulateBlockMine(final BlockVector3 pt) { + public void simulateBlockMine(BlockVector3 pt) { TaskManager.IMP.sync(new RunnableVal() { @Override public void run(Object value) { @@ -214,7 +220,7 @@ public class WorldWrapper extends AbstractWorld { } @Override - public boolean regenerate(final Region region, final EditSession session) { + public boolean regenerate(Region region, EditSession session) { return session.regenerate(region); } @@ -234,7 +240,7 @@ public class WorldWrapper extends AbstractWorld { } @Override - public List getEntities(final Region region) { + public List getEntities(Region region) { return TaskManager.IMP.sync(new RunnableVal>() { @Override public void run(List value) { @@ -279,6 +285,11 @@ public class WorldWrapper extends AbstractWorld { return parent.setBiome(position, biome); } + @Override + public boolean setBiome(int x, int y, int z, BiomeType biome) { + return parent.setBiome(x, y , z, biome); + } + @Override public boolean notifyAndLightBlock(BlockVector3 position, BlockState previousType) throws WorldEditException { return parent.notifyAndLightBlock(position, previousType); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index 16c67f4ac..dc9adb337 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -64,6 +64,7 @@ import com.sk89q.worldedit.function.GroundFunction; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.RegionMaskingFilter; import com.sk89q.worldedit.function.block.BlockReplace; +import com.sk89q.worldedit.function.block.Counter; import com.sk89q.worldedit.function.block.Naturalizer; import com.sk89q.worldedit.function.generator.ForestGenerator; import com.sk89q.worldedit.function.generator.GardenPatchGenerator; @@ -144,8 +145,8 @@ import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -216,7 +217,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { public static final UUID CONSOLE = UUID.fromString("1-1-3-3-7"); @Deprecated - public EditSession(@Nonnull World world, @Nullable Player player, @Nullable FaweLimit limit, @Nullable FaweChangeSet changeSet, @Nullable RegionWrapper[] allowedRegions, @Nullable Boolean autoQueue, @Nullable Boolean fastmode, @Nullable Boolean checkMemory, @Nullable Boolean combineStages, @Nullable BlockBag blockBag, @Nullable EventBus bus, @Nullable EditSessionEvent event) { + public EditSession(@NotNull World world, @Nullable Player player, @Nullable FaweLimit limit, @Nullable FaweChangeSet changeSet, @Nullable RegionWrapper[] allowedRegions, @Nullable Boolean autoQueue, @Nullable Boolean fastmode, @Nullable Boolean checkMemory, @Nullable Boolean combineStages, @Nullable BlockBag blockBag, @Nullable EventBus bus, @Nullable EditSessionEvent event) { this(null, world, player, limit, changeSet, allowedRegions, autoQueue, fastmode, checkMemory, combineStages, blockBag, bus, event); } @@ -1091,7 +1092,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { } } - public int fall(final Region region, boolean fullHeight, final BlockStateHolder replace) { + public > int fall(final Region region, boolean fullHeight, final B replace) { FlatRegion flat = asFlatRegion(region); final int startPerformY = region.getMinimumPoint().getBlockY(); final int startCheckY = fullHeight ? 0 : startPerformY; @@ -1160,6 +1161,33 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { return this.changes = visitor.getAffected(); } + /** + * Count the number of blocks of a list of types in a region. + * + * @param region the region + * @param searchBlocks the list of blocks to search + * @return the number of blocks that matched the block + */ + public int countBlocks(Region region, Set searchBlocks) { + BlockMask mask = new BlockMask(this, searchBlocks); + return countBlocks(region, mask); + } + + /** + * Count the number of blocks of a list of types in a region. + * + * @param region the region + * @param searchMask mask to match + * @return the number of blocks that matched the mask + */ + public int countBlocks(Region region, Mask searchMask) { + Counter count = new Counter(); + RegionMaskingFilter filter = new RegionMaskingFilter(searchMask, count); + RegionVisitor visitor = new RegionVisitor(region, filter); + Operations.completeBlindly(visitor); // We can't throw exceptions, nor do we expect any + return count.getCount(); + } + /** * Fills an area recursively in the X/Z directions. * @@ -1259,8 +1287,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { getWorld(), // Causes clamping of Y range position.add(-apothem + 1, 0, -apothem + 1), position.add(apothem - 1, -height + 1, apothem - 1)); - Pattern pattern = BlockTypes.AIR.getDefaultState(); - return setBlocks(region, pattern); + return setBlocks(region, BlockTypes.AIR.getDefaultState()); } /** @@ -2515,7 +2542,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { for (int x = minX; x <= maxX; ++x) { for (int y = minY; y <= maxY; ++y) { for (int z = minZ; z <= maxZ; ++z) { - BlockStateHolder blk = getBlock(x, y, z); + BlockState blk = getBlock(x, y, z); BlockType type = blk.getBlockType(); int[] stateCounter = counter[type.getInternalId()]; if (stateCounter == null) { @@ -2526,8 +2553,8 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { } } } else { - for (final BlockVector3 pt : region) { - BlockStateHolder blk = this.getBlock(pt); + for (BlockVector3 pt : region) { + BlockState blk = this.getBlock(pt); BlockType type = blk.getBlockType(); int[] stateCounter = counter[type.getInternalId()]; if (stateCounter == null) { @@ -2638,8 +2665,8 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { return deformRegion(region, zero, unit, expressionString, WorldEdit.getInstance().getConfiguration().calculationTimeout); } - public int deformRegion(final Region region, final Vector3 zero, final Vector3 unit, final String expressionString, - final int timeout) throws ExpressionException, MaxChangedBlocksException { + public int deformRegion(Region region, Vector3 zero, Vector3 unit, String expressionString, + int timeout) throws ExpressionException, MaxChangedBlocksException { final Expression expression = Expression.compile(expressionString, "x", "y", "z"); expression.optimize(); @@ -2692,7 +2719,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { return hollowOutRegion(region, thickness, pattern, new SolidBlockMask(this)); } - public int hollowOutRegion(final Region region, final int thickness, final Pattern pattern, Mask mask) { + public int hollowOutRegion(Region region, int thickness, Pattern pattern, Mask mask) { try { final Set outside = new LocalBlockVectorSet(); @@ -2760,7 +2787,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { return changes; } - public int drawLine(final Pattern pattern, final BlockVector3 pos1, final BlockVector3 pos2, final double radius, final boolean filled) throws MaxChangedBlocksException { + public int drawLine(Pattern pattern, BlockVector3 pos1, BlockVector3 pos2, double radius, boolean filled) throws MaxChangedBlocksException { return drawLine(pattern, pos1, pos2, radius, filled, false); } @@ -2795,8 +2822,8 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { if (Math.max(Math.max(dx, dy), dz) == dx && notdrawn) { for (int domstep = 0; domstep <= dx; domstep++) { tipx = x1 + domstep * (x2 - x1 > 0 ? 1 : -1); - tipy = (int) Math.round(y1 + domstep * ((double) dy) / ((double) dx) * (y2 - y1 > 0 ? 1 : -1)); - tipz = (int) Math.round(z1 + domstep * ((double) dz) / ((double) dx) * (z2 - z1 > 0 ? 1 : -1)); + tipy = (int) Math.round(y1 + domstep * (double) dy / (double) dx * (y2 - y1 > 0 ? 1 : -1)); + tipz = (int) Math.round(z1 + domstep * (double) dz / (double) dx * (z2 - z1 > 0 ? 1 : -1)); vset.add(BlockVector3.at(tipx, tipy, tipz)); } @@ -2806,8 +2833,8 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { if (Math.max(Math.max(dx, dy), dz) == dy && notdrawn) { for (int domstep = 0; domstep <= dy; domstep++) { tipy = y1 + domstep * (y2 - y1 > 0 ? 1 : -1); - tipx = (int) Math.round(x1 + domstep * ((double) dx) / ((double) dy) * (x2 - x1 > 0 ? 1 : -1)); - tipz = (int) Math.round(z1 + domstep * ((double) dz) / ((double) dy) * (z2 - z1 > 0 ? 1 : -1)); + tipx = (int) Math.round(x1 + domstep * (double) dx / (double) dy * (x2 - x1 > 0 ? 1 : -1)); + tipz = (int) Math.round(z1 + domstep * (double) dz / (double) dy * (z2 - z1 > 0 ? 1 : -1)); vset.add(BlockVector3.at(tipx, tipy, tipz)); } @@ -2817,8 +2844,8 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { if (Math.max(Math.max(dx, dy), dz) == dz && notdrawn) { for (int domstep = 0; domstep <= dz; domstep++) { tipz = z1 + domstep * (z2 - z1 > 0 ? 1 : -1); - tipy = (int) Math.round(y1 + domstep * ((double) dy) / ((double) dz) * (y2-y1>0 ? 1 : -1)); - tipx = (int) Math.round(x1 + domstep * ((double) dx) / ((double) dz) * (x2-x1>0 ? 1 : -1)); + tipy = (int) Math.round(y1 + domstep * (double) dy / (double) dz * (y2-y1>0 ? 1 : -1)); + tipx = (int) Math.round(x1 + domstep * (double) dx / (double) dz * (x2-x1>0 ? 1 : -1)); vset.add(BlockVector3.at(tipx, tipy, tipz)); } @@ -2921,7 +2948,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { } final LocalBlockVectorSet returnset = new LocalBlockVectorSet(); final int ceilrad = (int) Math.ceil(radius); - for (final BlockVector3 v : vset) { + for (BlockVector3 v : vset) { final int tipx = v.getBlockX(), tipy = v.getBlockY(), tipz = v.getBlockZ(); for (int loopx = tipx - ceilrad; loopx <= tipx + ceilrad; loopx++) { for (int loopz = tipz - ceilrad; loopz <= tipz + ceilrad; loopz++) { @@ -3055,11 +3082,11 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { Direction.DOWN.toBlockVector(), }; - public boolean regenerate(final Region region) { + public boolean regenerate(Region region) { return regenerate(region, this); } - public boolean regenerate(final Region region, final EditSession session) { + public boolean regenerate(Region region, EditSession session) { return session.regenerate(region, null, null); } @@ -3073,7 +3100,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { } } - public boolean regenerate(final Region region, final BiomeType biome, final Long seed) { + public boolean regenerate(Region region, BiomeType biome, Long seed) { //TODO Optimize - avoid Vector2D creation (make mutable) final FaweChangeSet fcs = (FaweChangeSet) this.getChangeSet(); this.setChangeSet(null); @@ -3096,11 +3123,13 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { final int bz = cz << 4; final BlockVector3 cmin = BlockVector3.at(bx, 0, bz); final BlockVector3 cmax = cmin.add(15, maxY, 15); - final boolean containsBot1 = (fe == null || fe.contains(cmin.getBlockX(), cmin.getBlockY(), cmin.getBlockZ())); + final boolean containsBot1 = + fe == null || fe.contains(cmin.getBlockX(), cmin.getBlockY(), cmin.getBlockZ()); final boolean containsBot2 = region.contains(cmin); - final boolean containsTop1 = (fe == null || fe.contains(cmax.getBlockX(), cmax.getBlockY(), cmax.getBlockZ())); + final boolean containsTop1 = + fe == null || fe.contains(cmax.getBlockX(), cmax.getBlockY(), cmax.getBlockZ()); final boolean containsTop2 = region.contains(cmax); - if (((containsBot2 && containsTop2)) && !containsBot1 && !containsTop1) { + if (containsBot2 && containsTop2 && !containsBot1 && !containsTop1) { continue; } boolean conNextX = chunks.contains(mutable2D.setComponents(cx + 1, cz)); @@ -3146,7 +3175,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { fcs.add(mutable, block, BlockTypes.AIR.getDefaultState().toBaseBlock()); } } else { - BlockStateHolder block = getFullBlock(mutable); + BaseBlock block = getFullBlock(mutable); try { setBlock(mutable, block); } catch (MaxChangedBlocksException e) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java index 8d2e13860..2fee668a2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java @@ -38,6 +38,8 @@ import com.boydti.fawe.object.schematic.Schematic; import com.boydti.fawe.util.ImgurUtility; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MaskTraverser; +import com.google.gson.Gson; +import com.google.gson.JsonObject; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; @@ -361,7 +363,13 @@ public class ClipboardCommands { ClipboardWriter writer = format.getWriter(baos); writer.write(target); baos.flush(); - url = ImgurUtility.uploadImage(baos.toByteArray()); + String json = ImgurUtility + .getImgurContent(ImgurUtility.CLIENT_ID, baos.toByteArray()); + Gson gson = new Gson(); + JsonObject obj = gson.fromJson(json, JsonObject.class); + JsonObject data = obj.get("data").getAsJsonObject(); + String link = data.get("link").getAsString(); + url = new URL(link); } catch (IOException e) { e.printStackTrace(); url = null; 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 99264b712..1519405c3 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,23 +19,17 @@ package com.sk89q.worldedit.extension.factory.parser; -import com.boydti.fawe.command.SuggestInputParseException; import com.boydti.fawe.config.BBC; -import com.boydti.fawe.jnbt.JSON2NBT; -import com.boydti.fawe.jnbt.NBTException; -import com.boydti.fawe.util.MathMan; -import com.boydti.fawe.util.StringMan; - +import com.google.common.collect.Maps; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.NotABlockException; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.MobSpawnerBlock; import com.sk89q.worldedit.blocks.SignBlock; import com.sk89q.worldedit.blocks.SkullBlock; -import com.sk89q.worldedit.blocks.metadata.MobType; +import com.sk89q.worldedit.command.util.SuggestionHelper; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.input.DisallowedUsageException; import com.sk89q.worldedit.extension.input.InputParseException; @@ -43,8 +37,6 @@ import com.sk89q.worldedit.extension.input.NoMatchException; import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Capability; -import com.sk89q.worldedit.extent.inventory.BlockBag; -import com.sk89q.worldedit.extent.inventory.SlottableBlockBag; import com.sk89q.worldedit.internal.registry.InputParser; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; @@ -57,13 +49,12 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.FuzzyBlockState; +import com.sk89q.worldedit.world.entity.EntityType; +import com.sk89q.worldedit.world.entity.EntityTypes; import com.sk89q.worldedit.world.registry.LegacyMapper; - -import java.util.Arrays; import java.util.HashMap; import java.util.Locale; import java.util.Map; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -166,6 +157,71 @@ public class DefaultBlockParser extends InputParser { } } + private static Map, Object> parseProperties(BlockType type, String[] stateProperties, ParserContext context) throws NoMatchException { + Map, Object> blockStates = new HashMap<>(); + + if (stateProperties.length > 0) { // Block data not yet detected + // Parse the block data (optional) + for (String parseableData : stateProperties) { + try { + String[] parts = parseableData.split("="); + if (parts.length != 2) { + throw new NoMatchException("Bad state format in " + parseableData); + } + + @SuppressWarnings("unchecked") + Property propertyKey = (Property) type.getPropertyMap().get(parts[0]); + if (propertyKey == null) { + if (context.getActor() != null) { + throw new NoMatchException("Unknown property " + parts[0] + " for block " + type.getId()); + } else { + WorldEdit.logger.warn("Unknown property " + parts[0] + " for block " + type.getId()); + } + return Maps.newHashMap(); + } + if (blockStates.containsKey(propertyKey)) { + throw new NoMatchException("Duplicate property " + parts[0]); + } + Object value; + try { + value = propertyKey.getValueFor(parts[1]); + } catch (IllegalArgumentException e) { + throw new NoMatchException("Unknown value " + parts[1] + " for state " + parts[0]); + } + + blockStates.put(propertyKey, value); + } catch (NoMatchException e) { + throw e; // Pass-through + } catch (Exception e) { + WorldEdit.logger.warn("Unknown state '" + parseableData + "'", e); + throw new NoMatchException("Unknown state '" + parseableData + "'"); + } + } + } + + return blockStates; + } + + @Override + public Stream getSuggestions(String input) { + final int idx = input.lastIndexOf('['); + if (idx < 0) { + return SuggestionHelper.getNamespacedRegistrySuggestions(BlockType.REGISTRY, input); + } + String blockType = input.substring(0, idx); + BlockType type = BlockTypes.get(blockType.toLowerCase(Locale.ROOT)); + if (type == null) { + return Stream.empty(); + } + + String props = input.substring(idx + 1); + if (props.isEmpty()) { + return type.getProperties().stream().map(p -> input + p.getName() + "="); + } + + return SuggestionHelper.getBlockPropertySuggestions(blockType, props); + } + private BaseBlock parseLogic(String input, ParserContext context) throws InputParseException { BlockType blockType = null; Map, Object> blockStates = new HashMap<>(); @@ -182,28 +238,16 @@ public class DefaultBlockParser extends InputParser { throw new InputParseException("Invalid colon."); } else if (split.length == 1) { state = LegacyMapper.getInstance().getBlockFromLegacy(Integer.parseInt(split[0])); - } else if (MathMan.isInteger(split[0])) { - int id = Integer.parseInt(split[0]); - int data = Integer.parseInt(split[1]); - if (data < 0 || data >= 16) { - throw new InputParseException("Invalid data " + data); - } - state = LegacyMapper.getInstance().getBlockFromLegacy(id, data); } else { - BlockType type = BlockTypes.get(split[0].toLowerCase(Locale.ROOT)); - if (type != null) { - int data = Integer.parseInt(split[1]); - if (data < 0 || data >= 16) { - throw new InputParseException("Invalid data " + data); - } - state = LegacyMapper.getInstance().getBlockFromLegacy(type.getLegacyCombinedId() >> 4, data); - } + state = LegacyMapper.getInstance().getBlockFromLegacy(Integer.parseInt(split[0]), Integer.parseInt(split[1])); + } + if (state != null) { + blockType = state.getBlockType(); } } catch (NumberFormatException ignored) { } } - CompoundTag nbt = null; if (state == null) { String typeString; String stateString = null; @@ -247,8 +291,7 @@ public class DefaultBlockParser extends InputParser { blockType = blockInHand.getBlockType(); blockStates.putAll(blockInHand.getStates()); - } else if (typeString.matches("pos[0-9]+")) { - int index = Integer.parseInt(typeString.replaceAll("[a-z]+", "")); + } else if ("pos1".equalsIgnoreCase(typeString)) { // Get the block type from the "primary position" final World world = context.requireWorld(); final BlockVector3 primaryPosition; @@ -261,74 +304,53 @@ public class DefaultBlockParser extends InputParser { blockType = blockInHand.getBlockType(); blockStates.putAll(blockInHand.getStates()); - } else if (typeString.matches("slot[0-9]+")) { - int slot = Integer.parseInt(typeString.substring(4)) - 1; - Actor actor = context.requireActor(); - if (!(actor instanceof Player)) { - throw new InputParseException("The user is not a player!"); - } - Player player = (Player) actor; - BlockBag bag = player.getInventoryBlockBag(); - if (true) { - throw new InputParseException("Unsupported!"); - } - SlottableBlockBag slottable = (SlottableBlockBag) bag; - BaseItem item = slottable.getItem(slot); - - if (!item.getType().hasBlockType()) { - throw new InputParseException("You're not holding a block!"); - } - state = item.getType().getBlockType().getDefaultState(); - nbt = item.getNbtData(); } else { - BlockType type = BlockTypes.parse(typeString.toLowerCase(Locale.ROOT)); - - if (type != null) { - state = type.getDefaultState(); - } - if (state == null) { - throw new NoMatchException( - "Does not match a valid block type: '" + input + "'"); - } + // Attempt to lookup a block from ID or name. + blockType = BlockTypes.get(typeString.toLowerCase(Locale.ROOT)); } - if (nbt == null) nbt = state.getNbtData(); - if (stateString != null) { - state = BlockState.get(state.getBlockType(), "[" + stateString + "]", state); - if (context.isPreferringWildcard()) { - if (stateString.isEmpty()) { - state = new FuzzyBlockState(state); - } else { - BlockType type = state.getBlockType(); - FuzzyBlockState.Builder fuzzyBuilder = FuzzyBlockState.builder(); - fuzzyBuilder.type(type); - String[] entries = stateString.split(","); - for (String entry : entries) { - String[] split = entry.split("="); - String key = split[0]; - String val = split[1]; - Property prop = type.getProperty(key); - fuzzyBuilder.withProperty(prop, prop.getValueFor(val)); - } - state = fuzzyBuilder.build(); - } + if (blockType == null) { + throw new NoMatchException("Does not match a valid block type: '" + input + "'"); + } + + blockStates.putAll(parseProperties(blockType, stateProperties, context)); + + if (context.isPreferringWildcard()) { + FuzzyBlockState.Builder fuzzyBuilder = FuzzyBlockState.builder(); + fuzzyBuilder.type(blockType); + for (Map.Entry, Object> blockState : blockStates.entrySet()) { + @SuppressWarnings("unchecked") + Property objProp = (Property) blockState.getKey(); + fuzzyBuilder.withProperty(objProp, blockState.getValue()); + } + state = fuzzyBuilder.build(); + } else { + // No wildcards allowed => eliminate them. (Start with default state) + state = blockType.getDefaultState(); + for (Map.Entry, Object> blockState : blockStates.entrySet()) { + @SuppressWarnings("unchecked") + Property objProp = (Property) blockState.getKey(); + state = state.with(objProp, blockState.getValue()); } } } - - if (blockAndExtraData.length > 1 && blockAndExtraData[1].startsWith("{")) { - String joined = StringMan.join(Arrays.copyOfRange(blockAndExtraData, 1, blockAndExtraData.length), "|"); - try { - nbt = JSON2NBT.getTagFromJson(joined); - } catch (NBTException e) { - throw new NoMatchException(e.getMessage()); - } + // this should be impossible but IntelliJ isn't that smart + if (blockType == null) { + throw new NoMatchException("Does not match a valid block type: '" + input + "'"); } // Check if the item is allowed - BlockType blockType = state.getBlockType(); + if (context.isRestricted()) { + Actor actor = context.requireActor(); + if (actor != null && !actor.hasPermission("worldedit.anyblock") + && worldEdit.getConfiguration().disallowedBlocks.contains(blockType.getId())) { + throw new DisallowedUsageException("You are not allowed to use '" + input + "'"); + } + } - if (nbt != null) return validate(context, state.toBaseBlock(nbt)); + if (!context.isTryingLegacy()) { + return state.toBaseBlock(); + } if (blockType == BlockTypes.SIGN || blockType == BlockTypes.WALL_SIGN || BlockCategories.SIGNS.contains(blockType)) { @@ -343,22 +365,17 @@ public class DefaultBlockParser extends InputParser { // Allow setting mob spawn type if (blockAndExtraData.length > 1) { String mobName = blockAndExtraData[1]; - for (MobType mobType : MobType.values()) { - if (mobType.getName().toLowerCase().equals(mobName.toLowerCase(Locale.ROOT))) { - mobName = mobType.getName(); - break; - } + EntityType ent = EntityTypes.get(mobName.toLowerCase(Locale.ROOT)); + if (ent == null) { + throw new NoMatchException("Unknown entity type '" + mobName + "'"); } + mobName = ent.getId(); if (!worldEdit.getPlatformManager().queryCapability(Capability.USER_COMMANDS).isValidMobType(mobName)) { - String finalMobName = mobName.toLowerCase(Locale.ROOT); - throw new SuggestInputParseException("Unknown mob type '" + mobName + "'", mobName, () -> Stream.of(MobType.values()) - .map(m -> m.getName().toLowerCase(Locale.ROOT)) - .filter(s -> s.startsWith(finalMobName)) - .collect(Collectors.toList())); + throw new NoMatchException("Unknown mob type '" + mobName + "'"); } return validate(context, new MobSpawnerBlock(state, mobName)); } else { - return validate(context, new MobSpawnerBlock(state, MobType.PIG.getName())); + return validate(context, new MobSpawnerBlock(state, EntityTypes.PIG.getId())); } } else if (blockType == BlockTypes.PLAYER_HEAD || blockType == BlockTypes.PLAYER_WALL_HEAD) { // allow setting type/player/rotation diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java index eea354038..abc72d2d4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java @@ -165,7 +165,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { if (free == 2) { final BlockVector3 pos = mutablePos.setComponents(x, y - 2, z); - final BlockStateHolder state = world.getBlock(pos); + final BlockState state = world.getBlock(pos); setPosition(new Location(world, Vector3.at(x + 0.5, y - 2 + BlockTypeUtil.centralTopLimit(state), z + 0.5))); return; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/binding/ProvideBindings.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/binding/ProvideBindings.java index a70857ade..4ec9adee1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/binding/ProvideBindings.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/binding/ProvideBindings.java @@ -28,7 +28,6 @@ import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.biome.Biomes; 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.BiomeRegistry; import java.awt.image.BufferedImage; @@ -120,10 +119,6 @@ public class ProvideBindings extends Bindings { return blockState(actor, argument).getBlockType(); } - public BlockStateHolder blockStateHolder(Actor actor, String argument) { - return blockState(actor, argument); - } - public BlockState blockState(Actor actor, String argument) { return baseBlock(actor, argument).toBlockState(); } 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 f5dcea2e4..8bb3252a5 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 @@ -32,8 +32,8 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.buffer.ForgetfulExtentBuffer; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.OperationQueue; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -124,10 +124,9 @@ public class AbstractDelegateExtent implements Extent, LightingExtent { } - /* - Bounds - */ + Bounds + */ @Override public int getMaxY() { return extent.getMaxY(); @@ -157,6 +156,12 @@ public class AbstractDelegateExtent implements Extent, LightingExtent { return extent.setBiome(x, y, z, biome); } + @Override + public > boolean setBlock(BlockVector3 position, T block) + throws WorldEditException { + return extent.setBlock(position.getX(), position.getY(), position.getZ(), block); + } + @Override public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { @@ -168,6 +173,11 @@ public class AbstractDelegateExtent implements Extent, LightingExtent { return setBlock(x, y, z, getBlock(x, y, z).toBaseBlock(tile)); } + @Override + public boolean setBiome(BlockVector2 position, BiomeType biome) { + return extent.setBiome(position.getX(), 0, position.getZ(), biome); + } + /* Light */ 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 f785de7aa..3e1388fff 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,6 +19,8 @@ package com.sk89q.worldedit.extent; +import static com.google.common.base.Preconditions.checkNotNull; + import com.boydti.fawe.object.clipboard.WorldCopyClipboard; import com.boydti.fawe.object.exception.FaweException; import com.sk89q.worldedit.MaxChangedBlocksException; @@ -59,16 +61,13 @@ 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.Nullable; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; - -import static com.google.common.base.Preconditions.checkNotNull; +import javax.annotation.Nullable; /** * A world, portion of a world, clipboard, or other object that can have blocks @@ -295,7 +294,7 @@ public interface Extent extends InputExtent, OutputExtent { int clearanceAbove = maxY - y; int clearanceBelow = y - minY; int clearance = Math.min(clearanceAbove, clearanceBelow); - BlockStateHolder block = getBlock(x, y, z); + BlockState block = getBlock(x, y, z); boolean state = !block.getBlockType().getMaterial().isMovementBlocker(); int offset = state ? 0 : 1; for (int d = 0; d <= clearance; d++) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/NullExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/NullExtent.java index 870ed65dc..f1289383d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/NullExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/NullExtent.java @@ -92,6 +92,12 @@ public class NullExtent implements Extent { return false; } + @Override + public > boolean setBlock(int x, int y, int z, T block) + throws WorldEditException { + return false; + } + @Override public boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException { return false; @@ -102,6 +108,11 @@ public class NullExtent implements Extent { return false; } + @Override + public boolean setBiome(int x, int y, int z, BiomeType biome) { + return false; + } + @Nullable @Override public Operation commit() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/PassthroughExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/PassthroughExtent.java index 3766e00b7..26d5ddca8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/PassthroughExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/PassthroughExtent.java @@ -186,6 +186,7 @@ public class PassthroughExtent extends AbstractDelegateExtent { return getExtent().cancel(); } + @Override public int getMaxY() { return getExtent().getMaxY(); }