From ff5860113d5b51f69d81544ce2ba2a97716513b9 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Thu, 25 Jul 2019 14:44:10 -0400 Subject: [PATCH] It started on work with commands then I got carried away. --- .../com/boydti/fawe/bukkit/FaweBukkit.java | 6 - .../fawe/bukkit/chat/BukkitChatManager.java | 64 -- .../boydti/fawe/bukkit/chat/FancyMessage.java | 874 ------------------ .../boydti/fawe/bukkit/chat/MessagePart.java | 156 ---- .../bukkit/listener/CFIPacketListener.java | 8 +- .../bukkit/regions/FactionsOneFeature.java | 7 +- .../bukkit/regions/FactionsUUIDFeature.java | 7 +- .../fawe/bukkit/wrapper/state/AsyncSign.java | 14 +- .../src/main/java/com/boydti/fawe/Fawe.java | 44 +- .../java/com/boydti/fawe/beta/IChunkSet.java | 2 + .../com/boydti/fawe/beta/IQueueExtent.java | 4 +- .../com/boydti/fawe/command/CFICommands.java | 229 +++-- .../fawe/database/RollbackDatabase.java | 30 +- .../com/boydti/fawe/object/FawePlayer.java | 22 +- .../fawe/object/brush/SplatterBrush.java | 2 - .../boydti/fawe/object/brush/SplineBrush.java | 32 +- .../visualization/ImmutableVirtualWorld.java | 19 - .../brush/visualization/VirtualWorld.java | 5 - .../brush/visualization/VisualQueue.java | 4 +- .../cfi/HeightMapMCAGenerator.java | 7 +- .../changeset/AbstractDelegateChangeSet.java | 5 - .../AbstractDelegateFaweClipboard.java | 2 - .../clipboard/CPUOptimizedClipboard.java | 13 +- .../clipboard/DiskOptimizedClipboard.java | 24 +- .../fawe/object/clipboard/EmptyClipboard.java | 29 - .../fawe/object/clipboard/FaweClipboard.java | 6 +- .../object/clipboard/LazyClipboardHolder.java | 1 - .../clipboard/MemoryOptimizedClipboard.java | 8 +- .../clipboard/MultiClipboardHolder.java | 11 +- .../object/clipboard/ReadOnlyClipboard.java | 2 - .../clipboard/ResizableClipboardBuilder.java | 3 +- .../object/clipboard/URIClipboardHolder.java | 5 +- .../object/clipboard/WorldCutClipboard.java | 2 +- .../clipboard/remap/ClipboardRemapper.java | 2 +- .../object/clipboard/remap/WikiScraper.java | 2 - .../collection/AdaptedSetCollection.java | 8 +- .../fawe/object/collection/BlockSet.java | 9 +- .../object/collection/BlockVectorSet.java | 1 - .../object/extent/MemoryCheckingExtent.java | 5 +- .../fawe/object/extent/ProcessedWEExtent.java | 20 - .../object/io/AsyncBufferedOutputStream.java | 6 +- .../fawe/object/io/zstd/ZstdInputStream.java | 16 +- .../boydti/fawe/object/mask/AngleMask.java | 1 - .../fawe/object/mask/BlockLightMask.java | 3 - .../fawe/object/mask/BrightnessMask.java | 1 - .../fawe/object/mask/FaweBlockMatcher.java | 1 - .../com/boydti/fawe/object/mask/IdMask.java | 3 - .../boydti/fawe/object/mask/LightMask.java | 3 - .../fawe/object/mask/MaskedTargetBlock.java | 4 +- .../boydti/fawe/object/mask/OpacityMask.java | 3 - .../boydti/fawe/object/mask/PlaneMask.java | 3 - .../boydti/fawe/object/mask/ROCAngleMask.java | 19 +- .../boydti/fawe/object/mask/RadiusMask.java | 3 - .../boydti/fawe/object/mask/RandomMask.java | 3 +- .../boydti/fawe/object/mask/SkyLightMask.java | 3 - .../fawe/object/mask/SolidPlaneMask.java | 3 - .../boydti/fawe/object/mask/XAxisMask.java | 3 - .../boydti/fawe/object/mask/ZAxisMask.java | 3 - .../object/pattern/AbstractExtentPattern.java | 5 +- .../object/pattern/AngleColorPattern.java | 6 +- .../object/pattern/AverageColorPattern.java | 3 - .../fawe/object/pattern/BiomePattern.java | 6 +- .../fawe/object/pattern/BufferedPattern.java | 7 +- .../fawe/object/pattern/DataPattern.java | 7 +- .../object/pattern/DesaturatePattern.java | 6 +- .../fawe/object/pattern/ExistingPattern.java | 3 +- .../object/pattern/ExpressionPattern.java | 11 +- .../object/pattern/FullClipboardPattern.java | 11 +- .../object/pattern/IdDataMaskPattern.java | 8 +- .../object/pattern/Linear2DBlockPattern.java | 7 +- .../object/pattern/Linear3DBlockPattern.java | 5 +- .../object/pattern/LinearBlockPattern.java | 4 +- .../fawe/object/pattern/MaskedPattern.java | 6 +- .../fawe/object/pattern/NoXPattern.java | 16 +- .../fawe/object/pattern/NoYPattern.java | 8 +- .../fawe/object/pattern/NoZPattern.java | 16 +- .../fawe/object/pattern/OffsetPattern.java | 19 +- .../fawe/object/pattern/PropertyPattern.java | 6 +- .../pattern/RandomFullClipboardPattern.java | 7 +- .../object/pattern/RandomOffsetPattern.java | 7 +- .../fawe/object/pattern/RelativePattern.java | 5 +- .../fawe/object/pattern/SaturatePattern.java | 4 - .../pattern/SolidRandomOffsetPattern.java | 26 +- .../pattern/SurfaceRandomOffsetPattern.java | 1 - .../regions/selector/FuzzyRegionSelector.java | 2 +- .../selector/PolyhedralRegionSelector.java | 2 +- .../object/schematic/MinecraftStructure.java | 159 ++-- .../fawe/object/schematic/PNGWriter.java | 5 +- .../fawe/object/schematic/Schematic.java | 79 +- .../boydti/fawe/util/CleanTextureUtil.java | 6 +- .../boydti/fawe/util/EditSessionBuilder.java | 9 +- .../java/com/boydti/fawe/util/IOUtil.java | 12 +- .../com/boydti/fawe/util/ImgurUtility.java | 10 +- .../main/java/com/boydti/fawe/util/Perm.java | 44 - .../java/com/boydti/fawe/util/Permission.java | 37 + .../boydti/fawe/util/RandomTextureUtil.java | 6 +- .../java/com/boydti/fawe/util/StringMan.java | 24 +- .../java/com/boydti/fawe/util/WEManager.java | 52 +- .../boydti/fawe/util/chat/ChatManager.java | 21 - .../com/boydti/fawe/util/chat/Message.java | 127 --- .../fawe/util/chat/PlainChatManager.java | 47 - .../com/boydti/fawe/util/image/ImageUtil.java | 71 +- .../boydti/fawe/util/task/TaskBuilder.java | 12 +- .../java/com/boydti/fawe/web/SchemSync.java | 3 +- .../worldedit/command/ChunkCommands.java | 2 +- .../worldedit/command/ClipboardCommands.java | 4 +- .../worldedit/command/GeneralCommands.java | 53 +- .../worldedit/command/GenerationCommands.java | 10 +- .../worldedit/command/HistoryCommands.java | 6 +- .../sk89q/worldedit/command/MaskCommands.java | 34 +- .../worldedit/command/NavigationCommands.java | 13 +- .../worldedit/command/PatternCommands.java | 10 +- .../worldedit/command/RegionCommands.java | 53 +- .../worldedit/command/SelectionCommands.java | 42 +- .../sk89q/worldedit/command/ToolCommands.java | 1 + .../worldedit/command/TransformCommands.java | 4 +- .../worldedit/command/UtilityCommands.java | 80 +- .../worldedit/command/WorldEditCommands.java | 2 +- .../worldedit/command/tool/BrushTool.java | 2 +- .../worldedit/command/tool/DistanceWand.java | 6 +- .../factory/parser/DefaultBlockParser.java | 4 +- .../parser/pattern/DefaultPatternParser.java | 2 +- .../platform/AbstractPlayerActor.java | 2 +- .../platform/PlatformCommandManager.java | 20 +- .../extension/platform/PlatformManager.java | 8 +- .../extent/AbstractDelegateExtent.java | 55 +- .../sk89q/worldedit/extent/NullExtent.java | 3 +- .../worldedit/extent/buffer/ExtentBuffer.java | 18 +- .../worldedit/extent/clipboard/Clipboard.java | 2 +- .../clipboard/io/BuiltInClipboardFormat.java | 41 +- .../extent/clipboard/io/ClipboardFormats.java | 10 +- .../extent/clipboard/io/ClipboardWriter.java | 22 + .../clipboard/io/SpongeSchematicReader.java | 86 +- .../clipboard/io/SpongeSchematicWriter.java | 36 +- .../extent/inventory/BlockBagExtent.java | 21 +- .../extent/reorder/ChunkBatchingExtent.java | 55 +- .../extent/reorder/MultiStageReorder.java | 24 +- .../function/block/BlockReplace.java | 2 +- .../function/entity/ExtentEntityCopy.java | 22 +- .../function/mask/AbstractExtentMask.java | 2 +- .../function/mask/BlockCategoryMask.java | 9 +- .../worldedit/function/mask/BlockMask.java | 73 +- .../function/mask/BlockStateMask.java | 8 +- .../function/mask/BlockTypeMask.java | 28 +- .../function/mask/BoundedHeightMask.java | 7 + .../function/mask/ExistingBlockMask.java | 10 +- .../mask/InverseSingleBlockTypeMask.java | 2 - .../sk89q/worldedit/function/mask/Mask.java | 5 - .../worldedit/function/mask/NoiseFilter.java | 6 +- .../worldedit/function/mask/RegionMask.java | 5 + .../function/mask/SolidBlockMask.java | 9 + .../function/operation/ChangeSetExecutor.java | 13 +- .../function/operation/ForwardExtentCopy.java | 4 +- .../function/pattern/FawePattern.java | 7 - .../worldedit/function/pattern/Pattern.java | 3 - .../function/pattern/WaterloggedRemover.java | 12 +- .../function/visitor/BreadthFirstSearch.java | 26 +- .../function/visitor/RegionVisitor.java | 10 +- .../changeset/BlockOptimizedHistory.java | 4 +- .../sk89q/worldedit/math/BlockVector2.java | 46 +- .../sk89q/worldedit/math/BlockVector3.java | 73 +- .../sk89q/worldedit/math/MutableVector2.java | 3 - .../sk89q/worldedit/math/MutableVector3.java | 5 +- .../com/sk89q/worldedit/math/Vector2.java | 17 +- .../com/sk89q/worldedit/math/Vector3.java | 15 + .../worldedit/math/convolution/HeightMap.java | 5 +- .../math/transform/AffineTransform.java | 2 - .../worldedit/regions/AbstractRegion.java | 14 + .../sk89q/worldedit/regions/CuboidRegion.java | 24 +- .../worldedit/regions/CylinderRegion.java | 16 + .../com/sk89q/worldedit/regions/Region.java | 6 +- .../worldedit/regions/RegionSelector.java | 4 +- .../worldedit/regions/TransformRegion.java | 191 ++++ .../ConvexPolyhedralRegionSelector.java | 2 +- .../selector/CuboidRegionSelector.java | 2 +- .../registry/state/BooleanProperty.java | 2 +- .../registry/state/DirectionalProperty.java | 2 +- .../registry/state/EnumProperty.java | 7 +- .../registry/state/IntegerProperty.java | 9 +- .../MinecraftHidingClassShutter.java | 41 + .../sk89q/worldedit/session/PasteBuilder.java | 3 +- .../worldedit/session/SessionManager.java | 23 +- .../util/collection/LocatedBlockList.java | 47 +- .../java/com/sk89q/worldedit/world/World.java | 4 - 184 files changed, 1694 insertions(+), 2580 deletions(-) delete mode 100644 worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/BukkitChatManager.java delete mode 100644 worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/FancyMessage.java delete mode 100644 worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/MessagePart.java delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/util/Perm.java create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/util/Permission.java delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/util/chat/ChatManager.java delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/util/chat/Message.java delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/util/chat/PlainChatManager.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/regions/TransformRegion.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/scripting/MinecraftHidingClassShutter.java diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java index feecc0ce5..e37f7b888 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java @@ -5,7 +5,6 @@ import com.boydti.fawe.IFawe; import com.boydti.fawe.beta.implementation.QueueHandler; import com.boydti.fawe.bukkit.beta.BukkitQueue; import com.boydti.fawe.bukkit.beta.BukkitQueueHandler; -import com.boydti.fawe.bukkit.chat.BukkitChatManager; import com.boydti.fawe.bukkit.listener.BrushListener; import com.boydti.fawe.bukkit.listener.BukkitImageListener; import com.boydti.fawe.bukkit.listener.CFIPacketListener; @@ -97,11 +96,6 @@ public class FaweBukkit implements IFawe, Listener { if (Bukkit.getVersion().contains("git-Paper") && Settings.IMP.EXPERIMENTAL.DYNAMIC_CHUNK_RENDERING > 1) { new RenderListener(plugin); } - try { - Fawe.get().setChatManager(new BukkitChatManager()); - } catch (Throwable throwable) { - throwable.printStackTrace(); - } } catch (final Throwable e) { e.printStackTrace(); Bukkit.getServer().shutdown(); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/BukkitChatManager.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/BukkitChatManager.java deleted file mode 100644 index 45a1ef127..000000000 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/BukkitChatManager.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.boydti.fawe.bukkit.chat; - -import com.boydti.fawe.bukkit.BukkitPlayer; -import com.boydti.fawe.config.BBC; -import com.boydti.fawe.object.FawePlayer; -import com.boydti.fawe.util.chat.ChatManager; -import com.boydti.fawe.util.chat.Message; - -import java.util.ArrayList; -import java.util.List; -import org.bukkit.ChatColor; - -public class BukkitChatManager implements ChatManager { - - @Override - public FancyMessage builder() { - return new FancyMessage(""); - } - - @Override - public void color(Message message, String color) { - message.$(this).color(ChatColor.getByChar(BBC.color(color).substring(1))); - } - - @Override - public void tooltip(Message message, Message... tooltips) { - List lines = new ArrayList<>(); - for (Message tooltip : tooltips) { - lines.add(tooltip.$(this)); - } - message.$(this).formattedTooltip(lines); - } - - @Override - public void command(Message message, String command) { - message.$(this).command(command); - } - - @Override - public void text(Message message, String text) { - message.$(this).color(BBC.color(text)); - } - - @Override - public void send(Message Message, FawePlayer player) { - if (!(player instanceof BukkitPlayer)) { - player.sendMessage(Message.$(this).toOldMessageFormat()); - } else { - Message.$(this).send(((BukkitPlayer) player).parent); - } - } - - @Override - public void suggest(Message Message, String command) { - Message.$(this).suggest(command); - } - - @Override - public void link(Message Message, String url) { - Message.$(this).link(url); - } - - -} diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/FancyMessage.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/FancyMessage.java deleted file mode 100644 index 3590e58f2..000000000 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/FancyMessage.java +++ /dev/null @@ -1,874 +0,0 @@ -package com.boydti.fawe.bukkit.chat; - -import static com.boydti.fawe.bukkit.chat.TextualComponent.rawText; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.stream.JsonWriter; -import java.io.IOException; -import java.io.StringWriter; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.function.Consumer; -import java.util.logging.Level; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.serialization.ConfigurationSerializable; -import org.bukkit.configuration.serialization.ConfigurationSerialization; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -/** - * Represents a formattable message. Such messages can use elements such as colors, formatting - * codes, hover and click data, and other features provided by the vanilla Minecraft JSON message formatter. This - * class allows plugins to emulate the functionality of the vanilla Minecraft tellraw command. - *

- * This class follows the builder pattern, allowing for method chaining. It is set up such that - * invocations of property-setting methods will affect the current editing component, and a call to - * {@link #then()} or {@link #then(String)} will append a new editing component to the end of the - * message, optionally initializing it with text. Further property-setting method calls will affect - * that editing component. - *

- */ -public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable, - ConfigurationSerializable { - - static { - ConfigurationSerialization.registerClass(FancyMessage.class); - } - - private List messageParts; - private int index; - private String jsonString; - private boolean dirty; - - private static Constructor nmsPacketPlayOutChatConstructor; - - @Override - public FancyMessage clone() throws CloneNotSupportedException { - FancyMessage instance = (FancyMessage) super.clone(); - instance.messageParts = new ArrayList<>(messageParts.size()); - for (int i = 0; i < messageParts.size(); i++) { - instance.messageParts.add(i, messageParts.get(i).clone()); - } - instance.index = index; - instance.dirty = false; - instance.jsonString = null; - return instance; - } - - /** - * Creates a JSON message with text. - * - * @param firstPartText The existing text in the message. - */ - public FancyMessage(String firstPartText) { - this(rawText(firstPartText)); - } - - private FancyMessage(TextualComponent firstPartText) { - messageParts = new ArrayList<>(); - messageParts.add(new MessagePart(firstPartText)); - index = messageParts.size(); - jsonString = null; - dirty = false; - if (nmsPacketPlayOutChatConstructor == null) { - try { - nmsPacketPlayOutChatConstructor = Reflection.getNMSClass("PacketPlayOutChat") - .getDeclaredConstructor(Reflection.getNMSClass("IChatBaseComponent")); - nmsPacketPlayOutChatConstructor.setAccessible(true); - } catch (NoSuchMethodException e) { - Bukkit.getLogger() - .log(Level.SEVERE, "Could not find Minecraft method or constructor.", e); - } catch (SecurityException e) { - Bukkit.getLogger().log(Level.WARNING, "Could not access constructor.", e); - } - } - } - - /** - * Creates a JSON message without text. - */ - public FancyMessage() { - this((TextualComponent) null); - } - - /** - * Sets the text of the current editing component to a value. - * - * @param text The new text of the current editing component. - * @return This builder instance. - */ - public FancyMessage text(String text) { - MessagePart latest = latest(); - latest.text = rawText(text); - dirty = true; - return this; - } - - /** - * Sets the text of the current editing component to a value. - * - * @param text The new text of the current editing component. - * @return This builder instance. - */ - public FancyMessage text(TextualComponent text) { - MessagePart latest = latest(); - latest.text = text; - dirty = true; - return this; - } - - /** - * @param text Text with coloring - * @return This builder instance. - * @throws IllegalArgumentException If the specified {@code ChatColor} enumeration value is not - * a color (but a format value). - */ - public FancyMessage color(String text) { - index = messageParts.size(); - boolean color = false; - ArrayDeque colors = new ArrayDeque<>(); - int last = 0; - for (int i = 0; i < text.length(); i++) { - char c = text.charAt(i); - if (color != (color = false)) { - ChatColor chatColor = ChatColor.getByChar(c); - if (chatColor != null) { - if (i - last > 1) { - append(text.substring(last, i - 1)); - colors.forEach(this::color); - colors.clear(); - } - colors.add(chatColor); - last = i + 1; - } - } - if (c == '\u00A7') { - color = true; - } - } - if (text.length() - last > 0) { - append(text.substring(last)); - colors.forEach(this::color); - } - index++; - return this; - } - - /** - * Sets the color of the current editing component to a value.
Setting the color will - * clear current styles - * - * @param color The new color of the current editing component. - * @return This builder instance. - * @throws IllegalArgumentException If the specified {@code ChatColor} enumeration value is not - * a color (but a format value). - */ - public FancyMessage color(ChatColor color) { - if (!color.isColor()) { - if (color.isFormat()) { - return style(color); - } - if (color == ChatColor.RESET) { - color = ChatColor.WHITE; - } - } else { - latest().styles.clear(); - } - latest().color = color; - dirty = true; - return this; - } - - /** - * Sets the stylization of the current editing component. - * - * @param styles The array of styles to apply to the editing component. - * @return This builder instance. - * @throws IllegalArgumentException If any of the enumeration values in the array do not - * represent formatters. - */ - public FancyMessage style(ChatColor... styles) { - for (ChatColor style : styles) { - if (!style.isFormat()) { - color(style); - } - } - latest().styles.addAll(Arrays.asList(styles)); - dirty = true; - return this; - } - - /** - * Set the behavior of the current editing component to instruct the client to open a file on - * the client side filesystem when the currently edited part of the {@code FancyMessage} is - * clicked. - * - * @param path The path of the file on the client filesystem. - * @return This builder instance. - */ - public FancyMessage file(String path) { - onClick("open_file", path); - return this; - } - - /** - * Set the behavior of the current editing component to instruct the client to open a webpage in - * the client's web browser when the currently edited part of the {@code FancyMessage} is - * clicked. - * - * @param url The URL of the page to open when the link is clicked. - * @return This builder instance. - */ - public FancyMessage link(String url) { - onClick("open_url", url); - return this; - } - - /** - * Set the behavior of the current editing component to instruct the client to replace the chat - * input box content with the specified string when the currently edited part of the {@code - * FancyMessage} is clicked. The client will not immediately send the command to the server to - * be executed unless the client player submits the command/chat message, usually with the enter - * key. - * - * @param command The text to display in the chat bar of the client. - * @return This builder instance. - */ - public FancyMessage suggest(String command) { - onClick("suggest_command", command); - return this; - } - - /** - * Set the behavior of the current editing component to instruct the client to append the chat - * input box content with the specified string when the currently edited part of the {@code - * FancyMessage} is SHIFT-CLICKED. The client will not immediately send the command to the - * server to be executed unless the client player submits the command/chat message, usually with - * the enter key. - * - * @param command The text to append to the chat bar of the client. - * @return This builder instance. - */ - public FancyMessage insert(String command) { - onCurrent(m -> m.insertionData = command); - dirty = true; - return this; - } - - /** - * Set the behavior of the current editing component to instruct the client to send the - * specified string to the server as a chat message when the currently edited part of the {@code - * FancyMessage} is clicked. The client will immediately send the command to the server - * to be executed when the editing component is clicked. - * - * @param command The text to display in the chat bar of the client. - * @return This builder instance. - */ - public FancyMessage command(String command) { - onClick("run_command", command); - return this; - } - - /** - * Set the behavior of the current editing component to display raw text when the client hovers - * over the text. - *

Tooltips do not inherit display characteristics, such as color and styles, from the - * message component on which they are applied.

- * - * @param text The text, which supports newlines, which will be displayed to the client upon - * hovering. - * @return This builder instance. - */ - public FancyMessage tooltip(String text) { - onHover("show_text", new JsonString(text)); - return this; - } - - /** - * Set the behavior of the current editing component to display raw text when the client hovers - * over the text. - *

Tooltips do not inherit display characteristics, such as color and styles, from the - * message component on which they are applied.

- * - * @param lines The lines of text which will be displayed to the client upon hovering. The - * iteration order of this object will be the order in which the lines of the - * tooltip are created. - * @return This builder instance. - */ - public FancyMessage tooltip(Iterable lines) { - tooltip(ArrayWrapper.toArray(lines, String.class)); - return this; - } - - /** - * Set the behavior of the current editing component to display raw text when the client hovers - * over the text. - *

Tooltips do not inherit display characteristics, such as color and styles, from the - * message component on which they are applied.

- * - * @param lines The lines of text which will be displayed to the client upon hovering. - * @return This builder instance. - */ - public FancyMessage tooltip(String... lines) { - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < lines.length; i++) { - builder.append(lines[i]); - if (i != lines.length - 1) { - builder.append('\n'); - } - } - tooltip(builder.toString()); - return this; - } - - /** - * Set the behavior of the current editing component to display formatted text when the client - * hovers over the text. - *

Tooltips do not inherit display characteristics, such as color and styles, from the - * message component on which they are applied.

- * - * @param text The formatted text which will be displayed to the client upon hovering. - * @return This builder instance. - */ - public FancyMessage formattedTooltip(FancyMessage text) { - for (MessagePart component : text.messageParts) { - if (component.clickActionData != null && component.clickActionName != null) { - throw new IllegalArgumentException("The tooltip text cannot have click data."); - } else if (component.hoverActionData != null && component.hoverActionName != null) { - throw new IllegalArgumentException("The tooltip text cannot have a tooltip."); - } - } - onHover("show_text", text); - return this; - } - - /** - * Set the behavior of the current editing component to display the specified lines of formatted - * text when the client hovers over the text. - *

Tooltips do not inherit display characteristics, such as color and styles, from the - * message component on which they are applied.

- * - * @param lines The lines of formatted text which will be displayed to the client upon - * hovering. - * @return This builder instance. - */ - public FancyMessage formattedTooltip(FancyMessage... lines) { - if (lines.length < 1) { - onHover(null, null); // Clear tooltip - return this; - } - - FancyMessage result = new FancyMessage(); - result.messageParts - .clear(); // Remove the one existing text component that exists by default, which destabilizes the object - - for (int i = 0; i < lines.length; i++) { - try { - for (MessagePart component : lines[i]) { - if (component.clickActionData != null && component.clickActionName != null) { - throw new IllegalArgumentException( - "The tooltip text cannot have click data."); - } else if (component.hoverActionData != null - && component.hoverActionName != null) { - throw new IllegalArgumentException( - "The tooltip text cannot have a tooltip."); - } - if (component.hasText()) { - result.messageParts.add(component.clone()); - result.index = result.messageParts.size(); - } - } - if (i != lines.length - 1) { - result.messageParts.add(new MessagePart(rawText("\n"))); - result.index = result.messageParts.size(); - } - } catch (CloneNotSupportedException e) { - Bukkit.getLogger().log(Level.WARNING, "Failed to clone object", e); - return this; - } - } - return formattedTooltip( - result.messageParts.isEmpty() ? null : result); // Throws NPE if size is 0, intended - } - - /** - * Set the behavior of the current editing component to display the specified lines of formatted - * text when the client hovers over the text. - *

Tooltips do not inherit display characteristics, such as color and styles, from the - * message component on which they are applied.

- * - * @param lines The lines of text which will be displayed to the client upon hovering. The - * iteration order of this object will be the order in which the lines of the - * tooltip are created. - * @return This builder instance. - */ - public FancyMessage formattedTooltip(Iterable lines) { - return formattedTooltip(ArrayWrapper.toArray(lines, FancyMessage.class)); - } - - /** - * If the text is a translatable key, and it has replaceable values, this function can be used - * to set the replacements that will be used in the message. - * - * @param replacements The replacements, in order, that will be used in the language-specific - * message. - * @return This builder instance. - */ - public FancyMessage translationReplacements(String... replacements) { - for (String str : replacements) { - latest().translationReplacements.add(new JsonString(str)); - } - dirty = true; - - return this; - } - /* - - /** - * If the text is a translatable key, and it has replaceable values, this function can be used to set the replacements that will be used in the message. - * @param replacements The replacements, in order, that will be used in the language-specific message. - * @return This builder instance. - */ /* ------------ - public FancyMessage translationReplacements(final Iterable replacements){ - for(CharSequence str : replacements){ - latest().translationReplacements.add(new JsonString(str)); - } - - return this; - } - - */ - - /** - * If the text is a translatable key, and it has replaceable values, this function can be used - * to set the replacements that will be used in the message. - * - * @param replacements The replacements, in order, that will be used in the language-specific - * message. - * @return This builder instance. - */ - public FancyMessage translationReplacements(FancyMessage... replacements) { - Collections.addAll(latest().translationReplacements, replacements); - - dirty = true; - - return this; - } - - /** - * If the text is a translatable key, and it has replaceable values, this function can be used - * to set the replacements that will be used in the message. - * - * @param replacements The replacements, in order, that will be used in the language-specific - * message. - * @return This builder instance. - */ - public FancyMessage translationReplacements(Iterable replacements) { - return translationReplacements( - ArrayWrapper.toArray(replacements, FancyMessage.class)); - } - - /** - * Terminate construction of the current editing component, and begin construction of a new - * message component. After a successful call to this method, all setter methods will refer to a - * new message component, created as a result of the call to this method. - * - * @param text The text which will populate the new message component. - * @return This builder instance. - */ - public FancyMessage then(String text) { - return then(rawText(text)); - } - - private FancyMessage append(String text) { - if (!latest().hasText()) { - throw new IllegalStateException("previous message part has no text"); - } - MessagePart latest = latest(); - messageParts.add(new MessagePart(rawText(text))); - latest().color = latest.color; - latest().styles.addAll(latest.styles); - dirty = true; - return this; - } - - /** - * Terminate construction of the current editing component, and begin construction of a new - * message component. After a successful call to this method, all setter methods will refer to a - * new message component, created as a result of the call to this method. - * - * @param text The text which will populate the new message component. - * @return This builder instance. - */ - public FancyMessage then(TextualComponent text) { - if (!latest().hasText()) { - throw new IllegalStateException("previous message part has no text"); - } - messageParts.add(new MessagePart(text)); - index = messageParts.size(); - dirty = true; - return this; - } - - /** - * Terminate construction of the current editing component, and begin construction of a new - * message component. After a successful call to this method, all setter methods will refer to a - * new message component, created as a result of the call to this method. - * - * @return This builder instance. - */ - public FancyMessage then() { - if (!latest().hasText()) { - throw new IllegalStateException("previous message part has no text"); - } - messageParts.add(new MessagePart()); - index = messageParts.size(); - dirty = true; - return this; - } - - @Override - public void writeJson(JsonWriter writer) throws IOException { - if (messageParts.size() == 1) { - latest().writeJson(writer); - } else { - writer.beginObject().name("text").value("").name("extra").beginArray(); - for (MessagePart part : this) { - part.writeJson(writer); - } - writer.endArray().endObject(); - } - } - - /** - * Serialize this fancy message, converting it into syntactically-valid JSON using a {@link - * JsonWriter}. This JSON should be compatible with vanilla formatter commands such as {@code - * /tellraw}. - * - * @return The JSON string representing this object. - */ - public String toJSONString() { - if (!dirty && jsonString != null) { - return jsonString; - } - StringWriter string = new StringWriter(); - JsonWriter json = new JsonWriter(string); - try { - writeJson(json); - json.close(); - } catch (IOException e) { - throw new RuntimeException("invalid message"); - } - jsonString = string.toString(); - dirty = false; - return jsonString; - } - - /** - * Sends this message to a player. The player will receive the fully-fledged formatted display - * of this message. - * - * @param player The player who will receive the message. - */ - public void send(Player player) { - send(player, toJSONString()); - } - - private void send(CommandSender sender, String jsonString) { - if (!(sender instanceof Player)) { - sender.sendMessage(toOldMessageFormat()); - return; - } - Player player = (Player) sender; - try { - Object handle = Reflection.getHandle(player); - Object connection = Reflection.getField(handle.getClass(), "playerConnection") - .get(handle); - Reflection - .getMethod(connection.getClass(), "sendPacket", Reflection.getNMSClass("Packet")) - .invoke(connection, createChatPacket(jsonString)); - } catch (IllegalArgumentException e) { - Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e); - } catch (IllegalAccessException e) { - Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e); - } catch (InstantiationException e) { - Bukkit.getLogger().log(Level.WARNING, "Underlying class is abstract.", e); - } catch (InvocationTargetException e) { - Bukkit.getLogger() - .log(Level.WARNING, "A error has occurred during invoking of method.", e); - } catch (NoSuchMethodException e) { - Bukkit.getLogger().log(Level.WARNING, "Could not find method.", e); - } catch (ClassNotFoundException e) { - Bukkit.getLogger().log(Level.WARNING, "Could not find class.", e); - } - } - - // The ChatSerializer's instance of Gson - private static Object nmsChatSerializerGsonInstance; - private static Method fromJsonMethod; - - private Object createChatPacket(String json) - throws IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { - if (nmsChatSerializerGsonInstance == null) { - // Find the field and its value, completely bypassing obfuscation - Class chatSerializerClazz; - - // Get the three parts of the version string (major version is currently unused) - // vX_Y_RZ - // X = major - // Y = minor - // Z = revision - final String version = Reflection.getVersion(); - String[] split = version.substring(1, version.length() - 1) - .split("_"); // Remove trailing dot - //int majorVersion = Integer.parseInt(split[0]); - int minorVersion = Integer.parseInt(split[1]); - int revisionVersion = Integer.parseInt(split[2].substring(1)); // Substring to ignore R - - if (minorVersion < 8 || minorVersion == 8 && revisionVersion == 1) { - chatSerializerClazz = Reflection.getNMSClass("ChatSerializer"); - } else { - chatSerializerClazz = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); - } - - if (chatSerializerClazz == null) { - throw new ClassNotFoundException("Can't find the ChatSerializer class"); - } - - for (Field declaredField : chatSerializerClazz.getDeclaredFields()) { - if (Modifier.isFinal(declaredField.getModifiers()) && Modifier - .isStatic(declaredField.getModifiers()) && declaredField.getType().getName() - .endsWith("Gson")) { - // We've found our field - declaredField.setAccessible(true); - nmsChatSerializerGsonInstance = declaredField.get(null); - fromJsonMethod = nmsChatSerializerGsonInstance.getClass() - .getMethod("fromJson", String.class, Class.class); - break; - } - } - } - - // Since the method is so simple, and all the obfuscated methods have the same name, it's easier to reimplement 'IChatBaseComponent a(String)' than to reflectively call it - // Of course, the implementation may change, but fuzzy matches might break with signature changes - Object serializedChatComponent = fromJsonMethod.invoke(nmsChatSerializerGsonInstance, json, - Reflection.getNMSClass("IChatBaseComponent")); - - return nmsPacketPlayOutChatConstructor.newInstance(serializedChatComponent); - } - - /** - * Sends this message to a command sender. If the sender is a player, they will receive the - * fully-fledged formatted display of this message. Otherwise, they will receive a version of - * this message with less formatting. - * - * @param sender The command sender who will receive the message. - * @see #toOldMessageFormat() - */ - public void send(CommandSender sender) { - send(sender, toJSONString()); - } - - /** - * Sends this message to multiple command senders. - * - * @param senders The command senders who will receive the message. - * @see #send(CommandSender) - */ - public void send(Iterable senders) { - String string = toJSONString(); - for (CommandSender sender : senders) { - send(sender, string); - } - } - - /** - * Convert this message to a human-readable string with limited formatting. This method is used - * to send this message to clients without JSON formatting support. - *

- * Serialization of this message by using this message will include (in this order for each - * message part): - *

    - *
  1. The color of each message part.
  2. - *
  3. The applicable stylizations for each message part.
  4. - *
  5. The core text of the message part.
  6. - *
- * The primary omissions are tooltips and clickable actions. Consequently, this method should be used only as a last resort. - *

- *

- * Color and formatting can be removed from the returned string by using {@link ChatColor#stripColor(String)}.

- * - * @return A human-readable string representing limited formatting in addition to the core text - * of this message. - */ - public String toOldMessageFormat() { - StringBuilder result = new StringBuilder(); - for (MessagePart part : this) { - result.append(part.color == null ? "" : part.color); - for (ChatColor formatSpecifier : part.styles) { - result.append(formatSpecifier); - } - result.append(part.text); - } - return result.toString(); - } - - private void onCurrent(Consumer call) { - for (int i = index - 1; i < messageParts.size(); i++) { - call.accept(messageParts.get(i)); - } - } - - private MessagePart latest() { - return messageParts.get(messageParts.size() - 1); - } - - private void onClick(String name, String data) { - onCurrent(m -> { - m.clickActionName = name; - m.clickActionData = data; - }); - dirty = true; - } - - private void onHover(String name, JsonRepresentedObject data) { - onCurrent(m -> { - m.hoverActionName = name; - m.hoverActionData = data; - }); - dirty = true; - } - - // Doc copied from interface - @Override - public Map serialize() { - HashMap map = new HashMap<>(); - map.put("messageParts", messageParts); -// map.put("JSON", toJSONString()); - return map; - } - - /** - * Deserializes a JSON-represented message from a mapping of key-value pairs. This is called by - * the Bukkit serialization API. It is not intended for direct public API consumption. - * - * @param serialized The key-value mapping which represents a fancy message. - */ - @SuppressWarnings("unchecked") - public static FancyMessage deserialize(Map serialized) { - FancyMessage msg = new FancyMessage(); - msg.messageParts = (List) serialized.get("messageParts"); - msg.jsonString = serialized.containsKey("JSON") ? serialized.get("JSON").toString() : null; - msg.dirty = !serialized.containsKey("JSON"); - return msg; - } - - /** - * Internally called method. Not for API consumption. - */ - @Override - @NotNull - public Iterator iterator() { - return messageParts.iterator(); - } - - private static JsonParser _stringParser = new JsonParser(); - - /** - * Deserializes a fancy message from its JSON representation. This JSON representation is of the - * format of that returned by {@link #toJSONString()}, and is compatible with vanilla inputs. - * - * @param json The JSON string which represents a fancy message. - * @return A {@code FancyMessage} representing the parameterized JSON message. - */ - public static FancyMessage deserialize(String json) { - JsonObject serialized = _stringParser.parse(json).getAsJsonObject(); - JsonArray extra = serialized.getAsJsonArray("extra"); // Get the extra component - FancyMessage returnVal = new FancyMessage(); - returnVal.messageParts.clear(); - for (JsonElement mPrt : extra) { - MessagePart component = new MessagePart(); - JsonObject messagePart = mPrt.getAsJsonObject(); - for (Map.Entry entry : messagePart.entrySet()) { - // Deserialize text - if (TextualComponent.isTextKey(entry.getKey())) { - // The map mimics the YAML serialization, which has a "key" field and one or more "value" fields - Map serializedMapForm = new HashMap<>(); // Must be object due to Bukkit serializer API compliance - serializedMapForm.put("key", entry.getKey()); - if (entry.getValue().isJsonPrimitive()) { - // Assume string - serializedMapForm.put("value", entry.getValue().getAsString()); - } else { - // Composite object, but we assume each element is a string - for (Map.Entry compositeNestedElement : entry - .getValue().getAsJsonObject().entrySet()) { - serializedMapForm.put("value." + compositeNestedElement.getKey(), - compositeNestedElement.getValue().getAsString()); - } - } - component.text = TextualComponent.deserialize(serializedMapForm); - } else if (MessagePart.stylesToNames.inverse().containsKey(entry.getKey())) { - if (entry.getValue().getAsBoolean()) { - component.styles - .add(MessagePart.stylesToNames.inverse().get(entry.getKey())); - } - } else if (entry.getKey().equals("color")) { - component.color = ChatColor.valueOf(entry.getValue().getAsString().toUpperCase()); - } else if (entry.getKey().equals("clickEvent")) { - JsonObject object = entry.getValue().getAsJsonObject(); - component.clickActionName = object.get("action").getAsString(); - component.clickActionData = object.get("value").getAsString(); - } else if (entry.getKey().equals("hoverEvent")) { - JsonObject object = entry.getValue().getAsJsonObject(); - component.hoverActionName = object.get("action").getAsString(); - if (object.get("value").isJsonPrimitive()) { - // Assume string - component.hoverActionData = new JsonString( - object.get("value").getAsString()); - } else { - // Assume composite type - // The only composite type we currently store is another FancyMessage - // Therefore, recursion time! - component.hoverActionData = deserialize(object.get("value") - .toString() /* This should properly serialize the JSON object as a JSON string */); - } - } else if (entry.getKey().equals("insertion")) { - component.insertionData = entry.getValue().getAsString(); - } else if (entry.getKey().equals("with")) { - for (JsonElement object : entry.getValue().getAsJsonArray()) { - if (object.isJsonPrimitive()) { - component.translationReplacements - .add(new JsonString(object.getAsString())); - } else { - // Only composite type stored in this array is - again - FancyMessages - // Recurse within this function to parse this as a translation replacement - component.translationReplacements.add(deserialize(object.toString())); - } - } - } - } - returnVal.messageParts.add(component); - returnVal.index = returnVal.messageParts.size(); - } - return returnVal; - } - -} diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/MessagePart.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/MessagePart.java deleted file mode 100644 index 805ad0b9d..000000000 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/MessagePart.java +++ /dev/null @@ -1,156 +0,0 @@ -package com.boydti.fawe.bukkit.chat; - -import com.google.common.collect.BiMap; -import com.google.common.collect.ImmutableBiMap; -import com.google.gson.stream.JsonWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.configuration.serialization.ConfigurationSerializable; -import org.bukkit.configuration.serialization.ConfigurationSerialization; - -/** - * Internal class: Represents a component of a JSON-serializable {@link FancyMessage}. - */ -final class MessagePart implements JsonRepresentedObject, ConfigurationSerializable, Cloneable { - - ChatColor color = ChatColor.WHITE; - ArrayList styles = new ArrayList<>(); - String clickActionName = null; - String clickActionData = null; - String hoverActionName = null; - JsonRepresentedObject hoverActionData = null; - TextualComponent text = null; - String insertionData = null; - ArrayList translationReplacements = new ArrayList<>(); - - MessagePart(final TextualComponent text) { - this.text = text; - } - - MessagePart() { - this.text = null; - } - - boolean hasText() { - return text != null; - } - - @Override - @SuppressWarnings("unchecked") - public MessagePart clone() throws CloneNotSupportedException { - MessagePart obj = (MessagePart) super.clone(); - obj.styles = (ArrayList) styles.clone(); - if (hoverActionData instanceof JsonString) { - obj.hoverActionData = new JsonString(((JsonString) hoverActionData).getValue()); - } else if (hoverActionData instanceof FancyMessage) { - obj.hoverActionData = ((FancyMessage) hoverActionData).clone(); - } - obj.translationReplacements = (ArrayList) translationReplacements.clone(); - return obj; - - } - - static final BiMap stylesToNames; - - static { - ImmutableBiMap.Builder builder = ImmutableBiMap.builder(); - for (final ChatColor style : ChatColor.values()) { - if (!style.isFormat()) { - continue; - } - - String styleName; - switch (style) { - case MAGIC: - styleName = "obfuscated"; - break; - case UNDERLINE: - styleName = "underlined"; - break; - default: - styleName = style.name().toLowerCase(); - break; - } - - builder.put(style, styleName); - } - stylesToNames = builder.build(); - } - - public void writeJson(JsonWriter json) { - try { - json.beginObject(); - text.writeJson(json); - json.name("color").value(color.name().toLowerCase()); - for (final ChatColor style : styles) { - json.name(stylesToNames.get(style)).value(true); - } - if (clickActionName != null && clickActionData != null) { - json.name("clickEvent") - .beginObject() - .name("action").value(clickActionName) - .name("value").value(clickActionData) - .endObject(); - } - if (hoverActionName != null && hoverActionData != null) { - json.name("hoverEvent") - .beginObject() - .name("action").value(hoverActionName) - .name("value"); - hoverActionData.writeJson(json); - json.endObject(); - } - if (insertionData != null) { - json.name("insertion").value(insertionData); - } - if (translationReplacements.size() > 0 && text != null && TextualComponent.isTranslatableText(text)) { - json.name("with").beginArray(); - for (JsonRepresentedObject obj : translationReplacements) { - obj.writeJson(json); - } - json.endArray(); - } - json.endObject(); - } catch (IOException e) { - Bukkit.getLogger().log(Level.WARNING, "A problem occured during writing of JSON string", e); - } - } - - public Map serialize() { - HashMap map = new HashMap<>(); - map.put("text", text); - map.put("styles", styles); - map.put("color", color.getChar()); - map.put("hoverActionName", hoverActionName); - map.put("hoverActionData", hoverActionData); - map.put("clickActionName", clickActionName); - map.put("clickActionData", clickActionData); - map.put("insertion", insertionData); - map.put("translationReplacements", translationReplacements); - return map; - } - - @SuppressWarnings("unchecked") - public static MessagePart deserialize(Map serialized) { - MessagePart part = new MessagePart((TextualComponent) serialized.get("text")); - part.styles = (ArrayList) serialized.get("styles"); - part.color = ChatColor.getByChar(serialized.get("color").toString()); - part.hoverActionName = (String) serialized.get("hoverActionName"); - part.hoverActionData = (JsonRepresentedObject) serialized.get("hoverActionData"); - part.clickActionName = (String) serialized.get("clickActionName"); - part.clickActionData = (String) serialized.get("clickActionData"); - part.insertionData = (String) serialized.get("insertion"); - part.translationReplacements = (ArrayList) serialized.get("translationReplacements"); - return part; - } - - static { - ConfigurationSerialization.registerClass(MessagePart.class); - } - -} 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 30005a683..e1a1b36b9 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 @@ -26,7 +26,9 @@ import com.sk89q.worldedit.event.platform.Interaction; import com.sk89q.worldedit.extension.platform.PlatformManager; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.util.formatting.text.TextComponent.Builder; import java.lang.reflect.InvocationTargetException; +import java.net.URI; import java.util.List; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -59,7 +61,7 @@ public class CFIPacketListener implements Listener { // Direct digging to the virtual world registerBlockEvent(PacketType.Play.Client.BLOCK_DIG, false, new RunnableVal3() { @Override - public void run(PacketEvent event, VirtualWorld gen, BlockVector3 pt) { + public void run(Builder event, URI gen, String pt) { try { Player plr = event.getPlayer(); BlockVector3 realPos = pt.add(gen.getOrigin().toBlockPoint()); @@ -75,7 +77,7 @@ public class CFIPacketListener implements Listener { // Direct placing to the virtual world RunnableVal3 placeTask = new RunnableVal3() { @Override - public void run(PacketEvent event, VirtualWorld gen, BlockVector3 pt) { + public void run(Builder event, URI gen, String pt) { try { Player plr = event.getPlayer(); List hands = event.getPacket().getHands().getValues(); @@ -112,7 +114,7 @@ public class CFIPacketListener implements Listener { // Cancel block change packets where the real world overlaps with the virtual one registerBlockEvent(PacketType.Play.Server.BLOCK_CHANGE, false, new RunnableVal3() { @Override - public void run(PacketEvent event, VirtualWorld gen, BlockVector3 pt) { + public void run(Builder event, URI gen, String pt) { // Do nothing } }); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsOneFeature.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsOneFeature.java index eafcb7634..e1ec86f25 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsOneFeature.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsOneFeature.java @@ -3,7 +3,7 @@ package com.boydti.fawe.bukkit.regions; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.RegionWrapper; import com.boydti.fawe.regions.FaweMask; -import com.boydti.fawe.util.Perm; +import com.boydti.fawe.util.Permission; import com.massivecraft.factions.FLocation; import com.sk89q.worldedit.bukkit.BukkitAdapter; import org.bukkit.Chunk; @@ -30,7 +30,8 @@ public class FactionsOneFeature extends BukkitMaskManager implements Listener { public FaweMask getMask(final FawePlayer fp, MaskType type) { final Player player = fp.parent; final Chunk chunk = player.getLocation().getChunk(); - final boolean perm = Perm.hasPermission(FawePlayer.wrap(player), "fawe.factions.wilderness"); + final boolean perm = Permission + .hasPermission(fp.toWorldEditPlayer(), "fawe.factions.wilderness"); final World world = player.getWorld(); RegionWrapper locs = new RegionWrapper(chunk.getX(), chunk.getX(), chunk.getZ(), chunk.getZ()); @@ -40,7 +41,7 @@ public class FactionsOneFeature extends BukkitMaskManager implements Listener { if (this.isAdded(locs, world, player, perm, type)) { boolean hasPerm = true; - while (hasPerm && (count > 0)) { + while (hasPerm && count > 0) { count--; hasPerm = false; diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsUUIDFeature.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsUUIDFeature.java index 12f10ae66..c6f9e3bb2 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsUUIDFeature.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsUUIDFeature.java @@ -4,7 +4,7 @@ import com.boydti.fawe.bukkit.FaweBukkit; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.RegionWrapper; import com.boydti.fawe.regions.FaweMask; -import com.boydti.fawe.util.Perm; +import com.boydti.fawe.util.Permission; import com.massivecraft.factions.Board; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.Faction; @@ -28,7 +28,8 @@ public class FactionsUUIDFeature extends BukkitMaskManager implements Listener { public FaweMask getMask(final FawePlayer fp, MaskType type) { final Player player = fp.parent; final Chunk chunk = player.getLocation().getChunk(); - final boolean perm = Perm.hasPermission(FawePlayer.wrap(player), "fawe.factions.wilderness"); + final boolean perm = Permission + .hasPermission(fp.toWorldEditPlayer(), "fawe.factions.wilderness"); final World world = player.getWorld(); RegionWrapper locs = new RegionWrapper(chunk.getX(), chunk.getX(), chunk.getZ(), chunk.getZ()); @@ -38,7 +39,7 @@ public class FactionsUUIDFeature extends BukkitMaskManager implements Listener { if (this.isAdded(locs, world, player, perm, type)) { boolean hasPerm = true; - while (hasPerm && (count > 0)) { + while (hasPerm && count > 0) { count--; hasPerm = false; diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncSign.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncSign.java index 09ac437a4..74b4927e4 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncSign.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncSign.java @@ -1,15 +1,15 @@ package com.boydti.fawe.bukkit.wrapper.state; -import com.boydti.fawe.bukkit.chat.FancyMessage; import com.boydti.fawe.bukkit.wrapper.AsyncBlock; import com.boydti.fawe.bukkit.wrapper.AsyncBlockState; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; +import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer; +import com.sk89q.worldedit.util.formatting.text.serializer.legacy.LegacyComponentSerializer; import java.util.Map; - -import net.minecraft.server.v1_14_R1.TileEntitySign; import org.bukkit.DyeColor; import org.bukkit.block.Sign; import org.bukkit.persistence.PersistentDataContainer; @@ -37,18 +37,18 @@ public class AsyncSign extends AsyncBlockState implements Sign { private String fromJson(String jsonInput) { if (jsonInput == null || jsonInput.isEmpty()) return ""; - return FancyMessage.deserialize(jsonInput).toOldMessageFormat(); + return GsonComponentSerializer.INSTANCE.deserialize(jsonInput).toString(); } private String toJson(String oldInput) { if (oldInput == null || oldInput.isEmpty()) return ""; - return new FancyMessage("").color(oldInput).toJSONString(); + return LegacyComponentSerializer.INSTANCE.serialize(TextComponent.of(oldInput)); } @Override public String getLine(int index) throws IndexOutOfBoundsException { CompoundTag nbt = getNbtData(); - return nbt == null ? null : fromJson(nbt.getString("Text" + (index + 1))); + return nbt == null ? "" : fromJson(nbt.getString("Text" + (index + 1))); } @Override @@ -80,7 +80,7 @@ public class AsyncSign extends AsyncBlockState implements Sign { CompoundTag nbt = getNbtData(); if (nbt != null) { String color = nbt.getString("Color").toUpperCase(); - if (color != null) return DyeColor.valueOf(color); + return DyeColor.valueOf(color); } return DyeColor.BLACK; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java b/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java index 5f6378ca3..0832a9fdc 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java @@ -7,27 +7,39 @@ import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.brush.visualization.VisualQueue; import com.boydti.fawe.regions.general.plot.PlotSquaredFeature; -import com.boydti.fawe.util.*; -import com.boydti.fawe.util.chat.ChatManager; -import com.boydti.fawe.util.chat.PlainChatManager; +import com.boydti.fawe.util.CachedTextureUtil; +import com.boydti.fawe.util.CleanTextureUtil; +import com.boydti.fawe.util.FaweTimer; +import com.boydti.fawe.util.MainUtil; +import com.boydti.fawe.util.MemUtil; +import com.boydti.fawe.util.RandomTextureUtil; +import com.boydti.fawe.util.TaskManager; +import com.boydti.fawe.util.TextureUtil; +import com.boydti.fawe.util.WEManager; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.factory.DefaultTransformParser; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.session.request.Request; - -import javax.annotation.Nullable; -import javax.management.InstanceAlreadyExistsException; -import javax.management.NotificationEmitter; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.lang.management.ManagementFactory; import java.lang.management.MemoryMXBean; import java.lang.management.MemoryPoolMXBean; import java.lang.management.MemoryUsage; -import java.util.*; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Objects; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; - -import static com.google.common.base.Preconditions.checkNotNull; +import javax.annotation.Nullable; +import javax.management.InstanceAlreadyExistsException; +import javax.management.NotificationEmitter; /** * [ WorldEdit action] @@ -80,7 +92,6 @@ public class Fawe { private VisualQueue visualQueue; private TextureUtil textures; private DefaultTransformParser transformParser; - private ChatManager chatManager = new PlainChatManager(); private QueueHandler queueHandler; @@ -202,15 +213,6 @@ public class Fawe { return queueHandler; } - public ChatManager getChatManager() { - return chatManager; - } - - public void setChatManager(ChatManager chatManager) { - checkNotNull(chatManager); - this.chatManager = chatManager; - } - public DefaultTransformParser getTransformParser() { return transformParser; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkSet.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkSet.java index 35efd352a..9e34c4d4d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkSet.java @@ -16,8 +16,10 @@ import java.util.UUID; * Interface for setting blocks */ public interface IChunkSet extends IBlocks, OutputExtent { + @Override boolean setBiome(int x, int y, int z, BiomeType biome); + @Override boolean setBlock(int x, int y, int z, BlockStateHolder holder); boolean isEmpty(); 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 a94003ca8..66d7dcfda 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 @@ -59,11 +59,13 @@ public interface IQueueExtent extends Flushable, Trimable, Extent { */ > T submit(IChunk chunk); + @Override default boolean setBlock(final int x, final int y, final int z, final BlockStateHolder state) { final IChunk chunk = getCachedChunk(x >> 4, z >> 4); return chunk.setBlock(x & 15, y, z & 15, state); } + @Override default boolean setBiome(final int x, final int y, final int z, final BiomeType biome) { final IChunk chunk = getCachedChunk(x >> 4, z >> 4); return chunk.setBiome(x & 15, y, z & 15, biome); @@ -127,4 +129,4 @@ public interface IQueueExtent extends Flushable, Trimable, Extent { boolean isEmpty(); void sendChunk(int chunkX, int chunkZ, int bitMask); -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java b/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java index 60787f493..29125b3c4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java @@ -47,6 +47,7 @@ import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TextComponent.Builder; import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; +import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -354,7 +355,7 @@ public class CFICommands { floor(fp, BlockTypes.SNOW.getDefaultState().with(PropertyKey.LAYERS, 7), image, mask, disableWhiteOnly); main(fp, BlockTypes.SNOW_BLOCK, image, mask, disableWhiteOnly); smooth(fp, 1, 8, image, mask, disableWhiteOnly); - TextComponent.of("Added snow!").send(fp); + fp.toWorldEditPlayer().print(TextComponent.of("Added snow!")); assertSettings(fp).resetComponent(); component(fp); } @@ -383,17 +384,28 @@ public class CFICommands { @CommandPermissions("worldedit.anvil.cfi") public void paletteblocks(FawePlayer fp, Player player, LocalSession session, @Arg(name = "arg", desc = "String", def = "") String arg) throws EmptyClipboardException, InputParseException, FileNotFoundException { if (arg == null) { - TextComponent.of("What blocks do you want to color with?").append(newline()) - .text("[All]").cmdTip(alias() + " PaletteBlocks *").text(" - All available blocks") - .append(newline()) - .text("[Clipboard]").cmdTip(alias() + " PaletteBlocks #clipboard").text(" - The blocks in your clipboard") - .append(newline()) - .text("[List]").suggestTip(alias() + " PaletteBlocks stone,gravel").text(" - A comma separated list of blocks") - .append(newline()) - .text("[Complexity]").cmdTip(alias() + " Complexity").text(" - Block textures within a complexity range") - .append(newline()) - .text("< [Back]").cmdTip(alias() + " " + Commands.getAlias(CFICommands.class, "coloring")) - .send(fp); + TextComponent build = TextComponent.builder("What blocks do you want to color with?") + .append(newline()) + .append(TextComponent.of("[All]") + .clickEvent(ClickEvent.runCommand("/cfi PaletteBlocks *"))) + .append(" - All available blocks") + .append(newline()) + .append(TextComponent.of("[Clipboard]") + .clickEvent(ClickEvent.runCommand("/cfi PaletteBlocks #clipboard"))) + .append(" - The blocks in your clipboard") + .append(newline()) + .append(TextComponent.of("[List]") + .clickEvent(ClickEvent.runCommand("/cfi PaletteBlocks stone,gravel"))) + .append(" - A comma separated list of blocks") + .append(newline()) + .append(TextComponent.of("[Complexity]") + .clickEvent(ClickEvent.runCommand("/cfi Complexity"))) + .append(" - Block textures within a complexity range") + .append(newline()) + .append(TextComponent.of("< [Back]").clickEvent(ClickEvent + .runCommand("/cfi " + Commands.getAlias(CFICommands.class, "coloring")))) + .build(); + fp.toWorldEditPlayer().print(build); return; } HeightMapMCAGenerator generator = assertSettings(fp).getGenerator(); @@ -505,7 +517,7 @@ public class CFICommands { } else { gen.addSchems(load(imageMask), mask, multi.getHolders(), rarity, distance, rotate); } - TextComponent.of("Added schematics!").send(fp); + fp.toWorldEditPlayer().print(TextComponent.of("Added schematics!")); populate(fp); } @@ -527,7 +539,7 @@ public class CFICommands { } else { gen.setBiome(biome); } - TextComponent.of("Set biome!").send(fp); + fp.toWorldEditPlayer().print(TextComponent.of("Set biome!")); assertSettings(fp).resetComponent(); component(fp); } @@ -539,7 +551,7 @@ public class CFICommands { @CommandPermissions("worldedit.anvil.cfi") public void caves(FawePlayer fp) throws WorldEditException { assertSettings(fp).getGenerator().addCaves(); - TextComponent.of("Added caves!").send(fp); + fp.toWorldEditPlayer().print(TextComponent.of("Added caves!")); populate(fp); } @@ -580,7 +592,6 @@ public class CFICommands { gen.setHeights(Integer.parseInt(arg)); } fp.toWorldEditPlayer().print("Set Height!"); - TextComponent.of("Set height!").send(fp); component(fp); } @@ -592,7 +603,8 @@ public class CFICommands { public void waterId(FawePlayer fp, BlockStateHolder block) throws WorldEditException { CFISettings settings = assertSettings(fp); settings.getGenerator().setWaterId(block.getBlockType().getInternalId()); - TextComponent.of("Set water id!").send(fp); + + fp.toWorldEditPlayer().print("Set water id!"); settings.resetComponent(); component(fp); } @@ -606,7 +618,7 @@ public class CFICommands { public void baseId(FawePlayer fp, BlockStateHolder block) throws WorldEditException { CFISettings settings = assertSettings(fp); settings.getGenerator().setBedrockId(block.getBlockType().getInternalId()); - TextComponent.of("Set base id!").send(fp); + fp.toWorldEditPlayer().print(TextComponent.of("Set base id!")); settings.resetComponent(); component(fp); } @@ -620,7 +632,7 @@ public class CFICommands { @CommandPermissions("worldedit.anvil.cfi") public void worldthickness(FawePlayer fp, int height) throws WorldEditException { assertSettings(fp).getGenerator().setWorldThickness(height); - TextComponent.of("Set world thickness!").send(fp); + fp.toWorldEditPlayer().print(TextComponent.of("Set world thickness!")); component(fp); } @@ -633,7 +645,7 @@ public class CFICommands { @CommandPermissions("worldedit.anvil.cfi") public void floorthickness(FawePlayer fp, int height) throws WorldEditException { assertSettings(fp).getGenerator().setFloorThickness(height); - TextComponent.of("Set floor thickness!").send(fp); + fp.toWorldEditPlayer().print(TextComponent.of("Set floor thickness!")); component(fp); } @@ -645,7 +657,7 @@ public class CFICommands { @CommandPermissions("worldedit.anvil.cfi") public void update(FawePlayer fp) throws WorldEditException { assertSettings(fp).getGenerator().update(); - TextComponent.of("Chunks refreshed!").send(fp); + fp.toWorldEditPlayer().print(TextComponent.of("Chunks refreshed!")); mainMenu(fp); } @@ -657,7 +669,7 @@ public class CFICommands { @CommandPermissions("worldedit.anvil.cfi") public void tp(FawePlayer fp) throws WorldEditException { HeightMapMCAGenerator gen = assertSettings(fp).getGenerator(); - TextComponent.of("Teleporting...").send(fp); + fp.toWorldEditPlayer().print(TextComponent.of("Teleporting...")); Vector3 origin = gen.getOrigin(); Player player = fp.getPlayer(); player.setPosition(origin.subtract(16, 0, 16)); @@ -675,7 +687,7 @@ public class CFICommands { @CommandPermissions("worldedit.anvil.cfi") public void waterheight(FawePlayer fp, int height) throws WorldEditException { assertSettings(fp).getGenerator().setWaterHeight(height); - TextComponent.of("Set water height!").send(fp); + fp.toWorldEditPlayer().print(TextComponent.of("Set water height!")); component(fp); } @@ -689,7 +701,7 @@ public class CFICommands { public void glass(FawePlayer fp, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri imageMask, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly) throws WorldEditException { CFISettings settings = assertSettings(fp); settings.getGenerator().setColorWithGlass(load(image)); - TextComponent.of("Set color with glass!").send(fp); + fp.toWorldEditPlayer().print(TextComponent.of("Set color with glass!")); settings.resetColoring(); mainMenu(fp); } @@ -714,7 +726,7 @@ public class CFICommands { gen.setColor(load(image)); } settings.resetColoring(); - TextComponent.of("Set color with blocks!").send(fp); + fp.toWorldEditPlayer().print(TextComponent.of("Set color with blocks!")); mainMenu(fp); } @@ -730,7 +742,7 @@ public class CFICommands { public void blockbiome(FawePlayer fp, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri imageMask, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly) throws WorldEditException { CFISettings settings = assertSettings(fp); settings.getGenerator().setBlockAndBiomeColor(load(image), mask, load(imageMask), !disableWhiteOnly); - TextComponent.of("Set color with blocks and biomes!").send(fp); + fp.toWorldEditPlayer().print(TextComponent.of("Set color with blocks and biomes!")); settings.resetColoring(); mainMenu(fp); } @@ -746,7 +758,7 @@ public class CFICommands { public void biomecolor(FawePlayer fp, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri imageMask, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly) throws WorldEditException { CFISettings settings = assertSettings(fp); settings.getGenerator().setBiomeColor(load(image)); - TextComponent.of("Set color with biomes!").send(fp); + fp.toWorldEditPlayer().print(TextComponent.of("Set color with biomes!")); settings.resetColoring(); mainMenu(fp); } @@ -811,13 +823,12 @@ public class CFICommands { .append(newline()); if (settings.image != null) { - StringBuilder colorArgs = new StringBuilder(); - colorArgs.append(" " + settings.imageArg); + StringBuilder colorArgs = new StringBuilder(" " + settings.imageArg); if (settings.imageMask != null) { - colorArgs.append(" " + settings.imageMaskArg); + colorArgs.append(" ").append(settings.imageMaskArg); } if (settings.mask != null) { - colorArgs.append(" " + settings.maskArg); + colorArgs.append(" ").append(settings.maskArg); } if (!settings.whiteOnly) { colorArgs.append(" -w"); @@ -854,14 +865,26 @@ public class CFICommands { settings.maskArg = mask != null ? split[index++] : null; settings.whiteOnly = !disableWhiteOnly; - StringBuilder cmd = new StringBuilder(alias() + " mask "); + StringBuilder cmd = new StringBuilder("/cfi mask "); - TextComponent.of(">> Current Settings <<").append(newline()) - .text("Image Mask ").text("[" + settings.imageMaskArg + "]").suggestTip(cmd + "http://") + String s = "/cfi mask http://"; + String s1 = "/cfi mask "; + String s2 = alias() + " " + settings.getCategory(); + TextComponent build = TextComponent.builder(">> Current Settings <<") .append(newline()) - .text("WorldEdit Mask ").text("[" + settings.maskArg + "]").suggestTip(cmd + "") + .append("Image Mask ").append( + TextComponent.of("[" + settings.imageMaskArg + "]") + .hoverEvent(HoverEvent.showText(TextComponent.of(s))) + .clickEvent(ClickEvent.suggestCommand("/cfi mask http://"))) .append(newline()) - .text("< [Back]").cmdTip(alias() + " " + settings.getCategory()).send(fp); + .append("WorldEdit Mask ").append(TextComponent.of("[" + settings.maskArg + "]") + .hoverEvent(HoverEvent.showText(TextComponent.of(s1))) + .clickEvent(ClickEvent.suggestCommand(s1))) + .append(newline()) + .append( + TextComponent.of("< [Back]").hoverEvent(HoverEvent.showText(TextComponent.of(s2))) + .clickEvent(ClickEvent.runCommand(s2))).build(); + fp.toWorldEditPlayer().print(build); } @Command( @@ -881,10 +904,17 @@ public class CFICommands { if (pattern != null) { settings.getCategory().accept(fp); } else { - TextComponent.of(">> Current Settings <<").append(newline()) - .text("Pattern ").text("[Click Here]").suggestTip(cmd + " stone") - .append(newline()) - .text("< [Back]").cmdTip(alias() + " " + settings.getCategory()).send(fp); + String s = cmd + " stone"; + String s1 = alias() + " " + settings.getCategory(); + TextComponent build = TextComponent.builder(">> Current Settings <<").append(newline()) + .append("Pattern ").append(TextComponent.of("[Click Here]") + .hoverEvent(HoverEvent.showText(TextComponent.of(s))) + .clickEvent(ClickEvent.suggestCommand(s))) + .append(newline()) + .append(TextComponent.of("< [Back]") + .hoverEvent(HoverEvent.showText(TextComponent.of(s1))) + .clickEvent(ClickEvent.runCommand(s1))).build(); + fp.toWorldEditPlayer().print(build); } } @@ -917,13 +947,12 @@ public class CFICommands { settings.image = image; settings.imageArg = image != null ? split[index++] : null; - StringBuilder cmd = new StringBuilder(alias() + " image "); if (image == null) { TextComponent build = TextComponent.builder("Please provide an image:") .append(newline()) - .append("From a URL: ").append("[Click Here]")//TODO .suggestTip(cmd + "http://") + .append("From a URL: ").append(TextComponent.of("[Click Here]").clickEvent(ClickEvent.suggestCommand("/cfi image http://"))) .append(newline()) - .append("From a file: ").append("[Click Here]")//TODO .suggestTip(cmd + "file://") + .append("From a file: ").append(TextComponent.of("[Click Here]").clickEvent(ClickEvent.suggestCommand("/cfi image file://"))) .build(); fp.toWorldEditPlayer().print(build); } else { @@ -994,50 +1023,76 @@ public class CFICommands { String snow = Commands.getAlias(CFICommands.class, "snow"); //TODO -// Message msg = TextComponent.builder(">> Current Settings <<").append(newline()) -// .append("Mask ").append("[" + mask + "]").cmdTip(alias() + " mask") -// .append(newline()) -// .append("Pattern ").append("[" + pattern + "]").cmdTip(alias() + " pattern") -// .append(newline()) -// .append(newline()) -// .append(">> Components <<") -// .append(newline()) -// .append("[Height]").suggestTip(alias() + " " + alias("height") + " 120").text(" - Terrain height for whole map") -// .append(newline()) -// .text("[WaterHeight]").suggestTip(alias() + " " + alias("waterheight") + " 60").text(" - Sea level for whole map") -// .append(newline()) -// .text("[FloorThickness]").suggestTip(alias() + " " + alias("floorthickness") + " 60").text(" - Floor thickness of entire map") -// .append(newline()) -// .text("[WorldThickness]").suggestTip(alias() + " " + alias("worldthickness") + " 60").text(" - World thickness of entire map") -// .append(newline()) -// .text("[Snow]").suggestTip(alias() + " " + alias("snow") + maskArgs).text(" - Set snow in the masked areas") -// .append(newline()); -// -// if (pattern != null) { -// String disabled = "You must specify a pattern"; -// msg -// .text("[&cWaterId]").tooltip(disabled).append(newline()) -// .text("[&cBedrockId]").tooltip(disabled).append(newline()) -// .text("[&cFloor]").tooltip(disabled).append(newline()) -// .text("[&cMain]").tooltip(disabled).append(newline()) -// .text("[&cColumn]").tooltip(disabled).append(newline()) -// .text("[&cOverlay]").tooltip(disabled).append(newline()); -// } else { -// StringBuilder compArgs = new StringBuilder(); -// compArgs.append(" " + settings.patternArg + maskArgs); -// -// msg -// .text("[WaterId]").cmdTip(alias() + " waterId " + pattern).text(" - Water id for whole map").append(newline()) -// .text("[BedrockId]").cmdTip(alias() + " baseId " + pattern).text(" - Bedrock id for whole map").append(newline()) -// .text("[Floor]").cmdTip(alias() + " floor" + compArgs).text(" - Set the floor in the masked areas").append(newline()) -// .text("[Main]").cmdTip(alias() + " main" + compArgs).text(" - Set the main block in the masked areas").append(newline()) -// .text("[Column]").cmdTip(alias() + " column" + compArgs).text(" - Set the columns in the masked areas").append(newline()) -// .text("[Overlay]").cmdTip(alias() + " overlay" + compArgs).text(" - Set the overlay in the masked areas").append(newline()); -// } -// -// msg.append(newline()) -// .text("< [Back]").cmdTip(alias()) -// .send(fp); + @NonNull Builder msg = TextComponent.builder(">> Current Settings <<").append(newline()) + .append("Mask ").append(TextComponent.of("[" + mask + "]") + .hoverEvent(HoverEvent.showText(TextComponent.of(alias() + " mask"))) + .clickEvent(ClickEvent.runCommand(alias() + " mask"))) + .append(newline()) + .append("Pattern ").append(TextComponent.of("[" + pattern + "]") + .hoverEvent(HoverEvent.showText(TextComponent.of(alias() + " pattern"))) + .clickEvent(ClickEvent.runCommand(alias() + " pattern"))) + .append(newline()) + .append(newline()) + .append(">> Components <<") + .append(newline()) + .append(TextComponent.of("[Height]") + .hoverEvent(HoverEvent.showText(TextComponent.of(alias() + " " + alias("height") + " 120"))) + .clickEvent(ClickEvent.suggestCommand(alias() + " " + alias("height") + " 120"))).append(" - Terrain height for whole map") + .append(newline()) + .append(TextComponent.of("[WaterHeight]") + .hoverEvent(HoverEvent.showText(TextComponent.of(alias() + " " + alias("waterheight") + " 60"))) + .clickEvent(ClickEvent.suggestCommand(alias() + " " + alias("waterheight") + " 60"))).append(" - Sea level for whole map") + .append(newline()) + .append(TextComponent.of("[FloorThickness]").hoverEvent(HoverEvent.showText(TextComponent.of(alias() + " " + alias("floorthickness") + " 60"))) + .clickEvent(ClickEvent.suggestCommand(alias() + " " + alias("floorthickness") + " 60"))).append(" - Floor thickness of entire map") + .append(newline()) + .append(TextComponent.of("[WorldThickness]").hoverEvent(HoverEvent.showText(TextComponent.of(alias() + " " + alias("worldthickness") + " 60"))) + .clickEvent(ClickEvent.suggestCommand(alias() + " " + alias("worldthickness") + " 60"))).append(" - World thickness of entire map") + .append(newline()) + .append(TextComponent.of("[Snow]").hoverEvent(HoverEvent.showText(TextComponent.of(alias() + " " + alias("snow") + maskArgs))) + .clickEvent(ClickEvent.suggestCommand(alias() + " " + alias("snow") + maskArgs))).append(" - Set snow in the masked areas") + .append(newline()); + + if (pattern != null) { + String disabled = "You must specify a pattern"; + msg.append(TextComponent.of("[&cWaterId]").hoverEvent(HoverEvent.showText(TextComponent.of(disabled)))).append(newline()) + .append(TextComponent.of("[&cBedrockId]").hoverEvent(HoverEvent.showText(TextComponent.of(disabled)))).append(newline()).append(newline()) + .append(TextComponent.of("[&cFloor]").hoverEvent(HoverEvent.showText(TextComponent.of(disabled)))).append(newline()).append(newline()) + .append(TextComponent.of("[&cMain]").hoverEvent(HoverEvent.showText(TextComponent.of(disabled)))).append(newline()).append(newline()) + .append(TextComponent.of("[&cColumn]").hoverEvent(HoverEvent.showText(TextComponent.of(disabled)))).append(newline()).append(newline()) + .append(TextComponent.of("[&cOverlay]").hoverEvent(HoverEvent.showText(TextComponent.of(disabled)))).append(newline()).append(newline()); + } else { + StringBuilder compArgs = new StringBuilder(); + compArgs.append(" " + settings.patternArg + maskArgs); + + msg + .append(TextComponent.of("[WaterId]") + .hoverEvent(HoverEvent.showText(TextComponent.of(alias() + " waterId " + pattern))) + .clickEvent(ClickEvent.runCommand(alias() + " waterId " + pattern))) + .append(" - Water id for whole map") + .append(newline()) + .append(TextComponent.of("[BedrockId]") + .hoverEvent(HoverEvent.showText(TextComponent.of(alias() + " baseId " + pattern))) + .clickEvent(ClickEvent.runCommand(alias() + " baseId " + pattern))) + .append(TextComponent.of(" - Bedrock id for whole map")) + .append(newline()) + .append(TextComponent.of("[Floor]") + .hoverEvent(HoverEvent.showText(TextComponent.of(alias() + " floor " + compArgs))) + .clickEvent(ClickEvent.runCommand(alias() + " floor " + compArgs))) + .append(TextComponent.of(" - Set the floor in the masked areas")).append(newline()) + .append(TextComponent.of("[Main]") + .hoverEvent(HoverEvent.showText(TextComponent.of(alias() + " main " + compArgs))) + .clickEvent(ClickEvent.runCommand(alias() + " main " + compArgs))) + .append(TextComponent.of(" - Set the main block in the masked areas")).append(newline()) + .append(TextComponent.of("[Column]").hoverEvent(HoverEvent.showText(TextComponent.of(alias() + " column" + compArgs))) + .clickEvent(ClickEvent.runCommand(alias() + " column" + compArgs))).append(" - Set the columns in the masked areas").append(newline()) + .append(TextComponent.of("[Overlay]").hoverEvent(HoverEvent.showText(TextComponent.of(alias() + " overlay" + compArgs))) + .clickEvent(ClickEvent.runCommand(alias() + " overlay" + compArgs))).append(" - Set the overlay in the masked areas").append(newline()); + } + + msg.append(newline()) + .append(TextComponent.of("< [Back]").hoverEvent(HoverEvent.showText(TextComponent.of(alias()))).clickEvent(ClickEvent.runCommand(alias()))); + fp.toWorldEditPlayer().print(msg.build()); } private static CFISettings assertSettings(FawePlayer fp) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java b/worldedit-core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java index 6e5b83bc1..970c31c20 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java @@ -10,7 +10,6 @@ import com.boydti.fawe.object.task.AsyncNotifyQueue; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.TaskManager; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.world.World; import java.io.File; import java.io.IOException; @@ -50,7 +49,7 @@ public class RollbackDatabase extends AsyncNotifyQueue { this(FaweAPI.getWorld(world)); } - public RollbackDatabase(final World world) throws SQLException, ClassNotFoundException { + public RollbackDatabase(World world) throws SQLException, ClassNotFoundException { this.prefix = ""; this.worldName = world.getName(); this.world = world; @@ -96,7 +95,7 @@ public class RollbackDatabase extends AsyncNotifyQueue { } } - public void delete(final UUID uuid, final int id) { + public void delete(UUID uuid, int id) { addTask(new Runnable() { @Override public void run() { @@ -127,12 +126,13 @@ public class RollbackDatabase extends AsyncNotifyQueue { }); } - public void getPotentialEdits(final UUID uuid, final long minTime, final BlockVector3 pos1, final BlockVector3 pos2, final RunnableVal onEach, final Runnable whenDone, final boolean delete, final boolean ascending) { + public void getPotentialEdits(UUID uuid, long minTime, BlockVector3 pos1, BlockVector3 pos2, RunnableVal onEach, Runnable whenDone, boolean delete, boolean ascending) { final World world = FaweAPI.getWorld(this.worldName); addTask(new Runnable() { @Override public void run() { - String stmtStr = ascending ? (uuid == null ? GET_EDITS_ASC : GET_EDITS_USER_ASC) : (uuid == null ? GET_EDITS : GET_EDITS_USER); + String stmtStr = ascending ? uuid == null ? GET_EDITS_ASC : GET_EDITS_USER_ASC : + uuid == null ? GET_EDITS : GET_EDITS_USER; try (PreparedStatement stmt = connection.prepareStatement(stmtStr)) { stmt.setInt(1, pos1.getBlockX()); stmt.setInt(2, pos2.getBlockX()); @@ -243,7 +243,7 @@ public class RollbackDatabase extends AsyncNotifyQueue { } commit(); return true; - } catch (final Exception e) { + } catch (Exception e) { e.printStackTrace(); } return false; @@ -258,7 +258,7 @@ public class RollbackDatabase extends AsyncNotifyQueue { connection.commit(); connection.setAutoCommit(true); } - } catch (final SQLException e) { + } catch (SQLException e) { e.printStackTrace(); } } @@ -270,11 +270,11 @@ public class RollbackDatabase extends AsyncNotifyQueue { if (!Fawe.imp().getDirectory().exists()) { Fawe.imp().getDirectory().mkdirs(); } - if (!(dbLocation.exists())) { + if (!dbLocation.exists()) { try { dbLocation.getParentFile().mkdirs(); dbLocation.createNewFile(); - } catch (final IOException e) { + } catch (IOException e) { e.printStackTrace(); Fawe.debug("&cUnable to create database!"); } @@ -299,9 +299,7 @@ public class RollbackDatabase extends AsyncNotifyQueue { if (connection == null) { try { forceConnection(); - } catch (final ClassNotFoundException e) { - e.printStackTrace(); - } catch (final SQLException e) { + } catch (ClassNotFoundException | SQLException e) { e.printStackTrace(); } } @@ -312,7 +310,7 @@ public class RollbackDatabase extends AsyncNotifyQueue { * Closes the connection with the database * * @return true if successful - * @throws java.sql.SQLException if the connection cannot be closed + * @throws SQLException if the connection cannot be closed */ public boolean closeConnection() throws SQLException { if (connection == null) { @@ -332,12 +330,12 @@ public class RollbackDatabase extends AsyncNotifyQueue { * Checks if a connection is open with the database * * @return true if the connection is open - * @throws java.sql.SQLException if the connection cannot be checked + * @throws SQLException if the connection cannot be checked */ public boolean checkConnection() { try { - return (connection != null) && !connection.isClosed(); - } catch (final SQLException e) { + return connection != null && !connection.isClosed(); + } catch (SQLException e) { return false; } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/FawePlayer.java b/worldedit-core/src/main/java/com/boydti/fawe/object/FawePlayer.java index 8ecf06f30..d61ef443d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/FawePlayer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/FawePlayer.java @@ -108,7 +108,7 @@ public abstract class FawePlayer extends Metadatable { } @Deprecated - public FawePlayer(final T parent) { + public FawePlayer(T parent) { this.parent = parent; Fawe.get().register(this); if (Settings.IMP.CLIPBOARD.USE_DISK) { @@ -247,7 +247,7 @@ public abstract class FawePlayer extends Metadatable { * Queue an action to run async * @param run */ - public void queueAction(final Runnable run) { + public void queueAction(Runnable run) { runAction(run, false, true); } @@ -288,7 +288,7 @@ public abstract class FawePlayer extends Metadatable { * @param async * @return false if the task was ran or queued */ - public boolean runAction(final Runnable ifFree, boolean checkFree, boolean async) { + public boolean runAction(Runnable ifFree, boolean checkFree, boolean async) { if (checkFree) { if (runningCount.get() != 0) return false; } @@ -363,7 +363,7 @@ public abstract class FawePlayer extends Metadatable { * * @param world */ - public void loadSessionsFromDisk(final World world) { + public void loadSessionsFromDisk(World world) { if (world == null) { return; } @@ -417,14 +417,14 @@ public abstract class FawePlayer extends Metadatable { * @param perm * @return */ - public abstract boolean hasPermission(final String perm); + public abstract boolean hasPermission(String perm); /** * Send a message to the player * * @param message */ - public abstract void sendMessage(final String message); + public abstract void sendMessage(String message); /** * Print a WorldEdit error. @@ -438,7 +438,7 @@ public abstract class FawePlayer extends Metadatable { * * @param substring */ - public abstract void executeCommand(final String substring); + public abstract void executeCommand(String substring); /** * Get the player's location @@ -473,7 +473,7 @@ public abstract class FawePlayer extends Metadatable { public Region getSelection() { try { return this.getSession().getSelection(this.getPlayer().getWorld()); - } catch (final IncompleteRegionException e) { + } catch (IncompleteRegionException e) { return null; } } @@ -509,7 +509,7 @@ public abstract class FawePlayer extends Metadatable { * @param region */ @Deprecated - public void setSelection(final RegionWrapper region) { + public void setSelection(RegionWrapper region) { final Player player = this.getPlayer(); BlockVector3 top = region.getMaximumPoint(); top.withY(getWorld().getMaxY()); @@ -539,7 +539,7 @@ public abstract class FawePlayer extends Metadatable { * * @param selector */ - public void setSelection(final RegionSelector selector) { + public void setSelection(RegionSelector selector) { this.getSession().setRegionSelector(toWorldEditPlayer().getWorld(), selector); } @@ -551,7 +551,7 @@ public abstract class FawePlayer extends Metadatable { public Region getLargestRegion() { int area = 0; Region max = null; - for (final Region region : this.getCurrentRegions()) { + for (Region region : this.getCurrentRegions()) { final int tmp = region.getArea(); if (tmp > area) { area = tmp; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplatterBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplatterBrush.java index 094461bda..c6b4693d0 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplatterBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplatterBrush.java @@ -5,7 +5,6 @@ import com.boydti.fawe.object.mask.SurfaceMask; import com.boydti.fawe.object.pattern.BiomePattern; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; @@ -52,7 +51,6 @@ public class SplatterBrush extends ScatterBrush { } return false; }, vector -> editSession.setBlock(vector, finalPattern), recursion); - visitor.setMaxBranch(2); visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS)); visitor.visit(position); Operations.completeBlindly(visitor); 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 de3edc14b..99ec8c3d8 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 @@ -10,7 +10,6 @@ import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.entity.Player; -import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.MaskIntersection; import com.sk89q.worldedit.function.operation.Operations; @@ -21,7 +20,6 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.interpolation.Node; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; public class SplineBrush implements Brush, ResettableTool { @@ -50,7 +48,7 @@ public class SplineBrush implements Brush, ResettableTool { } @Override - public void build(EditSession editSession, final BlockVector3 position, Pattern pattern, double size) throws WorldEditException { + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws WorldEditException { Mask mask = editSession.getMask(); if (mask == null) { mask = new IdMask(editSession); @@ -70,12 +68,9 @@ public class SplineBrush implements Brush, ResettableTool { } final ArrayList points = new ArrayList<>(); if (size > 0) { - DFSRecursiveVisitor visitor = new DFSRecursiveVisitor(mask, new RegionFunction() { - @Override - public boolean apply(BlockVector3 p) { - points.add(p); - return true; - } + DFSRecursiveVisitor visitor = new DFSRecursiveVisitor(mask, p -> { + points.add(p); + return true; }, (int) size, 1); List directions = visitor.getDirections(); for (int x = -1; x <= 1; x++) { @@ -90,7 +85,7 @@ public class SplineBrush implements Brush, ResettableTool { } } } - Collections.sort(directions, (o1, o2) -> (int) Math.signum(o1.lengthSq() - o2.lengthSq())); + directions.sort((o1, o2) -> (int) Math.signum(o1.lengthSq() - o2.lengthSq())); visitor.visit(position); Operations.completeBlindly(visitor); if (points.size() > numSplines) { @@ -121,7 +116,7 @@ public class SplineBrush implements Brush, ResettableTool { final List nodes = new ArrayList<>(centroids.size()); - for (final Vector3 nodevector : centroids) { + for (Vector3 nodevector : centroids) { final Node n = new Node(nodevector); n.setTension(tension); n.setBias(bias); @@ -133,7 +128,7 @@ public class SplineBrush implements Brush, ResettableTool { List currentSpline = new ArrayList<>(); for (ArrayList points : positionSets) { int listSize = points.size(); - int index = (int) (i * listSize / (double) (numSplines)); + int index = (int) (i * listSize / (double) numSplines); currentSpline.add(points.get(index)); } editSession.drawSpline(pattern, currentSpline, 0, 0, 0, 10, 0, true); @@ -161,12 +156,10 @@ public class SplineBrush implements Brush, ResettableTool { private BlockVector3 normal(Collection points, BlockVector3 centroid) { int n = points.size(); switch (n) { - case 1: { + case 1: return null; - } - case 2: { + case 2: return null; - } } // Calc full 3x3 covariance matrix, excluding symmetries: @@ -179,9 +172,9 @@ public class SplineBrush implements Brush, ResettableTool { MutableVector3 r = new MutableVector3(); for (BlockVector3 p : points) { - r.mutX((p.getX() - centroid.getX())); - r.mutY((p.getY() - centroid.getY())); - r.mutZ((p.getZ() - centroid.getZ())); + r.mutX(p.getX() - centroid.getX()); + r.mutY(p.getY() - centroid.getY()); + r.mutZ(p.getZ() - centroid.getZ()); xx += r.getX() * r.getX(); xy += r.getX() * r.getY(); xz += r.getX() * r.getZ(); @@ -214,7 +207,6 @@ public class SplineBrush implements Brush, ResettableTool { double b = (xz * xy - yz * xx) / det_z; dir = BlockVector3.at(a, b, 1.0); } - ; return dir.normalize(); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/ImmutableVirtualWorld.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/ImmutableVirtualWorld.java index 456f29586..3c33bd6d0 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/ImmutableVirtualWorld.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/ImmutableVirtualWorld.java @@ -4,7 +4,6 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItemStack; -import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; @@ -14,8 +13,6 @@ import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.weather.WeatherType; -import com.sk89q.worldedit.world.weather.WeatherTypes; - import javax.annotation.Nullable; public abstract class ImmutableVirtualWorld implements VirtualWorld { @@ -34,12 +31,6 @@ public abstract class ImmutableVirtualWorld implements VirtualWorld { return BiomeTypes.FOREST; } - @Nullable - @Override - public Operation commit() { - return null; - } - @Override public String getName() { return Integer.toString(hashCode()); @@ -90,16 +81,6 @@ public abstract class ImmutableVirtualWorld implements VirtualWorld { unsupported(); } - @Override - public WeatherType getWeather() { - return WeatherTypes.CLEAR; - } - - @Override - public long getRemainingWeatherDuration() { - return 0; - } - @Override public void setWeather(WeatherType weatherType) { unsupported(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VirtualWorld.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VirtualWorld.java index be92b1ec6..864f9123b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VirtualWorld.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VirtualWorld.java @@ -17,11 +17,6 @@ import java.io.IOException; public interface VirtualWorld extends SimpleWorld, Closeable { Vector3 getOrigin(); - @Override - default BaseBlock getFullBlock(BlockVector3 position) { - return getBlock(position).toBaseBlock(); - } - @Override default BaseBlock getFullBlock(int x, int y, int z) { return getBlock(x, y, z).toBaseBlock(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VisualQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VisualQueue.java index b0e6d2bf3..8d4cec5e2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VisualQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VisualQueue.java @@ -6,7 +6,6 @@ import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.command.tool.BrushTool; import com.sk89q.worldedit.command.tool.Tool; -import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.entity.Player; public class VisualQueue extends SingleThreadIntervalQueue { @@ -17,7 +16,8 @@ public class VisualQueue extends SingleThreadIntervalQueue { @Override public void operate(FawePlayer fp) { - LocalSession session = fp.getSession(); + LocalSession session = WorldEdit.getInstance().getSessionManager() + .get(fp.toWorldEditPlayer()); Player player = fp.getPlayer(); Tool tool = session.getTool(player); if (tool instanceof BrushTool) { 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 304b9166a..050aeab02 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 @@ -1942,11 +1942,6 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr return false; } - @Override - public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, BlockVector3 position) throws MaxChangedBlocksException { - return false; - } - @Override public void dropItem(Vector3 position, BaseItemStack item) { // TODO Auto-generated method stub @@ -1970,4 +1965,4 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr // TODO Auto-generated method stub return null; } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java index 3e01457f9..e69c1c41a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java @@ -33,11 +33,6 @@ public class AbstractDelegateChangeSet extends FaweChangeSet { super.addChangeTask(queue); } - @Override - public boolean closeAsync() { - return super.closeAsync(); - } - @Override public boolean flush() { return parent.flush(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/AbstractDelegateFaweClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/AbstractDelegateFaweClipboard.java index 37c9de4dd..6d9bd9b52 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/AbstractDelegateFaweClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/AbstractDelegateFaweClipboard.java @@ -1,7 +1,6 @@ package com.boydti.fawe.object.clipboard; import com.boydti.fawe.jnbt.NBTStreamer; - import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; @@ -10,7 +9,6 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; - import java.util.List; public class AbstractDelegateFaweClipboard extends FaweClipboard { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java index 6544286a6..3eaab8e9d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java @@ -3,7 +3,6 @@ package com.boydti.fawe.object.clipboard; import com.boydti.fawe.jnbt.NBTStreamer; import com.boydti.fawe.object.IntegerTrio; import com.boydti.fawe.util.ReflectionUtils; - import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.Tag; @@ -16,7 +15,6 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; - import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -127,13 +125,14 @@ public class CPUOptimizedClipboard extends FaweClipboard { return BlockVector3.at(width, height, length); } - private int ylast; - private int ylasti; - private int zlast; - private int zlasti; + private int yLast; + private int yLastI; + private int zLast; + private int zLastI; public int getIndex(int x, int y, int z) { - return x + ((ylast == y) ? ylasti : (ylasti = (ylast = y) * area)) + ((zlast == z) ? zlasti : (zlasti = (zlast = z) * width)); + return x + ((yLast == y) ? yLastI : (yLastI = (yLast = y) * area)) + ((zLast == z) ? zLastI + : (zLastI = (zLast = z) * width)); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java index 1d86aa11b..7f581f4e1 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java @@ -9,9 +9,6 @@ import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.world.biome.BiomeTypes; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.Extent; @@ -19,10 +16,12 @@ import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.biome.BiomeTypes; +import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; - import java.io.Closeable; import java.io.File; import java.io.IOException; @@ -82,7 +81,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable { area = width * length; this.volume = length * width * height; - if ((braf.length() - HEADER_SIZE) == (volume << 2) + area) { + if (braf.length() - HEADER_SIZE == (volume << 2) + area) { hasBiomes = true; } autoCloseTask(); @@ -357,7 +356,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable { } @Override - public void forEach(final BlockReader task, boolean air) { + public void forEach(BlockReader task, boolean air) { byteBuffer.force(); int pos = HEADER_SIZE; IntegerTrio trio = new IntegerTrio(); @@ -418,7 +417,8 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable { } public int getIndex(int x, int y, int z) { - return x + ((ylast == y) ? ylasti : (ylasti = (ylast = y) * area)) + ((zlast == z) ? zlasti : (zlasti = (zlast = z) * width)); + return x + (ylast == y ? ylasti : (ylasti = (ylast = y) * area)) + (zlast == z + ? zlasti : (zlasti = (zlast = z) * width)); } @Override @@ -445,7 +445,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable { @Override public BaseBlock getBlock(int i) { try { - int diskIndex = (HEADER_SIZE) + (i << 2); + int diskIndex = HEADER_SIZE + (i << 2); int combinedId = byteBuffer.getInt(diskIndex); BlockType type = BlockTypes.getFromStateId(combinedId); BaseBlock base = type.withStateId(combinedId).toBaseBlock(); @@ -464,7 +464,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable { } else { // x + z * width + y * area; int y = i / area; - int newI = (i - (y * area)); + int newI = i - y * area; int z = newI / width; int x = newI - z * width; nbt = nbtMap.get(new IntegerTrio(x, y, z)); @@ -494,7 +494,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable { @Override public > boolean setBlock(int x, int y, int z, B block) { try { - int index = (HEADER_SIZE) + ((getIndex(x, y, z) << 2)); + int index = HEADER_SIZE + (getIndex(x, y, z) << 2); int combined = block.getInternalId(); byteBuffer.putInt(index, combined); boolean hasNbt = block instanceof BaseBlock && block.hasNbtData(); @@ -512,12 +512,12 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable { public > boolean setBlock(int i, B block) { try { int combined = block.getInternalId(); - int index = (HEADER_SIZE) + (i << 2); + int index = HEADER_SIZE + (i << 2); byteBuffer.putInt(index, combined); boolean hasNbt = block instanceof BaseBlock && block.hasNbtData(); if (hasNbt) { int y = i / area; - int newI = (i - (y * area)); + int newI = i - y * area; int z = newI / width; int x = newI - z * width; setTile(x, y, z, block.getNbtData()); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/EmptyClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/EmptyClipboard.java index 78d49acca..1cc2a0329 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/EmptyClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/EmptyClipboard.java @@ -1,25 +1,17 @@ package com.boydti.fawe.object.clipboard; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.entity.BaseEntity; -import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; -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.BlockTypes; -import javax.annotation.Nullable; -import java.util.Collections; -import java.util.List; - public class EmptyClipboard implements Clipboard { public static final EmptyClipboard INSTANCE = new EmptyClipboard(); @@ -56,22 +48,6 @@ public class EmptyClipboard implements Clipboard { return BlockVector3.ZERO; } - @Override - public List getEntities(Region region) { - return Collections.emptyList(); - } - - @Override - public List getEntities() { - return Collections.emptyList(); - } - - @Nullable - @Override - public Entity createEntity(Location location, BaseEntity entity) { - return null; - } - @Override public BaseBlock getFullBlock(BlockVector3 position) { return BlockTypes.AIR.getDefaultState().toBaseBlock(); @@ -97,9 +73,4 @@ public class EmptyClipboard implements Clipboard { return false; } - @Nullable - @Override - public Operation commit() { - return null; - } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/FaweClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/FaweClipboard.java index 1345c8d78..0aa777c2a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/FaweClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/FaweClipboard.java @@ -66,11 +66,11 @@ public abstract class FaweClipboard { > void run(int x, int y, int z, B block); } - public abstract void streamBiomes(final NBTStreamer.ByteReader task); + public abstract void streamBiomes(NBTStreamer.ByteReader task); - public void streamCombinedIds(final NBTStreamer.ByteReader task) { + public void streamCombinedIds(NBTStreamer.ByteReader task) { forEach(new BlockReader() { - private int index = 0; + private int index; @Override public > void run(int x, int y, int z, B block) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/LazyClipboardHolder.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/LazyClipboardHolder.java index 9542f5fc3..e7b9522c7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/LazyClipboardHolder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/LazyClipboardHolder.java @@ -5,7 +5,6 @@ import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; - import java.io.InputStream; import java.net.URI; import java.util.UUID; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java index d09521a10..7d36969d6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java @@ -5,27 +5,25 @@ import com.boydti.fawe.jnbt.NBTStreamer; import com.boydti.fawe.object.IntegerTrio; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.ReflectionUtils; - import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.world.biome.BiomeTypes; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.biome.BiomeTypes; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; -import net.jpountz.util.SafeUtils; - import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import net.jpountz.util.SafeUtils; public class MemoryOptimizedClipboard extends FaweClipboard { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MultiClipboardHolder.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MultiClipboardHolder.java index 1238f3f91..b9e3ad59d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MultiClipboardHolder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MultiClipboardHolder.java @@ -1,15 +1,18 @@ package com.boydti.fawe.object.clipboard; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.session.ClipboardHolder; import java.net.URI; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; - -import static com.google.common.base.Preconditions.checkNotNull; - public class MultiClipboardHolder extends URIClipboardHolder { private final List holders; private Clipboard[] cached; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java index 88c373a0a..7ad3a4fdc 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java @@ -1,7 +1,6 @@ package com.boydti.fawe.object.clipboard; import com.boydti.fawe.jnbt.NBTStreamer; - import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; @@ -11,7 +10,6 @@ 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.BlockStateHolder; - import java.util.List; public abstract class ReadOnlyClipboard extends FaweClipboard { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ResizableClipboardBuilder.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ResizableClipboardBuilder.java index 8406b71a5..a7b74771f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ResizableClipboardBuilder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ResizableClipboardBuilder.java @@ -4,15 +4,14 @@ import com.boydti.fawe.object.change.MutableBlockChange; import com.boydti.fawe.object.change.MutableTileChange; import com.boydti.fawe.object.changeset.MemoryOptimizedHistory; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.history.change.Change; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.World; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; - import java.util.Iterator; public class ResizableClipboardBuilder extends MemoryOptimizedHistory { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/URIClipboardHolder.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/URIClipboardHolder.java index 5ae4c0502..c583565b1 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/URIClipboardHolder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/URIClipboardHolder.java @@ -1,14 +1,13 @@ package com.boydti.fawe.object.clipboard; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.session.ClipboardHolder; import java.net.URI; import java.util.Collections; import java.util.Set; - -import static com.google.common.base.Preconditions.checkNotNull; - public class URIClipboardHolder extends ClipboardHolder { private final URI uri; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCutClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCutClipboard.java index c8512e8e8..7340f9959 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCutClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCutClipboard.java @@ -2,8 +2,8 @@ package com.boydti.fawe.object.clipboard; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; public class WorldCutClipboard extends WorldCopyClipboard { 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 b48c55f6e..328dd1106 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 @@ -5,9 +5,9 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.item.ItemTypes; import java.io.File; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/WikiScraper.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/WikiScraper.java index 80ef67d78..acbcba52f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/WikiScraper.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/WikiScraper.java @@ -2,12 +2,10 @@ package com.boydti.fawe.object.clipboard.remap; import com.boydti.fawe.util.MainUtil; - import com.google.common.io.Resources; import com.google.common.reflect.TypeToken; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; - import java.io.File; import java.io.IOException; import java.nio.charset.Charset; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/AdaptedSetCollection.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/AdaptedSetCollection.java index 0f0b33b7b..8b9a23663 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/AdaptedSetCollection.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/AdaptedSetCollection.java @@ -2,9 +2,6 @@ package com.boydti.fawe.object.collection; import com.google.common.base.Function; import com.google.common.collect.Collections2; -import org.jetbrains.annotations.NotNull; - -import javax.annotation.Nullable; import java.util.Collection; import java.util.Iterator; import java.util.Set; @@ -12,6 +9,7 @@ import java.util.Spliterator; import java.util.function.Consumer; import java.util.function.Predicate; import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; /** * Adapt a collection to a set @@ -67,6 +65,7 @@ public class AdaptedSetCollection implements Set { return adapted.toArray(a); } + @Override public boolean add(V v) { return adapted.add(v); } @@ -81,6 +80,7 @@ public class AdaptedSetCollection implements Set { return adapted.containsAll(c); } + @Override public boolean addAll(@NotNull Collection c) { return adapted.addAll(c); } @@ -90,6 +90,7 @@ public class AdaptedSetCollection implements Set { return adapted.removeAll(c); } + @Override public boolean removeIf(Predicate filter) { return adapted.removeIf(filter); } @@ -129,6 +130,7 @@ public class AdaptedSetCollection implements Set { return adapted.parallelStream(); } + @Override public void forEach(Consumer action) { adapted.forEach(action); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockSet.java index a96a8f340..0edf2c6bd 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockSet.java @@ -4,9 +4,6 @@ import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.AbstractRegion; import com.sk89q.worldedit.regions.RegionOperationException; -import com.sk89q.worldedit.world.World; - -import java.util.AbstractSet; import java.util.Iterator; import java.util.Set; @@ -34,6 +31,7 @@ public abstract class BlockSet extends AbstractRegion { } } + @Override public boolean contains(BlockVector3 obj) { return contains(obj.getX(), obj.getY(), obj.getZ()); } @@ -94,10 +92,15 @@ public abstract class BlockSet extends AbstractRegion { public abstract void set(int x, int y, int z); public abstract void clear(int x, int y, int z); public abstract boolean remove(int x, int y, int z); + @Override public abstract Iterator iterator(); + @Override public abstract Set getChunks(); + @Override public abstract Set getChunkCubes(); + @Override public abstract BlockVector3 getMaximumPoint(); + @Override public abstract BlockVector3 getMinimumPoint(); @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVectorSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVectorSet.java index 068b25c10..74dc46802 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVectorSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVectorSet.java @@ -19,7 +19,6 @@ import java.util.*; */ public class BlockVectorSet extends AbstractCollection implements Set { private Int2ObjectMap localSets = new Int2ObjectOpenHashMap<>(); - private MutableBlockVector3 mutable = new MutableBlockVector3(); @Override public int size() { 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 72f7583cb..d9b428f96 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 @@ -4,10 +4,9 @@ import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.MemUtil; -import com.boydti.fawe.util.Perm; +import com.boydti.fawe.util.Permission; import com.boydti.fawe.util.WEManager; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; @@ -27,7 +26,7 @@ public class MemoryCheckingExtent extends AbstractDelegateExtent { if (MemUtil.isMemoryLimited()) { if (this.player != null) { player.sendMessage(BBC.WORLDEDIT_CANCEL_REASON.format(BBC.WORLDEDIT_CANCEL_REASON_LOW_MEMORY.s())); - if (Perm.hasPermission(this.player, "worldedit.fast")) { + if (Permission.hasPermission(this.player.toWorldEditPlayer(), "worldedit.fast")) { BBC.WORLDEDIT_OOM_ADMIN.send(this.player); } } 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 3aa689ada..8965d7d4d 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 @@ -1,10 +1,8 @@ package com.boydti.fawe.object.extent; -import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.FaweLimit; import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.WEManager; - import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; @@ -12,7 +10,6 @@ import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; @@ -20,8 +17,6 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; -import java.util.List; - public class ProcessedWEExtent extends AbstractDelegateExtent { private final FaweLimit limit; private final AbstractDelegateExtent extent; @@ -48,21 +43,6 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { return super.createEntity(location, entity); } - @Override - public BiomeType getBiome(final BlockVector2 position) { - return super.getBiome(position); - } - - @Override - public List getEntities() { - return super.getEntities(); - } - - @Override - public List getEntities(final Region region) { - return super.getEntities(region); - } - @Override public BlockState getBlock(int x, int y, int z) { if (!limit.MAX_CHECKS()) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/io/AsyncBufferedOutputStream.java b/worldedit-core/src/main/java/com/boydti/fawe/object/io/AsyncBufferedOutputStream.java index 2559af7e5..10d150982 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/io/AsyncBufferedOutputStream.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/io/AsyncBufferedOutputStream.java @@ -36,7 +36,7 @@ public final class AsyncBufferedOutputStream extends FilterOutputStream { } /** - * Creates an asynchronous buffered output stream with defined buffersize and + * Creates an asynchronous buffered output stream with defined bufferSize and * 5 maximal buffers. */ public AsyncBufferedOutputStream(OutputStream out, int bufSize) { @@ -46,7 +46,7 @@ public final class AsyncBufferedOutputStream extends FilterOutputStream { /** * Creates an asynchronous buffered output stream. * - * @param out the outputstream to layer on. + * @param out the outputStream to layer on. * @param bufSize the buffer size. * @param maxBuffers the number of buffers to keep in parallel. */ @@ -179,4 +179,4 @@ public final class AsyncBufferedOutputStream extends FilterOutputStream { } } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/io/zstd/ZstdInputStream.java b/worldedit-core/src/main/java/com/boydti/fawe/object/io/zstd/ZstdInputStream.java index 1f3e94d3d..18a9d9aac 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/io/zstd/ZstdInputStream.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/io/zstd/ZstdInputStream.java @@ -1,12 +1,9 @@ package com.github.luben.zstd; -import java.io.InputStream; +import com.github.luben.zstd.util.Native; import java.io.FilterInputStream; import java.io.IOException; -import java.lang.IndexOutOfBoundsException; - -import com.github.luben.zstd.util.Native; -import com.github.luben.zstd.Zstd; +import java.io.InputStream; /** * InputStream filter that decompresses the data provided @@ -42,16 +39,13 @@ public class ZstdInputStream extends FilterInputStream { private native int initDStream(long stream); private native int decompressStream(long stream, byte[] dst, int dst_size, byte[] src, int src_size); - // The main constuctor / legacy version dispatcher + // The main constructor / legacy version dispatcher public ZstdInputStream(InputStream inStream) throws IOException { // FilterInputStream constructor super(inStream); // allocate input buffer with max frame header size src = new byte[srcBuffSize]; - if (src == null) { - throw new IOException("Error allocating the input buffer of size " + srcBuffSize); - } stream = createDStream(); int size = initDStream(stream); if (Zstd.isError(size)) { @@ -80,9 +74,9 @@ public class ZstdInputStream extends FilterInputStream { throw new IOException("Stream closed"); } - // guard agains buffer overflows + // guard against buffer overflows if (offset < 0 || len > dst.length - offset) { - throw new IndexOutOfBoundsException("Requested lenght " + len + throw new IndexOutOfBoundsException("Requested length " + len + " from offset " + offset + " in buffer of size " + dst.length); } int dstSize = offset + len; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java index 430651602..ad07972be 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java @@ -4,7 +4,6 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; - import java.util.Arrays; public class AngleMask extends SolidBlockMask implements ResettableMask { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BlockLightMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BlockLightMask.java index 815a7fc2c..618b5256b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BlockLightMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BlockLightMask.java @@ -3,11 +3,8 @@ package com.boydti.fawe.object.mask; import com.boydti.fawe.object.extent.LightingExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; -import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.math.BlockVector3; -import javax.annotation.Nullable; - public class BlockLightMask extends AbstractExtentMask { private final int min, max; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BrightnessMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BrightnessMask.java index 9b08f93c0..b8e274d1a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BrightnessMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BrightnessMask.java @@ -1,7 +1,6 @@ package com.boydti.fawe.object.mask; import com.boydti.fawe.object.extent.LightingExtent; - import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.math.BlockVector3; 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 b05ad4ef5..421e3c133 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 @@ -1,7 +1,6 @@ package com.boydti.fawe.object.mask; import com.sk89q.worldedit.world.block.BaseBlock; - import java.util.Set; // TODO FIXME diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdMask.java index 38b0d8b7c..c235e93c5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdMask.java @@ -2,11 +2,8 @@ package com.boydti.fawe.object.mask; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; -import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.math.BlockVector3; -import javax.annotation.Nullable; - public class IdMask extends AbstractExtentMask implements ResettableMask { private transient int id = -1; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/LightMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/LightMask.java index 8489124ec..c6debf87d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/LightMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/LightMask.java @@ -3,11 +3,8 @@ package com.boydti.fawe.object.mask; import com.boydti.fawe.object.extent.LightingExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; -import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.math.BlockVector3; -import javax.annotation.Nullable; - public class LightMask extends AbstractExtentMask { private final int min, max; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/MaskedTargetBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/MaskedTargetBlock.java index 8735343fd..88b94072e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/MaskedTargetBlock.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/MaskedTargetBlock.java @@ -33,6 +33,6 @@ public class MaskedTargetBlock extends TargetBlock { } } Location currentBlock = getCurrentBlock(); - return (currentBlock != null || !useLastBlock ? currentBlock : lastBlock); + return currentBlock != null || !useLastBlock ? currentBlock : lastBlock; } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/OpacityMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/OpacityMask.java index 8d35f884e..0a5dd7720 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/OpacityMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/OpacityMask.java @@ -3,11 +3,8 @@ package com.boydti.fawe.object.mask; import com.boydti.fawe.object.extent.LightingExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; -import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.math.BlockVector3; -import javax.annotation.Nullable; - public class OpacityMask extends AbstractExtentMask { private final int min, max; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/PlaneMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/PlaneMask.java index ba22cbe75..07227a34c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/PlaneMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/PlaneMask.java @@ -1,11 +1,8 @@ package com.boydti.fawe.object.mask; import com.sk89q.worldedit.function.mask.AbstractMask; -import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.math.BlockVector3; -import javax.annotation.Nullable; - /** * Restricts the */ diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ROCAngleMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ROCAngleMask.java index b1ecb4f02..de4c437fc 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ROCAngleMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ROCAngleMask.java @@ -10,22 +10,25 @@ public class ROCAngleMask extends AngleMask { @Override protected boolean testSlope(int x, int y, int z) { - double slope, tmp; - boolean aboveMin; + double tmp; lastY = y; int base = getHeight(x, y, z); - slope = ((getHeight(x + distance, y, z) - base) - (base - getHeight(x - distance, y, z))) * ADJACENT_MOD; + double slope = + (getHeight(x + distance, y, z) - base - (base - getHeight(x - distance, y, z))) + * ADJACENT_MOD; - tmp = ((getHeight(x, y, z + distance) - base) - (base - getHeight(x, y, z - distance))) * ADJACENT_MOD; + tmp = (getHeight(x, y, z + distance) - base - (base - getHeight(x, y, z - distance))) * ADJACENT_MOD; if (Math.abs(tmp) > Math.abs(slope)) slope = tmp; - tmp = ((getHeight(x + distance, y, z + distance) - base) - (base - getHeight(x - distance, y, z - distance))) * DIAGONAL_MOD; + tmp = (getHeight(x + distance, y, z + distance) - base - (base - getHeight(x - distance, y, + z - distance))) * DIAGONAL_MOD; if (Math.abs(tmp) > Math.abs(slope)) slope = tmp; - tmp = ((getHeight(x - distance, y, z + distance) - base) - (base - getHeight(x + distance, y, z - distance))) * DIAGONAL_MOD; + tmp = (getHeight(x - distance, y, z + distance) - base - (base - getHeight(x + distance, y, + z - distance))) * DIAGONAL_MOD; if (Math.abs(tmp) > Math.abs(slope)) slope = tmp; - return lastValue = (slope >= min && slope <= max); + return lastValue = slope >= min && slope <= max; } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RadiusMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RadiusMask.java index 0ece9ff56..46091a7e8 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RadiusMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RadiusMask.java @@ -1,11 +1,8 @@ package com.boydti.fawe.object.mask; import com.sk89q.worldedit.function.mask.AbstractMask; -import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.math.BlockVector3; -import javax.annotation.Nullable; - public class RadiusMask extends AbstractMask implements ResettableMask { private transient BlockVector3 pos; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RandomMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RandomMask.java index 265184db9..05de613cc 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RandomMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RandomMask.java @@ -2,7 +2,6 @@ package com.boydti.fawe.object.mask; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.math.BlockVector3; - import java.util.SplittableRandom; public class RandomMask extends AbstractMask implements ResettableMask { @@ -23,4 +22,4 @@ public class RandomMask extends AbstractMask implements ResettableMask { public void reset() { random = new SplittableRandom(); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SkyLightMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SkyLightMask.java index 3be2f710f..bd014ed71 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SkyLightMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SkyLightMask.java @@ -3,11 +3,8 @@ package com.boydti.fawe.object.mask; import com.boydti.fawe.object.extent.LightingExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; -import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.math.BlockVector3; -import javax.annotation.Nullable; - public class SkyLightMask extends AbstractExtentMask { private final int min, max; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SolidPlaneMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SolidPlaneMask.java index 144397237..a560f7dc1 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SolidPlaneMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SolidPlaneMask.java @@ -1,13 +1,10 @@ package com.boydti.fawe.object.mask; import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; -import javax.annotation.Nullable; - /** * Restricts the */ diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/XAxisMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/XAxisMask.java index 109eea2f3..ec61666f3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/XAxisMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/XAxisMask.java @@ -1,11 +1,8 @@ package com.boydti.fawe.object.mask; import com.sk89q.worldedit.function.mask.AbstractMask; -import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.math.BlockVector3; -import javax.annotation.Nullable; - /** * Restricts the */ diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ZAxisMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ZAxisMask.java index cf8c082df..28d315953 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ZAxisMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ZAxisMask.java @@ -1,11 +1,8 @@ package com.boydti.fawe.object.mask; import com.sk89q.worldedit.function.mask.AbstractMask; -import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.math.BlockVector3; -import javax.annotation.Nullable; - /** * Restricts the */ diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AbstractExtentPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AbstractExtentPattern.java index 1e6a8204f..47c63dd05 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AbstractExtentPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AbstractExtentPattern.java @@ -1,11 +1,10 @@ package com.boydti.fawe.object.pattern; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; - -import static com.google.common.base.Preconditions.checkNotNull; - public abstract class AbstractExtentPattern extends AbstractPattern { private transient final Extent extent; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AngleColorPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AngleColorPattern.java index d94340204..250bb00e2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AngleColorPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AngleColorPattern.java @@ -1,13 +1,11 @@ package com.boydti.fawe.object.pattern; -import com.boydti.fawe.beta.FilterBlock; import com.boydti.fawe.object.DataAnglePattern; import com.boydti.fawe.util.TextureHolder; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; @@ -69,4 +67,4 @@ public class AngleColorPattern extends DataAnglePattern { if (newBlock == null) return false; return set.setBlock(extent, newBlock.getDefaultState()); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AverageColorPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AverageColorPattern.java index 952b6a661..c6ef74ef2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AverageColorPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AverageColorPattern.java @@ -1,6 +1,5 @@ package com.boydti.fawe.object.pattern; -import com.boydti.fawe.Fawe; import com.boydti.fawe.util.TextureHolder; import com.boydti.fawe.util.TextureUtil; import com.sk89q.worldedit.WorldEditException; @@ -9,8 +8,6 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockType; import java.awt.Color; -import java.io.IOException; -import java.io.ObjectInputStream; public class AverageColorPattern extends AbstractExtentPattern { private transient TextureHolder holder; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BiomePattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BiomePattern.java index 1446feb74..7907dcb5b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BiomePattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BiomePattern.java @@ -1,14 +1,10 @@ package com.boydti.fawe.object.pattern; -import com.boydti.fawe.beta.FilterBlock; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.math.MutableBlockVector2; import com.sk89q.worldedit.world.biome.BiomeType; -import java.io.IOException; +import com.sk89q.worldedit.world.block.BaseBlock; public class BiomePattern extends ExistingPattern { private final BiomeType biome; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BufferedPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BufferedPattern.java index 9bfafc9c5..222d4553b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BufferedPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BufferedPattern.java @@ -1,20 +1,15 @@ package com.boydti.fawe.object.pattern; import com.boydti.fawe.Fawe; -import com.boydti.fawe.beta.FilterBlock; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.collection.LocalBlockVectorSet; import com.boydti.fawe.util.FaweTimer; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BlockStateHolder; - -import java.io.IOException; +import com.sk89q.worldedit.world.block.BaseBlock; import java.util.UUID; public class BufferedPattern extends AbstractPattern implements ResettablePattern { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/DataPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/DataPattern.java index 7b3b580d2..01f2d2b34 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/DataPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/DataPattern.java @@ -1,16 +1,13 @@ package com.boydti.fawe.object.pattern; -import com.boydti.fawe.beta.DelegateFilterBlock; -import com.boydti.fawe.beta.FilterBlock; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockStateHolder; - -import static com.google.common.base.Preconditions.checkNotNull; public class DataPattern extends AbstractExtentPattern { private final Pattern pattern; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/DesaturatePattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/DesaturatePattern.java index fca405051..57440ecd3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/DesaturatePattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/DesaturatePattern.java @@ -1,6 +1,5 @@ package com.boydti.fawe.object.pattern; -import com.boydti.fawe.Fawe; import com.boydti.fawe.util.TextureHolder; import com.boydti.fawe.util.TextureUtil; import com.sk89q.worldedit.WorldEditException; @@ -9,8 +8,6 @@ import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockType; -import java.io.IOException; -import java.io.ObjectInputStream; public class DesaturatePattern extends AbstractPattern { private final TextureHolder holder; @@ -40,8 +37,7 @@ public class DesaturatePattern extends AbstractPattern { int red = (int) (r + value * (l - r)); int green = (int) (g + value * (l - g)); int blue = (int) (b + value * (l - b)); - int newColor = (alpha << 24) + (red << 16) + (green << 8) + (blue << 0); - return newColor; + return (alpha << 24) + (red << 16) + (green << 8) + (blue << 0); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ExistingPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ExistingPattern.java index 35f5299c9..bd81d765a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ExistingPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ExistingPattern.java @@ -1,10 +1,9 @@ package com.boydti.fawe.object.pattern; -import com.boydti.fawe.beta.FilterBlock; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.block.BaseBlock; public class ExistingPattern extends AbstractExtentPattern { public ExistingPattern(Extent extent) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ExpressionPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ExpressionPattern.java index 36500403b..300da2a5e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ExpressionPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ExpressionPattern.java @@ -1,20 +1,17 @@ package com.boydti.fawe.object.pattern; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.ExpressionException; import com.sk89q.worldedit.internal.expression.runtime.EvaluationException; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment; +import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; -import java.io.IOException; - - -import static com.google.common.base.Preconditions.checkNotNull; - /** * A mask that evaluates an expression. *

diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/FullClipboardPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/FullClipboardPattern.java index 8e234a9b4..7d77cf65e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/FullClipboardPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/FullClipboardPattern.java @@ -1,8 +1,8 @@ package com.boydti.fawe.object.pattern; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.mask.ExistingBlockMask; @@ -10,13 +10,10 @@ import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; -import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.world.block.BaseBlock; import java.io.IOException; import java.io.NotSerializableException; - -import static com.google.common.base.Preconditions.checkNotNull; - /** * A pattern that reads from {@link Clipboard}. */ @@ -51,4 +48,4 @@ public class FullClipboardPattern extends AbstractExtentPattern { private void writeObject(java.io.ObjectOutputStream stream) throws IOException { throw new NotSerializableException("Clipboard cannot be serialized!"); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/IdDataMaskPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/IdDataMaskPattern.java index 65a15f1c7..937376e6c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/IdDataMaskPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/IdDataMaskPattern.java @@ -1,13 +1,9 @@ package com.boydti.fawe.object.pattern; -import com.boydti.fawe.FaweCache; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BlockStateHolder; -import com.sk89q.worldedit.world.block.BlockTypes; +import com.sk89q.worldedit.world.block.BaseBlock; public class IdDataMaskPattern extends AbstractExtentPattern { private final Pattern pattern; @@ -27,4 +23,4 @@ public class IdDataMaskPattern extends AbstractExtentPattern { int newData = newBlock.getInternalPropertiesId() + oldData - (oldData & bitMask); return newBlock.withPropertyId(newData).toBaseBlock(); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/Linear2DBlockPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/Linear2DBlockPattern.java index 681b96892..5442510f9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/Linear2DBlockPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/Linear2DBlockPattern.java @@ -1,14 +1,11 @@ package com.boydti.fawe.object.pattern; -import com.boydti.fawe.beta.FilterBlock; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BlockStateHolder; +import com.sk89q.worldedit.world.block.BaseBlock; public class Linear2DBlockPattern extends AbstractPattern { @@ -35,4 +32,4 @@ public class Linear2DBlockPattern extends AbstractPattern { } return patternsArray[index].apply(extent, get, set); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/Linear3DBlockPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/Linear3DBlockPattern.java index 843d07c8e..cbf7d0002 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/Linear3DBlockPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/Linear3DBlockPattern.java @@ -1,14 +1,11 @@ package com.boydti.fawe.object.pattern; -import com.boydti.fawe.beta.FilterBlock; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BlockStateHolder; +import com.sk89q.worldedit.world.block.BaseBlock; public class Linear3DBlockPattern extends AbstractPattern { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/LinearBlockPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/LinearBlockPattern.java index 7cfd81991..078ee6db2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/LinearBlockPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/LinearBlockPattern.java @@ -1,13 +1,11 @@ package com.boydti.fawe.object.pattern; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BlockStateHolder; +import com.sk89q.worldedit.world.block.BaseBlock; public class LinearBlockPattern extends AbstractPattern implements ResettablePattern { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/MaskedPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/MaskedPattern.java index 4858a92b5..6eadf7ffd 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/MaskedPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/MaskedPattern.java @@ -1,16 +1,12 @@ package com.boydti.fawe.object.pattern; -import com.boydti.fawe.beta.FilterBlock; -import com.boydti.fawe.beta.SingleFilterBlock; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BlockStateHolder; +import com.sk89q.worldedit.world.block.BaseBlock; public class MaskedPattern extends AbstractPattern { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoXPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoXPattern.java index 93cf0f550..6b1cbde66 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoXPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoXPattern.java @@ -1,18 +1,12 @@ package com.boydti.fawe.object.pattern; -import com.boydti.fawe.beta.DelegateFilterBlock; -import com.boydti.fawe.beta.FilterBlock; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; -import com.sk89q.worldedit.world.block.BlockStateHolder; - -import java.io.IOException; +import com.sk89q.worldedit.world.block.BaseBlock; public class NoXPattern extends AbstractPattern { @@ -25,15 +19,15 @@ public class NoXPattern extends AbstractPattern { @Override public BaseBlock apply(BlockVector3 pos) { - mutable.mutY((pos.getY())); - mutable.mutZ((pos.getZ())); + mutable.mutY(pos.getY()); + mutable.mutZ(pos.getZ()); return pattern.apply(mutable); } @Override public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException { - mutable.mutY((get.getY())); - mutable.mutZ((get.getZ())); + mutable.mutY(get.getY()); + mutable.mutZ(get.getZ()); return pattern.apply(extent, mutable, set); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoYPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoYPattern.java index cd16b7c47..27de98222 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoYPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoYPattern.java @@ -19,15 +19,15 @@ public class NoYPattern extends AbstractPattern { @Override public BaseBlock apply(BlockVector3 pos) { - mutable.mutX((pos.getX())); - mutable.mutZ((pos.getZ())); + mutable.mutX(pos.getX()); + mutable.mutZ(pos.getZ()); return pattern.apply(mutable); } @Override public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException { - mutable.mutX((get.getX())); - mutable.mutZ((get.getZ())); + mutable.mutX(get.getX()); + mutable.mutZ(get.getZ()); return pattern.apply(extent, mutable, set); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoZPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoZPattern.java index e01894ae4..eb875c268 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoZPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoZPattern.java @@ -1,18 +1,12 @@ package com.boydti.fawe.object.pattern; -import com.boydti.fawe.beta.DelegateFilterBlock; -import com.boydti.fawe.beta.FilterBlock; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; -import com.sk89q.worldedit.world.block.BlockStateHolder; - -import java.io.IOException; +import com.sk89q.worldedit.world.block.BaseBlock; public class NoZPattern extends AbstractPattern { @@ -26,15 +20,15 @@ public class NoZPattern extends AbstractPattern { @Override public BaseBlock apply(BlockVector3 pos) { - mutable.mutX((pos.getX())); - mutable.mutY((pos.getY())); + mutable.mutX(pos.getX()); + mutable.mutY(pos.getY()); return pattern.apply(mutable); } @Override public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException { - mutable.mutX((get.getX())); - mutable.mutY((get.getY())); + mutable.mutX(get.getX()); + mutable.mutY(get.getY()); return pattern.apply(extent, mutable, set); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/OffsetPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/OffsetPattern.java index bc53d1864..366f17bc7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/OffsetPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/OffsetPattern.java @@ -1,17 +1,12 @@ package com.boydti.fawe.object.pattern; -import com.boydti.fawe.beta.FilterBlock; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; -import com.sk89q.worldedit.world.block.BlockStateHolder; - -import java.io.IOException; +import com.sk89q.worldedit.world.block.BaseBlock; public class OffsetPattern extends AbstractPattern { @@ -28,17 +23,17 @@ public class OffsetPattern extends AbstractPattern { @Override public BaseBlock apply(BlockVector3 position) { - mutable.mutX((position.getX() + dx)); - mutable.mutY((position.getY() + dy)); - mutable.mutZ((position.getZ() + dz)); + mutable.mutX(position.getX() + dx); + mutable.mutY(position.getY() + dy); + mutable.mutZ(position.getZ() + dz); return pattern.apply(mutable); } @Override public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException { - mutable.mutX((get.getX() + dx)); - mutable.mutY((get.getY() + dy)); - mutable.mutZ((get.getZ() + dz)); + mutable.mutX(get.getX() + dx); + mutable.mutY(get.getY() + dy); + mutable.mutZ(get.getZ() + dz); return pattern.apply(extent, get, mutable); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PropertyPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PropertyPattern.java index cb2ee7301..1aac6b20a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PropertyPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PropertyPattern.java @@ -1,12 +1,10 @@ package com.boydti.fawe.object.pattern; -import com.boydti.fawe.beta.FilterBlock; import com.boydti.fawe.object.string.MutableCharSequence; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.StringMan; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.WorldEditException; - import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.AbstractProperty; @@ -17,7 +15,6 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; - import java.util.ArrayList; import java.util.List; @@ -173,7 +170,7 @@ public class PropertyPattern extends AbstractExtentPattern { last = i + 1; break; } - default: { + default: Operator tmp = getOp(c); if (tmp != null) { operator = tmp; @@ -186,7 +183,6 @@ public class PropertyPattern extends AbstractExtentPattern { last = i + 1; } break; - } } } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RandomFullClipboardPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RandomFullClipboardPattern.java index d58548a2c..53a8f473e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RandomFullClipboardPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RandomFullClipboardPattern.java @@ -1,8 +1,9 @@ package com.boydti.fawe.object.pattern; +import static com.google.common.base.Preconditions.checkNotNull; + import com.boydti.fawe.object.schematic.Schematic; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.pattern.AbstractPattern; @@ -12,12 +13,10 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.session.ClipboardHolder; +import com.sk89q.worldedit.world.block.BaseBlock; import java.util.List; import java.util.concurrent.ThreadLocalRandom; - -import static com.google.common.base.Preconditions.checkNotNull; - public class RandomFullClipboardPattern extends AbstractPattern { private final Extent extent; private final MutableBlockVector3 mutable = new MutableBlockVector3(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RandomOffsetPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RandomOffsetPattern.java index d43d2a416..862a4cf02 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RandomOffsetPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RandomOffsetPattern.java @@ -1,15 +1,12 @@ package com.boydti.fawe.object.pattern; -import com.boydti.fawe.beta.FilterBlock; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; - -import java.io.IOException; +import com.sk89q.worldedit.world.block.BaseBlock; import java.util.SplittableRandom; public class RandomOffsetPattern extends AbstractPattern { @@ -47,4 +44,4 @@ public class RandomOffsetPattern extends AbstractPattern { mutable.mutZ((set.getZ() + r.nextInt(dz2) - dz)); return pattern.apply(extent, get, mutable); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RelativePattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RelativePattern.java index 4900a5317..74f447a30 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RelativePattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RelativePattern.java @@ -1,15 +1,12 @@ package com.boydti.fawe.object.pattern; -import com.boydti.fawe.beta.FilterBlock; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; - -import java.io.IOException; +import com.sk89q.worldedit.world.block.BaseBlock; public class RelativePattern extends AbstractPattern implements ResettablePattern { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SaturatePattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SaturatePattern.java index d9b4730b0..19975c2fd 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SaturatePattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SaturatePattern.java @@ -1,7 +1,5 @@ package com.boydti.fawe.object.pattern; -import com.boydti.fawe.Fawe; -import com.boydti.fawe.beta.FilterBlock; import com.boydti.fawe.util.TextureHolder; import com.boydti.fawe.util.TextureUtil; import com.sk89q.worldedit.WorldEditException; @@ -11,8 +9,6 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockType; import java.awt.Color; -import java.io.IOException; -import java.io.ObjectInputStream; public class SaturatePattern extends AbstractPattern { private final TextureHolder holder; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SolidRandomOffsetPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SolidRandomOffsetPattern.java index b5ab2fd4c..f53b2dd87 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SolidRandomOffsetPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SolidRandomOffsetPattern.java @@ -1,19 +1,15 @@ package com.boydti.fawe.object.pattern; -import com.boydti.fawe.beta.FilterBlock; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; - -import java.io.IOException; import java.util.SplittableRandom; public class SolidRandomOffsetPattern extends AbstractPattern { @@ -47,27 +43,25 @@ public class SolidRandomOffsetPattern extends AbstractPattern { @Override public BaseBlock apply(BlockVector3 position) { - mutable.mutX((position.getX() + r.nextInt(dx2) - dx)); - mutable.mutY((position.getY() + r.nextInt(dy2) - dy)); - mutable.mutZ((position.getZ() + r.nextInt(dz2) - dz)); + mutable.mutX(position.getX() + r.nextInt(dx2) - dx); + mutable.mutY(position.getY() + r.nextInt(dy2) - dy); + mutable.mutZ(position.getZ() + r.nextInt(dz2) - dz); BaseBlock block = pattern.apply(mutable); if (block.getMaterial().isSolid()) { return block; - } else { - return pattern.apply(position); } + return pattern.apply(position); } @Override public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException { - mutable.mutX((set.getX() + r.nextInt(dx2) - dx)); - mutable.mutY((set.getY() + r.nextInt(dy2) - dy)); - mutable.mutZ((set.getZ() + r.nextInt(dz2) - dz)); + mutable.mutX(set.getX() + r.nextInt(dx2) - dx); + mutable.mutY(set.getY() + r.nextInt(dy2) - dy); + mutable.mutZ(set.getZ() + r.nextInt(dz2) - dz); BlockStateHolder block = pattern.apply(mutable); if (block.getMaterial().isSolid()) { return pattern.apply(extent, get, mutable); - } else { - return pattern.apply(extent, get, set); } + return pattern.apply(extent, get, set); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SurfaceRandomOffsetPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SurfaceRandomOffsetPattern.java index 43dfb4acc..7af3cba67 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SurfaceRandomOffsetPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SurfaceRandomOffsetPattern.java @@ -16,7 +16,6 @@ public class SurfaceRandomOffsetPattern extends AbstractPattern { private final MutableBlockVector3 cur; private final MutableBlockVector3[] buffer; private final MutableBlockVector3[] allowed; - private MutableBlockVector3 next; public SurfaceRandomOffsetPattern(Pattern pattern, int distance) { this.pattern = pattern; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/FuzzyRegionSelector.java b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/FuzzyRegionSelector.java index 561b106a5..006f0527d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/FuzzyRegionSelector.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/FuzzyRegionSelector.java @@ -155,7 +155,7 @@ public class FuzzyRegionSelector extends AbstractDelegateExtent implements Regio } @Override - public List getVerticies() { + public List getVertices() { return positions; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/PolyhedralRegionSelector.java b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/PolyhedralRegionSelector.java index c028caa26..6ea78e09a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/PolyhedralRegionSelector.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/PolyhedralRegionSelector.java @@ -230,7 +230,7 @@ public class PolyhedralRegionSelector implements RegionSelector, CUIRegion { } @Override - public List getVerticies() { + public List getVertices() { return new ArrayList<>(region.getVertices()); } } 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 6029d2b85..70cdc7498 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 @@ -3,8 +3,14 @@ package com.boydti.fawe.object.schematic; import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.util.ReflectionUtils; - -import com.sk89q.jnbt.*; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.IntTag; +import com.sk89q.jnbt.ListTag; +import com.sk89q.jnbt.NBTInputStream; +import com.sk89q.jnbt.NBTOutputStream; +import com.sk89q.jnbt.NamedTag; +import com.sk89q.jnbt.StringTag; +import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; @@ -26,8 +32,6 @@ import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.entity.EntityTypes; import com.sk89q.worldedit.world.storage.NBTConversions; import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; -import org.jetbrains.annotations.NotNull; - import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -35,6 +39,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; +import org.jetbrains.annotations.NotNull; public class MinecraftStructure implements ClipboardReader, ClipboardWriter { private static final int WARN_SIZE = 32; @@ -73,7 +78,7 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter { // Init clipboard BlockVector3 origin = BlockVector3.at(0, 0, 0); CuboidRegion region = new CuboidRegion(origin, origin.add(width, height, length).subtract(BlockVector3.ONE)); - BlockArrayClipboard clipboard = new BlockArrayClipboard(region, clipboardId); + Clipboard clipboard = new BlockArrayClipboard(region, clipboardId); // Blocks ListTag blocks = (ListTag) tags.get("blocks"); if (blocks != null) { @@ -86,10 +91,6 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter { String name = ((StringTag) map.get("Name")).getValue(); BlockType type = BlockTypes.get(name); BlockState state = type.getDefaultState(); - if (type == null) { - Fawe.debug("Unknown block: " + name); - continue; - } CompoundTag properties = (CompoundTag) map.get("Properties"); if (properties != null) { for (Map.Entry entry : properties.getValue().entrySet()) { @@ -167,85 +168,79 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter { // Size structure.put("size", Arrays.asList(width, height, length)); // Palette - { - ArrayList> palette = new ArrayList<>(); - for (BlockVector3 point : region) { - BlockStateHolder block = clipboard.getBlock(point); - int combined = block.getInternalId(); - BlockType type = block.getBlockType(); + ArrayList> palette = new ArrayList<>(); + for (BlockVector3 point : region) { + BlockStateHolder block = clipboard.getBlock(point); + int combined = block.getInternalId(); + BlockType type = block.getBlockType(); - if (type == BlockTypes.STRUCTURE_VOID || indexes.containsKey(combined)) { - continue; - } + if (type == BlockTypes.STRUCTURE_VOID || indexes.containsKey(combined)) { + continue; + } - indexes.put(combined, (Integer) palette.size()); - HashMap paletteEntry = new HashMap<>(); - paletteEntry.put("Name", type.getId()); - if (block.getInternalId() != type.getInternalId()) { - Map properties = null; - for (AbstractProperty property : (List>) type.getProperties()) { - int propIndex = property.getIndex(block.getInternalId()); - if (propIndex != 0) { - if (properties == null) properties = new HashMap<>(); - Object value = property.getValues().get(propIndex); - properties.put(property.getName(), value.toString()); - } - } - if (properties != null) { - paletteEntry.put("Properties", properties); + indexes.put(combined, (Integer) palette.size()); + HashMap paletteEntry = new HashMap<>(); + paletteEntry.put("Name", type.getId()); + if (block.getInternalId() != type.getInternalId()) { + Map properties = null; + for (AbstractProperty property : (List>) type.getProperties()) { + int propIndex = property.getIndex(block.getInternalId()); + if (propIndex != 0) { + if (properties == null) properties = new HashMap<>(); + Object value = property.getValues().get(propIndex); + properties.put(property.getName(), value.toString()); } } - palette.add(paletteEntry); - } - if (!palette.isEmpty()) { - structure.put("palette", palette); + if (properties != null) { + paletteEntry.put("Properties", properties); + } } + palette.add(paletteEntry); + } + if (!palette.isEmpty()) { + structure.put("palette", palette); } // Blocks - { - ArrayList> blocks = new ArrayList<>(); - BlockVector3 min = region.getMinimumPoint(); - for (BlockVector3 point : region) { - BaseBlock block = clipboard.getFullBlock(point); - if (block.getBlockType() != BlockTypes.STRUCTURE_VOID) { - int combined = block.getInternalId(); - int index = indexes.get(combined); - List pos = Arrays.asList(point.getX() - min.getX(), - point.getY() - min.getY(), point.getZ() - min.getZ()); - if (!block.hasNbtData()) { - blocks.add(FaweCache.asMap("state", index, "pos", pos)); - } else { - blocks.add( - FaweCache.asMap("state", index, "pos", pos, "nbt", block.getNbtData())); - } + ArrayList> blocks = new ArrayList<>(); + BlockVector3 min = region.getMinimumPoint(); + for (BlockVector3 point : region) { + BaseBlock block = clipboard.getFullBlock(point); + if (block.getBlockType() != BlockTypes.STRUCTURE_VOID) { + int combined = block.getInternalId(); + int index = indexes.get(combined); + List pos = Arrays.asList(point.getX() - min.getX(), + point.getY() - min.getY(), point.getZ() - min.getZ()); + if (!block.hasNbtData()) { + blocks.add(FaweCache.asMap("state", index, "pos", pos)); + } else { + blocks.add( + FaweCache.asMap("state", index, "pos", pos, "nbt", block.getNbtData())); } } - if (!blocks.isEmpty()) { - structure.put("blocks", blocks); - } + } + if (!blocks.isEmpty()) { + structure.put("blocks", blocks); } // Entities - { - ArrayList> entities = new ArrayList<>(); - for (Entity entity : clipboard.getEntities()) { - Location loc = entity.getLocation(); - List pos = Arrays.asList(loc.getX(), loc.getY(), loc.getZ()); - List blockPos = Arrays.asList(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); - BaseEntity state = entity.getState(); - if (state != null) { - CompoundTag nbt = state.getNbtData(); - Map nbtMap = ReflectionUtils.getMap(nbt.getValue()); - // Replace rotation data - nbtMap.put("Rotation", writeRotation(entity.getLocation(), "Rotation")); - nbtMap.put("id", new StringTag(state.getType().getId())); - Map entityMap = FaweCache.asMap("pos", pos, "blockPos", blockPos, "nbt", nbt); - entities.add(entityMap); - } - } - if (!entities.isEmpty()) { - structure.put("entities", entities); + ArrayList> entities = new ArrayList<>(); + for (Entity entity : clipboard.getEntities()) { + Location loc = entity.getLocation(); + List pos = Arrays.asList(loc.getX(), loc.getY(), loc.getZ()); + List blockPos = Arrays.asList(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + BaseEntity state = entity.getState(); + if (state != null) { + CompoundTag nbt = state.getNbtData(); + Map nbtMap = ReflectionUtils.getMap(nbt.getValue()); + // Replace rotation data + nbtMap.put("Rotation", writeRotation(entity.getLocation())); + nbtMap.put("id", new StringTag(state.getType().getId())); + Map entityMap = FaweCache.asMap("pos", pos, "blockPos", blockPos, "nbt", nbt); + entities.add(entityMap); } } + if (!entities.isEmpty()) { + structure.put("entities", entities); + } out.writeNamedTag("", FaweCache.asTag(structure)); close(); } @@ -260,18 +255,4 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter { } } - private Tag writeVector(BlockVector3 vector, String name) { - List list = new ArrayList<>(); - list.add(new DoubleTag(vector.getX())); - list.add(new DoubleTag(vector.getY())); - list.add(new DoubleTag(vector.getZ())); - return new ListTag(DoubleTag.class, list); - } - - private Tag writeRotation(Location location, String name) { - List list = new ArrayList<>(); - list.add(new FloatTag(location.getYaw())); - list.add(new FloatTag(location.getPitch())); - return new ListTag(FloatTag.class, list); - } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/PNGWriter.java b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/PNGWriter.java index c91531b8f..89ab0a3e4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/PNGWriter.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/PNGWriter.java @@ -51,9 +51,6 @@ public class PNGWriter implements ClipboardWriter { double[] dpxi = new double[Math.max(256, width)]; double[] dpyj = new double[length]; double[] dpyi = new double[Math.max(256, width)]; - double[] hd = new double[256]; - for (int i = 0; i < hd.length; i++) { - } for (int j = 0; j < dpxj.length; j++) { dpxj[j] = cx + j * d; dpyj[j] = imageSize / 2 + d + j * d_2; @@ -165,4 +162,4 @@ public class PNGWriter implements ClipboardWriter { public void close() throws IOException { out.close(); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/Schematic.java b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/Schematic.java index dda472c7a..bc58ae29e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/Schematic.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/Schematic.java @@ -1,5 +1,7 @@ package com.boydti.fawe.object.schematic; +import static com.google.common.base.Preconditions.checkNotNull; + import com.boydti.fawe.object.clipboard.FaweClipboard; import com.boydti.fawe.object.clipboard.ReadOnlyClipboard; import com.boydti.fawe.util.EditSessionBuilder; @@ -18,6 +20,7 @@ import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; +import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.visitor.RegionVisitor; import com.sk89q.worldedit.math.BlockVector2; @@ -29,17 +32,14 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; - import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import javax.annotation.Nullable; - -import static com.google.common.base.Preconditions.checkNotNull; - public class Schematic { + private final Clipboard clipboard; public Schematic(Clipboard clipboard) { @@ -54,14 +54,15 @@ public class Schematic { */ public Schematic(Region region) { checkNotNull(region); - checkNotNull(region.getWorld(), "World cannot be null (use the other constructor for the region)"); - EditSession session = new EditSessionBuilder(region.getWorld()).allowedRegionsEverywhere().autoQueue(false).build(); + checkNotNull(region.getWorld(), + "World cannot be null (use the other constructor for the region)"); + EditSession session = new EditSessionBuilder(region.getWorld()).allowedRegionsEverywhere() + .autoQueue(false).build(); this.clipboard = new BlockArrayClipboard(region, ReadOnlyClipboard.of(session, region)); } - public @Nullable - Clipboard getClipboard() { + public Clipboard getClipboard() { return clipboard; } @@ -104,7 +105,8 @@ public class Schematic { } } - public EditSession paste(World world, BlockVector3 to, boolean allowUndo, boolean pasteAir, @Nullable Transform transform) { + public EditSession paste(World world, BlockVector3 to, boolean allowUndo, boolean pasteAir, + @Nullable Transform transform) { return paste(world, to, allowUndo, pasteAir, true, transform); } @@ -118,14 +120,16 @@ public class Schematic { * @param transform * @return */ - public EditSession paste(World world, BlockVector3 to, boolean allowUndo, boolean pasteAir, boolean copyEntities, @Nullable Transform transform) { + public EditSession paste(World world, BlockVector3 to, boolean allowUndo, boolean pasteAir, + boolean copyEntities, @Nullable Transform transform) { checkNotNull(world); checkNotNull(to); EditSession editSession; if (world instanceof EditSession) { editSession = (EditSession) world; } else { - EditSessionBuilder builder = new EditSessionBuilder(world).autoQueue(true).checkMemory(false).allowedRegionsEverywhere().limitUnlimited(); + EditSessionBuilder builder = new EditSessionBuilder(world).autoQueue(true) + .checkMemory(false).allowedRegionsEverywhere().limitUnlimited(); if (allowUndo) { editSession = builder.build(); } else { @@ -141,7 +145,8 @@ public class Schematic { editSession.flushQueue(); return editSession; } - ForwardExtentCopy copy = new ForwardExtentCopy(extent, clipboard.getRegion(), clipboard.getOrigin(), editSession, to); + ForwardExtentCopy copy = new ForwardExtentCopy(extent, clipboard.getRegion(), + clipboard.getOrigin(), editSession, to); if (transform != null && !transform.isIdentity()) { copy.setTransform(transform); } @@ -165,16 +170,13 @@ public class Schematic { public void paste(Extent extent, BlockVector3 to, boolean pasteAir, Transform transform) { checkNotNull(transform); - Region region = clipboard.getRegion(); - Extent source = clipboard; - if (transform != null) { - source = new BlockTransformExtent(clipboard, transform); - } - ForwardExtentCopy copy = new ForwardExtentCopy(source, clipboard.getRegion(), clipboard.getOrigin(), extent, to); - if (transform != null) { - copy.setTransform(transform); - } - copy.setCopyingBiomes(!(clipboard instanceof BlockArrayClipboard) || ((BlockArrayClipboard) clipboard).IMP.hasBiomes()); + Extent source = new BlockTransformExtent(clipboard, transform); + ForwardExtentCopy copy = new ForwardExtentCopy(source, clipboard.getRegion(), + clipboard.getOrigin(), extent, to); + copy.setTransform(transform); + copy.setCopyingBiomes( + !(clipboard instanceof BlockArrayClipboard) || ((BlockArrayClipboard) clipboard).IMP + .hasBiomes()); if (extent instanceof EditSession) { EditSession editSession = (EditSession) extent; Mask sourceMask = editSession.getSourceMask(); @@ -190,13 +192,14 @@ public class Schematic { Operations.completeBlindly(copy); } - public void paste(Extent extent, BlockVector3 to, final boolean pasteAir) { + public void paste(Extent extent, BlockVector3 to, boolean pasteAir) { Region region = clipboard.getRegion().clone(); - final int maxY = extent.getMaximumPoint().getBlockY(); final BlockVector3 bot = clipboard.getMinimumPoint(); final BlockVector3 origin = clipboard.getOrigin(); - final boolean copyBiomes = !(clipboard instanceof BlockArrayClipboard) || ((BlockArrayClipboard) clipboard).IMP.hasBiomes(); + final boolean copyBiomes = + !(clipboard instanceof BlockArrayClipboard) || ((BlockArrayClipboard) clipboard).IMP + .hasBiomes(); // Optimize for BlockArrayClipboard if (clipboard instanceof BlockArrayClipboard && region instanceof CuboidRegion) { @@ -209,9 +212,11 @@ public class Schematic { if (copyBiomes) { bac.IMP.forEach(new FaweClipboard.BlockReader() { MutableBlockVector2 mpos2d = new MutableBlockVector2(); + { mpos2d.setComponents(Integer.MIN_VALUE, Integer.MIN_VALUE); } + @Override public > void run(int x, int y, int z, B block) { try { @@ -225,7 +230,9 @@ public class Schematic { return; } extent.setBlock(xx, y + rely, zz, block); - } catch (WorldEditException e) { throw new RuntimeException(e);} + } catch (WorldEditException e) { + throw new RuntimeException(e); + } } }, true); } else { @@ -234,7 +241,9 @@ public class Schematic { public > void run(int x, int y, int z, B block) { try { extent.setBlock(x + relx, y + rely, z + relz, block); - } catch (WorldEditException e) { throw new RuntimeException(e);} + } catch (WorldEditException e) { + throw new RuntimeException(e); + } } }, pasteAir); } @@ -243,12 +252,14 @@ public class Schematic { final int relx = to.getBlockX() - origin.getBlockX(); final int rely = to.getBlockY() - origin.getBlockY(); final int relz = to.getBlockZ() - origin.getBlockZ(); - RegionVisitor visitor = new RegionVisitor(region, new RegionFunction() { -// MutableBlockVector2 mpos2d_2 = new MutableBlockVector2(); + Operation visitor = new RegionVisitor(region, new RegionFunction() { + // MutableBlockVector2 mpos2d_2 = new MutableBlockVector2(); MutableBlockVector2 mpos2d = new MutableBlockVector2(); + { mpos2d.setComponents(Integer.MIN_VALUE, Integer.MIN_VALUE); } + @Override public boolean apply(BlockVector3 mutable) throws WorldEditException { BlockStateHolder block = clipboard.getBlock(mutable); @@ -257,7 +268,8 @@ public class Schematic { if (copyBiomes && xx != mpos2d.getBlockX() && zz != mpos2d.getBlockZ()) { mpos2d.setComponents(xx, zz); // extent.setBiome(mpos2d, clipboard.getBiome(mpos2d_2.setComponents(mutable.getBlockX(), mutable.getBlockZ()))); - extent.setBiome(mpos2d, clipboard.getBiome(BlockVector2.at(mutable.getBlockX(), mutable.getBlockZ()))); + extent.setBiome(mpos2d, clipboard + .getBiome(BlockVector2.at(mutable.getBlockX(), mutable.getBlockZ()))); } if (!pasteAir && block.getBlockType().getMaterial().isAir()) { return false; @@ -275,11 +287,14 @@ public class Schematic { // entities for (Entity entity : clipboard.getEntities()) { // skip players on pasting schematic - if (entity.getState() != null && entity.getState().getType().getId().equals("minecraft:player")) { + if (entity.getState() != null && entity.getState().getType().getId() + .equals("minecraft:player")) { continue; } Location pos = entity.getLocation(); - Location newPos = new Location(pos.getExtent(), pos.getX() + entityOffsetX, pos.getY() + entityOffsetY, pos.getZ() + entityOffsetZ, pos.getYaw(), pos.getPitch()); + Location newPos = new Location(pos.getExtent(), pos.getX() + entityOffsetX, + pos.getY() + entityOffsetY, pos.getZ() + entityOffsetZ, pos.getYaw(), + pos.getPitch()); extent.createEntity(newPos, entity.getState()); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/CleanTextureUtil.java b/worldedit-core/src/main/java/com/boydti/fawe/util/CleanTextureUtil.java index 69de226b7..53d72efef 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/CleanTextureUtil.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/CleanTextureUtil.java @@ -10,8 +10,8 @@ public class CleanTextureUtil extends TextureUtil { super(parent.getFolder()); this.min = minPercent; this.max = maxPercent; - int minIndex = ((parent.distances.length - 1) * minPercent) / 100; - int maxIndex = ((parent.distances.length - 1) * maxPercent) / 100; + int minIndex = (parent.distances.length - 1) * minPercent / 100; + int maxIndex = (parent.distances.length - 1) * maxPercent / 100; long min = parent.distances[minIndex]; long max = parent.distances[maxIndex]; for (; minIndex > 0 && parent.distances[minIndex - 1] == min; minIndex--) ; @@ -44,4 +44,4 @@ public class CleanTextureUtil extends TextureUtil { public int getMax() { return max; } -} \ No newline at end of file +} 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 4858b00a8..bd4747444 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 @@ -1,5 +1,7 @@ package com.boydti.fawe.util; +import static com.google.common.base.Preconditions.checkNotNull; + import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweAPI; import com.boydti.fawe.config.BBC; @@ -24,12 +26,9 @@ import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.eventbus.EventBus; import com.sk89q.worldedit.world.World; - +import java.util.UUID; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.UUID; - -import static com.google.common.base.Preconditions.checkNotNull; public class EditSessionBuilder { private World world; @@ -294,7 +293,7 @@ public class EditSessionBuilder { } if (checkMemory) { if (MemUtil.isMemoryLimitedSlow()) { - if (Perm.hasPermission(player, "worldedit.fast")) { + if (Permission.hasPermission(player.toWorldEditPlayer(), "worldedit.fast")) { BBC.WORLDEDIT_OOM_ADMIN.send(player); } throw FaweException.LOW_MEMORY; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/IOUtil.java b/worldedit-core/src/main/java/com/boydti/fawe/util/IOUtil.java index a02be0890..7317b703d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/IOUtil.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/IOUtil.java @@ -15,14 +15,14 @@ public final class IOUtil { int ch4 = in.read(); if ((ch1 | ch2 | ch3 | ch4) < 0) throw new EOFException(); - return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0)); + return (ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0); } public static void writeInt(OutputStream out, int v) throws IOException { - out.write((v >>> 24) & 0xFF); - out.write((v >>> 16) & 0xFF); - out.write((v >>> 8) & 0xFF); - out.write((v >>> 0) & 0xFF); + out.write(v >>> 24 & 0xFF); + out.write(v >>> 16 & 0xFF); + out.write(v >>> 8 & 0xFF); + out.write(v >>> 0 & 0xFF); } public static int readVarInt(InputStream in) throws IOException { @@ -30,7 +30,7 @@ public final class IOUtil { int offset = 0; int b; while ((b = in.read()) > 127) { - i |= (b - 128) << offset; + i |= b - 128 << offset; offset += 7; } i |= b << offset; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/ImgurUtility.java b/worldedit-core/src/main/java/com/boydti/fawe/util/ImgurUtility.java index a445bd27e..0f719b489 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/ImgurUtility.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/ImgurUtility.java @@ -17,12 +17,12 @@ public class ImgurUtility { return uploadImage(new FileInputStream(file)); } - public static URL uploadImage(InputStream is) throws IOException { - is = new BufferedInputStream(is); + public static URL uploadImage(InputStream inputStream) throws IOException { + inputStream = new BufferedInputStream(inputStream); FastByteArrayOutputStream baos = new FastByteArrayOutputStream(Short.MAX_VALUE); - int d; - while ((d = is.read()) != -1) { - baos.write(d); + int i; + while ((i = inputStream.read()) != -1) { + baos.write(i); } baos.flush(); return uploadImage(baos.toByteArray()); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/Perm.java b/worldedit-core/src/main/java/com/boydti/fawe/util/Perm.java deleted file mode 100644 index 05c1db0ab..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/Perm.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.boydti.fawe.util; - -import com.boydti.fawe.object.FawePlayer; - -public enum Perm { - /* - * Permission related functions - */ - ADMIN("fawe.admin", "admin"); - - public String s; - public String cat; - - Perm(String perm, String cat) { - this.s = perm; - this.cat = cat; - } - - public boolean has(FawePlayer player) { - return this.hasPermission(player, this); - } - - public boolean hasPermission(FawePlayer player, Perm perm) { - return hasPermission(player, perm.s); - } - - public static boolean hasPermission(FawePlayer player, String perm) { - if (player == null || player.hasPermission(ADMIN.s)) { - return true; - } - if (player.hasPermission(perm)) { - return true; - } - final String[] nodes = perm.split("\\."); - final StringBuilder n = new StringBuilder(); - for (int i = 0; i < nodes.length - 1; i++) { - n.append(nodes[i]).append("."); - if (player.hasPermission(n + "*")) { - return true; - } - } - return false; - } -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/Permission.java b/worldedit-core/src/main/java/com/boydti/fawe/util/Permission.java new file mode 100644 index 000000000..c99930820 --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/Permission.java @@ -0,0 +1,37 @@ +package com.boydti.fawe.util; + +import com.sk89q.worldedit.util.auth.Subject; + +public enum Permission { + /* + * Permission related functions + */ + ADMIN("fawe.admin", "admin"); + + public String permission; + public String cat; + + Permission(String permission, String category) { + this.permission = permission; + this.cat = category; + } + + + public static boolean hasPermission(Subject player, String permission) { + if (player == null || player.hasPermission(ADMIN.permission)) { + return true; + } + if (player.hasPermission(permission)) { + return true; + } + final String[] nodes = permission.split("\\."); + final StringBuilder n = new StringBuilder(); + for (int i = 0; i < nodes.length - 1; i++) { + n.append(nodes[i]).append("."); + if (player.hasPermission(n + "*")) { + return true; + } + } + return false; + } +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/RandomTextureUtil.java b/worldedit-core/src/main/java/com/boydti/fawe/util/RandomTextureUtil.java index 97e1d3ef7..715eb141e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/RandomTextureUtil.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/RandomTextureUtil.java @@ -21,9 +21,9 @@ public class RandomTextureUtil extends CachedTextureUtil { int red1 = (c1 >> 16) & 0xFF; int green1 = (c1 >> 8) & 0xFF; int blue1 = (c1 >> 0) & 0xFF; - byte red2 = (byte) ((c2 >> 16)); - byte green2 = (byte) ((c2 >> 8)); - byte blue2 = (byte) ((c2 >> 0)); + byte red2 = (byte) (c2 >> 16); + byte green2 = (byte) (c2 >> 8); + byte blue2 = (byte) (c2 >> 0); int red = MathMan.clamp(red1 + random(red2), 0, 255); int green = MathMan.clamp(green1 + random(green2), 0, 255); int blue = MathMan.clamp(blue1 + random(blue2), 0, 255); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/StringMan.java b/worldedit-core/src/main/java/com/boydti/fawe/util/StringMan.java index b5fbd8e51..b49934f6a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/StringMan.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/StringMan.java @@ -8,10 +8,8 @@ import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Objects; import java.util.Set; import java.util.function.Function; -import java.util.stream.Collectors; import java.util.stream.IntStream; public class StringMan { @@ -37,10 +35,8 @@ public class StringMan { } public static boolean containsAny(CharSequence sequence, String any) { - for (int i = 0; i < sequence.length(); i++) { - if (any.indexOf(sequence.charAt(i)) != -1) return true; - } - return false; + return IntStream.range(0, sequence.length()) + .anyMatch(i -> any.indexOf(sequence.charAt(i)) != -1); } public static boolean containsIgnoreCase(String haystack, String needle) { @@ -122,14 +118,11 @@ public class StringMan { int len = string.length(); for (int i = len - 1; i >= 0; i--) { char c = string.charAt(i); - switch (c) { - case '-': - val = -val; - break; - default: - val = val + (c - 48) * numIndex; - numIndex *= 10; - break; + if (c == '-') { + val = -val; + } else { + val = val + (c - 48) * numIndex; + numIndex *= 10; } } return val; @@ -518,7 +511,8 @@ public class StringMan { } public static boolean isEqualIgnoreCase(String a, String b) { - return ((a == b) || ((a != null) && (b != null) && (a.length() == b.length()) && a.equalsIgnoreCase(b))); + return a == b || + a != null && b != null && a.length() == b.length() && a.equalsIgnoreCase(b); } public static String repeat(String s, int n) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/WEManager.java b/worldedit-core/src/main/java/com/boydti/fawe/util/WEManager.java index 2c931a902..40b948fc2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/WEManager.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/WEManager.java @@ -32,7 +32,7 @@ public class WEManager { if (!(currentExtent instanceof NullExtent)) { field.set(parent, new NullExtent((Extent) field.get(parent), reason)); } - } catch (final Exception e) { + } catch (Exception e) { e.printStackTrace(); } throw reason; @@ -42,41 +42,33 @@ public class WEManager { cancelEditSafe(parent, reason); } - public boolean maskContains(final HashSet mask, final int x, final int z) { - for (final RegionWrapper region : mask) { - if ((x >= region.minX) && (x <= region.maxX) && (z >= region.minZ) && (z <= region.maxZ)) { + public boolean maskContains(HashSet mask, int x, int z) { + for (RegionWrapper region : mask) { + if (x >= region.minX && x <= region.maxX && z >= region.minZ && z <= region.maxZ) { return true; } } return false; } - public boolean maskContains(RegionWrapper[] mask, final int x, final int z) { + public boolean maskContains(RegionWrapper[] mask, int x, int z) { switch (mask.length) { case 0: return false; case 1: return mask[0].isIn(x, z); default: - for (final RegionWrapper region : mask) { - if (region.isIn(x, z)) { - return true; - } - } - return false; + return Arrays.stream(mask).anyMatch(region -> region.isIn(x, z)); } } @Deprecated - public Region[] getMask(final FawePlayer player) { + public Region[] getMask(FawePlayer player) { return getMask(player, FaweMaskManager.MaskType.getDefaultMaskType()); } public boolean isIn(int x, int y, int z, Region region) { - if (region.contains(x, y, z)) { - return true; - } - return false; + return region.contains(x, y, z); } /** @@ -85,7 +77,7 @@ public class WEManager { * @param player * @return */ - public Region[] getMask(final FawePlayer player, FaweMaskManager.MaskType type) { + public Region[] getMask(FawePlayer player, FaweMaskManager.MaskType type) { if (!Settings.IMP.REGION_RESTRICTIONS || player.hasPermission("fawe.bypass") || player.hasPermission("fawe.bypass.regions")) { return new Region[]{RegionWrapper.GLOBAL()}; } @@ -129,7 +121,7 @@ public class WEManager { } } Set tmpMasks = new HashSet<>(); - for (final FaweMaskManager manager : managers) { + for (FaweMaskManager manager : managers) { if (player.hasPermission("fawe." + manager.getKey())) { try { if (manager.isExclusive() && !masks.isEmpty()) continue; @@ -154,17 +146,19 @@ public class WEManager { } - public boolean intersects(final Region region1, final Region region2) { + public boolean intersects(Region region1, Region region2) { BlockVector3 rg1P1 = region1.getMinimumPoint(); BlockVector3 rg1P2 = region1.getMaximumPoint(); BlockVector3 rg2P1 = region2.getMinimumPoint(); BlockVector3 rg2P2 = region2.getMaximumPoint(); - return (rg1P1.getBlockX() <= rg2P2.getBlockX()) && (rg1P2.getBlockX() >= rg2P1.getBlockX()) && (rg1P1.getBlockZ() <= rg2P2.getBlockZ()) && (rg1P2.getBlockZ() >= rg2P1.getBlockZ()); + return rg1P1.getBlockX() <= rg2P2.getBlockX() && rg1P2.getBlockX() >= rg2P1.getBlockX() && + rg1P1.getBlockZ() <= rg2P2.getBlockZ() && + rg1P2.getBlockZ() >= rg2P1.getBlockZ(); } - public boolean regionContains(final Region selection, final HashSet mask) { - for (final Region region : mask) { + public boolean regionContains(Region selection, HashSet mask) { + for (Region region : mask) { if (this.intersects(region, selection)) { return true; } @@ -172,29 +166,29 @@ public class WEManager { return false; } - public boolean delay(final FawePlayer player, final String command) { + public boolean delay(FawePlayer player, String command) { final long start = System.currentTimeMillis(); return this.delay(player, () -> { try { - if ((System.currentTimeMillis() - start) > 1000) { + if (System.currentTimeMillis() - start > 1000) { BBC.WORLDEDIT_RUN.send(FawePlayer.wrap(player)); } TaskManager.IMP.task(() -> { final long start1 = System.currentTimeMillis(); player.executeCommand(command.substring(1)); TaskManager.IMP.later(() -> SetQueue.IMP.addEmptyTask(() -> { - if ((System.currentTimeMillis() - start1) > 1000) { + if (System.currentTimeMillis() - start1 > 1000) { BBC.WORLDEDIT_COMPLETE.send(FawePlayer.wrap(player)); } }), 2); }); - } catch (final Exception e) { + } catch (Exception e) { e.printStackTrace(); } }, false, false); } - public boolean delay(final FawePlayer player, final Runnable whenDone, final boolean delayed, final boolean onlyDelayedExecution) { + public boolean delay(FawePlayer player, Runnable whenDone, boolean delayed, boolean onlyDelayedExecution) { final boolean free = SetQueue.IMP.addEmptyTask(null); if (free) { if (delayed) { @@ -202,14 +196,14 @@ public class WEManager { whenDone.run(); } } else { - if ((whenDone != null) && !onlyDelayedExecution) { + if (whenDone != null && !onlyDelayedExecution) { whenDone.run(); } else { return false; } } } else { - if (!delayed && (player != null)) { + if (!delayed && player != null) { BBC.WORLDEDIT_DELAYED.send(player); } SetQueue.IMP.addEmptyTask(whenDone); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/chat/ChatManager.java b/worldedit-core/src/main/java/com/boydti/fawe/util/chat/ChatManager.java deleted file mode 100644 index de8470014..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/chat/ChatManager.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.boydti.fawe.util.chat; - -import com.boydti.fawe.object.FawePlayer; - -public interface ChatManager { - T builder(); - - void color(Message message, String color); - - void tooltip(Message message, Message... tooltip); - - void command(Message message, String command); - - void text(Message message, String text); - - void send(Message message, FawePlayer player); - - void suggest(Message message, String command); - - void link(Message message, String url); -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/chat/Message.java b/worldedit-core/src/main/java/com/boydti/fawe/util/chat/Message.java deleted file mode 100644 index e62f02945..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/chat/Message.java +++ /dev/null @@ -1,127 +0,0 @@ -package com.boydti.fawe.util.chat; - -import com.boydti.fawe.Fawe; -import com.boydti.fawe.config.BBC; -import com.boydti.fawe.object.FawePlayer; -import com.sk89q.worldedit.extension.platform.Actor; -import java.io.Serializable; -import java.util.Objects; - -public class Message { - - private Object builder; - private boolean active; - - public Message() { - try { - reset(Fawe.get().getChatManager()); - } catch (Throwable e) { - Fawe.debug("Doesn't support fancy chat for " + Fawe.imp().getPlatform()); - Fawe.get().setChatManager(new PlainChatManager()); - reset(Fawe.get().getChatManager()); - } - active = !(Fawe.get().getChatManager() instanceof PlainChatManager); - } - - public Message(String text) { - this(); - text(text); - } - - public T $(ChatManager manager) { - return (T) this.builder; - } - - public T reset(ChatManager manager) { - return (T) (this.builder = manager.builder()); - } - - public boolean supportsInteraction() { - return active; - } - - public Message text(BBC caption, Object... args) { - return text(caption.format(args)); - } - - public Message text(Serializable text) { - Fawe.get().getChatManager().text(this, BBC.color(Objects.toString(text))); - return this; - } - - public Message link(String text) { - Fawe.get().getChatManager().link(this, text); - return this; - } - - public Message tooltip(Message... tooltip) { - Fawe.get().getChatManager().tooltip(this, tooltip); - return this; - } - - public Message tooltip(String tooltip) { - return tooltip(new Message(tooltip)); - } - - public Message command(String command) { - Fawe.get().getChatManager().command(this, "/" + command); - return this; - } - - public Message newline() { - return text("\n"); - } - - public Message cmdTip(String commandAndTooltip) { - return tooltip(commandAndTooltip).command(commandAndTooltip); - } - - public Message linkTip(String linkAndTooltip) { - return tooltip(linkAndTooltip).link(linkAndTooltip); - } - - public Message cmdOptions(String prefix, String suffix, String... options) { - for (int i = 0; i < options.length; i++) { - if (i != 0) text(" | "); - text("[" + options[i] + "]") - .cmdTip(prefix + options[i] + suffix); - } - return this; - } - - public Message suggestTip(String commandAndTooltip) { - return tooltip(commandAndTooltip).suggest(commandAndTooltip); - } - - public Message suggest(String command) { - Fawe.get().getChatManager().suggest(this, command); - return this; - } - - public void send(Actor player) { - send(FawePlayer.wrap(player)); - } - - public void send(FawePlayer player) { - Fawe.get().getChatManager().send(this, player); - } - - public Message paginate(String baseCommand, int page, int totalPages) { - if (!active) { - return text(BBC.PAGE_FOOTER.format(baseCommand, page + 1)); - } - if (page < totalPages && page > 1) { // Back | Next - this.text("<<").command(baseCommand + " " + (page - 1)).text(" | ").text(">>") - .command(baseCommand + " " + (page + 1)); - } else if (page <= 1 && totalPages > page) { // Next - this.text(" -").text(" | ").text(">>") - .command(baseCommand + " " + (page + 1)); - - } else if (page == totalPages && totalPages > 1) { // Back - this.text("<<").command(baseCommand + " " + (page - 1)).text(" | ").text("- "); - } else { - this.text(" - | - "); - } - return this; - } -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/chat/PlainChatManager.java b/worldedit-core/src/main/java/com/boydti/fawe/util/chat/PlainChatManager.java deleted file mode 100644 index d39fd2228..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/chat/PlainChatManager.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.boydti.fawe.util.chat; - - -import com.boydti.fawe.config.BBC; -import com.boydti.fawe.object.FawePlayer; -import java.util.ArrayList; -import java.util.List; - -public class PlainChatManager implements ChatManager> { - - @Override - public List builder() { - return new ArrayList<>(); - } - - @Override - public void color(Message message, String color) { - List parts = message.$(this); - parts.get(parts.size() - 1).insert(0, color); - } - - @Override - public void tooltip(Message message, Message... tooltips) {} - - @Override - public void command(Message message, String command) {} - - @Override - public void text(Message message, String text) { - message.$(this).add(new StringBuilder(BBC.color(text))); - } - - @Override - public void send(Message plotMessage, FawePlayer player) { - StringBuilder built = new StringBuilder(); - for (StringBuilder sb : plotMessage.$(this)) { - built.append(sb); - } - player.sendMessage(built.toString()); - } - - @Override - public void suggest(Message plotMessage, String command) {} - - @Override - public void link(Message message, String url) {} -} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/image/ImageUtil.java b/worldedit-core/src/main/java/com/boydti/fawe/util/image/ImageUtil.java index 1216bace0..80685f39a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/image/ImageUtil.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/image/ImageUtil.java @@ -23,51 +23,44 @@ import java.net.URL; public class ImageUtil { - public static BufferedImage getScaledInstance(BufferedImage img, - int targetWidth, - int targetHeight, - Object hint, - boolean higherQuality) { - if (img.getHeight() == targetHeight && img.getWidth() == targetWidth) { - return img; + public static BufferedImage getScaledInstance(BufferedImage image, int targetWidth, + int targetHeight, Object hint, boolean higherQuality) { + if (image.getHeight() == targetHeight && image.getWidth() == targetWidth) { + return image; } - int type = img.getTransparency() == Transparency.OPAQUE ? + int type = image.getTransparency() == Transparency.OPAQUE ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; - BufferedImage ret = img; - int w, h; + BufferedImage scaledImage = image; + int width, height; if (higherQuality) { // Use multi-step technique: start with original size, then // scale down in multiple passes with drawImage() // until the target size is reached - w = ret.getWidth(); - h = ret.getHeight(); + width = scaledImage.getWidth(); + height = scaledImage.getHeight(); } else { // Use one-step technique: scale directly from original // size to target size with a single drawImage() call - w = targetWidth; - h = targetHeight; + width = targetWidth; + height = targetHeight; } do { - if (higherQuality && w > targetWidth) { - w /= 2; - if (w < targetWidth) { - w = targetWidth; - } - } else if (w < targetWidth) { - w = targetWidth; + if (higherQuality && width > targetWidth) { + width /= 2; + } + if (width < targetWidth) { + width = targetWidth; } - if (higherQuality && h > targetHeight) { - h /= 2; - if (h < targetHeight) { - h = targetHeight; - } - } else if (h < targetHeight) { - h = targetHeight; + if (higherQuality && height > targetHeight) { + height /= 2; + } + if (height < targetHeight) { + height = targetHeight; } - BufferedImage tmp = new BufferedImage(w, h, type); + BufferedImage tmp = new BufferedImage(width, height, type); Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); @@ -75,13 +68,13 @@ public class ImageUtil { RenderingHints.VALUE_COLOR_RENDER_SPEED); g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED); - g2.drawImage(ret, 0, 0, w, h, null); + g2.drawImage(scaledImage, 0, 0, width, height, null); g2.dispose(); - ret = tmp; - } while (w != targetWidth || h != targetHeight); + scaledImage = tmp; + } while (width != targetWidth || height != targetHeight); - return ret; + return scaledImage; } public static void fadeAlpha(BufferedImage image) { @@ -207,14 +200,14 @@ public class ImageUtil { throw new IOException("Failed to read " + url + ", please try again later"); } return img; - } else if (arg.startsWith("file:/")) { + } + if (arg.startsWith("file:/")) { arg = arg.replaceFirst("file:/+", ""); File file = MainUtil.getFile(MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HEIGHTMAP), arg); return MainUtil.readImage(file); - } else { - throw new InputParseException("Invalid image " + arg); } + throw new InputParseException("Invalid image " + arg); } catch (IOException e) { throw new InputParseException(e.getMessage()); } @@ -227,7 +220,8 @@ public class ImageUtil { arg = "https://i.imgur.com/" + arg.split("imgur.com/")[1] + ".png"; } return new URL(arg).toURI(); - } else if (arg.startsWith("file:/")) { + } + if (arg.startsWith("file:/")) { arg = arg.replaceFirst("file:/+", ""); File file = MainUtil.getFile(MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HEIGHTMAP), arg); @@ -238,9 +232,8 @@ public class ImageUtil { throw new InputParseException("File is a directory " + file); } return file.toURI(); - } else { - throw new InputParseException("Invalid image " + arg); } + throw new InputParseException("Invalid image " + arg); } catch (IOException | URISyntaxException e) { throw new InputParseException(e.getMessage()); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/task/TaskBuilder.java b/worldedit-core/src/main/java/com/boydti/fawe/util/task/TaskBuilder.java index 45c3ebeae..04d4b86be 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/task/TaskBuilder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/task/TaskBuilder.java @@ -33,7 +33,7 @@ public class TaskBuilder extends Metadatable { return this; } - public TaskBuilder async(ReceiveTask task) { + public TaskBuilder async(ReceiveTask task) { tasks.add(RunnableTask.adapt(task, TaskType.ASYNC)); return this; } @@ -53,7 +53,7 @@ public class TaskBuilder extends Metadatable { return this; } - public TaskBuilder sync(ReceiveTask task) { + public TaskBuilder sync(ReceiveTask task) { tasks.add(RunnableTask.adapt(task, TaskType.SYNC)); return this; } @@ -95,7 +95,7 @@ public class TaskBuilder extends Metadatable { return this; } - public TaskBuilder syncParallel(ReceiveTask run) { + public TaskBuilder syncParallel(ReceiveTask run) { tasks.add(RunnableTask.adapt(run, TaskType.SYNC_PARALLEL)); return this; } @@ -122,7 +122,7 @@ public class TaskBuilder extends Metadatable { return this; } - public TaskBuilder asyncParallel(ReceiveTask run) { + public TaskBuilder asyncParallel(ReceiveTask run) { tasks.add(RunnableTask.adapt(run, TaskType.ASYNC_PARALLEL)); return this; } @@ -151,7 +151,7 @@ public class TaskBuilder extends Metadatable { return this; } - public TaskBuilder syncWhenFree(ReceiveTask run) { + public TaskBuilder syncWhenFree(ReceiveTask run) { tasks.add(RunnableTask.adapt(run, TaskType.SYNC_WHEN_FREE)); return this; } @@ -363,7 +363,7 @@ public class TaskBuilder extends Metadatable { }; } - public static RunnableTask adapt(final ReceiveTask task, TaskType type) { + public static RunnableTask adapt(final ReceiveTask task, TaskType type) { return new RunnableTask(type) { @Override public Object exec(Object previous) { 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 bb55074ad..7ee19ddf5 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 @@ -85,9 +85,8 @@ public class SchemSync implements Runnable { continue; } + File dir = new File(working, uuid.toString()); try (DataInputStream dis = new DataInputStream(in)) { - File dir = new File(working, uuid.toString()); - int data = dis.readByte() & 0xFF; switch (data) { case 0: // list diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java index 79eadbb7c..36d288eb4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java @@ -95,7 +95,7 @@ public class ChunkCommands { Set chunks = session.getSelection(player.getWorld()).getChunks(); PaginationBox paginationBox = PaginationBox.fromStrings("Selected Chunks", "/listchunks -p %page%", - chunks.stream().map(LegacyChunkStore::getFilename).collect(Collectors.toList())); + chunks.stream().map(BlockVector2::toString).collect(Collectors.toList())); player.print(paginationBox.create(page)); } 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 7aad5ab40..36f19c2c8 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 @@ -238,7 +238,7 @@ public class ClipboardCommands { @Selection Region region, @Arg(desc = "Pattern to leave in place of the selection", def = "air") Pattern leavePattern, - @Switch(name = 'e', desc = "skip cut entities") + @Switch(name = 'e', desc = "Skip cut entities") boolean skipEntities, @Switch(name = 'b', desc = "Also copy biomes, source biomes are unaffected") boolean copyBiomes, @@ -579,7 +579,7 @@ public class ClipboardCommands { desc = "Clear your clipboard" ) @CommandPermissions("worldedit.clipboard.clear") - public void clearClipboard(Player player, LocalSession session, EditSession editSession) throws WorldEditException { + public void clearClipboard(Player player, LocalSession session) throws WorldEditException { session.setClipboard(null); BBC.CLIPBOARD_CLEARED.send(player); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java index 6e9ba3911..a5cf25550 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java @@ -19,9 +19,10 @@ package com.sk89q.worldedit.command; +import static com.google.common.base.Preconditions.checkNotNull; + import com.boydti.fawe.Fawe; import com.boydti.fawe.config.BBC; -import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.extent.ResettableExtent; import com.boydti.fawe.util.CachedTextureUtil; import com.boydti.fawe.util.CleanTextureUtil; @@ -29,8 +30,6 @@ import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.RandomTextureUtil; import com.boydti.fawe.util.StringMan; import com.boydti.fawe.util.TextureUtil; -import com.sk89q.worldedit.extension.input.InputParseException; -import org.enginehub.piston.inject.InjectedValueAccess; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; @@ -41,36 +40,32 @@ import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.input.DisallowedUsageException; +import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.util.formatting.component.PaginationBox; import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.item.ItemType; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.TreeMap; +import java.util.concurrent.Callable; import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.param.Arg; import org.enginehub.piston.annotation.param.ArgFlag; import org.enginehub.piston.annotation.param.Switch; -import java.io.FileNotFoundException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.TreeMap; -import java.util.concurrent.Callable; - -import static com.google.common.base.Preconditions.checkNotNull; - /** * General WorldEdit commands. */ @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) -//@Command(aliases = {}, desc = "Player toggles, settings and item info") public class GeneralCommands { private final WorldEdit worldEdit; @@ -141,12 +136,16 @@ public class GeneralCommands { @CommandPermissions("worldedit.fast") public void fast(Player player, LocalSession session, @Arg(desc = "The new fast mode state", def = "") Boolean fastMode) { boolean hasFastMode = session.hasFastMode(); - if (fastMode == null) fastMode = !hasFastMode; - session.setFastMode(fastMode); - if (fastMode) { - BBC.FAST_ENABLED.send(player); - } else { + if (fastMode != null && fastMode == hasFastMode) { + player.printError("Fast mode already " + (fastMode ? "enabled" : "disabled") + "."); + return; + } + if (hasFastMode) { + session.setFastMode(false); BBC.FAST_DISABLED.send(player); + } else { + session.setFastMode(true); + BBC.FAST_ENABLED.send(player); } } @@ -299,7 +298,7 @@ public class GeneralCommands { desc = "Set the global mask" ) @CommandPermissions("worldedit.global-texture") - public void gtexture(FawePlayer player, LocalSession session, EditSession editSession, @Arg(name = "context", desc = "InjectedValueAccess", def = "") List arguments) throws WorldEditException, FileNotFoundException { + public void gtexture(Player player, World world, LocalSession session, EditSession editSession, @Arg(name = "context", desc = "InjectedValueAccess", def = "") List arguments) throws WorldEditException, FileNotFoundException { // gtexture // TODO NOT IMPLEMENTED convert this to an ArgumentConverter if (arguments.isEmpty()) { @@ -307,7 +306,7 @@ public class GeneralCommands { BBC.TEXTURE_DISABLED.send(player); } else { String arg = arguments.get(0); - String argLower = arg.toLowerCase(); + String argLower = arg.toLowerCase(Locale.ROOT); TextureUtil util = Fawe.get().getTextureUtil(); int randomIndex = 1; @@ -324,16 +323,15 @@ public class GeneralCommands { if (argLower.equals("true")) util = new RandomTextureUtil(util); checkRandomization = false; } else { - HashSet blocks = null; if (argLower.equals("#copy") || argLower.equals("#clipboard")) { - Clipboard clipboard = player.getSession().getClipboard().getClipboard(); + Clipboard clipboard = worldEdit.getSessionManager().get(player).getClipboard().getClipboard(); util = TextureUtil.fromClipboard(clipboard); } else if (argLower.equals("*") || argLower.equals("true")) { util = Fawe.get().getTextureUtil(); } else { ParserContext parserContext = new ParserContext(); - parserContext.setActor(player.getPlayer()); - parserContext.setWorld(player.getWorld()); + parserContext.setActor(player); + parserContext.setWorld(world); parserContext.setSession(session); parserContext.setExtent(editSession); Mask mask = worldEdit.getMaskFactory().parseFromInput(arg, parserContext); @@ -392,7 +390,6 @@ public class GeneralCommands { ) @CommandPermissions("fawe.tips") public void tips(Player player, LocalSession session) throws WorldEditException { - FawePlayer fp = FawePlayer.wrap(player); if (player.togglePermission("fawe.tips")) { BBC.WORLDEDIT_TOGGLE_TIPS_ON.send(player); } else { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java index 0b37041ef..273a602f4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java @@ -70,8 +70,7 @@ import org.enginehub.piston.inject.InjectedValueAccess; * Commands for the generation of shapes and other objects. */ @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) -//@Command(aliases = {}, desc = "Create structures and features: [More Info](https://goo.gl/KuLFRW)") -public class GenerationCommands extends MethodCommands { +public class GenerationCommands { private final WorldEdit worldEdit; @@ -275,9 +274,10 @@ public class GenerationCommands extends MethodCommands { int size, @Arg(desc = "The type of forest", def = "tree") TreeType type, - @Range(min = 0, max = 100) @Arg(desc = "The density of the forest, between 0 and 100", def = "5") + @Arg(desc = "The density of the forest, between 0 and 100", def = "5") double density) throws WorldEditException { - density = density / 100; + checkCommandArgument(0 <= density && density <= 100, "Density must be between 0 and 100"); + density /= 100; int affected = editSession.makeForest(session.getPlacementPosition(player), size, density, type); player.print(affected + " trees created."); return affected; @@ -393,7 +393,7 @@ public class GenerationCommands extends MethodCommands { fp.checkConfirmationRegion(() -> { try { - int affected = editSession.makeShape(region, zero, unit1, pattern, String.join(" ", expression), hollow, session.getTimeout()); + final int affected = editSession.makeShape(region, zero, unit1, pattern, String.join(" ", expression), hollow, session.getTimeout()); player.findFreePosition(); BBC.VISITOR_BLOCK.send(fp, affected); } catch (ExpressionException e) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java index 1793bccce..2942671a9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java @@ -60,7 +60,7 @@ import org.enginehub.piston.inject.InjectedValueAccess; * Commands to undo, redo, and clear history. */ @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) -public class HistoryCommands extends MethodCommands { +public class HistoryCommands { private final WorldEdit worldEdit; @@ -224,11 +224,12 @@ public class HistoryCommands extends MethodCommands { @Arg(name = "player", desc = "Undo this player's operations", def = "") String playerName, InjectedValueAccess context) throws WorldEditException { + times = Math.max(1, times); + LocalSession undoSession; if (session.hasFastMode()) { BBC.COMMAND_UNDO_DISABLED.send(player); return; } - LocalSession undoSession; if (playerName != null && !playerName.isEmpty()) { player.checkPermission("worldedit.history.undo.other"); undoSession = worldEdit.getSessionManager().findByName(playerName); @@ -239,7 +240,6 @@ public class HistoryCommands extends MethodCommands { } else { undoSession = session; } - times = Math.max(1, times); int finalTimes = times; FawePlayer.wrap(player).checkConfirmation(() -> { EditSession undone = null; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/MaskCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/MaskCommands.java index f5fe582a2..b9bb4a190 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/MaskCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/MaskCommands.java @@ -25,6 +25,7 @@ import com.boydti.fawe.object.mask.ZAxisMask; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.BlockMaskBuilder; @@ -39,12 +40,14 @@ import com.sk89q.worldedit.function.mask.RegionMask; import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.ExpressionException; +import com.sk89q.worldedit.internal.expression.runtime.ExpressionEnvironment; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment; import com.sk89q.worldedit.session.request.RequestSelection; import com.sk89q.worldedit.world.biome.BiomeType; import org.enginehub.piston.annotation.Command; +import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.param.Arg; import org.enginehub.piston.annotation.param.Switch; @@ -57,7 +60,8 @@ import org.enginehub.piston.annotation.param.Switch; // "e.g. >[stone,dirt],#light[0][5],$jungle\n" + // "More Info: https://git.io/v9r4K" //) -public class MaskCommands extends MethodCommands { +@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) +public class MaskCommands { private final WorldEdit worldEdit; public MaskCommands(WorldEdit worldEdit) { @@ -69,7 +73,7 @@ public class MaskCommands extends MethodCommands { desc = "Use simplex noise as the mask" ) public Mask simplex(double scale, double min, double max) { - scale = (1d / Math.max(1, scale)); + scale = 1d / Math.max(1, scale); min = (min - 50) / 50; max = (max - 50) / 50; return new SimplexMask(scale, min, max); @@ -290,11 +294,11 @@ public class MaskCommands extends MethodCommands { if (max.endsWith("d")) { double y1d = Expression.compile(min.substring(0, min.length() - 1)).evaluate(); double y2d = Expression.compile(max.substring(0, max.length() - 1)).evaluate(); - y1 = (Math.tan(y1d * (Math.PI / 180))); - y2 = (Math.tan(y2d * (Math.PI / 180))); + y1 = Math.tan(y1d * (Math.PI / 180)); + y2 = Math.tan(y2d * (Math.PI / 180)); } else { - y1 = (Expression.compile(min).evaluate()); - y2 = (Expression.compile(max).evaluate()); + y1 = Expression.compile(min).evaluate(); + y2 = Expression.compile(max).evaluate(); } return new AngleMask(extent, y1, y2, overlay, distance); } @@ -315,11 +319,11 @@ public class MaskCommands extends MethodCommands { if (max.endsWith("d")) { double y1d = Expression.compile(min.substring(0, min.length() - 1)).evaluate(); double y2d = Expression.compile(max.substring(0, max.length() - 1)).evaluate(); - y1 = (Math.tan(y1d * (Math.PI / 180))); - y2 = (Math.tan(y2d * (Math.PI / 180))); + y1 = Math.tan(y1d * (Math.PI / 180)); + y2 = Math.tan(y2d * (Math.PI / 180)); } else { - y1 = (Expression.compile(min).evaluate()); - y2 = (Expression.compile(max).evaluate()); + y1 = Expression.compile(min).evaluate(); + y2 = Expression.compile(max).evaluate(); } return new ROCAngleMask(extent, y1, y2, overlay, distance); } @@ -340,11 +344,11 @@ public class MaskCommands extends MethodCommands { if (max.endsWith("d")) { double y1d = Expression.compile(min.substring(0, min.length() - 1)).evaluate(); double y2d = Expression.compile(max.substring(0, max.length() - 1)).evaluate(); - y1 = (Math.tan(y1d * (Math.PI / 180))); - y2 = (Math.tan(y2d * (Math.PI / 180))); + y1 = Math.tan(y1d * (Math.PI / 180)); + y2 = Math.tan(y2d * (Math.PI / 180)); } else { - y1 = (Expression.compile(min).evaluate()); - y2 = (Expression.compile(max).evaluate()); + y1 = Expression.compile(min).evaluate(); + y2 = Expression.compile(max).evaluate(); } return new ExtremaMask(extent, y1, y2, overlay, distance); } @@ -430,7 +434,7 @@ public class MaskCommands extends MethodCommands { ) public Mask expression(Extent extent, String input) throws ExpressionException { Expression exp = Expression.compile(input, "x", "y", "z"); - WorldEditExpressionEnvironment env = new WorldEditExpressionEnvironment(extent, Vector3.ONE, Vector3.ZERO); + ExpressionEnvironment env = new WorldEditExpressionEnvironment(extent, Vector3.ONE, Vector3.ZERO); exp.setEnvironment(env); return new ExpressionMask(exp); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/NavigationCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/NavigationCommands.java index 6abdf1679..c69863cd4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/NavigationCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/NavigationCommands.java @@ -159,12 +159,21 @@ public class NavigationCommands { desc = "Teleport to a location" ) @CommandPermissions("worldedit.navigation.jumpto.command") - public void jumpTo(Player player, @Arg(desc = "Location to jump to", def = "") Location pos, @Switch(name='f', desc = "force teleport") boolean force) throws WorldEditException { + public void jumpTo(Player player, + @Arg(desc = "Location to jump to", def = "") + Location pos, + @Switch(name='f', desc = "force teleport") + boolean force) throws WorldEditException { + if (pos == null) { pos = player.getSolidBlockTrace(300); } if (pos != null) { - if(force) player.setPosition(pos); else player.findFreePosition(pos); + if (force) { + player.setPosition(pos); + } else { + player.findFreePosition(pos); + } BBC.POOF.send(player); } else { BBC.NO_BLOCK.send(player); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/PatternCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/PatternCommands.java index 3602dadd8..5ed497f6b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/PatternCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/PatternCommands.java @@ -8,6 +8,7 @@ import com.boydti.fawe.object.pattern.*; import com.boydti.fawe.object.random.SimplexRandom; import com.boydti.fawe.util.ColorUtil; import com.boydti.fawe.util.TextureUtil; +import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import org.enginehub.piston.annotation.Command; import com.sk89q.worldedit.*; import com.sk89q.worldedit.entity.Player; @@ -27,6 +28,7 @@ import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.internal.annotation.Range; import com.sk89q.worldedit.world.biome.BiomeType; +import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.param.Arg; import java.awt.Color; @@ -43,12 +45,8 @@ import java.util.Set; // "e.g. #surfacespread[10][#existing],andesite\n" + // "More Info: https://git.io/vSPmA" //) -public class PatternCommands extends MethodCommands { - private final WorldEdit worldEdit; - - public PatternCommands(WorldEdit worldEdit) { - this.worldEdit = worldEdit; - } +@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) +public class PatternCommands { @Command( name = "#existing", 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 cce58e383..ff8badd69 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 @@ -100,6 +100,26 @@ public class RegionCommands { this.worldEdit = worldEdit; } + @Command( + name = "/set", + desc = "Sets all the blocks in the region" + ) + @CommandPermissions("worldedit.region.set") + @Logging(REGION) + public void set(FawePlayer player, EditSession editSession, + @Selection Region region, + @Arg(desc = "The pattern of blocks to set") + Pattern pattern, InjectedValueAccess context) throws WorldEditException { + player.checkConfirmationRegion(() -> { + int affected = editSession.setBlocks(region, pattern); + if (affected != 0) { + BBC.OPERATION.send(player, affected); + if (!player.hasPermission("fawe.tips")) + BBC.TIP_FAST.or(BBC.TIP_CANCEL, BBC.TIP_MASK, BBC.TIP_MASK_ANGLE, BBC.TIP_SET_LINEAR, BBC.TIP_SURFACE_SPREAD, BBC.TIP_SET_HAND).send(player); + } + }, getArguments(context), region, context); + } + @Command( name = "/fixlighting", desc = "Get the light at a position" @@ -197,7 +217,7 @@ public class RegionCommands { @Arg(desc = "The pattern of blocks to place") Pattern pattern, @Arg(desc = "The thickness of the line", def = "0") - @Range(min = 0) int thickness, + int thickness, @Switch(name = 'h', desc = "Generate only a shell") boolean shell) throws WorldEditException { if (!(region instanceof CuboidRegion)) { @@ -227,7 +247,7 @@ public class RegionCommands { @Arg(desc = "The pattern of blocks to place") Pattern pattern, @Arg(desc = "The thickness of the curve", def = "0") - @Range(min = 0) int thickness, + int thickness, @Switch(name = 'h', desc = "Generate only a shell") boolean shell, InjectedValueAccess context) throws WorldEditException { if (!(region instanceof ConvexPolyhedralRegion)) { @@ -258,6 +278,9 @@ public class RegionCommands { Mask from, @Arg(desc = "The pattern of blocks to replace with") Pattern to, InjectedValueAccess context) throws WorldEditException { + if (from == null) { + from = new ExistingBlockMask(editSession); + } player.checkConfirmationRegion(() -> { int affected = editSession.replaceBlocks(region, from == null ? new ExistingBlockMask(editSession) : from, to); BBC.VISITOR_BLOCK.send(player, affected); @@ -269,31 +292,13 @@ public class RegionCommands { } }, getArguments(context), region, context); } - // Compatibility for SKCompat + @Deprecated public void set(Player player, LocalSession session, EditSession editSession, Pattern pattern) throws WorldEditException { set(FawePlayer.wrap(player), session, editSession, session.getSelection(player.getWorld()), pattern, null); } - @Command( - name = "/set", - aliases = { "/s" }, - desc = "Set all blocks within selection" -) - @CommandPermissions("worldedit.region.set") - @Logging(REGION) - public void set(FawePlayer player, LocalSession session, EditSession editSession, @Selection Region selection, Pattern to, InjectedValueAccess context) throws WorldEditException { - player.checkConfirmationRegion(() -> { - int affected = editSession.setBlocks(selection, to); - if (affected != 0) { - BBC.OPERATION.send(player, affected); - if (!player.hasPermission("fawe.tips")) - BBC.TIP_FAST.or(BBC.TIP_CANCEL, BBC.TIP_MASK, BBC.TIP_MASK_ANGLE, BBC.TIP_SET_LINEAR, BBC.TIP_SURFACE_SPREAD, BBC.TIP_SET_HAND).send(player); - } - }, getArguments(context), selection, context); - } - @Command( name = "/overlay", desc = "Set a block on top of blocks in the region" @@ -526,7 +531,7 @@ public class RegionCommands { ) @CommandPermissions("worldedit.region.stack") @Logging(ORIENTATION_REGION) - public void stack(FawePlayer player, World world, EditSession editSession, LocalSession session, + public void stack(FawePlayer player, EditSession editSession, LocalSession session, @Selection Region region, @Arg(desc = "# of copies to stack", def = "1") int count, @@ -557,8 +562,8 @@ public class RegionCommands { final BlockVector3 shiftVector = direction.toVector3().multiply(count * (Math.abs(direction.dot(size)) + 1)).toBlockPoint(); region.shift(shiftVector); - session.getRegionSelector(world).learnChanges(); - session.getRegionSelector(world).explainRegionAdjust(player.getPlayer(), session); + session.getRegionSelector(player.getWorld()).learnChanges(); + session.getRegionSelector(player.getWorld()).explainRegionAdjust(player.getPlayer(), session); } catch (RegionOperationException e) { player.toWorldEditPlayer().printError(e.getMessage()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java index 5dbd8db1e..591f61d76 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java @@ -34,6 +34,8 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.command.argument.SelectorChoice; +import com.sk89q.worldedit.command.tool.NavigationWand; +import com.sk89q.worldedit.command.tool.SelectionWand; import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.Logging; @@ -66,6 +68,7 @@ import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.world.World; +import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.storage.ChunkStore; import java.io.File; @@ -249,8 +252,23 @@ public class SelectionCommands { @CommandPermissions("worldedit.wand") public void wand(Player player, LocalSession session, @Switch(name = 'n', desc = "Get a navigation wand") boolean navWand) throws WorldEditException { - player.giveItem(new BaseItemStack(ItemTypes.parse(we.getConfiguration().wandItem), 1)); - BBC.SELECTION_WAND.send(player); + String wandId = navWand ? session.getNavWandItem() : session.getWandItem(); + if (wandId == null) { + wandId = navWand ? we.getConfiguration().navigationWand : we.getConfiguration().wandItem; + } + ItemType itemType = ItemTypes.parse(wandId); + if (itemType == null) { + player.printError("Wand item is mis-configured or disabled."); + return; + } + player.giveItem(new BaseItemStack(itemType, 1)); + if (navWand) { + session.setTool(itemType, new NavigationWand()); + player.print("Left click: jump to location; Right click: pass through walls"); + } else { + session.setTool(itemType, new SelectionWand()); + BBC.SELECTION_WAND.send(player); + } if (!player.hasPermission("fawe.tips")) BBC.TIP_SEL_LIST.or(BBC.TIP_SELECT_CONNECTED, BBC.TIP_SET_POS1, BBC.TIP_FARWAND, BBC.TIP_DISCORD).send(player); } @@ -440,20 +458,22 @@ public class SelectionCommands { index++; } return; - } + } else { - region = session.getSelection(player.getWorld()); + region = session.getSelection(player.getWorld()); + player.print("Type: " + session.getRegionSelector(player.getWorld()).getTypeName()); + + for (String line : session.getRegionSelector(player.getWorld()) + .getInformationLines()) { + player.print(line); + } + + } BlockVector3 size = region.getMaximumPoint() .subtract(region.getMinimumPoint()) .add(1, 1, 1); - player.print("Type: " + session.getRegionSelector(player.getWorld()) - .getTypeName()); - for (String line : session.getRegionSelector(player.getWorld()) - .getInformationLines()) { - player.print(line); - } player.print("Size: " + size); player.print("Cuboid distance: " + region.getMaximumPoint().distance(region.getMinimumPoint())); @@ -463,7 +483,7 @@ public class SelectionCommands { @Command( name = "/count", - desc = "Counts the number of a certain type of block" + desc = "Counts the number of blocks matching a mask" ) @CommandPermissions("worldedit.analysis.count") public void count(Player player, LocalSession session, EditSession editSession, diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java index 46eaadc41..f3a4d5252 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java @@ -110,6 +110,7 @@ public class ToolCommands { public void inspectBrush(Player player, LocalSession session, @Arg(desc = "The radius of the brush", def = "1") double radius) throws WorldEditException { + radius = Math.max(1,radius); BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND); session.setTool(player, new InspectBrush()); BBC.TOOL_INSPECT.send(player, itemStack.getType().getName()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/TransformCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/TransformCommands.java index 3cbc08e64..159763252 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/TransformCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/TransformCommands.java @@ -72,7 +72,7 @@ public class TransformCommands { aliases = {"#randomoffset"}, desc = "Random offset transform" ) - public ResettableExtent randomoffset(Actor actor, LocalSession session, double x, double y, double z, @Arg(name = "other", desc = "ResettableExtent", def = "#null") ResettableExtent other) { + public ResettableExtent randomOffset(Actor actor, LocalSession session, double x, double y, double z, @Arg(name = "other", desc = "ResettableExtent", def = "#null") ResettableExtent other) { return new RandomOffsetTransform(other, (int) x, (int) y, (int) z); } @@ -89,7 +89,7 @@ public class TransformCommands { desc = "All changes will be rotate around the initial position" ) public ResettableExtent rotate(Player player, LocalSession session, double x, double y, double z, @Arg(name = "other", desc = "ResettableExtent", def = "#null") ResettableExtent other) { - ExtentTraverser traverser = new ExtentTraverser(other).find(TransformExtent.class); + ExtentTraverser traverser = new ExtentTraverser<>(other).find(TransformExtent.class); BlockTransformExtent affine = traverser != null ? traverser.get() : null; if (affine == null) { other = affine = new TransformExtent(other); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java index 671d26ae1..53dcfd15a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java @@ -20,6 +20,7 @@ package com.sk89q.worldedit.command; import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT; +import static com.sk89q.worldedit.util.formatting.text.TextComponent.newline; import com.boydti.fawe.Fawe; import com.boydti.fawe.config.BBC; @@ -29,7 +30,6 @@ import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.RunnableVal3; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MathMan; -import com.boydti.fawe.util.chat.Message; import com.boydti.fawe.util.image.ImageUtil; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.IncompleteRegionException; @@ -70,6 +70,9 @@ import com.sk89q.worldedit.regions.CylinderRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.formatting.component.SubtleFormat; import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.TextComponent.Builder; +import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; +import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockTypes; @@ -85,10 +88,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.UUID; -import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; import java.util.function.Supplier; import javax.imageio.ImageIO; +import org.checkerframework.checker.nullness.qual.NonNull; import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.param.Arg; @@ -188,11 +191,13 @@ public class UtilityCommands { @Arg(desc = "The blocks to fill with") Pattern pattern, @Arg(desc = "The radius to fill in") - @Range(min = 1) double radius, + double radius, @Arg(desc = "The depth to fill", def = "1") - @Range(min = 1) int depth, + int depth, @Arg(desc = "Direction to fill", def = "down") BlockVector3 direction) throws WorldEditException { + radius = Math.max(1, radius); we.checkMaxRadius(radius); + depth = Math.max(1, depth); BlockVector3 pos = session.getPlacementPosition(player); int affected = editSession.fillDirection(pos, pattern, radius, depth, direction); @@ -281,9 +286,10 @@ public class UtilityCommands { @Arg(desc = "The blocks to fill with") Pattern pattern, @Arg(desc = "The radius to fill in") - @Range(min = 1) double radius, + double radius, @Arg(desc = "The depth to fill", def = "") - @Range(min = 1) Integer depth) throws WorldEditException { + Integer depth) throws WorldEditException { + radius = Math.max(1, radius); we.checkMaxRadius(radius); depth = depth == null ? Integer.MAX_VALUE : Math.max(1, depth); we.checkMaxRadius(radius); @@ -302,9 +308,10 @@ public class UtilityCommands { @Logging(PLACEMENT) public int drain(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The radius to drain") - @Range(min = 0) double radius, + double radius, @Switch(name = 'w', desc = "Also un-waterlog blocks") boolean waterlogged) throws WorldEditException { + radius = Math.max(0, radius); we.checkMaxRadius(radius); int affected = editSession.drainArea( session.getPlacementPosition(player), radius, waterlogged); @@ -321,7 +328,8 @@ public class UtilityCommands { @Logging(PLACEMENT) public int fixLava(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The radius to fix in") - @Range(min = 0) double radius) throws WorldEditException { + double radius) throws WorldEditException { + radius = Math.max(0, radius); we.checkMaxRadius(radius); int affected = editSession.fixLiquid(session.getPlacementPosition(player), radius, BlockTypes.LAVA); player.print(affected + " block(s) have been changed."); @@ -354,10 +362,13 @@ public class UtilityCommands { @Logging(PLACEMENT) public int removeAbove(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The apothem of the square to remove from", def = "1") - @Range(min = 1) int size, + int size, @Arg(desc = "The maximum height above you to remove from", def = "") Integer height) throws WorldEditException { + size = Math.max(1, size); we.checkMaxRadius(size); + World world = player.getWorld(); + height = height != null ? Math.min((world.getMaxY() + 1), height + 1) : (world.getMaxY() + 1); int affected = editSession.removeAbove(session.getPlacementPosition(player), size, height); BBC.VISITOR_BLOCK.send(player, affected); return affected; @@ -372,9 +383,10 @@ public class UtilityCommands { @Logging(PLACEMENT) public int removeBelow(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The apothem of the square to remove from", def = "1") - @Range(min =1) int size, + int size, @Arg(desc = "The maximum height below you to remove from", def = "") Integer height) throws WorldEditException { + size = Math.max(1, size); we.checkMaxRadius(size); World world = player.getWorld(); height = height != null ? Math.min((world.getMaxY() + 1), height + 1) : (world.getMaxY() + 1); @@ -395,7 +407,8 @@ public class UtilityCommands { @Arg(desc = "The mask of blocks to remove") Mask mask, @Arg(desc = "The radius of the square to remove from", def = "50") - @Range(min=1) int radius) throws WorldEditException { + int radius) throws WorldEditException { + radius = Math.max(1, radius); we.checkMaxRadius(radius); int affected = editSession.removeNear(session.getPlacementPosition(player), mask, radius); @@ -412,11 +425,12 @@ public class UtilityCommands { @Logging(PLACEMENT) public int replaceNear(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The radius of the square to remove in") - @Range(min=1) int radius, + int radius, @Arg(desc = "The mask matching blocks to remove", def = "") Mask from, @Arg(desc = "The pattern of blocks to replace with") Pattern to) throws WorldEditException { + radius = Math.max(1, radius); we.checkMaxRadius(radius); BlockVector3 base = session.getPlacementPosition(player); @@ -442,11 +456,12 @@ public class UtilityCommands { @Logging(PLACEMENT) public int snow(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The radius of the circle to snow in", def = "10") - @Range(min=1) double size) throws WorldEditException { + double size) throws WorldEditException { + size = Math.max(1, size); we.checkMaxRadius(size); int affected = editSession.simulateSnow(session.getPlacementPosition(player), size); - player.print(affected + " surfaces covered. Let it snow~"); + player.print(affected + " surface(s) covered. Let it snow~"); return affected; } @@ -459,11 +474,12 @@ public class UtilityCommands { @Logging(PLACEMENT) public int thaw(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The radius of the circle to thaw in", def = "10") - @Range(min=1) double size) throws WorldEditException { + double size) throws WorldEditException { + size = Math.max(1, size); we.checkMaxRadius(size); int affected = editSession.thaw(session.getPlacementPosition(player), size); - player.print(affected + " surfaces thawed."); + player.print(affected + " surface(s) thawed."); return affected; } @@ -476,9 +492,10 @@ public class UtilityCommands { @Logging(PLACEMENT) public int green(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The radius of the circle to convert in", def = "10") - @Range(min=1) double size, + double size, @Switch(name = 'f', desc = "Also convert coarse dirt") boolean convertCoarse) throws WorldEditException { + size = Math.max(1, size); we.checkMaxRadius(size); final boolean onlyNormalDirt = !convertCoarse; @@ -496,12 +513,12 @@ public class UtilityCommands { @Logging(PLACEMENT) public void extinguish(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The radius of the square to remove in", def = "") - @Range(min=1) Integer radius) throws WorldEditException { + Integer radius) throws WorldEditException { LocalConfiguration config = we.getConfiguration(); int defaultRadius = config.maxRadius != -1 ? Math.min(40, config.maxRadius) : 40; - int size = radius != null ? radius : defaultRadius; + int size = radius != null ? Math.max(1, radius) : defaultRadius; we.checkMaxRadius(size); Mask mask = new BlockTypeMask(editSession, BlockTypes.FIRE); @@ -657,7 +674,8 @@ public class UtilityCommands { return; } WorldEditAsyncCommandBuilder.createAndSendMessage(actor, () -> { - double result = expression.evaluateTimeout(WorldEdit.getInstance().getSessionManager().get(actor).getTimeout()); + double result = expression.evaluate( + new double[]{}, WorldEdit.getInstance().getSessionManager().get(actor).getTimeout()); String formatted = Double.isNaN(result) ? "NaN" : formatter.format(result); return SubtleFormat.wrap(input + " = ").append(TextComponent.of(formatted, TextColor.LIGHT_PURPLE)); }, null); @@ -690,16 +708,18 @@ public class UtilityCommands { } public static void list(File dir, Actor actor, InjectedValueAccess args, @Range(min = 0) int page, String formatName, boolean playerFolder, String onClickCmd) { - list(dir, actor, args, page, -1, formatName, playerFolder, new RunnableVal3() { + list(dir, actor, args, page, -1, formatName, playerFolder, new RunnableVal3() { @Override - public void run(Message m, URI uri, String fileName) { - m.text(BBC.SCHEMATIC_LIST_ELEM, fileName, ""); - if (onClickCmd != null) m.cmdTip(onClickCmd + " " + fileName); + public void run(Builder m, URI uri, String fileName) { + m.append(BBC.SCHEMATIC_LIST_ELEM.format(fileName, "")); + if (onClickCmd != null) { m.hoverEvent(HoverEvent.showText(TextComponent.of(onClickCmd + " " + fileName))) + .clickEvent(ClickEvent.runCommand(onClickCmd + " " + fileName)); + } } }); } - public static void list(File dir, Actor actor, InjectedValueAccess args, @Range(min = 0) int page, int perPage, String formatName, boolean playerFolder, RunnableVal3 eachMsg) { + public static void list(File dir, Actor actor, InjectedValueAccess args, @Range(min = 0) int page, int perPage, String formatName, boolean playerFolder, RunnableVal3 eachMsg) { List fileList = new ArrayList<>(); if (perPage == -1) perPage = actor instanceof Player ? 12 : 20; // More pages for console page = getFiles(dir, actor, args, page, perPage, formatName, playerFolder, fileList::add); @@ -719,7 +739,7 @@ public class UtilityCommands { return; } - final int sortType = args.hasFlag('d') ? -1 : args.hasFlag('n') ? 1 : 0; + final int sortType = 0; //args.hasFlag('d') ? -1 : args.hasFlag('n') ? 1 : 0; // cleanup file list fileList.sort((f1, f2) -> { boolean dir1 = f1.isDirectory(); @@ -751,18 +771,18 @@ public class UtilityCommands { if (fullArgs != null) { baseCmd = fullArgs.endsWith(" " + page) ? fullArgs.substring(0, fullArgs.length() - (" " + page).length()) : fullArgs; } - Message m = new Message(BBC.SCHEMATIC_LIST, page, pageCount); + @NonNull Builder m = TextComponent.builder(BBC.SCHEMATIC_LIST.format(page, pageCount)); UUID uuid = playerFolder ? actor.getUniqueId() : null; for (int i = offset; i < limit; i++) { - m.newline(); + m.append(newline()); File file = fileList.get(i); eachMsg.run(m, file.toURI(), getPath(dir, file, uuid)); } if (baseCmd != null) { - m.newline().paginate(baseCmd, page, pageCount); + //TODO m.newline().paginate(baseCmd, page, pageCount); } - m.send(actor); + actor.print(m.build()); } public static int getFiles(File root, Actor actor, InjectedValueAccess args, int page, int perPage, String formatName, boolean playerFolder, Consumer forEachFile, ListFilters... filters) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java index 39664aa18..a700bf576 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java @@ -101,7 +101,7 @@ public class WorldEditCommands { Platform platform = pm.queryCapability(capability); actor.printDebug(String.format("%s: %s", capability.name(), platform != null ? platform.getPlatformName() : "NONE")); } - actor.printDebug("------------------------------------"); + actor.printDebug(""); actor.printDebug("Wiki: " + "https://github.com/boy0001/FastAsyncWorldedit/wiki"); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java index b63b1f406..192796330 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java @@ -98,7 +98,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool protected int range = -1; private VisualMode visualMode = VisualMode.NONE; private TargetMode targetMode = TargetMode.TARGET_BLOCK_RANGE; - private Mask traceMask; + private Mask traceMask = null; private int targetOffset; private transient BrushSettings primary = new BrushSettings(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java index a854ed122..8fdbac6f7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java @@ -26,6 +26,7 @@ import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits; +import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.util.Location; @@ -72,10 +73,11 @@ public class DistanceWand extends BrushTool implements DoubleActionTraceTool { private Location getTarget(Player player) { Location target; + Mask mask = getTraceMask(); if (this.range > -1) { - target = player.getBlockTrace(getRange(), true); + target = player.getBlockTrace(getRange(), true, mask); } else { - target = player.getBlockTrace(DEFAULT_RANGE); + target = player.getBlockTrace(MAX_RANGE, false, mask); } if (target == null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java index d1c61edff..0589513fe 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java @@ -216,7 +216,7 @@ public class DefaultBlockParser extends InputParser { final World world = context.requireWorld(); final BlockVector3 primaryPosition; try { - primaryPosition = context.requireSession().getRegionSelector(world).getVerticies().get(index - 1); + primaryPosition = context.requireSession().getRegionSelector(world).getVertices().get(index - 1); } catch (IncompleteRegionException e) { throw new InputParseException("Your selection is not complete."); } @@ -356,4 +356,4 @@ public class DefaultBlockParser extends InputParser { } return holder; } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/DefaultPatternParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/DefaultPatternParser.java index f26231194..738cbea35 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/DefaultPatternParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/DefaultPatternParser.java @@ -54,7 +54,7 @@ public class DefaultPatternParser extends FaweParser { public DefaultPatternParser(WorldEdit worldEdit) { super(worldEdit); this.dispatcher = new SimpleDispatcher(); - this.register(new PatternCommands(worldEdit)); + this.register(new PatternCommands()); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java index cfa42f58a..c070e7cdf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java @@ -412,7 +412,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { if (typeId.hasBlockType()) { return typeId.getBlockType().getDefaultState().toBaseBlock(); } else { - return BlockTypes.AIR.getDefaultState().toBaseBlock(); + throw new NotABlockException(); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java index 0ac7ae229..415d797ea 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java @@ -59,6 +59,7 @@ import com.sk89q.worldedit.command.HistoryCommandsRegistration; import com.sk89q.worldedit.command.NavigationCommands; import com.sk89q.worldedit.command.NavigationCommandsRegistration; import com.sk89q.worldedit.command.PaintBrushCommands; +import com.sk89q.worldedit.command.PatternCommands; import com.sk89q.worldedit.command.RegionCommands; import com.sk89q.worldedit.command.RegionCommandsRegistration; import com.sk89q.worldedit.command.SchematicCommands; @@ -298,6 +299,20 @@ public final class PlatformCommandManager { public void registerAllCommands() { if (Settings.IMP.ENABLED_COMPONENTS.COMMANDS) { // TODO NOT IMPLEMENTED dunno why these have issues generating + registerSubCommands( + "patterns", + ImmutableList.of(), + "Patterns determine what blocks are placed", + PatternCommandsRegistration.builder(), + new PatternCommands() + ); + registerSubCommands( + "transforms", + ImmutableList.of(), + "Transforms modify how a block is placed", + TransformCommandsRegistration.builder(), + new TransformCommands() + ); registerSubCommands( "schematic", ImmutableList.of("schem", "/schematic", "/schem"), @@ -654,7 +669,7 @@ public final class PlatformCommandManager { handleCommandTask(task, context, session, event); } - public Object handleCommandTask(ThrowableSupplier task, InjectedValueAccess context, @Nullable LocalSession session, CommandEvent event) { + public void handleCommandTask(ThrowableSupplier task, InjectedValueAccess context, @Nullable LocalSession session, CommandEvent event) { Request.reset(); Actor actor = context.injectedValue(Key.of(Actor.class)).orElseThrow(() -> new IllegalStateException("No player")); @@ -666,7 +681,7 @@ public final class PlatformCommandManager { // exceptions without writing a hook into every dispatcher, we need to unwrap these // exceptions and rethrow their converted form, if their is one. try { - return task.get(); + task.get(); } catch (Throwable t) { // Use the exception converter to convert the exception if any of its causes // can be converted, otherwise throw the original exception @@ -729,7 +744,6 @@ public final class PlatformCommandManager { } event.setCancelled(true); - return null; } private MemoizingValueAccess initializeInjectedValues(Arguments arguments, Actor actor) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java index f99a689eb..04cea7ece 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java @@ -41,14 +41,10 @@ import com.sk89q.worldedit.command.tool.TraceTool; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.platform.BlockInteractEvent; import com.sk89q.worldedit.event.platform.ConfigurationLoadEvent; -import com.sk89q.worldedit.event.platform.Interaction; import com.sk89q.worldedit.event.platform.PlatformInitializeEvent; import com.sk89q.worldedit.event.platform.PlatformReadyEvent; import com.sk89q.worldedit.event.platform.PlayerInputEvent; -import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits; -import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; -import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; @@ -321,6 +317,8 @@ public class PlatformManager { LocalSession session = worldEdit.getSessionManager().get(actor); Request.reset(); + Request.request().setSession(session); + Request.request().setWorld(player.getWorld()); try { Vector3 vector = location.toVector(); @@ -335,7 +333,7 @@ public class PlatformManager { case HIT: { // superpickaxe is special because its primary interaction is a left click, not a right click // in addition, it is implicitly bound to all pickaxe items, not just a single tool item - if (session.hasSuperPickAxe()) { + if (session.hasSuperPickAxe() && player.isHoldingPickAxe()) { final BlockTool superPickaxe = session.getSuperPickaxe(); if (superPickaxe != null && superPickaxe.canUse(player) && player.isHoldingPickAxe()) { FawePlayer fp = FawePlayer.wrap(player); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java index 1589fcfaa..aad178ec3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java @@ -43,6 +43,7 @@ import javax.annotation.Nullable; * A base class for {@link Extent}s that merely passes extents onto another. */ public class AbstractDelegateExtent implements Extent, LightingExtent { + private final Extent extent; /** @@ -60,14 +61,19 @@ public class AbstractDelegateExtent implements Extent, LightingExtent { * * @return the extent */ - public final Extent getExtent() { + public Extent getExtent() { return extent; } + @Override + public BlockState getBlock(BlockVector3 position) { + return getBlock(position.getX(),position.getY(),position.getZ()); + } + /* - Queue based methods - TODO NOT IMPLEMENTED: IQueueExtent and such need to implement these - */ + Queue based methods + TODO NOT IMPLEMENTED: IQueueExtent and such need to implement these + */ public boolean isQueueEnabled() { return extent.isQueueEnabled(); } @@ -78,7 +84,8 @@ public class AbstractDelegateExtent implements Extent, LightingExtent { if (!(extent instanceof ForgetfulExtentBuffer)) { // placeholder extent.disableQueue(); } - } catch (FaweException ignored) {} + } catch (FaweException ignored) { + } if (extent instanceof AbstractDelegateExtent) { Extent next = ((AbstractDelegateExtent) extent).getExtent(); new ExtentTraverser(this).setNext(next); @@ -108,8 +115,7 @@ public class AbstractDelegateExtent implements Extent, LightingExtent { } else { history.setChangeSet(changeSet); } - } - else if (extent instanceof AbstractDelegateExtent) { + } else if (extent instanceof AbstractDelegateExtent) { ((AbstractDelegateExtent) extent).setChangeSet(changeSet); } else if (changeSet != null) { new ExtentTraverser<>(this).setNext(new HistoryExtent(extent, changeSet)); @@ -124,21 +130,12 @@ public class AbstractDelegateExtent implements Extent, LightingExtent { /* Bounds */ - @Override - public BlockVector3 getMinimumPoint() { - return extent.getMinimumPoint(); - } - - @Override - public BlockVector3 getMaximumPoint() { - return extent.getMaximumPoint(); - } - @Override public int getMaxY() { return extent.getMaxY(); } + /* Input + Output */ @@ -147,7 +144,6 @@ public class AbstractDelegateExtent implements Extent, LightingExtent { public BlockState getBlock(int x, int y, int z) { return extent.getBlock(x, y, z); } - @Override public BaseBlock getFullBlock(int x, int y, int z) { return extent.getFullBlock(x, y, z); @@ -164,10 +160,12 @@ public class AbstractDelegateExtent implements Extent, LightingExtent { } @Override - public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { + public > boolean setBlock(int x, int y, int z, T block) + throws WorldEditException { return extent.setBlock(x, y, z, block); } + /* Light */ @@ -184,7 +182,6 @@ public class AbstractDelegateExtent implements Extent, LightingExtent { } return getBrightness(x, y, z); } - public int getOpacity(int x, int y, int z) { if (extent instanceof LightingExtent) { return ((LightingExtent) extent).getOpacity(x, y, z); @@ -217,15 +214,21 @@ public class AbstractDelegateExtent implements Extent, LightingExtent { } } - /* - Generic - */ - @Override public String toString() { return super.toString() + ":" + extent.toString(); } + @Override + public BlockVector3 getMinimumPoint() { + return extent.getMinimumPoint(); + } + + @Override + public BlockVector3 getMaximumPoint() { + return extent.getMaximumPoint(); + } + protected Operation commitBefore() { return null; } @@ -234,7 +237,9 @@ public class AbstractDelegateExtent implements Extent, LightingExtent { public @Nullable Operation commit() { Operation ours = commitBefore(); Operation other = null; - if (extent != this) other = extent.commit(); + if (extent != this) { + other = extent.commit(); + } if (ours != null && other != null) { return new OperationQueue(ours, other); } else if (ours != null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/NullExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/NullExtent.java index cb31e893d..52a3d854c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/NullExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/NullExtent.java @@ -45,8 +45,6 @@ import javax.annotation.Nullable; */ public class NullExtent implements Extent { - public static final NullExtent INSTANCE = new NullExtent(); - @Override public BlockVector3 getMinimumPoint() { return BlockVector3.ZERO; @@ -73,6 +71,7 @@ public class NullExtent implements Extent { return null; } + @Override public BlockState getBlock(BlockVector3 position) { return BlockTypes.AIR.getDefaultState(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ExtentBuffer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ExtentBuffer.java index 562f094e5..a6cbab8f5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ExtentBuffer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ExtentBuffer.java @@ -19,9 +19,11 @@ package com.sk89q.worldedit.extent.buffer; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.Maps; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.extent.AbstractDelegateExtent; +import com.sk89q.worldedit.extent.AbstractBufferingExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Masks; @@ -29,16 +31,14 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; - import java.util.Map; - -import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Optional; /** * Buffers changes to an {@link Extent} and allows retrieval of the changed blocks, * without modifying the underlying extent. */ -public class ExtentBuffer extends AbstractDelegateExtent { +public class ExtentBuffer extends AbstractBufferingExtent { private final Map buffer = Maps.newHashMap(); private final Mask mask; @@ -66,6 +66,14 @@ public class ExtentBuffer extends AbstractDelegateExtent { this.mask = mask; } + @Override + protected Optional getBufferedBlock(BlockVector3 position) { + if (mask.test(position)) { + return Optional.of(buffer.computeIfAbsent(position, (pos -> getExtent().getFullBlock(pos)))); + } + return Optional.empty(); + } + @Override public BlockState getBlock(BlockVector3 position) { if (mask.test(position)) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java index 6994442fe..aeaf07e85 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java @@ -61,7 +61,7 @@ public interface Clipboard extends Extent { /** * Returns true if the clipboard has biome data. This can be checked since {@link Extent#getBiome(BlockVector2)} - * strongly suggests returning {@link com.sk89q.worldedit.world.biome.BiomeTypes#OCEAN} instead of {@code null} + * strongly suggests returning {@link com.sk89q.worldedit.world.biome.BiomeTypes.OCEAN} instead of {@code null} * if biomes aren't present. However, it might not be desired to set areas to ocean if the clipboard is defaulting * to ocean, instead of having biomes explicitly set. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/BuiltInClipboardFormat.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/BuiltInClipboardFormat.java index 1813d2240..9483f0d5b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/BuiltInClipboardFormat.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/BuiltInClipboardFormat.java @@ -72,13 +72,27 @@ public enum BuiltInClipboardFormat implements ClipboardFormat { @Override public ClipboardWriter getWriter(OutputStream outputStream) throws IOException { - throw new IOException("This format does not support saving, use `.schem` as format"); + throw new IOException("This format does not support saving"); } @Override public boolean isFormat(File file) { - String name = file.getName().toLowerCase(); - return name.endsWith(".schematic") || name.endsWith(".mcedit") || name.endsWith(".mce"); + try (NBTInputStream str = new NBTInputStream(new GZIPInputStream(new FileInputStream(file)))) { + NamedTag rootTag = str.readNamedTag(); + if (!rootTag.getName().equals("Schematic")) { + return false; + } + CompoundTag schematicTag = (CompoundTag) rootTag.getTag(); + + // Check + Map schematic = schematicTag.getValue(); + if (!schematic.containsKey("Materials")) { + return false; + } + } catch (Exception e) { + return false; + } + return true; } }, SPONGE_SCHEMATIC("sponge", "schem") { @@ -113,8 +127,23 @@ public enum BuiltInClipboardFormat implements ClipboardFormat { @Override public boolean isFormat(File file) { - String name = file.getName().toLowerCase(); - return name.endsWith(".schem") || name.endsWith(".sponge"); + try (NBTInputStream str = new NBTInputStream(new GZIPInputStream(new FileInputStream(file)))) { + NamedTag rootTag = str.readNamedTag(); + if (!rootTag.getName().equals("Schematic")) { + return false; + } + CompoundTag schematicTag = (CompoundTag) rootTag.getTag(); + + // Check + Map schematic = schematicTag.getValue(); + if (!schematic.containsKey("Version")) { + return false; + } + } catch (Exception e) { + return false; + } + + return true; } }, @@ -149,6 +178,8 @@ public enum BuiltInClipboardFormat implements ClipboardFormat { try (NBTInputStream str = new NBTInputStream(new GZIPInputStream(new FileInputStream(file)))) { NamedTag rootTag = str.readNamedTag(); CompoundTag structureTag = (CompoundTag) rootTag.getTag(); + + // Check Map structure = structureTag.getValue(); if (!structure.containsKey("DataVersion")) { return false; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java index f34396e2a..ee99024a6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java @@ -69,7 +69,7 @@ public class ClipboardFormats { checkNotNull(format); for (String key : format.getAliases()) { - String lowKey = key.toLowerCase(Locale.ROOT); + String lowKey = key.toLowerCase(Locale.ENGLISH); ClipboardFormat old = aliasMap.put(lowKey, format); if (old != null) { aliasMap.put(lowKey, old); @@ -77,7 +77,7 @@ public class ClipboardFormats { } } for (String ext : format.getFileExtensions()) { - String lowExt = ext.toLowerCase(Locale.ROOT); + String lowExt = ext.toLowerCase(Locale.ENGLISH); fileExtensionMap.put(lowExt, format); } registeredFormats.add(format); @@ -99,7 +99,7 @@ public class ClipboardFormats { @Nullable public static ClipboardFormat findByAlias(String alias) { checkNotNull(alias); - return aliasMap.get(alias.toLowerCase(Locale.ROOT).trim()); + return aliasMap.get(alias.toLowerCase(Locale.ENGLISH).trim()); } /** @@ -157,7 +157,7 @@ public class ClipboardFormats { * It is not in SchematicCommands because it may rely on internal register calls. */ public static String[] getFileExtensionArray() { - return fileExtensionMap.keySet().toArray(new String[0]); + return fileExtensionMap.keySet().toArray(new String[fileExtensionMap.keySet().size()]); } private ClipboardFormats() { @@ -259,7 +259,7 @@ public class ClipboardFormats { File[] files = dir.listFiles(pathname -> { String input = pathname.getName(); String extension = input.substring(input.lastIndexOf('.') + 1); - return (extensions.contains(extension.toLowerCase())); + return (extensions.contains(extension.toLowerCase(Locale.ENGLISH))); }); LazyClipboardHolder[] clipboards = new LazyClipboardHolder[files.length]; for (int i = 0; i < files.length; i++) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardWriter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardWriter.java index 1407f579e..c23306fd5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardWriter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardWriter.java @@ -19,10 +19,18 @@ package com.sk89q.worldedit.extent.clipboard.io; +import com.sk89q.jnbt.DoubleTag; +import com.sk89q.jnbt.FloatTag; +import com.sk89q.jnbt.ListTag; +import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.math.Vector3; +import com.sk89q.worldedit.util.Location; import java.io.Closeable; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; /** * Writes {@code Clipboard}s. @@ -39,4 +47,18 @@ public interface ClipboardWriter extends Closeable { */ void write(Clipboard clipboard) throws IOException; + default Tag writeVector(Vector3 vector) { + List list = new ArrayList<>(); + list.add(new DoubleTag(vector.getX())); + list.add(new DoubleTag(vector.getY())); + list.add(new DoubleTag(vector.getZ())); + return new ListTag(DoubleTag.class, list); + } + + default Tag writeRotation(Location location) { + List list = new ArrayList<>(); + list.add(new FloatTag(location.getYaw())); + list.add(new FloatTag(location.getPitch())); + return new ListTag(FloatTag.class, list); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java index b97885f84..f2195b37c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java @@ -19,9 +19,12 @@ package com.sk89q.worldedit.extent.clipboard.io; +import static com.google.common.base.Preconditions.checkNotNull; + import com.boydti.fawe.Fawe; import com.boydti.fawe.config.Settings; import com.boydti.fawe.jnbt.NBTStreamer; +import com.boydti.fawe.jnbt.NBTStreamer.LazyReader; import com.boydti.fawe.object.FaweInputStream; import com.boydti.fawe.object.FaweOutputStream; import com.boydti.fawe.object.clipboard.CPUOptimizedClipboard; @@ -31,21 +34,15 @@ import com.boydti.fawe.object.clipboard.MemoryOptimizedClipboard; import com.boydti.fawe.object.io.FastByteArrayOutputStream; import com.boydti.fawe.object.io.FastByteArraysInputStream; import com.boydti.fawe.util.IOUtil; - -import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.jnbt.ByteArrayTag; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.NBTInputStream; -import com.sk89q.jnbt.NamedTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.entity.BaseEntity; 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.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.math.BlockVector2; @@ -60,18 +57,16 @@ import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.entity.EntityType; import com.sk89q.worldedit.world.entity.EntityTypes; import com.sk89q.worldedit.world.storage.NBTConversions; -import net.jpountz.lz4.LZ4BlockInputStream; -import net.jpountz.lz4.LZ4BlockOutputStream; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.DataInputStream; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.function.BiConsumer; +import net.jpountz.lz4.LZ4BlockInputStream; +import net.jpountz.lz4.LZ4BlockOutputStream; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Reads schematic files using the Sponge Schematic Specification. @@ -174,24 +169,18 @@ public class SpongeSchematicReader extends NBTSchematicReader { /// readBiomes - streamer.addReader("Schematic.BlockData.#", new NBTStreamer.LazyReader() { - @Override - public void accept(Integer arrayLen, DataInputStream dis) { - try (FaweOutputStream blocks = new FaweOutputStream(new LZ4BlockOutputStream(blocksOut))) { - IOUtil.copy(dis, blocks, arrayLen); - } catch (IOException e) { - e.printStackTrace(); - } + streamer.addReader("Schematic.BlockData.#", (LazyReader) (arrayLen, dis) -> { + try (FaweOutputStream blocks = new FaweOutputStream(new LZ4BlockOutputStream(blocksOut))) { + IOUtil.copy(dis, blocks, arrayLen); + } catch (IOException e) { + e.printStackTrace(); } }); - streamer.addReader("Schematic.Biomes.#", new NBTStreamer.LazyReader() { - @Override - public void accept(Integer arrayLen, DataInputStream dis) { - try (FaweOutputStream biomes = new FaweOutputStream(new LZ4BlockOutputStream(biomesOut))) { - IOUtil.copy(dis, biomes, arrayLen); - } catch (IOException e) { - e.printStackTrace(); - } + streamer.addReader("Schematic.Biomes.#", (LazyReader) (arrayLen, dis) -> { + try (FaweOutputStream biomes = new FaweOutputStream(new LZ4BlockOutputStream(biomesOut))) { + IOUtil.copy(dis, biomes, arrayLen); + } catch (IOException e) { + e.printStackTrace(); } }); streamer.addReader("Schematic.TileEntities.#", (BiConsumer) (index, value) -> { @@ -291,6 +280,17 @@ public class SpongeSchematicReader extends NBTSchematicReader { return clipboard; } + private Clipboard readVersion2(BlockArrayClipboard version1, CompoundTag schematicTag) throws IOException { + Map schematic = schematicTag.getValue(); + if (schematic.containsKey("BiomeData")) { + readBiomes(version1, schematic); + } + if (schematic.containsKey("Entities")) { + readEntities(version1, schematic); + } + return version1; + } + private void readBiomes(BlockArrayClipboard clipboard, Map schematic) throws IOException { ByteArrayTag dataTag = requireTag(schematic, "BiomeData", ByteArrayTag.class); IntTag maxTag = requireTag(schematic, "BiomePaletteMax", IntTag.class); @@ -349,6 +349,36 @@ public class SpongeSchematicReader extends NBTSchematicReader { } } + private void readEntities(BlockArrayClipboard clipboard, Map schematic) throws IOException { + List entList = requireTag(schematic, "Entities", ListTag.class).getValue(); + if (entList.isEmpty()) { + return; + } + for (Tag et : entList) { + if (!(et instanceof CompoundTag)) { + continue; + } + CompoundTag entityTag = (CompoundTag) et; + Map tags = entityTag.getValue(); + String id = requireTag(tags, "Id", StringTag.class).getValue(); + entityTag = entityTag.createBuilder().putString("id", id).remove("Id").build(); + + if (fixer != null) { + entityTag = fixer.fixUp(DataFixer.FixTypes.ENTITY, entityTag, dataVersion); + } + + EntityType entityType = EntityTypes.get(id); + if (entityType != null) { + Location location = NBTConversions.toLocation(clipboard, + requireTag(tags, "Pos", ListTag.class), + requireTag(tags, "Rotation", ListTag.class)); + BaseEntity state = new BaseEntity(entityType, entityTag); + clipboard.createEntity(location, state); + } else { + log.warn("Unknown entity when pasting schematic: " + id); + } + } + } @Override public void close() throws IOException { inputStream.close(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java index 0a0240e4e..67bc219d6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java @@ -19,13 +19,19 @@ package com.sk89q.worldedit.extent.clipboard.io; +import static com.google.common.base.Preconditions.checkNotNull; + import com.boydti.fawe.jnbt.NBTStreamer; import com.boydti.fawe.object.clipboard.FaweClipboard; import com.boydti.fawe.util.IOUtil; - -import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.Maps; -import com.sk89q.jnbt.*; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.IntArrayTag; +import com.sk89q.jnbt.ListTag; +import com.sk89q.jnbt.NBTConstants; +import com.sk89q.jnbt.NBTOutputStream; +import com.sk89q.jnbt.StringTag; +import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; @@ -34,18 +40,13 @@ import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeTypes; 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 net.jpountz.lz4.LZ4BlockInputStream; -import net.jpountz.lz4.LZ4BlockOutputStream; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataOutput; @@ -53,13 +54,13 @@ import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; -import java.util.stream.IntStream; +import net.jpountz.lz4.LZ4BlockInputStream; +import net.jpountz.lz4.LZ4BlockOutputStream; /** * Writes schematic files using the Sponge schematic format. @@ -345,21 +346,6 @@ public class SpongeSchematicWriter implements ClipboardWriter { schematic.writeNamedTag("Entities", new ListTag(CompoundTag.class, entities)); } - private static Tag writeVector(Vector3 vector) { - List list = new ArrayList<>(); - list.add(new DoubleTag(vector.getX())); - list.add(new DoubleTag(vector.getY())); - list.add(new DoubleTag(vector.getZ())); - return new ListTag(DoubleTag.class, list); - } - - private static Tag writeRotation(Location location) { - List list = new ArrayList<>(); - list.add(new FloatTag(location.getYaw())); - list.add(new FloatTag(location.getPitch())); - return new ListTag(FloatTag.class, list); - } - @Override public void close() throws IOException { outputStream.close(); 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 a65134097..5044ce970 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 @@ -28,14 +28,10 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.util.Arrays; import java.util.HashMap; import java.util.Map; - -import static com.google.common.base.Preconditions.checkNotNull; +import javax.annotation.Nullable; /** * Applies a {@link BlockBag} to operations. @@ -44,7 +40,7 @@ public class BlockBagExtent extends AbstractDelegateExtent { private final boolean mine; private int[] missingBlocks = new int[BlockTypes.size()]; - private final BlockBag blockBag; + private BlockBag blockBag; /** * Create a new instance. @@ -52,13 +48,12 @@ public class BlockBagExtent extends AbstractDelegateExtent { * @param extent the extent * @param blockBag the block bag */ - public BlockBagExtent(Extent extent, @Nonnull BlockBag blockBag) { + public BlockBagExtent(Extent extent, @Nullable BlockBag blockBag) { this(extent, blockBag, false); } - public BlockBagExtent(Extent extent, @Nonnull BlockBag blockBag, boolean mine) { + public BlockBagExtent(Extent extent, @Nullable BlockBag blockBag, boolean mine) { super(extent); - checkNotNull(blockBag); this.blockBag = blockBag; this.mine = mine; } @@ -72,6 +67,14 @@ public class BlockBagExtent extends AbstractDelegateExtent { return blockBag; } + /** + * Set the block bag. + * + * @param blockBag a block bag, which may be null if none is used + */ + public void setBlockBag(@Nullable BlockBag blockBag) { + this.blockBag = blockBag; + } /** * Gets the list of missing blocks and clears the list for the next * operation. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/ChunkBatchingExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/ChunkBatchingExtent.java index b8f6082c4..112708924 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/ChunkBatchingExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/ChunkBatchingExtent.java @@ -19,22 +19,24 @@ package com.sk89q.worldedit.extent.reorder; +import com.google.common.collect.Table; +import com.google.common.collect.TreeBasedTable; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.extent.AbstractDelegateExtent; +import com.sk89q.worldedit.extent.AbstractBufferingExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.RunContext; -import com.sk89q.worldedit.function.operation.SetLocatedBlocks; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.util.collection.LocatedBlockList; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; - import java.util.Comparator; +import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.SortedMap; -import java.util.TreeMap; +import java.util.Map; +import java.util.Optional; +import java.util.Set; /** * A special extent that batches changes into Minecraft chunks. This helps @@ -42,17 +44,19 @@ import java.util.TreeMap; * loaded repeatedly, however it does take more memory due to caching the * blocks. */ -public class ChunkBatchingExtent extends AbstractDelegateExtent { +public class ChunkBatchingExtent extends AbstractBufferingExtent { /** * Comparator optimized for sorting chunks by the region file they reside * in. This allows for file caches to be used while loading the chunk. */ private static final Comparator REGION_OPTIMIZED_SORT = - Comparator.comparing((BlockVector2 vec) -> vec.divide(32), BlockVector2.COMPARING_GRID_ARRANGEMENT) + Comparator.comparing((BlockVector2 vec) -> vec.shr(5), BlockVector2.COMPARING_GRID_ARRANGEMENT) .thenComparing(BlockVector2.COMPARING_GRID_ARRANGEMENT); - private final SortedMap batches = new TreeMap<>(REGION_OPTIMIZED_SORT); + private final Table batches = + TreeBasedTable.create(REGION_OPTIMIZED_SORT, BlockVector3.sortByCoordsYzx()); + private final Set containedBlocks = new HashSet<>(); private boolean enabled; public ChunkBatchingExtent(Extent extent) { @@ -76,16 +80,32 @@ public class ChunkBatchingExtent extends AbstractDelegateExtent { return enabled; } + private BlockVector2 getChunkPos(BlockVector3 location) { + return location.shr(4).toBlockVector2(); + } + + private BlockVector3 getInChunkPos(BlockVector3 location) { + return BlockVector3.at(location.getX() & 15, location.getY(), location.getZ() & 15); + } @Override public > boolean setBlock(BlockVector3 location, B block) throws WorldEditException { if (!enabled) { - return getExtent().setBlock(location, block); + return setDelegateBlock(location, block); } - BlockVector2 chunkPos = BlockVector2.at(location.getBlockX() >> 4, location.getBlockZ() >> 4); - batches.computeIfAbsent(chunkPos, k -> new LocatedBlockList()).add(location, block); + BlockVector2 chunkPos = getChunkPos(location); + BlockVector3 inChunkPos = getInChunkPos(location); + batches.put(chunkPos, inChunkPos, block.toBaseBlock()); + containedBlocks.add(location); return true; } + @Override + protected Optional getBufferedBlock(BlockVector3 position) { + if (!containedBlocks.contains(position)) { + return Optional.empty(); + } + return Optional.of(batches.get(getChunkPos(position), getInChunkPos(position))); + } @Override protected Operation commitBefore() { if (!commitRequired()) { @@ -94,17 +114,22 @@ public class ChunkBatchingExtent extends AbstractDelegateExtent { return new Operation() { // we get modified between create/resume -- only create this on resume to prevent CME - private Iterator batchIterator; + private Iterator>> batchIterator; @Override public Operation resume(RunContext run) throws WorldEditException { if (batchIterator == null) { - batchIterator = batches.values().iterator(); + batchIterator = batches.rowMap().entrySet().iterator(); } if (!batchIterator.hasNext()) { return null; } - new SetLocatedBlocks(getExtent(), batchIterator.next()).resume(run); + Map.Entry> next = batchIterator.next(); + BlockVector3 chunkOffset = next.getKey().toBlockVector3().shl(4); + for (Map.Entry block : next.getValue().entrySet()) { + getExtent().setBlock(block.getKey().add(chunkOffset), block.getValue()); + containedBlocks.remove(block.getKey()); + } batchIterator.remove(); return this; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java index 55ddbcb73..e650bf90a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java @@ -20,7 +20,7 @@ package com.sk89q.worldedit.extent.reorder; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.extent.AbstractDelegateExtent; +import com.sk89q.worldedit.extent.AbstractBufferingExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.OperationQueue; @@ -33,16 +33,19 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; - import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; /** * Re-orders blocks into several stages. */ -public class MultiStageReorder extends AbstractDelegateExtent implements ReorderingExtent { +public class MultiStageReorder extends AbstractBufferingExtent implements ReorderingExtent { private static final Map priorityMap = new HashMap<>(); @@ -139,6 +142,7 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder priorityMap.put(BlockTypes.MOVING_PISTON, PlacementPriority.FINAL); } + private final Set containedBlocks = new HashSet<>(); private Map stages = new HashMap<>(); private boolean enabled; @@ -212,7 +216,7 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder @Override public > boolean setBlock(BlockVector3 location, B block) throws WorldEditException { if (!enabled) { - return super.setBlock(location, block); + return setDelegateBlock(location, block); } BlockState existing = getBlock(location); @@ -240,9 +244,21 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder } stages.get(priority).add(location, block); + containedBlocks.add(location); return !existing.equalsFuzzy(block); } + @Override + protected Optional getBufferedBlock(BlockVector3 position) { + if (!containedBlocks.contains(position)) { + return Optional.empty(); + } + return stages.values().stream() + .map(blocks -> blocks.get(position)) + .filter(Objects::nonNull) + .findAny(); + } + @Override public Operation commitBefore() { if (!commitRequired()) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/BlockReplace.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/BlockReplace.java index 57f9d5aff..00fbcd553 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/BlockReplace.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/BlockReplace.java @@ -50,7 +50,7 @@ public class BlockReplace implements RegionFunction { @Override public boolean apply(BlockVector3 position) throws WorldEditException { - return pattern.apply(extent, position, position); + return extent.setBlock(position, pattern.apply(position)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java index cea01978c..b4aa500bc 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java @@ -147,17 +147,33 @@ public class ExtentEntityCopy implements EntityFunction { CompoundTag tag = state.getNbtData(); if (tag != null) { + // Handle leashed entities + Tag leashTag = tag.getValue().get("Leash"); + if (leashTag instanceof CompoundTag) { + CompoundTag leashCompound = (CompoundTag) leashTag; + if (leashCompound.containsKey("X")) { // leashed to a fence + Vector3 tilePosition = Vector3.at(leashCompound.asInt("X"), leashCompound.asInt("Y"), leashCompound.asInt("Z")); + BlockVector3 newLeash = transform.apply(tilePosition.subtract(from)).add(to).toBlockPoint(); + return new BaseEntity(state.getType(), tag.createBuilder() + .put("Leash", leashCompound.createBuilder() + .putInt("X", newLeash.getBlockX()) + .putInt("Y", newLeash.getBlockY()) + .putInt("Z", newLeash.getBlockZ()) + .build() + ).build()); + } + } + boolean changed = false; // Handle hanging entities (paintings, item frames, etc.) - + boolean hasTilePosition = tag.containsKey("TileX") && tag.containsKey("TileY") && tag.containsKey("TileZ"); + boolean hasFacing = tag.containsKey("Facing"); tag = tag.createBuilder().build(); Map values = ReflectionUtils.getMap(tag.getValue()); - boolean hasTilePosition = tag.containsKey("TileX") && tag.containsKey("TileY") && tag.containsKey("TileZ"); boolean hasDirection = tag.containsKey("Direction"); boolean hasLegacyDirection = tag.containsKey("Dir"); - boolean hasFacing = tag.containsKey("Facing"); if (hasTilePosition) { changed = true; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/AbstractExtentMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/AbstractExtentMask.java index a5478156c..dbb3f28cc 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/AbstractExtentMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/AbstractExtentMask.java @@ -44,7 +44,7 @@ public abstract class AbstractExtentMask extends AbstractMask { * * @return the extent */ - public final Extent getExtent() { + public Extent getExtent() { return extent; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java index 6719f7587..318f8cb86 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java @@ -20,9 +20,11 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockCategory; +import javax.annotation.Nullable; /** * A mask that tests whether a block matches a given {@link BlockCategory}, or tag. @@ -39,7 +41,12 @@ public class BlockCategoryMask extends AbstractExtentMask { @Override public boolean test(BlockVector3 vector) { - return category.contains(vector.getBlock(getExtent())); + return category.contains(getExtent().getBlock(vector)); } + @Nullable + @Override + public Mask2D toMask2D() { + return null; + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java index 19d6c63fa..bb6923e24 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java @@ -19,6 +19,8 @@ package com.sk89q.worldedit.function.mask; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.NullExtent; import com.sk89q.worldedit.math.BlockVector3; @@ -31,8 +33,17 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.function.Predicate; +import javax.annotation.Nullable; +/** + * A mask that checks whether blocks at the given positions are matched by + * a block in a list. + * + *

This mask checks for both an exact block type and state value match, + * respecting fuzzy status of the BlockState.

+ */ public class BlockMask extends ABlockMask { + private final boolean[] ordinals; public BlockMask() { @@ -49,6 +60,10 @@ public class BlockMask extends ABlockMask { } /** + * Create a new block mask. + * + * @param extent the extent + * @param blocks a list of blocks to match * @deprecated NBT not supported by this mask */ @Deprecated @@ -57,11 +72,23 @@ public class BlockMask extends ABlockMask { add(blocks); } + /** + * Create a new block mask. + * + * @param extent the extent + * @param block an array of blocks to match + */ + public BlockMask(Extent extent, BaseBlock... block) { + this(extent, Arrays.asList(checkNotNull(block))); + } + public BlockMask add(Predicate predicate) { for (int i = 0; i < ordinals.length; i++) { if (!ordinals[i]) { BlockState state = BlockTypes.states[i]; - if (state != null) ordinals[i] = predicate.test(state); + if (state != null) { + ordinals[i] = predicate.test(state); + } } } return this; @@ -73,7 +100,9 @@ public class BlockMask extends ABlockMask { } public BlockMask remove(BlockState... states) { - for (BlockState state : states) ordinals[state.getOrdinal()] = false; + for (BlockState state : states) { + ordinals[state.getOrdinal()] = false; + } return this; } @@ -84,13 +113,17 @@ public class BlockMask extends ABlockMask { public boolean isEmpty() { for (boolean value : ordinals) { - if (value) return false; + if (value) { + return false; + } } return true; } - public BlockMask addStates(Collection states) { - for (BlockState state : states) ordinals[state.getOrdinal()] = true; + private BlockMask addStates(Collection states) { + for (BlockState state : states) { + ordinals[state.getOrdinal()] = true; + } return this; } @@ -99,7 +132,7 @@ public class BlockMask extends ABlockMask { return this; } - public BlockMask addTypes(Collection types) { + private BlockMask addTypes(Collection types) { for (BlockType type : types) { for (BlockState state : type.getAllStates()) { ordinals[state.getOrdinal()] = true; @@ -109,6 +142,9 @@ public class BlockMask extends ABlockMask { } /** + * Add the given blocks to the list of criteria. + * + * @param blocks a list of blocks * @deprecated NBT not supported by this mask */ @Deprecated @@ -118,6 +154,15 @@ public class BlockMask extends ABlockMask { } } + /** + * Add the given blocks to the list of criteria. + * + * @param block an array of blocks + */ + public void add(BaseBlock... block) { + add(Arrays.asList(checkNotNull(block))); + } + @Override public boolean test(BlockState state) { return ordinals[state.getOrdinal()]; @@ -156,6 +201,12 @@ public class BlockMask extends ABlockMask { return null; } + @Nullable + @Override + public Mask2D toMask2D() { + return null; + } + @Override public Mask tryOptimize() { int setStates = 0; @@ -218,7 +269,11 @@ public class BlockMask extends ABlockMask { } if (setTypes == totalTypes - 1) { - return new InverseSingleBlockTypeMask(getExtent(), unsetType); + if (unsetType != null) { + return new InverseSingleBlockTypeMask(getExtent(), unsetType); + } else { + throw new IllegalArgumentException("unsetType cannot be null when passed to InverseSingleBlockTypeMask"); + } } return null; @@ -227,7 +282,9 @@ public class BlockMask extends ABlockMask { @Override public Mask inverse() { boolean[] cloned = ordinals.clone(); - for (int i = 0; i < cloned.length; i++) cloned[i] = !cloned[i]; + for (int i = 0; i < cloned.length; i++) { + cloned[i] = !cloned[i]; + } return new BlockMask(getExtent(), cloned); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockStateMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockStateMask.java index 7e5acdc94..44e9dcdc3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockStateMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockStateMask.java @@ -19,7 +19,6 @@ package com.sk89q.worldedit.function.mask; -import com.boydti.fawe.beta.FilterBlock; import com.google.common.collect.Maps; import com.sk89q.worldedit.blocks.Blocks; import com.sk89q.worldedit.extent.Extent; @@ -27,8 +26,8 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; - import java.util.Map; +import javax.annotation.Nullable; @Deprecated public class BlockStateMask extends AbstractExtentMask { @@ -66,4 +65,9 @@ public class BlockStateMask extends AbstractExtentMask { .allMatch(entry -> block.getState(entry.getKey()) == entry.getValue()); } + @Nullable + @Override + public Mask2D toMask2D() { + return null; + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockTypeMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockTypeMask.java index e56bd813e..b235d573f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockTypeMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockTypeMask.java @@ -20,15 +20,16 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; - -import javax.annotation.Nullable; import java.util.Collection; import java.util.HashSet; import java.util.Set; +import javax.annotation.Nullable; +import org.jetbrains.annotations.NotNull; /** * A mask that checks whether blocks at the given positions are matched by @@ -38,10 +39,8 @@ import java.util.Set; * use {@link BlockMask}.

* @deprecated use BlockMaskBuilder */ -import static com.google.common.base.Preconditions.checkNotNull; - @Deprecated -public final class BlockTypeMask extends AbstractExtentMask { +public class BlockTypeMask extends AbstractExtentMask { private final boolean[] types; @@ -51,7 +50,7 @@ public final class BlockTypeMask extends AbstractExtentMask { * @param extent the extent * @param blocks a list of blocks to match */ - public BlockTypeMask(Extent extent, Collection blocks) { + public BlockTypeMask(Extent extent, @NotNull Collection blocks) { this(extent, blocks.toArray(new BlockType[0])); } @@ -61,23 +60,18 @@ public final class BlockTypeMask extends AbstractExtentMask { * @param extent the extent * @param block an array of blocks to match */ - public BlockTypeMask(Extent extent, BlockType... block) { + public BlockTypeMask(Extent extent, @NotNull BlockType... block) { super(extent); this.types = new boolean[BlockTypes.size()]; for (BlockType type : block) this.types[type.getInternalId()] = true; } - protected BlockTypeMask(Extent extent, boolean[] types) { - super(extent); - this.types = types; - } - /** * Add the given blocks to the list of criteria. * * @param blocks a list of blocks */ - public void add(Collection blocks) { + public void add(@NotNull Collection blocks) { checkNotNull(blocks); for (BlockType type : blocks) { add(type); @@ -92,7 +86,7 @@ public final class BlockTypeMask extends AbstractExtentMask { * * @param block an array of blocks */ - public void add(BlockType... block) { + public void add(@NotNull BlockType... block) { for (BlockType type : block) { this.types[type.getInternalId()] = true; } @@ -120,4 +114,10 @@ public final class BlockTypeMask extends AbstractExtentMask { return types[block.getInternalId()]; } + @Nullable + @Override + public Mask2D toMask2D() { + return null; + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BoundedHeightMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BoundedHeightMask.java index e31567191..364cb4cfe 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BoundedHeightMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BoundedHeightMask.java @@ -20,7 +20,9 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkArgument; + import com.sk89q.worldedit.math.BlockVector3; +import javax.annotation.Nullable; /** * Has the criteria where the Y value of passed positions must be within @@ -48,4 +50,9 @@ public class BoundedHeightMask extends AbstractMask { return vector.getY() >= minY && vector.getY() <= maxY; } + @Nullable + @Override + public Mask2D toMask2D() { + return null; + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java index e8bef2c08..e2dd4eda3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java @@ -19,9 +19,9 @@ package com.sk89q.worldedit.function.mask; -import com.boydti.fawe.beta.FilterBlock; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; +import javax.annotation.Nullable; /** * A mask that returns true whenever the block at the location is not @@ -40,7 +40,13 @@ public class ExistingBlockMask extends AbstractExtentMask { @Override public boolean test(BlockVector3 vector) { - return !vector.getBlock(getExtent()).getMaterial().isAir(); + return !getExtent().getBlock(vector).getBlockType().getMaterial().isAir(); + } + + @Nullable + @Override + public Mask2D toMask2D() { + return null; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockTypeMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockTypeMask.java index 8c800a743..c52de0587 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockTypeMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockTypeMask.java @@ -1,10 +1,8 @@ package com.sk89q.worldedit.function.mask; -import com.boydti.fawe.beta.FilterBlock; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java index 1818e7181..c939208f4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java @@ -22,17 +22,12 @@ package com.sk89q.worldedit.function.mask; import com.boydti.fawe.beta.DelegateFilter; import com.boydti.fawe.beta.Filter; import com.boydti.fawe.beta.FilterBlock; -import com.sk89q.minecraft.util.commands.Link; -import com.sk89q.worldedit.command.UtilityCommands; -import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; - import javax.annotation.Nullable; /** * Tests whether a given vector meets a criteria. */ -@Link(clazz = UtilityCommands.class, value = "masks") public interface Mask { /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter.java index 854d9471d..6e1e247b9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter.java @@ -22,11 +22,9 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import com.boydti.fawe.beta.FilterBlock; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableVector3; import com.sk89q.worldedit.math.noise.NoiseGenerator; - import javax.annotation.Nullable; /** @@ -87,8 +85,8 @@ public class NoiseFilter extends AbstractMask { } @Override - public boolean test(BlockVector3 v) { - return noiseGenerator.noise(MutableVector3.get(v.getX(), v.getY(), v.getZ())) <= density; + public boolean test(BlockVector3 vector) { + return noiseGenerator.noise(MutableVector3.get(vector.getX(), vector.getY(), vector.getZ())) <= density; } @Nullable diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/RegionMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/RegionMask.java index c3305d597..45a1343eb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/RegionMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/RegionMask.java @@ -63,4 +63,9 @@ public class RegionMask extends AbstractMask { return region.contains(vector); } + @Nullable + @Override + public Mask2D toMask2D() { + return null; + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SolidBlockMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SolidBlockMask.java index 67b0ce75b..44c5f8e66 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SolidBlockMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SolidBlockMask.java @@ -21,6 +21,8 @@ package com.sk89q.worldedit.function.mask; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.block.BlockState; import javax.annotation.Nullable; public class SolidBlockMask extends BlockMask { @@ -29,6 +31,13 @@ public class SolidBlockMask extends BlockMask { add(state -> state.getMaterial().isMovementBlocker()); } + @Override + public boolean test(BlockVector3 vector) { + Extent extent = getExtent(); + BlockState block = extent.getBlock(vector); + return block.getBlockType().getMaterial().isMovementBlocker(); + } + @Nullable @Override public Mask2D toMask2D() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ChangeSetExecutor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ChangeSetExecutor.java index 4799f17fe..aecf1302a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ChangeSetExecutor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ChangeSetExecutor.java @@ -19,16 +19,14 @@ package com.sk89q.worldedit.function.operation; -import com.boydti.fawe.object.changeset.FaweChangeSet; - import static com.google.common.base.Preconditions.checkNotNull; +import com.boydti.fawe.object.changeset.FaweChangeSet; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.history.UndoContext; import com.sk89q.worldedit.history.change.Change; import com.sk89q.worldedit.history.changeset.ChangeSet; - import java.util.Iterator; import java.util.List; @@ -68,13 +66,12 @@ public class ChangeSetExecutor implements Operation { @Override public Operation resume(RunContext run) throws WorldEditException { + while (iterator.hasNext()) { + Change change = iterator.next(); if (type == Type.UNDO) { - while (iterator.hasNext()) { - iterator.next().undo(context); - } + change.undo(context); } else { - while (iterator.hasNext()) { - iterator.next().redo(context); + change.redo(context); } } return null; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java index b3c9ed10c..60f6e0430 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java @@ -22,7 +22,6 @@ package com.sk89q.worldedit.function.operation; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import com.boydti.fawe.beta.IQueueExtent; import com.boydti.fawe.object.extent.BlockTranslateExtent; import com.boydti.fawe.object.extent.PositionTransformExtent; import com.boydti.fawe.object.function.block.BiomeCopy; @@ -30,7 +29,6 @@ import com.boydti.fawe.object.function.block.CombinedBlockCopy; import com.boydti.fawe.object.function.block.SimpleBlockCopy; import com.boydti.fawe.util.MaskTraverser; import com.google.common.collect.Lists; -import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.metadata.EntityProperties; @@ -74,7 +72,7 @@ public class ForwardExtentCopy implements Operation { private int repetitions = 1; private Mask sourceMask = Masks.alwaysTrue(); private boolean removingEntities; - private boolean copyingEntities = true; // default to true for backwards compatibility, sort of // No, it's not for compatibility, it makes sense for entities to be copied and people will get annoyed if it doesn't + private boolean copyingEntities = true; // default to true for backwards compatibility, sort of private boolean copyingBiomes; private RegionFunction sourceFunction = null; private Transform transform = new Identity(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/FawePattern.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/FawePattern.java index f062bb075..e42234db1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/FawePattern.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/FawePattern.java @@ -1,18 +1,11 @@ package com.sk89q.worldedit.function.pattern; -import com.sk89q.minecraft.util.commands.Link; -import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.command.UtilityCommands; -import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; /** * Returns a {@link BlockStateHolder} for a given position. * - Adapts the vector apply to integer */ -@Link(clazz = UtilityCommands.class, value = "patterns") public interface FawePattern extends Pattern { // // @Deprecated diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/Pattern.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/Pattern.java index 9791bb8ce..98e6bd271 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/Pattern.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/Pattern.java @@ -21,9 +21,7 @@ package com.sk89q.worldedit.function.pattern; import com.boydti.fawe.beta.Filter; import com.boydti.fawe.beta.FilterBlock; -import com.sk89q.minecraft.util.commands.Link; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.command.UtilityCommands; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; @@ -32,7 +30,6 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; /** * Returns a {@link BlockStateHolder} for a given position. */ -@Link(clazz = UtilityCommands.class, value = "patterns") public interface Pattern extends Filter { /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/WaterloggedRemover.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/WaterloggedRemover.java index b321b8e65..6d9a787e5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/WaterloggedRemover.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/WaterloggedRemover.java @@ -20,19 +20,13 @@ package com.sk89q.worldedit.function.pattern; import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.function.mask.BlockMaskBuilder; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.PropertyKey; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; - import java.lang.ref.SoftReference; -import java.util.Map; -import java.util.function.BiPredicate; -import java.util.function.Predicate; /** * Removes the waterlogged state from blocks if possible. If not possible, returns air. @@ -42,9 +36,9 @@ public class WaterloggedRemover extends AbstractExtentPattern { private static SoftReference cache = new SoftReference<>(null); private synchronized BlockState[] getRemap() { - BlockState[] remap = this.cache.get(); + BlockState[] remap = cache.get(); if (remap != null) return remap; - this.cache = new SoftReference<>(remap = new BlockState[BlockTypes.states.length]); + cache = new SoftReference<>(remap = new BlockState[BlockTypes.states.length]); // init for (int i = 0; i < remap.length; i++) { @@ -76,4 +70,4 @@ public class WaterloggedRemover extends AbstractExtentPattern { } return BlockTypes.AIR.getDefaultState().toBaseBlock(); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java index 875417f0c..304e81e21 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java @@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.collection.BlockVectorSet; +import com.google.common.collect.Sets; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.operation.Operation; @@ -130,7 +131,7 @@ public abstract class BreadthFirstSearch implements Operation { * Add the directions along the axes as directions to visit. */ public void addAxes() { - HashSet set = new HashSet<>(Arrays.asList(directions)); + HashSet set = Sets.newHashSet(directions); set.add(BlockVector3.UNIT_MINUS_Y); set.add(BlockVector3.UNIT_Y); set.add(BlockVector3.UNIT_MINUS_X); @@ -144,7 +145,7 @@ public abstract class BreadthFirstSearch implements Operation { * Add the diagonal directions as directions to visit. */ public void addDiagonal() { - HashSet set = new HashSet<>(Arrays.asList(directions)); + HashSet set = Sets.newHashSet(directions); set.add(Direction.NORTHEAST.toBlockVector()); set.add(Direction.SOUTHEAST.toBlockVector()); set.add(Direction.SOUTHWEST.toBlockVector()); @@ -175,6 +176,22 @@ public abstract class BreadthFirstSearch implements Operation { } } + /** + * Try to visit the given 'to' location. + * + * @param from the origin block + * @param to the block under question + */ + private void visit(BlockVector3 from, BlockVector3 to) { + BlockVector3 blockVector = to; + if (!visited.contains(blockVector)) { + visited.add(blockVector); + if (isVisitable(from, to)) { + queue.add(blockVector); + } + } + } + public void setVisited(BlockVectorSet set) { this.visited = set; } @@ -213,11 +230,8 @@ public abstract class BreadthFirstSearch implements Operation { @Override public Operation resume(RunContext run) throws WorldEditException { MutableBlockVector3 mutable = new MutableBlockVector3(); -// MutableBlockVector3 mutable2 = new MutableBlockVector3(); - boolean shouldTrim = false; BlockVector3[] dirs = directions; BlockVectorSet tempQueue = new BlockVectorSet(); - BlockVectorSet chunkLoadSet = new BlockVectorSet(); for (currentDepth = 0; !queue.isEmpty() && currentDepth <= maxDepth; currentDepth++) { for (BlockVector3 from : queue) { if (function.apply(from)) affected++; @@ -244,9 +258,7 @@ public abstract class BreadthFirstSearch implements Operation { BlockVectorSet tmp = queue; queue = tempQueue; tmp.clear(); - chunkLoadSet.clear(); tempQueue = tmp; - } return null; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java index 0fac8e499..159601b79 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java @@ -70,17 +70,13 @@ public class RegionVisitor implements Operation { @Override public Operation resume(RunContext run) throws WorldEditException { for (BlockVector3 pt : iterable) { - apply(pt); + if (function.apply(pt)) { + affected++; + } } return null; } - private void apply(BlockVector3 pt) throws WorldEditException { - if (function.apply(pt)) { - affected++; - } - } - @Override public void cancel() { } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/BlockOptimizedHistory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/BlockOptimizedHistory.java index 9c9ad2a85..05ac90c78 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/BlockOptimizedHistory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/BlockOptimizedHistory.java @@ -55,7 +55,9 @@ public class BlockOptimizedHistory extends ArrayListHistory { if (change instanceof BlockChange) { BlockChange blockChange = (BlockChange) change; BlockVector3 position = blockChange.getPosition(); - previous.add(position, blockChange.getPrevious()); + if (!previous.containsLocation(position)) { + previous.add(position, blockChange.getPrevious()); + } current.add(position, blockChange.getCurrent()); } else { super.add(change); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java index f47fd7f60..3385bef50 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java @@ -19,9 +19,7 @@ package com.sk89q.worldedit.math; -import com.google.common.collect.ComparisonChain; import com.sk89q.worldedit.math.transform.AffineTransform; - import java.util.Comparator; /** @@ -48,25 +46,31 @@ public class BlockVector2 { * cdef * */ - public static final Comparator COMPARING_GRID_ARRANGEMENT = (a, b) -> { - return ComparisonChain.start() - .compare(a.getBlockZ(), b.getBlockZ()) - .compare(a.getBlockX(), b.getBlockX()) - .result(); - }; + public static final Comparator COMPARING_GRID_ARRANGEMENT = + Comparator.comparingInt(BlockVector2::getZ).thenComparingInt(BlockVector2::getX); public static BlockVector2 at(double x, double z) { return at((int) Math.floor(x), (int) Math.floor(z)); } public static BlockVector2 at(int x, int z) { + switch (x) { + case 0: + if (z == 0) { + return ZERO; + } + break; + case 1: + if (z == 1) { + return ONE; + } + break; + } return new BlockVector2(x, z); } protected int x, z; - protected BlockVector2(){} - /** * Construct an instance. * @@ -342,6 +346,26 @@ public class BlockVector2 { return divide(n, n); } + /** + * Shift all components right. + * + * @param x the value to shift x by + * @param z the value to shift z by + * @return a new vector + */ + public BlockVector2 shr(int x, int z) { + return at(this.x >> x, this.z >> z); + } + + /** + * Shift all components right by {@code n}. + * + * @param n the value to shift by + * @return a new vector + */ + public BlockVector2 shr(int n) { + return shr(n, n); + } /** * Get the length of the vector. * @@ -572,4 +596,4 @@ public class BlockVector2 { return "(" + x + ", " + z + ")"; } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java index f125d3672..d87eafb60 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java @@ -21,14 +21,12 @@ package com.sk89q.worldedit.math; import static com.google.common.base.Preconditions.checkArgument; -import com.google.common.collect.ComparisonChain; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; - import java.util.Comparator; /** @@ -50,11 +48,26 @@ public abstract class BlockVector3 { } public static BlockVector3 at(int x, int y, int z) { + // switch for efficiency on typical cases + // in MC y is rarely 0/1 on selections + switch (y) { + case 0: + if (x == 0 && z == 0) { + return ZERO; + } + break; + case 1: + if (x == 1 && z == 1) { + return ONE; + } + break; + } return new BlockVector3Imp(x, y, z); } // thread-safe initialization idiom private static final class YzxOrderComparator { + private static final Comparator YZX_ORDER = Comparator.comparingInt(BlockVector3::getY) .thenComparingInt(BlockVector3::getZ) @@ -240,8 +253,7 @@ public abstract class BlockVector3 { } /** - * Add a list of vectors to this vector and return the - * result as a new vector. + * Add a list of vectors to this vector and return the result as a new vector. * * @param others an array of vectors * @return a new vector @@ -259,8 +271,7 @@ public abstract class BlockVector3 { } /** - * Subtract another vector from this vector and return the result - * as a new vector. + * Subtract another vector from this vector and return the result as a new vector. * * @param other the other vector * @return a new vector @@ -270,8 +281,7 @@ public abstract class BlockVector3 { } /** - * Subtract another vector from this vector and return the result - * as a new vector. + * Subtract another vector from this vector and return the result as a new vector. * * @param x the value to subtract * @param y the value to subtract @@ -283,8 +293,7 @@ public abstract class BlockVector3 { } /** - * Subtract a list of vectors from this vector and return the result - * as a new vector. + * Subtract a list of vectors from this vector and return the result as a new vector. * * @param others an array of vectors * @return a new vector @@ -469,8 +478,7 @@ public abstract class BlockVector3 { } /** - * Get the normalized vector, which is the vector divided by its - * length, as a new vector. + * Get the normalized vector, which is the vector divided by its length, as a new vector. * * @return a new vector */ @@ -514,7 +522,8 @@ public abstract class BlockVector3 { * @return true if the vector is contained */ public boolean containedWithin(BlockVector3 min, BlockVector3 max) { - return getX() >= min.getX() && getX() <= max.getX() && getY() >= min.getY() && getY() <= max.getY() && getZ() >= min.getZ() && getZ() <= max.getZ(); + return getX() >= min.getX() && getX() <= max.getX() && getY() >= min.getY() && getY() <= max + .getY() && getZ() >= min.getZ() && getZ() <= max.getZ(); } /** @@ -568,8 +577,7 @@ public abstract class BlockVector3 { } /** - * Returns a vector with the absolute values of the components of - * this vector. + * Returns a vector with the absolute values of the components of this vector. * * @return a new vector */ @@ -580,15 +588,16 @@ public abstract class BlockVector3 { /** * Perform a 2D transformation on this vector and return a new one. * - * @param angle in degrees - * @param aboutX about which x coordinate to rotate - * @param aboutZ about which z coordinate to rotate + * @param angle in degrees + * @param aboutX about which x coordinate to rotate + * @param aboutZ about which z coordinate to rotate * @param translateX what to add after rotation * @param translateZ what to add after rotation * @return a new vector * @see AffineTransform another method to transform vectors */ - public BlockVector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) { + public BlockVector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, + double translateZ) { angle = Math.toRadians(angle); double x = this.getX() - aboutX; double z = this.getZ() - aboutZ; @@ -599,7 +608,7 @@ public abstract class BlockVector3 { return BlockVector3.at( x2 + aboutX + translateX, - getY(), + getY(), z2 + aboutZ + translateZ ); } @@ -646,9 +655,9 @@ public abstract class BlockVector3 { */ public BlockVector3 getMinimum(BlockVector3 v2) { return new BlockVector3Imp( - Math.min(getX(), v2.getX()), - Math.min(getY(), v2.getY()), - Math.min(getZ(), v2.getZ()) + Math.min(getX(), v2.getX()), + Math.min(getY(), v2.getY()), + Math.min(getZ(), v2.getZ()) ); } @@ -660,9 +669,9 @@ public abstract class BlockVector3 { */ public BlockVector3 getMaximum(BlockVector3 v2) { return new BlockVector3Imp( - Math.max(getX(), v2.getX()), - Math.max(getY(), v2.getY()), - Math.max(getZ(), v2.getZ()) + Math.max(getX(), v2.getX()), + Math.max(getY(), v2.getY()), + Math.max(getZ(), v2.getZ()) ); } @@ -685,7 +694,7 @@ public abstract class BlockVector3 { } public boolean setFullBlock(Extent orDefault, BaseBlock block) { - return orDefault.setBlock(this, block); + return orDefault.setBlock(this, block); } public boolean setBiome(Extent orDefault, BiomeType biome) { @@ -724,11 +733,6 @@ public abstract class BlockVector3 { return orDefault.getBlock(getX(), getY() + y, getZ()); } - - /* - Adapt - */ - /** * Creates a 2D vector by dropping the Y component from this vector. * @@ -743,7 +747,7 @@ public abstract class BlockVector3 { } @Override - public final boolean equals(Object obj) { + public boolean equals(Object obj) { if (!(obj instanceof BlockVector3)) { return false; } @@ -752,7 +756,8 @@ public abstract class BlockVector3 { } public final boolean equals(BlockVector3 other) { - return other.getX() == this.getX() && other.getY() == this.getY() && other.getZ() == this.getZ(); + return other.getX() == this.getX() && other.getY() == this.getY() && other.getZ() == this + .getZ(); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableVector2.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableVector2.java index 584eae658..b7bad8a35 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableVector2.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableVector2.java @@ -2,9 +2,6 @@ package com.sk89q.worldedit.math; public class MutableVector2 extends Vector2 { - public MutableVector2() { - } - /** * Construct an instance. * 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 215411e25..5ed311cfd 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 @@ -3,9 +3,12 @@ package com.sk89q.worldedit.math; import com.boydti.fawe.FaweCache; public class MutableVector3 extends Vector3 { - private double x,y,z; + + private double x, y, z; + public MutableVector3() { } + public static MutableVector3 get(int x, int y, int z) { return FaweCache.MUTABLE_VECTOR3.get().setComponents(x, y, z); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java index b7a76e4ef..8d5f61d23 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java @@ -33,13 +33,24 @@ public class Vector2 { public static final Vector2 ONE = new Vector2(1, 1); public static Vector2 at(double x, double z) { + int xTrunc = (int) x; + switch (xTrunc) { + case 0: + if (x == 0 && z == 0) { + return ZERO; + } + break; + case 1: + if (x == 1 && z == 1) { + return ONE; + } + break; + } return new Vector2(x, z); } protected double x, z; - protected Vector2(){} - /** * Construct an instance. * @@ -491,7 +502,7 @@ public class Vector2 { @Override public int hashCode() { - return ((int) x << 16) ^ ((int) z); + return (int) x << 16 ^ (int) z; } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java index 79d4dd9e3..ede6a549b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java @@ -39,6 +39,21 @@ public abstract class Vector3 { public static final Vector3 ONE = Vector3.at(1, 1, 1); public static Vector3 at(double x, double y, double z) { + // switch for efficiency on typical cases + // in MC y is rarely 0/1 on selections + int yTrunc = (int) y; + switch (yTrunc) { + case 0: + if (x == 0 && y == 0 && z == 0) { + return ZERO; + } + break; + case 1: + if (x == 1 && y == 1 && z == 1) { + return ONE; + } + break; + } return new Vector3Impl(x, y, 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 bf5c3151e..4aff22f49 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 @@ -36,6 +36,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; import java.util.Iterator; +import javax.annotation.Nullable; /** * Allows applications of Kernels onto the region's height map. @@ -63,11 +64,11 @@ public class HeightMap { this(session, region, (Mask) null, false); } - public HeightMap(EditSession session, Region region, Mask mask) { + public HeightMap(EditSession session, Region region, @Nullable Mask mask) { this(session, region, mask, false); } - public HeightMap(EditSession session, Region region, Mask mask, boolean layers) { + public HeightMap(EditSession session, Region region, @Nullable Mask mask, boolean layers) { checkNotNull(session); checkNotNull(region); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java index cab7688bb..534a772c1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java @@ -22,8 +22,6 @@ package com.sk89q.worldedit.math.transform; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MathUtils; import com.sk89q.worldedit.math.Vector3; - -import java.io.IOException; import java.io.Serializable; /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java index a58cb450f..381403e1b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java @@ -106,6 +106,20 @@ public abstract class AbstractRegion extends AbstractSet implement return points; } + /** + * Get the number of blocks in the region. + * + * @return number of blocks + */ + @Override + public int getArea() { + BlockVector3 min = getMinimumPoint(); + BlockVector3 max = getMaximumPoint(); + + return (max.getX() - min.getX() + 1) * + (max.getY() - min.getY() + 1) * + (max.getZ() - min.getZ() + 1); + } /** * Get X-size. * 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 dcb3a469e..4fe9d3033 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 @@ -392,6 +392,14 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { return chunks; } + @Override + public boolean contains(BlockVector3 position) { + BlockVector3 min = getMinimumPoint(); + BlockVector3 max = getMaximumPoint(); + + return position.containedWithin(min, max); + } + @Override public boolean contains(int x, int y, int z) { return x >= this.minX && x <= this.maxX && z >= this.minZ && z <= this.maxZ && y >= this.minY && y <= this.maxY; @@ -511,14 +519,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { if (++nextZ > max.getBlockZ()) { nextZ = min.getBlockZ(); if (++nextY > max.getBlockY()) { - if (!hasNext) { - throw new NoSuchElementException("End of iterator") { - @Override - public Throwable fillInStackTrace() { - return this; - } - }; - } + if (!hasNext()) throw new NoSuchElementException(); nextX = max.getBlockX(); nextZ = max.getBlockZ(); nextY = max.getBlockY(); @@ -546,12 +547,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { @Override public BlockVector2 next() { - if (!hasNext()) throw new NoSuchElementException() { - @Override - public synchronized Throwable fillInStackTrace() { - return this; - } - }; + if (!hasNext()) throw new NoSuchElementException(); BlockVector2 answer = BlockVector2.at(nextX, nextZ); if (++nextX > max.getBlockX()) { nextX = min.getBlockX(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java index ae33ef8c8..754aaf4d3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java @@ -293,6 +293,22 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { minY += changeY; } + /** + * Checks to see if a point is inside this region. + */ + @Override + public boolean contains(BlockVector3 position) { + final int blockY = position.getBlockY(); + if (blockY < minY || blockY > maxY) { + return false; + } + + return position.toBlockVector2().subtract(center).toVector2().divide(radius).lengthSq() <= 1; + } + + /** + * Checks to see if a point is inside this region. + */ @Override public boolean contains(int x, int y, int z) { if (y < minY || y > maxY) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java index 89f2c3522..1406b94e8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java @@ -24,17 +24,13 @@ import com.boydti.fawe.beta.Filter; import com.boydti.fawe.beta.IChunk; import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkSet; -import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.math.MutableBlockVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.world.World; - -import javax.annotation.Nullable; -import java.util.Iterator; import java.util.List; import java.util.Set; +import javax.annotation.Nullable; /** * Represents a physical shape. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java index bfad407c1..25b6040e9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java @@ -158,11 +158,11 @@ public interface RegionSelector { List getInformationLines(); /** - * Get the verticies + * Get the vertices * @return * @throws IncompleteRegionException */ - default List getVerticies() throws IncompleteRegionException { + default List getVertices() throws IncompleteRegionException { return Collections.singletonList(getPrimaryPosition()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/TransformRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/TransformRegion.java new file mode 100644 index 000000000..911e40b8b --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/TransformRegion.java @@ -0,0 +1,191 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.regions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; +import com.sk89q.worldedit.math.transform.Identity; +import com.sk89q.worldedit.math.transform.Transform; +import com.sk89q.worldedit.world.World; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.annotation.Nullable; + +/** + * Transforms another region according to a provided vector {@code Transform}. + * + * @see Transform + */ +public class TransformRegion extends AbstractRegion { + + private final Region region; + private Transform transform = new Identity(); + + /** + * Create a new instance. + * + * @param region the region + * @param transform the transform + */ + public TransformRegion(Region region, Transform transform) { + this(null, region, transform); + } + + /** + * Create a new instance. + * + * @param world the world, which may be null + * @param region the region + * @param transform the transform + */ + public TransformRegion(@Nullable World world, Region region, Transform transform) { + super(world); + checkNotNull(region); + checkNotNull(transform); + this.region = region; + this.transform = transform; + } + + /** + * Get the untransformed, base region. + * + * @return the base region + */ + public Region getRegion() { + return region; + } + + /** + * Get the transform that is applied. + * + * @return the transform + */ + public Transform getTransform() { + return transform; + } + + /** + * Set the transform that is applied. + * + * @param transform the transform + */ + public void setTransform(Transform transform) { + checkNotNull(transform); + this.transform = transform; + } + + @Override + public BlockVector3 getMinimumPoint() { + return transform.apply(region.getMinimumPoint().toVector3()).toBlockPoint(); + } + + @Override + public BlockVector3 getMaximumPoint() { + return transform.apply(region.getMaximumPoint().toVector3()).toBlockPoint(); + } + + @Override + public Vector3 getCenter() { + return transform.apply(region.getCenter()); + } + + @Override + public int getArea() { + return region.getArea(); // Cannot transform this + } + + @Override + public int getWidth() { + return getMaximumPoint().subtract(getMinimumPoint()).getBlockX() + 1; + } + + @Override + public int getHeight() { + return getMaximumPoint().subtract(getMinimumPoint()).getBlockY() + 1; + } + + @Override + public int getLength() { + return getMaximumPoint().subtract(getMinimumPoint()).getBlockZ() + 1; + } + + @Override + public void expand(BlockVector3... changes) throws RegionOperationException { + throw new RegionOperationException("Can't expand a TransformedRegion"); + } + + @Override + public void contract(BlockVector3... changes) throws RegionOperationException { + throw new RegionOperationException("Can't contract a TransformedRegion"); + } + + @Override + public void shift(BlockVector3 change) throws RegionOperationException { + throw new RegionOperationException("Can't change a TransformedRegion"); + } + + @Override + public boolean contains(BlockVector3 position) { + return region.contains(transform.inverse().apply(position.toVector3()).toBlockPoint()); + } + + @Override + public List polygonize(int maxPoints) { + List origPoints = region.polygonize(maxPoints); + List transformedPoints = new ArrayList<>(); + for (BlockVector2 vector : origPoints) { + transformedPoints.add(transform.apply(vector.toVector3(0)).toVector2().toBlockPoint()); + } + return transformedPoints; + } + + @Override + public Iterator iterator() { + final Iterator it = region.iterator(); + + return new Iterator() { + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public BlockVector3 next() { + BlockVector3 next = it.next(); + if (next != null) { + return transform.apply(next.toVector3()).toBlockPoint(); + } else { + return null; + } + } + + @Override + public void remove() { + it.remove(); + } + }; + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java index 439d7f3d4..bff61996f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java @@ -278,7 +278,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion } @Override - public List getVerticies() { + public List getVertices() { return new ArrayList<>(region.getVertices()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java index f03716e43..a706da033 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java @@ -302,7 +302,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { } @Override - public List getVerticies() { + public List getVertices() { return Arrays.asList(position1, position2); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/BooleanProperty.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/BooleanProperty.java index a707afa8e..2c72d6ee0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/BooleanProperty.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/BooleanProperty.java @@ -31,7 +31,7 @@ public class BooleanProperty extends AbstractProperty { this(name, values, 0); } - public BooleanProperty(final String name, final List values, int bitOffset) { + private BooleanProperty(final String name, final List values, int bitOffset) { super(name, values, bitOffset); defaultIndex = values.get(0).booleanValue() == Boolean.TRUE ? 0 : 1; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/DirectionalProperty.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/DirectionalProperty.java index 7d1676a0e..17f71604c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/DirectionalProperty.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/DirectionalProperty.java @@ -35,7 +35,7 @@ public class DirectionalProperty extends AbstractProperty { this(name, values, 0); } - public DirectionalProperty(final String name, final List values, int bitOffset) { + private DirectionalProperty(final String name, final List values, int bitOffset) { super(name, values, bitOffset); this.map = new int[Direction.values().length]; Arrays.fill(this.map, -1); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/EnumProperty.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/EnumProperty.java index be7b82ef3..ba95e10d0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/EnumProperty.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/EnumProperty.java @@ -19,12 +19,9 @@ package com.sk89q.worldedit.registry.state; -import com.sk89q.worldedit.util.Direction; - import java.util.HashMap; import java.util.List; import java.util.Map; - import javax.annotation.Nullable; public class EnumProperty extends AbstractProperty { @@ -35,7 +32,7 @@ public class EnumProperty extends AbstractProperty { this(name, values, 0); } - public EnumProperty(final String name, final List values, int bitOffset) { + private EnumProperty(final String name, final List values, int bitOffset) { super(name, values, bitOffset); for (int i = 0; i < values.size(); i++) { String value = values.get(i).intern(); @@ -51,7 +48,7 @@ public class EnumProperty extends AbstractProperty { @Override public int getIndexFor(CharSequence string) throws IllegalArgumentException { - Integer value = offsets.get(string); + Integer value = offsets.get(string.toString()); return value == null ? -1 : value; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/IntegerProperty.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/IntegerProperty.java index f8ce2a5b5..ad0095b00 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/IntegerProperty.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/IntegerProperty.java @@ -34,7 +34,7 @@ public class IntegerProperty extends AbstractProperty { this(name, values, 0); } - public IntegerProperty(final String name, final List values, int bitOffset) { + private IntegerProperty(final String name, final List values, int bitOffset) { super(name, values, bitOffset); int max = Collections.max(values); this.map = new int[max + 1]; @@ -67,9 +67,10 @@ public class IntegerProperty extends AbstractProperty { public Integer getValueFor(String string) { try { int val = Integer.parseInt(string); -// if (!getValues().contains(val)) { // This check is slow -// throw new IllegalArgumentException("Invalid int value: " + string + ". Must be in " + getValues().toString()); -// } + //It shouldn't matter if this check is slow. It's an important check + if (!getValues().contains(val)) { + throw new IllegalArgumentException("Invalid int value: " + string + ". Must be in " + getValues().toString()); + } return val; } catch (NumberFormatException e) { throw new IllegalArgumentException("Invalid int value: " + string + ". Not an int."); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/MinecraftHidingClassShutter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/MinecraftHidingClassShutter.java new file mode 100644 index 000000000..20324ed59 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/MinecraftHidingClassShutter.java @@ -0,0 +1,41 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.scripting; + +import org.mozilla.javascript.ClassShutter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Hides Minecraft's obfuscated & de-obfuscated names from scripts. + */ +class MinecraftHidingClassShutter implements ClassShutter { + + private static final Logger LOGGER = LoggerFactory.getLogger(MinecraftHidingClassShutter.class); + + @Override + public boolean visibleToScripts(String fullClassName) { + if (!fullClassName.contains(".")) { + // Default package -- probably Minecraft + return false; + } + return !fullClassName.startsWith("net.minecraft"); + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/PasteBuilder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/PasteBuilder.java index 0b08e7485..28cc64520 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/session/PasteBuilder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/PasteBuilder.java @@ -24,7 +24,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.boydti.fawe.util.MaskTraverser; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.transform.BlockTransformExtent; import com.sk89q.worldedit.function.RegionFunction; @@ -152,7 +151,7 @@ public class PasteBuilder { copy.setFilterFunction(this.canApply); } if (ignoreAirBlocks) { - sourceMask = MaskIntersection.of(sourceMask, new ExistingBlockMask(clipboard)); + sourceMask = new MaskIntersection(sourceMask, new ExistingBlockMask(clipboard)); } if (targetExtent instanceof EditSession) { Mask esSourceMask = ((EditSession) targetExtent).getSourceMask(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/SessionManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/SessionManager.java index 8347a6001..08ad67ff3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/session/SessionManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/SessionManager.java @@ -20,6 +20,7 @@ package com.sk89q.worldedit.session; import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; @@ -28,6 +29,8 @@ import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.command.tool.InvalidToolBindException; +import com.sk89q.worldedit.command.tool.NavigationWand; +import com.sk89q.worldedit.command.tool.SelectionWand; import com.sk89q.worldedit.command.tool.Tool; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.platform.ConfigurationLoadEvent; @@ -40,10 +43,6 @@ import com.sk89q.worldedit.util.eventbus.Subscribe; import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.annotation.Nullable; import java.io.File; import java.io.IOException; import java.util.HashMap; @@ -53,6 +52,9 @@ import java.util.Timer; import java.util.TimerTask; import java.util.UUID; import java.util.concurrent.Callable; +import javax.annotation.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Session manager for WorldEdit. @@ -162,6 +164,19 @@ public class SessionManager { session.setConfiguration(config); session.setBlockChangeLimit(config.defaultChangeLimit); session.setTimeout(config.calculationTimeout); + try { + if (owner.hasPermission("worldedit.selection.pos")) { + setDefaultWand(session.getWandItem(), config.wandItem, session, new SelectionWand()); + } + if (owner.hasPermission("worldedit.navigation.jumpto.tool") || owner.hasPermission("worldedit.navigation.thru.tool")) { + setDefaultWand(session.getNavWandItem(), config.navigationWand, session, new NavigationWand()); + } + } catch (InvalidToolBindException e) { + if (!warnedInvalidTool) { + warnedInvalidTool = true; + log.warn("Invalid wand tool set in config. Tool will not be assigned: " + e.getItemType()); + } + } // Remember the session regardless of if it's currently active or not. // And have the SessionTracker FLUSH inactive sessions. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/LocatedBlockList.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/LocatedBlockList.java index 67280031d..c1296e88d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/LocatedBlockList.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/LocatedBlockList.java @@ -23,66 +23,67 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.LocatedBlock; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; - import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; -import java.util.ListIterator; +import java.util.Map; +import javax.annotation.Nullable; /** * Wrapper around a list of blocks located in the world. */ public class LocatedBlockList implements Iterable { - private final List list; + private final Map map = new LinkedHashMap<>(); public LocatedBlockList() { - list = new ArrayList<>(); } public LocatedBlockList(Collection collection) { - list = new ArrayList<>(collection); + for (LocatedBlock locatedBlock : collection) { + map.put(locatedBlock.getLocation(), locatedBlock); + } } public void add(LocatedBlock setBlockCall) { checkNotNull(setBlockCall); - list.add(setBlockCall); + map.put(setBlockCall.getLocation(), setBlockCall); } public > void add(BlockVector3 location, B block) { add(new LocatedBlock(location, block.toBaseBlock())); } + public boolean containsLocation(BlockVector3 location) { + return map.containsKey(location); + } + + public @Nullable BaseBlock get(BlockVector3 location) { + return map.get(location).getBlock(); + } + public int size() { - return list.size(); + return map.size(); } public void clear() { - list.clear(); + map.clear(); } @Override public Iterator iterator() { - return list.iterator(); + return map.values().iterator(); } public Iterator reverseIterator() { - return new Iterator() { - - private final ListIterator backingIterator = list.listIterator(list.size()); - - @Override - public boolean hasNext() { - return backingIterator.hasPrevious(); - } - - @Override - public LocatedBlock next() { - return backingIterator.previous(); - } - }; + List data = new ArrayList<>(map.values()); + Collections.reverse(data); + return data.iterator(); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java index 53d66d7a6..a6e061d01 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java @@ -284,8 +284,4 @@ public interface World extends Extent { return true; } - @Override - default World getWorld() { - return this; - } }