From e0f6869573ef32c5d314de5e1c48ed285c89f8e7 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Thu, 23 Jan 2020 14:41:57 -0500 Subject: [PATCH] Revert "More code quality fixes" This reverts commit 2d6957ce --- .../com/boydti/fawe/bukkit/FaweBukkit.java | 16 +- .../adapter/mc1_13/BukkitAdapter_1_13.java | 6 +- .../adapter/mc1_14/BukkitAdapter_1_14.java | 5 +- .../adapter/mc1_15/BukkitAdapter_1_15.java | 4 +- .../adapter/mc1_15/BukkitGetBlocks_1_15.java | 4 +- .../fawe/bukkit/listener/BrushListener.java | 7 +- .../bukkit/listener/BukkitImageListener.java | 2 +- .../fawe/bukkit/listener/ChunkListener.java | 5 +- .../fawe/bukkit/listener/ChunkListener_9.java | 3 +- .../fawe/bukkit/listener/RenderListener.java | 3 +- .../bukkit/regions/BukkitMaskManager.java | 3 +- .../bukkit/util/BukkitReflectionUtils.java | 2 +- .../com/boydti/fawe/bukkit/util/ItemUtil.java | 2 +- .../bukkit/util/image/BukkitImageViewer.java | 17 +- .../sk89q/worldedit/bukkit/BukkitAdapter.java | 4 +- .../bukkit/BukkitServerInterface.java | 3 - .../worldedit/bukkit/WorldEditPlugin.java | 18 +- .../bukkit/adapter/CachedBukkitAdapter.java | 2 +- .../src/main/java/com/boydti/fawe/Fawe.java | 21 +- .../main/java/com/boydti/fawe/FaweCache.kt | 66 +-- .../com/boydti/fawe/beta/CombinedBlocks.java | 5 +- .../com/boydti/fawe/beta/IBatchProcessor.java | 2 +- .../java/com/boydti/fawe/beta/IBlocks.java | 4 +- .../com/boydti/fawe/beta/IQueueExtent.java | 2 +- .../implementation/blocks/BitSetBlocks.java | 2 +- .../blocks/FallbackChunkGet.java | 2 +- .../implementation/chunk/ChunkHolder.java | 3 - .../processors/LimitExtent.java | 27 +- .../queue/ParallelQueueExtent.java | 2 +- .../fawe/jnbt/CorruptSchematicStreamer.java | 312 ++++++++++++++ .../com/boydti/fawe/jnbt/anvil/MCAChunk.java | 12 +- .../com/boydti/fawe/jnbt/anvil/MCAFile.java | 2 +- .../java/com/boydti/fawe/object/BytePair.java | 42 ++ .../com/boydti/fawe/object/FaweLimit.java | 24 +- .../com/boydti/fawe/object/IntegerPair.java | 33 ++ .../com/boydti/fawe/object/IntegerTrio.java | 60 +++ .../com/boydti/fawe/object/NullChangeSet.java | 3 +- .../fawe/object/brush/AbstractBrush.java | 20 + .../boydti/fawe/object/brush/RaiseBrush.java | 5 + .../fawe/object/brush/ShatterBrush.java | 2 +- .../boydti/fawe/object/brush/SplineBrush.java | 3 +- .../brush/heightmap/ScalableHeightMap.java | 6 +- .../cfi/HeightMapMCAGenerator.java | 10 +- .../object/change/MutableBiomeChange.java | 2 +- .../object/changeset/BlockBagChangeSet.java | 4 +- .../object/changeset/DiskStorageHistory.java | 15 +- .../object/changeset/FaweStreamChangeSet.java | 6 +- .../clipboard/CPUOptimizedClipboard.java | 14 +- .../clipboard/DiskOptimizedClipboard.java | 73 ++-- .../clipboard/MemoryOptimizedClipboard.java | 19 +- .../object/clipboard/ReadOnlyClipboard.java | 5 +- .../object/clipboard/SimpleClipboard.java | 2 - .../object/clipboard/WorldCutClipboard.java | 55 +++ .../fawe/object/collection/AdaptedMap.java | 3 +- .../fawe/object/collection/BlockSet.java | 2 - .../object/collection/BlockVectorSet.java | 8 +- .../collection/CleanableThreadLocal.java | 4 +- .../object/collection/DifferentialArray.java | 2 +- .../collection/DifferentialBlockBuffer.java | 2 +- .../collection/LocalBlockVectorSet.java | 12 +- .../fawe/object/collection/LongHashSet.java | 4 +- .../fawe/object/collection/MemBlockSet.java | 22 +- .../fawe/object/collection/PrimitiveList.java | 338 ++++++++++++++++ .../fawe/object/collection/SparseBitSet.java | 383 +++++++++--------- .../fawe/object/collection/YieldIterable.java | 8 +- .../fawe/object/extent/FaweRegionExtent.java | 24 +- .../object/extent/MemoryCheckingExtent.java | 2 +- .../boydti/fawe/object/extent/NullExtent.java | 2 +- .../fawe/object/extent/ProcessedWEExtent.java | 15 +- .../fawe/object/visitor/DFSVisitor.java | 14 +- .../boydti/fawe/util/EditSessionBuilder.java | 8 +- .../java/com/boydti/fawe/util/MathMan.java | 8 - .../java/com/boydti/fawe/web/SchemSync.java | 2 +- .../java/com/sk89q/jnbt/ByteArrayTag.java | 5 + .../src/main/java/com/sk89q/jnbt/ByteTag.java | 4 + .../main/java/com/sk89q/jnbt/CompoundTag.java | 5 + .../main/java/com/sk89q/jnbt/DoubleTag.java | 4 + .../src/main/java/com/sk89q/jnbt/EndTag.java | 5 + .../main/java/com/sk89q/jnbt/FloatTag.java | 4 + .../main/java/com/sk89q/jnbt/IntArrayTag.java | 5 + .../src/main/java/com/sk89q/jnbt/IntTag.java | 4 + .../src/main/java/com/sk89q/jnbt/ListTag.java | 5 + .../java/com/sk89q/jnbt/LongArrayTag.java | 5 + .../src/main/java/com/sk89q/jnbt/LongTag.java | 4 + .../java/com/sk89q/jnbt/NBTOutputStream.java | 2 +- .../main/java/com/sk89q/jnbt/ShortTag.java | 4 + .../main/java/com/sk89q/jnbt/StringTag.java | 5 + .../src/main/java/com/sk89q/jnbt/Tag.java | 2 + .../java/com/sk89q/util/yaml/YAMLNode.java | 24 +- .../java/com/sk89q/worldedit/EditSession.java | 2 +- .../worldedit/command/ClipboardCommands.java | 6 +- .../worldedit/command/RegionCommands.java | 2 +- .../worldedit/command/TransformCommands.java | 14 +- .../worldedit/command/WorldEditCommands.java | 5 +- .../command/factory/ReplaceFactory.java | 4 +- .../command/factory/TreeGeneratorFactory.java | 2 +- .../worldedit/command/tool/BrushTool.java | 18 +- .../worldedit/command/tool/DistanceWand.java | 2 +- .../command/tool/FloatingTreeRemover.java | 2 +- .../command/tool/brush/GravityBrush.java | 6 +- .../command/tool/brush/SphereBrush.java | 2 +- .../extent/AbstractDelegateExtent.java | 13 +- .../com/sk89q/worldedit/extent/Extent.java | 2 +- .../extent/clipboard/BlockArrayClipboard.java | 2 - .../worldedit/extent/clipboard/Clipboard.java | 16 +- .../extent/inventory/BlockBagExtent.java | 5 +- .../sk89q/worldedit/math/BlockVector3.java | 200 ++++----- .../sk89q/worldedit/math/BlockVector3Imp.java | 92 +++++ .../worldedit/math/DelegateBlockVector3.java | 5 - .../worldedit/math/MutableBlockVector3.java | 18 +- .../sk89q/worldedit/math/MutableVector3.java | 4 +- .../worldedit/math/OffsetBlockVector3.java | 1 - .../worldedit/regions/AbstractRegion.java | 8 +- .../sk89q/worldedit/regions/CuboidRegion.java | 6 +- .../com/sk89q/worldedit/regions/Region.java | 16 +- 115 files changed, 1688 insertions(+), 686 deletions(-) create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/jnbt/CorruptSchematicStreamer.java create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/BytePair.java create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/IntegerPair.java create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/IntegerTrio.java create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/brush/AbstractBrush.java create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCutClipboard.java create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/collection/PrimitiveList.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3Imp.java diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java index 776ab7218..266fbecd1 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java @@ -48,7 +48,6 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; -import org.inventivetalent.mapmanager.MapManagerPlugin; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,7 +56,6 @@ public class FaweBukkit implements IFawe, Listener { private static final Logger log = LoggerFactory.getLogger(FaweBukkit.class); private final Plugin plugin; - private final String separator = System.lineSeparator(); private VaultUtil vault; private ItemUtil itemUtil; @@ -75,7 +73,11 @@ public class FaweBukkit implements IFawe, Listener { Settings.IMP.TICK_LIMITER.ENABLED = !Bukkit.hasWhitelist(); Fawe.set(this); Fawe.setupInjector(); - plugin.getServer().getPluginManager().registerEvents(this, plugin); + try { + new BrushListener(plugin); + } catch (Throwable e) { + log.debug("Brush Listener Failed", e); + } if (PaperLib.isPaper() && Settings.IMP.EXPERIMENTAL.DYNAMIC_CHUNK_RENDERING > 1) { new RenderListener(plugin); } @@ -140,7 +142,7 @@ public class FaweBukkit implements IFawe, Listener { fos.write(jarData); } } - ImageViewer viewer = new BukkitImageViewer(BukkitAdapter.adapt(player), ((MapManagerPlugin) manager.getPlugin("MapManager")).getMapManager()); + BukkitImageViewer viewer = new BukkitImageViewer(BukkitAdapter.adapt(player)); if (imageListener == null) { this.imageListener = new BukkitImageListener(plugin); } @@ -208,11 +210,11 @@ public class FaweBukkit implements IFawe, Listener { @Override public String getDebugInfo() { StringBuilder msg = new StringBuilder(); - msg.append("Server Version: ").append(Bukkit.getVersion()).append(separator); - msg.append("Plugins: " + separator); + msg.append("Server Version: ").append(Bukkit.getVersion()).append("\n"); + msg.append("Plugins: \n"); for (Plugin p : Bukkit.getPluginManager().getPlugins()) { msg.append(" - ").append(p.getName()).append(": ") - .append(p.getDescription().getVersion()).append(separator); + .append(p.getDescription().getVersion()).append("\n"); } return msg.toString(); } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_13/BukkitAdapter_1_13.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_13/BukkitAdapter_1_13.java index 4bf1b23e9..775416f8f 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_13/BukkitAdapter_1_13.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_13/BukkitAdapter_1_13.java @@ -15,6 +15,7 @@ import io.papermc.lib.PaperLib; import net.jpountz.util.UnsafeUtils; import net.minecraft.server.v1_13_R2.Block; import net.minecraft.server.v1_13_R2.Chunk; +import net.minecraft.server.v1_13_R2.ChunkCoordIntPair; import net.minecraft.server.v1_13_R2.ChunkSection; import net.minecraft.server.v1_13_R2.DataBits; import net.minecraft.server.v1_13_R2.DataPalette; @@ -29,6 +30,7 @@ import org.bukkit.craftbukkit.v1_13_R2.CraftWorld; import sun.misc.Unsafe; import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.concurrent.CompletableFuture; import java.util.concurrent.locks.Lock; @@ -208,8 +210,8 @@ public final class BukkitAdapter_1_13 extends NMSAdapter { } final int[] blockToPalette = FaweCache.INSTANCE.getBLOCK_TO_PALETTE().get(); final int[] paletteToBlock = FaweCache.INSTANCE.getPALETTE_TO_BLOCK().get(); - final long[] blockStates = FaweCache.INSTANCE.getBlockStates().get(); - final int[] blocksCopy = FaweCache.INSTANCE.getSectionBlocks().get(); + final long[] blockStates = FaweCache.INSTANCE.getBLOCK_STATES().get(); + final int[] blocksCopy = FaweCache.INSTANCE.getSECTION_BLOCKS().get(); try { int[] num_palette_buffer = new int[1]; int air; diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitAdapter_1_14.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitAdapter_1_14.java index 06abc80ff..64e2a12c5 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitAdapter_1_14.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitAdapter_1_14.java @@ -30,6 +30,7 @@ import org.bukkit.craftbukkit.v1_14_R1.CraftWorld; import sun.misc.Unsafe; import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.concurrent.CompletableFuture; import java.util.concurrent.locks.Lock; @@ -202,8 +203,8 @@ public final class BukkitAdapter_1_14 extends NMSAdapter { } final int[] blockToPalette = FaweCache.INSTANCE.getBLOCK_TO_PALETTE().get(); final int[] paletteToBlock = FaweCache.INSTANCE.getPALETTE_TO_BLOCK().get(); - final long[] blockStates = FaweCache.INSTANCE.getBlockStates().get(); - final int[] blocksCopy = FaweCache.INSTANCE.getSectionBlocks().get(); + final long[] blockStates = FaweCache.INSTANCE.getBLOCK_STATES().get(); + final int[] blocksCopy = FaweCache.INSTANCE.getSECTION_BLOCKS().get(); try { int[] num_palette_buffer = new int[1]; int air; diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitAdapter_1_15.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitAdapter_1_15.java index 9fde9c90d..7e89ec3a6 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitAdapter_1_15.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitAdapter_1_15.java @@ -181,8 +181,8 @@ public final class BukkitAdapter_1_15 extends NMSAdapter { } final int[] blockToPalette = FaweCache.INSTANCE.getBLOCK_TO_PALETTE().get(); final int[] paletteToBlock = FaweCache.INSTANCE.getPALETTE_TO_BLOCK().get(); - final long[] blockStates = FaweCache.INSTANCE.getBlockStates().get(); - final int[] blocksCopy = FaweCache.INSTANCE.getSectionBlocks().get(); + final long[] blockStates = FaweCache.INSTANCE.getBLOCK_STATES().get(); + final int[] blocksCopy = FaweCache.INSTANCE.getSECTION_BLOCKS().get(); try { int[] num_palette_buffer = new int[1]; int air; diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitGetBlocks_1_15.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitGetBlocks_1_15.java index 6470812be..24102e985 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitGetBlocks_1_15.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitGetBlocks_1_15.java @@ -96,7 +96,7 @@ public class BukkitGetBlocks_1_15 extends CharGetBlocks { BiomeStorage index = getChunk().getBiomeIndex(); BiomeBase base = null; if (y == -1) { - for (y = 0; y < FaweCache.worldHeight; y++) { + for (y = 0; y < FaweCache.WORLD_HEIGHT; y++) { base = index.getBiome(x, y, z); if (base != null) break; } @@ -324,7 +324,7 @@ public class BukkitGetBlocks_1_15 extends CharGetBlocks { if (biome != null) { final Biome craftBiome = BukkitAdapter.adapt(biome); BiomeBase nmsBiome = CraftBlock.biomeToBiomeBase(craftBiome); - for (int y = 0; y < FaweCache.worldHeight; y++) { + for (int y = 0; y < FaweCache.WORLD_HEIGHT; y++) { currentBiomes.setBiome(x, y, z, nmsBiome); } } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BrushListener.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BrushListener.java index a1435ffad..345775726 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BrushListener.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BrushListener.java @@ -20,6 +20,9 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.plugin.Plugin; public class BrushListener implements Listener { + public BrushListener(Plugin plugin) { + Bukkit.getPluginManager().registerEvents(this, plugin); + } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerItemHoldEvent(final PlayerItemHeldEvent event) { @@ -34,7 +37,7 @@ public class BrushListener implements Listener { final int slot = event.getNewSlot(); final int oldSlot = event.getPreviousSlot(); final int ri; - if (slot - oldSlot <= 4 && slot - oldSlot > 0 || slot - oldSlot < -4) { + if ((((slot - oldSlot) <= 4) && ((slot - oldSlot) > 0)) || (((slot - oldSlot) < -4))) { ri = 1; } else { ri = -1; @@ -50,7 +53,7 @@ public class BrushListener implements Listener { public void onPlayerMove(PlayerMoveEvent event) { Location from = event.getFrom(); Location to = event.getTo(); - if (from.getYaw() != to.getYaw() && from.getPitch() != to.getPitch() || from.getBlockX() != to.getBlockX() || from.getBlockZ() != to.getBlockZ() || from.getBlockY() != to.getBlockY()) { + if ((from.getYaw() != to.getYaw() && from.getPitch() != to.getPitch()) || from.getBlockX() != to.getBlockX() || from.getBlockZ() != to.getBlockZ() || from.getBlockY() != to.getBlockY()) { Player bukkitPlayer = event.getPlayer(); com.sk89q.worldedit.entity.Player player = BukkitAdapter.adapt(bukkitPlayer); LocalSession session = player.getSession(); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java index 00d2bbb0f..ebbf41fb3 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java @@ -286,7 +286,7 @@ public class BukkitImageListener implements Listener { EditSession es = new EditSessionBuilder(bukkitPlayer.getWorld()).player(bukkitPlayer) .combineStages(false).autoQueue(false).blockBag(null).limitUnlimited() .build(); - ExtentTraverser last = new ExtentTraverser<>(es.getExtent()).last(); + ExtentTraverser last = new ExtentTraverser(es.getExtent()).last(); Extent extent = last.get(); if (extent instanceof IQueueExtent) { last = last.previous(); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/ChunkListener.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/ChunkListener.java index c1c526e7c..0d37d4379 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/ChunkListener.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/ChunkListener.java @@ -54,7 +54,6 @@ public abstract class ChunkListener implements Listener { public ChunkListener() { if (Settings.IMP.TICK_LIMITER.ENABLED) { PluginManager plm = Bukkit.getPluginManager(); - assert Fawe.imp() != null; Plugin plugin = Fawe.imp().getPlugin(); plm.registerEvents(this, plugin); try { @@ -294,8 +293,8 @@ public abstract class ChunkListener implements Listener { if (elem != null) { String methodName = elem.getMethodName(); // setAir | setTypeAndData (hacky, but this needs to be efficient) - if (methodName.charAt(0) == 's' && (methodName.length() == 6 - || methodName.length() == 14)) { + if (methodName.charAt(0) == 's' && methodName.length() == 6 + || methodName.length() == 14) { return true; } } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/ChunkListener_9.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/ChunkListener_9.java index f76fb3fa9..accc84b90 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/ChunkListener_9.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/ChunkListener_9.java @@ -9,6 +9,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockPhysicsEvent; +// public class ChunkListener_9 extends ChunkListener { private Exception exception; @@ -87,4 +88,4 @@ public class ChunkListener_9 extends ChunkListener { StackTraceElement[] elems = getElements(ex); return elems.length > i ? elems[i] : null; } -} +} \ No newline at end of file diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/RenderListener.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/RenderListener.java index 5d5a24f51..e89b90745 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/RenderListener.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/RenderListener.java @@ -9,7 +9,6 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -100,7 +99,7 @@ public class RenderListener implements Listener { player.setViewDistance(value); } - private int getViewDistance(Entity player) { + private int getViewDistance(Player player) { int[] value = views.get(player.getUniqueId()); return value == null ? Settings.IMP.EXPERIMENTAL.DYNAMIC_CHUNK_RENDERING : value[0]; } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/BukkitMaskManager.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/BukkitMaskManager.java index 02c9d69d7..95a31d98e 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/BukkitMaskManager.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/BukkitMaskManager.java @@ -2,7 +2,6 @@ package com.boydti.fawe.bukkit.regions; import com.boydti.fawe.regions.FaweMaskManager; import org.bukkit.entity.Player; -import org.bukkit.permissions.Permissible; public abstract class BukkitMaskManager extends FaweMaskManager { @@ -10,7 +9,7 @@ public abstract class BukkitMaskManager extends FaweMaskManager { super(plugin); } - public boolean hasMemberPermission(Permissible player) { + public boolean hasMemberPermission(Player player) { return player.hasPermission("fawe." + getKey() + ".member"); } } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/BukkitReflectionUtils.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/BukkitReflectionUtils.java index d62e54853..43a1d5968 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/BukkitReflectionUtils.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/BukkitReflectionUtils.java @@ -30,7 +30,7 @@ public class BukkitReflectionUtils { try { final Method getHandle = bukkitServerClass.getDeclaredMethod("getHandle"); final Object handle = getHandle.invoke(server); - final Class handleServerClass = handle.getClass(); + final Class handleServerClass = handle.getClass(); pas = handleServerClass.getName().split("\\."); if (pas.length == 5) { final String verM = pas[3]; diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/ItemUtil.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/ItemUtil.java index e3f890537..2e709913c 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/ItemUtil.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/ItemUtil.java @@ -26,7 +26,7 @@ public class ItemUtil { private final Field fieldHandle; private final BukkitImplAdapter adapter; - private SoftReference>> hashToNMSTag = new SoftReference<>(new Int2ObjectOpenHashMap<>()); + private SoftReference>> hashToNMSTag = new SoftReference(new Int2ObjectOpenHashMap<>()); public ItemUtil() throws Exception { this.adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/image/BukkitImageViewer.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/image/BukkitImageViewer.java index 9d6c211e8..b49a35b3f 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/image/BukkitImageViewer.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/image/BukkitImageViewer.java @@ -15,7 +15,6 @@ import org.bukkit.Rotation; import org.bukkit.World; import org.bukkit.block.BlockFace; import org.bukkit.entity.Entity; -import org.bukkit.entity.HumanEntity; import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -33,12 +32,12 @@ public class BukkitImageViewer implements ImageViewer { private ItemFrame[][] frames; private boolean reverse; - public BukkitImageViewer(Player player, MapManager mapManager) { - this.mapManager = mapManager; + public BukkitImageViewer(Player player) { + mapManager = ((MapManagerPlugin) Bukkit.getPluginManager().getPlugin("MapManager")).getMapManager(); this.player = player; } - public void selectFrame(Entity start) { + public void selectFrame(ItemFrame start) { Location pos1 = start.getLocation().clone(); Location pos2 = start.getLocation().clone(); @@ -109,7 +108,7 @@ public class BukkitImageViewer implements ImageViewer { Collection entities = world.getNearbyEntities(pos, 0.1, 0.1, 0.1); boolean contains = false; for (Entity ent : entities) { - if (ent instanceof ItemFrame && ent.getFacing() == facing) { + if (ent instanceof ItemFrame && ((ItemFrame) ent).getFacing() == facing) { ItemFrame itemFrame = (ItemFrame) ent; itemFrame.setRotation(Rotation.NONE); contains = true; @@ -138,7 +137,7 @@ public class BukkitImageViewer implements ImageViewer { boolean initializing = last == null; if (this.frames != null) { - if (image == null) image = drawable.draw(); + if (image == null && drawable != null) image = drawable.draw(); last = image; int width = frames.length; int height = frames[0].length; @@ -159,7 +158,7 @@ public class BukkitImageViewer implements ImageViewer { } else if (player.getInventory().getHeldItemSlot() != slot) { player.getInventory().setHeldItemSlot(slot); } - if (image == null) image = drawable.draw(); + if (image == null && drawable != null) image = drawable.draw(); last = image; BufferedImage scaled = ImageUtil.getScaledInstance(image, 128, 128, RenderingHints.VALUE_INTERPOLATION_BILINEAR, false); MapWrapper mapWrapper = mapManager.wrapImage(scaled); @@ -170,7 +169,7 @@ public class BukkitImageViewer implements ImageViewer { } } - private int getMapSlot(HumanEntity player) { + private int getMapSlot(Player player) { PlayerInventory inventory = player.getInventory(); for (int i = 0; i < 9; i++) { ItemStack item = inventory.getItem(i); @@ -189,4 +188,4 @@ public class BukkitImageViewer implements ImageViewer { public void close() throws IOException { last = null; } -} +} \ No newline at end of file diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java index a0ea8f5f7..dc2a46c9e 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java @@ -376,7 +376,7 @@ public enum BukkitAdapter { * @param block The WorldEdit BlockStateHolder * @return The Bukkit BlockData */ - public static > BlockData adapt(@NotNull T block) { + public static BlockData adapt(@NotNull BlockStateHolder block) { return getAdapter().adapt(block); } @@ -409,4 +409,4 @@ public enum BukkitAdapter { public static ItemStack adapt(BaseItemStack item) { return getAdapter().adapt(item); } -} +} \ No newline at end of file diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java index 82716c789..d26bb36df 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java @@ -70,9 +70,6 @@ public class BukkitServerInterface implements MultiUserPlatform { dynamicCommands = new CommandRegistration(plugin); } - CommandRegistration getDynamicCommands() { - return dynamicCommands; - } boolean isHookingEvents() { return hookingEvents; } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index 43cb8e16a..de1c01f77 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -87,7 +87,6 @@ import org.bukkit.event.Listener; import org.bukkit.event.world.WorldInitEvent; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.MetadataValue; -import org.bukkit.metadata.Metadatable; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginManager; @@ -576,7 +575,7 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter return wePlayer; } - public BukkitPlayer getCachedPlayer(Metadatable player) { + public BukkitPlayer getCachedPlayer(Player player) { List meta = player.getMetadata("WE"); if (meta == null || meta.isEmpty()) { return null; @@ -649,24 +648,15 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter String buffer = event.getBuffer(); int firstSpace = buffer.indexOf(' '); if (firstSpace < 0) return; - String label = buffer.substring(1, firstSpace); - Plugin owner = server.getDynamicCommands().getCommandOwner(label); - if (owner != WorldEditPlugin.this) { - return; - } - int plSep = label.indexOf(":"); - if (plSep >= 0 && plSep < label.length() + 1) { - label = label.substring(plSep + 1); - buffer = "/" + buffer.substring(plSep + 2); - } + final String label = buffer.substring(0, firstSpace); final Optional command = WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().getCommand(label); if (!command.isPresent()) return; - CommandSuggestionEvent suggestEvent = new CommandSuggestionEvent(wrapCommandSender(event.getSender()), buffer); + CommandSuggestionEvent suggestEvent = new CommandSuggestionEvent(wrapCommandSender(event.getSender()), event.getBuffer()); getWorldEdit().getEventBus().post(suggestEvent); - event.setCompletions(CommandUtil.fixSuggestions(buffer, suggestEvent.getSuggestions())); + event.setCompletions(CommandUtil.fixSuggestions(event.getBuffer(), suggestEvent.getSuggestions())); event.setHandled(true); } } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/CachedBukkitAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/CachedBukkitAdapter.java index 295f1b38f..43beef3b7 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/CachedBukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/CachedBukkitAdapter.java @@ -79,7 +79,7 @@ public abstract class CachedBukkitAdapter implements IBukkitAdapter { Material material = blockData.getMaterial(); BlockType type = BlockTypes.getFromStateId(blockTypes[material.ordinal()]); List propList = type.getProperties(); - if (propList.isEmpty()) return type.getDefaultState(); + if (propList.size() == 0) return type.getDefaultState(); String properties = blockData.getAsString(); return BlockState.get(type, properties, type.getDefaultState()); } catch (NullPointerException e) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java b/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java index 1415eab06..0d692550f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java @@ -28,15 +28,10 @@ import java.lang.management.ManagementFactory; import java.lang.management.MemoryMXBean; import java.lang.management.MemoryPoolMXBean; import java.lang.management.MemoryUsage; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.time.ZoneId; import java.util.Date; -import java.util.GregorianCalendar; import java.util.List; import java.util.Locale; import java.util.Objects; -import java.util.TimeZone; import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; import javax.management.InstanceAlreadyExistsException; @@ -162,7 +157,7 @@ public class Fawe { * The platform specific implementation */ private final IFawe IMP; - private final Thread thread; + private Thread thread; private Fawe(final IFawe implementation) { INSTANCE = this; @@ -294,11 +289,7 @@ public class Fawe { String dateString = br.readLine(); br.close(); this.version = FaweVersion.tryParse(versionString, commitString, dateString); - //noinspection MagicConstant - GregorianCalendar gregorianCalendar = new GregorianCalendar(2000 + version.year, - version.month - 1, version.day); - gregorianCalendar.setTimeZone(TimeZone.getTimeZone("GMT")); - Settings.IMP.DATE = DateFormat.getDateInstance().format(gregorianCalendar.getTime()); + Settings.IMP.DATE = new Date(100 + version.year, version.month, version.day).toGMTString(); Settings.IMP.BUILD = "https://ci.athion.net/job/FastAsyncWorldEdit-1.15/" + version.build; Settings.IMP.COMMIT = "https://github.com/IntellectualSites/FastAsyncWorldEdit-1.13/commit/" + Integer.toHexString(version.hash); } catch (Throwable ignore) {} @@ -421,4 +412,12 @@ public class Fawe { return INSTANCE == null || INSTANCE.thread == Thread.currentThread(); } + /** + * Sets the main thread to the current thread + * + * @return + */ + public Thread setMainThread() { + return this.thread = Thread.currentThread(); + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.kt b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.kt index e56fc33cc..7c7d788ad 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.kt +++ b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.kt @@ -31,9 +31,9 @@ import java.util.function.Supplier object FaweCache : Trimable { const val BLOCKS_PER_LAYER = 4096 - const val chunkLayers = 16 - const val worldHeight = chunkLayers shl 4 - const val worldMaxY = 255 + const val CHUNK_LAYERS = 16 + const val WORLD_HEIGHT = CHUNK_LAYERS shl 4 + const val WORLD_MAX_Y = WORLD_HEIGHT - 1 val EMPTY_CHAR_4096 = CharArray(4096) @@ -57,7 +57,7 @@ object FaweCache : Trimable { result } - val sectionBitsToChar = CleanableThreadLocal { CharArray(4096) } + val SECTION_BITS_TO_CHAR = CleanableThreadLocal { CharArray(4096) } val PALETTE_TO_BLOCK = CleanableThreadLocal { IntArray(Character.MAX_VALUE.toInt() + 1) } @@ -67,23 +67,23 @@ object FaweCache : Trimable { }, fun(a: CharArray): Unit = Arrays.fill(a, Char.MAX_VALUE) ) - val blockStates = CleanableThreadLocal { LongArray(2048) } + val BLOCK_STATES = CleanableThreadLocal { LongArray(2048) } - val sectionBlocks = CleanableThreadLocal { IntArray(4096) } + val SECTION_BLOCKS = CleanableThreadLocal { IntArray(4096) } - val indexStore = CleanableThreadLocal { IntArray(256) } + val INDEX_STORE = CleanableThreadLocal { IntArray(256) } - val heightStore = CleanableThreadLocal { IntArray(256) } + val HEIGHT_STORE = CleanableThreadLocal { IntArray(256) } - private val paletteCache = CleanableThreadLocal(Supplier { Palette() }) + private val PALETTE_CACHE = CleanableThreadLocal(Supplier { Palette() }) /* * Vector cache */ - var mutableBlockVector3 = CleanableThreadLocal(Supplier { MutableBlockVector3() }) + var MUTABLE_BLOCKVECTOR3 = CleanableThreadLocal(Supplier { MutableBlockVector3() }) - var mutableVector3: CleanableThreadLocal = object : CleanableThreadLocal(Supplier { MutableVector3() }) { + var MUTABLE_VECTOR3: CleanableThreadLocal = object : CleanableThreadLocal(Supplier { MutableVector3() }) { override fun init(): MutableVector3 { return MutableVector3() } @@ -102,15 +102,15 @@ object FaweCache : Trimable { BYTE_BUFFER_8192.clean() BLOCK_TO_PALETTE.clean() PALETTE_TO_BLOCK.clean() - blockStates.clean() - sectionBlocks.clean() - paletteCache.clean() + BLOCK_STATES.clean() + SECTION_BLOCKS.clean() + PALETTE_CACHE.clean() PALETTE_TO_BLOCK_CHAR.clean() - indexStore.clean() + INDEX_STORE.clean() - mutableVector3.clean() - mutableBlockVector3.clean() - sectionBitsToChar.clean() + MUTABLE_VECTOR3.clean() + MUTABLE_BLOCKVECTOR3.clean() + SECTION_BITS_TO_CHAR.clean() for ((_, value) in REGISTERED_SINGLETONS) { value.clean() } @@ -239,8 +239,8 @@ object FaweCache : Trimable { private fun toPalette(layerOffset: Int, blocksInts: IntArray?, blocksChars: CharArray?): Palette { val blockToPalette = BLOCK_TO_PALETTE.get() val paletteToBlock = PALETTE_TO_BLOCK.get() - val blockStates = blockStates.get() - val blocksCopy = sectionBlocks.get() + val blockStates = BLOCK_STATES.get() + val blocksCopy = SECTION_BLOCKS.get() val blockIndexStart = layerOffset shl 12 val blockIndexEnd = blockIndexStart + 4096 @@ -305,7 +305,7 @@ object FaweCache : Trimable { } // Construct palette - val palette = paletteCache.get() + val palette = PALETTE_CACHE.get() palette.bitsPerEntry = bitsPerEntry palette.paletteToBlockLength = num_palette palette.paletteToBlock = paletteToBlock @@ -419,7 +419,7 @@ object FaweCache : Trimable { return asTag((if (value) 1 else 0).toByte()) } else if (value == null) { println("Invalid nbt: " + value!!) - return value + return null } else { val clazz = value.javaClass if (clazz.name.startsWith("com.intellectualcrafters.jnbt")) { @@ -507,15 +507,15 @@ object FaweCache : Trimable { } } - val chunk = FaweChunkLoadException() - val blockBag = FaweBlockBagException() - val manual = FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.manual")) - val noRegion = FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.no.region")) - val outsideRegion = FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.outside.region")) - val maxChecks = FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.max.checks")) - val maxChanges = FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.max.changes")) - val lowMemory = FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.low.memory")) - val maxEntities = FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.max.entities")) - val maxTiles = FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.max.tiles")) - val maxIterations = FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.max.iterations")) + val CHUNK = FaweChunkLoadException() + val BLOCK_BAG = FaweBlockBagException() + val MANUAL = FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.manual")) + val NO_REGION = FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.no.region")) + val OUTSIDE_REGION = FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.outside.region")) + val MAX_CHECKS = FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.max.checks")) + val MAX_CHANGES = FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.max.changes")) + val LOW_MEMORY = FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.low.memory")) + val MAX_ENTITIES = FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.max.entities")) + val MAX_TILES = FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.max.tiles")) + val MAX_ITERATIONS = FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.max.iterations")) } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/CombinedBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/CombinedBlocks.java index 28d97409d..089533d96 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/CombinedBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/CombinedBlocks.java @@ -1,10 +1,13 @@ package com.boydti.fawe.beta; import com.boydti.fawe.FaweCache; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import java.util.HashMap; @@ -31,7 +34,7 @@ public class CombinedBlocks implements IBlocks { @Override public int getBitMask() { int bitMask = addMask; - for (int layer = 0; layer < FaweCache.chunkLayers; layer++) { + for (int layer = 0; layer < FaweCache.CHUNK_LAYERS; layer++) { if (primary.hasSection(layer)) { bitMask |= (1 << layer); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBatchProcessor.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBatchProcessor.java index 910ed0e5e..8bce0c6d0 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBatchProcessor.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBatchProcessor.java @@ -56,7 +56,7 @@ public interface IBatchProcessor { } } int maxLayer = (maxY + 1) >> 4; - for (int layer = maxLayer; layer < FaweCache.chunkLayers; layer++) { + for (int layer = maxLayer; layer < FaweCache.CHUNK_LAYERS; layer++) { if (set.hasSection(layer)) { if (layer == minLayer) { char[] arr = set.load(layer); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java index b09e1202b..220a165a9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java @@ -36,7 +36,7 @@ public interface IBlocks extends Trimable { BiomeType getBiomeType(int x, int y, int z); default int getBitMask() { - return IntStream.range(0, FaweCache.chunkLayers).filter(this::hasSection) + return IntStream.range(0, FaweCache.CHUNK_LAYERS).filter(this::hasSection) .map(layer -> (1 << layer)).sum(); } @@ -56,7 +56,7 @@ public interface IBlocks extends Trimable { FaweOutputStream sectionWriter = new FaweOutputStream(sectionByteArray); try { - for (int layer = 0; layer < FaweCache.chunkLayers; layer++) { + for (int layer = 0; layer < FaweCache.CHUNK_LAYERS; layer++) { if (!this.hasSection(layer) || (bitMask & (1 << layer)) == 0) continue; char[] ids = this.load(layer); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueExtent.java index 8c6ded67f..bdb431bae 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueExtent.java @@ -78,7 +78,7 @@ public interface IQueueExtent extends Flushable, Trimable, ICh @Override default BlockVector3 getMaximumPoint() { - return BlockVector3.at(30000000, FaweCache.worldMaxY, 30000000); + return BlockVector3.at(30000000, FaweCache.WORLD_MAX_Y, 30000000); } /** diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/BitSetBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/BitSetBlocks.java index 63638352c..ab0c98ba9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/BitSetBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/BitSetBlocks.java @@ -84,7 +84,7 @@ public class BitSetBlocks implements IChunkSet { @Override public char[] load(int layer) { - char[] arr = FaweCache.INSTANCE.getSectionBitsToChar().get(); + char[] arr = FaweCache.INSTANCE.getSECTION_BITS_TO_CHAR().get(); MemBlockSet.IRow nullRowY = row.getRow(layer); if (nullRowY instanceof MemBlockSet.RowY) { char value = blockState.getOrdinalChar(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/FallbackChunkGet.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/FallbackChunkGet.java index 83d94a99c..a0e98f71c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/FallbackChunkGet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/FallbackChunkGet.java @@ -142,7 +142,7 @@ public class FallbackChunkGet implements IChunkGet { @Override public char[] load(int layer) { - char[] arr = FaweCache.INSTANCE.getSectionBitsToChar().get(); + char[] arr = FaweCache.INSTANCE.getSECTION_BITS_TO_CHAR().get(); int by = layer << 4; for (int y = 0, i = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ChunkHolder.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ChunkHolder.java index bbfd5db61..c5dcc3bea 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ChunkHolder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ChunkHolder.java @@ -23,7 +23,6 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.Future; import javax.annotation.Nullable; -import org.jetbrains.annotations.Range; /** * An abstract {@link IChunk} class that implements basic get/set blocks @@ -40,9 +39,7 @@ public class ChunkHolder> implements IQueueChunk { private IChunkSet chunkSet; // The blocks to be set to the chunkExisting private IBlockDelegate delegate; // delegate handles the abstraction of the chunk layers private IQueueExtent extent; // the parent queue extent which has this chunk - @Range(from = 0, to = 15) private int chunkX; - @Range(from = 0, to = 15) private int chunkZ; public ChunkHolder() { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/LimitExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/LimitExtent.java index 507892358..28982600c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/LimitExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/LimitExtent.java @@ -29,21 +29,22 @@ 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.Collection; import java.util.Collections; import java.util.List; import java.util.Set; import java.util.UUID; -import javax.annotation.Nullable; public class LimitExtent extends PassthroughExtent { private final FaweLimit limit; /** - * Create a new instance. - * - * @param extent the extent - */ + * Create a new instance. + * + * @param extent the extent + */ public LimitExtent(Extent extent, FaweLimit limit) { super(extent); this.limit = limit; @@ -118,7 +119,7 @@ public class LimitExtent extends PassthroughExtent { @Override public int getHighestTerrainBlock(int x, int z, int minY, int maxY) { - limit.THROW_MAX_CHECKS(FaweCache.worldHeight); + limit.THROW_MAX_CHECKS(FaweCache.WORLD_HEIGHT); try { return getExtent().getHighestTerrainBlock(x, z, minY, maxY); } catch (FaweException e) { @@ -131,7 +132,7 @@ public class LimitExtent extends PassthroughExtent { @Override public int getHighestTerrainBlock(int x, int z, int minY, int maxY, Mask filter) { - limit.THROW_MAX_CHECKS(FaweCache.worldHeight); + limit.THROW_MAX_CHECKS(FaweCache.WORLD_HEIGHT); try { return getExtent().getHighestTerrainBlock(x, z, minY, maxY, filter); } catch (FaweException e) { @@ -144,7 +145,7 @@ public class LimitExtent extends PassthroughExtent { @Override public int getNearestSurfaceLayer(int x, int z, int y, int minY, int maxY) { - limit.THROW_MAX_CHECKS(FaweCache.worldHeight); + limit.THROW_MAX_CHECKS(FaweCache.WORLD_HEIGHT); try { return getExtent().getNearestSurfaceLayer(x, z, y, minY, maxY); } catch (FaweException e) { @@ -157,7 +158,7 @@ public class LimitExtent extends PassthroughExtent { @Override public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, boolean ignoreAir) { - limit.THROW_MAX_CHECKS(FaweCache.worldHeight); + limit.THROW_MAX_CHECKS(FaweCache.WORLD_HEIGHT); try { return getExtent().getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, ignoreAir); } catch (FaweException e) { @@ -170,7 +171,7 @@ public class LimitExtent extends PassthroughExtent { @Override public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY) { - limit.THROW_MAX_CHECKS(FaweCache.worldHeight); + limit.THROW_MAX_CHECKS(FaweCache.WORLD_HEIGHT); try { return getExtent().getNearestSurfaceTerrainBlock(x, z, y, minY, maxY); } catch (FaweException e) { @@ -183,7 +184,7 @@ public class LimitExtent extends PassthroughExtent { @Override public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax) { - limit.THROW_MAX_CHECKS(FaweCache.worldHeight); + limit.THROW_MAX_CHECKS(FaweCache.WORLD_HEIGHT); try { return getExtent().getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax); } catch (FaweException e) { @@ -196,7 +197,7 @@ public class LimitExtent extends PassthroughExtent { @Override public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, Mask mask) { - limit.THROW_MAX_CHECKS(FaweCache.worldHeight); + limit.THROW_MAX_CHECKS(FaweCache.WORLD_HEIGHT); try { return getExtent().getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, mask); } catch (FaweException e) { @@ -209,7 +210,7 @@ public class LimitExtent extends PassthroughExtent { @Override public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, boolean ignoreAir) { - limit.THROW_MAX_CHECKS(FaweCache.worldHeight); + limit.THROW_MAX_CHECKS(FaweCache.WORLD_HEIGHT); try { return getExtent().getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, ignoreAir); } catch (FaweException e) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/ParallelQueueExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/ParallelQueueExtent.java index 77f997dcb..f6e0a2023 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/ParallelQueueExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/ParallelQueueExtent.java @@ -58,7 +58,7 @@ public class ParallelQueueExtent extends PassthroughExtent implements IQueueWrap @Override public boolean cancel() { if (super.cancel()) { - processor.setProcessor(new NullExtent(this, FaweCache.INSTANCE.getManual())); + processor.setProcessor(new NullExtent(this, FaweCache.INSTANCE.getMANUAL())); return true; } return false; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/CorruptSchematicStreamer.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/CorruptSchematicStreamer.java new file mode 100644 index 000000000..2df358190 --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/CorruptSchematicStreamer.java @@ -0,0 +1,312 @@ +package com.boydti.fawe.jnbt; + +import com.boydti.fawe.Fawe; +import com.boydti.fawe.config.Settings; +import com.boydti.fawe.object.clipboard.CPUOptimizedClipboard; +import com.boydti.fawe.object.clipboard.DiskOptimizedClipboard; +import com.boydti.fawe.object.clipboard.LinearClipboard; +import com.boydti.fawe.object.clipboard.MemoryOptimizedClipboard; +import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.math.BlockVector3; + +import java.io.BufferedInputStream; +import java.io.DataInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.zip.GZIPInputStream; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CorruptSchematicStreamer { + + private final Logger log = LoggerFactory.getLogger(CorruptSchematicStreamer.class); + private final InputStream stream; + private final UUID uuid; + private LinearClipboard fc; + final AtomicInteger volume = new AtomicInteger(); + final AtomicInteger width = new AtomicInteger(); + final AtomicInteger height = new AtomicInteger(); + final AtomicInteger length = new AtomicInteger(); + final AtomicInteger offsetX = new AtomicInteger(); + final AtomicInteger offsetY = new AtomicInteger(); + final AtomicInteger offsetZ = new AtomicInteger(); + final AtomicInteger originX = new AtomicInteger(); + final AtomicInteger originY = new AtomicInteger(); + final AtomicInteger originZ = new AtomicInteger(); + + public CorruptSchematicStreamer(InputStream rootStream, UUID uuid) { + this.stream = rootStream; + this.uuid = uuid; + } + + public void match(String matchTag, CorruptReader reader) { + try { + stream.reset(); + stream.mark(Integer.MAX_VALUE); + DataInputStream dataInput = new DataInputStream(new BufferedInputStream(new GZIPInputStream(stream))); + byte[] match = matchTag.getBytes(); + int[] matchValue = new int[match.length]; + int matchIndex = 0; + int read; + while ((read = dataInput.read()) != -1) { + int expected = match[matchIndex]; + if (expected == -1) { + if (++matchIndex == match.length) { + break; + } + } else if (read == expected) { + if (++matchIndex == match.length) { + reader.run(dataInput); + break; + } + } else { + if (matchIndex == 2) + matchIndex = 0; + } + } + log.debug(" - Recover " + matchTag + " = success"); + } catch (Throwable e) { + log.error(" - Recover " + matchTag + " = partial failure", e); + } + } + + public LinearClipboard setupClipboard() { + if (fc != null) { + return fc; + } + BlockVector3 dimensions = guessDimensions(volume.get(), width.get(), height.get(), length.get()); + if (width.get() == 0 || height.get() == 0 || length.get() == 0) { + log.debug("No dimensions found! Estimating based on factors:" + dimensions); + } + if (Settings.IMP.CLIPBOARD.USE_DISK) { + fc = new DiskOptimizedClipboard(dimensions, uuid); + } else if (Settings.IMP.CLIPBOARD.COMPRESSION_LEVEL == 0) { + fc = new CPUOptimizedClipboard(dimensions); + } else { + fc = new MemoryOptimizedClipboard(dimensions); + } + return fc; + } + + public Clipboard recover() { + // TODO FIXME + throw new UnsupportedOperationException("TODO FIXME"); +// try { +// if (stream == null || !stream.markSupported()) { +// throw new IllegalArgumentException("Can only recover from a marked and resettable stream!"); +// } +// match("Width", new CorruptSchematicStreamer.CorruptReader() { +// @Override +// public void run(DataInputStream in) throws IOException { +// width.set(in.readShort()); +// } +// }); +// match("Height", new CorruptSchematicStreamer.CorruptReader() { +// @Override +// public void run(DataInputStream in) throws IOException { +// height.set(in.readShort()); +// } +// }); +// match("Length", new CorruptSchematicStreamer.CorruptReader() { +// @Override +// public void run(DataInputStream in) throws IOException { +// length.set(in.readShort()); +// } +// }); +// match("WEOffsetX", new CorruptSchematicStreamer.CorruptReader() { +// @Override +// public void run(DataInputStream in) throws IOException { +// offsetX.set(in.readInt()); +// } +// }); +// match("WEOffsetY", new CorruptSchematicStreamer.CorruptReader() { +// @Override +// public void run(DataInputStream in) throws IOException { +// offsetY.set(in.readInt()); +// } +// }); +// match("WEOffsetZ", new CorruptSchematicStreamer.CorruptReader() { +// @Override +// public void run(DataInputStream in) throws IOException { +// offsetZ.set(in.readInt()); +// } +// }); +// match("WEOriginX", new CorruptSchematicStreamer.CorruptReader() { +// @Override +// public void run(DataInputStream in) throws IOException { +// originX.set(in.readInt()); +// } +// }); +// match("WEOriginY", new CorruptSchematicStreamer.CorruptReader() { +// @Override +// public void run(DataInputStream in) throws IOException { +// originY.set(in.readInt()); +// } +// }); +// match("WEOriginZ", new CorruptSchematicStreamer.CorruptReader() { +// @Override +// public void run(DataInputStream in) throws IOException { +// originZ.set(in.readInt()); +// } +// }); +// match("Blocks", new CorruptSchematicStreamer.CorruptReader() { +// @Override +// public void run(DataInputStream in) throws IOException { +// int length = in.readInt(); +// volume.set(length); +// setupClipboard(); +// for (int i = 0; i < length; i++) { +// fc.setId(i, in.read()); +// } +// } +// }); +// match("Data", new CorruptSchematicStreamer.CorruptReader() { +// @Override +// public void run(DataInputStream in) throws IOException { +// int length = in.readInt(); +// volume.set(length); +// setupClipboard(); +// for (int i = 0; i < length; i++) { +// fc.setData(i, in.read()); +// } +// } +// }); +// match("AddBlocks", new CorruptSchematicStreamer.CorruptReader() { +// @Override +// public void run(DataInputStream in) throws IOException { +// int length = in.readInt(); +// int expected = volume.get(); +// if (expected == 0) { +// expected = length * 2; +// volume.set(expected); +// } +// setupClipboard(); +// if (expected == length * 2) { +// for (int i = 0; i < length; i++) { +// int value = in.read(); +// int first = value & 0x0F; +// int second = (value & 0xF0) >> 4; +// int gIndex = i << 1; +// if (first != 0) fc.setAdd(gIndex, first); +// if (second != 0) fc.setAdd(gIndex + 1, second); +// } +// } else { +// for (int i = 0; i < length; i++) { +// int value = in.read(); +// if (value != 0) fc.setAdd(i, value); +// } +// } +// } +// }); +// match("Biomes", new CorruptSchematicStreamer.CorruptReader() { +// @Override +// public void run(DataInputStream in) throws IOException { +// int length = in.readInt(); +// for (int i = 0; i < length; i++) { +// fc.setBiome(i, in.read()); +// } +// } +// }); +// Vector dimensions = guessDimensions(volume.get(), width.get(), height.get(), length.get()); +// Vector min = new Vector(originX.get(), originY.get(), originZ.get()); +// Vector offset = new Vector(offsetX.get(), offsetY.get(), offsetZ.get()); +// Vector origin = min.subtract(offset); +// CuboidRegion region = new CuboidRegion(min, min.add(dimensions.getBlockX(), dimensions.getBlockY(), dimensions.getBlockZ()).subtract(Vector.ONE)); +// fc.setOrigin(offset); +// final BlockArrayClipboard clipboard = new BlockArrayClipboard(region, fc); +// match("TileEntities", new CorruptSchematicStreamer.CorruptReader() { +// @Override +// public void run(DataInputStream in) throws IOException { +// int childType = in.readByte(); +// int length = in.readInt(); +// NBTInputStream nis = new NBTInputStream(in); +// for (int i = 0; i < length; ++i) { +// CompoundTag tag = (CompoundTag) nis.readTagPayload(childType, 1); +// int x = tag.getInt("x"); +// int y = tag.getInt("y"); +// int z = tag.getInt("z"); +// fc.setTile(x, y, z, tag); +// } +// } +// }); +// match("Entities", new CorruptSchematicStreamer.CorruptReader() { +// @Override +// public void run(DataInputStream in) throws IOException { +// int childType = in.readByte(); +// int length = in.readInt(); +// NBTInputStream nis = new NBTInputStream(in); +// for (int i = 0; i < length; ++i) { +// CompoundTag tag = (CompoundTag) nis.readTagPayload(childType, 1); +// int x = tag.getInt("x"); +// int y = tag.getInt("y"); +// int z = tag.getInt("z"); +// String id = tag.getString("id"); +// if (id.isEmpty()) { +// return; +// } +// ListTag positionTag = tag.getListTag("Pos"); +// ListTag directionTag = tag.getListTag("Rotation"); +// BaseEntity state = new BaseEntity(id, tag); +// fc.createEntity(clipboard, positionTag.asDouble(0), positionTag.asDouble(1), positionTag.asDouble(2), (float) directionTag.asDouble(0), (float) directionTag.asDouble(1), state); +// } +// } +// }); +// return clipboard; +// } catch (Throwable e) { +// if (fc != null) fc.close(); +// throw e; +// } + } + + private BlockVector3 guessDimensions(int volume, int width, int height, int length) { + if (volume == 0) { + return BlockVector3.at(width, height, length); + } + if (volume == width * height * length) { + return BlockVector3.at(width, height, length); + } + if (width == 0 && height != 0 && length != 0 && volume % (height * length) == 0 && height * length <= volume) { + return BlockVector3.at(volume / (height * length), height, length); + } + if (height == 0 && width != 0 && length != 0 && volume % (width * length) == 0 && width * length <= volume) { + return BlockVector3.at(width, volume / (width * length), length); + } + if (length == 0 && height != 0 && width != 0 && volume % (height * width) == 0 && height * width <= volume) { + return BlockVector3.at(width, height, volume / (width * height)); + } + List factors = new ArrayList<>(); + for (int i = (int) Math.sqrt(volume); i > 0; i--) { + if (volume % i == 0) { + factors.add(i); + factors.add(volume / i); + } + } + int min = Integer.MAX_VALUE; + int vx = 0, vy = 0, vz = 0; + for (int x = 0; x < factors.size(); x++) { + int xValue = factors.get(x); + for (int yValue : factors) { + long area = xValue * yValue; + if (volume % area == 0) { + int z = (int) (volume / area); + int max = Math.max(Math.max(xValue, yValue), z); + if (max < min) { + min = max; + vx = xValue; + vz = z; + vy = yValue; + } + } + } + } + return BlockVector3.at(vx, vz, vy); + } + + public interface CorruptReader { + void run(DataInputStream in) throws IOException; + } +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java index aef82ff33..522b90e32 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java @@ -47,7 +47,7 @@ public class MCAChunk implements IChunk { public final boolean[] hasSections = new boolean[16]; public boolean hasBiomes = false; - public final BiomeType[] biomes = new BiomeType[1024]; + public final BiomeType[] biomes = new BiomeType[256]; public final char[] blocks = new char[65536]; @@ -72,7 +72,7 @@ public class MCAChunk implements IChunk { int bitsPerEntry = MathMan.log2nlz(section.palette.length - 1); BitArray4096 bitArray = new BitArray4096(section.blocks, bitsPerEntry); - char[] buffer = FaweCache.INSTANCE.getSectionBitsToChar().get(); + char[] buffer = FaweCache.INSTANCE.getSECTION_BITS_TO_CHAR().get(); bitArray.toRaw(buffer); int offset = section.layer << 12; for (int i = 0; i < buffer.length; i++) { @@ -220,8 +220,8 @@ public class MCAChunk implements IChunk { public void write(NBTOutputStream nbtOut) throws IOException { int[] blockToPalette = FaweCache.INSTANCE.getBLOCK_TO_PALETTE().get(); int[] paletteToBlock = FaweCache.INSTANCE.getPALETTE_TO_BLOCK().get(); - long[] blockstates = FaweCache.INSTANCE.getBlockStates().get(); - int[] blocksCopy = FaweCache.INSTANCE.getSectionBlocks().get(); + long[] blockstates = FaweCache.INSTANCE.getBLOCK_STATES().get(); + int[] blocksCopy = FaweCache.INSTANCE.getSECTION_BLOCKS().get(); nbtOut.writeNamedTagName("", NBTConstants.TYPE_COMPOUND); nbtOut.writeNamedTag("DataVersion", 1631); @@ -243,7 +243,7 @@ public class MCAChunk implements IChunk { out.writeNamedTag("InhabitedTime", inhabitedTime); out.writeNamedTag("LastUpdate", lastUpdate); if (hasBiomes) { - int type = NBTConstants.TYPE_INT_ARRAY; + int type = NBTConstants.TYPE_BYTE_ARRAY; out.writeNamedTagName("Biomes", type); out.writeInt(biomes.length); for (BiomeType biome : biomes) { @@ -524,7 +524,7 @@ public class MCAChunk implements IChunk { @Override public char[] load(int layer) { - char[] tmp = FaweCache.INSTANCE.getSectionBitsToChar().get(); + char[] tmp = FaweCache.INSTANCE.getSECTION_BITS_TO_CHAR().get(); int offset = layer << 12; System.arraycopy(blocks, offset, tmp, 0, 4096); return tmp; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAFile.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAFile.java index 9f3be6328..76c4050c4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAFile.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAFile.java @@ -138,7 +138,7 @@ public class MCAFile extends ExtentBatchProcessorHolder implements Trimable, ICh @Override public BlockVector3 getMaximumPoint() { - return BlockVector3.at((this.X << 9) + 511, FaweCache.worldMaxY, (this.Z << 9) + 511); + return BlockVector3.at((this.X << 9) + 511, FaweCache.WORLD_MAX_Y, (this.Z << 9) + 511); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/BytePair.java b/worldedit-core/src/main/java/com/boydti/fawe/object/BytePair.java new file mode 100644 index 000000000..ccb56666e --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/BytePair.java @@ -0,0 +1,42 @@ +package com.boydti.fawe.object; + +import com.boydti.fawe.util.MathMan; + +public class BytePair { + public short pair; + + public BytePair(final byte x, final byte z) { + this.pair = MathMan.pairByte(x, z); + } + + public int get0x() { + return MathMan.unpair16x((byte) get0()); + } + + public int get0y() { + return MathMan.unpair16y((byte) get0()); + } + + public int get0() { + return MathMan.unpairShortX(pair); + } + + public int get1() { + return MathMan.unpairShortY(pair); + } + + @Override + public int hashCode() { + return pair; + } + + @Override + public String toString() { + return pair + ""; + } + + @Override + public boolean equals(final Object obj) { + return obj.hashCode() == pair; + } +} 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 7cf4a887b..179403f20 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 @@ -136,51 +136,51 @@ public class FaweLimit { } public void THROW_MAX_CHANGES() { - if (MAX_CHANGES-- <= 0) throw FaweCache.INSTANCE.getMaxChanges(); + if (MAX_CHANGES-- <= 0) throw FaweCache.INSTANCE.getMAX_CHANGES(); } public void THROW_MAX_FAILS() { - if (MAX_FAILS-- <= 0) throw FaweCache.INSTANCE.getMaxChecks(); + if (MAX_FAILS-- <= 0) throw FaweCache.INSTANCE.getMAX_CHECKS(); } public void THROW_MAX_CHECKS() { - if (MAX_CHECKS-- <= 0) throw FaweCache.INSTANCE.getMaxChecks(); + if (MAX_CHECKS-- <= 0) throw FaweCache.INSTANCE.getMAX_CHECKS(); } public void THROW_MAX_ITERATIONS() { - if (MAX_ITERATIONS-- <= 0) throw FaweCache.INSTANCE.getMaxIterations(); + if (MAX_ITERATIONS-- <= 0) throw FaweCache.INSTANCE.getMAX_ITERATIONS(); } public void THROW_MAX_BLOCKSTATES() { - if (MAX_BLOCKSTATES-- <= 0) throw FaweCache.INSTANCE.getMaxTiles(); + if (MAX_BLOCKSTATES-- <= 0) throw FaweCache.INSTANCE.getMAX_TILES(); } public void THROW_MAX_ENTITIES() { - if (MAX_ENTITIES-- <= 0) throw FaweCache.INSTANCE.getMaxEntities(); + if (MAX_ENTITIES-- <= 0) throw FaweCache.INSTANCE.getMAX_ENTITIES(); } public void THROW_MAX_CHANGES(int amt) { - if ((MAX_CHANGES -= amt) <= 0) throw FaweCache.INSTANCE.getMaxChanges(); + if ((MAX_CHANGES -= amt) <= 0) throw FaweCache.INSTANCE.getMAX_CHANGES(); } public void THROW_MAX_FAILS(int amt) { - if ((MAX_FAILS -= amt) <= 0) throw FaweCache.INSTANCE.getMaxChecks(); + if ((MAX_FAILS -= amt) <= 0) throw FaweCache.INSTANCE.getMAX_CHECKS(); } public void THROW_MAX_CHECKS(int amt) { - if ((MAX_CHECKS -= amt) <= 0) throw FaweCache.INSTANCE.getMaxChecks(); + if ((MAX_CHECKS -= amt) <= 0) throw FaweCache.INSTANCE.getMAX_CHECKS(); } public void THROW_MAX_ITERATIONS(int amt) { - if ((MAX_ITERATIONS -= amt) <= 0) throw FaweCache.INSTANCE.getMaxIterations(); + if ((MAX_ITERATIONS -= amt) <= 0) throw FaweCache.INSTANCE.getMAX_ITERATIONS(); } public void THROW_MAX_BLOCKSTATES(int amt) { - if ((MAX_BLOCKSTATES -= amt) <= 0) throw FaweCache.INSTANCE.getMaxTiles(); + if ((MAX_BLOCKSTATES -= amt) <= 0) throw FaweCache.INSTANCE.getMAX_TILES(); } public void THROW_MAX_ENTITIES(int amt) { - if ((MAX_ENTITIES -= amt) <= 0) throw FaweCache.INSTANCE.getMaxEntities(); + if ((MAX_ENTITIES -= amt) <= 0) throw FaweCache.INSTANCE.getMAX_ENTITIES(); } public boolean isUnlimited() { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/IntegerPair.java b/worldedit-core/src/main/java/com/boydti/fawe/object/IntegerPair.java new file mode 100644 index 000000000..902848f9c --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/IntegerPair.java @@ -0,0 +1,33 @@ +package com.boydti.fawe.object; + +public class IntegerPair { + public int x; + public int z; + + public IntegerPair(final int x, final int z) { + this.x = x; + this.z = z; + } + + @Override + public int hashCode() { + return (x << 16) | (z & 0xFFFF); + } + + @Override + public String toString() { + return x + "," + z; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if ((obj == null) || (this.getClass() != obj.getClass())) { + return false; + } + final IntegerPair other = (IntegerPair) obj; + return ((this.x == other.x) && (this.z == other.z)); + } +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/IntegerTrio.java b/worldedit-core/src/main/java/com/boydti/fawe/object/IntegerTrio.java new file mode 100644 index 000000000..b328836a0 --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/IntegerTrio.java @@ -0,0 +1,60 @@ +package com.boydti.fawe.object; + +public class IntegerTrio { + public int x, y, z; + + public IntegerTrio(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public IntegerTrio(IntegerTrio node) { + this.x = node.x; + this.y = node.y; + this.z = node.z; + } + + public IntegerTrio() { + } + + public final void set(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public final void set(IntegerTrio node) { + this.x = node.x; + this.y = node.y; + this.z = node.z; + } + + @Override + public final int hashCode() { + return (x ^ (z << 12)) ^ (y << 24); + } + + public final int getX() { + return x; + } + + public final int getY() { + return y; + } + + public final int getZ() { + return z; + } + + @Override + public String toString() { + return x + "," + y + "," + z; + } + + @Override + public boolean equals(Object obj) { + IntegerTrio other = (IntegerTrio) obj; + return other.x == x && other.z == z && other.y == y; + } +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/NullChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/NullChangeSet.java index e8c7cd1a3..1a8d166ec 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/NullChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/NullChangeSet.java @@ -7,7 +7,6 @@ import com.sk89q.worldedit.history.change.Change; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BiomeType; import java.util.ArrayList; -import java.util.Collections; import java.util.Iterator; public class NullChangeSet extends AbstractChangeSet { @@ -59,7 +58,7 @@ public class NullChangeSet extends AbstractChangeSet { @Override public final Iterator getIterator(boolean undo) { - return Collections.emptyIterator(); + return new ArrayList().iterator(); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/AbstractBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/AbstractBrush.java new file mode 100644 index 000000000..910450f34 --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/AbstractBrush.java @@ -0,0 +1,20 @@ +package com.boydti.fawe.object.brush; + +import com.sk89q.worldedit.command.tool.BrushTool; +import com.sk89q.worldedit.command.tool.brush.Brush; + +public abstract class AbstractBrush implements Brush { + private BrushTool tool; + + public AbstractBrush(BrushTool tool) { + this.tool = tool; + } + + public void setTool(BrushTool tool) { + this.tool = tool; + } + + public BrushTool getTool() { + return tool; + } +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RaiseBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RaiseBrush.java index dffcb29e3..4ae931884 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RaiseBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RaiseBrush.java @@ -1,5 +1,10 @@ package com.boydti.fawe.object.brush; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; + public class RaiseBrush extends ErodeBrush { public RaiseBrush() { this(6, 0, 1, 1); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ShatterBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ShatterBrush.java index 50fcab3a5..903d4f80e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ShatterBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ShatterBrush.java @@ -37,7 +37,7 @@ public class ShatterBrush extends ScatterBrush { LocalBlockVectorSet set = new LocalBlockVectorSet(); set.add(pos); frontiers[i] = set; - frontiersVisited[i] = new LocalBlockVectorSet(set); + frontiersVisited[i] = set.clone(); i++; } // Mask diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java index 8988a1839..fadad9001 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java @@ -1,6 +1,7 @@ package com.boydti.fawe.object.brush; import com.boydti.fawe.FaweCache; +import com.sk89q.worldedit.function.mask.DelegateExtentMask; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.boydti.fawe.object.brush.visualization.VisualExtent; import com.boydti.fawe.object.mask.IdMask; @@ -62,7 +63,7 @@ public class SplineBrush implements Brush, ResettableTool { this.position = position; if (newPos) { if (positionSets.size() >= MAX_POINTS) { - throw FaweCache.INSTANCE.getMaxChecks(); + throw FaweCache.INSTANCE.getMAX_CHECKS(); } final ArrayList points = new ArrayList<>(); if (size > 0) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/ScalableHeightMap.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/ScalableHeightMap.java index a831e4438..dae06fbf0 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/ScalableHeightMap.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/ScalableHeightMap.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.brush.heightmap; +import com.boydti.fawe.object.IntegerPair; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MathMan; import com.sk89q.worldedit.extent.clipboard.Clipboard; @@ -11,7 +12,6 @@ import java.awt.image.Raster; import java.io.IOException; import java.io.InputStream; import java.util.HashSet; -import kotlin.Pair; public class ScalableHeightMap implements HeightMap { public int size2; @@ -65,9 +65,9 @@ public class ScalableHeightMap implements HeightMap { int minY = clipboard.getMinimumPoint().getBlockY(); int maxY = clipboard.getMaximumPoint().getBlockY(); int clipHeight = maxY - minY + 1; - HashSet> visited = new HashSet<>(); + HashSet visited = new HashSet<>(); for (BlockVector3 pos : clipboard.getRegion()) { - Pair pair = new Pair<>(pos.getBlockX(), pos.getBlockZ()); + IntegerPair pair = new IntegerPair(pos.getBlockX(), pos.getBlockZ()); if (visited.contains(pair)) { continue; } 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 ec76dff40..c5cd08d7a 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 @@ -7,9 +7,13 @@ import com.boydti.fawe.FaweCache; import com.boydti.fawe.beta.IBlocks; import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkSet; +import com.boydti.fawe.beta.implementation.filter.block.AbstractFilterBlock; import com.boydti.fawe.beta.implementation.filter.block.ArrayFilterBlock; +import com.boydti.fawe.beta.implementation.filter.block.MultiFilterBlock; +import com.boydti.fawe.beta.implementation.filter.block.SingleFilterBlock; import com.boydti.fawe.beta.implementation.packet.ChunkPacket; import com.boydti.fawe.beta.implementation.blocks.FallbackChunkGet; +import com.boydti.fawe.beta.implementation.packet.ChunkPacket; import com.boydti.fawe.jnbt.anvil.MCAChunk; import com.boydti.fawe.object.FaweInputStream; import com.boydti.fawe.object.FaweOutputStream; @@ -35,6 +39,7 @@ import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.operation.Operation; @@ -54,6 +59,7 @@ import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeTypes; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockID; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -1557,12 +1563,12 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr char[] floor = this.floor.get(); char[] overlay = this.overlay != null ? this.overlay.get() : null; try { - int[] indexes = FaweCache.INSTANCE.getIndexStore().get(); + int[] indexes = FaweCache.INSTANCE.getINDEX_STORE().get(); int index; int maxY = 0; int minY = Integer.MAX_VALUE; - int[] heightMap = FaweCache.INSTANCE.getHeightStore().get(); + int[] heightMap = FaweCache.INSTANCE.getHEIGHT_STORE().get(); int globalIndex; for (int z = csz; z <= cez; z++) { globalIndex = z * getWidth() + csx; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableBiomeChange.java b/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableBiomeChange.java index b1c21356d..db2b83226 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableBiomeChange.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableBiomeChange.java @@ -8,7 +8,7 @@ import com.sk89q.worldedit.world.biome.BiomeTypes; public class MutableBiomeChange implements Change { - private final MutableBlockVector2 mutable = new MutableBlockVector2(); + private MutableBlockVector2 mutable = new MutableBlockVector2(); private int from; private int to; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java index 6f2762831..c527c560f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java @@ -87,10 +87,10 @@ public class BlockBagChangeSet extends AbstractDelegateChangeSet { try { blockBag.fetchPlacedBlock(typeTo.getDefaultState()); } catch (UnplaceableBlockException e) { - throw FaweCache.INSTANCE.getBlockBag(); + throw FaweCache.INSTANCE.getBLOCK_BAG(); } catch (BlockBagException e) { missingBlocks[typeTo.getInternalId()]++; - throw FaweCache.INSTANCE.getBlockBag(); + throw FaweCache.INSTANCE.getBLOCK_BAG(); } } if (mine) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java index 409ca481e..5c199c326 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java @@ -6,6 +6,8 @@ import com.boydti.fawe.database.DBHandler; import com.boydti.fawe.database.RollbackDatabase; import com.boydti.fawe.object.FaweInputStream; import com.boydti.fawe.object.FaweOutputStream; +import com.boydti.fawe.object.IntegerPair; +import com.boydti.fawe.object.change.MutableFullBlockChange; import com.boydti.fawe.util.MainUtil; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.NBTOutputStream; @@ -14,13 +16,12 @@ import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.World; +import java.io.EOFException; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.UUID; -import kotlin.Pair; /** * Store the change on disk @@ -402,23 +403,25 @@ public class DiskStorageHistory extends FaweStreamChangeSet { return null; } - public Pair readHeader() { + public IntegerPair readHeader() { int ox = getOriginX(); int oz = getOriginZ(); if (ox == 0 && oz == 0 && bdFile.exists()) { - try (FileInputStream fis = new FileInputStream(bdFile); FaweInputStream gis = MainUtil - .getCompressedIS(fis)) { + try (FileInputStream fis = new FileInputStream(bdFile)) { + final FaweInputStream gis = MainUtil.getCompressedIS(fis); // skip mode gis.skipFully(1); // origin ox = ((gis.read() << 24) + (gis.read() << 16) + (gis.read() << 8) + gis.read()); oz = ((gis.read() << 24) + (gis.read() << 16) + (gis.read() << 8) + gis.read()); setOrigin(ox, oz); + fis.close(); + gis.close(); } catch (IOException e) { e.printStackTrace(); } } - return new Pair<>(ox, oz); + return new IntegerPair(ox, oz); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java index 1635b625d..d82a6f4c2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java @@ -456,7 +456,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet { public Iterator getBiomeIterator(final boolean dir) throws IOException { final FaweInputStream is = getBiomeIS(); if (is == null) { - return Collections.emptyIterator(); + return new ArrayList().iterator(); } final MutableBiomeChange change = new MutableBiomeChange(); return new Iterator() { @@ -570,7 +570,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet { public Iterator getEntityIterator(final NBTInputStream is, final boolean create) { if (is == null) { - return Collections.emptyIterator(); + return new ArrayList().iterator(); } final MutableEntityChange change = new MutableEntityChange(null, create); try { @@ -619,7 +619,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet { public Iterator getTileIterator(final NBTInputStream is, final boolean create) { if (is == null) { - return Collections.emptyIterator(); + return new ArrayList().iterator(); } final MutableTileChange change = new MutableTileChange(null, create); try { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java index 68d80c9d7..b47880573 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java @@ -1,6 +1,7 @@ package com.boydti.fawe.object.clipboard; import com.boydti.fawe.jnbt.streamer.IntValueReader; +import com.boydti.fawe.object.IntegerTrio; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; @@ -15,24 +16,23 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; -import java.util.Map.Entry; import javax.annotation.Nullable; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.UUID; -import kotlin.Triple; public class CPUOptimizedClipboard extends LinearClipboard { private BiomeType[] biomes = null; private char[] states; - private final HashMap, CompoundTag> nbtMapLoc; + private final HashMap nbtMapLoc; private final HashMap nbtMapIndex; @@ -95,9 +95,9 @@ public class CPUOptimizedClipboard extends LinearClipboard { if (nbtMapLoc.isEmpty()) { return; } - for (Entry, CompoundTag> entry : nbtMapLoc.entrySet()) { - Triple key = entry.getKey(); - setTile(getIndex(key.getFirst(), key.getSecond(), key.getThird()), entry.getValue()); + for (Map.Entry entry : nbtMapLoc.entrySet()) { + IntegerTrio key = entry.getKey(); + setTile(getIndex(key.x, key.y, key.z), entry.getValue()); } nbtMapLoc.clear(); } @@ -168,7 +168,7 @@ public class CPUOptimizedClipboard extends LinearClipboard { @Override public boolean setTile(int x, int y, int z, CompoundTag tag) { - nbtMapLoc.put(new Triple<>(x, y, z), tag); + nbtMapLoc.put(new IntegerTrio(x, y, z), tag); return true; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java index 01b32e76c..a3523e1df 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java @@ -3,6 +3,7 @@ package com.boydti.fawe.object.clipboard; import com.boydti.fawe.Fawe; import com.boydti.fawe.config.Settings; import com.boydti.fawe.jnbt.streamer.IntValueReader; +import com.boydti.fawe.object.IntegerTrio; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; @@ -38,10 +39,8 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.UUID; import javax.annotation.Nullable; -import kotlin.Triple; /** * A clipboard with disk backed storage. (lower memory + loads on crash) @@ -52,7 +51,7 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable private static int HEADER_SIZE = 14; - private final HashMap, CompoundTag> nbtMap; + private final HashMap nbtMap; private final File file; private RandomAccessFile braf; @@ -61,41 +60,45 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable private FileChannel fileChannel; private boolean hasBiomes; - public DiskOptimizedClipboard(BlockVector3 dimensions, UUID uuid) throws IOException { + public DiskOptimizedClipboard(BlockVector3 dimensions, UUID uuid) { this(dimensions, MainUtil.getFile(Fawe.get() != null ? Fawe.imp().getDirectory() : new File("."), Settings.IMP.PATHS.CLIPBOARD + File.separator + uuid + ".bd")); } - public DiskOptimizedClipboard(BlockVector3 dimensions) throws IOException { + public DiskOptimizedClipboard(BlockVector3 dimensions) { this(dimensions, MainUtil.getFile(Fawe.imp() != null ? Fawe.imp().getDirectory() : new File("."), Settings.IMP.PATHS.CLIPBOARD + File.separator + UUID.randomUUID() + ".bd")); } - public DiskOptimizedClipboard(BlockVector3 dimensions, File file) throws IOException { + public DiskOptimizedClipboard(BlockVector3 dimensions, File file) { super(dimensions); if (getWidth() > Character.MAX_VALUE || getHeight() > Character.MAX_VALUE || getLength() > Character.MAX_VALUE) { throw new IllegalArgumentException("Too large"); } nbtMap = new HashMap<>(); - this.file = file; try { - if (!file.exists()) { - File parent = file.getParentFile(); - if (parent != null) { - file.getParentFile().mkdirs(); + this.file = file; + try { + if (!file.exists()) { + File parent = file.getParentFile(); + if (parent != null) { + file.getParentFile().mkdirs(); + } + file.createNewFile(); } - file.createNewFile(); + } catch (Exception e) { + e.printStackTrace(); } - } catch (Exception e) { - e.printStackTrace(); + this.braf = new RandomAccessFile(file, "rw"); + long fileLength = (long) getVolume() * 2L + (long) HEADER_SIZE; + braf.setLength(0); + braf.setLength(fileLength); + init(); + // write getLength() etc + byteBuffer.putChar(2, (char) getWidth()); + byteBuffer.putChar(4, (char) getHeight()); + byteBuffer.putChar(6, (char) getLength()); + } catch (IOException e) { + throw new RuntimeException(e); } - this.braf = new RandomAccessFile(file, "rw"); - long fileLength = (long) getVolume() * 2L + (long) HEADER_SIZE; - braf.setLength(0); - braf.setLength(fileLength); - init(); - // write getLength() etc - byteBuffer.putChar(2, (char) getWidth()); - byteBuffer.putChar(4, (char) getHeight()); - byteBuffer.putChar(6, (char) getLength()); } @Override @@ -307,9 +310,9 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable CompoundTag nbt; if (nbtMap.size() < 4) { nbt = null; - for (Entry, CompoundTag> entry : nbtMap.entrySet()) { - Triple key = entry.getKey(); - int index = getIndex(key.getFirst(), key.getSecond(), key.getThird()); + for (Map.Entry entry : nbtMap.entrySet()) { + IntegerTrio key = entry.getKey(); + int index = getIndex(key.x, key.y, key.z); if (index == i) { nbt = entry.getValue(); break; @@ -320,7 +323,7 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable int newI = i - y * getArea(); int z = newI / getWidth(); int x = newI - z * getWidth(); - nbt = nbtMap.get(new Triple<>(x, y, z)); + nbt = nbtMap.get(new IntegerTrio(x, y, z)); } return state.toBaseBlock(nbt); } @@ -329,7 +332,7 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable private BaseBlock toBaseBlock(BlockState state, int x, int y, int z) { if (state.getMaterial().hasContainer() && !nbtMap.isEmpty()) { - CompoundTag nbt = nbtMap.get(new Triple<>(x, y, z)); + CompoundTag nbt = nbtMap.get(new IntegerTrio(x, y, z)); return state.toBaseBlock(nbt); } return state.toBaseBlock(); @@ -360,7 +363,7 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable @Override public boolean setTile(int x, int y, int z, CompoundTag tag) { - nbtMap.put(new Triple<>(x, y, z), tag); + nbtMap.put(new IntegerTrio(x, y, z), tag); Map values = ReflectionUtils.getMap(tag.getValue()); values.put("x", new IntTag(x)); values.put("y", new IntTag(y)); @@ -424,4 +427,16 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable this.entities.remove(entity); } + @Override + public void removeEntity(int x, int y, int z, UUID uuid) { + Iterator iter = this.entities.iterator(); + while (iter.hasNext()) { + BlockArrayClipboard.ClipboardEntity entity = iter.next(); + UUID entUUID = entity.getState().getNbtData().getUUID(); + if (uuid.equals(entUUID)) { + iter.remove(); + return; + } + } + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java index 5dc7e1282..4e97c9561 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java @@ -2,6 +2,7 @@ package com.boydti.fawe.object.clipboard; import com.boydti.fawe.config.Settings; import com.boydti.fawe.jnbt.streamer.IntValueReader; +import com.boydti.fawe.object.IntegerTrio; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; @@ -19,15 +20,17 @@ 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.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Map.Entry; -import javax.annotation.Nullable; -import kotlin.Triple; +import java.util.UUID; public class MemoryOptimizedClipboard extends LinearClipboard { @@ -40,7 +43,7 @@ public class MemoryOptimizedClipboard extends LinearClipboard { private byte[] buffer = new byte[MainUtil.getMaxCompressedLength(BLOCK_SIZE)]; private byte[] biomes = null; - private final HashMap, CompoundTag> nbtMapLoc; + private final HashMap nbtMapLoc; private final HashMap nbtMapIndex; @@ -68,9 +71,9 @@ public class MemoryOptimizedClipboard extends LinearClipboard { if (nbtMapLoc.isEmpty()) { return; } - for (Entry, CompoundTag> entry : nbtMapLoc.entrySet()) { - Triple key = entry.getKey(); - setTile(getIndex(key.getFirst(), key.getSecond(), key.getThird()), entry.getValue()); + for (Map.Entry entry : nbtMapLoc.entrySet()) { + IntegerTrio key = entry.getKey(); + setTile(getIndex(key.x, key.y, key.z), entry.getValue()); } nbtMapLoc.clear(); } @@ -263,7 +266,7 @@ public class MemoryOptimizedClipboard extends LinearClipboard { @Override public boolean setTile(int x, int y, int z, CompoundTag tag) { - nbtMapLoc.put(new Triple<>(x, y, z), tag); + nbtMapLoc.put(new IntegerTrio(x, y, z), tag); return true; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java index 9597faa15..1fe4f1ef9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java @@ -15,7 +15,6 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; import java.util.List; import java.util.function.Supplier; -import org.jetbrains.annotations.NotNull; public abstract class ReadOnlyClipboard extends SimpleClipboard { public final Region region; @@ -69,8 +68,6 @@ public abstract class ReadOnlyClipboard extends SimpleClipboard { }; } - @NotNull - @Override public Region getRegion() { return region; } @@ -84,7 +81,7 @@ public abstract class ReadOnlyClipboard extends SimpleClipboard { public abstract List getEntities(); @Override - public > boolean setBlock(int x, int y, int z, B block) { + public boolean setBlock(int x, int y, int z, BlockStateHolder block) { throw new UnsupportedOperationException("Clipboard is immutable"); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/SimpleClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/SimpleClipboard.java index 507d74f74..b614e5bef 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/SimpleClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/SimpleClipboard.java @@ -6,7 +6,6 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import java.io.Closeable; -import org.jetbrains.annotations.NotNull; public abstract class SimpleClipboard implements Clipboard, Closeable { private final BlockVector3 size; @@ -45,7 +44,6 @@ public abstract class SimpleClipboard implements Clipboard, Closeable { return size.subtract(BlockVector3.ONE); } - @NotNull @Override public Region getRegion() { return new CuboidRegion(BlockVector3.at(0, 0, 0), BlockVector3.at(getWidth() - 1, getHeight() - 1, getLength() - 1)); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCutClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCutClipboard.java new file mode 100644 index 000000000..ed4287ef5 --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCutClipboard.java @@ -0,0 +1,55 @@ +package com.boydti.fawe.object.clipboard; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockTypes; + +import java.io.Closeable; +import java.io.IOException; +import java.util.function.Supplier; + +public class WorldCutClipboard extends WorldCopyClipboard { + public WorldCutClipboard(Supplier supplier, Region region) { + super(supplier, region); + } + + public WorldCutClipboard(Supplier supplier, Region region, boolean hasEntities, boolean hasBiomes) { + super(supplier, region, hasEntities, hasBiomes); + } + + @Override + public BaseBlock getFullBlock(int x, int y, int z) { + Extent extent = getExtent(); + BaseBlock block = extent.getFullBlock(x, y, z); + extent.setBlock(x, y, z, BlockTypes.AIR.getDefaultState()); + return block; + } + + @Override + public BlockState getBlock(int x, int y, int z) { + Extent extent = getExtent(); + BlockState block = extent.getBlock(x, y, z); + extent.setBlock(x, y, z, BlockTypes.AIR.getDefaultState()); + return block; + } + + @Override + public void close() { + Extent extent = getExtent(); + if (extent instanceof EditSession) { + ((EditSession) extent).flushQueue(); + } else if (extent instanceof Closeable) { + try { + ((Closeable) extent).close(); + } catch (IOException e) { + e.printStackTrace(); + } + } else { + extent.commit(); + } + } +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/AdaptedMap.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/AdaptedMap.java index 7814daf50..87c9a247a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/AdaptedMap.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/AdaptedMap.java @@ -1,6 +1,5 @@ package com.boydti.fawe.object.collection; -import com.google.common.base.Functions; import org.jetbrains.annotations.NotNull; import java.util.Collections; @@ -16,7 +15,7 @@ public class AdaptedMap implements IAdaptedMap { private final Function value; private final Function key; - private static final Function SAME = Functions.identity(); + private static final Function SAME = o -> o; private static final Function IMMUTABLE = o -> { throw new UnsupportedOperationException("Immutable"); }; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockSet.java index 30dec1e54..0edf2c6bd 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockSet.java @@ -6,7 +6,6 @@ import com.sk89q.worldedit.regions.AbstractRegion; import com.sk89q.worldedit.regions.RegionOperationException; import java.util.Iterator; import java.util.Set; -import org.jetbrains.annotations.NotNull; public abstract class BlockSet extends AbstractRegion { private final int chunkOffsetX; @@ -93,7 +92,6 @@ public abstract class BlockSet extends AbstractRegion { public abstract void set(int x, int y, int z); public abstract void clear(int x, int y, int z); public abstract boolean remove(int x, int y, int z); - @NotNull @Override public abstract Iterator iterator(); @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVectorSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVectorSet.java index e4e6c2274..74dc46802 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVectorSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVectorSet.java @@ -180,7 +180,7 @@ public class BlockVectorSet extends AbstractCollection implements public boolean retainAll(@NotNull Collection c) { Objects.requireNonNull(c); boolean modified = false; - Iterator it = iterator(); + Iterator it = iterator(); while (it.hasNext()) { if (!c.contains(it.next())) { it.remove(); @@ -192,7 +192,11 @@ public class BlockVectorSet extends AbstractCollection implements @Override public boolean removeAll(Collection c) { - return c.stream().map(this::remove).reduce(false, (a, b) -> a || b); + boolean result = false; + for (Object o : c) { + result |= remove(o); + } + return result; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/CleanableThreadLocal.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/CleanableThreadLocal.java index 99abe1afa..87aef5b8d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/CleanableThreadLocal.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/CleanableThreadLocal.java @@ -87,7 +87,7 @@ public class CleanableThreadLocal extends ThreadLocal implements Closeable return list; } - public static void iterate(ThreadLocal instance, Consumer withMap) { + public static void iterate(ThreadLocal instance, Consumer withMap) { try { Thread[] threads = MainUtil.getThreads(); Field tl = Thread.class.getDeclaredField("threadLocals"); @@ -105,7 +105,7 @@ public class CleanableThreadLocal extends ThreadLocal implements Closeable } } - public static void clean(ThreadLocal instance) { + public static void clean(ThreadLocal instance) { iterate(instance, new Consumer() { Method methodRemove; @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/DifferentialArray.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/DifferentialArray.java index eeb859282..47ea5c752 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/DifferentialArray.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/DifferentialArray.java @@ -35,7 +35,7 @@ public final class DifferentialArray implements DifferentialCollection { public DifferentialArray(T array) { checkNotNull(array); - Class clazz = array.getClass(); + Class clazz = array.getClass(); checkArgument(clazz.isArray(), "Data must be an array"); checkArgument(clazz.getComponentType().isPrimitive(), "Data must be a primitive array"); this.data = array; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/DifferentialBlockBuffer.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/DifferentialBlockBuffer.java index 2682aa8e0..ce6efa400 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/DifferentialBlockBuffer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/DifferentialBlockBuffer.java @@ -148,7 +148,7 @@ public final class DifferentialBlockBuffer implements DifferentialCollection { offsetX = offsetZ = Integer.MAX_VALUE; this.set = new SparseBitSet(); } - public LocalBlockVectorSet(LocalBlockVectorSet copy) { - this.offsetX = copy.offsetX; - this.offsetZ = copy.offsetZ; - this.set = copy.set.clone(); - } public LocalBlockVectorSet(int x, int z, SparseBitSet set) { this.offsetX = x; @@ -60,7 +55,12 @@ public class LocalBlockVectorSet implements Set { } return false; } - + + @Override + public LocalBlockVectorSet clone() { + return new LocalBlockVectorSet(offsetX, offsetZ, set.clone()); + } + public boolean containsRadius(int x, int y, int z, int radius) { if (radius <= 0) { return contains(x, y, z); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/LongHashSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/LongHashSet.java index 61c9ea1c8..2d9e37a1e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/LongHashSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/LongHashSet.java @@ -60,11 +60,11 @@ public class LongHashSet { public void add(long key) { int mainIdx = (int) (key & 255); - long[][] outer = this.values[mainIdx]; + long outer[][] = this.values[mainIdx]; if (outer == null) this.values[mainIdx] = outer = new long[256][]; int outerIdx = (int) ((key >> 32) & 255); - long[] inner = outer[outerIdx]; + long inner[] = outer[outerIdx]; if (inner == null) { synchronized (this) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/MemBlockSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/MemBlockSet.java index 779b927ed..3a7735439 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/MemBlockSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/MemBlockSet.java @@ -73,12 +73,10 @@ public final class MemBlockSet extends BlockSet { return rows[x >> 4].remove(this.rows, x, y, z - getBlockOffsetZ()); } - @Override public BlockVector3 getMinimumPoint() { return BlockVector3.at(getMinX(), getMinimumY(), getMinZ()); } - @Override public BlockVector3 getMaximumPoint() { return BlockVector3.at(getMaxX(), getMaximumY(), getMaxZ()); } @@ -175,10 +173,8 @@ public final class MemBlockSet extends BlockSet { }; } - @Override public Set getChunkCubes() { return new AbstractSet() { - @NotNull @Override public Iterator iterator() { return new Iterator() { @@ -283,6 +279,7 @@ public final class MemBlockSet extends BlockSet { }; } + @Override public int getMinimumY() { int maxY = 15; int maxy = 16; @@ -327,6 +324,7 @@ public final class MemBlockSet extends BlockSet { return by; } + @Override public int getMaximumY() { int maxY = 0; int maxy = 0; @@ -359,8 +357,8 @@ public final class MemBlockSet extends BlockSet { maxy = y + 1; } by = (Y << 4) + y; - if (by == FaweCache.worldMaxY) - return FaweCache.worldMaxY; + if (by == FaweCache.WORLD_MAX_Y) + return FaweCache.WORLD_MAX_Y; break outer; } } @@ -741,7 +739,6 @@ public final class MemBlockSet extends BlockSet { return total; } - @Override public void clear() { Arrays.fill(rows, NULL_ROW_X); } @@ -830,7 +827,7 @@ public final class MemBlockSet extends BlockSet { public final IRow[] rows; public RowZ() { - this.rows = new IRow[FaweCache.chunkLayers]; + this.rows = new IRow[FaweCache.CHUNK_LAYERS]; reset(); } @@ -864,7 +861,12 @@ public final class MemBlockSet extends BlockSet { } public boolean isEmpty() { - return Arrays.stream(rows).noneMatch(row -> row instanceof RowY); + for (IRow row :rows) { + if (row instanceof RowY) { + return false; + } + } + return true; } public void reset(int layer) { @@ -872,7 +874,7 @@ public final class MemBlockSet extends BlockSet { } public void reset() { - for (int i = 0; i < FaweCache.chunkLayers; i++) rows[i] = NULL_ROW_Y; + for (int i = 0; i < FaweCache.CHUNK_LAYERS; i++) rows[i] = NULL_ROW_Y; } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/PrimitiveList.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/PrimitiveList.java new file mode 100644 index 000000000..84b2ccd5e --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/PrimitiveList.java @@ -0,0 +1,338 @@ +package com.boydti.fawe.object.collection; + +import java.lang.reflect.Array; +import java.util.AbstractList; + +public class PrimitiveList extends AbstractList { + private final Class primitive; + private final Type type; + private int length; + private int totalLength; + private Object arr; + + private enum Type { + Byte, + Boolean, + Short, + Character, + Integer, + Float, + Long, + Double + } + + public PrimitiveList(Class type) { + try { + Class boxed; + if (type.isPrimitive()) { + this.primitive = type; + boxed = (Class) Array.get(Array.newInstance(primitive, 1), 0).getClass(); + } else { + this.primitive = (Class) type.getField("TYPE").get(null); + boxed = type; + } + this.type = Type.valueOf(boxed.getSimpleName()); + } catch (Throwable e) { + throw new RuntimeException(e); + } + length = 0; + totalLength = 0; + arr = Array.newInstance(primitive, 0); + } + + public PrimitiveList(T[] arr) { + try { + Class boxed = (Class) arr.getClass().getComponentType(); + this.primitive = (Class) boxed.getField("TYPE").get(null); + this.type = Type.valueOf(boxed.getSimpleName()); + } catch (Throwable e) { + throw new RuntimeException(e); + } + this.arr = Array.newInstance(primitive, arr.length); + for (int i = 0; i < arr.length; i++) { + T val = arr[i]; + if (val != null) setFast(i, val); + } + this.length = arr.length; + this.totalLength = length; + } + + public PrimitiveList(Object arr) { + if (!arr.getClass().isArray()) { + throw new IllegalArgumentException("Argument must be an array!"); + } + this.primitive = arr.getClass().getComponentType(); + Class boxed = (Class) Array.get(Array.newInstance(primitive, 1), 0).getClass(); + this.type = Type.valueOf(boxed.getSimpleName()); + this.arr = arr; + this.length = Array.getLength(arr); + this.totalLength = length; + } + + public Object getArray() { + return arr; + } + + @Override + public T get(int index) { + return (T) getFast(index); + } + + public byte getByte(int index) { + return type == Type.Double ? ((byte[]) arr)[index] : (byte) getFast(index); + } + + public boolean getBoolean(int index) { + return type == Type.Boolean ? ((boolean[]) arr)[index] : (boolean) getFast(index); + } + + public short getShort(int index) { + return type == Type.Short ? ((short[]) arr)[index] : (short) getFast(index); + } + + public char getCharacter(int index) { + return type == Type.Character ? ((char[]) arr)[index] : (char) getFast(index); + } + + public int getInt(int index) { + return type == Type.Integer ? ((int[]) arr)[index] : (int) getFast(index); + } + + public float getFloat(int index) { + return type == Type.Float ? ((float[]) arr)[index] : (float) getFast(index); + } + + public long getLong(int index) { + return type == Type.Long ? ((long[]) arr)[index] : (long) getFast(index); + } + + public double getDouble(int index) { + return type == Type.Double ? ((double[]) arr)[index] : (double) getFast(index); + } + + private final Object getFast(int index) { + switch (type) { + case Byte: + return ((byte[]) arr)[index]; + case Boolean: + return ((boolean[]) arr)[index]; + case Short: + return ((short[]) arr)[index]; + case Character: + return ((char[]) arr)[index]; + case Integer: + return ((int[]) arr)[index]; + case Float: + return ((float[]) arr)[index]; + case Long: + return ((long[]) arr)[index]; + case Double: + return ((double[]) arr)[index]; + } + return null; + } + + @Override + public T set(int index, T element) { + T value = get(index); + setFast(index, element); + return value; + } + + public void set(int index, char value) { + switch (type) { + case Character: + ((char[]) arr)[index] = value; + return; + default: + setFast(index, value); + return; + } + } + + public void set(int index, byte value) { + switch (type) { + case Byte: + ((byte[]) arr)[index] = value; + return; + default: + setFast(index, value); + return; + } + } + + public void set(int index, int value) { + switch (type) { + case Integer: + ((int[]) arr)[index] = value; + return; + case Long: + ((long[]) arr)[index] = (long) value; + return; + case Double: + ((double[]) arr)[index] = (double) value; + return; + default: + setFast(index, value); + return; + } + } + + public void set(int index, long value) { + switch (type) { + case Integer: + ((int[]) arr)[index] = (int) value; + return; + case Long: + ((long[]) arr)[index] = value; + return; + case Double: + ((double[]) arr)[index] = (double) value; + return; + default: + setFast(index, value); + return; + } + } + + public void set(int index, double value) { + switch (type) { + case Float: + ((float[]) arr)[index] = (float) value; + return; + case Long: + ((long[]) arr)[index] = (long) value; + return; + case Double: + ((double[]) arr)[index] = value; + return; + default: + setFast(index, value); + return; + } + } + + public final void setFast(int index, Object element) { + switch (type) { + case Byte: + ((byte[]) arr)[index] = (byte) element; + return; + case Boolean: + ((boolean[]) arr)[index] = (boolean) element; + return; + case Short: + ((short[]) arr)[index] = (short) element; + return; + case Character: + ((char[]) arr)[index] = (char) element; + return; + case Integer: + ((int[]) arr)[index] = (int) element; + return; + case Float: + ((float[]) arr)[index] = (float) element; + return; + case Long: + ((long[]) arr)[index] = (long) element; + return; + case Double: + ((double[]) arr)[index] = (double) element; + return; + } + } + + + @Override + public void add(int index, T element) { + if (index == length) { + if (totalLength == length) { + Object tmp = arr; + totalLength = (length << 1) + 16; + arr = Array.newInstance(primitive, totalLength); + System.arraycopy(tmp, 0, arr, 0, length); + } + setFast(length, element); + length++; + } else { + if (totalLength == length) { + Object tmp = arr; + totalLength = (length << 1) + 16; + arr = Array.newInstance(primitive, totalLength); + System.arraycopy(tmp, 0, arr, 0, index); + } + System.arraycopy(arr, index, arr, index + 1, length - index); + set(index, element); + length++; + } + } + + private void ensureAddCapacity() { + if (totalLength == length) { + Object tmp = arr; + totalLength = (length << 1) + 16; + arr = Array.newInstance(primitive, totalLength); + System.arraycopy(tmp, 0, arr, 0, length); + } + } + + @Override + public boolean add(T element) { + ensureAddCapacity(); + setFast(length++, element); + return true; + } + + public boolean add(int element) { + ensureAddCapacity(); + set(length++, element); + return true; + } + + public boolean add(long element) { + ensureAddCapacity(); + set(length++, element); + return true; + } + + public boolean add(double element) { + ensureAddCapacity(); + set(length++, element); + return true; + } + + public boolean add(byte element) { + ensureAddCapacity(); + set(length++, element); + return true; + } + + public boolean add(char element) { + ensureAddCapacity(); + set(length++, element); + return true; + } + + @Override + public T remove(int index) { + if (index < 0 || index > length) throw new IndexOutOfBoundsException(index + " not in [0, " + length + "]"); + T value = get(index); + if (index != length) { + System.arraycopy(arr, index + 1, arr, index, length - index - 1); + } + length--; + return value; + } + + @Override + public int size() { + return length; + } + + @Override + public void clear() { + if (length != 0) { + this.arr = Array.newInstance(primitive, 0); + } + length = 0; + } +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/SparseBitSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/SparseBitSet.java index db03b1b6d..79055a77b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/SparseBitSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/SparseBitSet.java @@ -1,48 +1,47 @@ // CHECKSTYLE:OFF package com.boydti.fawe.object.collection; -/* This software is the work of Paladin Software International, Incorporated, +/*- This software is the work of Paladin Software International, Incorporated, * based upon previous work done for and by Sun Microsystems, Inc. */ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; -import java.util.Arrays; /** * This class implements a set of bits that grows as needed. Each bit of the - * bit set represents a {@code boolean} value. The values of a - * {@code SparseBitSet} are indexed by non-negative integers. + * bit set represents a boolean value. The values of a + * SparseBitSet are indexed by non-negative integers. * Individual indexed values may be examined, set, cleared, or modified by - * logical operations. One {@code SparseBitSet} or logical value may be - * used to modify the contents of (another) {@code SparseBitSet} through + * logical operations. One SparseBitSet or logical value may be + * used to modify the contents of (another) SparseBitSet through * logical AND, logical inclusive OR, logical exclusive * OR, and And NOT operations over all or part of the bit sets. *

- * All values in a bit set initially have the value {@code false}. + * All values in a bit set initially have the value false. *

* Every bit set has a current size, which is the number of bits of space * nominally in use by the bit set from the first set bit to just after * the last set bit. The length of the bit set effectively tells the position * available after the last bit of the SparseBitSet. *

- * The maximum cardinality of a {@code SparseBitSet} is - * {@link Integer#MAX_VALUE}, which means the bits of a - * {@code SparseBitSet} are labelled {@code 0} ..  - * {@code Integer.MAX_VALUE − 1}. - * After the last set bit of a {@code SparseBitSet}, any attempt to find + * The maximum cardinality of a SparseBitSet is + * Integer.MAX_VALUE, which means the bits of a + * SparseBitSet are labelled + * 0 .. Integer.MAX_VALUE − 1. + * After the last set bit of a SparseBitSet, any attempt to find * a subsequent bit (nextSetBit()), will return an value of −1. * If an attempt is made to use nextClearBit(), and all the bits are * set from the starting position of the search to the bit labelled - * {@code Integer.MAX_VALUE − 1}, then similarly −1 + * Integer.MAX_VALUE − 1, then similarly −1 * will be returned. *

* Unless otherwise noted, passing a null parameter to any of the methods in - * a {@code SparseBitSet} will result in a - * {@link NullPointerException}. + * a SparseBitSet will result in a + * NullPointerException. *

- * A {@code SparseBitSet} is not safe for multi-threaded use without + * A SparseBitSet is not safe for multi-threaded use without * external synchronization. * * @author Bruce K. Haddon @@ -52,6 +51,7 @@ import java.util.Arrays; * @version 1.0, 2009-03-17 * @since 1.6 */ +@SuppressWarnings("ALL") public class SparseBitSet implements Cloneable, Serializable { /* My apologies for listing all the additional authors, but concepts, code, @@ -123,7 +123,7 @@ public class SparseBitSet implements Cloneable, Serializable /** * The storage for this SparseBitSet. The ith bit is stored in a word - * represented by a long value, and is at bit position {@code i % 64} + * represented by a long value, and is at bit position i % 64 * within that word (where bit position 0 refers to the least significant bit * and 63 refers to the most significant bit). *

@@ -334,7 +334,7 @@ public class SparseBitSet implements Cloneable, Serializable /** * Constructor for a new (sparse) bit set. All bits initially are effectively - * {@code false}. This is a internal constructor that collects all the + * false. This is a internal constructor that collects all the * needed actions to initialise the bit set. *

* The capacity is taken to be a suggestion for a size of the bit set, @@ -365,7 +365,7 @@ public class SparseBitSet implements Cloneable, Serializable /** * Constructs an empty bit set with the default initial size. - * Initially all bits are effectively {@code false}. + * Initially all bits are effectively false. * * @since 1.6 */ @@ -377,9 +377,9 @@ public class SparseBitSet implements Cloneable, Serializable /** * Creates a bit set whose initial size is large enough to efficiently - * represent bits with indices in the range {@code 0} through - * at least {@code nbits-1}. Initially all bits are effectively - * {@code false}. + * represent bits with indices in the range 0 through + * at least nbits-1. Initially all bits are effectively + * false. *

* No guarantees are given for how large or small the actual object will be. * The setting of bits above the given range is permitted (and will perhaps @@ -399,8 +399,8 @@ public class SparseBitSet implements Cloneable, Serializable /** * Performs a logical AND of the addressed target bit with the argument * value. This bit set is modified so that the addressed bit has the value - * {@code true} if and only if it both initially had the value - * {@code true} and the argument value is also {@code true}. + * true if and only if it both initially had the value + * true and the argument value is also true. * * @param i a bit index * @param value a boolean value to AND with that bit @@ -419,17 +419,17 @@ public class SparseBitSet implements Cloneable, Serializable /** * Performs a logical AND of this target bit set with the argument bit * set within the given range of bits. Within the range, this bit set is - * modified so that each bit in it has the value {@code true} if and only - * if it both initially had the value {@code true} and the corresponding - * bit in the bit set argument also had the value {@code true}. Outside + * modified so that each bit in it has the value true if and only + * if it both initially had the value true and the corresponding + * bit in the bit set argument also had the value true. Outside * the range, this set is not changed. * * @param i index of the first bit to be included in the operation * @param j index after the last bit to included in the operation * @param b a SparseBitSet - * @exception IndexOutOfBoundsException if {@code i} is negative or - * equal to Integer.MAX_VALUE, or {@code j} is negative, - * or {@code i} is larger than {@code j} + * @exception IndexOutOfBoundsException if i is negative or + * equal to Integer.MAX_VALUE, or j is negative, + * or i is larger than j * @since 1.6 */ public void and(int i, int j, SparseBitSet b) throws IndexOutOfBoundsException @@ -440,9 +440,9 @@ public class SparseBitSet implements Cloneable, Serializable /** * Performs a logical AND of this target bit set with the argument bit * set. This bit set is modified so that each bit in it has the value - * {@code true} if and only if it both initially had the value - * {@code true} and the corresponding bit in the bit set argument also - * had the value {@code true}. + * true if and only if it both initially had the value + * true and the corresponding bit in the bit set argument also + * had the value true. * * @param b a SparseBitSet * @since 1.6 @@ -454,11 +454,11 @@ public class SparseBitSet implements Cloneable, Serializable } /** - * Performs a logical AND of the two given {@code SparseBitSet}s. - * The returned {@code SparseBitSet} is created so that each bit in it - * has the value {@code true} if and only if both the given sets - * initially had the corresponding bits {@code true}, otherwise - * {@code false}. + * Performs a logical AND of the two given SparseBitSets. + * The returned SparseBitSet is created so that each bit in it + * has the value true if and only if both the given sets + * initially had the corresponding bits true, otherwise + * false. * * @param a a SparseBitSet * @param b another SparseBitSet @@ -475,8 +475,8 @@ public class SparseBitSet implements Cloneable, Serializable /** * Performs a logical AndNOT of the addressed target bit with the * argument value. This bit set is modified so that the addressed bit has the - * value {@code true} if and only if it both initially had the value - * {@code true} and the argument value is {@code false}. + * value true if and only if it both initially had the value + * true and the argument value is false. * * @param i a bit index * @param value a boolean value to AndNOT with that bit @@ -495,17 +495,17 @@ public class SparseBitSet implements Cloneable, Serializable /** * Performs a logical AndNOT of this target bit set with the argument * bit set within the given range of bits. Within the range, this bit set is - * modified so that each bit in it has the value {@code true} if and only - * if it both initially had the value {@code true} and the corresponding - * bit in the bit set argument has the value {@code false}. Outside + * modified so that each bit in it has the value true if and only + * if it both initially had the value true and the corresponding + * bit in the bit set argument has the value false. Outside * the range, this set is not changed. * * @param i index of the first bit to be included in the operation * @param j index after the last bit to included in the operation * @param b the SparseBitSet with which to mask this SparseBitSet - * @exception IndexOutOfBoundsException if {@code i} is negative or - * equal to Integer.MAX_VALUE, or {@code j} is negative, - * or {@code i} is larger than {@code j} + * @exception IndexOutOfBoundsException if i is negative or + * equal to Integer.MAX_VALUE, or j is negative, + * or i is larger than j * @since 1.6 */ public void andNot(int i, int j, SparseBitSet b) @@ -517,9 +517,9 @@ public class SparseBitSet implements Cloneable, Serializable /** * Performs a logical AndNOT of this target bit set with the argument * bit set. This bit set is modified so that each bit in it has the value - * {@code true} if and only if it both initially had the value - * {@code true} and the corresponding bit in the bit set argument has - * the value {@code false}. + * true if and only if it both initially had the value + * true and the corresponding bit in the bit set argument has + * the value false. * * @param b the SparseBitSet with which to mask this SparseBitSet * @since 1.6 @@ -530,12 +530,12 @@ public class SparseBitSet implements Cloneable, Serializable } /** - * Creates a bit set from thie first {@code SparseBitSet} whose + * Creates a bit set from thie first SparseBitSet whose * corresponding bits are cleared by the set bits of the second - * {@code SparseBitSet}. The resulting bit set is created so that a bit - * in it has the value {@code true} if and only if the corresponding bit - * in the {@code SparseBitSet} of the first is set, and that same - * corresponding bit is not set in the {@code SparseBitSet} of the second + * SparseBitSet. The resulting bit set is created so that a bit + * in it has the value true if and only if the corresponding bit + * in the SparseBitSet of the first is set, and that same + * corresponding bit is not set in the SparseBitSet of the second * argument. * * @param a a SparseBitSet @@ -552,8 +552,8 @@ public class SparseBitSet implements Cloneable, Serializable } /** - * Returns the number of bits set to {@code true} in this - * {@code SparseBitSet}. + * Returns the number of bits set to true in this + * SparseBitSet. * * @return the number of bits set to true in this SparseBitSet * @since 1.6 @@ -565,7 +565,7 @@ public class SparseBitSet implements Cloneable, Serializable } /** - * Sets the bit at the specified index to {@code false}. + * Sets the bit at the specified index to false. * * @param i a bit index. * @exception IndexOutOfBoundsException if the specified index is negative @@ -593,14 +593,14 @@ public class SparseBitSet implements Cloneable, Serializable } /** - * Sets the bits from the specified {@code i} (inclusive) to the - * specified {@code j} (exclusive) to {@code false}. + * Sets the bits from the specified i (inclusive) to the + * specified j (exclusive) to false. * * @param i index of the first bit to be cleared * @param j index after the last bit to be cleared - * @exception IndexOutOfBoundsException if {@code i} is negative or - * equal to Integer.MAX_VALUE, or {@code j} is negative, - * or {@code i} is larger than {@code j} + * @exception IndexOutOfBoundsException if i is negative or + * equal to Integer.MAX_VALUE, or j is negative, + * or i is larger than j * @since 1.6 */ public void clear(int i, int j) throws IndexOutOfBoundsException @@ -609,8 +609,8 @@ public class SparseBitSet implements Cloneable, Serializable } /** - * Sets all of the bits in this {@code SparseBitSet} to - * {@code false}. + * Sets all of the bits in this SparseBitSet to + * false. * * @since 1.6 */ @@ -621,15 +621,15 @@ public class SparseBitSet implements Cloneable, Serializable } /** - * Cloning this {@code SparseBitSet} produces a new - * {@code SparseBitSet} that is equal() to it. The clone of the + * Cloning this SparseBitSet produces a new + * SparseBitSet that is equal() to it. The clone of the * bit set is another bit set that has exactly the same bits set to - * {@code true} as this bit set. + * true as this bit set. *

* Note: the actual space allocated to the clone tries to minimise the actual * amount of storage allocated to hold the bits, while still trying to * keep access to the bits being a rapid as possible. Since the space - * allocated to a {@code SparseBitSet} is not normally decreased, + * allocated to a SparseBitSet is not normally decreased, * replacing a bit set by its clone may be a way of both managing memory * consumption and improving the rapidity of access. * @@ -667,16 +667,16 @@ public class SparseBitSet implements Cloneable, Serializable /** * Compares this object against the specified object. The result is - * {@code true} if and only if the argument is not {@code null} - * and is a {@code SparseBitSet} object that has exactly the same bits - * set to {@code true} as this bit set. That is, for every nonnegative - * {@code i} indexing a bit in the set, + * true if and only if the argument is not null + * and is a SparseBitSet object that has exactly the same bits + * set to true as this bit set. That is, for every nonnegative + * i indexing a bit in the set, *

((SparseBitSet)obj).get(i) == this.get(i)
* must be true. * * @param obj the Object with which to compare - * @return {@code true} if the objects are equivalent; - * {@code false} otherwise. + * @return true if the objects are equivalent; + * false otherwise. * @since 1.6 */ @Override @@ -726,15 +726,15 @@ public class SparseBitSet implements Cloneable, Serializable } /** - * Sets each bit from the specified {@code i} (inclusive) to the - * specified {@code j} (exclusive) to the complement of its current + * Sets each bit from the specified i (inclusive) to the + * specified j (exclusive) to the complement of its current * value. * * @param i index of the first bit to flip * @param j index after the last bit to flip - * @exception IndexOutOfBoundsException if {@code i} is negative or is - * equal to Integer.MAX_VALUE, or {@code j} is negative, or - * {@code i} is larger than {@code j} + * @exception IndexOutOfBoundsException if i is negative or is + * equal to Integer.MAX_VALUE, or j is negative, or + * i is larger than j * @since 1.6 */ public void flip(int i, int j) throws IndexOutOfBoundsException @@ -744,9 +744,9 @@ public class SparseBitSet implements Cloneable, Serializable /** * Returns the value of the bit with the specified index. The value is - * {@code true} if the bit with the index {@code i} is currently set - * in this {@code SparseBitSet}; otherwise, the result is - * {@code false}. + * true if the bit with the index i is currently set + * in this SparseBitSet; otherwise, the result is + * false. * * @param i the bit index * @return the boolean value of the bit with the specified index. @@ -768,16 +768,16 @@ public class SparseBitSet implements Cloneable, Serializable } /** - * Returns a new {@code SparseBitSet} composed of bits from this - * {@code SparseBitSet} from {@code i} (inclusive) to {@code j} + * Returns a new SparseBitSet composed of bits from this + * SparseBitSet from i (inclusive) to j * (exclusive). * * @param i index of the first bit to include * @param j index after the last bit to include * @return a new SparseBitSet from a range of this SparseBitSet - * @exception IndexOutOfBoundsException if {@code i} is negative or is - * equal to Integer.MAX_VALUE, or {@code j} is negative, or - * {@code i} is larger than {@code j} + * @exception IndexOutOfBoundsException if i is negative or is + * equal to Integer.MAX_VALUE, or j is negative, or + * i is larger than j * @since 1.6 */ public SparseBitSet get(int i, int j) throws IndexOutOfBoundsException @@ -789,17 +789,17 @@ public class SparseBitSet implements Cloneable, Serializable /** * Returns a hash code value for this bit set. The hash code depends only on - * which bits have been set within this {@code SparseBitSet}. The + * which bits have been set within this SparseBitSet. The * algorithm used to compute it may be described as follows. *

- * Suppose the bits in the {@code SparseBitSet} were to be stored in an - * array of {@code long} integers called, say, {@code bits}, in such - * a manner that bit {@code i} is set in the {@code SparseBitSet} - * (for nonnegative values of {@code i}) if and only if the expression + * Suppose the bits in the SparseBitSet were to be stored in an + * array of long integers called, say, bits, in such + * a manner that bit i is set in the SparseBitSet + * (for nonnegative values of i) if and only if the expression *

      *  ((i>>6) < bits.length) && ((bits[i>>6] & (1L << (bit & 0x3F))) != 0)
      *  
- * is true. Then the following definition of the {@code hashCode} method + * is true. Then the following definition of the hashCode method * would be a correct implementation of the actual algorithm: *
      *  public int hashCode()
@@ -824,19 +824,19 @@ public class SparseBitSet implements Cloneable, Serializable
     }
 
     /**
-     *  Returns true if the specified {@code SparseBitSet} has any bits
-     *  within the given range {@code i} (inclusive) to {@code j}
-     *  (exclusive) set to {@code true} that are also set to {@code true}
-     *  in the same range of this {@code SparseBitSet}.
+     *  Returns true if the specified SparseBitSet has any bits
+     *  within the given range i (inclusive) to j
+     *  (exclusive) set to true that are also set to true
+     *  in the same range of this SparseBitSet.
      *
      * @param       i index of the first bit to include
      * @param       j index after the last bit to include
      * @param       b the SparseBitSet with which to intersect
      * @return      the boolean indicating whether this SparseBitSet intersects the
      *              specified SparseBitSet
-     * @exception   IndexOutOfBoundsException if {@code i} is negative or
-     *              equal to Integer.MAX_VALUE, or {@code j} is negative,
-     *              or {@code i} is larger than {@code j}
+     * @exception   IndexOutOfBoundsException if i is negative or
+     *              equal to Integer.MAX_VALUE, or j is negative,
+     *              or i is larger than j
      * @since       1.6
      */
     public boolean intersects(int i, int j, SparseBitSet b)
@@ -847,9 +847,9 @@ public class SparseBitSet implements Cloneable, Serializable
     }
 
     /**
-     *  Returns true if the specified {@code SparseBitSet} has any bits set to
-     *  {@code true} that are also set to {@code true} in this
-     *  {@code SparseBitSet}.
+     *  Returns true if the specified SparseBitSet has any bits set to
+     *  true that are also set to true in this
+     *  SparseBitSet.
      *
      * @param       b a SparseBitSet with which to intersect
      * @return      boolean indicating whether this SparseBitSet intersects the
@@ -863,8 +863,8 @@ public class SparseBitSet implements Cloneable, Serializable
     }
 
     /**
-     *  Returns true if this {@code SparseBitSet} contains no bits that are
-     *  set to {@code true}.
+     *  Returns true if this SparseBitSet contains no bits that are
+     *  set to true.
      *
      * @return      the boolean indicating whether this SparseBitSet is empty
      * @since       1.6
@@ -876,9 +876,9 @@ public class SparseBitSet implements Cloneable, Serializable
     }
 
     /**
-     *  Returns the "logical length" of this {@code SparseBitSet}: the index
-     *  of the highest set bit in the {@code SparseBitSet} plus one. Returns
-     *  zero if the {@code SparseBitSet} contains no set bits.
+     *  Returns the "logical length" of this SparseBitSet: the index
+     *  of the highest set bit in the SparseBitSet plus one. Returns
+     *  zero if the SparseBitSet contains no set bits.
      *
      * @return      the logical length of this SparseBitSet
      * @since       1.6
@@ -890,7 +890,7 @@ public class SparseBitSet implements Cloneable, Serializable
     }
 
     /**
-     *  Returns the index of the first bit that is set to {@code false} that
+     *  Returns the index of the first bit that is set to false that
      *  occurs on or after the specified starting index.
      *
      * @param       i the index to start checking from (inclusive)
@@ -957,12 +957,12 @@ public class SparseBitSet implements Cloneable, Serializable
     }
 
     /**
-     *  Returns the index of the first bit that is set to {@code true} that
+     *  Returns the index of the first bit that is set to true that
      *  occurs on or after the specified starting index. If no such it exists then
      *  -1 is returned.
      *  

- * To iterate over the {@code true} bits in a {@code SparseBitSet - * sbs}, use the following loop: + * To iterate over the true bits in a SparseBitSet + * sbs, use the following loop: * *

      *  for( int i = sbbits.nextSetBit(0); i >= 0; i = sbbits.nextSetBit(i+1) )
@@ -1168,8 +1168,8 @@ public class SparseBitSet implements Cloneable, Serializable
     /**
      *  Performs a logical OR of the addressed target bit with the
      *  argument value. This bit set is modified so that the addressed bit has the
-     *  value {@code true} if and only if it both initially had the value
-     *  {@code true} or the argument value is {@code true}.
+     *  value true if and only if it both initially had the value
+     *  true or the argument value is true.
      *
      * @param       i a bit index
      * @param       value a boolean value to OR with that bit
@@ -1188,18 +1188,18 @@ public class SparseBitSet implements Cloneable, Serializable
     /**
      *  Performs a logical OR of the addressed target bit with the
      *  argument value within the given range. This bit set is modified so that
-     *  within the range a bit in it has the value {@code true} if and only if
-     *  it either already had the value {@code true} or the corresponding bit
-     *  in the bit set argument has the value {@code true}. Outside the range
+     *  within the range a bit in it has the value true if and only if
+     *  it either already had the value true or the corresponding bit
+     *  in the bit set argument has the value true. Outside the range
      *  this set is not changed.
      *
      * @param       i index of the first bit to be included in the operation
      * @param       j index after the last bit to included in the operation
      * @param       b the SparseBitSet with which to perform the OR
      *              operation with this SparseBitSet
-     * @exception   IndexOutOfBoundsException if {@code i} is negative or
-     *              equal to Integer.MAX_VALUE, or {@code j} is negative,
-     *              or {@code i} is larger than {@code j}
+     * @exception   IndexOutOfBoundsException if i is negative or
+     *              equal to Integer.MAX_VALUE, or j is negative,
+     *              or i is larger than j
      * @since       1.6
      */
     public void or(int i, int j, SparseBitSet b) throws IndexOutOfBoundsException
@@ -1209,9 +1209,9 @@ public class SparseBitSet implements Cloneable, Serializable
 
     /**
      *  Performs a logical OR of this bit set with the bit set argument.
-     *  This bit set is modified so that a bit in it has the value {@code true}
-     *  if and only if it either already had the value {@code true} or the
-     *  corresponding bit in the bit set argument has the value {@code true}.
+     *  This bit set is modified so that a bit in it has the value true
+     *  if and only if it either already had the value true or the
+     *  corresponding bit in the bit set argument has the value true.
      *
      * @param       b the SparseBitSet with which to perform the OR
      *              operation with this SparseBitSet
@@ -1223,11 +1223,11 @@ public class SparseBitSet implements Cloneable, Serializable
     }
 
     /**
-     *  Performs a logical OR of the two given {@code SparseBitSet}s.
-     *  The returned {@code SparseBitSet} is created so that a bit in it has
-     *  the value {@code true} if and only if it either had the value
-     *  {@code true} in the set given by the first arguemetn or had the value
-     *  {@code true} in the second argument, otherwise {@code false}.
+     *  Performs a logical OR of the two given SparseBitSets.
+     *  The returned SparseBitSet is created so that a bit in it has
+     *  the value true if and only if it either had the value
+     *  true in the set given by the first arguemetn or had the value
+     *  true in the second argument, otherwise false.
      *
      * @param       a a SparseBitSet
      * @param       b another SparseBitSet
@@ -1287,14 +1287,14 @@ public class SparseBitSet implements Cloneable, Serializable
     }
 
     /**
-     *  Sets the bits from the specified {@code i} (inclusive) to the specified
-     *  {@code j} (exclusive) to {@code true}.
+     *  Sets the bits from the specified i (inclusive) to the specified
+     *  j (exclusive) to true.
      *
      * @param       i index of the first bit to be set
      * @param       j index after the last bit to be se
-     * @exception   IndexOutOfBoundsException if {@code i} is negative or is
-     *              equal to Integer.MAX_INT, or {@code j} is negative, or
-     *              {@code i} is larger than {@code j}.
+     * @exception   IndexOutOfBoundsException if i is negative or is
+     *              equal to Integer.MAX_INT, or j is negative, or
+     *              i is larger than j.
      * @since       1.6
      */
     public void set(int i, int j) throws IndexOutOfBoundsException
@@ -1303,15 +1303,15 @@ public class SparseBitSet implements Cloneable, Serializable
     }
 
     /**
-     *  Sets the bits from the specified {@code i} (inclusive) to the specified
-     *  {@code j} (exclusive) to the specified value.
+     *  Sets the bits from the specified i (inclusive) to the specified
+     *  j (exclusive) to the specified value.
      *
      * @param       i index of the first bit to be set
      * @param       j index after the last bit to be set
      * @param       value to which to set the selected bits
-     * @exception   IndexOutOfBoundsException if {@code i} is negative or is
-     *              equal to Integer.MAX_VALUE, or {@code j} is negative, or
-     *              {@code i} is larger than {@code j}
+     * @exception   IndexOutOfBoundsException if i is negative or is
+     *              equal to Integer.MAX_VALUE, or j is negative, or
+     *              i is larger than j
      * @since       1.6
      */
     public void set(int i, int j, boolean value)
@@ -1324,7 +1324,7 @@ public class SparseBitSet implements Cloneable, Serializable
 
     /**
      *  Returns the number of bits of space nominally in use by this
-     *  {@code SparseBitSet} to represent bit values. The count of bits in
+     *  SparseBitSet to represent bit values. The count of bits in
      *  the set is the (label of the last set bit) + 1 - (the label of the first
      *  set bit).
      *
@@ -1360,7 +1360,7 @@ public class SparseBitSet implements Cloneable, Serializable
      *  

* This method is intended for diagnostic use (as it is relatively expensive * in time), but can be useful in understanding an application's use of a - * {@code SparseBitSet}. + * SparseBitSet. * * @param values an array for the individual results (if not null) * @return a String detailing the statistics of the bit set @@ -1423,7 +1423,7 @@ public class SparseBitSet implements Cloneable, Serializable /** * Returns a string representation of this bit set. For every index for which - * this {@code SparseBitSet} contains a bit in the set state, the decimal + * this SparseBitSet contains a bit in the set state, the decimal * representation of that index is included in the result. Such indices are * listed in order from lowest to highest. If there is a subsequence of set * bits longer than the value given by toStringCompaction, the subsequence @@ -1437,22 +1437,22 @@ public class SparseBitSet implements Cloneable, Serializable *

      *      SparseBitSet drPepper = new SparseBitSet();
      *  
- * Now {@code drPepper.toString()} returns "{@code {}}". + * Now drPepper.toString() returns "{}". *
*
      *      drPepper.set(2);
      *  
- * Now {@code drPepper.toString()} returns "{@code {2}}". + * Now drPepper.toString() returns "{2}". *
*
      *      drPepper.set(3, 4);
      *      drPepper.set(10);
      *  
- * Now {@code drPepper.toString()} returns "{@code {2..4, 10}}". + * Now drPepper.toString() returns "{2..4, 10}". *
* This method is intended for diagnostic use (as it is relatively expensive * in time), but can be useful in interpreting problems in an application's use - * of a {@code SparseBitSet}. + * of a SparseBitSet. * * @return a String representation of this SparseBitSet * @see #toStringCompaction(int length) @@ -1504,18 +1504,18 @@ public class SparseBitSet implements Cloneable, Serializable } /** Sequences of set bits longer than this value are shown by - * {@link #toString()} as a "sub-sequence," in the form {@code a..b}. + * {@link #toString()} as a "sub-sequence," in the form a..b. * Setting this value to zero causes each set bit to be listed individually. * The default default value is 2 (which means sequences of three or more * bits set are shown as a subsequence, and all other set bits are listed * individually). *

- * Note: this value will be passed to {@code SparseBitSet}s that + * Note: this value will be passed to SparseBitSets that * may be created within or as a result of the operations on this bit set, * or, for static methods, from the value belonging to the first parameter. * * @param count the maximum count of a run of bits that are shown as - * individual entries in a {@code toString}() conversion. + * individual entries in a toString() conversion. * If 0, all bits are shown individually. * @since 1.6 * @see #toString() @@ -1526,9 +1526,9 @@ public class SparseBitSet implements Cloneable, Serializable } /** - * If change is {@code true}, the current value of the + * If change is true, the current value of the * toStringCompaction() value is made the default value for all - * {@code SparseBitSet}s created from this point onward in this JVM. + * SparseBitSets created from this point onward in this JVM. * * @param change if true, change the default value * @since 1.6 @@ -1546,17 +1546,17 @@ public class SparseBitSet implements Cloneable, Serializable /** * Performs a logical XOR of the addressed target bit with the * argument value. This bit set is modified so that the addressed bit has the - * value {@code true} if and only one of the following statements holds: + * value true if and only one of the following statements holds: *

    - *
  • The addressed bit initially had the value {@code true}, and the - * value of the argument is {@code false}. - *
  • The bit initially had the value {@code false}, and the - * value of the argument is {@code true}. + *
  • The addressed bit initially had the value true, and the + * value of the argument is false. + *
  • The bit initially had the value false, and the + * value of the argument is true. *
* * @param i a bit index * @param value a boolean value to XOR with that bit - * @exception IndexOutOfBoundsException if the specified index + * @exception java.lang.IndexOutOfBoundsException if the specified index * is negative * or equal to Integer.MAX_VALUE * @since 1.6 @@ -1572,13 +1572,13 @@ public class SparseBitSet implements Cloneable, Serializable /** * Performs a logical XOR of this bit set with the bit set argument * within the given range. This resulting bit set is computed so that a bit - * within the range in it has the value {@code true} if and only if one + * within the range in it has the value true if and only if one * of the following statements holds: *
    - *
  • The bit initially had the value {@code true}, and the - * corresponding bit in the argument set has the value {@code false}. - *
  • The bit initially had the value {@code false}, and the - * corresponding bit in the argument set has the value {@code true}. + *
  • The bit initially had the value true, and the + * corresponding bit in the argument set has the value false. + *
  • The bit initially had the value false, and the + * corresponding bit in the argument set has the value true. *
* Outside the range this set is not changed. * @@ -1586,9 +1586,9 @@ public class SparseBitSet implements Cloneable, Serializable * @param j index after the last bit to included in the operation * @param b the SparseBitSet with which to perform the XOR * operation with this SparseBitSet - * @exception IndexOutOfBoundsException if {@code i} is negative or - * equal to Integer.MAX_VALUE, or {@code j} is negative, - * or {@code i} is larger than {@code j} + * @exception IndexOutOfBoundsException if i is negative or + * equal to Integer.MAX_VALUE, or j is negative, + * or i is larger than j * @since 1.6 */ public void xor(int i, int j, SparseBitSet b) throws IndexOutOfBoundsException @@ -1599,12 +1599,12 @@ public class SparseBitSet implements Cloneable, Serializable /** * Performs a logical XOR of this bit set with the bit set argument. * This resulting bit set is computed so that a bit in it has the value - * {@code true} if and only if one of the following statements holds: + * true if and only if one of the following statements holds: *
    - *
  • The bit initially had the value {@code true}, and the - * corresponding bit in the argument set has the value {@code false}. - *
  • The bit initially had the value {@code false}, and the - * corresponding bit in the argument set has the value {@code true}. + *
  • The bit initially had the value true, and the + * corresponding bit in the argument set has the value false. + *
  • The bit initially had the value false, and the + * corresponding bit in the argument set has the value true. *
* * @param b the SparseBitSet with which to perform the XOR @@ -1617,16 +1617,16 @@ public class SparseBitSet implements Cloneable, Serializable } /** - * Performs a logical XOR of the two given {@code SparseBitSet}s. + * Performs a logical XOR of the two given SparseBitSets. * The resulting bit set is created so that a bit in it has the value - * {@code true} if and only if one of the following statements holds: + * true if and only if one of the following statements holds: *
    - *
  • A bit in the first argument has the value {@code true}, and the + *
  • A bit in the first argument has the value true, and the * corresponding bit in the second argument has the value - * {@code false}.
  • - *
  • A bit in the first argument has the value {@code false}, and the + * false.
  • + *
  • A bit in the first argument has the value false, and the * corresponding bit in the second argument has the value - * {@code true}.
+ * true. * * @param a a SparseBitSet * @param b another SparseBitSet @@ -1645,7 +1645,7 @@ public class SparseBitSet implements Cloneable, Serializable //============================================================================== /** - * Throw the exception to indicate a range error. The {@code String} + * Throw the exception to indicate a range error. The String * constructed reports all the possible errors in one message. * * @param i lower bound for a operation @@ -1743,7 +1743,7 @@ public class SparseBitSet implements Cloneable, Serializable * Scans over the bit set (and a second bit set if part of the operation) are * all performed by this method. The properties and the operation executed * are defined by a given strategy, which must be derived from the - * {@code AbstractStrategy}. The strategy defines how to operate on a + * AbstractStrategy. The strategy defines how to operate on a * single word, and on whole words that may or may not constitute a full * block of words. * @@ -1993,7 +1993,7 @@ public class SparseBitSet implements Cloneable, Serializable //============================================================================== /** - * Save the state of the {@code SparseBitSet} instance to a stream + * Save the state of the SparseBitSet instance to a stream * (i.e., serialize it). * * @param s the ObjectOutputStream to which to write the serialized object @@ -2004,10 +2004,10 @@ public class SparseBitSet implements Cloneable, Serializable * @serialData The default data is emitted, followed by the current * compactionCount for the bit set, and then the * length of the set (the position of the last bit), - * followed by the cache.count value (an {@code int}, - * the number of {@code int->long} pairs needed to describe - * the set), followed by the index ({@code int}) and word - * ({@code long}) for each {@code int->long} pair. + * followed by the cache.count value (an int, + * the number of int->long pairs needed to describe + * the set), followed by the index (int) and word + * (long) for each int->long pair. * The mappings need not be emitted in any particular order. This * is followed by the hashCode for the set that can be used * as an integrity check when the bit set is read back. @@ -2056,7 +2056,7 @@ public class SparseBitSet implements Cloneable, Serializable private static final long serialVersionUID = -6663013367427929992L; /** - * Reconstitute the {@code SparseBitSet} instance from a stream + * Reconstitute the SparseBitSet instance from a stream * (i.e., deserialize it). * * @param s the ObjectInputStream to use @@ -2110,12 +2110,12 @@ public class SparseBitSet implements Cloneable, Serializable /** * These enumeration values are used as labels for the values in the String * created by the statistics() method. The values of the corresponding - * statistics are {@code int}s, except for the loadFactor and - * Average_chain_length values, which are {@code float}s. + * statistics are ints, except for the loadFactor and + * Average_chain_length values, which are floats. *

- * An array of {@code String}s may be obtained containing a + * An array of Strings may be obtained containing a * representation of each of these values. An element of such an array, say, - * {@code values}, may be accessed, for example, by: + * values, may be accessed, for example, by: *

      *      values[SparseBitSet.statistics.Buckets_available.ordinal()]
* @@ -2243,12 +2243,12 @@ public class SparseBitSet implements Cloneable, Serializable /** * This strategy class is used by the setScanner to carry out the a variety * of operations on this set, and usually a second set. The - * setScanner() method of the main {@code SparseBitSet} class + * setScanner() method of the main SparseBitSet class * essentially finds matching level3 blocks, and then calls the strategy to * do the appropriate operation on each of the elements of the block. *

* The symbolic constants control optimisation paths in the - * setScanner() method of the main {@code SparseBitSet} class. + * setScanner() method of the main SparseBitSet class. * * @see SparseBitSet#setScanner(int i, int j, * SparseBitSet b, AbstractStrategy op) @@ -2366,7 +2366,10 @@ public class SparseBitSet implements Cloneable, Serializable */ protected final boolean isZeroBlock(long[] a3) { - return Arrays.stream(a3).noneMatch(word -> word != 0L); + for (long word : a3) + if (word != 0L) + return false; + return true; } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/YieldIterable.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/YieldIterable.java index f89147111..83025877e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/YieldIterable.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/YieldIterable.java @@ -1,6 +1,5 @@ package com.boydti.fawe.object.collection; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.Closeable; @@ -13,9 +12,9 @@ import java.util.function.Consumer; public class YieldIterable implements Iterable, Consumer, Closeable { private static final Object END_MARKER = new Object(); private final LinkedBlockingQueue queue; - private Future future; + private Future future; - public YieldIterable(@Nullable Future task) { + public YieldIterable(@Nullable Future task) { this.queue = new LinkedBlockingQueue<>(); this.future = task; } @@ -24,11 +23,10 @@ public class YieldIterable implements Iterable, Consumer, Closeable { this(null); } - public void setFuture(Future future) { + public void setFuture(Future future) { this.future = future; } - @NotNull @Override public Iterator iterator() { return new Iterator() { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java index bc530b82f..e4eeba80a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java @@ -71,7 +71,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public > boolean setBlock(int x, int y, int z, B block) throws WorldEditException { if (!contains(x, y, z)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOutsideRegion()); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOUTSIDE_REGION()); } return false; } @@ -82,7 +82,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public boolean setBiome(int x, int y, int z, BiomeType biome) { if (!contains(x, y, z)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOutsideRegion()); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOUTSIDE_REGION()); } return false; } @@ -93,7 +93,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public BiomeType getBiome(BlockVector2 position) { if (!contains(position)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOutsideRegion()); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOUTSIDE_REGION()); } return null; } @@ -104,7 +104,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public BiomeType getBiomeType(int x, int y, int z) { if (!contains(x, z)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOutsideRegion()); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOUTSIDE_REGION()); } return null; } @@ -115,7 +115,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public BaseBlock getFullBlock(BlockVector3 position) { if (!contains(position)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOutsideRegion()); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOUTSIDE_REGION()); } return BlockTypes.AIR.getDefaultState().toBaseBlock(); } @@ -126,7 +126,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public BlockState getBlock(BlockVector3 position) { if (!contains(position)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOutsideRegion()); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOUTSIDE_REGION()); } return BlockTypes.AIR.getDefaultState(); } @@ -137,7 +137,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public int getBlockLight(int x, int y, int z) { if (!contains(x, y, z)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOutsideRegion()); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOUTSIDE_REGION()); } return 0; } @@ -148,7 +148,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public int getBrightness(int x, int y, int z) { if (!contains(x, y, z)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOutsideRegion()); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOUTSIDE_REGION()); } return 0; } @@ -159,7 +159,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public int getLight(int x, int y, int z) { if (!contains(x, y, z)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOutsideRegion()); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOUTSIDE_REGION()); } return 0; } @@ -170,7 +170,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public int getOpacity(int x, int y, int z) { if (!contains(x, y, z)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOutsideRegion()); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOUTSIDE_REGION()); } return 0; } @@ -181,7 +181,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public int getSkyLight(int x, int y, int z) { if (!contains(x, y, z)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOutsideRegion()); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOUTSIDE_REGION()); } return 0; } @@ -193,7 +193,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public Entity createEntity(Location location, BaseEntity entity) { if (!contains(location.getBlockX(), location.getBlockY(), location.getBlockZ())) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOutsideRegion()); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getOUTSIDE_REGION()); } return null; } 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 029efe52c..cab4422f4 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 @@ -26,7 +26,7 @@ public class MemoryCheckingExtent extends PassthroughExtent { this.player.print(TranslatableComponent.of("fawe.info.worldedit.oom.admin")); } } - WEManager.IMP.cancelEdit(this, FaweCache.INSTANCE.getLowMemory()); + WEManager.IMP.cancelEdit(this, FaweCache.INSTANCE.getLOW_MEMORY()); } return super.getExtent(); } 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 a99e9c268..670186c6e 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 @@ -54,7 +54,7 @@ public class NullExtent extends FaweRegionExtent implements IBatchProcessor { } public NullExtent() { - this(new com.sk89q.worldedit.extent.NullExtent(), FaweCache.INSTANCE.getManual()); + this(new com.sk89q.worldedit.extent.NullExtent(), FaweCache.INSTANCE.getMANUAL()); } @Override 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 19f1af11e..3586e4590 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 @@ -2,6 +2,7 @@ package com.boydti.fawe.object.extent; import com.boydti.fawe.FaweCache; import com.boydti.fawe.object.FaweLimit; +import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.WEManager; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.BaseEntity; @@ -37,7 +38,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { return null; } if (!limit.MAX_ENTITIES()) { - WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getMaxEntities()); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getMAX_ENTITIES()); return null; } return super.createEntity(location, entity); @@ -46,7 +47,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { @Override public BlockState getBlock(int x, int y, int z) { if (!limit.MAX_CHECKS()) { - WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getMaxChecks()); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getMAX_CHECKS()); return BlockTypes.AIR.getDefaultState(); } else { return extent.getBlock(x, y, z); @@ -56,7 +57,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { @Override public BaseBlock getFullBlock(BlockVector3 pos) { if (!limit.MAX_CHECKS()) { - WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getMaxChecks()); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getMAX_CHECKS()); return BlockTypes.AIR.getDefaultState().toBaseBlock(); } else { return extent.getFullBlock(pos); @@ -78,18 +79,18 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { boolean hasNbt = block instanceof BaseBlock && block.hasNbtData(); if (hasNbt) { if (!limit.MAX_BLOCKSTATES()) { - WEManager.IMP.cancelEdit(this, FaweCache.INSTANCE.getMaxTiles()); + WEManager.IMP.cancelEdit(this, FaweCache.INSTANCE.getMAX_TILES()); return false; } else { if (!limit.MAX_CHANGES()) { - WEManager.IMP.cancelEdit(this, FaweCache.INSTANCE.getMaxChanges()); + WEManager.IMP.cancelEdit(this, FaweCache.INSTANCE.getMAX_CHANGES()); return false; } return extent.setBlock(x, y, z, block); } } if (!limit.MAX_CHANGES()) { - WEManager.IMP.cancelEdit(this, FaweCache.INSTANCE.getMaxChanges()); + WEManager.IMP.cancelEdit(this, FaweCache.INSTANCE.getMAX_CHANGES()); return false; } else { return extent.setBlock(x, y, z, block); @@ -99,7 +100,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { @Override public boolean setBiome(BlockVector2 position, BiomeType biome) { if (!limit.MAX_CHANGES()) { - WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getMaxChanges()); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getMAX_CHANGES()); return false; } return super.setBiome(position, biome); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSVisitor.java b/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSVisitor.java index 834662452..89f5634de 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSVisitor.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSVisitor.java @@ -4,6 +4,7 @@ import com.google.common.collect.Lists; import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.boydti.fawe.object.IntegerTrio; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.operation.Operation; @@ -19,7 +20,6 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; -import kotlin.Triple; public abstract class DFSVisitor implements Operation { @@ -57,11 +57,11 @@ public abstract class DFSVisitor implements Operation { return this.directions; } - private Triple[] getIntDirections() { - Triple[] array = new Triple[directions.size()]; + private IntegerTrio[] getIntDirections() { + IntegerTrio[] array = new IntegerTrio[directions.size()]; for (int i = 0; i < array.length; i++) { BlockVector3 dir = directions.get(i); - array[i] = new Triple<>(dir.getBlockX(), dir.getBlockY(), dir.getBlockZ()); + array[i] = new IntegerTrio(dir.getBlockX(), dir.getBlockY(), dir.getBlockZ()); } return array; } @@ -83,7 +83,7 @@ public abstract class DFSVisitor implements Operation { // MutableBlockVector3 mutable = new MutableBlockVector3(); // MutableBlockVector3 mutable2 = new MutableBlockVector3(); int countAdd, countAttempt; - Triple[] dirs = getIntDirections(); + IntegerTrio[] dirs = getIntDirections(); for (int layer = 0; !queue.isEmpty(); layer++) { current = queue.poll(); @@ -99,11 +99,11 @@ public abstract class DFSVisitor implements Operation { function.apply(bv); countAdd = 0; countAttempt = 0; - for (Triple direction : dirs) { + for (IntegerTrio direction : dirs) { // mutable2.mutX(from.getX() + direction.x); // mutable2.mutY(from.getY() + direction.y); // mutable2.mutZ(from.getZ() + direction.z); - BlockVector3 bv2 = BlockVector3.at(from.getX() + direction.getFirst(), from.getY() + direction.getSecond(), from.getZ() + direction.getThird()); + BlockVector3 bv2 = BlockVector3.at(from.getX() + direction.x, from.getY() + direction.y, from.getZ() + direction.z); if (isVisitable(bv, bv2)) { adjacent = new Node(bv2.getBlockX(), bv2.getBlockY(), bv2.getBlockZ()); if ((!adjacent.equals(current.from))) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/EditSessionBuilder.java b/worldedit-core/src/main/java/com/boydti/fawe/util/EditSessionBuilder.java index 8f9555061..7b2b52b79 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/EditSessionBuilder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/EditSessionBuilder.java @@ -232,11 +232,11 @@ public class EditSessionBuilder { event.setExtent(extent); eventBus.post(event); if (event.isCancelled()) { - return new NullExtent(extent, FaweCache.INSTANCE.getManual()); + return new NullExtent(extent, FaweCache.INSTANCE.getMANUAL()); } final Extent toReturn = event.getExtent(); if(toReturn instanceof com.sk89q.worldedit.extent.NullExtent) { - return new NullExtent(toReturn, FaweCache.INSTANCE.getManual()); + return new NullExtent(toReturn, FaweCache.INSTANCE.getMANUAL()); } // if (!(toReturn instanceof AbstractDelegateExtent)) { // Fawe.debug("Extent " + toReturn + " must be AbstractDelegateExtent"); @@ -316,7 +316,7 @@ public class EditSessionBuilder { if (Permission.hasPermission(player, "worldedit.fast")) { player.print(TranslatableComponent.of("fawe.info.worldedit.oom.admin")); } - throw FaweCache.INSTANCE.getLowMemory(); + throw FaweCache.INSTANCE.getLOW_MEMORY(); } } // this.originalLimit = limit; @@ -420,7 +420,7 @@ public class EditSessionBuilder { FaweRegionExtent regionExtent = null; if (allowedRegions != null) { if (allowedRegions.length == 0) { - regionExtent = new NullExtent(this.extent, FaweCache.INSTANCE.getNoRegion()); + regionExtent = new NullExtent(this.extent, FaweCache.INSTANCE.getNO_REGION()); } else { // this.extent = new ProcessedWEExtent(this.extent, this.limit); if (allowedRegions.length == 1) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/MathMan.java b/worldedit-core/src/main/java/com/boydti/fawe/util/MathMan.java index 09055f5c8..b9cb2d22e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/MathMan.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/MathMan.java @@ -1,7 +1,5 @@ package com.boydti.fawe.util; -import kotlin.UInt; - public class MathMan { /** @@ -416,10 +414,4 @@ public class MathMan { public static boolean isPowerOfTwo(int x) { return (x & (x - 1)) == 0; } - - public static int floor(double value) { - int i = (int)value; - return value < (double)i ? i - 1 : i; - } - } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/web/SchemSync.java b/worldedit-core/src/main/java/com/boydti/fawe/web/SchemSync.java index 4694a0146..a1f71161c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/web/SchemSync.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/web/SchemSync.java @@ -58,7 +58,7 @@ public class SchemSync implements Runnable { private void close(Error error) throws IOException { this.clientSocket.getOutputStream().write(error.ordinal()); - throw FaweCache.INSTANCE.getManual(); + throw FaweCache.INSTANCE.getMANUAL(); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/ByteArrayTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/ByteArrayTag.java index 791ee97ea..38298c5a0 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/ByteArrayTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/ByteArrayTag.java @@ -26,6 +26,11 @@ import java.util.Locale; */ public final class ByteArrayTag extends Tag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_BYTE_ARRAY; + } + private final byte[] value; /** diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/ByteTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/ByteTag.java index 6ea46c1b0..b90b1acfb 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/ByteTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/ByteTag.java @@ -23,6 +23,10 @@ package com.sk89q.jnbt; * The {@code TAG_Byte} tag. */ public final class ByteTag extends NumberTag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_BYTE; + } private final byte value; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java index 8768a3b39..faa23c1df 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java @@ -33,6 +33,11 @@ import java.util.UUID; */ public class CompoundTag extends Tag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_COMPOUND; + } + private Map value; /** diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/DoubleTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/DoubleTag.java index e571e8e76..ca27de1e7 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/DoubleTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/DoubleTag.java @@ -24,6 +24,10 @@ package com.sk89q.jnbt; * */ public final class DoubleTag extends NumberTag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_DOUBLE; + } private final double value; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/EndTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/EndTag.java index 02da93f18..00e9d9da8 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/EndTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/EndTag.java @@ -24,6 +24,11 @@ package com.sk89q.jnbt; */ public final class EndTag extends Tag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_END; + } + @Override public Object getValue() { return null; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/FloatTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/FloatTag.java index 7a4895810..eaf76c620 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/FloatTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/FloatTag.java @@ -23,6 +23,10 @@ package com.sk89q.jnbt; * The {@code TAG_Float} tag. */ public final class FloatTag extends NumberTag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_FLOAT; + } private final float value; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/IntArrayTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/IntArrayTag.java index 04ec07be8..b4fa50a20 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/IntArrayTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/IntArrayTag.java @@ -28,6 +28,11 @@ import java.util.Locale; */ public final class IntArrayTag extends Tag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_INT_ARRAY; + } + private final int[] value; /** diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/IntTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/IntTag.java index 1fa374cce..e1da41b01 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/IntTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/IntTag.java @@ -23,6 +23,10 @@ package com.sk89q.jnbt; * The {@code TAG_Int} tag. */ public final class IntTag extends NumberTag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_INT; + } private final int value; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/ListTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/ListTag.java index 1cef4ac8c..205492f8c 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/ListTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/ListTag.java @@ -32,6 +32,11 @@ import javax.annotation.Nullable; */ public class ListTag extends Tag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_LIST; + } + private final Class type; private final List value; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/LongArrayTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/LongArrayTag.java index 1771ed9a6..f5139cfc4 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/LongArrayTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/LongArrayTag.java @@ -28,6 +28,11 @@ import java.util.Locale; */ public class LongArrayTag extends Tag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_LONG_ARRAY; + } + private final long[] value; /** diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/LongTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/LongTag.java index 1a7f4d8f6..c3fe1cb04 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/LongTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/LongTag.java @@ -24,6 +24,10 @@ package com.sk89q.jnbt; * */ public final class LongTag extends NumberTag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_LONG; + } private final long value; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java index 107cbaae6..99b0acdf0 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java @@ -311,7 +311,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da int size = tags.size(); if (!tags.isEmpty()) { Tag tag0 = tags.get(0); - os.writeByte(NBTUtils.getTypeCode(tag0.getClass())); + os.writeByte(tag0.getTypeCode()); } else { os.writeByte(NBTUtils.getTypeCode(clazz)); } diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/ShortTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/ShortTag.java index 212958ef4..3464254bf 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/ShortTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/ShortTag.java @@ -23,6 +23,10 @@ package com.sk89q.jnbt; * The {@code TAG_Short} tag. */ public final class ShortTag extends NumberTag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_SHORT; + } private final short value; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/StringTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/StringTag.java index 5a2c504a8..057ac8c64 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/StringTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/StringTag.java @@ -26,6 +26,11 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public final class StringTag extends Tag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_STRING; + } + private final String value; /** diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/Tag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/Tag.java index d7c273b17..adfc5147a 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/Tag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/Tag.java @@ -35,4 +35,6 @@ public abstract class Tag { return getValue(); } + public abstract int getTypeCode(); + } diff --git a/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLNode.java b/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLNode.java index 1129e5256..cca293ddf 100644 --- a/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLNode.java +++ b/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLNode.java @@ -62,7 +62,7 @@ public class YAMLNode { /** * Gets a property at a location. This will either return an Object - * or null, with null meaning that no configuration value exists at + * or null, with null meaning no configuration value exists at * that location. This could potentially return a default value (not yet * implemented) as defined by a plugin, if this is a plugin-tied * configuration. @@ -197,7 +197,7 @@ public class YAMLNode { } /** - * Gets a string at a location. This will either return an String + * Gets a string at a location. This will either return a String * or null, with null meaning that no configuration value exists at * that location. If the object at the particular location is not actually * a string, it will be converted to its string representation. @@ -214,7 +214,7 @@ public class YAMLNode { } /** - * Gets a vector at a location. This will either return an Vector + * Gets a vector at a location. This will either return a Vector * or a null. If the object at the particular location is not * actually a string, it will be converted to its string representation. * @@ -239,7 +239,7 @@ public class YAMLNode { } /** - * Gets a 2D vector at a location. This will either return an Vector + * Gets a 2D vector at a location. This will either return a Vector * or a null. If the object at the particular location is not * actually a string, it will be converted to its string representation. * @@ -263,7 +263,7 @@ public class YAMLNode { } /** - * Gets a string at a location. This will either return an Vector + * Gets a string at a location. This will either return a Vector * or the default value. If the object at the particular location is not * actually a string, it will be converted to its string representation. * @@ -281,7 +281,7 @@ public class YAMLNode { } /** - * Gets a string at a location. This will either return an String + * Gets a string at a location. This will either return a String * or the default value. If the object at the particular location is not * actually a string, it will be converted to its string representation. * @@ -337,10 +337,10 @@ public class YAMLNode { } /** - * Gets a double at a location. This will either return an double + * Gets a double at a location. This will either return a double * or null. If the object at the particular location is not * actually a double, the default value will be returned. However, other - * number types will be casted to an double. + * number types will be casted to a double. * * @param path path to node (dot notation) * @return double or null @@ -355,10 +355,10 @@ public class YAMLNode { } /** - * Gets a double at a location. This will either return an double + * Gets a double at a location. This will either return a double * or the default value. If the object at the particular location is not * actually a double, the default value will be returned. However, other - * number types will be casted to an double. + * number types will be casted to a double. * * @param path path to node (dot notation) * @param def default value @@ -375,7 +375,7 @@ public class YAMLNode { } /** - * Gets a boolean at a location. This will either return an boolean + * Gets a boolean at a location. This will either return a boolean * or null. If the object at the particular location is not * actually a boolean, the default value will be returned. * @@ -392,7 +392,7 @@ public class YAMLNode { } /** - * Gets a boolean at a location. This will either return an boolean + * Gets a boolean at a location. This will either return a boolean * or the default value. If the object at the particular location is not * actually a boolean, the default value will be returned. * 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 b89812547..170fc76e0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -2802,7 +2802,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { BlockVector3 max = region.getMaximumPoint(); BlockVector3 min = region.getMinimumPoint(); if (!fe.contains(max.getBlockX(), max.getBlockY(), max.getBlockZ()) && !fe.contains(min.getBlockX(), min.getBlockY(), min.getBlockZ())) { - throw FaweCache.INSTANCE.getOutsideRegion(); + throw FaweCache.INSTANCE.getOUTSIDE_REGION(); } } final Set chunks = region.getChunks(); 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 c374ce1ae..90150a27a 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 @@ -128,7 +128,7 @@ public class ClipboardCommands { ((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1); FaweLimit limit = actor.getLimit(); if (volume >= limit.MAX_CHECKS) { - throw FaweCache.INSTANCE.getMaxChecks(); + throw FaweCache.INSTANCE.getMAX_CHECKS(); } session.setClipboard(null); @@ -246,10 +246,10 @@ public class ClipboardCommands { long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1)); FaweLimit limit = actor.getLimit(); if (volume >= limit.MAX_CHECKS) { - throw FaweCache.INSTANCE.getMaxChecks(); + throw FaweCache.INSTANCE.getMAX_CHECKS(); } if (volume >= limit.MAX_CHANGES) { - throw FaweCache.INSTANCE.getMaxChanges(); + throw FaweCache.INSTANCE.getMAX_CHANGES(); } session.setClipboard(null); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java index fd2aaffc8..8fae5e501 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java @@ -422,7 +422,7 @@ public class RegionCommands { long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1)); FaweLimit limit = actor.getLimit(); if (volume >= limit.MAX_CHECKS) { - throw FaweCache.INSTANCE.getMaxChecks(); + throw FaweCache.INSTANCE.getMAX_CHECKS(); } int affected = 0; try { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/TransformCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/TransformCommands.java index f4215548d..dc28b2751 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/TransformCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/TransformCommands.java @@ -30,7 +30,7 @@ public class TransformCommands { aliases = {"#l"}, desc = "Sequentially pick from a list of transform" ) - public ResettableExtent linear(Actor actor, LocalSession session, @Arg(desc = "ResettableExtent", def = "#null") ResettableExtent other) { + public ResettableExtent linear(Actor actor, LocalSession session, @Arg(name = "other", desc = "ResettableExtent", def = "#null") ResettableExtent other) { if (other instanceof RandomTransform) { Set extents = ((RandomTransform) other).getExtents(); return new LinearTransform(extents.toArray(new ResettableExtent[0])); @@ -43,7 +43,7 @@ public class TransformCommands { aliases = {"#l3d"}, desc = "Use the x,y,z coordinate to pick a transform from the list" ) - public ResettableExtent linear3d(Actor actor, LocalSession session, @Arg(desc = "ResettableExtent", def = "#null") ResettableExtent other) { + public ResettableExtent linear3d(Actor actor, LocalSession session, @Arg(name = "other", desc = "ResettableExtent", def = "#null") ResettableExtent other) { if (other instanceof RandomTransform) { Set extents = ((RandomTransform) other).getExtents(); return new Linear3DTransform(extents.toArray(new ResettableExtent[0])); @@ -55,7 +55,7 @@ public class TransformCommands { name = "#pattern", desc = "Always use a specific pattern" ) - public ResettableExtent pattern(Actor actor, LocalSession session, @Arg(desc = "Pattern") Pattern pattern, @Arg(desc = "ResettableExtent", def = "#null") ResettableExtent other) { + public ResettableExtent pattern(Actor actor, LocalSession session, @Arg(desc = "Pattern") Pattern pattern, @Arg(name = "other", desc = "ResettableExtent", def = "#null") ResettableExtent other) { return new PatternTransform(other, pattern); } @@ -63,7 +63,7 @@ public class TransformCommands { name = "#offset", desc = "Offset transform" ) - public ResettableExtent offset(Actor actor, LocalSession session, double x, double y, double z, @Arg(desc = "ResettableExtent", def = "#null") ResettableExtent other) { + public ResettableExtent offset(Actor actor, LocalSession session, double x, double y, double z, @Arg(name = "other", desc = "ResettableExtent", def = "#null") ResettableExtent other) { return new OffsetExtent(other, (int) x, (int) y, (int) z); } @@ -72,7 +72,7 @@ public class TransformCommands { aliases = {"#randomoffset"}, desc = "Random offset transform" ) - public ResettableExtent randomOffset(Actor actor, LocalSession session, double x, double y, double z, @Arg(desc = "ResettableExtent", def = "#null") ResettableExtent other) { + public ResettableExtent randomOffset(Actor actor, LocalSession session, double x, double y, double z, @Arg(name = "other", desc = "ResettableExtent", def = "#null") ResettableExtent other) { return new RandomOffsetTransform(other, (int) x, (int) y, (int) z); } @@ -80,7 +80,7 @@ public class TransformCommands { name = "#scale", desc = "All changes will be scaled" ) - public ResettableExtent scale(Actor actor, LocalSession session, double x, double y, double z, @Arg(desc = "ResettableExtent", def = "#null") ResettableExtent other) { + public ResettableExtent scale(Actor actor, LocalSession session, double x, double y, double z, @Arg(name = "other", desc = "ResettableExtent", def = "#null") ResettableExtent other) { return new ScaleTransform(other, x, y, z); } @@ -88,7 +88,7 @@ public class TransformCommands { name = "#rotate", desc = "All changes will be rotate around the initial position" ) - public ResettableExtent rotate(Player player, LocalSession session, double x, double y, double z, @Arg(desc = "ResettableExtent", def = "#null") ResettableExtent other) { + public ResettableExtent rotate(Player player, LocalSession session, double x, double y, double z, @Arg(name = "other", desc = "ResettableExtent", def = "#null") ResettableExtent other) { ExtentTraverser traverser = new ExtentTraverser<>(other).find(TransformExtent.class); BlockTransformExtent affine = traverser != null ? traverser.get() : null; if (affine == null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java index 07432bc0d..1666916ef 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java @@ -46,7 +46,6 @@ import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.TextStyle; import java.time.zone.ZoneRulesException; -import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.List; @@ -80,9 +79,7 @@ public class WorldEditCommands { if (fVer != null) { FaweVersion version = Fawe.get().getVersion(); - //noinspection MagicConstant - Date date = new GregorianCalendar(2000 + version.year, - version.month - 1, version.day) + Date date = new GregorianCalendar(2000 + version.year, version.month - 1, version.day) .getTime(); TextComponent dateArg = TextComponent.of(date.toLocaleString()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/factory/ReplaceFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/factory/ReplaceFactory.java index 4c1797b52..fa09c8911 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/factory/ReplaceFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/factory/ReplaceFactory.java @@ -19,6 +19,8 @@ package com.sk89q.worldedit.command.factory; +import static com.sk89q.worldedit.util.GuavaUtil.firstNonNull; + import com.sk89q.worldedit.extent.NullExtent; import com.sk89q.worldedit.function.Contextual; import com.sk89q.worldedit.function.EditContext; @@ -26,8 +28,6 @@ import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.block.BlockReplace; import com.sk89q.worldedit.function.pattern.Pattern; -import static com.sk89q.worldedit.util.GuavaUtil.firstNonNull; - public class ReplaceFactory implements Contextual { private final Pattern fill; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/factory/TreeGeneratorFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/factory/TreeGeneratorFactory.java index 76d875851..a0b684539 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/factory/TreeGeneratorFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/factory/TreeGeneratorFactory.java @@ -41,4 +41,4 @@ public final class TreeGeneratorFactory implements Contextual { public String toString() { return "tree of type " + type; } -} +} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java index f028cff5d..ce02f08e3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java @@ -114,7 +114,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool /** * Construct the tool. - * + * * @param permission the permission to check before use is allowed */ public BrushTool(String permission) { @@ -275,7 +275,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool /** * Get the filter. - * + * * @return the filter */ public Mask getMask() { @@ -303,7 +303,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool /** * Set the block filter used for identifying blocks to replace. - * + * * @param filter the filter to set */ public void setMask(Mask filter) { @@ -342,7 +342,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool /** * Set the brush. - * + * * @param brush tbe brush * @param permission the permission */ @@ -356,7 +356,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool /** * Get the current brush. - * + * * @return the current brush */ public Brush getBrush() { @@ -365,7 +365,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool /** * Set the material. - * + * * @param material the material */ public void setFill(@Nullable Pattern material) { @@ -383,7 +383,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool /** * Get the set brush size. - * + * * @return a radius */ public double getSize() { @@ -392,7 +392,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool /** * Set the set brush size. - * + * * @param radius a radius */ public void setSize(double radius) { @@ -410,7 +410,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool /** * Get the set brush range. - * + * * @return the range of the brush in blocks */ public int getRange() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java index 2aef51e92..642a8c4aa 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.command.tool; +import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.entity.Player; @@ -28,7 +29,6 @@ import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; /** * A wand that can be used at a distance. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java index 87ef84b39..3d299f456 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.command.tool; +import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.boydti.fawe.object.collection.LocalBlockVectorSet; import com.sk89q.worldedit.EditSession; @@ -31,7 +32,6 @@ import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockCategories; import com.sk89q.worldedit.world.block.BlockState; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java index 9ca71b7d4..69b64a037 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java @@ -24,13 +24,13 @@ import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.LocatedBlock; -import com.sk89q.worldedit.util.collection.LocatedBlockList; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockTypes; import java.util.LinkedHashSet; import java.util.Set; +import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.util.collection.LocatedBlockList; import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockTypes; public class GravityBrush implements Brush { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java index 03b50a7e9..fbd406865 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java @@ -34,4 +34,4 @@ public class SphereBrush implements Brush { } editSession.makeSphere(position, pattern, size, size, size, true); } -} +} \ No newline at end of file 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 769389180..8a7ce511c 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 @@ -129,7 +129,12 @@ public class AbstractDelegateExtent implements Extent, LightingExtent { new ExtentTraverser<>(this).setNext(new HistoryExtent(extent, changeSet)); } } - + + @Override + public int getMaxY() { + return extent.getMaxY(); + } + @Override public BlockState getBlock(int x, int y, int z) { return extent.getBlock(x, y, z); @@ -172,12 +177,14 @@ public class AbstractDelegateExtent implements Extent, LightingExtent { } @Override - public > boolean setBlock(BlockVector3 position, T block) throws WorldEditException { + 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 { + public > boolean setBlock(int x, int y, int z, T block) + throws WorldEditException { return extent.setBlock(x, y, z, block); } 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 08ee007d8..1f2f2b7f6 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 @@ -457,7 +457,7 @@ public interface Extent extends InputExtent, OutputExtent { default boolean cancel() { ExtentTraverser traverser = new ExtentTraverser<>(this); - NullExtent nullExtent = new NullExtent(this, FaweCache.INSTANCE.getManual()); + NullExtent nullExtent = new NullExtent(this, FaweCache.INSTANCE.getMANUAL()); ExtentTraverser next = traverser.next(); if (next != null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java index ec1f5e15f..f05619fd5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java @@ -54,7 +54,6 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class BlockArrayClipboard extends DelegateClipboard implements Clipboard, Closeable { - @NotNull private Region region; private BlockVector3 offset; @@ -86,7 +85,6 @@ public class BlockArrayClipboard extends DelegateClipboard implements Clipboard, setRegion(region); } - @NotNull @Override public Region getRegion() { return region; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java index b638f5646..21ddee061 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java @@ -77,17 +77,12 @@ public interface Clipboard extends Extent, Iterable, Closeable { static Clipboard create(BlockVector3 size, UUID uuid) { if (Settings.IMP.CLIPBOARD.USE_DISK) { - try { - return new DiskOptimizedClipboard(size, uuid); - } catch (IOException e) { - e.printStackTrace(); - } + return new DiskOptimizedClipboard(size, uuid); } else if (Settings.IMP.CLIPBOARD.COMPRESSION_LEVEL == 0) { return new CPUOptimizedClipboard(size); } else { return new MemoryOptimizedClipboard(size); } - return null; } /** @@ -121,10 +116,11 @@ public interface Clipboard extends Extent, Iterable, Closeable { void setOrigin(BlockVector3 origin); /** - * Returns true if the clipboard has biome data. This can be checked since {@link Extent#getBiome(BlockVector2)} - * strongly suggests returning {@link com.sk89q.worldedit.world.biome.BiomeTypes#OCEAN} instead of {@code null} - * if biomes aren't present. However, it might not be desired to set areas to ocean if the clipboard is defaulting - * to ocean, instead of having biomes explicitly set. + * Returns true if the clipboard has biome data. This can be checked since {@link + * Extent#getBiome(BlockVector2)} strongly suggests returning {@link + * com.sk89q.worldedit.world.biome.BiomeTypes#OCEAN} instead of {@code null} if biomes aren't + * present. However, it might not be desired to set areas to ocean if the clipboard is + * defaulting to ocean, instead of having biomes explicitly set. * * @return true if the clipboard has biome data set */ diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java index 6687cda38..3ca0aefc2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java @@ -20,6 +20,7 @@ package com.sk89q.worldedit.extent.inventory; import com.boydti.fawe.FaweCache; +import com.boydti.fawe.object.exception.FaweException; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; @@ -106,10 +107,10 @@ public class BlockBagExtent extends AbstractDelegateExtent { try { blockBag.fetchPlacedBlock(block.toImmutableState()); } catch (UnplaceableBlockException e) { - throw FaweCache.INSTANCE.getBlockBag(); + throw FaweCache.INSTANCE.getBLOCK_BAG(); } catch (BlockBagException e) { missingBlocks[block.getBlockType().getInternalId()]++; - throw FaweCache.INSTANCE.getBlockBag(); + throw FaweCache.INSTANCE.getBLOCK_BAG(); } } if (mine) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java index f97394f31..bb9448e8a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java @@ -32,22 +32,20 @@ import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import java.util.Comparator; -import javax.annotation.concurrent.Immutable; /** * An immutable 3-dimensional vector. */ -@Immutable -public class BlockVector3 { +public abstract class BlockVector3 { - public static final BlockVector3 ZERO = new BlockVector3(0, 0, 0); - public static final BlockVector3 UNIT_X = new BlockVector3(1, 0, 0); - public static final BlockVector3 UNIT_Y = new BlockVector3(0, 1, 0); - public static final BlockVector3 UNIT_Z = new BlockVector3(0, 0, 1); - public static final BlockVector3 UNIT_MINUS_X = new BlockVector3(-1, 0, 0); - public static final BlockVector3 UNIT_MINUS_Y = new BlockVector3(0, -1, 0); - public static final BlockVector3 UNIT_MINUS_Z = new BlockVector3(0, 0, -1); - public static final BlockVector3 ONE = new BlockVector3(1, 1, 1); + public static final BlockVector3 ZERO = BlockVector3.at(0, 0, 0); + public static final BlockVector3 UNIT_X = BlockVector3.at(1, 0, 0); + public static final BlockVector3 UNIT_Y = BlockVector3.at(0, 1, 0); + public static final BlockVector3 UNIT_Z = BlockVector3.at(0, 0, 1); + public static final BlockVector3 UNIT_MINUS_X = BlockVector3.at(-1, 0, 0); + public static final BlockVector3 UNIT_MINUS_Y = BlockVector3.at(0, -1, 0); + public static final BlockVector3 UNIT_MINUS_Z = BlockVector3.at(0, 0, -1); + public static final BlockVector3 ONE = BlockVector3.at(1, 1, 1); public static BlockVector3 at(double x, double y, double z) { return at((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z)); @@ -70,7 +68,7 @@ public class BlockVector3 { break; } */ - return new BlockVector3(x, y, z); + return new BlockVector3Imp(x, y, z); } private static final int WORLD_XZ_MINMAX = 30_000_000; @@ -116,21 +114,6 @@ public class BlockVector3 { return YzxOrderComparator.YZX_ORDER; } - private final int x, y, z; - - /** - * Construct an instance. - * - * @param x the X coordinate - * @param y the Y coordinate - * @param z the Z coordinate - */ - public BlockVector3(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - public MutableBlockVector3 setComponents(double x, double y, double z) { return new MutableBlockVector3((int) x, (int) y, (int) z); } @@ -141,35 +124,35 @@ public class BlockVector3 { public long toLongPackedForm() { checkLongPackable(this); - return (x & BITS_26) | ((z & BITS_26) << 26) | (((y & (long) BITS_12) << (26 + 26))); + return (getX() & BITS_26) | ((getZ() & BITS_26) << 26) | (((getY() & (long) BITS_12) << (26 + 26))); } public MutableBlockVector3 mutX(double x) { - return new MutableBlockVector3((int) x, y, z); + return new MutableBlockVector3((int) x, getY(), getZ()); } public MutableBlockVector3 mutY(double y) { - return new MutableBlockVector3(x, (int) y, z); + return new MutableBlockVector3(getX(), (int) y, getZ()); } public MutableBlockVector3 mutZ(double z) { - return new MutableBlockVector3(x, y, (int) z); + return new MutableBlockVector3(getX(), getY(), (int) z); } public MutableBlockVector3 mutX(int x) { - return new MutableBlockVector3(x, y, z); + return new MutableBlockVector3(x, getY(), getZ()); } public MutableBlockVector3 mutY(int y) { - return new MutableBlockVector3(x, y, z); + return new MutableBlockVector3(getX(), y, getZ()); } public MutableBlockVector3 mutZ(int z) { - return new MutableBlockVector3(x, y, z); + return new MutableBlockVector3(getX(), getY(), z); } public BlockVector3 toImmutable() { - return BlockVector3.at(x, y, z); + return BlockVector3.at(getX(), getY(), getZ()); } /** @@ -177,9 +160,7 @@ public class BlockVector3 { * * @return the x coordinate */ - public int getX() { - return x; - } + public abstract int getX(); /** * Get the X coordinate. @@ -187,7 +168,7 @@ public class BlockVector3 { * @return the x coordinate */ public int getBlockX() { - return x; + return getX(); } /** @@ -197,7 +178,7 @@ public class BlockVector3 { * @return a new vector */ public BlockVector3 withX(int x) { - return BlockVector3.at(x, y, z); + return BlockVector3.at(x, getY(), getZ()); } /** @@ -205,9 +186,7 @@ public class BlockVector3 { * * @return the y coordinate */ - public int getY() { - return y; - } + public abstract int getY(); /** * Get the Y coordinate. @@ -215,7 +194,7 @@ public class BlockVector3 { * @return the y coordinate */ public int getBlockY() { - return y; + return getY(); } /** @@ -225,7 +204,7 @@ public class BlockVector3 { * @return a new vector */ public BlockVector3 withY(int y) { - return BlockVector3.at(x, y, z); + return BlockVector3.at(getX(), y, getZ()); } /** @@ -233,9 +212,7 @@ public class BlockVector3 { * * @return the z coordinate */ - public int getZ() { - return z; - } + public abstract int getZ(); /** * Get the Z coordinate. @@ -243,7 +220,7 @@ public class BlockVector3 { * @return the z coordinate */ public int getBlockZ() { - return z; + return getZ(); } /** @@ -253,7 +230,7 @@ public class BlockVector3 { * @return a new vector */ public BlockVector3 withZ(int z) { - return BlockVector3.at(x, y, z); + return BlockVector3.at(getX(), getY(), z); } /** @@ -263,7 +240,7 @@ public class BlockVector3 { * @return a new vector */ public BlockVector3 add(BlockVector3 other) { - return add(other.x, other.y, other.z); + return add(other.getX(), other.getY(), other.getZ()); } /** @@ -275,7 +252,7 @@ public class BlockVector3 { * @return a new vector */ public BlockVector3 add(int x, int y, int z) { - return BlockVector3.at(this.x + x, this.y + y, this.z + z); + return BlockVector3.at(this.getX() + x, this.getY() + y, this.getZ() + z); } /** @@ -286,12 +263,12 @@ public class BlockVector3 { * @return a new vector */ public BlockVector3 add(BlockVector3... others) { - int newX = x, newY = y, newZ = z; + int newX = getX(), newY = getY(), newZ = getZ(); for (BlockVector3 other : others) { - newX += other.x; - newY += other.y; - newZ += other.z; + newX += other.getX(); + newY += other.getY(); + newZ += other.getZ(); } return BlockVector3.at(newX, newY, newZ); @@ -305,7 +282,7 @@ public class BlockVector3 { * @return a new vector */ public BlockVector3 subtract(BlockVector3 other) { - return subtract(other.x, other.y, other.z); + return subtract(other.getX(), other.getY(), other.getZ()); } /** @@ -318,7 +295,7 @@ public class BlockVector3 { * @return a new vector */ public BlockVector3 subtract(int x, int y, int z) { - return BlockVector3.at(this.x - x, this.y - y, this.z - z); + return BlockVector3.at(this.getX() - x, this.getY() - y, this.getZ() - z); } /** @@ -329,12 +306,12 @@ public class BlockVector3 { * @return a new vector */ public BlockVector3 subtract(BlockVector3... others) { - int newX = x, newY = y, newZ = z; + int newX = getX(), newY = getY(), newZ = getZ(); for (BlockVector3 other : others) { - newX -= other.x; - newY -= other.y; - newZ -= other.z; + newX -= other.getX(); + newY -= other.getY(); + newZ -= other.getZ(); } return BlockVector3.at(newX, newY, newZ); @@ -347,7 +324,7 @@ public class BlockVector3 { * @return a new vector */ public BlockVector3 multiply(BlockVector3 other) { - return multiply(other.x, other.y, other.z); + return multiply(other.getX(), other.getY(), other.getZ()); } /** @@ -359,7 +336,7 @@ public class BlockVector3 { * @return a new vector */ public BlockVector3 multiply(int x, int y, int z) { - return BlockVector3.at(this.x * x, this.y * y, this.z * z); + return BlockVector3.at(this.getX() * x, this.getY() * y, this.getZ() * z); } /** @@ -369,12 +346,12 @@ public class BlockVector3 { * @return a new vector */ public BlockVector3 multiply(BlockVector3... others) { - int newX = x, newY = y, newZ = z; + int newX = getX(), newY = getY(), newZ = getZ(); for (BlockVector3 other : others) { - newX *= other.x; - newY *= other.y; - newZ *= other.z; + newX *= other.getX(); + newY *= other.getY(); + newZ *= other.getZ(); } return BlockVector3.at(newX, newY, newZ); @@ -397,7 +374,7 @@ public class BlockVector3 { * @return a new vector */ public BlockVector3 divide(BlockVector3 other) { - return divide(other.x, other.y, other.z); + return divide(other.getX(), other.getY(), other.getZ()); } /** @@ -409,7 +386,7 @@ public class BlockVector3 { * @return a new vector */ public BlockVector3 divide(int x, int y, int z) { - return BlockVector3.at(this.x / x, this.y / y, this.z / z); + return BlockVector3.at(this.getX() / x, this.getY() / y, this.getZ() / z); } /** @@ -431,7 +408,7 @@ public class BlockVector3 { * @return a new vector */ public BlockVector3 shr(int x, int y, int z) { - return at(this.x >> x, this.y >> y, this.z >> z); + return at(this.getX() >> x, this.getY() >> y, this.getZ() >> z); } /** @@ -453,7 +430,7 @@ public class BlockVector3 { * @return a new vector */ public BlockVector3 shl(int x, int y, int z) { - return at(this.x << x, this.y << y, this.z << z); + return at(this.getX() << x, this.getY() << y, this.getZ() << z); } /** @@ -481,7 +458,7 @@ public class BlockVector3 { * @return length, squared */ public int lengthSq() { - return x * x + y * y + z * z; + return getX() * getX() + getY() * getY() + getZ() * getZ(); } /** @@ -501,9 +478,9 @@ public class BlockVector3 { * @return distance */ public int distanceSq(BlockVector3 other) { - int dx = other.x - x; - int dy = other.y - y; - int dz = other.z - z; + int dx = other.getX() - getX(); + int dy = other.getY() - getY(); + int dz = other.getZ() - getZ(); return dx * dx + dy * dy + dz * dz; } @@ -515,9 +492,9 @@ public class BlockVector3 { */ public BlockVector3 normalize() { double len = length(); - double x = this.x / len; - double y = this.y / len; - double z = this.z / len; + double x = this.getX() / len; + double y = this.getY() / len; + double z = this.getZ() / len; return BlockVector3.at(x, y, z); } @@ -528,7 +505,7 @@ public class BlockVector3 { * @return the dot product of this and the other vector */ public double dot(BlockVector3 other) { - return x * other.x + y * other.y + z * other.z; + return getX() * other.getX() + getY() * other.getY() + getZ() * other.getZ(); } /** @@ -538,10 +515,10 @@ public class BlockVector3 { * @return the cross product of this and the other vector */ public BlockVector3 cross(BlockVector3 other) { - return new BlockVector3( - y * other.z - z * other.y, - z * other.x - x * other.z, - x * other.y - y * other.x + return new BlockVector3Imp( + getY() * other.getZ() - getZ() * other.getY(), + getZ() * other.getX() - getX() * other.getZ(), + getX() * other.getY() - getY() * other.getX() ); } @@ -553,7 +530,8 @@ public class BlockVector3 { * @return true if the vector is contained */ public boolean containedWithin(BlockVector3 min, BlockVector3 max) { - return x >= min.x && x <= max.x && y >= min.y && y <= max.y && z >= min.z && z <= max.z; + return getX() >= min.getX() && getX() <= max.getX() && getY() >= min.getY() && getY() <= max + .getY() && getZ() >= min.getZ() && getZ() <= max.getZ(); } /** @@ -565,11 +543,11 @@ public class BlockVector3 { */ public BlockVector3 clampY(int min, int max) { checkArgument(min <= max, "minimum cannot be greater than maximum"); - if (y < min) { - return BlockVector3.at(x, min, z); + if (getY() < min) { + return BlockVector3.at(getX(), min, getZ()); } - if (y > max) { - return BlockVector3.at(x, max, z); + if (getY() > max) { + return BlockVector3.at(getX(), max, getZ()); } return this; } @@ -613,7 +591,7 @@ public class BlockVector3 { * @return a new vector */ public BlockVector3 abs() { - return BlockVector3.at(Math.abs(x), Math.abs(y), Math.abs(z)); + return BlockVector3.at(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ())); } /** @@ -629,8 +607,8 @@ public class BlockVector3 { */ public BlockVector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) { angle = Math.toRadians(angle); - double x = this.x - aboutX; - double z = this.z - aboutZ; + double x = this.getX() - aboutX; + double z = this.getZ() - aboutZ; double cos = Math.cos(angle); double sin = Math.sin(angle); double x2 = x * cos - z * sin; @@ -638,7 +616,7 @@ public class BlockVector3 { return BlockVector3.at( x2 + aboutX + translateX, - y, + getY(), z2 + aboutZ + translateZ ); } @@ -684,10 +662,10 @@ public class BlockVector3 { * @return minimum */ public BlockVector3 getMinimum(BlockVector3 v2) { - return new BlockVector3( - Math.min(x, v2.x), - Math.min(y, v2.y), - Math.min(z, v2.z) + return new BlockVector3Imp( + Math.min(getX(), v2.getX()), + Math.min(getY(), v2.getY()), + Math.min(getZ(), v2.getZ()) ); } @@ -698,10 +676,10 @@ public class BlockVector3 { * @return maximum */ public BlockVector3 getMaximum(BlockVector3 v2) { - return new BlockVector3( - Math.max(x, v2.x), - Math.max(y, v2.y), - Math.max(z, v2.z) + return new BlockVector3Imp( + Math.max(getX(), v2.getX()), + Math.max(getY(), v2.getY()), + Math.max(getZ(), v2.getZ()) ); } @@ -728,7 +706,7 @@ public class BlockVector3 { } public boolean setBiome(Extent orDefault, BiomeType biome) { - return orDefault.setBiome(x, y, z, biome); + return orDefault.setBiome(getX(), getY(), getZ(), biome); } public int getOrdinal(Extent orDefault) { @@ -748,19 +726,19 @@ public class BlockVector3 { } public CompoundTag getNbtData(Extent orDefault) { - return orDefault.getFullBlock(x, y, z).getNbtData(); + return orDefault.getFullBlock(getX(), getY(), getZ()).getNbtData(); } public BlockState getOrdinalBelow(Extent orDefault) { - return orDefault.getBlock(x, y - 1, z); + return orDefault.getBlock(getX(), getY() - 1, getZ()); } public BlockState getStateAbove(Extent orDefault) { - return orDefault.getBlock(x, y + 1, z); + return orDefault.getBlock(getX(), getY() + 1, getZ()); } public BlockState getStateRelativeY(Extent orDefault, final int y) { - return orDefault.getBlock(x, this.y + y, z); + return orDefault.getBlock(getX(), getY() + y, getZ()); } /** @@ -769,11 +747,11 @@ public class BlockVector3 { * @return a new {@link BlockVector2} */ public BlockVector2 toBlockVector2() { - return BlockVector2.at(x, z); + return BlockVector2.at(getX(), getZ()); } public Vector3 toVector3() { - return Vector3.at(x, y, z); + return Vector3.at(getX(), getY(), getZ()); } @Override @@ -783,7 +761,7 @@ public class BlockVector3 { } BlockVector3 other = (BlockVector3) obj; - return other.x == this.x && other.y == this.y && other.z == this.z; + return other.getX() == this.getX() && other.getY() == this.getY() && other.getZ() == this.getZ(); } public final boolean equals(BlockVector3 other) { @@ -793,12 +771,12 @@ public class BlockVector3 { @Override public int hashCode() { - return (x ^ (z << 12)) ^ (y << 24); + return (getX() ^ (getZ() << 12)) ^ (getY() << 24); } @Override public String toString() { - return "(" + x + ", " + y + ", " + z + ")"; + return "(" + getX() + ", " + getY() + ", " + getZ() + ")"; } //Used by VS fork diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3Imp.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3Imp.java new file mode 100644 index 000000000..dd7399c64 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3Imp.java @@ -0,0 +1,92 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.math; + +import static com.google.common.base.Preconditions.checkArgument; + +import com.google.common.collect.ComparisonChain; +import com.sk89q.worldedit.math.transform.AffineTransform; + +import java.util.Comparator; + +/** + * An immutable 3-dimensional vector. + */ +public final class BlockVector3Imp extends BlockVector3 { + + public static final BlockVector3Imp ZERO = new BlockVector3Imp(0, 0, 0); + public static final BlockVector3Imp UNIT_X = new BlockVector3Imp(1, 0, 0); + public static final BlockVector3Imp UNIT_Y = new BlockVector3Imp(0, 1, 0); + public static final BlockVector3Imp UNIT_Z = new BlockVector3Imp(0, 0, 1); + public static final BlockVector3Imp ONE = new BlockVector3Imp(1, 1, 1); + + public static BlockVector3Imp at(double x, double y, double z) { + return at((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z)); + } + + public static BlockVector3Imp at(int x, int y, int z) { + return new BlockVector3Imp(x, y, z); + } + + private final int x, y, z; + + /** + * Construct an instance. + * + * @param x the X coordinate + * @param y the Y coordinate + * @param z the Z coordinate + */ + protected BlockVector3Imp(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + @Override + public final int getX() { + return x; + } + + @Override + public final int getY() { + return y; + } + + @Override + public final int getZ() { + return z; + } + + @Override + public int hashCode() { + return (getX() ^ (getZ() << 12)) ^ (getY() << 24); + } + + @Override + public final BlockVector3 toImmutable() { + return this; + } + + @Override + public String toString() { + return "(" + getX() + ", " + getY() + ", " + getZ() + ")"; + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/DelegateBlockVector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/DelegateBlockVector3.java index af9ec50c2..eb4b1c3ec 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/DelegateBlockVector3.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/DelegateBlockVector3.java @@ -11,11 +11,6 @@ import java.util.Comparator; public class DelegateBlockVector3 extends BlockVector3 { private BlockVector3 parent; - public DelegateBlockVector3(BlockVector3 parent) { - super(parent.getX(), parent.getY(), parent.getZ()); - this.parent = parent; - } - public DelegateBlockVector3 init(BlockVector3 parent) { this.parent = parent; return this; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableBlockVector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableBlockVector3.java index 1a43f45da..012431c73 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableBlockVector3.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableBlockVector3.java @@ -1,7 +1,6 @@ package com.sk89q.worldedit.math; import com.boydti.fawe.FaweCache; -import com.boydti.fawe.util.MathMan; public class MutableBlockVector3 extends BlockVector3 { @@ -14,34 +13,27 @@ public class MutableBlockVector3 extends BlockVector3 { } public static MutableBlockVector3 get(int x, int y, int z) { - return FaweCache.INSTANCE.getMutableBlockVector3().get().setComponents(x, y, z); + return FaweCache.INSTANCE.getMUTABLE_BLOCKVECTOR3().get().setComponents(x, y, z); } - public MutableBlockVector3() { - this(0, 0, 0); - } + public MutableBlockVector3() {} - public MutableBlockVector3(BlockVector3 blockVector3) { - this(blockVector3.getX(), blockVector3.getY(), blockVector3.getZ()); + public MutableBlockVector3(BlockVector3 other) { + this(other.getX(), other.getY(), other.getZ()); } public MutableBlockVector3 setComponents(BlockVector3 other) { return setComponents(other.getBlockX(), other.getBlockY(), other.getBlockZ()); } - private int x, y, z; + private int x,y,z; public MutableBlockVector3(int x, int y, int z) { - super(0, 0, 0); this.x = x; this.y = y; this.z = z; } - public MutableBlockVector3(double x, double y, double z) { - this(MathMan.floor(x), MathMan.floor(y), MathMan.floor(z)); - } - @Override public MutableBlockVector3 setComponents(int x, int y, int z) { this.x = x; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableVector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableVector3.java index e356b3662..e3ff705c1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableVector3.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableVector3.java @@ -10,11 +10,11 @@ public class MutableVector3 extends Vector3 { } public static MutableVector3 get(int x, int y, int z) { - return FaweCache.INSTANCE.getMutableVector3().get().setComponents(x, y, z); + return FaweCache.INSTANCE.getMUTABLE_VECTOR3().get().setComponents(x, y, z); } public static MutableVector3 get(double x, double y, double z) { - return FaweCache.INSTANCE.getMutableVector3().get().setComponents(x, y, z); + return FaweCache.INSTANCE.getMUTABLE_VECTOR3().get().setComponents(x, y, z); } public MutableVector3(double x, double y, double z) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/OffsetBlockVector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/OffsetBlockVector3.java index cf5650311..ea8253632 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/OffsetBlockVector3.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/OffsetBlockVector3.java @@ -4,7 +4,6 @@ public class OffsetBlockVector3 extends DelegateBlockVector3 { private final BlockVector3 offset; public OffsetBlockVector3(BlockVector3 offset) { - super(offset); this.offset = offset; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java index 4156d0781..9c63c884a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java @@ -172,10 +172,10 @@ public abstract class AbstractRegion extends AbstractSet implement final BlockVector3 min = getMinimumPoint().divide(16); final BlockVector3 max = getMaximumPoint().divide(16); - for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) { - for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) { - if (containsChunk(x, z)) { - chunks.add(BlockVector2.at(x, z)); + for (int X = min.getBlockX(); X <= max.getBlockX(); ++X) { + for (int Z = min.getBlockZ(); Z <= max.getBlockZ(); ++Z) { + if (containsChunk(X, Z)) { + chunks.add(BlockVector2.at(X, Z)); } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java index 40259edb4..6552c948c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java @@ -124,8 +124,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { if (pos1 == null || pos2 == null) { return; } - pos1 = pos1.clampY(world == null ? 0 : 0, world == null ? FaweCache.worldMaxY : world.getMaxY()); - pos2 = pos2.clampY(world == null ? 0 : 0, world == null ? FaweCache.worldMaxY : world.getMaxY()); + pos1 = pos1.clampY(world == null ? 0 : 0, world == null ? FaweCache.WORLD_MAX_Y : world.getMaxY()); + pos2 = pos2.clampY(world == null ? 0 : 0, world == null ? FaweCache.WORLD_MAX_Y : world.getMaxY()); minX = Math.min(pos1.getX(), pos2.getX()); minY = Math.min(pos1.getY(), pos2.getY()); minZ = Math.min(pos1.getZ(), pos2.getZ()); @@ -730,7 +730,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { boolean trimZ = lowerZ != 0 || upperZ != 15; int indexY, index; - for (int layer = 0; layer < FaweCache.chunkLayers; layer++) { + for (int layer = 0; layer < FaweCache.CHUNK_LAYERS; layer++) { if (set.hasSection(layer)) { char[] arr = set.load(layer); if (trimX || trimZ) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java index a1babfc22..f35860b01 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java @@ -67,7 +67,9 @@ public interface Region extends Iterable, Cloneable, IBatchProcess * * @return center point */ - Vector3 getCenter(); + default Vector3 getCenter() { + return getMinimumPoint().add(getMaximumPoint()).toVector3().divide(2); + } /** * Get the number of blocks in the region. @@ -193,9 +195,17 @@ public interface Region extends Iterable, Cloneable, IBatchProcess */ List polygonize(int maxPoints); + default int getMinimumY() { + return getMinimumPoint().getY(); + } + + default int getMaximumY() { + return getMaximumPoint().getY(); + } + default void filter(final IChunk chunk, final Filter filter, ChunkFilterBlock block, final IChunkGet get, final IChunkSet set, boolean full) { - int minSection = Math.max(0, getMinimumPoint().getBlockY() >> 4); - int maxSection = Math.min(15, getMaximumPoint().getBlockY() >> 4); + int minSection = Math.max(0, getMinimumY() >> 4); + int maxSection = Math.min(15, getMaximumY() >> 4); for (int layer = minSection; layer <= maxSection; layer++) { if ((!full && !get.hasSection(layer)) || !filter.appliesLayer(chunk, layer)) return; block = block.initLayer(get, set, layer);