From 62cb04b8cad157e5a5fdd8ce5be4124204d98c0c Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Fri, 21 Feb 2020 14:56:21 -0500 Subject: [PATCH] Remove CFI redirect and other minor changes. --- .../adapter/mc1_14/BukkitGetBlocks_1_14.java | 14 +++--- .../adapter/mc1_15/BukkitGetBlocks_1_15.java | 14 +++--- .../fawe/bukkit/regions/FreeBuildRegion.java | 3 +- .../regions/plotsquared/CFIRedirect.java | 50 ------------------- .../fawe/object/collection/SoftHashMap.java | 33 ++++++++---- .../com/boydti/fawe/util/ReflectionUtils.java | 2 +- .../net/jpountz/lz4/LZ4BlockOutputStream.java | 45 ++++++++++++----- 7 files changed, 74 insertions(+), 87 deletions(-) delete mode 100644 worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/CFIRedirect.java 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..52f7d90e8 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 @@ -39,6 +39,8 @@ import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.Future; import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import javax.annotation.Nullable; import net.minecraft.server.v1_14_R1.BiomeBase; import net.minecraft.server.v1_14_R1.BlockPosition; @@ -183,15 +185,13 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks { @NotNull @Override public Iterator iterator() { - Iterable result = Iterables.transform(Iterables.concat(slices), new com.google.common.base.Function() { - @Nullable - @Override - public CompoundTag apply(@Nullable Entity input) { - BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); + Iterable result = StreamSupport + .stream(Iterables.concat(slices).spliterator(), false).map(input -> { + BukkitImplAdapter adapter = WorldEditPlugin.getInstance() + .getBukkitImplAdapter(); NBTTagCompound tag = new NBTTagCompound(); return (CompoundTag) adapter.toNative(input.save(tag)); - } - }); + }).collect(Collectors.toList()); return result.iterator(); } }; 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..ae9cb0535 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 @@ -39,6 +39,8 @@ import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.Future; import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import javax.annotation.Nullable; import net.minecraft.server.v1_15_R1.BiomeBase; import net.minecraft.server.v1_15_R1.BiomeStorage; @@ -191,15 +193,13 @@ public class BukkitGetBlocks_1_15 extends CharGetBlocks { @NotNull @Override public Iterator iterator() { - Iterable result = Iterables.transform(Iterables.concat(slices), new com.google.common.base.Function() { - @Nullable - @Override - public CompoundTag apply(@Nullable Entity input) { - BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); + Iterable result = StreamSupport + .stream(Iterables.concat(slices).spliterator(), false).map(input -> { + BukkitImplAdapter adapter = WorldEditPlugin.getInstance() + .getBukkitImplAdapter(); NBTTagCompound tag = new NBTTagCompound(); return (CompoundTag) adapter.toNative(input.save(tag)); - } - }); + }).collect(Collectors.toList()); return result.iterator(); } }; diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java index f1b12574c..6d9c78668 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java @@ -4,6 +4,7 @@ import com.boydti.fawe.bukkit.wrapper.AsyncBlock; import com.boydti.fawe.bukkit.wrapper.AsyncWorld; import com.boydti.fawe.regions.FaweMask; import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.bukkit.BukkitPlayer; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; @@ -54,7 +55,7 @@ public class FreeBuildRegion extends BukkitMaskManager { BlockVector3 pos2 = BlockVector3.ZERO; AsyncBlock block = new AsyncBlock(asyncWorld, 0, 0, 0); - BlockBreakEvent event = new BlockBreakEvent(block, BukkitAdapter.adapt(player)); + BlockBreakEvent event = new BlockBreakEvent(block, ((BukkitPlayer) player).getPlayer()); return new FaweMask(pos1, pos2) { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/CFIRedirect.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/CFIRedirect.java deleted file mode 100644 index b80ee9cc4..000000000 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/CFIRedirect.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.boydti.fawe.bukkit.regions.plotsquared; - -import com.github.intellectualsites.plotsquared.commands.Command; -import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; -import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory; -import com.github.intellectualsites.plotsquared.plot.commands.MainCommand; -import com.github.intellectualsites.plotsquared.plot.commands.RequiredType; -import com.github.intellectualsites.plotsquared.plot.config.Captions; -import com.github.intellectualsites.plotsquared.plot.object.Plot; -import com.github.intellectualsites.plotsquared.plot.object.PlotArea; -import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2; -import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; -import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea; -import com.sk89q.worldedit.WorldEdit; -import java.util.concurrent.CompletableFuture; - -@CommandDeclaration( - command = "cfi", - permission = "plots.createfromimage", - aliases = {"createfromheightmap", "createfromimage", "cfhm"}, - category = CommandCategory.APPEARANCE, - requiredType = RequiredType.NONE, - description = "Generate a world from an image heightmap: [More info](https://goo.gl/friFbV)", - usage = "/plots cfi [url or dimensions]" -) -public class CFIRedirect extends Command { - private final WorldEdit we; - - public CFIRedirect() { - super(MainCommand.getInstance(), true); - this.we = WorldEdit.getInstance(); - } - - @Override - public CompletableFuture execute(final PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) throws CommandException { - checkTrue(args.length >= 1, Captions.COMMAND_SYNTAX, getUsage()); - final Plot plot = check(player.getCurrentPlot(), Captions.NOT_IN_PLOT); - checkTrue(plot.isOwner(player.getUUID()), Captions.NOW_OWNER); - checkTrue(plot.getRunning() == 0, Captions.WAIT_FOR_TIMER); - final PlotArea area = plot.getArea(); - if (area instanceof SinglePlotArea) { - player.sendMessage("The command has been changed to: //cfi"); - } else { - player.sendMessage("Must have the `worlds` component enabled in the PlotSquared config.yml"); - return CompletableFuture.completedFuture(false); - } - return CompletableFuture.completedFuture(true); - } -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/SoftHashMap.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/SoftHashMap.java index 883d4d235..7a17bb076 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/SoftHashMap.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/SoftHashMap.java @@ -13,6 +13,7 @@ import java.util.WeakHashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.locks.ReentrantLock; +import org.jetbrains.annotations.NotNull; /** @@ -83,13 +84,12 @@ public class SoftHashMap implements Map { * elements retained after a GC due to the strong references. *

* Note that in a highly concurrent environments the exact total number of strong references may differ slightly - * than the actual retentionSize value. This number is intended to be a best-effort retention low + * than the actual {@code retentionSize} value. This number is intended to be a best-effort retention low * water mark. * * @param retentionSize the total number of most recent entries in the map that will be strongly referenced * (retained), preventing them from being eagerly garbage collected by the JVM. */ - @SuppressWarnings({"unchecked"}) public SoftHashMap(int retentionSize) { super(); RETENTION_SIZE = Math.max(0, retentionSize); @@ -120,7 +120,7 @@ public class SoftHashMap implements Map { * elements retained after a GC due to the strong references. *

* Note that in a highly concurrent environments the exact total number of strong references may differ slightly - * than the actual retentionSize value. This number is intended to be a best-effort retention low + * than the actual {@code retentionSize} value. This number is intended to be a best-effort retention low * water mark. * * @param source the backing map to populate this {@code SoftHashMap} @@ -132,6 +132,7 @@ public class SoftHashMap implements Map { putAll(source); } + @Override public V get(Object key) { processQueue(); @@ -185,24 +186,28 @@ public class SoftHashMap implements Map { } } + @Override public boolean isEmpty() { processQueue(); return map.isEmpty(); } + @Override public boolean containsKey(Object key) { processQueue(); return map.containsKey(key); } + @Override public boolean containsValue(Object value) { processQueue(); - Collection values = values(); - return values != null && values.contains(value); + Collection values = values(); + return values.contains(value); } - public void putAll(Map m) { - if (m == null || m.isEmpty()) { + @Override + public void putAll(@NotNull Map m) { + if (m.isEmpty()) { processQueue(); return; } @@ -211,17 +216,21 @@ public class SoftHashMap implements Map { } } + @Override + @NotNull public Set keySet() { processQueue(); return map.keySet(); } + @Override + @NotNull public Collection values() { processQueue(); Collection keys = map.keySet(); if (keys.isEmpty()) { //noinspection unchecked - return Collections.EMPTY_SET; + return Collections.emptySet(); } Collection values = new ArrayList<>(keys.size()); for (K key : keys) { @@ -236,6 +245,7 @@ public class SoftHashMap implements Map { /** * Creates a new entry, but wraps the value in a SoftValue instance to enable auto garbage collection. */ + @Override public V put(K key, V value) { processQueue(); // throw out garbage collected values first SoftValue sv = new SoftValue<>(value, key, queue); @@ -244,12 +254,14 @@ public class SoftHashMap implements Map { return previous != null ? previous.get() : null; } + @Override public V remove(Object key) { processQueue(); // throw out garbage collected values first SoftValue raw = map.remove(key); return raw != null ? raw.get() : null; } + @Override public void clear() { strongReferencesLock.lock(); try { @@ -261,17 +273,20 @@ public class SoftHashMap implements Map { map.clear(); } + @Override public int size() { processQueue(); // throw out garbage collected values first return map.size(); } + @Override + @NotNull public Set> entrySet() { processQueue(); // throw out garbage collected values first Collection keys = map.keySet(); if (keys.isEmpty()) { //noinspection unchecked - return Collections.EMPTY_SET; + return Collections.emptySet(); } Map kvPairs = new HashMap<>(keys.size()); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java index d8229af19..a167f468f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java @@ -80,7 +80,7 @@ public class ReflectionUtils { blankField(enumClass, "enumConstants"); // IBM JDK } - private static Class UNMODIFIABLE_MAP = Collections.unmodifiableMap(Collections.EMPTY_MAP).getClass(); + private static Class UNMODIFIABLE_MAP = Collections.unmodifiableMap(Collections.emptyMap()).getClass(); public static Map getMap(Map map) { try { diff --git a/worldedit-core/src/main/java/net/jpountz/lz4/LZ4BlockOutputStream.java b/worldedit-core/src/main/java/net/jpountz/lz4/LZ4BlockOutputStream.java index 03e79e365..149ba3680 100644 --- a/worldedit-core/src/main/java/net/jpountz/lz4/LZ4BlockOutputStream.java +++ b/worldedit-core/src/main/java/net/jpountz/lz4/LZ4BlockOutputStream.java @@ -12,6 +12,8 @@ package net.jpountz.lz4; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * This file has been modified for use in the FAWE project. */ import java.io.FilterOutputStream; @@ -21,10 +23,10 @@ import java.util.zip.Checksum; import net.jpountz.util.SafeUtils; /** - * Streaming LZ4. - *

+ * Streaming LZ4 (not compatible with the LZ4 Frame format). * This class compresses data into fixed-size blocks of compressed data. - * + * This class uses its own format and is not compatible with the LZ4 Frame format. + * @see LZ4BlockInputStream */ public final class LZ4BlockOutputStream extends FilterOutputStream { @@ -73,17 +75,17 @@ public final class LZ4BlockOutputStream extends FilterOutputStream { private int o; /** - * Create a new {@link OutputStream} with configurable block size. Large + * Creates a new {@link OutputStream} with configurable block size. Large * blocks require more memory at compression and decompression time but * should improve the compression ratio. * * @param out the {@link OutputStream} to feed * @param blockSize the maximum number of bytes to try to compress at once, - * must be >= 64 and <= 32 M + * must be >= 64 and <= 32 M * @param compressor the {@link LZ4Compressor} instance to use to compress - * data + * data * @param checksum the {@link Checksum} instance to use to check data for - * integrity. + * integrity. * @param syncFlush true if pending data should also be flushed on {@link #flush()} */ public LZ4BlockOutputStream(OutputStream out, int blockSize, LZ4Compressor compressor, Checksum checksum, boolean syncFlush) { @@ -101,14 +103,29 @@ public final class LZ4BlockOutputStream extends FilterOutputStream { System.arraycopy(MAGIC, 0, compressedBuffer, 0, MAGIC_LENGTH); } + /** + * Creates a new instance which checks stream integrity and doesn't sync flush. + * + * @param out the {@link OutputStream} to feed + * @param blockSize the maximum number of bytes to try to compress at once, + * must be >= 64 and <= 32 M + * @param compressor the {@link LZ4Compressor} instance to use to compress + * data + * + * @see #LZ4BlockOutputStream(OutputStream, int, LZ4Compressor, Checksum, boolean) + */ public LZ4BlockOutputStream(OutputStream out, int blockSize, LZ4Compressor compressor) { this(out, blockSize, compressor, null, false); } /** - * Create a new instance which compresses with the standard LZ4 compression + * Creates a new instance which compresses with the standard LZ4 compression * algorithm. * + * @param out the {@link OutputStream} to feed + * @param blockSize the maximum number of bytes to try to compress at once, + * must be >= 64 and <= 32 M + * * @see #LZ4BlockOutputStream(OutputStream, int, LZ4Compressor) * @see LZ4Factory#fastCompressor() */ @@ -117,7 +134,9 @@ public final class LZ4BlockOutputStream extends FilterOutputStream { } /** - * Create a new instance which compresses into blocks of 64 KB. + * Creates a new instance which compresses into blocks of 64 KB. + * + * @param out the {@link OutputStream} to feed * * @see #LZ4BlockOutputStream(OutputStream, int) */ @@ -206,8 +225,8 @@ public final class LZ4BlockOutputStream extends FilterOutputStream { } /** - * Flush this compressed {@link OutputStream}. - *

+ * Flushes this compressed {@link OutputStream}. + * * If the stream has been created with syncFlush=true, pending * data will be compressed and appended to the underlying {@link OutputStream} * before calling {@link OutputStream#flush()} on the underlying stream. @@ -228,6 +247,8 @@ public final class LZ4BlockOutputStream extends FilterOutputStream { /** * Same as {@link #close()} except that it doesn't close the underlying stream. * This can be useful if you want to keep on using the underlying stream. + * + * @throws IOException if an I/O error occurs. */ public void finish() throws IOException { ensureNotFinished(); @@ -255,4 +276,4 @@ public final class LZ4BlockOutputStream extends FilterOutputStream { + ", compressor=" + compressor + ", checksum=" + checksum + ")"; } -} \ No newline at end of file +}