From 88359f02151d0258b5fe492c5b862e75d10395d2 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Tue, 21 Jan 2020 14:30:13 -0500 Subject: [PATCH] More Kotlin --- .../fawe/bukkit/adapter/FaweAdapter_All.java | 2 +- .../adapter/mc1_13/BukkitAdapter_1_13.java | 8 +- .../adapter/mc1_13/BukkitGetBlocks_1_13.java | 10 +- .../adapter/mc1_14/BukkitAdapter_1_14.java | 8 +- .../adapter/mc1_14/BukkitGetBlocks_1_14.java | 10 +- .../adapter/mc1_15/BukkitAdapter_1_15.java | 8 +- .../adapter/mc1_15/BukkitGetBlocks_1_15.java | 14 +- .../bukkit/listener/CFIPacketListener.java | 4 +- .../fawe/bukkit/wrapper/AsyncBlock.java | 7 +- .../fawe/bukkit/wrapper/AsyncWorld.java | 7 +- .../wrapper/state/AsyncDataContainer.java | 2 +- .../adapter/impl/FAWE_Spigot_v1_13_R2.java | 4 +- .../adapter/impl/FAWE_Spigot_v1_14_R4.java | 4 +- .../adapter/impl/FAWE_Spigot_v1_15_R1.java | 8 +- .../main/java/com/boydti/fawe/FaweCache.java | 545 ------------------ .../main/java/com/boydti/fawe/FaweCache.kt | 521 +++++++++++++++++ .../com/boydti/fawe/beta/CombinedBlocks.java | 2 +- .../com/boydti/fawe/beta/IBatchProcessor.java | 2 +- .../java/com/boydti/fawe/beta/IBlocks.java | 20 +- .../fawe/beta/IDelegateQueueExtent.java | 369 ------------ .../com/boydti/fawe/beta/IQueueExtent.java | 2 +- .../implementation/blocks/BitSetBlocks.java | 2 +- .../implementation/blocks/CharSetBlocks.java | 2 +- .../blocks/FallbackChunkGet.java | 2 +- .../implementation/blocks/NullChunkGet.kt | 2 +- .../implementation/chunk/ChunkHolder.java | 2 +- .../beta/implementation/chunk/NullChunk.java | 150 ----- .../beta/implementation/chunk/NullChunk.kt | 121 ++++ .../filter/block/CharFilterBlock.java | 2 +- .../implementation/packet/ChunkPacket.java | 6 +- .../processors/LimitExtent.java | 16 +- .../queue/ParallelQueueExtent.java | 17 +- .../implementation/queue/QueueHandler.java | 2 +- .../queue/SingleThreadQueueExtent.java | 1 - .../boydti/fawe/command/AnvilCommands.java | 2 +- .../com/boydti/fawe/jnbt/anvil/MCAChunk.java | 18 +- .../com/boydti/fawe/jnbt/anvil/MCAFile.java | 12 +- .../boydti/fawe/logging/LoggingChangeSet.java | 8 +- .../boydti/fawe/object/DataAnglePattern.java | 4 +- .../com/boydti/fawe/object/FaweLimit.java | 26 +- .../boydti/fawe/object/brush/ImageBrush.java | 3 +- .../boydti/fawe/object/brush/LayerBrush.java | 2 +- .../fawe/object/brush/RecurseBrush.java | 3 +- .../boydti/fawe/object/brush/SplineBrush.java | 2 +- .../cfi/HeightMapMCAGenerator.java | 4 +- .../object/changeset/AbstractChangeSet.java | 2 +- .../object/changeset/BlockBagChangeSet.java | 4 +- .../clipboard/remap/ClipboardRemapper.java | 4 +- .../fawe/object/collection/MemBlockSet.java | 10 +- .../fawe/object/extent/FaweRegionExtent.java | 24 +- .../object/extent/MemoryCheckingExtent.java | 2 +- .../boydti/fawe/object/extent/NullExtent.java | 2 +- .../fawe/object/extent/ProcessedWEExtent.java | 14 +- .../fawe/object/mask/FaweBlockMatcher.java | 18 +- .../object/schematic/MinecraftStructure.java | 10 +- .../plotquared/FaweLocalBlockQueue.java | 2 +- .../plotquared/FaweSchematicHandler.java | 2 +- .../java/com/boydti/fawe/util/BrushCache.java | 2 +- .../boydti/fawe/util/EditSessionBuilder.java | 8 +- .../java/com/boydti/fawe/web/SchemSync.java | 2 +- .../java/com/sk89q/worldedit/EditSession.java | 2 +- .../worldedit/command/ClipboardCommands.java | 6 +- .../worldedit/command/RegionCommands.java | 2 +- .../parser/mask/DefaultMaskParser.java | 3 +- .../com/sk89q/worldedit/extent/Extent.java | 4 +- .../sk89q/worldedit/extent/MaskingExtent.java | 2 +- .../clipboard/io/FastSchematicReader.java | 6 +- .../extent/clipboard/io/SchematicReader.java | 4 +- .../extent/inventory/BlockBagExtent.java | 4 +- .../function/generator/CavesGen.java | 15 +- .../mask/InverseSingleBlockStateMask.java | 2 +- .../function/mask/SingleBlockStateMask.java | 2 +- .../function/pattern/FawePattern.java | 23 - .../worldedit/math/MutableBlockVector3.java | 2 +- .../sk89q/worldedit/math/MutableVector3.java | 4 +- .../worldedit/math/convolution/HeightMap.java | 10 +- .../sk89q/worldedit/regions/CuboidRegion.java | 6 +- .../registry/state/PropertyGroup.java | 4 +- .../worldedit/world/block/BlockState.java | 4 +- .../world/block/BlockStateHolder.java | 6 +- .../worldedit/world/block/BlockType.java | 5 +- .../worldedit/world/block/BlockTypes.java | 22 +- 82 files changed, 867 insertions(+), 1343 deletions(-) delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/FaweCache.kt delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateQueueExtent.java delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/NullChunk.java create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/NullChunk.kt delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/FawePattern.java diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/FaweAdapter_All.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/FaweAdapter_All.java index d4aa283d1..8c4e41d25 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/FaweAdapter_All.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/FaweAdapter_All.java @@ -382,7 +382,7 @@ // int z = location.getBlockZ(); // // org.bukkit.block.Block bukkitBlock = location.getBlock(); -// BaseBlock block = FaweCache.IMP.getBlock(bukkitBlock.getTypeId(), bukkitBlock.getData()); +// BaseBlock block = FaweCache.INSTANCE.getBlock(bukkitBlock.getTypeId(), bukkitBlock.getData()); // // // Read the NBT data // Object nmsWorld = getHandleWorld.invoke(craftWorld); 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 6f948ffad..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 @@ -208,10 +208,10 @@ public final class BukkitAdapter_1_13 extends NMSAdapter { if (set == null) { return newChunkSection(layer, light); } - final int[] blockToPalette = FaweCache.IMP.BLOCK_TO_PALETTE.get(); - final int[] paletteToBlock = FaweCache.IMP.PALETTE_TO_BLOCK.get(); - final long[] blockStates = FaweCache.IMP.BLOCK_STATES.get(); - final int[] blocksCopy = FaweCache.IMP.SECTION_BLOCKS.get(); + final int[] blockToPalette = FaweCache.INSTANCE.getBLOCK_TO_PALETTE().get(); + final int[] paletteToBlock = FaweCache.INSTANCE.getPALETTE_TO_BLOCK().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_13/BukkitGetBlocks_1_13.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_13/BukkitGetBlocks_1_13.java index 98513aeb4..527b9408c 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_13/BukkitGetBlocks_1_13.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_13/BukkitGetBlocks_1_13.java @@ -493,9 +493,9 @@ public class BukkitGetBlocks_1_13 extends CharGetBlocks { ChunkSection section = getSections()[layer]; // Section is null, return empty array if (section == null) { - return FaweCache.IMP.EMPTY_CHAR_4096; + return FaweCache.INSTANCE.getEMPTY_CHAR_4096(); } - if (data == null || data == FaweCache.IMP.EMPTY_CHAR_4096) { + if (data == null || data == FaweCache.INSTANCE.getEMPTY_CHAR_4096()) { data = new char[4096]; } DelegateLock lock = BukkitAdapter_1_13.applyLock(section); @@ -522,8 +522,8 @@ public class BukkitGetBlocks_1_13 extends CharGetBlocks { num_palette = ((DataPaletteHash) palette).b(); } else { num_palette = 0; - int[] paletteToBlockInts = FaweCache.IMP.PALETTE_TO_BLOCK.get(); - char[] paletteToBlockChars = FaweCache.IMP.PALETTE_TO_BLOCK_CHAR.get(); + int[] paletteToBlockInts = FaweCache.INSTANCE.getPALETTE_TO_BLOCK().get(); + char[] paletteToBlockChars = FaweCache.INSTANCE.getPALETTE_TO_BLOCK_CHAR().get(); try { for (int i = 0; i < 4096; i++) { char paletteVal = data[i]; @@ -549,7 +549,7 @@ public class BukkitGetBlocks_1_13 extends CharGetBlocks { return data; } - char[] paletteToOrdinal = FaweCache.IMP.PALETTE_TO_BLOCK_CHAR.get(); + char[] paletteToOrdinal = FaweCache.INSTANCE.getPALETTE_TO_BLOCK_CHAR().get(); try { if (num_palette != 1) { for (int i = 0; i < num_palette; i++) { 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 3c3a2f551..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 @@ -201,10 +201,10 @@ public final class BukkitAdapter_1_14 extends NMSAdapter { if (set == null) { return newChunkSection(layer); } - final int[] blockToPalette = FaweCache.IMP.BLOCK_TO_PALETTE.get(); - final int[] paletteToBlock = FaweCache.IMP.PALETTE_TO_BLOCK.get(); - final long[] blockStates = FaweCache.IMP.BLOCK_STATES.get(); - final int[] blocksCopy = FaweCache.IMP.SECTION_BLOCKS.get(); + final int[] blockToPalette = FaweCache.INSTANCE.getBLOCK_TO_PALETTE().get(); + final int[] paletteToBlock = FaweCache.INSTANCE.getPALETTE_TO_BLOCK().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/BukkitGetBlocks_1_14.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java index a78d322e7..652ed9bc8 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java @@ -490,9 +490,9 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks { ChunkSection section = getSections()[layer]; // Section is null, return empty array if (section == null) { - return FaweCache.IMP.EMPTY_CHAR_4096; + return FaweCache.INSTANCE.getEMPTY_CHAR_4096(); } - if (data == null || data == FaweCache.IMP.EMPTY_CHAR_4096) { + if (data == null || data == FaweCache.INSTANCE.getEMPTY_CHAR_4096()) { data = new char[4096]; } DelegateLock lock = BukkitAdapter_1_14.applyLock(section); @@ -519,8 +519,8 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks { num_palette = ((DataPaletteHash) palette).b(); } else { num_palette = 0; - int[] paletteToBlockInts = FaweCache.IMP.PALETTE_TO_BLOCK.get(); - char[] paletteToBlockChars = FaweCache.IMP.PALETTE_TO_BLOCK_CHAR.get(); + int[] paletteToBlockInts = FaweCache.INSTANCE.getPALETTE_TO_BLOCK().get(); + char[] paletteToBlockChars = FaweCache.INSTANCE.getPALETTE_TO_BLOCK_CHAR().get(); try { for (int i = 0; i < 4096; i++) { char paletteVal = data[i]; @@ -546,7 +546,7 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks { return data; } - char[] paletteToOrdinal = FaweCache.IMP.PALETTE_TO_BLOCK_CHAR.get(); + char[] paletteToOrdinal = FaweCache.INSTANCE.getPALETTE_TO_BLOCK_CHAR().get(); try { if (num_palette != 1) { for (int i = 0; i < num_palette; i++) { 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 b00001bd5..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 @@ -179,10 +179,10 @@ public final class BukkitAdapter_1_15 extends NMSAdapter { if (set == null) { return newChunkSection(layer); } - final int[] blockToPalette = FaweCache.IMP.BLOCK_TO_PALETTE.get(); - final int[] paletteToBlock = FaweCache.IMP.PALETTE_TO_BLOCK.get(); - final long[] blockStates = FaweCache.IMP.BLOCK_STATES.get(); - final int[] blocksCopy = FaweCache.IMP.SECTION_BLOCKS.get(); + final int[] blockToPalette = FaweCache.INSTANCE.getBLOCK_TO_PALETTE().get(); + final int[] paletteToBlock = FaweCache.INSTANCE.getPALETTE_TO_BLOCK().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 02caa2818..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.IMP.WORLD_HEIGHT; 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.IMP.WORLD_HEIGHT; y++) { + for (int y = 0; y < FaweCache.WORLD_HEIGHT; y++) { currentBiomes.setBiome(x, y, z, nmsBiome); } } @@ -502,9 +502,9 @@ public class BukkitGetBlocks_1_15 extends CharGetBlocks { ChunkSection section = getSections()[layer]; // Section is null, return empty array if (section == null) { - return FaweCache.IMP.EMPTY_CHAR_4096; + return FaweCache.INSTANCE.getEMPTY_CHAR_4096(); } - if (data == null || data == FaweCache.IMP.EMPTY_CHAR_4096) { + if (data == null || data == FaweCache.INSTANCE.getEMPTY_CHAR_4096()) { data = new char[4096]; } DelegateLock lock = BukkitAdapter_1_15.applyLock(section); @@ -531,8 +531,8 @@ public class BukkitGetBlocks_1_15 extends CharGetBlocks { num_palette = ((DataPaletteHash) palette).b(); } else { num_palette = 0; - int[] paletteToBlockInts = FaweCache.IMP.PALETTE_TO_BLOCK.get(); - char[] paletteToBlockChars = FaweCache.IMP.PALETTE_TO_BLOCK_CHAR.get(); + int[] paletteToBlockInts = FaweCache.INSTANCE.getPALETTE_TO_BLOCK().get(); + char[] paletteToBlockChars = FaweCache.INSTANCE.getPALETTE_TO_BLOCK_CHAR().get(); try { for (int i = 0; i < 4096; i++) { char paletteVal = data[i]; @@ -558,7 +558,7 @@ public class BukkitGetBlocks_1_15 extends CharGetBlocks { return data; } - char[] paletteToOrdinal = FaweCache.IMP.PALETTE_TO_BLOCK_CHAR.get(); + char[] paletteToOrdinal = FaweCache.INSTANCE.getPALETTE_TO_BLOCK_CHAR().get(); try { if (num_palette != 1) { for (int i = 0; i < num_palette; i++) { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/CFIPacketListener.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/CFIPacketListener.java index b7be10671..0a89e1657 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/CFIPacketListener.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/CFIPacketListener.java @@ -93,7 +93,7 @@ public class CFIPacketListener implements Listener { case VOID_AIR: break; default: { - BlockStateHolder block = BukkitAdapter.asBlockState(hand); + BlockState block = BukkitAdapter.asBlockState(hand); if (block != null) { gen.setBlock(pt, block); return; @@ -123,7 +123,7 @@ public class CFIPacketListener implements Listener { protocolmanager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.MAP_CHUNK) { @Override public void onPacketSending(PacketEvent event) { - if (!event.isServerPacket() || FaweCache.IMP.CHUNK_FLAG.get().get()) return; + if (!event.isServerPacket() || FaweCache.INSTANCE.getCHUNK_FLAG().get().get()) return; VirtualWorld gen = getGenerator(event); if (gen != null) { BlockVector3 origin = gen.getOrigin().toBlockPoint(); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java index 48dc1500d..3542cf874 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java @@ -312,9 +312,10 @@ public class AsyncBlock implements Block { return this.getWorld().getHumidity(this.getX(), this.getZ()); } + @NotNull @Override public PistonMoveReaction getPistonMoveReaction() { - return null; + return PistonMoveReaction.IGNORE; } @Deprecated @@ -332,6 +333,10 @@ public class AsyncBlock implements Block { return TaskManager.IMP.sync(() -> getUnsafeBlock().breakNaturally(tool)); } + public boolean breakNaturally(@NotNull ItemStack tool, boolean value) { + return TaskManager.IMP.sync(() -> getUnsafeBlock().breakNaturally(tool)); + } + @NotNull @Override public Collection getDrops() { return TaskManager.IMP.sync(() -> getUnsafeBlock().getDrops()); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java index bde9cdb8c..5b161e14e 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java @@ -1249,12 +1249,7 @@ public class AsyncWorld extends PassthroughExtent implements World { @Override public int getHighestBlockYAt(int x, int z, com.destroystokyo.paper.HeightmapType heightmap) throws UnsupportedOperationException { - return TaskManager.IMP.sync(new Supplier() { - @Override - public Integer get() { - return parent.getHighestBlockYAt(x, z, heightmap); - } - }); + return TaskManager.IMP.sync(() -> parent.getHighestBlockYAt(x, z, heightmap)); } @Override diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncDataContainer.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncDataContainer.java index e2bc8ce64..e41e17f5a 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncDataContainer.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncDataContainer.java @@ -54,7 +54,7 @@ public final class AsyncDataContainer implements PersistentDataContainer { Validate.notNull(key, "The provided key for the custom value was null"); Validate.notNull(type, "The provided type for the custom value was null"); Validate.notNull(value, "The provided value for the custom value was null"); - get().put(key.toString(), FaweCache.IMP.asTag(type.toPrimitive(value, null))); + get().put(key.toString(), FaweCache.INSTANCE.asTag(type.toPrimitive(value, null))); } public boolean has(NamespacedKey key, PersistentDataType type) { diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_13_R2.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_13_R2.java index 28d7d9627..a47937759 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_13_R2.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_13_R2.java @@ -347,10 +347,10 @@ public final class FAWE_Spigot_v1_13_R2 extends CachedBukkitAdapter implements I packet.setNativePacket(nmsPacket); } try { - FaweCache.IMP.CHUNK_FLAG.get().set(true); + FaweCache.INSTANCE.getCHUNK_FLAG().get().set(true); current.playerConnection.sendPacket(nmsPacket); } finally { - FaweCache.IMP.CHUNK_FLAG.get().set(false); + FaweCache.INSTANCE.getCHUNK_FLAG().get().set(false); } } } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_14_R4.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_14_R4.java index 0c1055d68..73148a4e8 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_14_R4.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_14_R4.java @@ -347,10 +347,10 @@ public final class FAWE_Spigot_v1_14_R4 extends CachedBukkitAdapter implements I packet.setNativePacket(nmsPacket); } try { - FaweCache.IMP.CHUNK_FLAG.get().set(true); + FaweCache.INSTANCE.getCHUNK_FLAG().get().set(true); entityPlayer.playerConnection.sendPacket(nmsPacket); } finally { - FaweCache.IMP.CHUNK_FLAG.get().set(false); + FaweCache.INSTANCE.getCHUNK_FLAG().get().set(false); } } }); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_15_R1.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_15_R1.java index beeec07ce..ed2dc78d0 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_15_R1.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_15_R1.java @@ -25,6 +25,8 @@ import com.bekvon.bukkit.residence.commands.server; import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.beta.IChunkGet; +import com.boydti.fawe.beta.IQueueChunk; +import com.boydti.fawe.beta.IQueueExtent; import com.boydti.fawe.beta.implementation.packet.ChunkPacket; import com.boydti.fawe.beta.implementation.queue.SingleThreadQueueExtent; import com.boydti.fawe.bukkit.adapter.mc1_14.BlockMaterial_1_14; @@ -343,10 +345,10 @@ public final class FAWE_Spigot_v1_15_R1 extends CachedBukkitAdapter implements I packet.setNativePacket(nmsPacket); } try { - FaweCache.IMP.CHUNK_FLAG.get().set(true); + FaweCache.INSTANCE.getCHUNK_FLAG().get().set(true); entityPlayer.playerConnection.sendPacket(nmsPacket); } finally { - FaweCache.IMP.CHUNK_FLAG.get().set(false); + FaweCache.INSTANCE.getCHUNK_FLAG().get().set(false); } } }); @@ -431,7 +433,7 @@ public final class FAWE_Spigot_v1_15_R1 extends CachedBukkitAdapter implements I // We need to also pull one more chunk in every direction Fawe.get().getQueueHandler().startSet(true); try { - SingleThreadQueueExtent extent = new SingleThreadQueueExtent(); + IQueueExtent extent = new SingleThreadQueueExtent(); extent.init(null, (x, z) -> new BukkitGetBlocks_1_15(freshWorld, x, z) { @Override public Chunk ensureLoaded(World nmsWorld, int X, int Z) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java deleted file mode 100644 index aee4d4285..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java +++ /dev/null @@ -1,545 +0,0 @@ -package com.boydti.fawe; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.slf4j.LoggerFactory.getLogger; - -import com.boydti.fawe.beta.Trimable; -import com.boydti.fawe.beta.implementation.queue.Pool; -import com.boydti.fawe.beta.implementation.queue.QueuePool; -import com.boydti.fawe.config.Settings; -import com.boydti.fawe.object.collection.BitArray4096; -import com.boydti.fawe.object.collection.CleanableThreadLocal; -import com.boydti.fawe.object.collection.VariableThreadLocal; -import com.boydti.fawe.object.exception.FaweBlockBagException; -import com.boydti.fawe.object.exception.FaweChunkLoadException; -import com.boydti.fawe.object.exception.FaweException; -import com.boydti.fawe.util.IOUtil; -import com.boydti.fawe.util.MathMan; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import com.sk89q.jnbt.ByteArrayTag; -import com.sk89q.jnbt.ByteTag; -import com.sk89q.jnbt.CompoundTag; -import com.sk89q.jnbt.DoubleTag; -import com.sk89q.jnbt.EndTag; -import com.sk89q.jnbt.FloatTag; -import com.sk89q.jnbt.IntArrayTag; -import com.sk89q.jnbt.IntTag; -import com.sk89q.jnbt.ListTag; -import com.sk89q.jnbt.LongArrayTag; -import com.sk89q.jnbt.LongTag; -import com.sk89q.jnbt.ShortTag; -import com.sk89q.jnbt.StringTag; -import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.math.MutableBlockVector3; -import com.sk89q.worldedit.math.MutableVector3; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.world.block.BlockTypesCache; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.IdentityHashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.CancellationException; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Function; -import java.util.function.Supplier; - -public enum FaweCache implements Trimable { - IMP - ; // singleton - - public final int BLOCKS_PER_LAYER = 4096; - public final int CHUNK_LAYERS = 16; - public final int WORLD_HEIGHT = CHUNK_LAYERS << 4; - public final int WORLD_MAX_Y = WORLD_HEIGHT - 1; - - public final char[] EMPTY_CHAR_4096 = new char[4096]; - - private final IdentityHashMap, CleanableThreadLocal> REGISTERED_SINGLETONS = new IdentityHashMap<>(); - private final IdentityHashMap, Pool> REGISTERED_POOLS = new IdentityHashMap<>(); - - /* - Palette buffers / cache - */ - - @Override - public synchronized boolean trim(boolean aggressive) { - if (aggressive) { - CleanableThreadLocal.cleanAll(); - } else { - CHUNK_FLAG.clean(); - BYTE_BUFFER_8192.clean(); - BLOCK_TO_PALETTE.clean(); - PALETTE_TO_BLOCK.clean(); - BLOCK_STATES.clean(); - SECTION_BLOCKS.clean(); - PALETTE_CACHE.clean(); - PALETTE_TO_BLOCK_CHAR.clean(); - INDEX_STORE.clean(); - - MUTABLE_VECTOR3.clean(); - MUTABLE_BLOCKVECTOR3.clean(); - SECTION_BITS_TO_CHAR.clean(); - for (Map.Entry, CleanableThreadLocal> entry : REGISTERED_SINGLETONS.entrySet()) { - entry.getValue().clean(); - } - } - for (Map.Entry, Pool> entry : REGISTERED_POOLS.entrySet()) { - Pool pool = entry.getValue(); - pool.clear(); - } - - return false; - } - - public final Pool getPool(Class clazz) { - Pool pool = REGISTERED_POOLS.get(clazz); - if (pool == null) { - synchronized (this) { - pool = REGISTERED_POOLS.get(clazz); - if (pool == null) { - getLogger(FaweCache.class).debug("Not registered " + clazz); - Supplier supplier = IOUtil.supplier(clazz::newInstance); - pool = supplier::get; - REGISTERED_POOLS.put(clazz, pool); - } - } - } - return pool; - } - - public final T getFromPool(Class clazz) { - Pool pool = getPool(clazz); - return pool.poll(); - } - - public final T getSingleton(Class clazz) { - CleanableThreadLocal cache = REGISTERED_SINGLETONS.get(clazz); - if (cache == null) { - synchronized (this) { - cache = REGISTERED_SINGLETONS.get(clazz); - if (cache == null) { - getLogger(FaweCache.class).debug("Not registered " + clazz); - cache = new CleanableThreadLocal<>(IOUtil.supplier(clazz::newInstance)); - REGISTERED_SINGLETONS.put(clazz, cache); - } - } - } - return cache.get(); - } - - public synchronized CleanableThreadLocal registerSingleton(Class clazz, Supplier cache) { - checkNotNull(cache); - CleanableThreadLocal local = new CleanableThreadLocal<>(cache); - CleanableThreadLocal previous = REGISTERED_SINGLETONS.putIfAbsent(clazz, local); - if (previous != null) { - throw new IllegalStateException("Previous key"); - } - return local; - } - - public synchronized Pool registerPool(Class clazz, Supplier cache, boolean buffer) { - checkNotNull(cache); - Pool pool; - if (buffer) { - pool = new QueuePool<>(cache); - } else { - pool = cache::get; - } - Pool previous = REGISTERED_POOLS.putIfAbsent(clazz, pool); - if (previous != null) { - throw new IllegalStateException("Previous key"); - } - return pool; - } - - public LoadingCache createCache(Supplier withInitial) { - return CacheBuilder.newBuilder().build(new CacheLoader() { - @Override - public V load(T key) { - return withInitial.get(); - } - }); - } - - public LoadingCache createCache(Function withInitial) { - return CacheBuilder.newBuilder().build(new CacheLoader() { - @Override - public V load(T key) { - return withInitial.apply(key); - } - }); - } - - /* - Exceptions - */ - public static final FaweChunkLoadException CHUNK = new FaweChunkLoadException(); - public static final FaweBlockBagException BLOCK_BAG = new FaweBlockBagException(); - public static final FaweException MANUAL = new FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.manual")); - public static final FaweException NO_REGION = new FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.no.region")); - public static final FaweException OUTSIDE_REGION = new FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.outside.region")); - public static final FaweException MAX_CHECKS = new FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.max.checks")); - public static final FaweException MAX_CHANGES = new FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.max.changes")); - public static final FaweException LOW_MEMORY = new FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.low.memory")); - public static final FaweException MAX_ENTITIES = new FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.max.entities")); - public static final FaweException MAX_TILES = new FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.max.tiles")); - public static final FaweException MAX_ITERATIONS = new FaweException(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.max.iterations")); - - /* - thread cache - */ - public final CleanableThreadLocal CHUNK_FLAG = new CleanableThreadLocal<>(AtomicBoolean::new); // resets to false - - public final CleanableThreadLocal LONG_BUFFER_1024 = new CleanableThreadLocal<>(() -> new long[1024]); - - public final CleanableThreadLocal BYTE_BUFFER_8192 = new CleanableThreadLocal<>(() -> new byte[8192]); - - public final VariableThreadLocal BYTE_BUFFER_VAR = new VariableThreadLocal(); - - public final CleanableThreadLocal BLOCK_TO_PALETTE = new CleanableThreadLocal<>(() -> { - int[] result = new int[BlockTypesCache.states.length]; - Arrays.fill(result, Integer.MAX_VALUE); - return result; - }); - - public final CleanableThreadLocal SECTION_BITS_TO_CHAR = new CleanableThreadLocal<>(() -> new char[4096]); - - public final CleanableThreadLocal PALETTE_TO_BLOCK = new CleanableThreadLocal<>(() -> new int[Character.MAX_VALUE + 1]); - - public final CleanableThreadLocal PALETTE_TO_BLOCK_CHAR = new CleanableThreadLocal<>( - () -> new char[Character.MAX_VALUE + 1], a -> { - Arrays.fill(a, Character.MAX_VALUE); - } - ); - - public final CleanableThreadLocal BLOCK_STATES = new CleanableThreadLocal<>(() -> new long[2048]); - - public final CleanableThreadLocal SECTION_BLOCKS = new CleanableThreadLocal<>(() -> new int[4096]); - - public final CleanableThreadLocal INDEX_STORE = new CleanableThreadLocal<>(() -> new int[256]); - - public final CleanableThreadLocal HEIGHT_STORE = new CleanableThreadLocal<>(() -> new int[256]); - - /** - * Holds data for a palette used in a chunk section - */ - public static final class Palette { - public int bitsPerEntry; - - public int paletteToBlockLength; - /** - * Reusable buffer array, MUST check paletteToBlockLength for actual length - */ - public int[] paletteToBlock; - - public int blockStatesLength; - /** - * Reusable buffer array, MUST check blockStatesLength for actual length - */ - public long[] blockStates; - } - - private final CleanableThreadLocal PALETTE_CACHE = new CleanableThreadLocal<>(Palette::new); - - /** - * Convert raw char array to palette - * @param layerOffset - * @param blocks - * @return palette - */ - public Palette toPalette(int layerOffset, char[] blocks) { - return toPalette(layerOffset, null, blocks); - } - - /** - * Convert raw int array to palette - * @param layerOffset - * @param blocks - * @return palette - */ - public Palette toPalette(int layerOffset, int[] blocks) { - return toPalette(layerOffset, blocks, null); - } - - private Palette toPalette(int layerOffset, int[] blocksInts, char[] blocksChars) { - int[] blockToPalette = BLOCK_TO_PALETTE.get(); - int[] paletteToBlock = PALETTE_TO_BLOCK.get(); - long[] blockStates = BLOCK_STATES.get(); - int[] blocksCopy = SECTION_BLOCKS.get(); - - int blockIndexStart = layerOffset << 12; - int blockIndexEnd = blockIndexStart + 4096; - int num_palette = 0; - try { - if (blocksChars != null) { - for (int i = blockIndexStart, j = 0; i < blockIndexEnd; i++, j++) { - int ordinal = blocksChars[i]; - int palette = blockToPalette[ordinal]; - if (palette == Integer.MAX_VALUE) { - blockToPalette[ordinal] = palette = num_palette; - paletteToBlock[num_palette] = ordinal; - num_palette++; - } - blocksCopy[j] = palette; - } - } else if (blocksInts != null) { - for (int i = blockIndexStart, j = 0; i < blockIndexEnd; i++, j++) { - int ordinal = blocksInts[i]; - int palette = blockToPalette[ordinal]; - if (palette == Integer.MAX_VALUE) { -// BlockState state = BlockTypesCache.states[ordinal]; - blockToPalette[ordinal] = palette = num_palette; - paletteToBlock[num_palette] = ordinal; - num_palette++; - } - blocksCopy[j] = palette; - } - } else { - throw new IllegalArgumentException(); - } - - for (int i = 0; i < num_palette; i++) { - blockToPalette[paletteToBlock[i]] = Integer.MAX_VALUE; - } - - // BlockStates - int bitsPerEntry = MathMan.log2nlz(num_palette - 1); - if (Settings.IMP.PROTOCOL_SUPPORT_FIX || num_palette != 1) { - bitsPerEntry = Math.max(bitsPerEntry, 4); // Protocol support breaks <4 bits per entry - } else { - bitsPerEntry = Math.max(bitsPerEntry, 1); // For some reason minecraft needs 4096 bits to store 0 entries - } - int blockBitArrayEnd = (bitsPerEntry * 4096) >> 6; - if (num_palette == 1) { - // Set a value, because minecraft needs it for some reason - blockStates[0] = 0; - blockBitArrayEnd = 1; - } else { - BitArray4096 bitArray = new BitArray4096(blockStates, bitsPerEntry); - bitArray.fromRaw(blocksCopy); - } - - // Construct palette - Palette palette = PALETTE_CACHE.get(); - palette.bitsPerEntry = bitsPerEntry; - palette.paletteToBlockLength = num_palette; - palette.paletteToBlock = paletteToBlock; - - palette.blockStatesLength = blockBitArrayEnd; - palette.blockStates = blockStates; - - return palette; - } catch (Throwable e) { - e.printStackTrace(); - Arrays.fill(blockToPalette, Integer.MAX_VALUE); - throw e; - } - } - - /* - * Vector cache - */ - - public CleanableThreadLocal MUTABLE_BLOCKVECTOR3 = new CleanableThreadLocal<>(MutableBlockVector3::new); - - public CleanableThreadLocal MUTABLE_VECTOR3 = new CleanableThreadLocal(MutableVector3::new) { - @Override - public MutableVector3 init() { - return new MutableVector3(); - } - }; - - /* - Conversion methods between JNBT tags and raw values - */ - public Map asMap(Object... pairs) { - HashMap map = new HashMap<>(pairs.length >> 1); - for (int i = 0; i < pairs.length; i += 2) { - String key = (String) pairs[i]; - Object value = pairs[i + 1]; - map.put(key, value); - } - return map; - } - - public ShortTag asTag(short value) { - return new ShortTag(value); - } - - public IntTag asTag(int value) { - return new IntTag(value); - } - - public DoubleTag asTag(double value) { - return new DoubleTag(value); - } - - public ByteTag asTag(byte value) { - return new ByteTag(value); - } - - public FloatTag asTag(float value) { - return new FloatTag(value); - } - - public LongTag asTag(long value) { - return new LongTag(value); - } - - public ByteArrayTag asTag(byte[] value) { - return new ByteArrayTag(value); - } - - public IntArrayTag asTag(int[] value) { - return new IntArrayTag(value); - } - - public LongArrayTag asTag(long[] value) { - return new LongArrayTag(value); - } - - public StringTag asTag(String value) { - return new StringTag(value); - } - - public CompoundTag asTag(Map value) { - HashMap map = new HashMap<>(); - for (Map.Entry entry : value.entrySet()) { - Object child = entry.getValue(); - Tag tag = asTag(child); - map.put(entry.getKey(), tag); - } - return new CompoundTag(map); - } - - public Tag asTag(Object value) { - if (value instanceof Integer) { - return asTag((int) value); - } else if (value instanceof Short) { - return asTag((short) value); - } else if (value instanceof Double) { - return asTag((double) value); - } else if (value instanceof Byte) { - return asTag((byte) value); - } else if (value instanceof Float) { - return asTag((float) value); - } else if (value instanceof Long) { - return asTag((long) value); - } else if (value instanceof String) { - return asTag((String) value); - } else if (value instanceof Map) { - return asTag((Map) value); - } else if (value instanceof Collection) { - return asTag((Collection) value); - } else if (value instanceof Object[]) { - return asTag((Object[]) value); - } else if (value instanceof byte[]) { - return asTag((byte[]) value); - } else if (value instanceof int[]) { - return asTag((int[]) value); - } else if (value instanceof long[]) { - return asTag((long[]) value); - } else if (value instanceof Tag) { - return (Tag) value; - } else if (value instanceof Boolean) { - return asTag((byte) ((boolean) value ? 1 : 0)); - } else if (value == null) { - System.out.println("Invalid nbt: " + value); - return null; - } else { - Class clazz = value.getClass(); - if (clazz.getName().startsWith("com.intellectualcrafters.jnbt")) { - try { - if (clazz.getName().equals("com.intellectualcrafters.jnbt.EndTag")) { - return new EndTag(); - } - Field field = clazz.getDeclaredField("value"); - field.setAccessible(true); - return asTag(field.get(value)); - } catch (Throwable e) { - e.printStackTrace(); - } - } - System.out.println("Invalid nbt: " + value); - return null; - } - } - - public ListTag asTag(Object... values) { - Class clazz = null; - List list = new ArrayList<>(values.length); - for (Object value : values) { - Tag tag = asTag(value); - if (clazz == null) { - clazz = tag.getClass(); - } - list.add(tag); - } - if (clazz == null) clazz = EndTag.class; - return new ListTag(clazz, list); - } - - public ListTag asTag(Collection values) { - Class clazz = null; - List list = new ArrayList<>(values.size()); - for (Object value : values) { - Tag tag = asTag(value); - if (clazz == null) { - clazz = tag.getClass(); - } - list.add(tag); - } - if (clazz == null) clazz = EndTag.class; - return new ListTag(clazz, list); - } - - /* - Thread stuff - */ - public ThreadPoolExecutor newBlockingExecutor() { - int nThreads = Settings.IMP.QUEUE.PARALLEL_THREADS; - ArrayBlockingQueue queue = new ArrayBlockingQueue<>(nThreads); - return new ThreadPoolExecutor(nThreads, nThreads, - 0L, TimeUnit.MILLISECONDS, queue - , Executors.defaultThreadFactory(), - new ThreadPoolExecutor.CallerRunsPolicy()) { - protected void afterExecute(Runnable r, Throwable t) { - try { - super.afterExecute(r, t); - if (t == null && r instanceof Future) { - try { - Future future = (Future) r; - if (future.isDone()) { - future.get(); - } - } catch (CancellationException ce) { - t = ce; - } catch (ExecutionException ee) { - t = ee.getCause(); - } catch (InterruptedException ie) { - Thread.currentThread().interrupt(); - } - } - if (t != null) { - t.printStackTrace(); - } - } catch (Throwable e) { - e.printStackTrace(); - } - } - }; - } -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.kt b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.kt new file mode 100644 index 000000000..7c7d788ad --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.kt @@ -0,0 +1,521 @@ +package com.boydti.fawe + +import com.boydti.fawe.`object`.collection.BitArray4096 +import com.boydti.fawe.`object`.collection.CleanableThreadLocal +import com.boydti.fawe.`object`.collection.VariableThreadLocal +import com.boydti.fawe.`object`.exception.FaweBlockBagException +import com.boydti.fawe.`object`.exception.FaweChunkLoadException +import com.boydti.fawe.`object`.exception.FaweException +import com.boydti.fawe.beta.Trimable +import com.boydti.fawe.beta.implementation.queue.Pool +import com.boydti.fawe.beta.implementation.queue.QueuePool +import com.boydti.fawe.config.Settings +import com.boydti.fawe.util.IOUtil +import com.boydti.fawe.util.MathMan +import com.google.common.base.Preconditions.checkNotNull +import com.google.common.cache.CacheBuilder +import com.google.common.cache.CacheLoader +import com.google.common.cache.LoadingCache +import com.sk89q.jnbt.* +import com.sk89q.worldedit.math.MutableBlockVector3 +import com.sk89q.worldedit.math.MutableVector3 +import com.sk89q.worldedit.util.formatting.text.TranslatableComponent +import com.sk89q.worldedit.world.block.BlockTypesCache +import org.slf4j.LoggerFactory.getLogger +import java.util.* +import java.util.concurrent.* +import java.util.concurrent.atomic.AtomicBoolean +import java.util.function.Function +import java.util.function.Supplier + +object FaweCache : Trimable { + + const val BLOCKS_PER_LAYER = 4096 + 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) + + private val REGISTERED_SINGLETONS = IdentityHashMap, CleanableThreadLocal<*>>() + private val REGISTERED_POOLS = IdentityHashMap, Pool<*>>() + + /* + thread cache + */ + val CHUNK_FLAG = CleanableThreadLocal(Supplier { AtomicBoolean() }) // resets to false + + val LONG_BUFFER_1024 = CleanableThreadLocal { LongArray(1024) } + + val BYTE_BUFFER_8192 = CleanableThreadLocal { ByteArray(8192) } + + val BYTE_BUFFER_VAR = VariableThreadLocal() + + val BLOCK_TO_PALETTE = CleanableThreadLocal { + val result = IntArray(BlockTypesCache.states.size) + Arrays.fill(result, Integer.MAX_VALUE) + result + } + + val SECTION_BITS_TO_CHAR = CleanableThreadLocal { CharArray(4096) } + + val PALETTE_TO_BLOCK = CleanableThreadLocal { IntArray(Character.MAX_VALUE.toInt() + 1) } + + val PALETTE_TO_BLOCK_CHAR = CleanableThreadLocal( + fun(): CharArray { + return CharArray(Char.MAX_VALUE.toInt() + 1) + }, fun(a: CharArray): Unit = Arrays.fill(a, Char.MAX_VALUE) + ) + + val BLOCK_STATES = CleanableThreadLocal { LongArray(2048) } + + val SECTION_BLOCKS = CleanableThreadLocal { IntArray(4096) } + + val INDEX_STORE = CleanableThreadLocal { IntArray(256) } + + val HEIGHT_STORE = CleanableThreadLocal { IntArray(256) } + + private val PALETTE_CACHE = CleanableThreadLocal(Supplier { Palette() }) + + /* + * Vector cache + */ + + var MUTABLE_BLOCKVECTOR3 = CleanableThreadLocal(Supplier { MutableBlockVector3() }) + + var MUTABLE_VECTOR3: CleanableThreadLocal = object : CleanableThreadLocal(Supplier { MutableVector3() }) { + override fun init(): MutableVector3 { + return MutableVector3() + } + } + + /* + Palette buffers / cache + */ + + @Synchronized + override fun trim(aggressive: Boolean): Boolean { + if (aggressive) { + CleanableThreadLocal.cleanAll() + } else { + CHUNK_FLAG.clean() + BYTE_BUFFER_8192.clean() + BLOCK_TO_PALETTE.clean() + PALETTE_TO_BLOCK.clean() + BLOCK_STATES.clean() + SECTION_BLOCKS.clean() + PALETTE_CACHE.clean() + PALETTE_TO_BLOCK_CHAR.clean() + INDEX_STORE.clean() + + MUTABLE_VECTOR3.clean() + MUTABLE_BLOCKVECTOR3.clean() + SECTION_BITS_TO_CHAR.clean() + for ((_, value) in REGISTERED_SINGLETONS) { + value.clean() + } + } + for ((_, pool) in REGISTERED_POOLS) { + pool.clear() + } + + return false + } + + fun getPool(clazz: Class): Pool? { + var pool: Pool? = REGISTERED_POOLS[clazz] as Pool? + if (pool == null) { + synchronized(this) { + pool = REGISTERED_POOLS[clazz] as Pool? + if (pool == null) { + getLogger(FaweCache::class.java).debug("Not registered $clazz") + val supplier = IOUtil.supplier { clazz.newInstance() } + pool = Pool { supplier.get() } + REGISTERED_POOLS[clazz] = pool + } + } + } + return pool + } + + fun getFromPool(clazz: Class): T? { + val pool = getPool(clazz) + return pool?.poll() + } + + fun getSingleton(clazz: Class): T { + var cache: CleanableThreadLocal? = REGISTERED_SINGLETONS[clazz] as CleanableThreadLocal? + if (cache == null) { + synchronized(this) { + cache = REGISTERED_SINGLETONS[clazz] as CleanableThreadLocal? + if (cache == null) { + getLogger(FaweCache::class.java).debug("Not registered $clazz") + cache = CleanableThreadLocal(IOUtil.supplier { clazz.newInstance() }) + REGISTERED_SINGLETONS[clazz] = cache + } + } + } + return cache!!.get() + } + + @Synchronized + fun registerSingleton(clazz: Class, cache: Supplier): CleanableThreadLocal { + checkNotNull(cache) + val local = CleanableThreadLocal(cache) + val previous = (REGISTERED_SINGLETONS as java.util.Map, CleanableThreadLocal<*>>).putIfAbsent(clazz, local) + check(previous == null) { "Previous key" } + return local + } + + @Synchronized + fun registerPool(clazz: Class, cache: Supplier, buffer: Boolean): Pool { + checkNotNull(cache) + val pool: Pool + if (buffer) { + pool = QueuePool(cache) + } else { + pool = Pool { cache.get() } + } + val previous = (REGISTERED_POOLS as java.util.Map, Pool<*>>).putIfAbsent(clazz, pool) + check(previous == null) { "Previous key" } + return pool + } + + fun createCache(withInitial: Supplier): LoadingCache { + return CacheBuilder.newBuilder().build(object : CacheLoader() { + override fun load(key: T): V { + return withInitial.get() + } + }) + } + + fun createCache(withInitial: Function): LoadingCache { + return CacheBuilder.newBuilder().build(object : CacheLoader() { + override fun load(key: T): V { + return withInitial.apply(key) + } + }) + } + + /** + * Holds data for a palette used in a chunk section + */ + class Palette { + var bitsPerEntry: Int = 0 + + var paletteToBlockLength: Int = 0 + /** + * Reusable buffer array, MUST check paletteToBlockLength for actual length + */ + var paletteToBlock: IntArray? = null + + var blockStatesLength: Int = 0 + /** + * Reusable buffer array, MUST check blockStatesLength for actual length + */ + var blockStates: LongArray? = null + } + + /** + * Convert raw char array to palette + * @param layerOffset + * @param blocks + * @return palette + */ + fun toPalette(layerOffset: Int, blocks: CharArray): Palette { + return toPalette(layerOffset, null, blocks) + } + + /** + * Convert raw int array to palette + * @param layerOffset + * @param blocks + * @return palette + */ + fun toPalette(layerOffset: Int, blocks: IntArray): Palette { + return toPalette(layerOffset, blocks, null) + } + + private fun toPalette(layerOffset: Int, blocksInts: IntArray?, blocksChars: CharArray?): Palette { + val blockToPalette = BLOCK_TO_PALETTE.get() + val paletteToBlock = PALETTE_TO_BLOCK.get() + val blockStates = BLOCK_STATES.get() + val blocksCopy = SECTION_BLOCKS.get() + + val blockIndexStart = layerOffset shl 12 + val blockIndexEnd = blockIndexStart + 4096 + var num_palette = 0 + try { + if (blocksChars != null) { + var i = blockIndexStart + var j = 0 + while (i < blockIndexEnd) { + val ordinal = blocksChars[i].toInt() + var palette = blockToPalette[ordinal] + if (palette == Integer.MAX_VALUE) { + palette = num_palette + blockToPalette[ordinal] = palette + paletteToBlock[num_palette] = ordinal + num_palette++ + } + blocksCopy[j] = palette + i++ + j++ + } + } else if (blocksInts != null) { + var i = blockIndexStart + var j = 0 + while (i < blockIndexEnd) { + val ordinal = blocksInts[i] + var palette = blockToPalette[ordinal] + if (palette == Integer.MAX_VALUE) { + // BlockState state = BlockTypesCache.states[ordinal]; + palette = num_palette + blockToPalette[ordinal] = palette + paletteToBlock[num_palette] = ordinal + num_palette++ + } + blocksCopy[j] = palette + i++ + j++ + } + } else { + throw IllegalArgumentException() + } + + for (i in 0 until num_palette) { + blockToPalette[paletteToBlock[i]] = Integer.MAX_VALUE + } + + // BlockStates + var bitsPerEntry = MathMan.log2nlz(num_palette - 1) + if (Settings.IMP.PROTOCOL_SUPPORT_FIX || num_palette != 1) { + bitsPerEntry = Math.max(bitsPerEntry, 4) // Protocol support breaks <4 bits per entry + } else { + bitsPerEntry = Math.max(bitsPerEntry, 1) // For some reason minecraft needs 4096 bits to store 0 entries + } + var blockBitArrayEnd = bitsPerEntry * 4096 shr 6 + if (num_palette == 1) { + // Set a value, because minecraft needs it for some reason + blockStates[0] = 0 + blockBitArrayEnd = 1 + } else { + val bitArray = BitArray4096(blockStates, bitsPerEntry) + bitArray.fromRaw(blocksCopy) + } + + // Construct palette + val palette = PALETTE_CACHE.get() + palette.bitsPerEntry = bitsPerEntry + palette.paletteToBlockLength = num_palette + palette.paletteToBlock = paletteToBlock + + palette.blockStatesLength = blockBitArrayEnd + palette.blockStates = blockStates + + return palette + } catch (e: Throwable) { + e.printStackTrace() + Arrays.fill(blockToPalette, Integer.MAX_VALUE) + throw e + } + + } + + /* + Conversion methods between JNBT tags and raw values + */ + fun asMap(vararg pairs: Any): Map { + val map = HashMap(pairs.size shr 1) + var i = 0 + while (i < pairs.size) { + val key = pairs[i] as String + val value = pairs[i + 1] + map[key] = value + i += 2 + } + return map + } + + fun asTag(value: Short): ShortTag { + return ShortTag(value) + } + + fun asTag(value: Int): IntTag { + return IntTag(value) + } + + fun asTag(value: Double): DoubleTag { + return DoubleTag(value) + } + + fun asTag(value: Byte): ByteTag { + return ByteTag(value) + } + + fun asTag(value: Float): FloatTag { + return FloatTag(value) + } + + fun asTag(value: Long): LongTag { + return LongTag(value) + } + + fun asTag(value: ByteArray): ByteArrayTag { + return ByteArrayTag(value) + } + + fun asTag(value: IntArray): IntArrayTag { + return IntArrayTag(value) + } + + fun asTag(value: LongArray): LongArrayTag { + return LongArrayTag(value) + } + + fun asTag(value: String): StringTag { + return StringTag(value) + } + + fun asTag(value: Map): CompoundTag { + val map = HashMap() + for ((key, child) in value) { + val tag = asTag(child) + map[key] = tag + } + return CompoundTag(map) + } + + fun asTag(value: Any?): Tag? { + if (value is Int) { + return asTag(value) + } else if (value is Short) { + return asTag(value) + } else if (value is Double) { + return asTag(value) + } else if (value is Byte) { + return asTag(value) + } else if (value is Float) { + return asTag(value) + } else if (value is Long) { + return asTag(value) + } else if (value is String) { + return asTag(value as String?) + } else if (value is Map<*, *>) { + return asTag((value as Map?)!!) + } else if (value is Collection<*>) { + return asTag((value as Collection<*>?)!!) + } else if (value is Array<*>) { + return asTag(*(value as Array?)!!) + } else if (value is ByteArray) { + return asTag(value as ByteArray?) + } else if (value is IntArray) { + return asTag(value as IntArray?) + } else if (value is LongArray) { + return asTag(value as LongArray?) + } else if (value is Tag) { + return value + } else if (value is Boolean) { + return asTag((if (value) 1 else 0).toByte()) + } else if (value == null) { + println("Invalid nbt: " + value!!) + return null + } else { + val clazz = value.javaClass + if (clazz.name.startsWith("com.intellectualcrafters.jnbt")) { + try { + if (clazz.name == "com.intellectualcrafters.jnbt.EndTag") { + return EndTag() + } + val field = clazz.getDeclaredField("value") + field.isAccessible = true + return asTag(field.get(value)) + } catch (e: Throwable) { + e.printStackTrace() + } + + } + println("Invalid nbt: $value") + return null + } + } + + fun asTag(vararg values: Any): ListTag { + var clazz: Class? = null + val list = ArrayList(values.size) + for (value in values) { + val tag = asTag(value) + if (clazz == null) { + clazz = tag.javaClass + } + list.add(tag) + } + if (clazz == null) clazz = EndTag::class.java + return ListTag(clazz, list) + } + + fun asTag(values: Collection<*>): ListTag { + var clazz: Class? = null + val list: ArrayList = ArrayList(values.size) + for (value in values) { + val tag = asTag(value) + if (clazz == null) { + clazz = tag!!.javaClass + } + if (tag != null) { + list.add(tag) + } + } + if (clazz == null) clazz = EndTag::class.java + return ListTag(clazz, list) + } + + /* + Thread stuff + */ + fun newBlockingExecutor(): ThreadPoolExecutor { + val nThreads = Settings.IMP.QUEUE.PARALLEL_THREADS + val queue = ArrayBlockingQueue(nThreads) + return object : ThreadPoolExecutor(nThreads, nThreads, + 0L, TimeUnit.MILLISECONDS, queue, Executors.defaultThreadFactory(), + ThreadPoolExecutor.CallerRunsPolicy()) { + override fun afterExecute(r: Runnable?, t: Throwable?) { + var t = t + try { + super.afterExecute(r, t) + if (t == null && r is Future<*>) { + try { + val future = r as Future<*>? + if (future!!.isDone) { + future.get() + } + } catch (ce: CancellationException) { + t = ce + } catch (ee: ExecutionException) { + t = ee.cause + } catch (ie: InterruptedException) { + Thread.currentThread().interrupt() + } + + } + t?.printStackTrace() + } catch (e: Throwable) { + e.printStackTrace() + } + + } + } + } + + 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 0915fed10..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 @@ -34,7 +34,7 @@ public class CombinedBlocks implements IBlocks { @Override public int getBitMask() { int bitMask = addMask; - for (int layer = 0; layer < FaweCache.IMP.CHUNK_LAYERS; 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 7f913b5d1..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.IMP.CHUNK_LAYERS; 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 b175b62d3..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.IMP.CHUNK_LAYERS).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.IMP.CHUNK_LAYERS; layer++) { + for (int layer = 0; layer < FaweCache.CHUNK_LAYERS; layer++) { if (!this.hasSection(layer) || (bitMask & (1 << layer)) == 0) continue; char[] ids = this.load(layer); @@ -92,12 +92,12 @@ public interface IBlocks extends Trimable { // } // sectionWriter.write(bits.getData()); // } else { - FaweCache.Palette palette = FaweCache.IMP.toPalette(0, ids); + FaweCache.Palette palette = FaweCache.INSTANCE.toPalette(0, ids); - sectionWriter.writeByte(palette.bitsPerEntry); // bits per block - sectionWriter.writeVarInt(palette.paletteToBlockLength); - for (int i = 0; i < palette.paletteToBlockLength; i++) { - int ordinal = palette.paletteToBlock[i]; + sectionWriter.writeByte(palette.getBitsPerEntry()); // bits per block + sectionWriter.writeVarInt(palette.getPaletteToBlockLength()); + for (int i = 0; i < palette.getPaletteToBlockLength(); i++) { + int ordinal = palette.getPaletteToBlock()[i]; switch (ordinal) { case BlockID.__RESERVED__: case BlockID.CAVE_AIR: @@ -112,9 +112,9 @@ public interface IBlocks extends Trimable { break; } } - sectionWriter.writeVarInt(palette.blockStatesLength); - for (int i = 0; i < palette.blockStatesLength; i++) { - sectionWriter.writeLong(palette.blockStates[i]); + sectionWriter.writeVarInt(palette.getBlockStatesLength()); + for (int i = 0; i < palette.getBlockStatesLength(); i++) { + sectionWriter.writeLong(palette.getBlockStates()[i]); } // } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateQueueExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateQueueExtent.java deleted file mode 100644 index 8a120ef6e..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateQueueExtent.java +++ /dev/null @@ -1,369 +0,0 @@ -package com.boydti.fawe.beta; - -import com.boydti.fawe.beta.implementation.filter.block.ChunkFilterBlock; -import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.entity.BaseEntity; -import com.sk89q.worldedit.entity.Entity; -import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.function.generator.GenBase; -import com.sk89q.worldedit.function.generator.Resource; -import com.sk89q.worldedit.function.mask.Mask; -import com.sk89q.worldedit.function.operation.Operation; -import com.sk89q.worldedit.function.pattern.Pattern; -import com.sk89q.worldedit.math.BlockVector2; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.session.ClipboardHolder; -import com.sk89q.worldedit.util.Countable; -import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.world.biome.BiomeType; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockStateHolder; -import com.sk89q.worldedit.world.block.BlockType; - -import javax.annotation.Nullable; -import java.util.List; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.Future; - -/** - * Delegate for IQueueExtent - */ -public interface IDelegateQueueExtent extends IQueueExtent { - - IQueueExtent getParent(); - - @Override - default boolean isQueueEnabled() { - return getParent().isQueueEnabled(); - } - - @Override - default void enableQueue() { - getParent().enableQueue(); - } - - @Override - default void disableQueue() { - getParent().disableQueue(); - } - - @Override - default void init(Extent extent, IChunkCache get, IChunkCache set) { - getParent().init(extent, get, set); - } - - @Override - default IChunkGet getCachedGet(int x, int z) { - return getParent().getCachedGet(x, z); - } - - @Override - default IChunkSet getCachedSet(int x, int z) { - return getParent().getCachedSet(x, z); - } - - @Override - default T getOrCreateChunk(int x, int z) { - return getParent().getOrCreateChunk(x, z); - } - - @Override - default > V submit(T chunk) { - return getParent().submit(chunk); - } - - @Override - default > boolean setBlock(int x, int y, int z, B state) { - return getParent().setBlock(x, y, z, state); - } - - @Override - default boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException { - return getParent().setTile(x, y, z, tile); - } - - @Override - default boolean setBiome(int x, int y, int z, BiomeType biome) { - return getParent().setBiome(x, y, z, biome); - } - - @Override - default BlockState getBlock(int x, int y, int z) { - return getParent().getBlock(x, y, z); - } - - @Override - default BaseBlock getFullBlock(int x, int y, int z) { - return getParent().getFullBlock(x, y, z); - } - - @Override - default BlockVector3 getMinimumPoint() { - return getParent().getMinimumPoint(); - } - - @Override - default BlockVector3 getMaximumPoint() { - return getParent().getMaximumPoint(); - } - - @Override - default T create(boolean isFull) { - return getParent().create(isFull); - } - - @Override - default T wrap(T root) { - return getParent().wrap(root); - } - - @Override - default void flush() { - getParent().flush(); - } - - @Override - default ChunkFilterBlock initFilterBlock() { - return getParent().initFilterBlock(); - } - - @Override - default int size() { - return getParent().size(); - } - - @Override - default boolean isEmpty() { - return getParent().isEmpty(); - } - - @Override - default boolean trim(boolean aggressive) { - return getParent().trim(aggressive); - } - - @Override - default void recycle() { - getParent().recycle(); - } - - @Override - default List getEntities(Region region) { - return getParent().getEntities(region); - } - - @Override - default List getEntities() { - return getParent().getEntities(); - } - - @Override - @Nullable - default Entity createEntity(Location location, BaseEntity entity) { - return getParent().createEntity(location, entity); - } - - @Override - default void removeEntity(int x, int y, int z, UUID uuid) { - getParent().removeEntity(x, y, z, uuid); - } - - @Override - default boolean isWorld() { - return getParent().isWorld(); - } - - @Override - default boolean regenerateChunk(int x, int z, @Nullable BiomeType type, @Nullable Long seed) { - return getParent().regenerateChunk(x, z, type, seed); - } - - @Override - default int getHighestTerrainBlock(int x, int z, int minY, int maxY) { - return getParent().getHighestTerrainBlock(x, z, minY, maxY); - } - - @Override - default int getHighestTerrainBlock(int x, int z, int minY, int maxY, Mask filter) { - return getParent().getHighestTerrainBlock(x, z, minY, maxY, filter); - } - - @Override - default int getNearestSurfaceLayer(int x, int z, int y, int minY, int maxY) { - return getParent().getNearestSurfaceLayer(x, z, y, minY, maxY); - } - - @Override - default int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, boolean ignoreAir) { - return getParent().getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, ignoreAir); - } - - @Override - default int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY) { - return getParent().getNearestSurfaceTerrainBlock(x, z, y, minY, maxY); - } - - @Override - default int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax) { - return getParent().getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax); - } - - @Override - default int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, Mask mask) { - return getParent().getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, mask); - } - - @Override - default int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, boolean ignoreAir) { - return getParent().getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, ignoreAir); - } - - @Override - default void addCaves(Region region) throws WorldEditException { - getParent().addCaves(region); - } - - @Override - default void generate(Region region, GenBase gen) throws WorldEditException { - getParent().generate(region, gen); - } - - @Override - default void addSchems(Region region, Mask mask, List clipboards, int rarity, boolean rotate) throws WorldEditException { - getParent().addSchems(region, mask, clipboards, rarity, rotate); - } - - @Override - default void spawnResource(Region region, Resource gen, int rarity, int frequency) throws WorldEditException { - getParent().spawnResource(region, gen, rarity, frequency); - } - - @Override - default boolean contains(BlockVector3 pt) { - return getParent().contains(pt); - } - - @Override - default void addOre(Region region, Mask mask, Pattern material, int size, int frequency, int rarity, int minY, int maxY) throws WorldEditException { - getParent().addOre(region, mask, material, size, frequency, rarity, minY, maxY); - } - - @Override - default void addOres(Region region, Mask mask) throws WorldEditException { - getParent().addOres(region, mask); - } - - @Override - default List> getBlockDistribution(Region region) { - return getParent().getBlockDistribution(region); - } - - @Override - default List> getBlockDistributionWithData(Region region) { - return getParent().getBlockDistributionWithData(region); - } - - @Override - @Nullable - default Operation commit() { - return getParent().commit(); - } - - @Override - default boolean cancel() { - return getParent().cancel(); - } - - @Override - default int getMaxY() { - return getParent().getMaxY(); - } - - @Override - default Clipboard lazyCopy(Region region) { - return getParent().lazyCopy(region); - } - - @Override - default int countBlocks(Region region, Set searchBlocks) { - return getParent().countBlocks(region, searchBlocks); - } - - @Override - default int countBlocks(Region region, Mask searchMask) { - return getParent().countBlocks(region, searchMask); - } - - @Override - default > int setBlocks(Region region, B block) throws MaxChangedBlocksException { - return getParent().setBlocks(region, block); - } - - @Override - default int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException { - return getParent().setBlocks(region, pattern); - } - - @Override - default > int replaceBlocks(Region region, Set filter, B replacement) throws MaxChangedBlocksException { - return getParent().replaceBlocks(region, filter, replacement); - } - - @Override - default int replaceBlocks(Region region, Set filter, Pattern pattern) throws MaxChangedBlocksException { - return getParent().replaceBlocks(region, filter, pattern); - } - - @Override - default int replaceBlocks(Region region, Mask mask, Pattern pattern) throws MaxChangedBlocksException { - return getParent().replaceBlocks(region, mask, pattern); - } - - @Override - default int center(Region region, Pattern pattern) throws MaxChangedBlocksException { - return getParent().center(region, pattern); - } - - @Override - default int setBlocks(Set vset, Pattern pattern) { - return getParent().setBlocks(vset, pattern); - } - - @Override - default BlockState getBlock(BlockVector3 position) { - return getParent().getBlock(position); - } - - @Override - default BaseBlock getFullBlock(BlockVector3 position) { - return getParent().getFullBlock(position); - } - - @Override - default BiomeType getBiome(BlockVector2 position) { - return getParent().getBiome(position); - } - - @Override - default BiomeType getBiomeType(int x, int y, int z) { - return getParent().getBiomeType(x, y, z); - } - - @Override - @Deprecated - default > boolean setBlock(BlockVector3 position, B block) throws WorldEditException { - return getParent().setBlock(position, block); - } - - @Override - default boolean setBiome(BlockVector2 position, BiomeType biome) { - return getParent().setBiome(position, biome); - } -} 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 8a5a2c2e5..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.IMP.WORLD_MAX_Y, 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 a3712a053..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.IMP.SECTION_BITS_TO_CHAR.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/CharSetBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharSetBlocks.java index 584928704..923162497 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharSetBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharSetBlocks.java @@ -24,7 +24,7 @@ import java.util.UUID; import java.util.stream.IntStream; public class CharSetBlocks extends CharBlocks implements IChunkSet { - private static Pool POOL = FaweCache.IMP.registerPool(CharSetBlocks.class, CharSetBlocks::new, Settings.IMP.QUEUE.POOL); + private static Pool POOL = FaweCache.INSTANCE.registerPool(CharSetBlocks.class, CharSetBlocks::new, Settings.IMP.QUEUE.POOL); public static CharSetBlocks newInstance() { return POOL.poll(); } 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 0c0ab3d44..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.IMP.SECTION_BITS_TO_CHAR.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/blocks/NullChunkGet.kt b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/NullChunkGet.kt index 77e85f715..ac154a3e7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/NullChunkGet.kt +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/NullChunkGet.kt @@ -55,7 +55,7 @@ object NullChunkGet : IChunkGet { } override fun load(layer: Int): CharArray { - return FaweCache.IMP.EMPTY_CHAR_4096 + return FaweCache.EMPTY_CHAR_4096 } override fun hasSection(layer: Int): Boolean { 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 d7b4e866b..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 @@ -29,7 +29,7 @@ import javax.annotation.Nullable; */ public class ChunkHolder> implements IQueueChunk { - private static Pool POOL = FaweCache.IMP.registerPool(ChunkHolder.class, ChunkHolder::new, Settings.IMP.QUEUE.POOL); + private static Pool POOL = FaweCache.INSTANCE.registerPool(ChunkHolder.class, ChunkHolder::new, Settings.IMP.QUEUE.POOL); public static ChunkHolder newInstance() { return POOL.poll(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/NullChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/NullChunk.java deleted file mode 100644 index cd5846a70..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/NullChunk.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.boydti.fawe.beta.implementation.chunk; - -import com.boydti.fawe.beta.Filter; -import com.boydti.fawe.beta.IChunkSet; -import com.boydti.fawe.beta.IQueueChunk; -import com.boydti.fawe.beta.implementation.filter.block.ChunkFilterBlock; -import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.world.biome.BiomeType; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockStateHolder; -import com.sk89q.worldedit.world.block.BlockTypes; -import java.util.Collections; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.Future; -import javax.annotation.Nullable; - -public enum NullChunk implements IQueueChunk { - INSTANCE; - - @Override - public int getX() { - return 0; - } - - @Override - public int getZ() { - return 0; - } - - @Override - public boolean isEmpty() { - return true; - } - - @Override - public Future call() { - return null; - } - - @Override - public void filterBlocks(Filter filter, ChunkFilterBlock block, @Nullable Region region, boolean full) { - - } - -// @Override -// public void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block) { -// -// } - - @Override - public boolean setBiome(int x, int y, int z, BiomeType biome) { - return false; - } - - @Override - public boolean setTile(int x, int y, int z, CompoundTag tag) { - return false; - } - - @Override - public void setEntity(CompoundTag tag) { - - } - - @Override - public void removeEntity(UUID uuid) { - - } - - @Override - public Set getEntityRemoves() { - return null; - } - - @Override - public BiomeType[] getBiomes() { - return null; - } - - @Override - public > boolean setBlock(int x, int y, int z, B block) { - return false; - } - - @Override - public void setBlocks(int layer, char[] data) { - - } - - @Override - public BiomeType getBiomeType(int x, int y, int z) { - return null; - } - - @Override - public boolean hasSection(int layer) { - return false; - } - - @Override - public BlockState getBlock(int x, int y, int z) { - return BlockTypes.__RESERVED__.getDefaultState(); - } - - @Override - public BaseBlock getFullBlock(int x, int y, int z) { - return BlockTypes.__RESERVED__.getDefaultState().toBaseBlock(); - } - - @Override - public Map getTiles() { - return Collections.emptyMap(); - } - - @Override - public CompoundTag getTile(int x, int y, int z) { - return null; - } - - @Override - public Set getEntities() { - return Collections.emptySet(); - } - - @Override - public char[] load(int layer) { - return null; - } - - @Override - public CompoundTag getEntity(UUID uuid) { - return null; - } - - @Override - public Future call(IChunkSet set, Runnable finalize) { - return null; - } - - @Override - public boolean trim(boolean aggressive) { - return true; - } -} - diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/NullChunk.kt b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/NullChunk.kt new file mode 100644 index 000000000..06a3d6e8c --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/NullChunk.kt @@ -0,0 +1,121 @@ +package com.boydti.fawe.beta.implementation.chunk + +import com.boydti.fawe.beta.Filter +import com.boydti.fawe.beta.IChunkSet +import com.boydti.fawe.beta.IQueueChunk +import com.boydti.fawe.beta.implementation.filter.block.ChunkFilterBlock +import com.sk89q.jnbt.CompoundTag +import com.sk89q.worldedit.math.BlockVector3 +import com.sk89q.worldedit.regions.Region +import com.sk89q.worldedit.world.biome.BiomeType +import com.sk89q.worldedit.world.block.BaseBlock +import com.sk89q.worldedit.world.block.BlockState +import com.sk89q.worldedit.world.block.BlockStateHolder +import com.sk89q.worldedit.world.block.BlockTypes +import java.util.UUID +import java.util.concurrent.Future + +object NullChunk : IQueueChunk { + + override fun getX(): Int { + return 0 + } + + override fun getZ(): Int { + return 0 + } + + override fun isEmpty(): Boolean { + return true + } + + override fun call(): Nothing? { + return null + } + + override fun filterBlocks(filter: Filter, block: ChunkFilterBlock, region: Region?, full: Boolean) { + + } + + // @Override + // public void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block) { + // + // } + + override fun setBiome(x: Int, y: Int, z: Int, biome: BiomeType): Boolean { + return false + } + + override fun setTile(x: Int, y: Int, z: Int, tag: CompoundTag): Boolean { + return false + } + + override fun setEntity(tag: CompoundTag) { + + } + + override fun removeEntity(uuid: UUID) { + + } + + override fun getEntityRemoves(): Set? { + return null + } + + override fun getBiomes(): Array? { + return null + } + + override fun > setBlock(x: Int, y: Int, z: Int, block: B): Boolean { + return false + } + + override fun setBlocks(layer: Int, data: CharArray) { + + } + + override fun getBiomeType(x: Int, y: Int, z: Int): BiomeType? { + return null + } + + override fun hasSection(layer: Int): Boolean { + return false + } + + override fun getBlock(x: Int, y: Int, z: Int): BlockState { + return BlockTypes.__RESERVED__!!.defaultState + } + + override fun getFullBlock(x: Int, y: Int, z: Int): BaseBlock { + return BlockTypes.__RESERVED__!!.defaultState.toBaseBlock() + } + + override fun getTiles(): Map { + return emptyMap() + } + + override fun getTile(x: Int, y: Int, z: Int): CompoundTag? { + return null + } + + override fun getEntities(): Set { + return emptySet() + } + + override fun load(layer: Int): CharArray? { + return null + } + + override fun getEntity(uuid: UUID): CompoundTag? { + return null + } + + override fun ?> call(set: IChunkSet?, finalize: Runnable?): T? { + return null + } + + override fun trim(aggressive: Boolean): Boolean { + return true + } +} + diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/CharFilterBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/CharFilterBlock.java index 7fa28bbfe..8c9000e50 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/CharFilterBlock.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/CharFilterBlock.java @@ -67,7 +67,7 @@ public class CharFilterBlock extends ChunkFilterBlock { this.layer = layer; final IBlocks get = (CharGetBlocks) iget; if (!get.hasSection(layer)) { - getArr = FaweCache.IMP.EMPTY_CHAR_4096; + getArr = FaweCache.INSTANCE.getEMPTY_CHAR_4096(); } else { getArr = get.load(layer); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/packet/ChunkPacket.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/packet/ChunkPacket.java index b904c5cd6..9ed925870 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/packet/ChunkPacket.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/packet/ChunkPacket.java @@ -63,7 +63,7 @@ public class ChunkPacket implements Function, Supplier { synchronized (this) { if (sectionBytes == null) { IBlocks tmpChunk = getChunk(); - byte[] buf = FaweCache.IMP.BYTE_BUFFER_8192.get(); + byte[] buf = FaweCache.INSTANCE.getBYTE_BUFFER_8192().get(); sectionBytes = tmpChunk.toByteArray(buf, tmpChunk.getBitMask(), this.full); } tmp = sectionBytes; @@ -83,13 +83,13 @@ public class ChunkPacket implements Function, Supplier { @Override @Deprecated public byte[] get() { - return apply(FaweCache.IMP.BYTE_BUFFER_8192.get()); + return apply(FaweCache.INSTANCE.getBYTE_BUFFER_8192().get()); } public CompoundTag getHeightMap() { HashMap map = new HashMap<>(); map.put("MOTION_BLOCKING", new long[36]); - CompoundTag tag = FaweCache.IMP.asTag(map); + CompoundTag tag = FaweCache.INSTANCE.asTag(map); // TODO return tag; } 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 1c59fc96d..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 @@ -119,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.IMP.WORLD_HEIGHT); + limit.THROW_MAX_CHECKS(FaweCache.WORLD_HEIGHT); try { return getExtent().getHighestTerrainBlock(x, z, minY, maxY); } catch (FaweException e) { @@ -132,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.IMP.WORLD_HEIGHT); + limit.THROW_MAX_CHECKS(FaweCache.WORLD_HEIGHT); try { return getExtent().getHighestTerrainBlock(x, z, minY, maxY, filter); } catch (FaweException e) { @@ -145,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.IMP.WORLD_HEIGHT); + limit.THROW_MAX_CHECKS(FaweCache.WORLD_HEIGHT); try { return getExtent().getNearestSurfaceLayer(x, z, y, minY, maxY); } catch (FaweException e) { @@ -158,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.IMP.WORLD_HEIGHT); + limit.THROW_MAX_CHECKS(FaweCache.WORLD_HEIGHT); try { return getExtent().getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, ignoreAir); } catch (FaweException e) { @@ -171,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.IMP.WORLD_HEIGHT); + limit.THROW_MAX_CHECKS(FaweCache.WORLD_HEIGHT); try { return getExtent().getNearestSurfaceTerrainBlock(x, z, y, minY, maxY); } catch (FaweException e) { @@ -184,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.IMP.WORLD_HEIGHT); + limit.THROW_MAX_CHECKS(FaweCache.WORLD_HEIGHT); try { return getExtent().getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax); } catch (FaweException e) { @@ -197,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.IMP.WORLD_HEIGHT); + limit.THROW_MAX_CHECKS(FaweCache.WORLD_HEIGHT); try { return getExtent().getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, mask); } catch (FaweException e) { @@ -210,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.IMP.WORLD_HEIGHT); + 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 07c022d0d..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 @@ -9,11 +9,9 @@ import com.boydti.fawe.beta.implementation.filter.CountFilter; import com.boydti.fawe.beta.implementation.filter.DistrFilter; import com.boydti.fawe.beta.implementation.processors.BatchProcessorHolder; import com.boydti.fawe.config.Settings; -import com.boydti.fawe.object.changeset.AbstractChangeSet; import com.boydti.fawe.object.clipboard.WorldCopyClipboard; import com.boydti.fawe.object.extent.NullExtent; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.PassthroughExtent; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.mask.BlockMask; @@ -60,7 +58,7 @@ public class ParallelQueueExtent extends PassthroughExtent implements IQueueWrap @Override public boolean cancel() { if (super.cancel()) { - processor.setProcessor(new NullExtent(this, FaweCache.MANUAL)); + processor.setProcessor(new NullExtent(this, FaweCache.INSTANCE.getMANUAL())); return true; } return false; @@ -77,11 +75,6 @@ public class ParallelQueueExtent extends PassthroughExtent implements IQueueWrap return queue; } - @Override - public Extent enableHistory(AbstractChangeSet changeSet) { - return super.enableHistory(changeSet); - } - @Override public T apply(Region region, T filter, boolean full) { // The chunks positions to iterate over @@ -187,10 +180,6 @@ public class ParallelQueueExtent extends PassthroughExtent implements IQueueWrap return apply(region, new DistrFilter(), false).getTypeDistribution(); } - /** - * To optimize - */ - /** * Lazily copy a region * @@ -199,7 +188,7 @@ public class ParallelQueueExtent extends PassthroughExtent implements IQueueWrap */ @Override public Clipboard lazyCopy(Region region) { - WorldCopyClipboard clipboard = new WorldCopyClipboard(() -> this, region); + Clipboard clipboard = new WorldCopyClipboard(() -> this, region); clipboard.setOrigin(region.getMinimumPoint()); return clipboard; } @@ -213,7 +202,7 @@ public class ParallelQueueExtent extends PassthroughExtent implements IQueueWrap */ @Override public int countBlocks(Region region, Set searchBlocks) { - BlockMask mask = new BlockMask(this, searchBlocks); + Mask mask = new BlockMask(this, searchBlocks); return countBlocks(region, mask); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/QueueHandler.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/QueueHandler.java index 343d4b484..03dd8424d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/QueueHandler.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/QueueHandler.java @@ -40,7 +40,7 @@ public abstract class QueueHandler implements Trimable, Runnable { private ForkJoinPool forkJoinPoolPrimary = new ForkJoinPool(); private ForkJoinPool forkJoinPoolSecondary = new ForkJoinPool(); - private ThreadPoolExecutor blockingExecutor = FaweCache.IMP.newBlockingExecutor(); + private ThreadPoolExecutor blockingExecutor = FaweCache.INSTANCE.newBlockingExecutor(); private ConcurrentLinkedQueue syncTasks = new ConcurrentLinkedQueue<>(); private ConcurrentLinkedQueue syncWhenFree = new ConcurrentLinkedQueue<>(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/SingleThreadQueueExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/SingleThreadQueueExtent.java index acf2357ee..79e690de6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/SingleThreadQueueExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/SingleThreadQueueExtent.java @@ -209,7 +209,6 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen lastChunk = NullChunk.INSTANCE; return NullChunk.INSTANCE; } - IQueueChunk chunk = chunks.get(pair); if (chunk instanceof ReferenceChunk) { chunk = ((ReferenceChunk) chunk).getParent(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/command/AnvilCommands.java b/worldedit-core/src/main/java/com/boydti/fawe/command/AnvilCommands.java index 295ff09be..381da4689 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/command/AnvilCommands.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/command/AnvilCommands.java @@ -475,7 +475,7 @@ public class AnvilCommands { // }); // if (useData) { // for (long[] c : map) { -// BaseBlock block = FaweCache.IMP.CACHE_BLOCK[(int) c[0]]; +// BaseBlock block = FaweCache.INSTANCE.CACHE_BLOCK[(int) c[0]]; // String name = BlockType.fromID(block.getId()).getName(); // String str = String.format("%-7s (%.3f%%) %s #%d:%d", // String.valueOf(c[1]), 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 16cc9f06d..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 @@ -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.IMP.SECTION_BITS_TO_CHAR.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++) { @@ -152,20 +152,20 @@ public class MCAChunk implements IChunk { StreamDelegate blockStates = layer.add("BlockStates"); blockStates.withInfo((length, type) -> { if (section.blocks == null) { - section.blocks = FaweCache.IMP.LONG_BUFFER_1024.get(); + section.blocks = FaweCache.INSTANCE.getLONG_BUFFER_1024().get(); } section.blocksLength = length; }); blockStates.withLong((index, value) -> section.blocks[index] = value); level.add("TileEntities").withElem((ValueReader>) (index, value) -> { - CompoundTag tile = FaweCache.IMP.asTag(value); + CompoundTag tile = FaweCache.INSTANCE.asTag(value); int x = tile.getInt("x") & 15; int y = tile.getInt("y"); int z = tile.getInt("z") & 15; tiles.put(x, y, z, tile); }); level.add("Entities").withElem((ValueReader>) (index, value) -> { - CompoundTag entity = FaweCache.IMP.asTag(value); + CompoundTag entity = FaweCache.INSTANCE.asTag(value); entities.put(entity.getUUID(), entity); }); level.add("Biomes").withInt((index, value) -> biomes[index] = BiomeTypes.getLegacy(value)); @@ -218,10 +218,10 @@ public class MCAChunk implements IChunk { } public void write(NBTOutputStream nbtOut) throws IOException { - int[] blockToPalette = FaweCache.IMP.BLOCK_TO_PALETTE.get(); - int[] paletteToBlock = FaweCache.IMP.PALETTE_TO_BLOCK.get(); - long[] blockstates = FaweCache.IMP.BLOCK_STATES.get(); - int[] blocksCopy = FaweCache.IMP.SECTION_BLOCKS.get(); + int[] blockToPalette = FaweCache.INSTANCE.getBLOCK_TO_PALETTE().get(); + int[] paletteToBlock = FaweCache.INSTANCE.getPALETTE_TO_BLOCK().get(); + long[] blockstates = FaweCache.INSTANCE.getBLOCK_STATES().get(); + int[] blocksCopy = FaweCache.INSTANCE.getSECTION_BLOCKS().get(); nbtOut.writeNamedTagName("", NBTConstants.TYPE_COMPOUND); nbtOut.writeNamedTag("DataVersion", 1631); @@ -524,7 +524,7 @@ public class MCAChunk implements IChunk { @Override public char[] load(int layer) { - char[] tmp = FaweCache.IMP.SECTION_BITS_TO_CHAR.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 f8ceb5f10..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.IMP.WORLD_MAX_Y, (this.Z << 9) + 511); + return BlockVector3.at((this.X << 9) + 511, FaweCache.WORLD_MAX_Y, (this.Z << 9) + 511); } @Override @@ -361,7 +361,7 @@ public class MCAFile extends ExtentBatchProcessorHolder implements Trimable, ICh raf.seek(offset); int size = raf.readInt(); int compression = raf.read(); - byte[] data = FaweCache.IMP.BYTE_BUFFER_VAR.get(size); + byte[] data = FaweCache.INSTANCE.getBYTE_BUFFER_VAR().get(size); raf.readFully(data, 0, size); FastByteArrayInputStream result = new FastByteArrayInputStream(data, 0, size); return result; @@ -379,7 +379,7 @@ public class MCAFile extends ExtentBatchProcessorHolder implements Trimable, ICh private NBTInputStream getChunkIS(InputStream is) throws IllegalAccessException { InflaterInputStream iis = new InflaterInputStream(is, new Inflater(), 1); - fieldBuf2.set(iis, FaweCache.IMP.BYTE_BUFFER_8192.get()); + fieldBuf2.set(iis, FaweCache.INSTANCE.getBYTE_BUFFER_8192().get()); BufferedInputStream bis = new BufferedInputStream(iis); NBTInputStream nis = new NBTInputStream(bis); return nis; @@ -414,13 +414,13 @@ public class MCAFile extends ExtentBatchProcessorHolder implements Trimable, ICh if (chunk.isDeleted()) { return null; } - byte[] writeBuffer = FaweCache.IMP.BYTE_BUFFER_VAR.get(4096); + byte[] writeBuffer = FaweCache.INSTANCE.getBYTE_BUFFER_VAR().get(4096); FastByteArrayOutputStream uncompressed = chunk.toBytes(writeBuffer); if (uncompressed.array.length > writeBuffer.length) { - FaweCache.IMP.BYTE_BUFFER_VAR.set(uncompressed.array); + FaweCache.INSTANCE.getBYTE_BUFFER_VAR().set(uncompressed.array); } writeBuffer = uncompressed.array; - byte[] buffer = FaweCache.IMP.BYTE_BUFFER_8192.get(); + byte[] buffer = FaweCache.INSTANCE.getBYTE_BUFFER_8192().get(); int length = uncompressed.length; uncompressed.reset(); // cheat, reusing the same buffer to read/write diff --git a/worldedit-core/src/main/java/com/boydti/fawe/logging/LoggingChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/logging/LoggingChangeSet.java index bbd71dae8..7ab8746ec 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/logging/LoggingChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/logging/LoggingChangeSet.java @@ -55,10 +55,10 @@ public class LoggingChangeSet extends AbstractDelegateChangeSet { // loc.x = x; // loc.y = y; // loc.z = z; -// oldBlock.id = FaweCache.IMP.getId(combinedId4DataFrom); -// oldBlock.data = FaweCache.IMP.getData(combinedId4DataFrom); -// newBlock.id = FaweCache.IMP.getId(combinedId4DataTo); -// newBlock.data = FaweCache.IMP.getData(combinedId4DataTo); +// oldBlock.id = FaweCache.INSTANCE.getId(combinedId4DataFrom); +// oldBlock.data = FaweCache.INSTANCE.getData(combinedId4DataFrom); +// newBlock.id = FaweCache.INSTANCE.getId(combinedId4DataTo); +// newBlock.data = FaweCache.INSTANCE.getData(combinedId4DataTo); // // Log to BlocksHub and parent // api.logBlock(loc, player, world, oldBlock, newBlock); parent.add(x, y, z, combinedId4DataFrom, combinedId4DataTo); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/DataAnglePattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/DataAnglePattern.java index 84a156c37..cb927b5ac 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/DataAnglePattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/DataAnglePattern.java @@ -48,10 +48,10 @@ public class DataAnglePattern extends AbstractPattern { @Override public boolean apply(Extent extent, BlockVector3 setPosition, BlockVector3 getPosition) throws WorldEditException { - BlockStateHolder block = extent.getBlock(getPosition); + BlockState block = extent.getBlock(getPosition); int slope = getSlope(block, getPosition, extent); if (slope == -1) return false; - int data = (Math.min(slope, 255)) >> 4; + int data = Math.min(slope, 255) >> 4; return extent.setBlock(setPosition, block.withPropertyId(data)); } } 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 87d2f84a0..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.MAX_CHANGES; + if (MAX_CHANGES-- <= 0) throw FaweCache.INSTANCE.getMAX_CHANGES(); } public void THROW_MAX_FAILS() { - if (MAX_FAILS-- <= 0) throw FaweCache.MAX_CHECKS; + if (MAX_FAILS-- <= 0) throw FaweCache.INSTANCE.getMAX_CHECKS(); } public void THROW_MAX_CHECKS() { - if (MAX_CHECKS-- <= 0) throw FaweCache.MAX_CHECKS; + if (MAX_CHECKS-- <= 0) throw FaweCache.INSTANCE.getMAX_CHECKS(); } public void THROW_MAX_ITERATIONS() { - if (MAX_ITERATIONS-- <= 0) throw FaweCache.MAX_ITERATIONS; + if (MAX_ITERATIONS-- <= 0) throw FaweCache.INSTANCE.getMAX_ITERATIONS(); } public void THROW_MAX_BLOCKSTATES() { - if (MAX_BLOCKSTATES-- <= 0) throw FaweCache.MAX_TILES; + if (MAX_BLOCKSTATES-- <= 0) throw FaweCache.INSTANCE.getMAX_TILES(); } public void THROW_MAX_ENTITIES() { - if (MAX_ENTITIES-- <= 0) throw FaweCache.MAX_ENTITIES; + if (MAX_ENTITIES-- <= 0) throw FaweCache.INSTANCE.getMAX_ENTITIES(); } public void THROW_MAX_CHANGES(int amt) { - if ((MAX_CHANGES -= amt) <= 0) throw FaweCache.MAX_CHANGES; + if ((MAX_CHANGES -= amt) <= 0) throw FaweCache.INSTANCE.getMAX_CHANGES(); } public void THROW_MAX_FAILS(int amt) { - if ((MAX_FAILS -= amt) <= 0) throw FaweCache.MAX_CHECKS; + if ((MAX_FAILS -= amt) <= 0) throw FaweCache.INSTANCE.getMAX_CHECKS(); } public void THROW_MAX_CHECKS(int amt) { - if ((MAX_CHECKS -= amt) <= 0) throw FaweCache.MAX_CHECKS; + if ((MAX_CHECKS -= amt) <= 0) throw FaweCache.INSTANCE.getMAX_CHECKS(); } public void THROW_MAX_ITERATIONS(int amt) { - if ((MAX_ITERATIONS -= amt) <= 0) throw FaweCache.MAX_ITERATIONS; + if ((MAX_ITERATIONS -= amt) <= 0) throw FaweCache.INSTANCE.getMAX_ITERATIONS(); } public void THROW_MAX_BLOCKSTATES(int amt) { - if ((MAX_BLOCKSTATES -= amt) <= 0) throw FaweCache.MAX_TILES; + if ((MAX_BLOCKSTATES -= amt) <= 0) throw FaweCache.INSTANCE.getMAX_TILES(); } public void THROW_MAX_ENTITIES(int amt) { - if ((MAX_ENTITIES -= amt) <= 0) throw FaweCache.MAX_ENTITIES; + if ((MAX_ENTITIES -= amt) <= 0) throw FaweCache.INSTANCE.getMAX_ENTITIES(); } public boolean isUnlimited() { @@ -193,7 +193,7 @@ public class FaweLimit { MAX_HISTORY == Integer.MAX_VALUE && INVENTORY_MODE == 0 && SPEED_REDUCTION == 0 && - FAST_PLACEMENT == true && + FAST_PLACEMENT && (STRIP_NBT == null || STRIP_NBT.isEmpty()); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ImageBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ImageBrush.java index a2f08e1fc..c6d103f23 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ImageBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ImageBrush.java @@ -18,6 +18,7 @@ import com.sk89q.worldedit.math.MutableVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; @@ -51,7 +52,7 @@ public class ImageBrush implements Brush { case 255: return color; default: - BlockStateHolder block = extent.getBlock(pos); + BlockState block = extent.getBlock(pos); TextureUtil tu = session.getTextureUtil(); int existingColor = tu.getColor(block.getBlockType()); return tu.combineTransparency(color, existingColor); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java index df9ff4b56..9ee24a339 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java @@ -75,7 +75,7 @@ public class LayerBrush implements Brush { } }, pos -> { int depth = visitor.getDepth(); - BlockStateHolder currentPattern = layers[depth]; + BlockState currentPattern = layers[depth]; return currentPattern.apply(editSession, pos, pos); }, layers.length - 1); for (BlockVector3 pos : visited) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RecurseBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RecurseBrush.java index 7e0ee0ee1..e15ee9d7e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RecurseBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RecurseBrush.java @@ -13,6 +13,7 @@ import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.visitor.RecursiveVisitor; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; public class RecurseBrush implements Brush { @@ -32,7 +33,7 @@ public class RecurseBrush implements Brush { mask = mask.withExtent(editSession); } final int radius = (int) size; - BlockStateHolder block = editSession.getBlock(position); + BlockState block = editSession.getBlock(position); if (block.getBlockType().getMaterial().isAir()) { return; } 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 938344f27..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 @@ -63,7 +63,7 @@ public class SplineBrush implements Brush, ResettableTool { this.position = position; if (newPos) { if (positionSets.size() >= MAX_POINTS) { - throw FaweCache.MAX_CHECKS; + 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/visualization/cfi/HeightMapMCAGenerator.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java index 460ce7402..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 @@ -1563,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.IMP.INDEX_STORE.get(); + int[] indexes = FaweCache.INSTANCE.getINDEX_STORE().get(); int index; int maxY = 0; int minY = Integer.MAX_VALUE; - int[] heightMap = FaweCache.IMP.HEIGHT_STORE.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/changeset/AbstractChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractChangeSet.java index d2ce6f254..8fb85e0da 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractChangeSet.java @@ -171,7 +171,7 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor, C // add each block and tile char[] blocksGet = get.load(layer); if (blocksGet == null) { - blocksGet = FaweCache.IMP.EMPTY_CHAR_4096; + blocksGet = FaweCache.INSTANCE.getEMPTY_CHAR_4096(); } char[] blocksSet = set.load(layer); 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 f92ad4fb9..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.BLOCK_BAG; + throw FaweCache.INSTANCE.getBLOCK_BAG(); } catch (BlockBagException e) { missingBlocks[typeTo.getInternalId()]++; - throw FaweCache.BLOCK_BAG; + throw FaweCache.INSTANCE.getBLOCK_BAG(); } } if (mine) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/ClipboardRemapper.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/ClipboardRemapper.java index e2c00c8e5..f506554d8 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/ClipboardRemapper.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/ClipboardRemapper.java @@ -223,7 +223,7 @@ public class ClipboardRemapper { // String name = entry.getKey(); // int id = value.get("id").getAsInt(); // int data = value.get("data").getAsInt(); -// int combined = FaweCache.IMP.getCombined(id, data); +// int combined = FaweCache.INSTANCE.getCombined(id, data); // map.putIfAbsent(name, new ArrayList<>()); // map.get(name).add(combined); // } @@ -496,7 +496,7 @@ public class ClipboardRemapper { // int combined = block.getCombined(); // if (remap[combined]) { // char value = remapCombined[combined]; -// BaseBlock newBlock = FaweCache.IMP.CACHE_BLOCK[value]; +// BaseBlock newBlock = FaweCache.INSTANCE.CACHE_BLOCK[value]; // newBlock.setNbtData(block.getNbtData()); // return newBlock; // } 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 332643e57..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 @@ -20,7 +20,7 @@ import org.jetbrains.annotations.NotNull; */ public final class MemBlockSet extends BlockSet { public final static int BITS_PER_WORD = 6; - public final static int WORDS = FaweCache.IMP.BLOCKS_PER_LAYER >> BITS_PER_WORD; + public final static int WORDS = FaweCache.BLOCKS_PER_LAYER >> BITS_PER_WORD; public final static IRow NULL_ROW_X = new NullRowX(); public final static IRow NULL_ROW_Z = new NullRowZ(); public final static IRow NULL_ROW_Y = new NullRowY(); @@ -357,8 +357,8 @@ public final class MemBlockSet extends BlockSet { maxy = y + 1; } by = (Y << 4) + y; - if (by == FaweCache.IMP.WORLD_MAX_Y) - return FaweCache.IMP.WORLD_MAX_Y; + if (by == FaweCache.WORLD_MAX_Y) + return FaweCache.WORLD_MAX_Y; break outer; } } @@ -827,7 +827,7 @@ public final class MemBlockSet extends BlockSet { public final IRow[] rows; public RowZ() { - this.rows = new IRow[FaweCache.IMP.CHUNK_LAYERS]; + this.rows = new IRow[FaweCache.CHUNK_LAYERS]; reset(); } @@ -874,7 +874,7 @@ public final class MemBlockSet extends BlockSet { } public void reset() { - for (int i = 0; i < FaweCache.IMP.CHUNK_LAYERS; 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/extent/FaweRegionExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java index f67b3b3e9..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.OUTSIDE_REGION); + 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.OUTSIDE_REGION); + 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.OUTSIDE_REGION); + 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.OUTSIDE_REGION); + 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.OUTSIDE_REGION); + 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.OUTSIDE_REGION); + 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.OUTSIDE_REGION); + 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.OUTSIDE_REGION); + 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.OUTSIDE_REGION); + 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.OUTSIDE_REGION); + 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.OUTSIDE_REGION); + 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.OUTSIDE_REGION); + 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 d5c309a1c..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.LOW_MEMORY); + 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 e796c2b20..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.MANUAL); + 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 948bd3fd1..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 @@ -38,7 +38,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { return null; } if (!limit.MAX_ENTITIES()) { - WEManager.IMP.cancelEditSafe(this, FaweCache.MAX_ENTITIES); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getMAX_ENTITIES()); return null; } return super.createEntity(location, entity); @@ -47,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.MAX_CHECKS); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getMAX_CHECKS()); return BlockTypes.AIR.getDefaultState(); } else { return extent.getBlock(x, y, z); @@ -57,7 +57,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { @Override public BaseBlock getFullBlock(BlockVector3 pos) { if (!limit.MAX_CHECKS()) { - WEManager.IMP.cancelEditSafe(this, FaweCache.MAX_CHECKS); + WEManager.IMP.cancelEditSafe(this, FaweCache.INSTANCE.getMAX_CHECKS()); return BlockTypes.AIR.getDefaultState().toBaseBlock(); } else { return extent.getFullBlock(pos); @@ -79,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.MAX_TILES); + WEManager.IMP.cancelEdit(this, FaweCache.INSTANCE.getMAX_TILES()); return false; } else { if (!limit.MAX_CHANGES()) { - WEManager.IMP.cancelEdit(this, FaweCache.MAX_CHANGES); + 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.MAX_CHANGES); + WEManager.IMP.cancelEdit(this, FaweCache.INSTANCE.getMAX_CHANGES()); return false; } else { return extent.setBlock(x, y, z, block); @@ -100,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.MAX_CHANGES); + 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/mask/FaweBlockMatcher.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/FaweBlockMatcher.java index 84f3e7aca..45bd489df 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/FaweBlockMatcher.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/FaweBlockMatcher.java @@ -31,10 +31,10 @@ public abstract class FaweBlockMatcher { // public boolean apply(BaseBlock oldBlock) { // int currentId = oldBlock.getId(); // oldBlock.setId(id); -// if (FaweCache.IMP.hasData(currentId)) { +// if (FaweCache.INSTANCE.hasData(currentId)) { // oldBlock.setData(0); // } -// if (FaweCache.IMP.hasNBT(currentId)) { +// if (FaweCache.INSTANCE.hasNBT(currentId)) { // oldBlock.setNbtData(null); // } // return true; @@ -47,7 +47,7 @@ public abstract class FaweBlockMatcher { // int currentId = oldBlock.getId(); // oldBlock.setId(id); // oldBlock.setData(data); -// if (FaweCache.IMP.hasNBT(currentId)) { +// if (FaweCache.INSTANCE.hasNBT(currentId)) { // oldBlock.setNbtData(null); // } // return true; @@ -67,10 +67,10 @@ public abstract class FaweBlockMatcher { // BaseBlock replace = array[random.random(size)]; // int currentId = block.getId(); // block.setId(replace.getId()); -// if (FaweCache.IMP.hasNBT(currentId)) { +// if (FaweCache.INSTANCE.hasNBT(currentId)) { // block.setNbtData(null); // } -// if (FaweCache.IMP.hasData(currentId) || replace.getData() != 0) { +// if (FaweCache.INSTANCE.hasData(currentId) || replace.getData() != 0) { // block.setData(replace.getData()); // } // return true; @@ -82,7 +82,7 @@ public abstract class FaweBlockMatcher { public static FaweBlockMatcher fromBlock(BaseBlock block, boolean checkData) { // final int id = block.getId(); // final int data = block.getData(); -// if (checkData && FaweCache.IMP.hasData(id)) { +// if (checkData && FaweCache.INSTANCE.hasData(id)) { // return new FaweBlockMatcher() { // @Override // public boolean apply(BaseBlock block) { @@ -104,13 +104,13 @@ public abstract class FaweBlockMatcher { // if (searchBlocks.size() == 1) { // return fromBlock(searchBlocks.iterator().next(), checkData); // } -// final boolean[] allowedId = new boolean[FaweCache.IMP.getId(Character.MAX_VALUE)]; +// final boolean[] allowedId = new boolean[FaweCache.INSTANCE.getId(Character.MAX_VALUE)]; // for (BaseBlock block : searchBlocks) { // allowedId[block.getId()] = true; // } // final boolean[] allowed = new boolean[Character.MAX_VALUE]; // for (BaseBlock block : searchBlocks) { -// allowed[FaweCache.IMP.getCombined(block)] = true; +// allowed[FaweCache.INSTANCE.getCombined(block)] = true; // } // if (checkData) { // return new FaweBlockMatcher() { @@ -118,7 +118,7 @@ public abstract class FaweBlockMatcher { // public boolean apply(BaseBlock block) { // int id = block.getId(); // if (allowedId[id]) { -// if (FaweCache.IMP.hasData(id)) { +// if (FaweCache.INSTANCE.hasData(id)) { // return allowed[(id << 4) + block.getData()]; // } // return true; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/MinecraftStructure.java b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/MinecraftStructure.java index ef83c1285..7b8ce41fd 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/MinecraftStructure.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/MinecraftStructure.java @@ -162,7 +162,7 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter { if (width > WARN_SIZE || height > WARN_SIZE || length > WARN_SIZE) { getLogger(MinecraftStructure.class).debug("A structure longer than 32 is unsupported by minecraft (but probably still works)"); } - Map structure = FaweCache.IMP.asMap("version", 1, "author", owner); + Map structure = FaweCache.INSTANCE.asMap("version", 1, "author", owner); // ignored: version / owner MutableBlockVector3 mutable = new MutableBlockVector3(0, 0, 0); Int2ObjectArrayMap indexes = new Int2ObjectArrayMap<>(); @@ -212,10 +212,10 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter { List pos = Arrays.asList(point.getX() - min.getX(), point.getY() - min.getY(), point.getZ() - min.getZ()); if (!block.hasNbtData()) { - blocks.add(FaweCache.IMP.asMap("state", index, "pos", pos)); + blocks.add(FaweCache.INSTANCE.asMap("state", index, "pos", pos)); } else { blocks.add( - FaweCache.IMP.asMap("state", index, "pos", pos, "nbt", block.getNbtData())); + FaweCache.INSTANCE.asMap("state", index, "pos", pos, "nbt", block.getNbtData())); } } } @@ -235,14 +235,14 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter { // Replace rotation data nbtMap.put("Rotation", writeRotation(entity.getLocation())); nbtMap.put("id", new StringTag(state.getType().getId())); - Map entityMap = FaweCache.IMP.asMap("pos", pos, "blockPos", blockPos, "nbt", nbt); + Map entityMap = FaweCache.INSTANCE.asMap("pos", pos, "blockPos", blockPos, "nbt", nbt); entities.add(entityMap); } } if (!entities.isEmpty()) { structure.put("entities", entities); } - out.writeNamedTag("", FaweCache.IMP.asTag(structure)); + out.writeNamedTag("", FaweCache.INSTANCE.asTag(structure)); close(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/integrations/plotquared/FaweLocalBlockQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/regions/general/integrations/plotquared/FaweLocalBlockQueue.java index ed10b172d..8047612f7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/integrations/plotquared/FaweLocalBlockQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/regions/general/integrations/plotquared/FaweLocalBlockQueue.java @@ -124,7 +124,7 @@ public class FaweLocalBlockQueue extends LocalBlockQueue { @Override public boolean setTile(int x, int y, int z, CompoundTag tag) { - IMP.setTile(x, y, z, (com.sk89q.jnbt.CompoundTag) FaweCache.IMP.asTag(tag)); + IMP.setTile(x, y, z, (com.sk89q.jnbt.CompoundTag) FaweCache.INSTANCE.asTag(tag)); return true; } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/integrations/plotquared/FaweSchematicHandler.java b/worldedit-core/src/main/java/com/boydti/fawe/regions/general/integrations/plotquared/FaweSchematicHandler.java index 3a3eec8ff..553a0b891 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/integrations/plotquared/FaweSchematicHandler.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/regions/general/integrations/plotquared/FaweSchematicHandler.java @@ -108,7 +108,7 @@ public class FaweSchematicHandler extends SchematicHandler { com.github.intellectualsites.plotsquared.plot.util.TaskManager.runTask(whenDone); return; } - CompoundTag weTag = (CompoundTag) FaweCache.IMP.asTag(tag); + CompoundTag weTag = (CompoundTag) FaweCache.INSTANCE.asTag(tag); if (weTag instanceof CompressedSchematicTag) { Clipboard clipboard = ((CompressedSchematicTag) weTag).getSource(); URL url = FaweAPI.upload(clipboard, BuiltInClipboardFormat.SPONGE_SCHEMATIC); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/BrushCache.java b/worldedit-core/src/main/java/com/boydti/fawe/util/BrushCache.java index 8964a5ebe..db36de331 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/BrushCache.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/BrushCache.java @@ -92,7 +92,7 @@ public final class BrushCache { } else { displayMap = ReflectionUtils.getMap(display.getValue()); } - displayMap.put("Lore", FaweCache.IMP.asTag(json.split("\\r?\\n"))); + displayMap.put("Lore", FaweCache.INSTANCE.asTag(json.split("\\r?\\n"))); String primary = (String) tool.getPrimary().getSettings().get(BrushSettings.SettingType.BRUSH); String secondary = (String) tool.getSecondary().getSettings().get(BrushSettings.SettingType.BRUSH); if (primary == null) primary = secondary; 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 cc29e7479..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.MANUAL); + 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.MANUAL); + 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.LOW_MEMORY; + 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.NO_REGION); + 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/web/SchemSync.java b/worldedit-core/src/main/java/com/boydti/fawe/web/SchemSync.java index b721ee2b3..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.MANUAL; + throw FaweCache.INSTANCE.getMANUAL(); } @Override 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 a42f03181..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.OUTSIDE_REGION; + 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 6c747999d..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.MAX_CHECKS; + 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.MAX_CHECKS; + throw FaweCache.INSTANCE.getMAX_CHECKS(); } if (volume >= limit.MAX_CHANGES) { - throw FaweCache.MAX_CHANGES; + 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 04bcea5b7..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.MAX_CHECKS; + throw FaweCache.INSTANCE.getMAX_CHECKS(); } int affected = 0; try { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/DefaultMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/DefaultMaskParser.java index d9b52fafa..411c1aa28 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/DefaultMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/DefaultMaskParser.java @@ -34,6 +34,7 @@ import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.MaskIntersection; import com.sk89q.worldedit.function.mask.MaskUnion; import com.sk89q.worldedit.session.request.Request; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -167,7 +168,7 @@ public class DefaultMaskParser extends FaweParser { if (mask == null) { context.setPreferringWildcard(false); context.setRestricted(false); - BlockStateHolder block = worldEdit.getBlockFactory().parseFromInput(full, context); + BaseBlock block = worldEdit.getBlockFactory().parseFromInput(full, context); builder.add(block); mask = builder.build(extent); } 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 423df21b0..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.MANUAL); + NullExtent nullExtent = new NullExtent(this, FaweCache.INSTANCE.getMANUAL()); ExtentTraverser next = traverser.next(); if (next != null) { @@ -523,7 +523,7 @@ public interface Extent extends InputExtent, OutputExtent { default > int setBlocks(Region region, B block) throws MaxChangedBlocksException { checkNotNull(region); checkNotNull(block); - boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData(); + boolean hasNbt = block instanceof BaseBlock && block.hasNbtData(); int changes = 0; for (BlockVector3 pos : region) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java index 7aea7c97a..7daad2b45 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java @@ -51,7 +51,7 @@ import java.util.concurrent.ConcurrentHashMap; public class MaskingExtent extends AbstractDelegateExtent implements IBatchProcessor, Filter { private Mask mask; - private LoadingCache threadIdToFilter = FaweCache.IMP.createCache(() -> new CharFilterBlock(getExtent())); + private LoadingCache threadIdToFilter = FaweCache.INSTANCE.createCache(() -> new CharFilterBlock(getExtent())); /** * Create a new instance. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/FastSchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/FastSchematicReader.java index a2215234e..c824da795 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/FastSchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/FastSchematicReader.java @@ -268,7 +268,7 @@ public class FastSchematicReader extends NBTSchematicReader { // tiles if (tiles != null && !tiles.isEmpty()) { for (Map tileRaw : tiles) { - CompoundTag tile = FaweCache.IMP.asTag(tileRaw); + CompoundTag tile = FaweCache.INSTANCE.asTag(tileRaw); int[] pos = tile.getIntArray("Pos"); int x,y,z; @@ -303,7 +303,7 @@ public class FastSchematicReader extends NBTSchematicReader { // entities if (entities != null && !entities.isEmpty()) { for (Map entRaw : entities) { - CompoundTag ent = FaweCache.IMP.asTag(entRaw); + CompoundTag ent = FaweCache.INSTANCE.asTag(entRaw); Map value = ent.getValue(); StringTag id = (StringTag) value.get("Id"); @@ -340,4 +340,4 @@ public class FastSchematicReader extends NBTSchematicReader { public void close() throws IOException { inputStream.close(); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java index 6625aad43..36918bee9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java @@ -322,7 +322,7 @@ public class SchematicReader implements ClipboardReader { if (tiles != null && !tiles.isEmpty()) { outer: for (Map tileRaw : tiles) { - CompoundTag tile = FaweCache.IMP.asTag(tileRaw); + CompoundTag tile = FaweCache.INSTANCE.asTag(tileRaw); int x = (int) tileRaw.get("x"); int y = (int) tileRaw.get("y"); int z = (int) tileRaw.get("z"); @@ -350,7 +350,7 @@ public class SchematicReader implements ClipboardReader { entRaw.put("Id", id); EntityType type = EntityTypes.parse(id); if (type != null) { - CompoundTag ent = FaweCache.IMP.asTag(entRaw); + CompoundTag ent = FaweCache.INSTANCE.asTag(entRaw); for (EntityNBTCompatibilityHandler compat : ENTITY_COMPATIBILITY_HANDLERS) { if (compat.isAffectedEntity(type, ent)) { ent = compat.updateNBT(type, ent); 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 c2187ff1b..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 @@ -107,10 +107,10 @@ public class BlockBagExtent extends AbstractDelegateExtent { try { blockBag.fetchPlacedBlock(block.toImmutableState()); } catch (UnplaceableBlockException e) { - throw FaweCache.BLOCK_BAG; + throw FaweCache.INSTANCE.getBLOCK_BAG(); } catch (BlockBagException e) { missingBlocks[block.getBlockType().getInternalId()]++; - throw FaweCache.BLOCK_BAG; + throw FaweCache.INSTANCE.getBLOCK_BAG(); } } if (mine) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/CavesGen.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/CavesGen.java index 3f004bae4..6db6bf816 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/CavesGen.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/CavesGen.java @@ -5,6 +5,7 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.world.block.BlockID; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -145,11 +146,11 @@ public class CavesGen extends GenBase { // Search for water boolean waterFound = false; - for (int local_x = m; (!waterFound) && (local_x < n); local_x++) { - for (int local_z = i3; (!waterFound) && (local_z < i4); local_z++) { - for (int local_y = i2 + 1; (!waterFound) && (local_y >= i1 - 1); local_y--) { + for (int local_x = m; !waterFound && (local_x < n); local_x++) { + for (int local_z = i3; !waterFound && (local_z < i4); local_z++) { + for (int local_y = i2 + 1; !waterFound && (local_y >= i1 - 1); local_y--) { if (local_y < 255) { - BlockStateHolder material = chunk.getBlock(bx + local_x, local_y, bz + local_z); + BlockState material = chunk.getBlock(bx + local_x, local_y, bz + local_z); if (material.getBlockType() == BlockTypes.WATER) { waterFound = true; } @@ -173,8 +174,8 @@ public class CavesGen extends GenBase { for (int local_y = i2; local_y > i1; local_y--) { double d11 = ((local_y - 1) + 0.5D - y) / d4; if ((d11 > -0.7D) && (d9 * d9 + d11 * d11 + d10 * d10 < 1.0D)) { - BlockStateHolder material = chunk.getBlock(bx + local_x, local_y, bz + local_z); - BlockStateHolder materialAbove = chunk.getBlock(bx + local_x, local_y + 1, bz + local_z); + BlockState material = chunk.getBlock(bx + local_x, local_y, bz + local_z); + BlockState materialAbove = chunk.getBlock(bx + local_x, local_y + 1, bz + local_z); BlockType blockType = material.getBlockType(); switch (blockType.getInternalId()) { case BlockID.MYCELIUM: @@ -191,7 +192,7 @@ public class CavesGen extends GenBase { // If grass was just deleted, try to // move it down if (grassFound) { - BlockStateHolder block = chunk.getBlock(bx + local_x, local_y - 1, bz + local_z); + BlockState block = chunk.getBlock(bx + local_x, local_y - 1, bz + local_z); if (block.getBlockType() == BlockTypes.DIRT) { chunk.setBlock(bx + local_x, local_y - 1, bz + local_z, BlockTypes.STONE.getDefaultState()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockStateMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockStateMask.java index 25efcfb03..0f0ddb907 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockStateMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockStateMask.java @@ -8,7 +8,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; public class InverseSingleBlockStateMask extends ABlockMask { private final char ordinal; - public BlockStateHolder getBlockState() { + public BlockState getBlockState() { return BlockState.getFromOrdinal(ordinal); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockStateMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockStateMask.java index bb97aa592..b9164c0aa 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockStateMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockStateMask.java @@ -9,7 +9,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; public class SingleBlockStateMask extends ABlockMask { private final char ordinal; - public BlockStateHolder getBlockState() { + public BlockState getBlockState() { return BlockState.getFromOrdinal(ordinal); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/FawePattern.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/FawePattern.java deleted file mode 100644 index e42234db1..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/FawePattern.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.sk89q.worldedit.function.pattern; - -import com.sk89q.worldedit.world.block.BlockStateHolder; - -/** - * Returns a {@link BlockStateHolder} for a given position. - * - Adapts the vector apply to integer - */ -public interface FawePattern extends Pattern { -// -// @Deprecated -// default BaseBlock apply(BlockVector3 position) { -// throw new UnsupportedOperationException("Please use apply(extent, get, set)"); -// } -// -// /** -// * Return a {@link BlockStateHolder} for the given position. -// * -// * @return a block -// */ -// @Override -// boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException; -} 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 cbee3feb9..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 @@ -13,7 +13,7 @@ public class MutableBlockVector3 extends BlockVector3 { } public static MutableBlockVector3 get(int x, int y, int z) { - return FaweCache.IMP.MUTABLE_BLOCKVECTOR3.get().setComponents(x, y, z); + return FaweCache.INSTANCE.getMUTABLE_BLOCKVECTOR3().get().setComponents(x, y, z); } public MutableBlockVector3() {} 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 4c38e9ea1..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.IMP.MUTABLE_VECTOR3.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.IMP.MUTABLE_VECTOR3.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/convolution/HeightMap.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java index be6917344..432445223 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java @@ -144,7 +144,6 @@ public class HeightMap { * @param filter the filter * @param iterations the number of iterations * @return number of blocks affected - * @throws MaxChangedBlocksException */ public int applyFilter(HeightMapFilter filter, int iterations) throws MaxChangedBlocksException { @@ -173,7 +172,7 @@ public class HeightMap { int blocksChanged = 0; - BlockStateHolder tmpBlock = BlockTypes.AIR.getDefaultState(); + BlockStateHolder tmpBlock = BlockTypes.AIR.getDefaultState(); int maxY4 = maxY << 4; int index = 0; @@ -197,13 +196,13 @@ public class HeightMap { // Depending on growing or shrinking we need to start at the bottom or top if (newHeight > curHeight) { // Set the top block of the column to be the same type (this might go wrong with rounding) - BlockStateHolder existing = session.getBlock(xr, curBlock, zr); + BlockStateHolder existing = session.getBlock(xr, curBlock, zr); // Skip water/lava if (existing.getBlockType().getMaterial().isMovementBlocker()) { // Grow -- start from 1 below top replacing airblocks for (int setY = newBlock - 1, getY = curBlock; setY >= curBlock; --setY, getY--) { - BlockStateHolder get = session.getBlock(xr, getY, zr); + BlockStateHolder get = session.getBlock(xr, getY, zr); if (get != BlockTypes.AIR.getDefaultState()) tmpBlock = get; session.setBlock(xr, setY, zr, tmpBlock); ++blocksChanged; @@ -228,7 +227,7 @@ public class HeightMap { // Set the top block of the column to be the same type // (this could otherwise go wrong with rounding) int setData = newHeight & 15; - BlockStateHolder existing = session.getBlock(xr, curBlock, zr); + BlockStateHolder existing = session.getBlock(xr, curBlock, zr); if (setData != 0) { existing = PropertyGroup.LEVEL.set(existing, setData - 1); session.setBlock(xr, newBlock, zr, existing); @@ -248,7 +247,6 @@ public class HeightMap { * * @param data the data * @return number of blocks affected - * @throws MaxChangedBlocksException */ public int apply(int[] data) throws MaxChangedBlocksException { 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 03b6fdc6c..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.IMP.WORLD_MAX_Y : world.getMaxY()); - pos2 = pos2.clampY(world == null ? 0 : 0, world == null ? FaweCache.IMP.WORLD_MAX_Y : 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.IMP.CHUNK_LAYERS; 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/registry/state/PropertyGroup.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/PropertyGroup.java index 2441771b1..f8d233fb5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/PropertyGroup.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/PropertyGroup.java @@ -80,7 +80,7 @@ public class PropertyGroup { private static final Function VOID_FUNCTION = o -> o; - public G get(BlockStateHolder state) { + public > G get(BlockStateHolder state) { BlockType type = state.getBlockType(); PropertyFunction func = states[type.getInternalId()]; if (func == null) return defaultValue; @@ -88,7 +88,7 @@ public class PropertyGroup { return (G) func.getFunc.apply(value); } - public BlockStateHolder set(BlockStateHolder state, A value) { + public > BlockStateHolder set(BlockStateHolder state, A value) { BlockType type = state.getBlockType(); PropertyFunction func = states[type.getInternalId()]; if (func != null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java index 1803b72af..8d3bcb3d2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java @@ -35,7 +35,7 @@ import com.sk89q.worldedit.extent.NullExtent; import com.sk89q.worldedit.extent.OutputExtent; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.SingleBlockStateMask; -import com.sk89q.worldedit.function.pattern.FawePattern; +import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.AbstractProperty; import com.sk89q.worldedit.registry.state.Property; @@ -51,7 +51,7 @@ import java.util.stream.Stream; * An immutable class that represents the state a block can be in. */ @SuppressWarnings("unchecked") -public class BlockState implements BlockStateHolder, FawePattern { +public class BlockState implements BlockStateHolder, Pattern { private final int internalId; private final int ordinal; private final char ordinalChar; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java index 93c85be90..983e52571 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java @@ -21,12 +21,10 @@ package com.sk89q.worldedit.world.block; import com.boydti.fawe.beta.ITileInput; import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.blocks.TileEntityBlock; import com.sk89q.worldedit.extent.OutputExtent; -import com.sk89q.worldedit.function.pattern.FawePattern; +import com.sk89q.worldedit.function.pattern.Pattern; import java.util.Locale; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; @@ -37,7 +35,7 @@ import javax.annotation.Nullable; import java.util.Map; import java.util.stream.Collectors; -public interface BlockStateHolder> extends FawePattern, TileEntityBlock { +public interface BlockStateHolder> extends TileEntityBlock, Pattern { /** * Get the block type diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java index 4328788be..639c205bd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java @@ -25,14 +25,13 @@ import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.NullExtent; import com.sk89q.worldedit.function.mask.SingleBlockTypeMask; -import com.sk89q.worldedit.function.pattern.FawePattern; +import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.Keyed; import com.sk89q.worldedit.registry.NamespacedRegistry; import com.sk89q.worldedit.registry.state.AbstractProperty; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.PropertyKey; -import com.sk89q.worldedit.util.concurrency.LazyReference; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.registry.BlockMaterial; @@ -48,7 +47,7 @@ import java.util.stream.IntStream; import static com.google.common.base.Preconditions.checkArgument; -public class BlockType implements FawePattern, Keyed { +public class BlockType implements Keyed, Pattern { public static final NamespacedRegistry REGISTRY = new NamespacedRegistry<>("block type"); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java index f5095c767..a2e73ae26 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java @@ -21,36 +21,16 @@ package com.sk89q.worldedit.world.block; import com.boydti.fawe.command.SuggestInputParseException; import com.boydti.fawe.object.string.JoinedCharSequence; -import com.boydti.fawe.util.MathMan; -import com.boydti.fawe.util.ReflectionUtils; import com.boydti.fawe.util.StringMan; -import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.input.InputParseException; -import com.sk89q.worldedit.extension.platform.Capability; -import com.sk89q.worldedit.extension.platform.Platform; -import com.sk89q.worldedit.registry.state.AbstractProperty; -import com.sk89q.worldedit.registry.state.Property; -import com.sk89q.worldedit.registry.state.PropertyKey; -import com.sk89q.worldedit.world.registry.BlockMaterial; -import com.sk89q.worldedit.world.registry.BlockRegistry; import com.sk89q.worldedit.world.registry.LegacyMapper; -import com.sk89q.worldedit.world.registry.Registries; import javax.annotation.Nullable; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.List; import java.util.Locale; -import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import java.util.Optional; /** * Stores a list of common Block String IDs. @@ -777,7 +757,7 @@ public final class BlockTypes { if (result != null) return result; try { - BlockStateHolder block = LegacyMapper.getInstance().getBlockFromLegacy(input); + BlockStateHolder block = LegacyMapper.getInstance().getBlockFromLegacy(input); if (block != null) return block.getBlockType(); } catch (NumberFormatException | IndexOutOfBoundsException e) { }