From 8b96cdc9a50300abcdf6290cf5f6cf6740675204 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Fri, 20 Sep 2019 21:52:35 -0400 Subject: [PATCH] * A tribute to Jesse --- buildSrc/src/main/kotlin/CommonConfig.kt | 3 +- buildSrc/src/main/kotlin/LibsConfig.kt | 1 + config/checkstyle/import-control.xml | 1 + worldedit-bukkit/build.gradle.kts | 7 +- .../com/boydti/fawe/bukkit/FaweBukkit.java | 12 + .../mc1_14/DataConverters_1_14_R4.java | 21 +- .../bukkit/listener/CFIPacketListener.java | 6 +- .../regions/plotquared}/CFIRedirect.java | 2 +- .../regions/plotquared}/FaweChunkManager.java | 2 +- .../plotquared}/FaweLocalBlockQueue.java | 2 +- .../plotquared}/FaweSchematicHandler.java | 2 +- .../bukkit/regions/plotquared}/FaweTrim.java | 3 +- .../bukkit/regions/plotquared}/MoveTo512.java | 2 +- .../regions/plotquared}/PlotRegionFilter.java | 2 +- .../regions/plotquared}/PlotSetBiome.java | 52 ++- .../plotquared}/PlotSquaredFeature.java | 43 ++- .../regions/plotquared}/ReplaceAll.java | 0 .../sk89q/worldedit/bukkit/BukkitAdapter.java | 150 ++++++-- .../bukkit/BukkitBlockCommandSender.java | 2 +- .../bukkit/adapter/BukkitImplAdapter.java | 9 +- .../bukkit/adapter/IBukkitAdapter.java | 94 ----- worldedit-core/build.gradle.kts | 4 - .../src/main/java/com/boydti/fawe/Fawe.java | 2 - .../java/com/boydti/fawe/beta/IChunkSet.java | 1 + .../com/boydti/fawe/command/CFICommands.java | 98 ++--- .../boydti/fawe/object/brush/BlendBall.java | 17 +- .../boydti/fawe/object/brush/BlobBrush.java | 8 +- .../fawe/object/brush/BrushSettings.java | 11 +- .../fawe/object/brush/CatenaryBrush.java | 7 +- .../boydti/fawe/object/brush/ErodeBrush.java | 34 +- .../fawe/object/brush/InspectBrush.java | 2 +- .../boydti/fawe/object/brush/LayerBrush.java | 46 +-- .../boydti/fawe/object/brush/LineBrush.java | 5 +- .../boydti/fawe/object/brush/RaiseBrush.java | 4 +- .../fawe/object/brush/RecurseBrush.java | 9 +- .../object/brush/ScatterOverlayBrush.java | 3 +- .../boydti/fawe/object/brush/SpikeBrush.java | 15 - .../fawe/object/brush/SplatterBrush.java | 9 +- .../boydti/fawe/object/brush/SplineBrush.java | 2 - .../fawe/object/brush/SurfaceSpline.java | 17 +- .../object/changeset/DiskStorageHistory.java | 16 +- .../fawe/object/collection/MemBlockSet.java | 90 ++--- .../object/extent/ExtentHeightCacher.java | 3 +- .../fawe/object/extent/FaweRegionExtent.java | 13 +- .../fawe/object/extent/OffsetExtent.java | 4 +- .../fawe/object/extent/TransformExtent.java | 28 +- .../fawe/object/mask/AdjacentAnyMask2.java | 11 - .../fawe/object/number/MutableLong.java | 21 -- .../fawe/object/pattern/RelativePattern.java | 12 +- .../fawe/object/random/SimpleRandom.java | 5 +- .../boydti/fawe/object/random/TrueRandom.java | 9 +- .../boydti/fawe/object/regions/Triangle.java | 78 ++-- .../selector/PolyhedralRegionSelector.java | 15 +- .../com/boydti/fawe/regions/SimpleRegion.java | 48 --- .../fawe/regions/general/RegionFilter.java | 7 +- .../com/sk89q/worldedit/LocalSession.java | 41 +- .../worldedit/command/ApplyBrushCommands.java | 1 - .../worldedit/command/BrushCommands.java | 352 ++++++++++-------- .../worldedit/command/HistoryCommands.java | 69 ++-- .../command/argument/FactoryConverter.java | 3 + .../worldedit/command/tool/BlockReplacer.java | 7 +- .../worldedit/command/tool/BrushTool.java | 31 +- .../command/tool/NavigationWand.java | 70 ++-- .../worldedit/command/tool/QueryTool.java | 6 +- .../command/tool/RecursivePickaxe.java | 4 - .../worldedit/command/tool/SelectionWand.java | 3 +- .../worldedit/command/tool/TreePlanter.java | 4 +- .../tool/brush/HollowCylinderBrush.java | 1 - .../command/tool/brush/HollowSphereBrush.java | 1 - .../command/util/SuggestionHelper.java | 11 +- .../factory/parser/DefaultBlockParser.java | 119 +++--- .../parser/mask/BlockCategoryMaskParser.java | 1 - .../factory/parser/mask/BlocksMaskParser.java | 1 - .../sk89q/worldedit/extent/OutputExtent.java | 20 +- .../worldedit/extent/PassthroughExtent.java | 3 + .../extent/buffer/ForgetfulExtentBuffer.java | 76 +++- .../extent/clipboard/BlockArrayClipboard.java | 1 + .../transform/BlockTransformExtent.java | 36 +- .../function/CombinedRegionFunction.java | 8 +- .../worldedit/function/RegionFunction.java | 1 + .../function/biome/BiomeReplace.java | 19 +- .../function/block/BlockReplace.java | 2 +- .../worldedit/function/block/Naturalizer.java | 9 +- .../function/entity/ExtentEntityCopy.java | 8 +- .../function/generator/ForestGenerator.java | 2 +- .../worldedit/function/mask/BlockMask.java | 16 +- .../function/mask/BoundedHeightMask.java | 1 + .../function/mask/ExistingBlockMask.java | 2 +- .../sk89q/worldedit/function/mask/Mask.java | 11 - .../function/mask/MaskIntersection.java | 5 +- .../sk89q/worldedit/function/mask/Masks.java | 5 +- .../worldedit/function/mask/OffsetMask.java | 1 - .../worldedit/function/mask/RegionMask.java | 1 + .../function/operation/ChangeSetExecutor.java | 11 +- .../function/pattern/BiomePattern.java | 37 ++ .../function/pattern/BlockPattern.java | 1 + .../function/pattern/WaterloggedRemover.java | 8 +- .../function/visitor/BreadthFirstSearch.java | 9 +- .../function/visitor/FlatRegionVisitor.java | 1 + .../function/visitor/RegionVisitor.java | 12 +- .../command/CommandRegistrationHandler.java | 2 +- .../WorldEditExceptionConverter.java | 1 + .../internal/expression/Expression.java | 25 +- .../expression/runtime/ReturnException.java | 2 +- .../worldedit/internal/util/Substring.java | 8 +- .../sk89q/worldedit/math/BlockVector3.java | 75 ++-- .../KochanekBartelsInterpolation.java | 4 +- .../worldedit/regions/AbstractRegion.java | 1 + .../sk89q/worldedit/regions/CuboidRegion.java | 5 + .../worldedit/regions/CylinderRegion.java | 9 +- .../worldedit/regions/EllipsoidRegion.java | 7 +- .../com/sk89q/worldedit/regions/Region.java | 4 +- .../scripting/RhinoCraftScriptEngine.java | 1 + .../worldedit/session/ClipboardHolder.java | 8 +- .../worldedit/session/SessionManager.java | 7 +- .../session/request/RequestSelection.java | 1 - .../worldedit/util/paste/EngineHubPaste.java | 2 +- .../worldedit/world/block/BaseBlock.java | 23 +- .../world/block/BlockStateHolder.java | 12 +- .../worldedit/world/block/BlockType.java | 24 +- worldedit-libs/core/ap/build.gradle.kts | 4 +- 121 files changed, 1196 insertions(+), 1130 deletions(-) rename {worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot => worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared}/CFIRedirect.java (98%) rename {worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot => worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared}/FaweChunkManager.java (99%) rename {worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot => worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared}/FaweLocalBlockQueue.java (98%) rename {worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot => worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared}/FaweSchematicHandler.java (99%) rename {worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot => worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared}/FaweTrim.java (95%) rename {worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot => worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared}/MoveTo512.java (99%) rename {worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot => worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared}/PlotRegionFilter.java (95%) rename {worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot => worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared}/PlotSetBiome.java (72%) rename {worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot => worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared}/PlotSquaredFeature.java (82%) rename {worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot => worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared}/ReplaceAll.java (100%) delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/brush/SpikeBrush.java delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask2.java delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/number/MutableLong.java delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/regions/SimpleRegion.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/BiomePattern.java diff --git a/buildSrc/src/main/kotlin/CommonConfig.kt b/buildSrc/src/main/kotlin/CommonConfig.kt index 718b33213..b342b7992 100644 --- a/buildSrc/src/main/kotlin/CommonConfig.kt +++ b/buildSrc/src/main/kotlin/CommonConfig.kt @@ -21,7 +21,8 @@ fun Project.applyCommonConfiguration() { } configurations.all { resolutionStrategy { - cacheChangingModulesFor(5, "minutes") + cacheChangingModulesFor(10, "minutes") } } + } diff --git a/buildSrc/src/main/kotlin/LibsConfig.kt b/buildSrc/src/main/kotlin/LibsConfig.kt index 2ab16095b..b4897f677 100644 --- a/buildSrc/src/main/kotlin/LibsConfig.kt +++ b/buildSrc/src/main/kotlin/LibsConfig.kt @@ -33,6 +33,7 @@ fun Project.applyLibrariesConfiguration() { exclude(dependency("com.google.guava:guava")) exclude(dependency("com.google.code.gson:gson")) exclude(dependency("org.checkerframework:checker-qual")) + exclude(dependency("org.slf4j:slf4j-api")) } relocate("net.kyori.text", "com.sk89q.worldedit.util.formatting.text") diff --git a/config/checkstyle/import-control.xml b/config/checkstyle/import-control.xml index 1ef3e6098..dc8dace40 100644 --- a/config/checkstyle/import-control.xml +++ b/config/checkstyle/import-control.xml @@ -42,6 +42,7 @@ + diff --git a/worldedit-bukkit/build.gradle.kts b/worldedit-bukkit/build.gradle.kts index b94e9fc1b..4f2d23708 100644 --- a/worldedit-bukkit/build.gradle.kts +++ b/worldedit-bukkit/build.gradle.kts @@ -40,9 +40,7 @@ dependencies { "implementation"("io.papermc:paperlib:1.0.2") "compileOnly"("com.sk89q:dummypermscompat:1.10") "implementation"("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1") - "testCompile"("org.mockito:mockito-core:1.9.0-rc1") { - exclude("junit", "junit") - } + "testCompile"("org.mockito:mockito-core:1.9.0-rc1") "compileOnly"("com.sk89q.worldguard:worldguard-bukkit:7.0.0") { exclude("com.sk89q.worldedit", "worldedit-bukkit") exclude("com.sk89q.worldedit", "worldedit-core") @@ -61,6 +59,9 @@ dependencies { "implementation"("com.thevoxelbox.voxelsniper:voxelsniper:5.171.0") { isTransitive = false } "implementation"("com.comphenix.protocol:ProtocolLib-API:4.4.0-SNAPSHOT") { isTransitive = false } "implementation"("com.wasteofplastic:askyblock:3.0.8.2") { isTransitive = false } + "compileOnly"("com.github.intellectualsites.plotsquared:PlotSquared-API:latest") { + isTransitive = false + } } tasks.named("processResources") { 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 ee6d6d847..f0515ac6a 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 @@ -20,6 +20,7 @@ import com.boydti.fawe.bukkit.regions.ResidenceFeature; import com.boydti.fawe.bukkit.regions.TownyFeature; import com.boydti.fawe.bukkit.regions.Worldguard; import com.boydti.fawe.bukkit.regions.WorldguardFlag; +import com.boydti.fawe.bukkit.regions.plotquared.PlotSquaredFeature; import com.boydti.fawe.bukkit.util.BukkitTaskMan; import com.boydti.fawe.bukkit.util.ItemUtil; import com.boydti.fawe.bukkit.util.VaultUtil; @@ -29,6 +30,7 @@ import com.boydti.fawe.object.FaweCommand; import com.boydti.fawe.regions.FaweMaskManager; import com.boydti.fawe.util.Jars; import com.boydti.fawe.util.TaskManager; +import com.boydti.fawe.util.WEManager; import com.boydti.fawe.util.image.ImageViewer; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.world.World; @@ -84,6 +86,7 @@ public class FaweBukkit implements IFawe, Listener { if (PaperLib.isPaper() && Settings.IMP.EXPERIMENTAL.DYNAMIC_CHUNK_RENDERING > 1) { new RenderListener(plugin); } + WEManager.IMP.managers.add(new PlotSquaredFeature()); } catch (final Throwable e) { e.printStackTrace(); Bukkit.getServer().shutdown(); @@ -205,6 +208,15 @@ public class FaweBukkit implements IFawe, Listener { Player player = Bukkit.getPlayer(name); return player != null ? BukkitAdapter.adapt(player) : null; } + if (obj.getClass() == UUID.class) { + UUID uuid = (UUID) obj; + com.sk89q.worldedit.entity.Player existing = Fawe.get().getCachedPlayer(uuid); + if (existing != null) { + return existing; + } + Player player = Bukkit.getPlayer(uuid); + return player != null ? BukkitAdapter.adapt(player) : null; + } return null; } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/DataConverters_1_14_R4.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/DataConverters_1_14_R4.java index 01497bbba..0045ec18b 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/DataConverters_1_14_R4.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/DataConverters_1_14_R4.java @@ -1,3 +1,22 @@ +/* + * 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.boydti.fawe.bukkit.adapter.mc1_14; import com.google.common.collect.Lists; @@ -2708,4 +2727,4 @@ public class DataConverters_1_14_R4 extends DataFixerBuilder implements com.sk89 return cmp; } } -} \ No newline at end of file +} 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 ece1f4cd1..8574de6f4 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 @@ -21,7 +21,7 @@ import com.sk89q.worldedit.event.platform.BlockInteractEvent; import com.sk89q.worldedit.event.platform.Interaction; import com.sk89q.worldedit.extension.platform.PlatformManager; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BlockStateHolder; +import com.sk89q.worldedit.world.block.BlockState; import java.lang.reflect.InvocationTargetException; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -239,14 +239,14 @@ public class CFIPacketListener implements Listener { platform.handleBlockInteract(toCall); if (toCall.isCancelled() || action == Interaction.OPEN) { BlockVector3 realPos = pt.add(gen.getOrigin().toBlockPoint()); - BlockStateHolder block = gen.getBlock(pt); + BlockState block = gen.getBlock(pt); sendBlockChange(plr, realPos, block); return true; } return false; } - private void sendBlockChange(Player plr, BlockVector3 pt, BlockStateHolder block) { + private void sendBlockChange(Player plr, BlockVector3 pt, BlockState block) { plr.sendBlockChange(new Location(plr.getWorld(), pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()), BukkitAdapter.adapt(block)); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/CFIRedirect.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/CFIRedirect.java similarity index 98% rename from worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/CFIRedirect.java rename to worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/CFIRedirect.java index d4ea6a302..ec7645158 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/CFIRedirect.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/CFIRedirect.java @@ -1,4 +1,4 @@ -package com.boydti.fawe.regions.general.plot; +package com.boydti.fawe.bukkit.regions.plotquared; import com.github.intellectualsites.plotsquared.commands.Command; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/FaweChunkManager.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/FaweChunkManager.java similarity index 99% rename from worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/FaweChunkManager.java rename to worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/FaweChunkManager.java index 91717c269..f51d370a9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/FaweChunkManager.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/FaweChunkManager.java @@ -1,4 +1,4 @@ -package com.boydti.fawe.regions.general.plot; +package com.boydti.fawe.bukkit.regions.plotquared; import com.boydti.fawe.util.EditSessionBuilder; import com.boydti.fawe.util.TaskManager; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/FaweLocalBlockQueue.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/FaweLocalBlockQueue.java similarity index 98% rename from worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/FaweLocalBlockQueue.java rename to worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/FaweLocalBlockQueue.java index 60b97c662..3ac1e6c63 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/FaweLocalBlockQueue.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/FaweLocalBlockQueue.java @@ -1,4 +1,4 @@ -package com.boydti.fawe.regions.general.plot; +package com.boydti.fawe.bukkit.regions.plotquared; import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweAPI; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/FaweSchematicHandler.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/FaweSchematicHandler.java similarity index 99% rename from worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/FaweSchematicHandler.java rename to worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/FaweSchematicHandler.java index 5fff70a1e..e48e36977 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/FaweSchematicHandler.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/FaweSchematicHandler.java @@ -1,4 +1,4 @@ -package com.boydti.fawe.regions.general.plot; +package com.boydti.fawe.bukkit.regions.plotquared; import com.boydti.fawe.FaweCache; import com.boydti.fawe.object.clipboard.ReadOnlyClipboard; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/FaweTrim.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/FaweTrim.java similarity index 95% rename from worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/FaweTrim.java rename to worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/FaweTrim.java index 6f7a3ce37..7302697eb 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/FaweTrim.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/FaweTrim.java @@ -1,4 +1,4 @@ -package com.boydti.fawe.regions.general.plot; +package com.boydti.fawe.bukkit.regions.plotquared; import com.boydti.fawe.util.TaskManager; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; @@ -6,7 +6,6 @@ import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory; import com.github.intellectualsites.plotsquared.plot.commands.RequiredType; import com.github.intellectualsites.plotsquared.plot.commands.SubCommand; import com.github.intellectualsites.plotsquared.plot.config.Captions; -import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/MoveTo512.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/MoveTo512.java similarity index 99% rename from worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/MoveTo512.java rename to worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/MoveTo512.java index 41c211d1f..bd2349adc 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/MoveTo512.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/MoveTo512.java @@ -1,4 +1,4 @@ -package com.boydti.fawe.regions.general.plot; +package com.boydti.fawe.bukkit.regions.plotquared; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/PlotRegionFilter.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/PlotRegionFilter.java similarity index 95% rename from worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/PlotRegionFilter.java rename to worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/PlotRegionFilter.java index d69ce516f..47bc3908d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/PlotRegionFilter.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/PlotRegionFilter.java @@ -1,4 +1,4 @@ -package com.boydti.fawe.regions.general.plot; +package com.boydti.fawe.bukkit.regions.plotquared; import static com.google.common.base.Preconditions.checkNotNull; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/PlotSetBiome.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/PlotSetBiome.java similarity index 72% rename from worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/PlotSetBiome.java rename to worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/PlotSetBiome.java index 08a1e0183..1813368be 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/PlotSetBiome.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/PlotSetBiome.java @@ -1,4 +1,4 @@ -package com.boydti.fawe.regions.general.plot; +package com.boydti.fawe.bukkit.regions.plotquared; import com.boydti.fawe.Fawe; import com.boydti.fawe.util.EditSessionBuilder; @@ -20,6 +20,7 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; @@ -31,6 +32,7 @@ import java.util.Collection; import java.util.HashSet; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadLocalRandom; +import org.bukkit.Bukkit; @CommandDeclaration( command = "generatebiome", @@ -65,34 +67,28 @@ public class PlotSetBiome extends Command { MainUtil.sendMessage(player, Captions.SUBCOMMAND_SET_OPTIONS_HEADER.toString() + biomes); return CompletableFuture.completedFuture(false); } - confirm.run(this, new Runnable() { - @Override - public void run() { - if (plot.getRunning() != 0) { - Captions.WAIT_FOR_TIMER.send(player); - return; - } - plot.addRunning(); - TaskManager.IMP.async(new Runnable() { - @Override - public void run() { - EditSession session = new EditSessionBuilder(plot.getArea().worldname) - .autoQueue(false) - .checkMemory(false) - .allowedRegionsEverywhere() - .player(Fawe.imp().wrap(player.getName())) - .limitUnlimited() - .build(); - long seed = ThreadLocalRandom.current().nextLong(); - for (RegionWrapper region : regions) { - CuboidRegion cuboid = new CuboidRegion(BlockVector3.at(region.minX, 0, region.minZ), BlockVector3.at(region.maxX, 256, region.maxZ)); - session.regenerate(cuboid, biome, seed); - } - session.flushQueue(); - plot.removeRunning(); - } - }); + confirm.run(this, () -> { + if (plot.getRunning() != 0) { + Captions.WAIT_FOR_TIMER.send(player); + return; } + plot.addRunning(); + TaskManager.IMP.async(() -> { + EditSession session = new EditSessionBuilder(BukkitAdapter.adapt(Bukkit.getWorld(plot.getArea().worldname))) + .autoQueue(false) + .checkMemory(false) + .allowedRegionsEverywhere() + .player(Fawe.imp().wrap(player.getUUID())) + .limitUnlimited() + .build(); + long seed = ThreadLocalRandom.current().nextLong(); + for (RegionWrapper region : regions) { + CuboidRegion cuboid = new CuboidRegion(BlockVector3.at(region.minX, 0, region.minZ), BlockVector3.at(region.maxX, 256, region.maxZ)); + session.regenerate(cuboid, biome, seed); + } + session.flushQueue(); + plot.removeRunning(); + }); }, null); return CompletableFuture.completedFuture(true); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/PlotSquaredFeature.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/PlotSquaredFeature.java similarity index 82% rename from worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/PlotSquaredFeature.java rename to worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/PlotSquaredFeature.java index 772a67f9f..dcab75585 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/PlotSquaredFeature.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/PlotSquaredFeature.java @@ -1,10 +1,8 @@ -package com.boydti.fawe.regions.general.plot; +package com.boydti.fawe.bukkit.regions.plotquared; import com.boydti.fawe.Fawe; -import com.boydti.fawe.FaweAPI; import com.boydti.fawe.regions.FaweMask; import com.boydti.fawe.regions.FaweMaskManager; -import com.boydti.fawe.regions.SimpleRegion; import com.boydti.fawe.regions.general.RegionFilter; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.commands.MainCommand; @@ -22,12 +20,16 @@ import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.AbstractRegion; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.regions.RegionOperationException; import java.util.HashSet; import java.util.UUID; +import org.bukkit.Bukkit; public class PlotSquaredFeature extends FaweMaskManager { public PlotSquaredFeature() { @@ -89,7 +91,7 @@ public class PlotSquaredFeature extends FaweMaskManager { } } - public boolean isAllowed(com.sk89q.worldedit.entity.Player player, Plot plot, MaskType type) { + public boolean isAllowed(Player player, Plot plot, MaskType type) { if (plot == null) { return false; } @@ -114,14 +116,14 @@ public class PlotSquaredFeature extends FaweMaskManager { } } } - if (regions.size() == 0) { + if (regions.isEmpty()) { return null; } PlotArea area = pp.getApplicablePlotArea(); int min = area != null ? area.MIN_BUILD_HEIGHT : 0; int max = area != null ? Math.min(255, area.MAX_BUILD_HEIGHT) : 255; final HashSet faweRegions = new HashSet<>(); - for (final RegionWrapper current : regions) { + for (RegionWrapper current : regions) { faweRegions.add(new com.boydti.fawe.object.RegionWrapper(current.minX, current.maxX, min, max, current.minZ, current.maxZ)); } final RegionWrapper region = regions.iterator().next(); @@ -136,7 +138,27 @@ public class PlotSquaredFeature extends FaweMaskManager { if (regions.size() == 1) { maskedRegion = new CuboidRegion(pos1, pos2); } else { - maskedRegion = new SimpleRegion(FaweAPI.getWorld(area.worldname), pos1, pos2) { + maskedRegion = new AbstractRegion(BukkitAdapter.adapt(Bukkit.getWorld(area.worldname))) { + @Override + public BlockVector3 getMinimumPoint() { + return pos1; + } + + @Override + public BlockVector3 getMaximumPoint() { + return pos2; + } + + @Override + public void expand(BlockVector3... changes) throws RegionOperationException { + throw new UnsupportedOperationException("Region is immutable"); + } + + @Override + public void contract(BlockVector3... changes) throws RegionOperationException { + throw new UnsupportedOperationException("Region is immutable"); + } + @Override public boolean contains(int x, int y, int z) { return WEManager.maskContains(regions, x, y, z); @@ -146,12 +168,17 @@ public class PlotSquaredFeature extends FaweMaskManager { public boolean contains(int x, int z) { return WEManager.maskContains(regions, x, z); } + + @Override + public boolean contains(BlockVector3 position) { + return contains(position.getBlockX(), position.getBlockY(), position.getBlockZ()); + } }; } return new FaweMask(maskedRegion) { @Override - public boolean isValid(com.sk89q.worldedit.entity.Player player, MaskType type) { + public boolean isValid(Player player, MaskType type) { if (Settings.Done.RESTRICT_BUILDING && Flags.DONE.isSet(finalPlot)) { return false; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/ReplaceAll.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/ReplaceAll.java similarity index 100% rename from worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/ReplaceAll.java rename to worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotquared/ReplaceAll.java diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java index ec1d484f9..e462f8409 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java @@ -34,12 +34,22 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; +import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.entity.EntityType; +import com.sk89q.worldedit.world.entity.EntityTypes; import com.sk89q.worldedit.world.gamemode.GameMode; +import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.item.ItemType; +import com.sk89q.worldedit.world.item.ItemTypes; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.Objects; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; @@ -82,7 +92,7 @@ public enum BukkitAdapter { * @return If they are equal */ public static boolean equals(BlockType blockType, Material type) { - return getAdapter().equals(blockType, type); + return Objects.equals(blockType.getId(), type.getKey().toString()); } /** @@ -95,7 +105,15 @@ public enum BukkitAdapter { * @return a wrapped Bukkit world */ public static BukkitWorld asBukkitWorld(World world) { - return getAdapter().asBukkitWorld(world); + if (world instanceof BukkitWorld) { + return (BukkitWorld) world; + } else { + BukkitWorld bukkitWorld = WorldEditPlugin.getInstance().getInternalPlatform().matchWorld(world); + if (bukkitWorld == null) { + throw new RuntimeException("World '" + world.getName() + "' has no matching version in Bukkit"); + } + return bukkitWorld; + } } /** @@ -105,11 +123,8 @@ public enum BukkitAdapter { * @return a WorldEdit world */ public static World adapt(org.bukkit.World world) { - return getAdapter().adapt(world); - } - - public static org.bukkit.World adapt(World world) { - return getAdapter().adapt(world); + checkNotNull(world); + return new BukkitWorld(world); } /** @@ -119,7 +134,7 @@ public enum BukkitAdapter { * @return The WorldEdit player */ public static BukkitPlayer adapt(Player player) { - return getAdapter().adapt(player); + return WorldEditPlugin.getInstance().wrapPlayer(player); } /** @@ -129,7 +144,27 @@ public enum BukkitAdapter { * @return The Bukkit player */ public static Player adapt(com.sk89q.worldedit.entity.Player player) { - return getAdapter().adapt(player); + return ((BukkitPlayer) player).getPlayer(); + } + + /** + * Create a Bukkit world from a WorldEdit world. + * + * @param world the WorldEdit world + * @return a Bukkit world + */ + public static org.bukkit.World adapt(World world) { + checkNotNull(world); + if (world instanceof BukkitWorld) { + return ((BukkitWorld) world).getWorld(); + } else { + org.bukkit.World match = Bukkit.getServer().getWorld(world.getName()); + if (match != null) { + return match; + } else { + throw new IllegalArgumentException("Can't find a Bukkit world for " + world.getName()); + } + } } /** @@ -140,7 +175,12 @@ public enum BukkitAdapter { */ public static Location adapt(org.bukkit.Location location) { checkNotNull(location); - return getAdapter().adapt(location); + Vector3 position = asVector(location); + return new com.sk89q.worldedit.util.Location( + adapt(location.getWorld()), + position, + location.getYaw(), + location.getPitch()); } /** @@ -151,7 +191,12 @@ public enum BukkitAdapter { */ public static org.bukkit.Location adapt(Location location) { checkNotNull(location); - return getAdapter().adapt(location); + Vector3 position = location; + return new org.bukkit.Location( + adapt((World) location.getExtent()), + position.getX(), position.getY(), position.getZ(), + location.getYaw(), + location.getPitch()); } /** @@ -162,7 +207,11 @@ public enum BukkitAdapter { * @return a Bukkit location */ public static org.bukkit.Location adapt(org.bukkit.World world, Vector3 position) { - return getAdapter().adapt(world, position); + checkNotNull(world); + checkNotNull(position); + return new org.bukkit.Location( + world, + position.getX(), position.getY(), position.getZ()); } /** @@ -175,7 +224,9 @@ public enum BukkitAdapter { public static org.bukkit.Location adapt(org.bukkit.World world, BlockVector3 position) { checkNotNull(world); checkNotNull(position); - return getAdapter().adapt(world, position); + return new org.bukkit.Location( + world, + position.getX(), position.getY(), position.getZ()); } /** @@ -188,7 +239,11 @@ public enum BukkitAdapter { public static org.bukkit.Location adapt(org.bukkit.World world, Location location) { checkNotNull(world); checkNotNull(location); - return getAdapter().adapt(world, location); + return new org.bukkit.Location( + world, + location.getX(), location.getY(), location.getZ(), + location.getYaw(), + location.getPitch()); } /** @@ -221,7 +276,7 @@ public enum BukkitAdapter { */ public static Entity adapt(org.bukkit.entity.Entity entity) { checkNotNull(entity); - return getAdapter().adapt(entity); + return new BukkitEntity(entity); } /** @@ -232,7 +287,10 @@ public enum BukkitAdapter { */ public static Material adapt(ItemType itemType) { checkNotNull(itemType); - return getAdapter().adapt(itemType); + if (!itemType.getId().startsWith("minecraft:")) { + throw new IllegalArgumentException("Bukkit only supports Minecraft items"); + } + return Material.getMaterial(itemType.getId().substring(10).toUpperCase(Locale.ROOT)); } /** @@ -241,8 +299,12 @@ public enum BukkitAdapter { * @param blockType The WorldEdit BlockType * @return The Bukkit Material */ - public static Material adapt(@NotNull BlockType blockType) { - return getAdapter().adapt(blockType); + public static Material adapt(BlockType blockType) { + checkNotNull(blockType); + if (!blockType.getId().startsWith("minecraft:")) { + throw new IllegalArgumentException("Bukkit only supports Minecraft blocks"); + } + return Material.getMaterial(blockType.getId().substring(10).toUpperCase(Locale.ROOT)); } /** @@ -253,7 +315,7 @@ public enum BukkitAdapter { */ public static GameMode adapt(org.bukkit.GameMode gameMode) { checkNotNull(gameMode); - return getAdapter().adapt(gameMode); + return GameModes.get(gameMode.name().toLowerCase(Locale.ROOT)); } /** @@ -263,11 +325,18 @@ public enum BukkitAdapter { * @return WorldEdit BiomeType */ public static BiomeType adapt(Biome biome) { - return getAdapter().adapt(biome); + return BiomeTypes.get(biome.name().toLowerCase(Locale.ROOT)); } public static Biome adapt(BiomeType biomeType) { - return getAdapter().adapt(biomeType); + if (!biomeType.getId().startsWith("minecraft:")) { + throw new IllegalArgumentException("Bukkit only supports vanilla biomes"); + } + try { + return Biome.valueOf(biomeType.getId().substring(10).toUpperCase(Locale.ROOT)); + } catch (IllegalArgumentException e) { + return null; + } } /** @@ -277,11 +346,18 @@ public enum BukkitAdapter { * @return WorldEdit EntityType */ public static EntityType adapt(org.bukkit.entity.EntityType entityType) { - return getAdapter().adapt(entityType); + final String name = entityType.getName(); + if (name == null) { + return null; + } + return EntityTypes.get(name.toLowerCase(Locale.ROOT)); } public static org.bukkit.entity.EntityType adapt(EntityType entityType) { - return getAdapter().adapt(entityType); + if (!entityType.getId().startsWith("minecraft:")) { + throw new IllegalArgumentException("Bukkit only supports vanilla entities"); + } + return org.bukkit.entity.EntityType.fromName(entityType.getId().substring(10)); } /** @@ -290,8 +366,12 @@ public enum BukkitAdapter { * @param material The material * @return The blocktype */ - public static BlockType asBlockType(@NotNull Material material) { - return getAdapter().asBlockType(material); + public static BlockType asBlockType(Material material) { + checkNotNull(material); + if (!material.isBlock()) { + throw new IllegalArgumentException(material.getKey().toString() + " is not a block!"); + } + return BlockTypes.get(material.getKey().toString()); } /** @@ -302,9 +382,13 @@ public enum BukkitAdapter { */ public static ItemType asItemType(Material material) { checkNotNull(material); - return getAdapter().asItemType(material); + if (!material.isItem()) { + throw new IllegalArgumentException(material.getKey().toString() + " is not an item!"); + } + return ItemTypes.get(material.getKey().toString()); } + private static Map blockStateCache = new HashMap<>(); /** * Create a WorldEdit BlockState from a Bukkit BlockData @@ -320,6 +404,8 @@ public enum BukkitAdapter { return getAdapter().adapt(material); } + private static Map blockDataCache = new HashMap<>(); + /** * Create a Bukkit BlockData from a WorldEdit BlockStateHolder * @@ -339,7 +425,7 @@ public enum BukkitAdapter { public static BlockState asBlockState(ItemStack itemStack) throws WorldEditException { checkNotNull(itemStack); if (itemStack.getType().isBlock()) { - return getAdapter().asBlockState(itemStack); + return adapt(itemStack.getType().createBlockData()); } else { throw new NotABlockException(); } @@ -353,7 +439,10 @@ public enum BukkitAdapter { */ public static BaseItemStack adapt(ItemStack itemStack) { checkNotNull(itemStack); - return getAdapter().adapt(itemStack); + if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) { + return WorldEditPlugin.getInstance().getBukkitImplAdapter().adapt(itemStack); + } + return new BaseItemStack(ItemTypes.get(itemStack.getType().getKey().toString()), itemStack.getAmount()); } /** @@ -364,6 +453,9 @@ public enum BukkitAdapter { */ public static ItemStack adapt(BaseItemStack item) { checkNotNull(item); - return getAdapter().adapt(item); + if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) { + return WorldEditPlugin.getInstance().getBukkitImplAdapter().adapt(item); + } + return new ItemStack(adapt(item.getType()), item.getAmount()); } } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java index 465948668..44f31fdef 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java @@ -164,7 +164,7 @@ public class BukkitBlockCommandSender extends AbstractNonPlayerActor implements @Override public boolean isPersistent() { - return true; + return false; } @Override diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java index 177f45563..26423c18b 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java @@ -35,8 +35,9 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.registry.BlockMaterial; - +import java.util.Map; import java.util.OptionalInt; +import javax.annotation.Nullable; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; @@ -45,11 +46,6 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import java.util.Map; -import java.util.OptionalInt; - -import javax.annotation.Nullable; - /** * An interface for adapters of various Bukkit implementations. */ @@ -202,7 +198,6 @@ public interface BukkitImplAdapter extends IBukkitAdapter { * @param state The block state * @return the internal ID of the state */ - default OptionalInt getInternalBlockStateId(BlockState state) { return OptionalInt.empty(); } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IBukkitAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IBukkitAdapter.java index bf630d76f..5edd1a1ce 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IBukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IBukkitAdapter.java @@ -2,7 +2,6 @@ package com.sk89q.worldedit.bukkit.adapter; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.NotABlockException; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.bukkit.BukkitEntity; import com.sk89q.worldedit.bukkit.BukkitItemStack; @@ -21,9 +20,6 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.entity.EntityType; -import com.sk89q.worldedit.world.entity.EntityTypes; -import com.sk89q.worldedit.world.gamemode.GameMode; -import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.item.ItemType; import java.util.Locale; import org.bukkit.Bukkit; @@ -35,17 +31,6 @@ import org.bukkit.inventory.ItemStack; public interface IBukkitAdapter { - /** - * Checks equality between a WorldEdit BlockType and a Bukkit Material - * - * @param blockType The WorldEdit BlockType - * @param type The Bukkit Material - * @return If they are equal - */ - default boolean equals(BlockType blockType, Material type) { - return blockType == asItemType(type).getBlockType(); - } - /** * Convert any WorldEdit world into an equivalent wrapped Bukkit world. * @@ -67,17 +52,6 @@ public interface IBukkitAdapter { } } - /** - * Create a WorldEdit world from a Bukkit world. - * - * @param world the Bukkit world - * @return a WorldEdit world - */ - default World adapt(org.bukkit.World world) { - checkNotNull(world); - return new BukkitWorld(world); - } - /** * Create a Bukkit world from a WorldEdit world. * @@ -98,38 +72,6 @@ public interface IBukkitAdapter { } } - /** - * Create a WorldEdit location from a Bukkit location. - * - * @param location the Bukkit location - * @return a WorldEdit location - */ - default Location adapt(org.bukkit.Location location) { - checkNotNull(location); - Vector3 position = asVector(location); - return new Location( - adapt(location.getWorld()), - position, - location.getYaw(), - location.getPitch()); - } - - /** - * Create a Bukkit location from a WorldEdit location. - * - * @param location the WorldEdit location - * @return a Bukkit location - */ - default org.bukkit.Location adapt(Location location) { - checkNotNull(location); - Vector3 position = location; - return new org.bukkit.Location( - adapt((World) location.getExtent()), - position.getX(), position.getY(), position.getZ(), - location.getYaw(), - location.getPitch()); - } - /** * Create a Bukkit location from a WorldEdit position with a Bukkit world. * @@ -228,27 +170,6 @@ public interface IBukkitAdapter { return Material.getMaterial(id); } - /** - * Create a WorldEdit GameMode from a Bukkit one. - * - * @param gameMode Bukkit GameMode - * @return WorldEdit GameMode - */ - default GameMode adapt(org.bukkit.GameMode gameMode) { - checkNotNull(gameMode); - return GameModes.get(gameMode.name().toLowerCase(Locale.ROOT)); - } - - /** - * Create a WorldEdit EntityType from a Bukkit one. - * - * @param entityType Bukkit EntityType - * @return WorldEdit EntityType - */ - default EntityType adapt(org.bukkit.entity.EntityType entityType) { - return EntityTypes.get(entityType.getName().toLowerCase(Locale.ROOT)); - } - default org.bukkit.entity.EntityType adapt(EntityType entityType) { if (!entityType.getId().startsWith("minecraft:")) { throw new IllegalArgumentException("Bukkit only supports vanilla entities"); @@ -303,21 +224,6 @@ public interface IBukkitAdapter { */ BlockData adapt(BlockStateHolder block); - /** - * Create a WorldEdit BlockStateHolder from a Bukkit ItemStack - * - * @param itemStack The Bukkit ItemStack - * @return The WorldEdit BlockState - */ - default BlockState asBlockState(ItemStack itemStack) { - checkNotNull(itemStack); - if (itemStack.getType().isBlock()) { - return adapt(itemStack.getType().createBlockData()); - } else { - throw new NotABlockException(); - } - } - /** * Create a WorldEdit BaseItemStack from a Bukkit ItemStack * diff --git a/worldedit-core/build.gradle.kts b/worldedit-core/build.gradle.kts index 2363ab57f..86537bd11 100644 --- a/worldedit-core/build.gradle.kts +++ b/worldedit-core/build.gradle.kts @@ -33,10 +33,6 @@ dependencies { "annotationProcessor"("com.google.auto.value:auto-value:${Versions.AUTO_VALUE}") "compile"("co.aikar:fastutil-lite:1.0") "compile"("com.github.luben:zstd-jni:1.4.3-1") - //"compile"("com.mojang:datafixerupper:1.0.20") - "compileOnly"("com.github.intellectualsites.plotsquared:PlotSquared-API:latest") { - isTransitive = false - } "compileOnly"("net.fabiozumbi12:redprotect:1.9.6") } 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 7d9993d35..48485a7d0 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java @@ -4,7 +4,6 @@ import com.boydti.fawe.beta.implementation.QueueHandler; import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.brush.visualization.VisualQueue; -import com.boydti.fawe.regions.general.plot.PlotSquaredFeature; import com.boydti.fawe.util.CachedTextureUtil; import com.boydti.fawe.util.CleanTextureUtil; import com.boydti.fawe.util.FaweTimer; @@ -186,7 +185,6 @@ public class Fawe { transformParser = new DefaultTransformParser(getWorldEdit()); visualQueue = new VisualQueue(3); WEManager.IMP.managers.addAll(Fawe.this.IMP.getMaskManagers()); - WEManager.IMP.managers.add(new PlotSquaredFeature()); Fawe.debug("Plugin 'PlotSquared' found. Using it now."); } catch (Throwable ignored) {} try { 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 2f48cae49..e0c45f84c 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 @@ -24,6 +24,7 @@ public interface IChunkSet extends IBlocks, OutputExtent { boolean isEmpty(); + @Override boolean setTile(int x, int y, int z, CompoundTag tile); void setEntity(CompoundTag tag); 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 34207e391..86bdcf8cd 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 @@ -104,7 +104,7 @@ public class CFICommands { desc = "Start CFI with a height map as a base" ) @CommandPermissions("worldedit.anvil.cfi") - public void heightmap(Player fp, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "yscale", desc = "double", def = "1") double yscale) { + public void heightmap(Player player, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "yscale", desc = "double", def = "1") double yscale) { if (yscale != 0) { int[] raw = ((DataBufferInt) image.load().getRaster().getDataBuffer()).getData(); int[] table = IntStream.range(0, 256).map(i -> Math.min(255, (int) (i * yscale))) @@ -118,7 +118,7 @@ public class CFICommands { } } HeightMapMCAGenerator generator = new HeightMapMCAGenerator(image.load(), getFolder(generateName())); - setup(generator, fp); + setup(generator, player); } @Command( @@ -126,9 +126,9 @@ public class CFICommands { desc = "Start CFI with an empty map as a base" ) @CommandPermissions("worldedit.anvil.cfi") - public void heightMap(Player fp, int width, int length) { + public void heightMap(Player player, int width, int length) { HeightMapMCAGenerator generator = new HeightMapMCAGenerator(width, length, getFolder(generateName())); - setup(generator, fp); + setup(generator, player); } private String generateName() { @@ -136,13 +136,13 @@ public class CFICommands { return df.format(new Date()); } - private void setup(HeightMapMCAGenerator generator, Player fp) { - CFISettings settings = getSettings(fp).remove(); - generator.setPacketViewer(fp); + private void setup(HeightMapMCAGenerator generator, Player player) { + CFISettings settings = getSettings(player).remove(); + generator.setPacketViewer(player); settings.setGenerator(generator).bind(); - generator.setImageViewer(Fawe.imp().getImageViewer(fp)); + generator.setImageViewer(Fawe.imp().getImageViewer(player)); generator.update(); - mainMenu(fp); + mainMenu(player); } @Command( @@ -172,9 +172,9 @@ public class CFICommands { desc = "Cancel creation" ) @CommandPermissions("worldedit.anvil.cfi") - public void cancel(Player fp) { - getSettings(fp).remove(); - fp.print("Cancelled!"); + public void cancel(Player player) { + getSettings(player).remove(); + player.print("Cancelled!"); } @Command( @@ -238,8 +238,8 @@ public class CFICommands { desc = "Set the floor and main block" ) @CommandPermissions("worldedit.anvil.cfi") - public void column(Player fp, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask maskOpt, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){ - HeightMapMCAGenerator gen = assertSettings(fp).getGenerator(); + public void column(Player player, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask maskOpt, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){ + HeightMapMCAGenerator gen = assertSettings(player).getGenerator(); if (image != null) { gen.setColumn(load(image), patternArg, !disableWhiteOnly); } else if (maskOpt != null) { @@ -247,9 +247,9 @@ public class CFICommands { } else { gen.setColumn(patternArg); } - fp.print("Set column!"); - assertSettings(fp).resetComponent(); - component(fp); + player.print("Set column!"); + assertSettings(player).resetComponent(); + component(player); } @Command( @@ -257,15 +257,15 @@ public class CFICommands { desc = "Set the floor (default: grass)" ) @CommandPermissions("worldedit.anvil.cfi") - public void floorCmd(Player fp, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask maskOpt, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){ - floor(fp, patternArg, image, maskOpt, disableWhiteOnly); - fp.print("Set floor!"); - assertSettings(fp).resetComponent(); - component(fp); + public void floorCmd(Player player, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask maskOpt, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){ + floor(player, patternArg, image, maskOpt, disableWhiteOnly); + player.print("Set floor!"); + assertSettings(player).resetComponent(); + component(player); } - private void floor(Player fp, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask maskOpt, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly) { - HeightMapMCAGenerator gen = assertSettings(fp).getGenerator(); + private void floor(Player player, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask maskOpt, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly) { + HeightMapMCAGenerator gen = assertSettings(player).getGenerator(); if (image != null) { gen.setFloor(load(image), patternArg, !disableWhiteOnly); } else if (maskOpt != null) { @@ -280,15 +280,15 @@ public class CFICommands { desc = "Set the main block (default: stone)" ) @CommandPermissions("worldedit.anvil.cfi") - public void mainCmd(Player fp, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask maskOpt, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){ - main(fp, patternArg, image, maskOpt, disableWhiteOnly); - fp.print("Set main!"); - assertSettings(fp).resetComponent(); - component(fp); + public void mainCmd(Player player, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask maskOpt, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){ + main(player, patternArg, image, maskOpt, disableWhiteOnly); + player.print("Set main!"); + assertSettings(player).resetComponent(); + component(player); } - public void main(Player fp, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask maskOpt, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){ - HeightMapMCAGenerator gen = assertSettings(fp).getGenerator(); + public void main(Player player, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask maskOpt, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){ + HeightMapMCAGenerator gen = assertSettings(player).getGenerator(); if (image != null) { gen.setMain(load(image), patternArg, !disableWhiteOnly); } else if (maskOpt != null) { @@ -306,8 +306,8 @@ public class CFICommands { "e.g. Tallgrass" ) @CommandPermissions("worldedit.anvil.cfi") - public void overlay(Player fp, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask maskOpt, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){ - HeightMapMCAGenerator gen = assertSettings(fp).getGenerator(); + public void overlay(Player player, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask maskOpt, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){ + HeightMapMCAGenerator gen = assertSettings(player).getGenerator(); if (image != null) { gen.setOverlay(load(image), patternArg, !disableWhiteOnly); } else if (maskOpt != null) { @@ -315,8 +315,8 @@ public class CFICommands { } else { gen.setOverlay(patternArg); } - fp.print("Set overlay!"); - component(fp); + player.print("Set overlay!"); + component(player); } @Command( @@ -328,14 +328,14 @@ public class CFICommands { " - A good value for radius and iterations would be 1 8." ) @CommandPermissions("worldedit.anvil.cfi") - public void smoothCmd(Player fp, int radius, int iterations, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask maskOpt, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){ - smooth(fp, radius, iterations, image, maskOpt, disableWhiteOnly); - assertSettings(fp).resetComponent(); - component(fp); + public void smoothCmd(Player player, int radius, int iterations, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask maskOpt, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){ + smooth(player, radius, iterations, image, maskOpt, disableWhiteOnly); + assertSettings(player).resetComponent(); + component(player); } - private void smooth(Player fp, int radius, int iterations, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask maskOpt, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){ - HeightMapMCAGenerator gen = assertSettings(fp).getGenerator(); + private void smooth(Player player, int radius, int iterations, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask maskOpt, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){ + HeightMapMCAGenerator gen = assertSettings(player).getGenerator(); if (image != null) { gen.smooth(load(image), !disableWhiteOnly, radius, iterations); } else { @@ -348,14 +348,14 @@ public class CFICommands { desc = "Create some snow" ) @CommandPermissions("worldedit.anvil.cfi") - public void snow(Player fp, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask maskOpt, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){ - HeightMapMCAGenerator gen = assertSettings(fp).getGenerator(); - floor(fp, BlockTypes.SNOW.getDefaultState().with(PropertyKey.LAYERS, 7), image, maskOpt, disableWhiteOnly); - main(fp, BlockTypes.SNOW_BLOCK, image, maskOpt, disableWhiteOnly); - smooth(fp, 1, 8, image, maskOpt, disableWhiteOnly); - fp.print(TextComponent.of("Added snow!")); - assertSettings(fp).resetComponent(); - component(fp); + public void snow(Player player, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask maskOpt, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){ + HeightMapMCAGenerator gen = assertSettings(player).getGenerator(); + floor(player, BlockTypes.SNOW.getDefaultState().with(PropertyKey.LAYERS, 7), image, maskOpt, disableWhiteOnly); + main(player, BlockTypes.SNOW_BLOCK, image, maskOpt, disableWhiteOnly); + smooth(player, 1, 8, image, maskOpt, disableWhiteOnly); + player.print(TextComponent.of("Added snow!")); + assertSettings(player).resetComponent(); + component(player); } @Command( diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BlendBall.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BlendBall.java index bb94e1a66..df6339e29 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BlendBall.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BlendBall.java @@ -1,16 +1,13 @@ package com.boydti.fawe.object.brush; -import com.google.common.collect.Maps; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.command.tool.brush.Brush; 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.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; - import java.util.Arrays; -import java.util.Map; public class BlendBall implements Brush { @@ -38,8 +35,8 @@ public class BlendBall implements Brush { } int z0 = z + tz; int highest = 1; - BlockStateHolder currentState = editSession.getBlock(x0, y0, z0); - BlockStateHolder highestState = currentState; + BlockState currentState = editSession.getBlock(x0, y0, z0); + BlockState highestState = currentState; Arrays.fill(frequency, 0); boolean tie = false; for (int ox = -1; ox <= 1; ox++) { @@ -48,13 +45,9 @@ public class BlendBall implements Brush { if (oy + y0 < 0 || oy + y0 > maxY) { continue; } - BlockStateHolder state = editSession.getBlock(x0 + ox, y0 + oy, z0 + oz); + BlockState state = editSession.getBlock(x0 + ox, y0 + oy, z0 + oz); Integer count = frequency[state.getInternalBlockTypeId()]; - if (count == null) { - count = 1; - } else { - count++; - } + count++; if (count > highest) { highest = count; highestState = state; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BlobBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BlobBrush.java index db139fbf7..ec7f995d6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BlobBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BlobBrush.java @@ -67,9 +67,9 @@ public class BlobBrush implements Brush { .rotateY(ThreadLocalRandom.current().nextInt(360)) .rotateZ(ThreadLocalRandom.current().nextInt(360)); - double manScaleX = (1.25 + seedX * 0.5); - double manScaleY = (1.25 + seedY * 0.5); - double manScaleZ = (1.25 + seedZ * 0.5); + double manScaleX = 1.25 + seedX * 0.5; + double manScaleY = 1.25 + seedY * 0.5; + double manScaleZ = 1.25 + seedZ * 0.5; MutableVector3 mutable = new MutableVector3(); double roughness = 1 - sphericity; @@ -103,4 +103,4 @@ public class BlobBrush implements Brush { } } } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BrushSettings.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BrushSettings.java index 46eda2246..36a80d788 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BrushSettings.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BrushSettings.java @@ -5,7 +5,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.boydti.fawe.Fawe; import com.boydti.fawe.object.brush.scroll.ScrollAction; import com.boydti.fawe.object.extent.ResettableExtent; -import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.command.tool.BrushTool; @@ -42,10 +41,10 @@ public class BrushSettings { private final Map constructor = new ConcurrentHashMap<>(); - private Brush brush = null; - private Mask mask = null; - private Mask sourceMask = null; - private ResettableExtent transform = null; + private Brush brush; + private Mask mask; + private Mask sourceMask; + private ResettableExtent transform; private Pattern material; private Expression size = new Expression(1); private Set permissions; @@ -57,7 +56,7 @@ public class BrushSettings { this.constructor.put(SettingType.PERMISSIONS, permissions); } - public static BrushSettings get(BrushTool tool, Player player, LocalSession session, Map settings) throws CommandException, InputParseException { + public static BrushSettings get(BrushTool tool, Player player, LocalSession session, Map settings) throws InputParseException { PlatformCommandManager manager = PlatformCommandManager.getInstance(); String constructor = (String) settings.get(SettingType.BRUSH.name()); if (constructor == null) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CatenaryBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CatenaryBrush.java index 5d938e7f9..29a17b0c2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CatenaryBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CatenaryBrush.java @@ -31,7 +31,7 @@ public class CatenaryBrush implements Brush, ResettableTool { @Override public void build(EditSession editSession, BlockVector3 pos2, final Pattern pattern, double size) throws MaxChangedBlocksException { - boolean visual = (editSession.getExtent() instanceof VisualExtent); + boolean visual = editSession.getExtent() instanceof VisualExtent; if (pos1 == null || pos2.equals(pos1)) { if (!visual) { pos1 = pos2; @@ -64,9 +64,8 @@ public class CatenaryBrush implements Brush, ResettableTool { if (!select) { pos1 = null; return; - } else { - pos1 = pos2; } + pos1 = pos2; } } @@ -87,7 +86,7 @@ public class CatenaryBrush implements Brush, ResettableTool { double a = 0.00001; for (;g < a * Math.sinh(dh/(2 * a)); a *= 1.00001); double vertX = (dh-a*Math.log((curveLen + dy)/(curveLen - dy)))/2.0; - double z = (dh/2)/a; + double z = (dh / 2) / a; double oY = (dy - curveLen * (Math.cosh(z) / Math.sinh(z))) / 2; double vertY = a * 1 + oY; return pos1.add(pos2.subtract(pos1).multiply(vertX / dh).add(0, vertY, 0)).round().toBlockPoint(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java index 272c950de..493c58a67 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java @@ -9,23 +9,23 @@ import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; +import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; - import java.util.Arrays; -import java.util.function.Function; -import java.util.stream.Stream; public class ErodeBrush implements Brush { - private static final BlockVector3[] FACES_TO_CHECK = Direction.valuesOf(Direction.Flag.CARDINAL).stream().map(direction -> direction.toBlockVector()).toArray(size -> new BlockVector3[size]); + private static final BlockVector3[] FACES_TO_CHECK = Direction.valuesOf(Direction.Flag.CARDINAL).stream().map(Direction::toBlockVector).toArray(BlockVector3[]::new); @Override public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { - this.erosion(editSession, 2, 1, 5, 1, position, size); + this.erosion(editSession, 2, 1, 5, position, size); } - public void erosion(final EditSession es, int erodeFaces, int erodeRec, int fillFaces, int fillRec, BlockVector3 target, double size) { + void erosion(EditSession es, int erodeFaces, int erodeRec, int fillFaces, + BlockVector3 target, double size) { int brushSize = (int) size + 1; int brushSizeSquared = (int) (size * size); int dimension = brushSize * 2 + 1; @@ -42,7 +42,7 @@ public class ErodeBrush implements Brush { int y0 = y + by; for (int z = -brushSize; z <= brushSize; z++) { int z0 = z + bz; - BlockStateHolder state = es.getBlock(x0, y0, z0); + BlockState state = es.getBlock(x0, y0, z0); buffer1.setBlock(x, y, z, state); buffer2.setBlock(x, y, z, state); } @@ -55,7 +55,7 @@ public class ErodeBrush implements Brush { swap++; } - for (int i = 0; i < fillRec; ++i) { + for (int i = 0; i < 1; ++i) { fillIteration(brushSize, brushSizeSquared, fillFaces, swap % 2 == 0 ? buffer1 : buffer2, swap % 2 == 1 ? buffer1 : buffer2); swap++; } @@ -69,7 +69,8 @@ public class ErodeBrush implements Brush { }, true); } - public void fillIteration(int brushSize, int brushSizeSquared, int fillFaces, FaweClipboard current, FaweClipboard target) { + private void fillIteration(int brushSize, int brushSizeSquared, int fillFaces, + FaweClipboard current, FaweClipboard target) { int[] frequency = null; for (int x = -brushSize; x <= brushSize; x++) { int x2 = x * x; @@ -81,20 +82,20 @@ public class ErodeBrush implements Brush { if (cube >= brushSizeSquared) { continue; } - BlockStateHolder state = current.getBlock(x, y, z); + BaseBlock state = current.getBlock(x, y, z); if (state.getBlockType().getMaterial().isMovementBlocker()) { continue; } int total = 0; int highest = 1; - BlockStateHolder highestState = state; + BaseBlock highestState = state; if (frequency == null) { frequency = new int[BlockTypes.size()]; } else { Arrays.fill(frequency, 0); } for (BlockVector3 offs : FACES_TO_CHECK) { - BlockStateHolder next = current.getBlock(x + offs.getBlockX(), y + offs.getBlockY(), z + offs.getBlockZ()); + BaseBlock next = current.getBlock(x + offs.getBlockX(), y + offs.getBlockY(), z + offs.getBlockZ()); if (!next.getBlockType().getMaterial().isMovementBlocker()) { continue; } @@ -113,7 +114,8 @@ public class ErodeBrush implements Brush { } } - public void erosionIteration(int brushSize, int brushSizeSquared, int erodeFaces, FaweClipboard current, FaweClipboard target) { + private void erosionIteration(int brushSize, int brushSizeSquared, int erodeFaces, + FaweClipboard current, FaweClipboard target) { int[] frequency = null; for (int x = -brushSize; x <= brushSize; x++) { int x2 = x * x; @@ -125,20 +127,20 @@ public class ErodeBrush implements Brush { if (cube >= brushSizeSquared) { continue; } - BlockStateHolder state = current.getBlock(x, y, z); + BaseBlock state = current.getBlock(x, y, z); if (!state.getBlockType().getMaterial().isMovementBlocker()) { continue; } int total = 0; int highest = 1; - BlockStateHolder highestState = state; + BaseBlock highestState = state; if (frequency == null) { frequency = new int[BlockTypes.size()]; } else { Arrays.fill(frequency, 0); } for (BlockVector3 offs : FACES_TO_CHECK) { - BlockStateHolder next = current.getBlock(x + offs.getBlockX(), y + offs.getBlockY(), z + offs.getBlockZ()); + BaseBlock next = current.getBlock(x + offs.getBlockX(), y + offs.getBlockY(), z + offs.getBlockZ()); if (next.getBlockType().getMaterial().isMovementBlocker()) { continue; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java index dd3089cdd..f7ad7b62a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java @@ -47,7 +47,7 @@ public class InspectBrush extends BrushTool implements DoubleActionTraceTool { } public Vector3 getTarget(Player player, boolean adjacent) { - int range = this.range > -1 ? getRange() : DEFAULT_RANGE; + int range = this.range > -1 ? getRange() : MAX_RANGE; if (adjacent) { Location face = player.getBlockTraceFace(range, true); return face.add(face.getDirection()); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java index 566df8501..fd890ec46 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java @@ -1,7 +1,5 @@ package com.boydti.fawe.object.brush; -import com.boydti.fawe.beta.FilterBlock; -import com.boydti.fawe.beta.IQueueExtent; import com.boydti.fawe.object.collection.BlockVectorSet; import com.boydti.fawe.object.mask.AdjacentAnyMask; import com.boydti.fawe.object.mask.RadiusMask; @@ -9,8 +7,6 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.function.mask.BlockMask; -import com.sk89q.worldedit.function.mask.BlockTypeMask; -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; @@ -21,7 +17,6 @@ import com.sk89q.worldedit.math.MutableBlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; - import java.util.Arrays; public class LayerBrush implements Brush { @@ -44,32 +39,29 @@ public class LayerBrush implements Brush { visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS)); Operations.completeBlindly(visitor); BlockVectorSet visited = visitor.getVisited(); - visitor = new RecursiveVisitor(new Mask() { - @Override - public boolean test(BlockVector3 pos) { - int depth = visitor.getDepth() + 1; - if (depth > 1) { - boolean found = false; - BlockState previous = layers[depth - 1]; - BlockState previous2 = layers[depth - 2]; - for (BlockVector3 dir : BreadthFirstSearch.DEFAULT_DIRECTIONS) { - mutable.setComponents(pos.getBlockX() + dir.getBlockX(), pos.getBlockY() + dir.getBlockY(), pos.getBlockZ() + dir.getBlockZ()); - if (visitor.isVisited(mutable) && editSession.getBlock(mutable.getBlockX(), mutable.getBlockY(), mutable.getBlockZ()) == previous) { - mutable.setComponents(pos.getBlockX() + dir.getBlockX() * 2, pos.getBlockY() + dir.getBlockY() * 2, pos.getBlockZ() + dir.getBlockZ() * 2); - if (visitor.isVisited(mutable) && editSession.getBlock(mutable.getBlockX(), mutable.getBlockY(), mutable.getBlockZ()) == previous2) { - found = true; - break; - } else { - return false; - } + visitor = new RecursiveVisitor(pos -> { + int depth = visitor.getDepth() + 1; + if (depth > 1) { + boolean found = false; + BlockState previous = layers[depth - 1]; + BlockState previous2 = layers[depth - 2]; + for (BlockVector3 dir : BreadthFirstSearch.DEFAULT_DIRECTIONS) { + mutable.setComponents(pos.getBlockX() + dir.getBlockX(), pos.getBlockY() + dir.getBlockY(), pos.getBlockZ() + dir.getBlockZ()); + if (visitor.isVisited(mutable) && editSession.getBlock(mutable.getBlockX(), mutable.getBlockY(), mutable.getBlockZ()) == previous) { + mutable.setComponents(pos.getBlockX() + dir.getBlockX() * 2, pos.getBlockY() + dir.getBlockY() * 2, pos.getBlockZ() + dir.getBlockZ() * 2); + if (visitor.isVisited(mutable) && editSession.getBlock(mutable.getBlockX(), mutable.getBlockY(), mutable.getBlockZ()) == previous2) { + found = true; + break; + } else { + return false; } } - if (!found) { - return false; - } } - return !adjacent.test(pos); + if (!found) { + return false; + } } + return !adjacent.test(pos); }, pos -> { int depth = visitor.getDepth(); BlockStateHolder currentPattern = layers[depth]; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LineBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LineBrush.java index 0ed02da3d..709ea9562 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LineBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LineBrush.java @@ -20,8 +20,8 @@ public class LineBrush implements Brush, ResettableTool { } @Override - public void build(EditSession editSession, BlockVector3 position, final Pattern pattern, double size) throws MaxChangedBlocksException { - boolean visual = (editSession.getExtent() instanceof VisualExtent); + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { + boolean visual = editSession.getExtent() instanceof VisualExtent; if (pos1 == null) { if (!visual) { pos1 = position; @@ -34,7 +34,6 @@ public class LineBrush implements Brush, ResettableTool { BBC.BRUSH_LINE_SECONDARY.send(editSession.getPlayer()); if (!select) { pos1 = null; - return; } else { pos1 = position; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RaiseBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RaiseBrush.java index 4bbb4642a..498ed1932 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RaiseBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RaiseBrush.java @@ -8,6 +8,6 @@ import com.sk89q.worldedit.math.BlockVector3; public class RaiseBrush extends ErodeBrush { @Override public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { - this.erosion(editSession, 6, 0, 1, 1, position, size); + this.erosion(editSession, 6, 0, 1, position, size); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RecurseBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RecurseBrush.java index 75f24345b..27c092e11 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RecurseBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RecurseBrush.java @@ -4,7 +4,6 @@ import com.boydti.fawe.object.mask.RadiusMask; import com.boydti.fawe.object.visitor.DFSRecursiveVisitor; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.function.block.BlockReplace; import com.sk89q.worldedit.function.mask.Mask; @@ -24,7 +23,7 @@ public class RecurseBrush implements Brush { } @Override - public void build(final EditSession editSession, final BlockVector3 position, Pattern to, double size) throws MaxChangedBlocksException { + public void build(EditSession editSession, BlockVector3 position, Pattern to, double size) throws MaxChangedBlocksException { Mask mask = editSession.getMask(); if (mask == null) { mask = Masks.alwaysTrue(); @@ -35,7 +34,7 @@ public class RecurseBrush implements Brush { return; } final BlockReplace replace = new BlockReplace(editSession, to); - editSession.setMask((Mask) null); + editSession.setMask(null); final int maxY = editSession.getMaxY(); if (dfs) { final Mask radMask = new RadiusMask(0, (int) size); @@ -43,7 +42,7 @@ public class RecurseBrush implements Brush { @Override public boolean isVisitable(BlockVector3 from, BlockVector3 to) { int y = to.getBlockY(); - return y >= y && y < maxY && radMask.test(to) && super.isVisitable(from, to); + return y < maxY && radMask.test(to) && super.isVisitable(from, to); } }; visitor.visit(position); @@ -53,7 +52,7 @@ public class RecurseBrush implements Brush { @Override public boolean isVisitable(BlockVector3 from, BlockVector3 to) { int y = to.getBlockY(); - return y >= y && y < maxY && super.isVisitable(from, to); + return y < maxY && super.isVisitable(from, to); } }; visitor.visit(position); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterOverlayBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterOverlayBrush.java index 9e6f80c0b..72ce8a9e8 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterOverlayBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterOverlayBrush.java @@ -17,7 +17,6 @@ public class ScatterOverlayBrush extends ScatterBrush { int y = pt.getBlockY(); int z = pt.getBlockZ(); BlockVector3 dir = getDirection(pt); -// dir.setComponents(x + dir.getBlockX(), y + dir.getBlockY(), z + dir.getBlockZ()); editSession.setBlock(x + dir.getBlockX(), y + dir.getBlockY(), z + dir.getBlockZ(), p); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SpikeBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SpikeBrush.java deleted file mode 100644 index e4362abaa..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SpikeBrush.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.boydti.fawe.object.brush; - -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.command.tool.brush.Brush; -import com.sk89q.worldedit.function.pattern.Pattern; -import com.sk89q.worldedit.math.BlockVector3; - -public class SpikeBrush implements Brush { - - @Override - public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { - - } -} \ No newline at end of file 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 0d9fe33c5..6d89691ba 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,13 +5,11 @@ 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.SolidBlockMask; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.visitor.BreadthFirstSearch; import com.sk89q.worldedit.function.visitor.RecursiveVisitor; import com.sk89q.worldedit.math.BlockVector3; - import java.util.Arrays; import java.util.concurrent.ThreadLocalRandom; @@ -32,8 +30,8 @@ public class SplatterBrush extends ScatterBrush { Pattern tmp; try { tmp = p.apply(position); - } catch (BiomePattern.BiomePatternException ignore) { - tmp = ignore.getPattern(); + } catch (BiomePattern.BiomePatternException e) { + tmp = e.getPattern(); } finalPattern = tmp; } else { @@ -44,7 +42,8 @@ public class SplatterBrush extends ScatterBrush { RecursiveVisitor visitor = new RecursiveVisitor(vector -> { double dist = vector.distanceSq(position); - if (dist < size2 && !placed.contains(vector) && (ThreadLocalRandom.current().nextInt(5) < 2) && surface.test(vector)) { + if (dist < size2 && !placed.contains(vector) && ThreadLocalRandom.current().nextInt(5) < 2 + && surface.test(vector)) { placed.add(vector); return true; } 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 e36f5e1e8..fca13dc96 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 @@ -28,12 +28,10 @@ public class SplineBrush implements Brush, ResettableTool { private ArrayList> positionSets; private int numSplines; - private final LocalSession session; private final Player player; private BlockVector3 position; public SplineBrush(Player player, LocalSession session) { - this.session = session; this.player = player; this.positionSets = new ArrayList<>(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SurfaceSpline.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SurfaceSpline.java index f5b545ce3..bd1d7235f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SurfaceSpline.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SurfaceSpline.java @@ -16,9 +16,12 @@ import java.util.ArrayList; import java.util.List; public class SurfaceSpline implements Brush { - final double tension, bias, continuity, quality; + private final double tension; + private final double bias; + private final double continuity; + private final double quality; - public SurfaceSpline(final double tension, final double bias, final double continuity, final double quality) { + public SurfaceSpline(double tension, double bias, double continuity, double quality) { this.tension = tension; this.bias = bias; this.continuity = continuity; @@ -43,7 +46,7 @@ public class SurfaceSpline implements Brush { final List nodes = new ArrayList<>(path.size()); final KochanekBartelsInterpolation interpol = new KochanekBartelsInterpolation(); - for (final BlockVector3 nodevector : path) { + for (BlockVector3 nodevector : path) { final Node n = new Node(nodevector.toVector3()); n.setTension(tension); n.setBias(bias); @@ -72,13 +75,13 @@ public class SurfaceSpline implements Brush { } } if (radius != 0) { - double radius2 = (radius * radius); + double radius2 = radius * radius; LocalBlockVectorSet newSet = new LocalBlockVectorSet(); final int ceilrad = (int) Math.ceil(radius); - for (final BlockVector3 v : vset) { + for (BlockVector3 v : vset) { final int tipx = v.getBlockX(), tipy = v.getBlockY(), tipz = v.getBlockZ(); - for (int loopx = tipx - ceilrad; loopx <= (tipx + ceilrad); loopx++) { - for (int loopz = tipz - ceilrad; loopz <= (tipz + ceilrad); loopz++) { + for (int loopx = tipx - ceilrad; loopx <= tipx + ceilrad; loopx++) { + for (int loopz = tipz - ceilrad; loopz <= tipz + ceilrad; loopz++) { if (MathMan.hypot2(loopx - tipx, 0, loopz - tipz) <= radius2) { int y = editSession.getNearestSurfaceTerrainBlock(loopx, loopz, v.getBlockY(), 0, maxY); if (y == -1) continue; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java index a920fb68b..125f43f34 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java @@ -139,23 +139,23 @@ public class DiskStorageHistory extends FaweStreamChangeSet { enttFile.delete(); } - public void undo(Player fp, Region[] regions) { - EditSession session = toEditSession(fp, regions); + public void undo(Player player, Region[] regions) { + EditSession session = toEditSession(player, regions); session.undo(session); deleteFiles(); } - public void undo(Player fp) { - undo(fp, null); + public void undo(Player player) { + undo(player, null); } - public void redo(Player fp, Region[] regions) { - EditSession session = toEditSession(fp, regions); + public void redo(Player player, Region[] regions) { + EditSession session = toEditSession(player, regions); session.redo(session); } - public void redo(Player fp) { - undo(fp, null); + public void redo(Player player) { + undo(player, null); } public UUID getUUID() { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/MemBlockSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/MemBlockSet.java index b9ae7a46e..d467d7f86 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/MemBlockSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/MemBlockSet.java @@ -140,8 +140,7 @@ public final class MemBlockSet extends BlockSet { @Override public int size() { int size = 0; - for (int X = 0;X < rows.length; X++) { - IRow nullRowX = rows[X]; + for (IRow nullRowX : rows) { if (nullRowX instanceof RowX) { RowX rowx = (RowX) nullRowX; for (int Z = 0; Z < rowx.rows.length; Z++) { @@ -238,8 +237,7 @@ public final class MemBlockSet extends BlockSet { @Override public int size() { int size = 0; - for (int X = 0;X < rows.length; X++) { - IRow nullRowX = rows[X]; + for (IRow nullRowX : rows) { if (nullRowX instanceof RowX) { RowX rowx = (RowX) nullRowX; for (int Z = 0; Z < rowx.rows.length; Z++) { @@ -286,18 +284,20 @@ public final class MemBlockSet extends BlockSet { int maxY = 15; int maxy = 16; int by = Integer.MAX_VALUE; - for (int X = 0; X < rows.length; X++) { - IRow nullRowX = rows[X]; - if (!(nullRowX instanceof RowX)) continue; + for (IRow nullRowX : rows) { + if (!(nullRowX instanceof RowX)) + continue; RowX rowx = (RowX) nullRowX; for (int Z = 0; Z < rowx.rows.length; Z++) { IRow nullRowZ = rowx.rows[Z]; - if (!(nullRowZ instanceof RowZ)) continue; + if (!(nullRowZ instanceof RowZ)) + continue; RowZ rowz = (RowZ) nullRowZ; outer: for (int Y = 0; Y <= maxY; Y++) { IRow nullRowY = rowz.rows[Y]; - if (!(nullRowY instanceof RowY)) continue; + if (!(nullRowY instanceof RowY)) + continue; RowY rowY = (RowY) nullRowY; int localMaxy = Y == maxY ? maxy : 15; for (int y = 0, i = 0; y < localMaxy; y++) { @@ -312,7 +312,8 @@ public final class MemBlockSet extends BlockSet { maxy = y; } by = (Y << 4) + y; - if (by == 0) return 0; + if (by == 0) + return 0; break outer; } } @@ -328,18 +329,20 @@ public final class MemBlockSet extends BlockSet { int maxY = 0; int maxy = 0; int by = Integer.MIN_VALUE; - for (int X = 0; X < rows.length; X++) { - IRow nullRowX = rows[X]; - if (!(nullRowX instanceof RowX)) continue; + for (IRow nullRowX : rows) { + if (!(nullRowX instanceof RowX)) + continue; RowX rowx = (RowX) nullRowX; for (int Z = 0; Z < rowx.rows.length; Z++) { IRow nullRowZ = rowx.rows[Z]; - if (!(nullRowZ instanceof RowZ)) continue; + if (!(nullRowZ instanceof RowZ)) + continue; RowZ rowz = (RowZ) nullRowZ; outer: for (int Y = 15; Y >= maxY; Y--) { IRow nullRowY = rowz.rows[Y]; - if (!(nullRowY instanceof RowY)) continue; + if (!(nullRowY instanceof RowY)) + continue; RowY rowY = (RowY) nullRowY; int localMaxy = Y == maxY ? maxy : 0; for (int y = 15, i = 63; y >= localMaxy; y--) { @@ -354,7 +357,8 @@ public final class MemBlockSet extends BlockSet { maxy = y + 1; } by = (Y << 4) + y; - if (by == FaweCache.IMP.WORLD_MAX_Y) return FaweCache.IMP.WORLD_MAX_Y; + if (by == FaweCache.IMP.WORLD_MAX_Y) + return FaweCache.IMP.WORLD_MAX_Y; break outer; } } @@ -425,9 +429,7 @@ public final class MemBlockSet extends BlockSet { IRow nullRowY = rowz.rows[Y]; if (!(nullRowY instanceof RowY)) continue; RowY rowY = (RowY) nullRowY; - for (long value : rowY.bits) { - or |= value; - } + or |= Arrays.stream(rowY.bits).reduce(0, (a, b) -> a | b); or = (or & 0xFFFF) | ((or >> 16) & 0xFFFF) | ((or >> 32) & 0xFFFF) | ((or >> 48) & 0xFFFF); if (highestBit(or) == 15) return tx + 15; } @@ -444,14 +446,15 @@ public final class MemBlockSet extends BlockSet { int maxChunkZ = rows.length - 1; int maxz = 16; int bz = Integer.MAX_VALUE; - for (int X = 0; X < rows.length; X++) { - IRow nullRowX = rows[X]; - if (!(nullRowX instanceof RowX)) continue; + for (IRow nullRowX : rows) { + if (!(nullRowX instanceof RowX)) + continue; RowX rowx = (RowX) nullRowX; outer: for (int Z = 0; Z <= maxChunkZ; Z++) { IRow nullRowZ = rowx.rows[Z]; - if (!(nullRowZ instanceof RowZ)) continue; + if (!(nullRowZ instanceof RowZ)) + continue; RowZ rowz = (RowZ) nullRowZ; if (Z != maxChunkZ) { maxChunkZ = Z; @@ -459,7 +462,8 @@ public final class MemBlockSet extends BlockSet { } for (int Y = 0; Y < rowz.rows.length; Y++) { IRow nullRowY = rowz.rows[Y]; - if (!(nullRowY instanceof RowY)) continue; + if (!(nullRowY instanceof RowY)) + continue; RowY rowY = (RowY) nullRowY; for (int y = 0, i1 = 0; y < 16; y++, i1 += 4) { for (int z = 0, i = i1; z < maxz; z += 4, i++) { @@ -500,9 +504,7 @@ public final class MemBlockSet extends BlockSet { IRow nullRowY = rowz.rows[Y]; if (!(nullRowY instanceof RowY)) continue; RowY rowY = (RowY) nullRowY; - for (long value : rowY.bits) { - or |= value; - } + or |= Arrays.stream(rowY.bits).reduce(0, (a, b) -> a | b); or = (or & 0xFFFF) | ((or >> 16) & 0xFFFF) | ((or >> 32) & 0xFFFF) | ((or >> 48) & 0xFFFF); if (lowestBit(or) == 0) return bx; } @@ -566,7 +568,6 @@ public final class MemBlockSet extends BlockSet { private int bx, by, bz, zz, yy; private RowX rowX; private RowZ rowZ; - private RowY rowY; private long[] bits; private int bitsIndex = 0; private int yIndex = 0; @@ -618,7 +619,7 @@ public final class MemBlockSet extends BlockSet { by = yIndex << 4; IRow nullRowY = rowZ.rows[yIndex++]; if (nullRowY instanceof RowY) { - rowY = (RowY) nullRowY; + RowY rowY = (RowY) nullRowY; bits = rowY.bits; return true; } @@ -656,9 +657,7 @@ public final class MemBlockSet extends BlockSet { public BlockVector3 next() { final long lowBit = Long.lowestOneBit(bitBuffer); final int bitIndex = Long.bitCount(lowBit-1); - { - mutable.setComponents((bx) + (bitIndex & 15), yy, (zz) + (bitIndex)); - } + mutable.setComponents((bx) + (bitIndex & 15), yy, (zz) + (bitIndex)); bitBuffer = bitBuffer ^ lowBit; nextLong(); return mutable; @@ -674,20 +673,23 @@ public final class MemBlockSet extends BlockSet { @Override public boolean isEmpty() { - for (int X = 0; X < rows.length; X++) { - IRow nullRowX = rows[X]; - if (!(nullRowX instanceof RowX)) continue; + for (IRow nullRowX : rows) { + if (!(nullRowX instanceof RowX)) + continue; RowX rowx = (RowX) nullRowX; for (int Z = 0; Z < rowx.rows.length; Z++) { IRow nullRowZ = rowx.rows[Z]; - if (!(nullRowZ instanceof RowZ)) continue; + if (!(nullRowZ instanceof RowZ)) + continue; RowZ rowz = (RowZ) nullRowZ; for (int Y = 0; Y < 16; Y++) { IRow nullRowY = rowz.rows[Y]; - if (!(nullRowY instanceof RowY)) continue; + if (!(nullRowY instanceof RowY)) + continue; RowY rowY = (RowY) nullRowY; for (long bit : rowY.bits) { - if (bit != 0) return true; + if (bit != 0) + return true; } } } @@ -704,13 +706,14 @@ public final class MemBlockSet extends BlockSet { long total = 0; long lastBit = 0; int lastCount = 0; - for (int x = 0; x < rows.length; x++) { - IRow nullRowX = rows[x]; - if (!(nullRowX instanceof RowX)) continue; + for (IRow nullRowX : rows) { + if (!(nullRowX instanceof RowX)) + continue; RowX rowx = (RowX) nullRowX; for (int z = 0; z < rowx.rows.length; z++) { IRow nullRowZ = rowx.rows[z]; - if (!(nullRowZ instanceof RowZ)) continue; + if (!(nullRowZ instanceof RowZ)) + continue; RowZ rowz = (RowZ) nullRowZ; for (int y = 0; y < 16; y++) { IRow nullRowY = rowz.rows[y]; @@ -755,7 +758,8 @@ public final class MemBlockSet extends BlockSet { remove(rows, x, y, z); return false; } - default void clear(IRow[] rows, int x, int y, int z) { return; } + default void clear(IRow[] rows, int x, int y, int z) { + } } public static final class NullRowX implements IRow { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ExtentHeightCacher.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ExtentHeightCacher.java index 9368c5856..b658d630b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ExtentHeightCacher.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ExtentHeightCacher.java @@ -1,6 +1,5 @@ package com.boydti.fawe.object.extent; -import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.PassthroughExtent; @@ -30,7 +29,7 @@ public class ExtentHeightCacher extends PassthroughExtent { int rx = x - cacheBotX + 16; int rz = z - cacheBotZ + 16; int index; - if (((rx & 0xFF) != rx || (rz & 0xFF) != rz)) { + if ((rx & 0xFF) != rx || (rz & 0xFF) != rz) { cacheBotX = x - 16; cacheBotZ = z - 16; lastY = y; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java index 7d2304482..6ba63c070 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java @@ -1,12 +1,9 @@ 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.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; @@ -15,9 +12,10 @@ 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; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; - import java.util.Collection; import javax.annotation.Nullable; @@ -41,12 +39,7 @@ public abstract class FaweRegionExtent extends ResettableExtent { public abstract Collection getRegions(); public boolean isGlobal() { - for (Region region : getRegions()) { - if (region.isGlobal()) { - return true; - } - } - return false; + return getRegions().stream().anyMatch(Region::isGlobal); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/OffsetExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/OffsetExtent.java index b9a8d6d6b..2071b2762 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/OffsetExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/OffsetExtent.java @@ -30,12 +30,12 @@ public class OffsetExtent extends ResettableExtent { } @Override - public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(BlockVector3 location, T block) throws WorldEditException { return getExtent().setBlock(location.getBlockX() + dx, location.getBlockY() + dy, location.getBlockZ() + dz, block); } @Override - public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { return getExtent().setBlock(x + dx, y + dy, z + dz, block); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TransformExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TransformExtent.java index b5a6cd329..16baf4fe6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TransformExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TransformExtent.java @@ -51,13 +51,13 @@ public class TransformExtent extends BlockTransformExtent { if (min == null) { min = pos; } - mutable1.mutX(((pos.getX() - min.getX()))); - mutable1.mutY(((pos.getY() - min.getY()))); - mutable1.mutZ(((pos.getZ() - min.getZ()))); + mutable1.mutX(pos.getX() - min.getX()); + mutable1.mutY(pos.getY() - min.getY()); + mutable1.mutZ(pos.getZ() - min.getZ()); Vector3 tmp = getTransform().apply(mutable1); - mutable2.mutX((tmp.getX() + min.getX())); - mutable2.mutY((tmp.getY() + min.getY())); - mutable2.mutZ((tmp.getZ() + min.getZ())); + mutable2.mutX(tmp.getX() + min.getX()); + mutable2.mutY(tmp.getY() + min.getY()); + mutable2.mutZ(tmp.getZ() + min.getZ()); return mutable2; } @@ -65,13 +65,13 @@ public class TransformExtent extends BlockTransformExtent { if (min == null) { min = BlockVector3.at(x, y, z); } - mutable1.mutX(((x - min.getX()))); - mutable1.mutY(((y - min.getY()))); - mutable1.mutZ(((z - min.getZ()))); + mutable1.mutX(x - min.getX()); + mutable1.mutY(y - min.getY()); + mutable1.mutZ(z - min.getZ()); Vector3 tmp = getTransform().apply(mutable1); - mutable2.mutX((tmp.getX() + min.getX())); - mutable2.mutY((tmp.getY() + min.getY())); - mutable2.mutZ((tmp.getZ() + min.getZ())); + mutable2.mutX(tmp.getX() + min.getX()); + mutable2.mutY(tmp.getY() + min.getY()); + mutable2.mutZ(tmp.getZ() + min.getZ()); return tmp.toBlockPoint(); } @@ -93,13 +93,13 @@ public class TransformExtent extends BlockTransformExtent { } @Override - public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { return super.setBlock(getPos(x, y, z), transformInverse(block)); } @Override - public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(BlockVector3 location, B block) throws WorldEditException { return super.setBlock(getPos(location), transformInverse(block)); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask2.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask2.java deleted file mode 100644 index 8cb5f6ffc..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask2.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.boydti.fawe.object.mask; - -import com.sk89q.worldedit.function.mask.AbstractMask; -import com.sk89q.worldedit.math.BlockVector3; - -public class AdjacentAnyMask2 extends AbstractMask { - @Override - public boolean test(BlockVector3 vector) { - return false; - } -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/number/MutableLong.java b/worldedit-core/src/main/java/com/boydti/fawe/object/number/MutableLong.java deleted file mode 100644 index bcbe87056..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/number/MutableLong.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.boydti.fawe.object.number; - -public final class MutableLong { - private long value; - - public final void increment() { - value++; - } - - public void set(long value) { - this.value = value; - } - - public long get() { - return value; - } - - public void add(long amount) { - this.value += amount; - } -} 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 74f447a30..88afd3e48 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 @@ -23,9 +23,9 @@ public class RelativePattern extends AbstractPattern implements ResettablePatter if (origin == null) { origin = pos; } - mutable.mutX((pos.getX() - origin.getX())); - mutable.mutY((pos.getY() - origin.getY())); - mutable.mutZ((pos.getZ() - origin.getZ())); + mutable.mutX(pos.getX() - origin.getX()); + mutable.mutY(pos.getY() - origin.getY()); + mutable.mutZ(pos.getZ() - origin.getZ()); return pattern.apply(mutable); } @@ -34,9 +34,9 @@ public class RelativePattern extends AbstractPattern implements ResettablePatter if (origin == null) { origin = set; } - mutable.mutX((set.getX() - origin.getX())); - mutable.mutY((set.getY() - origin.getY())); - mutable.mutZ((set.getZ() - origin.getZ())); + mutable.mutX(set.getX() - origin.getX()); + mutable.mutY(set.getY() - origin.getY()); + mutable.mutZ(set.getZ() - origin.getZ()); return pattern.apply(extent, get, mutable); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/random/SimpleRandom.java b/worldedit-core/src/main/java/com/boydti/fawe/object/random/SimpleRandom.java index 1301c455c..1b3848e19 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/random/SimpleRandom.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/random/SimpleRandom.java @@ -1,9 +1,10 @@ package com.boydti.fawe.object.random; public interface SimpleRandom { - public double nextDouble(int x, int y, int z); - public default int nextInt(int x, int y, int z, int len) { + double nextDouble(int x, int y, int z); + + default int nextInt(int x, int y, int z, int len) { double val = nextDouble(x, y, z); return (int) (val * len); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/random/TrueRandom.java b/worldedit-core/src/main/java/com/boydti/fawe/object/random/TrueRandom.java index a486d677f..a1e379026 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/random/TrueRandom.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/random/TrueRandom.java @@ -3,19 +3,16 @@ package com.boydti.fawe.object.random; import java.util.SplittableRandom; public class TrueRandom implements SimpleRandom { - private final SplittableRandom r; - public TrueRandom() { - this.r = new SplittableRandom(); - } + private final SplittableRandom random = new SplittableRandom(); @Override public double nextDouble(int x, int y, int z) { - return r.nextDouble(); + return random.nextDouble(); } @Override public int nextInt(int x, int y, int z, int len) { - return r.nextInt(len); + return random.nextInt(len); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/Triangle.java b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/Triangle.java index 8cea2bfe3..e8b710486 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/Triangle.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/Triangle.java @@ -35,7 +35,8 @@ public class Triangle { radius[1] = RADIUS; radius[2] = RADIUS; this.normalVec = pos2.subtract(pos1).cross(pos3.subtract(pos1)).normalize(); - this.b = Math.max(Math.max(this.normalVec.dot(pos1), this.normalVec.dot(pos2)), this.normalVec.dot(pos3)); + this.b = Math.max(Math.max(this.normalVec.dot(pos1), this.normalVec.dot(pos2)), + this.normalVec.dot(pos3)); } public boolean above(BlockVector3 pt) { @@ -45,9 +46,14 @@ public class Triangle { public Edge getEdge(int index) { if (index == this.verts.length - 1) { - return new Edge(Vector3.at(this.verts[index][0], this.verts[index][1],this.verts[index][2]), Vector3.at(this.verts[0][0], this.verts[0][1], this.verts[0][2])); + return new Edge( + Vector3.at(this.verts[index][0], this.verts[index][1], this.verts[index][2]), + Vector3.at(this.verts[0][0], this.verts[0][1], this.verts[0][2])); } else { - return new Edge(Vector3.at(this.verts[index][0], this.verts[index][1],this.verts[index][2]), Vector3.at(this.verts[index + 1][0], this.verts[index + 1][1], this.verts[index + 1][2])); + return new Edge( + Vector3.at(this.verts[index][0], this.verts[index][1], this.verts[index][2]), + Vector3.at(this.verts[index + 1][0], this.verts[index + 1][1], + this.verts[index + 1][2])); } } @@ -80,7 +86,7 @@ public class Triangle { } private double dot(double[] v1, double[] v2) { - return (v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]); + return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]; } @@ -175,8 +181,8 @@ public class Triangle { } - private boolean overlaps(double boxcenter[], double boxhalfsize[], double triverts[][]) { - double min, max, p0, p1, p2, rad, fex, fey, fez; + private boolean overlaps(double[] boxcenter, double[] boxhalfsize, double[][] triverts) { + double min, max, fex, fey, fez; sub(v0, triverts[0], boxcenter); sub(v1, triverts[1], boxcenter); sub(v2, triverts[2], boxcenter); @@ -188,48 +194,71 @@ public class Triangle { fey = Math.abs(e0[1]); fez = Math.abs(e0[2]); - if (!axisTestX01(e0[2], e0[1], fez, fey)) return false; - if (!axisTestY02(e0[2], e0[0], fez, fex)) return false; - if (!axisTestZ12(e0[1], e0[0], fey, fex)) return false; + if (!axisTestX01(e0[2], e0[1], fez, fey)) { + return false; + } + if (!axisTestY02(e0[2], e0[0], fez, fex)) { + return false; + } + if (!axisTestZ12(e0[1], e0[0], fey, fex)) { + return false; + } fex = Math.abs(e1[0]); fey = Math.abs(e1[1]); fez = Math.abs(e1[2]); - if (!axisTestX01(e1[2], e1[1], fez, fey)) return false; - if (!axisTestY02(e1[2], e1[0], fez, fex)) return false; - if (!axisTestZ0(e1[1], e1[0], fey, fex)) return false; - + if (!axisTestX01(e1[2], e1[1], fez, fey)) { + return false; + } + if (!axisTestY02(e1[2], e1[0], fez, fex)) { + return false; + } + if (!axisTestZ0(e1[1], e1[0], fey, fex)) { + return false; + } fex = Math.abs(e2[0]); fey = Math.abs(e2[1]); fez = Math.abs(e2[2]); - if (!axisTestX2(e2[2], e2[1], fez, fey)) return false; - if (!axisTestY1(e2[2], e2[0], fez, fex)) return false; - if (!axisTestZ12(e2[1], e2[0], fey, fex)) return false; + if (!axisTestX2(e2[2], e2[1], fez, fey)) { + return false; + } + if (!axisTestY1(e2[2], e2[0], fez, fex)) { + return false; + } + if (!axisTestZ12(e2[1], e2[0], fey, fex)) { + return false; + } max = MathMan.max(v0[0], v1[0], v2[0]); min = MathMan.min(v0[0], v1[0], v2[0]); - if (min > boxhalfsize[0] || max < -boxhalfsize[0]) return false; + if (min > boxhalfsize[0] || max < -boxhalfsize[0]) { + return false; + } max = MathMan.max(v0[1], v1[1], v2[1]); min = MathMan.min(v0[1], v1[1], v2[1]); - if (min > boxhalfsize[1] || max < -boxhalfsize[1]) return false; + if (min > boxhalfsize[1] || max < -boxhalfsize[1]) { + return false; + } max = MathMan.max(v0[2], v1[2], v2[2]); min = MathMan.min(v0[2], v1[2], v2[2]); - if (min > boxhalfsize[2] || max < -boxhalfsize[2]) return false; + if (min > boxhalfsize[2] || max < -boxhalfsize[2]) { + return false; + } cross(normal, e0, e1); - return (planeBoxOverlap(normal, v0, boxhalfsize)); + return planeBoxOverlap(normal, v0, boxhalfsize); } - private boolean planeBoxOverlap(double normal[], double vert[], double maxbox[]) { + private boolean planeBoxOverlap(double[] normal, double[] vert, double[] maxbox) { for (int q = 0; q <= 2; q++) { double v = vert[q]; if (normal[q] > 0.0f) { @@ -240,8 +269,9 @@ public class Triangle { vmax[q] = -maxbox[q] - v; } } - if (dot(normal, vmin) > 0.0f) return false; - if (dot(normal, vmax) >= 0.0f) return true; - return false; + if (dot(normal, vmin) > 0.0f) { + return false; + } + return dot(normal, vmax) >= 0.0f; } } 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 6ea78e09a..8ecb65138 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 @@ -19,6 +19,8 @@ package com.boydti.fawe.object.regions.selector; +import static com.google.common.base.Preconditions.checkNotNull; + import com.boydti.fawe.object.regions.PolyhedralRegion; import com.boydti.fawe.object.regions.Triangle; import com.sk89q.worldedit.IncompleteRegionException; @@ -32,13 +34,14 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; import com.sk89q.worldedit.world.World; - -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; import javax.annotation.Nullable; - -import static com.google.common.base.Preconditions.checkNotNull; - /** * Creates a {@code PolyhedralRegion} from a user's selections. */ @@ -51,7 +54,7 @@ public class PolyhedralRegionSelector implements RegionSelector, CUIRegion { * Create a new selector with a {@code null} world. */ public PolyhedralRegionSelector() { - this((World) null); + this(null); } /** diff --git a/worldedit-core/src/main/java/com/boydti/fawe/regions/SimpleRegion.java b/worldedit-core/src/main/java/com/boydti/fawe/regions/SimpleRegion.java deleted file mode 100644 index 6879154db..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/regions/SimpleRegion.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.boydti.fawe.regions; - -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.regions.AbstractRegion; -import com.sk89q.worldedit.regions.RegionOperationException; -import com.sk89q.worldedit.world.World; - -public abstract class SimpleRegion extends AbstractRegion { - private final BlockVector3 max; - private final BlockVector3 min; - - public SimpleRegion(World world, BlockVector3 min, BlockVector3 max) { - super(world); - this.min = min; - this.max = max; - } - - @Override - public BlockVector3 getMinimumPoint() { - return min; - } - - @Override - public BlockVector3 getMaximumPoint() { - return max; - } - - @Override - public void expand(BlockVector3... changes) throws RegionOperationException { - throw new UnsupportedOperationException("Region is immutable"); - } - - @Override - public void contract(BlockVector3... changes) throws RegionOperationException { - throw new UnsupportedOperationException("Region is immutable"); - } - - @Override - public boolean contains(BlockVector3 p) { - return contains(p.getBlockX(), p.getBlockY(), p.getBlockZ()); - } - - @Override - public abstract boolean contains(int x, int y, int z); - - @Override - public abstract boolean contains(int x, int z); -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/RegionFilter.java b/worldedit-core/src/main/java/com/boydti/fawe/regions/general/RegionFilter.java index e8de32bc8..11cc95460 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/RegionFilter.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/regions/general/RegionFilter.java @@ -1,7 +1,8 @@ package com.boydti.fawe.regions.general; public interface RegionFilter { - public boolean containsRegion(int mcaX, int mcaZ); - public boolean containsChunk(int chunkX, int chunkZ); -} \ No newline at end of file + boolean containsRegion(int mcaX, int mcaZ); + + boolean containsChunk(int chunkX, int chunkZ); +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java index 037b5f9e8..412adfaf8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -372,8 +372,8 @@ public class LocalSession implements TextureHolder { public void remember(EditSession editSession) { checkNotNull(editSession); - Player fp = editSession.getPlayer(); - int limit = fp == null ? Integer.MAX_VALUE : fp.getLimit().MAX_HISTORY; + Player player = editSession.getPlayer(); + int limit = player == null ? Integer.MAX_VALUE : player.getLimit().MAX_HISTORY; remember(editSession, true, limit); } @@ -507,7 +507,6 @@ public class LocalSession implements TextureHolder { */ public EditSession undo(@Nullable BlockBag newBlockBag, Actor actor) { checkNotNull(actor); - //TODO This method needs to be modified to use actors instead of FAWEPlayer loadSessionHistoryFromDisk(actor.getUniqueId(), ((Player) actor).getWorldForEditing()); if (getHistoryNegativeIndex() < history.size()) { FaweChangeSet changeSet = getChangeSet(history.get(getHistoryIndex())); @@ -544,7 +543,6 @@ public class LocalSession implements TextureHolder { */ public EditSession redo(@Nullable BlockBag newBlockBag, Actor actor) { checkNotNull(actor); - //TODO This method needs to be modified to use actors instead of FAWEPlayer loadSessionHistoryFromDisk(actor.getUniqueId(), ((Player)actor).getWorldForEditing()); if (getHistoryNegativeIndex() > 0) { setDirty(); @@ -622,16 +620,12 @@ public class LocalSession implements TextureHolder { */ public RegionSelector getRegionSelector(World world) { checkNotNull(world); - try { - if (selector.getWorld() == null || !selector.getWorld().equals(world)) { - selector.setWorld(world); - selector.clear(); - if (hasWorldOverride() && !world.equals(getWorldOverride())) { - setWorldOverride(null); - } - } - } catch (Throwable ignore) { + if (selector.getWorld() == null || !selector.getWorld().equals(world)) { + selector.setWorld(world); selector.clear(); + if (hasWorldOverride() && !world.equals(getWorldOverride())) { + setWorldOverride(null); + } } return selector; } @@ -1044,6 +1038,7 @@ public class LocalSession implements TextureHolder { } else if (type.getId().equalsIgnoreCase(config.navigationWand)) { throw new InvalidToolBindException(type, "Already used for the navigation wand"); } + Tool previous; if (player != null && (tool instanceof BrushTool || tool == null) && Settings.IMP.EXPERIMENTAL.PERSISTENT_BRUSHES && item.getNativeItem() != null) { previous = BrushCache.getCachedTool(item); @@ -1350,23 +1345,25 @@ public class LocalSession implements TextureHolder { */ public EditSession createEditSession(Actor actor) { checkNotNull(actor); - BlockBag blockBag = null; - if (actor.isPlayer() && actor instanceof Player) { - blockBag = getBlockBag((Player) actor); - } + World world = null; if (hasWorldOverride()) { world = getWorldOverride(); } else if (actor instanceof Locatable && ((Locatable) actor).getExtent() instanceof World) { world = (World) ((Locatable) actor).getExtent(); } - EditSessionBuilder builder = new EditSessionBuilder(world); - if (actor.isPlayer() && actor instanceof Player) builder.player((Player) actor); - builder.blockBag(blockBag); - builder.fastmode(fastMode); // Create an edit session - EditSession editSession = builder.build(); + EditSession editSession; + EditSessionBuilder builder = new EditSessionBuilder(world); + if (actor.isPlayer() && actor instanceof Player) { + BlockBag blockBag = getBlockBag((Player) actor); + builder.player((Player) actor); + builder.blockBag(blockBag); + } + builder.fastmode(fastMode); + + editSession = builder.build(); if (mask != null) { editSession.setMask(mask); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java index 48e3f8d66..4366fd8dc 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java @@ -41,7 +41,6 @@ import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.internal.annotation.Direction; import com.sk89q.worldedit.internal.command.CommandRegistrationHandler; import com.sk89q.worldedit.internal.expression.Expression; -import com.sk89q.worldedit.internal.expression.runtime.Constant; import com.sk89q.worldedit.regions.factory.RegionFactory; import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.formatting.text.TextComponent; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java index d9ba33c29..b1ce4974c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java @@ -132,7 +132,6 @@ import org.enginehub.piston.annotation.param.Arg; import org.enginehub.piston.annotation.param.ArgFlag; import org.enginehub.piston.annotation.param.Switch; import org.enginehub.piston.inject.InjectedValueAccess; -import org.enginehub.piston.inject.Key; /** * Commands to set brush shape. @@ -162,9 +161,9 @@ public class BrushCommands { @CommandPermissions("worldedit.brush.blendball") public void blendBallBrush(Player player, LocalSession session, @Arg(desc = "The radius to sample for blending", def = "5") - Expression radius, InjectedValueAccess context) throws WorldEditException { + Expression radius) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - set(session, context, new BlendBall()).setSize(radius); + set(player, session, new BlendBall()).setSize(radius); } @Command( @@ -174,9 +173,9 @@ public class BrushCommands { @CommandPermissions("worldedit.brush.erode") public void erodeBrush(Player player, LocalSession session, @Arg(desc = "The radius for eroding", def = "5") - Expression radius, InjectedValueAccess context) throws WorldEditException { + Expression radius) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - set(session, context, new ErodeBrush()).setSize(radius); + set(player, session, new ErodeBrush()).setSize(radius); } @Command( @@ -186,9 +185,9 @@ public class BrushCommands { @CommandPermissions("worldedit.brush.pull") public void pullBrush(Player player, LocalSession session, @Arg(desc = "The radius to sample for blending", def = "5") - Expression radius, InjectedValueAccess context) throws WorldEditException { + Expression radius) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - set(session, context, new RaiseBrush()).setSize(radius); + set(player, session, new RaiseBrush()).setSize(radius); } @Command( @@ -196,11 +195,12 @@ public class BrushCommands { desc = "Creates a circle which revolves around your facing direction" ) @CommandPermissions("worldedit.brush.sphere") - public void circleBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, + public void circleBrush(Player player, EditSession editSession, LocalSession session, + Pattern fill, @Arg(desc = "The radius to sample for blending", def = "5") - Expression radius, InjectedValueAccess context) throws WorldEditException { + Expression radius) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - set(session, context, new CircleBrush(player)).setSize(radius).setFill(fill); + set(player, session, new CircleBrush(player)).setSize(radius).setFill(fill); } @Command( @@ -211,14 +211,14 @@ public class BrushCommands { "Note: Set a mask to recurse along specific blocks" ) @CommandPermissions("worldedit.brush.recursive") - public void recursiveBrush(Player player, LocalSession session, EditSession editSession, Pattern fill, + public void recursiveBrush(Player player, LocalSession session, EditSession editSession, + Pattern fill, @Arg(desc = "The radius to sample for blending", def = "5") Expression radius, @Switch(name = 'd', desc = "Apply in depth first order") - boolean depthFirst, - InjectedValueAccess context) throws WorldEditException { + boolean depthFirst) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - set(session, context, new RecurseBrush(depthFirst)) + set(player, session, new RecurseBrush(depthFirst)) .setSize(radius).setFill(fill).setMask(new IdMask(editSession)); } @@ -236,9 +236,9 @@ public class BrushCommands { @Switch(name = 's', desc = "Selects the clicked point after drawing") boolean select, @Switch(name = 'f', desc = "Create a flat line") - boolean flat, InjectedValueAccess context) throws WorldEditException { + boolean flat) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - set(session, context, new LineBrush(shell, select, flat)).setSize(radius).setFill(fill); + set(player, session, new LineBrush(shell, select, flat)).setSize(radius).setFill(fill); } @Command( @@ -252,13 +252,14 @@ public class BrushCommands { "Tutorial: https://www.planetminecraft.com/blog/fawe-tutorial/" ) @CommandPermissions("worldedit.brush.spline") - public void splineBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, + public void splineBrush(Player player, EditSession editSession, LocalSession session, + Pattern fill, @Arg(desc = "The radius to sample for blending", def = "25") - Expression radius, InjectedValueAccess context) throws WorldEditException { + Expression radius) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); player.print(BBC.BRUSH_SPLINE.format(radius)); - set(session, context, - new SplineBrush(player, session)) + set(player, session, + new SplineBrush(player, session)) .setSize(radius) .setFill(fill); } @@ -272,9 +273,10 @@ public class BrushCommands { "Set [copies] to a value > 0 if you want to have your selection pasted a limited amount of times equally spaced on the curve" ) @CommandPermissions("worldedit.brush.sweep") - public void sweepBrush(Player player, LocalSession session, @Arg(name = "copies", desc = "int", def = "-1") int copies, InjectedValueAccess context) throws WorldEditException { + public void sweepBrush(Player player, LocalSession session, + @Arg(name = "copies", desc = "int", def = "-1") int copies) throws WorldEditException { player.print(BBC.BRUSH_SPLINE.s()); - set(session, context, new SweepBrush(copies)); + set(player, session, new SweepBrush(copies)); } @Command( @@ -283,7 +285,8 @@ public class BrushCommands { desc = "Create a hanging line between two points" ) @CommandPermissions("worldedit.brush.spline") - public void catenaryBrush(LocalSession session, Pattern fill, @Arg(def = "1.2", desc = "Length of wire compared to distance between points") @Range(min = 1) double lengthFactor, + public void catenaryBrush(Player player, LocalSession session, Pattern fill, + @Arg(def = "1.2", desc = "Length of wire compared to distance between points") @Range(min = 1) double lengthFactor, @Arg(desc = "The radius to sample for blending", def = "0") Expression radius, @Switch(name = 'h', desc = "Create only a shell") @@ -291,12 +294,11 @@ public class BrushCommands { @Switch(name = 's', desc = "Select the clicked point after drawing") boolean select, @Switch(name = 'd', desc = "sags the catenary toward the facing direction") - boolean facingDirection, - InjectedValueAccess context) throws WorldEditException { + boolean facingDirection) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); Brush brush = new CatenaryBrush(shell, select, facingDirection, lengthFactor); - set(session, context, - new CatenaryBrush(shell, select, facingDirection, lengthFactor)) + set(player, session, + new CatenaryBrush(shell, select, facingDirection, lengthFactor)) .setSize(radius) .setFill(fill); } @@ -311,11 +313,14 @@ public class BrushCommands { @CommandPermissions("worldedit.brush.surfacespline") // 0, 0, 0, 10, 0, public void surfaceSpline(Player player, LocalSession session, Pattern fill, @Arg(desc = "The radius to sample for blending", def = "0") - Expression radius, @Arg(name = "tension", desc = "double", def = "0") double tension, @Arg(name = "bias", desc = "double", def = "0") double bias, @Arg(name = "continuity", desc = "double", def = "0") double continuity, @Arg(name = "quality", desc = "double", def = "10") double quality, InjectedValueAccess context) throws WorldEditException { + Expression radius, @Arg(name = "tension", desc = "double", def = "0") double tension, + @Arg(name = "bias", desc = "double", def = "0") double bias, + @Arg(name = "continuity", desc = "double", def = "0") double continuity, + @Arg(name = "quality", desc = "double", def = "10") double quality) throws WorldEditException { player.print(BBC.BRUSH_SPLINE.format(radius)); worldEdit.checkMaxBrushRadius(radius); - set(session, context, - new SurfaceSpline(tension, bias, continuity, quality)) + set(player, session, + new SurfaceSpline(tension, bias, continuity, quality)) .setSize(radius) .setFill(fill); } @@ -326,11 +331,19 @@ public class BrushCommands { desc = "Creates a distorted sphere" ) @CommandPermissions("worldedit.brush.rock") - public void blobBrush(LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Vector3", def = "10") Vector3 radius, @Arg(name = "sphericity", desc = "double", def = "100") double sphericity, @Arg(name = "frequency", desc = "double", def = "30") double frequency, @Arg(name = "amplitude", desc = "double", def = "50") double amplitude, InjectedValueAccess context) throws WorldEditException { + public void blobBrush(Player player, LocalSession session, Pattern fill, + @Arg(name = "radius", desc = "Vector3", def = "10") + Vector3 radius, + @Arg(name = "sphericity", desc = "double", def = "100") + double sphericity, + @Arg(name = "frequency", desc = "double", def = "30") + double frequency, + @Arg(name = "amplitude", desc = "double", def = "50") + double amplitude) throws WorldEditException { double max = MathMan.max(radius.getX(), radius.getY(), radius.getZ()); worldEdit.checkMaxBrushRadius(max); Brush brush = new BlobBrush(radius.divide(max), frequency / 100, amplitude / 100, sphericity / 100); - set(session, context, brush).setSize(max).setFill(fill); + set(player, session, brush).setSize(max).setFill(fill); } @Command( @@ -347,7 +360,7 @@ public class BrushCommands { @Switch(name = 'h', desc = "Create hollow spheres instead") boolean hollow, @Switch(name = 'f', desc = "Create falling spheres instead") - boolean falling, InjectedValueAccess context) throws WorldEditException { + boolean falling) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); Brush brush; if (hollow) { @@ -369,10 +382,7 @@ public class BrushCommands { } } - set(session, context, - brush) - .setSize(radius) - .setFill(pattern); + set(player, session, brush).setSize(radius).setFill(pattern); } @Command( @@ -383,13 +393,14 @@ public class BrushCommands { "Pic: https://i.imgur.com/2xKsZf2.png" ) @CommandPermissions("worldedit.brush.shatter") - public void shatterBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, + public void shatterBrush(Player player, EditSession editSession, LocalSession session, + Pattern fill, @Arg(desc = "The radius to sample for blending", def = "10") - Expression radius, - @Arg(desc = "Lines", def = "10") int count, InjectedValueAccess context) throws WorldEditException { + Expression radius, + @Arg(desc = "Lines", def = "10") int count) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - set(session, context, - new ShatterBrush(count)) + set(player, session, + new ShatterBrush(count)) .setSize(radius) .setFill(fill) .setMask(new ExistingBlockMask(editSession)); @@ -402,13 +413,12 @@ public class BrushCommands { ) @CommandPermissions("worldedit.brush.stencil") public void stencilBrush(Player player, LocalSession session, Pattern fill, - @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, - @Arg(name = "image", desc = "String", def = "") String image, - @Arg(def = "0", desc = "rotation") @Range(min = 0, max = 360) int rotation, - @Arg(name = "yscale", desc = "double", def = "1") double yscale, - @Switch(name = 'w', desc = "Apply at maximum saturation") boolean onlyWhite, - @Switch(name = 'r', desc = "Apply random rotation") boolean randomRotate, - InjectedValueAccess context) throws WorldEditException, FileNotFoundException { + @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, + @Arg(name = "image", desc = "String", def = "") String image, + @Arg(def = "0", desc = "rotation") @Range(min = 0, max = 360) int rotation, + @Arg(name = "yscale", desc = "double", def = "1") double yscale, + @Switch(name = 'w', desc = "Apply at maximum saturation") boolean onlyWhite, + @Switch(name = 'r', desc = "Apply random rotation") boolean randomRotate) throws WorldEditException, FileNotFoundException { worldEdit.checkMaxBrushRadius(radius); InputStream stream = getHeightmapStream(image); HeightBrush brush; @@ -420,8 +430,8 @@ public class BrushCommands { if (randomRotate) { brush.setRandomRotate(true); } - set(session, context, - brush) + set(player, session, + brush) .setSize(radius) .setFill(fill); } @@ -432,12 +442,16 @@ public class BrushCommands { desc = "Use a height map to paint a surface", descFooter = "Use a height map to paint any surface.\n") @CommandPermissions("worldedit.brush.stencil") - public void imageBrush(LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, - ProvideBindings.ImageUri imageUri, - @Arg(def = "1", desc = "scale height") @Range(min = Double.MIN_NORMAL) double yscale, - @Switch(name = 'a', desc = "Use image Alpha") boolean alpha, - @Switch(name = 'f', desc = "Blend the image with existing terrain") boolean fadeOut, - InjectedValueAccess context) throws WorldEditException, IOException { + public void imageBrush(Player player, LocalSession session, + @Arg(name = "radius", desc = "Expression", def = "5") + Expression radius, + ProvideBindings.ImageUri imageUri, + @Arg(def = "1", desc = "scale height") @Range(min = Double.MIN_NORMAL) + double yscale, + @Switch(name = 'a', desc = "Use image Alpha") + boolean alpha, + @Switch(name = 'f', desc = "Blend the image with existing terrain") + boolean fadeOut) throws WorldEditException, IOException { BufferedImage image = imageUri.load(); worldEdit.checkMaxBrushRadius(radius); if (yscale != 1) { @@ -449,9 +463,7 @@ public class BrushCommands { alpha = true; } ImageBrush brush = new ImageBrush(image, session, alpha); - set(session, context, - brush) - .setSize(radius); + set(player, session, brush).setSize(radius); } @Command( @@ -463,12 +475,11 @@ public class BrushCommands { "The -r flag will apply random rotation" ) @CommandPermissions("worldedit.brush.surface") - public void surfaceBrush(LocalSession session, Pattern fill, + public void surfaceBrush(Player player, LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Expression", def = "5") - Expression radius, - InjectedValueAccess context) throws WorldEditException { + Expression radius) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - set(session, context, new SurfaceSphereBrush()).setFill(fill).setSize(radius); + set(player, session, new SurfaceSphereBrush()).setFill(fill).setSize(radius); } @Command( @@ -478,7 +489,11 @@ public class BrushCommands { "Video: https://youtu.be/RPZIaTbqoZw?t=34s" ) @CommandPermissions("worldedit.brush.scatter") - public void scatterBrush(LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "points", desc = "double", def = "5") double pointsOpt, @Arg(name = "distance", desc = "double", def = "1") double distanceOpt, @Switch(name = 'o', desc = "Overlay the block") boolean overlay, InjectedValueAccess context) throws WorldEditException { + public void scatterBrush(Player player, LocalSession session, Pattern fill, + @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, + @Arg(name = "points", desc = "double", def = "5") double pointsOpt, + @Arg(name = "distance", desc = "double", def = "1") double distanceOpt, + @Switch(name = 'o', desc = "Overlay the block") boolean overlay) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); Brush brush; if (overlay) { @@ -486,10 +501,7 @@ public class BrushCommands { } else { brush = new ScatterBrush((int) pointsOpt, (int) distanceOpt); } - set(session, context, - brush) - .setSize(radius) - .setFill(fill); + set(player, session, brush).setSize(radius).setFill(fill); } @Command( @@ -498,7 +510,11 @@ public class BrushCommands { desc = "Scatter a schematic on a surface" ) @CommandPermissions("worldedit.brush.populateschematic") - public void scatterSchemBrush(Player player, LocalSession session, Mask mask, @Arg(name = "clipboard", desc = "Clipboard uri") String clipboardStr, @Arg(name = "radius", desc = "Expression", def = "30") Expression radius, @Arg(name = "density", desc = "double", def = "50") double density, @Switch(name = 'r', desc = "Apply random rotation") boolean rotate, InjectedValueAccess context) throws WorldEditException { + public void scatterSchemBrush(Player player, LocalSession session, Mask mask, + @Arg(name = "clipboard", desc = "Clipboard uri") String clipboardStr, + @Arg(name = "radius", desc = "Expression", def = "30") Expression radius, + @Arg(name = "density", desc = "double", def = "50") double density, + @Switch(name = 'r', desc = "Apply random rotation") boolean rotate) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); try { MultiClipboardHolder clipboards = ClipboardFormats.loadAllFromInput(player, clipboardStr, null, true); @@ -512,8 +528,8 @@ public class BrushCommands { return; } - set(session, context, - new PopulateSchem(mask, holders, (int) density, rotate)).setSize(radius); + set(player, session, + new PopulateSchem(mask, holders, (int) density, rotate)).setSize(radius); } catch (IOException e) { throw new RuntimeException(e); } @@ -527,9 +543,10 @@ public class BrushCommands { "Pic: https://i.imgur.com/XV0vYoX.png" ) @CommandPermissions("worldedit.brush.layer") - public void surfaceLayer(LocalSession session, @Arg(name = "radius", desc = "Expression") Expression radius, List blockLayers, InjectedValueAccess context) throws WorldEditException { + public void surfaceLayer(Player player, LocalSession session, + @Arg(name = "radius", desc = "Expression") Expression radius, List blockLayers) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - set(session, context, new LayerBrush(blockLayers.toArray(new BlockState[0]))).setSize(radius); + set(player, session, new LayerBrush(blockLayers.toArray(new BlockState[0]))).setSize(radius); } @Command( @@ -541,9 +558,13 @@ public class BrushCommands { "Note: The seeds define how many splotches there are, recursion defines how large, solid defines whether the pattern is applied per seed, else per block." ) @CommandPermissions("worldedit.brush.splatter") - public void splatterBrush(LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "points", desc = "double", def = "1") double pointsOpt, @Arg(name = "recursion", desc = "double", def = "5") double recursion, @Arg(name = "solid", desc = "boolean", def = "true") boolean solid, InjectedValueAccess context) throws WorldEditException { + public void splatterBrush(Player player, LocalSession session, Pattern fill, + @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, + @Arg(name = "points", desc = "double", def = "1") double pointsOpt, + @Arg(name = "recursion", desc = "double", def = "5") double recursion, + @Arg(name = "solid", desc = "boolean", def = "true") boolean solid) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - set(session, context, new SplatterBrush((int) pointsOpt, (int) recursion, solid)).setSize(radius).setFill(fill); + set(player, session, new SplatterBrush((int) pointsOpt, (int) recursion, solid)).setSize(radius).setFill(fill); } @Command( @@ -557,10 +578,12 @@ public class BrushCommands { " - Placeholders: {x}, {y}, {z}, {world}, {size}" ) @CommandPermissions("worldedit.brush.scattercommand") - public void scatterCommandBrush(Player player, EditSession editSession, LocalSession session, @Arg(name = "radius", desc = "Expression") Expression radius, double points, double distance, List commandStr, InjectedValueAccess context) throws WorldEditException { + public void scatterCommandBrush(Player player, EditSession editSession, LocalSession session, + @Arg(name = "radius", desc = "Expression") Expression radius, double points, + double distance, List commandStr) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - set(session, context, - new ScatterCommand((int) points, (int) distance, StringMan.join(commandStr, " "))) + set(player, session, + new ScatterCommand((int) points, (int) distance, StringMan.join(commandStr, " "))) .setSize(radius); } @@ -578,19 +601,17 @@ public class BrushCommands { @Arg(desc = "The height of the cylinder", def = "1") int height, @Switch(name = 'h', desc = "Create hollow cylinders instead") - boolean hollow, - InjectedValueAccess context) throws WorldEditException { + boolean hollow) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(height); BrushSettings settings; if (hollow) { - settings = set(session, context, new HollowCylinderBrush(height)); + settings = set(player, session, new HollowCylinderBrush(height)); } else { - settings = set(session, context, new CylinderBrush(height)); + settings = set(player, session, new CylinderBrush(height)); } - settings.setSize(radius) - .setFill(pattern); + settings.setSize(radius).setFill(pattern); } @Command( @@ -603,20 +624,20 @@ public class BrushCommands { ) @Deprecated @CommandPermissions("worldedit.brush.clipboard") - public void clipboardBrush(Player player,LocalSession session, - @Switch(name = 'a', desc = "Don't paste air from the clipboard") - boolean ignoreAir, - @Switch(name = 'o', desc = "Paste starting at the target location, instead of centering on it") - boolean usingOrigin, - @Switch(name = 'e', desc = "Skip paste entities if available") - boolean skipEntities, - @Switch(name = 'b', desc = "Paste biomes if available") - boolean pasteBiomes, - @ArgFlag(name = 'm', desc = "Skip blocks matching this mask in the clipboard", def = "") - @ClipboardMask - Mask sourceMask, - InjectedValueAccess context) throws WorldEditException { + public void clipboardBrush(Player player, LocalSession session, + @Switch(name = 'a', desc = "Don't paste air from the clipboard") + boolean ignoreAir, + @Switch(name = 'o', desc = "Paste starting at the target location, instead of centering on it") + boolean usingOrigin, + @Switch(name = 'e', desc = "Skip paste entities if available") + boolean skipEntities, + @Switch(name = 'b', desc = "Paste biomes if available") + boolean pasteBiomes, + @ArgFlag(name = 'm', desc = "Skip blocks matching this mask in the clipboard", def = "") + @ClipboardMask + Mask sourceMask) throws WorldEditException { ClipboardHolder holder = session.getClipboard(); + Clipboard clipboard = holder.getClipboard(); ClipboardHolder newHolder = new ClipboardHolder(clipboard); newHolder.setTransform(holder.getTransform()); @@ -627,7 +648,8 @@ public class BrushCommands { worldEdit.checkMaxBrushRadius(size.getBlockY() / 2D - 1); worldEdit.checkMaxBrushRadius(size.getBlockZ() / 2D - 1); - set(session, context, new ClipboardBrush(newHolder, ignoreAir, usingOrigin, !skipEntities, pasteBiomes, sourceMask)); + set(player, session, + new ClipboardBrush(newHolder, ignoreAir, usingOrigin, !skipEntities, pasteBiomes, sourceMask)); } @Command( @@ -637,19 +659,19 @@ public class BrushCommands { ) @CommandPermissions("worldedit.brush.smooth") public void smoothBrush(Player player, LocalSession session, EditSession editSession, - @Arg(desc = "The radius to sample for softening", def = "2") - Expression radius, - @Arg(desc = "The number of iterations to perform", def = "4") - int iterations, - @Arg(desc = "The mask of blocks to use for the heightmap", def = "") - Mask maskOpt, InjectedValueAccess context) throws WorldEditException { + @Arg(desc = "The radius to sample for softening", def = "2") + Expression radius, + @Arg(desc = "The number of iterations to perform", def = "4") + int iterations, + @Arg(desc = "The mask of blocks to use for the heightmap", def = "") + Mask maskOpt) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); FaweLimit limit = Settings.IMP.getLimit(player); iterations = Math.min(limit.MAX_ITERATIONS, iterations); - set(session, context, - new SmoothBrush(iterations, maskOpt)) + set(player, session, + new SmoothBrush(iterations, maskOpt)) .setSize(radius); } @@ -660,16 +682,14 @@ public class BrushCommands { ) @CommandPermissions("worldedit.brush.ex") public void extinguishBrush(Player player, LocalSession session, EditSession editSession, - @Arg(desc = "The radius to extinguish", def = "5") - Expression radius, - InjectedValueAccess context) throws WorldEditException { + @Arg(desc = "The radius to extinguish", def = "5") + Expression radius) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - Pattern fill = BlockTypes.AIR.getDefaultState(); - set(session, context, - new SphereBrush()) + set(player, session, + new SphereBrush()) .setSize(radius) - .setFill(fill) + .setFill(BlockTypes.AIR.getDefaultState()) .setMask(new SingleBlockTypeMask(editSession, BlockTypes.FIRE)); } @@ -681,15 +701,12 @@ public class BrushCommands { @CommandPermissions("worldedit.brush.gravity") public void gravityBrush(Player player, LocalSession session, @Arg(desc = "The radius to apply gravity in", def = "5") - Expression radius, + Expression radius, @Switch(name = 'h', desc = "Affect blocks starting at max Y, rather than the target location Y + radius") - boolean fromMaxY, - InjectedValueAccess context) throws WorldEditException { + boolean fromMaxY) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - set(session, context, - new GravityBrush(fromMaxY)) - .setSize(radius); + set(player, session, new GravityBrush(fromMaxY)).setSize(radius); } @Command( @@ -705,7 +722,7 @@ public class BrushCommands { ) @CommandPermissions("worldedit.brush.height") public void heightBrush(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "image", desc = "String", def = "") String image, @Arg(def = "0", desc = "rotation") @Range(min = 0, max = 360) int rotation, @Arg(name = "yscale", desc = "double", def = "1") double yscale, @Switch(name = 'r', desc = "TODO") boolean randomRotate, @Switch(name = 'l', desc = "TODO") boolean layers, @Switch(name = 's', desc = "TODO") boolean dontSmooth, InjectedValueAccess context) throws WorldEditException, FileNotFoundException { - terrainBrush(player, session, radius, image, rotation, yscale, false, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CONE, context); + terrainBrush(player, session, radius, image, rotation, yscale, false, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CONE); } @Command( @@ -730,7 +747,7 @@ public class BrushCommands { boolean layers, @Switch(name = 's', desc = "Disables smoothing") boolean dontSmooth, InjectedValueAccess context) throws WorldEditException, FileNotFoundException { - terrainBrush(player, session, radius, image, rotation, yscale, true, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CYLINDER, context); + terrainBrush(player, session, radius, image, rotation, yscale, true, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CYLINDER); } @Command( @@ -746,10 +763,13 @@ public class BrushCommands { boolean layers, @Switch(name = 's', desc = "Disables smoothing") boolean dontSmooth, InjectedValueAccess context) throws WorldEditException, FileNotFoundException { - terrainBrush(player, session, radius, image, rotation, yscale, true, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CONE, context); + terrainBrush(player, session, radius, image, rotation, yscale, true, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CONE); } - private void terrainBrush(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression") Expression radius, String image, int rotation, double yscale, boolean flat, boolean randomRotate, boolean layers, boolean smooth, Shape shape, InjectedValueAccess context) throws WorldEditException, FileNotFoundException { + private void terrainBrush(Player player, LocalSession session, + @Arg(name = "radius", desc = "Expression") Expression radius, String image, int rotation, + double yscale, boolean flat, boolean randomRotate, boolean layers, boolean smooth, + Shape shape) throws WorldEditException, FileNotFoundException { worldEdit.checkMaxBrushRadius(radius); InputStream stream = getHeightmapStream(image); HeightBrush brush; @@ -769,7 +789,7 @@ public class BrushCommands { if (randomRotate) { brush.setRandomRotate(true); } - set(session, context, + set(player, session, brush) .setSize(radius); } @@ -794,12 +814,15 @@ public class BrushCommands { "Video: https://www.youtube.com/watch?v=RPZIaTbqoZw" ) @CommandPermissions("worldedit.brush.copy") - public void copy(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Switch(name = 'r', desc = "Apply random rotation on paste") boolean randomRotate, @Switch(name = 'a', desc = "Apply auto view based rotation on paste") boolean autoRotate, InjectedValueAccess context) throws WorldEditException { + public void copy(Player player, LocalSession session, + @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, + @Switch(name = 'r', desc = "Apply random rotation on paste") boolean randomRotate, + @Switch(name = 'a', desc = "Apply auto view based rotation on paste") boolean autoRotate) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); player.print(BBC.BRUSH_COPY.format(radius)); - set(session, context, - new CopyPastaBrush(player, session, randomRotate, autoRotate)) + set(player, session, + new CopyPastaBrush(player, session, randomRotate, autoRotate)) .setSize(radius); } @@ -812,11 +835,13 @@ public class BrushCommands { " - Placeholders: {x}, {y}, {z}, {world}, {size}" ) @CommandPermissions("worldedit.brush.command") - public void command(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression") Expression radius, @Arg(desc = "Command to run") List input, InjectedValueAccess context) throws WorldEditException { + public void command(Player player, LocalSession session, + @Arg(name = "radius", desc = "Expression") Expression radius, + @Arg(desc = "Command to run") List input) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); String cmd = StringMan.join(input, " "); - set(session, context, - new CommandBrush(cmd)) + set(player, session, + new CommandBrush(cmd)) .setSize(radius); } @@ -826,25 +851,25 @@ public class BrushCommands { desc = "Butcher brush, kills mobs within a radius" ) @CommandPermissions("worldedit.brush.butcher") - public void butcherBrush(Player player, LocalSession session, InjectedValueAccess context, - @Arg(desc = "Radius to kill mobs in", def = "5") - Expression radius, - @Switch(name = 'p', desc = "Also kill pets") - boolean killPets, - @Switch(name = 'n', desc = "Also kill NPCs") - boolean killNpcs, - @Switch(name = 'g', desc = "Also kill golems") - boolean killGolems, - @Switch(name = 'a', desc = "Also kill animals") - boolean killAnimals, - @Switch(name = 'b', desc = "Also kill ambient mobs") - boolean killAmbient, - @Switch(name = 't', desc = "Also kill mobs with name tags") - boolean killWithName, - @Switch(name = 'f', desc = "Also kill all friendly mobs (Applies the flags `-abgnpt`)") - boolean killFriendly, - @Switch(name = 'r', desc = "Also destroy armor stands") - boolean killArmorStands) throws WorldEditException { + public void butcherBrush(Player player, LocalSession session, + @Arg(desc = "Radius to kill mobs in", def = "5") + Expression radius, + @Switch(name = 'p', desc = "Also kill pets") + boolean killPets, + @Switch(name = 'n', desc = "Also kill NPCs") + boolean killNpcs, + @Switch(name = 'g', desc = "Also kill golems") + boolean killGolems, + @Switch(name = 'a', desc = "Also kill animals") + boolean killAnimals, + @Switch(name = 'b', desc = "Also kill ambient mobs") + boolean killAmbient, + @Switch(name = 't', desc = "Also kill mobs with name tags") + boolean killWithName, + @Switch(name = 'f', desc = "Also kill all friendly mobs (Applies the flags `-abgnpt`)") + boolean killFriendly, + @Switch(name = 'r', desc = "Also destroy armor stands") + boolean killArmorStands) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); CreatureButcher flags = new CreatureButcher(player); @@ -857,7 +882,7 @@ public class BrushCommands { flags.or(CreatureButcher.Flags.TAGGED , killWithName, "worldedit.butcher.tagged"); flags.or(CreatureButcher.Flags.ARMOR_STAND , killArmorStands, "worldedit.butcher.armorstands"); - set(session, context, new ButcherBrush(flags)).setSize(radius); + set(player, session, new ButcherBrush(flags)).setSize(radius); } public BrushSettings process(CommandLocals locals, BrushSettings settings) throws WorldEditException { @@ -873,11 +898,10 @@ public class BrushCommands { return null; } - public BrushSettings set(LocalSession session, InjectedValueAccess context, Brush brush) throws InvalidToolBindException { - Player plr = context.injectedValue(Key.of(Player.class)) - .orElseThrow(() -> new IllegalStateException("No player")); + public BrushSettings set(Player player, LocalSession session, + Brush brush) throws InvalidToolBindException { BrushSettings bs = new BrushSettings(); - BrushTool tool = session.getBrushTool(plr, false); + BrushTool tool = session.getBrushTool(player, false); if (tool != null) { BrushSettings currentContext = tool.getContext(); if (currentContext != null) { @@ -896,14 +920,14 @@ public class BrushCommands { ) @CommandPermissions("worldedit.brush.forest") public void forest(Player player, LocalSession localSession, - @Arg(desc = "The shape of the region") - RegionFactory shape, - @Arg(desc = "The size of the brush", def = "5") - Expression radius, - @Arg(desc = "The density of the brush", def = "20") - double density, - @Arg(desc = "The type of tree to use") - TreeGenerator.TreeType type) throws WorldEditException, EvaluationException { + @Arg(desc = "The shape of the region") + RegionFactory shape, + @Arg(desc = "The size of the brush", def = "5") + Expression radius, + @Arg(desc = "The density of the brush", def = "20") + double density, + @Arg(desc = "The type of tree to use") + TreeGenerator.TreeType type) throws WorldEditException, EvaluationException { setOperationBasedBrush(player, localSession, radius, new Paint(new TreeGeneratorFactory(type), density / 100), shape, "worldedit.brush.forest"); } @@ -931,7 +955,7 @@ public class BrushCommands { @Arg(desc = "The shape of the region") RegionFactory shape, @Arg(desc = "The size of the brush", def = "5") - Expression radius) throws WorldEditException, EvaluationException { + Expression radius) throws WorldEditException, EvaluationException { setOperationBasedBrush(player, localSession, radius, new Deform("y+=1"), shape, "worldedit.brush.lower"); } 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 810cf48d1..da9a6d69c 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 @@ -47,6 +47,7 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.World; import java.io.File; +import java.util.Objects; import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; import org.enginehub.piston.annotation.Command; @@ -93,45 +94,51 @@ public class HistoryCommands { return; } File folder = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HISTORY); - if (!folder.exists()) { - return; - } - for (File worldFolder : folder.listFiles()) { - if (!worldFolder.isDirectory()) { - continue; - } - String worldName = worldFolder.getName(); - World world = FaweAPI.getWorld(worldName); - if (world != null) { - for (File userFolder : worldFolder.listFiles()) { - if (!userFolder.isDirectory()) { - continue; - } - String userUUID = userFolder.getName(); - try { - UUID uuid = UUID.fromString(userUUID); - for (File historyFile : userFolder.listFiles()) { - String name = historyFile.getName(); - if (!name.endsWith(".bd")) { + if (folder.exists()) { + for (File worldFolder : Objects.requireNonNull(folder.listFiles())) { + if (worldFolder != null && worldFolder.isDirectory()) { + String worldName = worldFolder.getName(); + World world = FaweAPI.getWorld(worldName); + if (world != null) { + for (File userFolder : worldFolder.listFiles()) { + if (!userFolder.isDirectory()) { continue; } - RollbackOptimizedHistory rollback = new RollbackOptimizedHistory(world, uuid, Integer.parseInt(name.substring(0, name.length() - 3))); - DiskStorageHistory.DiskStorageSummary summary = rollback.summarize(RegionWrapper.GLOBAL(), false); - if (summary != null) { - rollback.setDimensions(BlockVector3.at(summary.minX, 0, summary.minZ), BlockVector3.at(summary.maxX, 255, summary.maxZ)); - rollback.setTime(historyFile.lastModified()); - RollbackDatabase db = DBHandler.IMP.getDatabase(world); - db.logEdit(rollback); - player.print("Logging: " + historyFile); + String userUUID = userFolder.getName(); + try { + UUID uuid = UUID.fromString(userUUID); + for (File historyFile : userFolder.listFiles()) { + String name = historyFile.getName(); + if (!name.endsWith(".bd")) { + continue; + } + RollbackOptimizedHistory rollback = new RollbackOptimizedHistory( + world, uuid, + Integer.parseInt( + name.substring(0, name.length() - 3))); + DiskStorageHistory.DiskStorageSummary summary = rollback + .summarize(RegionWrapper.GLOBAL(), false); + if (summary != null) { + rollback.setDimensions( + BlockVector3.at(summary.minX, 0, summary.minZ), + BlockVector3 + .at(summary.maxX, 255, summary.maxZ)); + rollback.setTime(historyFile.lastModified()); + RollbackDatabase db = DBHandler.IMP + .getDatabase(world); + db.logEdit(rollback); + player.print("Logging: " + historyFile); + } + } + } catch (IllegalArgumentException e) { + e.printStackTrace(); } } - } catch (IllegalArgumentException e) { - e.printStackTrace(); } } } + player.print("Done import!"); } - player.print("Done import!"); return; } String toParse = user.substring(1); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/FactoryConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/FactoryConverter.java index 8b5a56f0c..8e5b0d9e8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/FactoryConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/FactoryConverter.java @@ -110,6 +110,9 @@ public class FactoryConverter implements ArgumentConverter { parserContext.setWorld((World) extent); } parserContext.setExtent(new RequestExtent()); + } else if (session.hasWorldOverride()) { + parserContext.setWorld(session.getWorldOverride()); + parserContext.setExtent(new RequestExtent()); } parserContext.setSession(session); parserContext.setRestricted(true); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java index 58e432db1..040e3e4d2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java @@ -30,7 +30,7 @@ import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BaseBlock; /** * A mode that replaces one block. @@ -55,7 +55,7 @@ public class BlockReplacer implements DoubleActionBlockTool { try (EditSession editSession = session.createEditSession(player)) { try { BlockVector3 position = clicked.toVector().toBlockPoint(); - editSession.setBlock(position, pattern.apply(position)); + editSession.setBlock(position, pattern); } catch (MaxChangedBlocksException ignored) { } finally { session.remember(editSession); @@ -72,8 +72,7 @@ public class BlockReplacer implements DoubleActionBlockTool { @Override public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) { - EditSession editSession = session.createEditSession(player); - BlockState targetBlock = editSession.getBlock(clicked.toVector().toBlockPoint()); + BaseBlock targetBlock = player.getWorld().getFullBlock(clicked.toVector().toBlockPoint()); if (targetBlock != null) { pattern = targetBlock; 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 a05c0a020..fe1f9cca3 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 @@ -91,7 +91,6 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool } protected static int MAX_RANGE = 500; - protected static int DEFAULT_RANGE = 240; protected int range = -1; private VisualMode visualMode = VisualMode.NONE; private TargetMode targetMode = TargetMode.TARGET_BLOCK_RANGE; @@ -178,7 +177,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool if (targetMode != TargetMode.TARGET_BLOCK_RANGE) { map.put("target", targetMode); } - if (range != -1 && range != DEFAULT_RANGE) { + if (range != -1 && range != MAX_RANGE) { map.put("range", range); } if (targetOffset != 0) { @@ -312,7 +311,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool * @return the mask used to stop block traces */ public @Nullable Mask getTraceMask() { - return traceMask; + return this.traceMask; } /** @@ -409,7 +408,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool * @return the range of the brush in blocks */ public int getRange() { - return (range < 0) ? DEFAULT_RANGE : Math.min(range, MAX_RANGE); + return (range < 0) ? MAX_RANGE : Math.min(range, MAX_RANGE); } /** @@ -418,16 +417,12 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool * @param range the range of the brush in blocks */ public void setRange(int range) { - if (range == DEFAULT_RANGE) { - this.range = -1; - } else { - this.range = range; - } + this.range = range; } @Override public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session) { - return act(BrushAction.PRIMARY, server, config, player, session); + return act(BrushAction.PRIMARY, player, session); } public BlockVector3 getPosition(EditSession editSession, Player player) { @@ -481,7 +476,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool }); } - public boolean act(BrushAction action, Platform server, LocalConfiguration config, Player player, LocalSession session) { + public boolean act(BrushAction action, Player player, LocalSession session) { switch (action) { case PRIMARY: setContext(primary); @@ -499,14 +494,14 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool return false; } try (EditSession editSession = session.createEditSession(player)) { - BlockVector3 target = getPosition(editSession, player); + Location target = player.getBlockTrace(getRange(), true, traceMask); if (target == null) { editSession.cancel(); - BBC.NO_BLOCK.send(player); + player.print(BBC.NO_BLOCK.s()); return true; } - BlockBag bag = editSession.getBlockBag(); + BlockBag bag = session.getBlockBag(player); Request.request().setEditSession(editSession); Mask mask = current.getMask(); @@ -536,7 +531,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool new PatternTraverser(current).reset(editSession); double size = current.getSize(); WorldEdit.getInstance().checkMaxBrushRadius(size); - brush.build(editSession, target, current.getMaterial(), size); + brush.build(editSession, target.toBlockPoint(), current.getMaterial(), size); } catch (MaxChangedBlocksException e) { player.printError("Max blocks change limit reached."); } finally { @@ -554,7 +549,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool @Override public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session) { - return act(BrushAction.SECONDARY, server, config, player, session); + return act(BrushAction.SECONDARY, player, session); } @@ -627,8 +622,8 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool return false; } - public void queueVisualization(Player fp) { - Fawe.get().getVisualQueue().queue(fp); + public void queueVisualization(Player player) { + Fawe.get().getVisualQueue().queue(player); } @Deprecated diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/NavigationWand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/NavigationWand.java index 24b8990df..ca4d12745 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/NavigationWand.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/NavigationWand.java @@ -27,42 +27,42 @@ import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.util.Location; public class NavigationWand implements DoubleActionTraceTool { - @Override - public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session) { - if (!player.hasPermission("worldedit.navigation.jumpto.tool")) { - return false; - } - final int maxDist = config.navigationWandMaxDistance; - if (maxDist <= 0) { - return false; - } - Location pos = player.getSolidBlockTrace(maxDist); - if (pos != null) { - player.findFreePosition(pos); - } else { - player.printError("No block in sight (or too far)!"); - } - return true; - } - - @Override - public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session) { - if (!player.hasPermission("worldedit.navigation.thru.tool")) { - return false; - } - final int maxDist = config.navigationWandMaxDistance; - if (maxDist <= 0) { - return false; + @Override + public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session) { + if (!player.hasPermission("worldedit.navigation.jumpto.tool")) { + return false; + } + final int maxDist = config.navigationWandMaxDistance; + if (maxDist <= 0) { + return false; + } + Location pos = player.getSolidBlockTrace(maxDist); + if (pos != null) { + player.findFreePosition(pos); + } else { + player.printError("No block in sight (or too far)!"); + } + return true; } - if (!player.passThroughForwardWall(Math.max(1, maxDist - 10))) { - player.printError("Nothing to pass through (or too far)!"); - } - return true; - } + @Override + public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session) { + if (!player.hasPermission("worldedit.navigation.thru.tool")) { + return false; + } + final int maxDist = config.navigationWandMaxDistance; + if (maxDist <= 0) { + return false; + } - @Override - public boolean canUse(Actor actor) { - return true; // skip check here - checked separately for primary/secondary - } + if (!player.passThroughForwardWall(Math.max(1, maxDist - 10))) { + player.printError("Nothing to pass through (or too far)!"); + } + return true; + } + + @Override + public boolean canUse(Actor actor) { + return true; // skip check here - checked separately for primary/secondary + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java index 469de149b..1bad0a30d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java @@ -55,7 +55,7 @@ public class QueryTool implements BlockTool { builder.append(TextComponent.of("@" + clicked.toVector().toBlockPoint() + ": ", TextColor.BLUE)); builder.append(TextComponent.of(block.getBlockType().getName(), TextColor.YELLOW)); builder.append(TextComponent.of(" (" + block + ") ", TextColor.GRAY) - .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Block state")))); + .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Block state")))); /* final OptionalInt internalId = BlockStateIdAccess.getBlockStateId(block.toImmutableState()); if (internalId.isPresent()) { @@ -64,8 +64,8 @@ public class QueryTool implements BlockTool { } */ builder.append(TextComponent.of(" (" + world.getBlockLightLevel(blockPoint) + "/" - + world.getBlockLightLevel(blockPoint.add(0, 1, 0)) + ")", TextColor.WHITE) - .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Block Light/Light Above")))); + + world.getBlockLightLevel(blockPoint.add(0, 1, 0)) + ")", TextColor.WHITE) + .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Block Light/Light Above")))); player.print(builder.build()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java index 35aaa785c..ca4b65c26 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java @@ -20,11 +20,9 @@ package com.sk89q.worldedit.command.tool; import com.boydti.fawe.object.mask.IdMask; - import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; @@ -37,8 +35,6 @@ import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; -import java.util.Set; - /** * A pickaxe mode that recursively finds adjacent blocks within range of * an initial block and of the same type. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/SelectionWand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/SelectionWand.java index 43b5f1ea0..fcc83209c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/SelectionWand.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/SelectionWand.java @@ -34,8 +34,8 @@ public class SelectionWand implements DoubleActionBlockTool { @Override public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) { RegionSelector selector = session.getRegionSelector(player.getWorld()); - BlockVector3 blockPoint = clicked.toVector().toBlockPoint(); + if (selector.selectPrimary(blockPoint, ActorSelectorLimits.forActor(player))) { selector.explainPrimarySelection(player, session, blockPoint); } @@ -46,6 +46,7 @@ public class SelectionWand implements DoubleActionBlockTool { public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) { RegionSelector selector = session.getRegionSelector(player.getWorld()); BlockVector3 blockPoint = clicked.toVector().toBlockPoint(); + if (selector.selectSecondary(blockPoint, ActorSelectorLimits.forActor(player))) { selector.explainSecondarySelection(player, session, blockPoint); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java index d4bc048b3..905d45465 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java @@ -64,10 +64,10 @@ public class TreePlanter implements BlockTool { } if (!successful) { - BBC.TOOL_TREE_ERROR_BLOCK.send(player); + player.printError(BBC.TOOL_TREE_ERROR_BLOCK.s()); } } catch (MaxChangedBlocksException e) { - BBC.WORLDEDIT_CANCEL_REASON_MAX_CHANGES.send(player); + player.printError(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHANGES.s()); } finally { session.remember(editSession); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java index be47971b7..4cbef5503 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java @@ -21,7 +21,6 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockTypes; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java index 42a300048..c4170d00e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java @@ -21,7 +21,6 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockTypes; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/SuggestionHelper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/SuggestionHelper.java index 7d0be8e9a..268b2cd3d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/SuggestionHelper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/SuggestionHelper.java @@ -19,6 +19,9 @@ package com.sk89q.worldedit.command.util; +import static org.enginehub.piston.converter.SuggestionHelper.byPrefix; +import static org.enginehub.piston.converter.SuggestionHelper.limitByPrefix; + import com.sk89q.worldedit.registry.Keyed; import com.sk89q.worldedit.registry.NamespacedRegistry; import com.sk89q.worldedit.registry.Registry; @@ -26,7 +29,6 @@ import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.world.block.BlockCategory; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; - import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -37,9 +39,6 @@ import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; -import static org.enginehub.piston.converter.SuggestionHelper.byPrefix; -import static org.enginehub.piston.converter.SuggestionHelper.limitByPrefix; - /** * Internal class for generating common command suggestions. */ @@ -140,12 +139,12 @@ public final class SuggestionHelper { public static Stream getRegistrySuggestions(Registry registry, String input) { if (registry instanceof NamespacedRegistry) { - return getNamespacedRegistrySuggestions(((NamespacedRegistry) registry), input); + return getNamespacedRegistrySuggestions(((NamespacedRegistry) registry), input); } return limitByPrefix(registry.keySet().stream(), input).stream(); } - public static Stream getNamespacedRegistrySuggestions(NamespacedRegistry registry, String input) { + public static Stream getNamespacedRegistrySuggestions(NamespacedRegistry registry, String input) { if (input.isEmpty() || input.equals(":")) { final Set namespaces = registry.getKnownNamespaces(); if (namespaces.size() == 1) { 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 0589513fe..99264b712 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 @@ -60,7 +60,9 @@ import com.sk89q.worldedit.world.block.FuzzyBlockState; import com.sk89q.worldedit.world.registry.LegacyMapper; import java.util.Arrays; +import java.util.HashMap; import java.util.Locale; +import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -73,10 +75,10 @@ public class DefaultBlockParser extends InputParser { super(worldEdit); } - private static BlockState getBlockInHand(Actor actor, HandSide handSide) throws InputParseException { + private static BaseBlock getBlockInHand(Actor actor, HandSide handSide) throws InputParseException { if (actor instanceof Player) { try { - return ((Player) actor).getBlockInHand(handSide).toImmutableState(); + return ((Player) actor).getBlockInHand(handSide); } catch (NotABlockException e) { throw new InputParseException("You're not holding a block!"); } catch (WorldEditException e) { @@ -111,6 +113,8 @@ public class DefaultBlockParser extends InputParser { } } + private static String[] EMPTY_STRING_ARRAY = {}; + /** * Backwards compatibility for wool colours in block syntax. * @@ -163,7 +167,9 @@ public class DefaultBlockParser extends InputParser { } private BaseBlock parseLogic(String input, ParserContext context) throws InputParseException { - String[] blockAndExtraData = input.trim().split("\\|", 2); + BlockType blockType = null; + Map, Object> blockStates = new HashMap<>(); + String[] blockAndExtraData = input.trim().split("\\|"); blockAndExtraData[0] = woolMapper(blockAndExtraData[0]); BlockState state = null; @@ -171,8 +177,10 @@ public class DefaultBlockParser extends InputParser { // Legacy matcher if (context.isTryingLegacy()) { try { - String[] split = blockAndExtraData[0].split(":"); - if (split.length == 1) { + String[] split = blockAndExtraData[0].split(":", 2); + if (split.length == 0) { + throw new InputParseException("Invalid colon."); + } else if (split.length == 1) { state = LegacyMapper.getInstance().getBlockFromLegacy(Integer.parseInt(split[0])); } else if (MathMan.isInteger(split[0])) { int id = Integer.parseInt(split[0]); @@ -191,7 +199,7 @@ public class DefaultBlockParser extends InputParser { state = LegacyMapper.getInstance().getBlockFromLegacy(type.getLegacyCombinedId() >> 4, data); } } - } catch (NumberFormatException e) { + } catch (NumberFormatException ignored) { } } @@ -204,58 +212,83 @@ public class DefaultBlockParser extends InputParser { typeString = blockAndExtraData[0]; } else { typeString = blockAndExtraData[0].substring(0, stateStart); + if (stateStart + 1 >= blockAndExtraData[0].length()) { + throw new InputParseException("Invalid format. Hanging bracket @ " + stateStart + "."); + } + int stateEnd = blockAndExtraData[0].lastIndexOf(']'); + if (stateEnd < 0) { + throw new InputParseException("Invalid format. Unclosed property."); + } stateString = blockAndExtraData[0].substring(stateStart + 1, blockAndExtraData[0].length() - 1); } if (typeString.isEmpty()) { throw new InputParseException("Invalid format"); } - // PosX - if (typeString.matches("pos[0-9]+")) { + String[] stateProperties = EMPTY_STRING_ARRAY; + if (stateString != null) { + stateProperties = stateString.split(","); + } + + if ("hand".equalsIgnoreCase(typeString)) { + // Get the block type from the item in the user's hand. + final BaseBlock blockInHand = getBlockInHand(context.requireActor(), HandSide.MAIN_HAND); + if (blockInHand.getClass() != BaseBlock.class) { + return blockInHand; + } + + blockType = blockInHand.getBlockType(); + blockStates.putAll(blockInHand.getStates()); + } else if ("offhand".equalsIgnoreCase(typeString)) { + // Get the block type from the item in the user's off hand. + final BaseBlock blockInHand = getBlockInHand(context.requireActor(), HandSide.OFF_HAND); + if (blockInHand.getClass() != BaseBlock.class) { + return blockInHand; + } + + blockType = blockInHand.getBlockType(); + blockStates.putAll(blockInHand.getStates()); + } else if (typeString.matches("pos[0-9]+")) { int index = Integer.parseInt(typeString.replaceAll("[a-z]+", "")); // Get the block type from the "primary position" final World world = context.requireWorld(); final BlockVector3 primaryPosition; try { - primaryPosition = context.requireSession().getRegionSelector(world).getVertices().get(index - 1); + primaryPosition = context.requireSession().getRegionSelector(world).getPrimaryPosition(); } catch (IncompleteRegionException e) { throw new InputParseException("Your selection is not complete."); } - state = world.getBlock(primaryPosition); + final BlockState blockInHand = world.getBlock(primaryPosition); + + blockType = blockInHand.getBlockType(); + blockStates.putAll(blockInHand.getStates()); + } else if (typeString.matches("slot[0-9]+")) { + int slot = Integer.parseInt(typeString.substring(4)) - 1; + Actor actor = context.requireActor(); + if (!(actor instanceof Player)) { + throw new InputParseException("The user is not a player!"); + } + Player player = (Player) actor; + BlockBag bag = player.getInventoryBlockBag(); + if (true) { + throw new InputParseException("Unsupported!"); + } + SlottableBlockBag slottable = (SlottableBlockBag) bag; + BaseItem item = slottable.getItem(slot); + + if (!item.getType().hasBlockType()) { + throw new InputParseException("You're not holding a block!"); + } + state = item.getType().getBlockType().getDefaultState(); + nbt = item.getNbtData(); } else { - if ("hand".equalsIgnoreCase(typeString)) { - // Get the block type from the item in the user's hand. - state = getBlockInHand(context.requireActor(), HandSide.MAIN_HAND); - } else if ("offhand".equalsIgnoreCase(typeString)) { - // Get the block type from the item in the user's off hand. - state = getBlockInHand(context.requireActor(), HandSide.OFF_HAND); - } else if (typeString.matches("slot[0-9]+")) { - int slot = Integer.parseInt(typeString.substring(4)) - 1; - Actor actor = context.requireActor(); - if (!(actor instanceof Player)) { - throw new InputParseException("The user is not a player!"); - } - Player player = (Player) actor; - BlockBag bag = player.getInventoryBlockBag(); - if (bag == null || !(bag instanceof SlottableBlockBag)) { - throw new InputParseException("Unsupported!"); - } - SlottableBlockBag slottable = (SlottableBlockBag) bag; - BaseItem item = slottable.getItem(slot); + BlockType type = BlockTypes.parse(typeString.toLowerCase(Locale.ROOT)); - if (!item.getType().hasBlockType()) { - throw new InputParseException("You're not holding a block!"); - } - state = item.getType().getBlockType().getDefaultState(); - nbt = item.getNbtData(); - } else { - BlockType type = BlockTypes.parse(typeString.toLowerCase(Locale.ROOT)); - - if (type != null) { - state = type.getDefaultState(); - } - if (state == null) { - throw new NoMatchException("Does not match a valid block type: '" + input + "'"); - } + if (type != null) { + state = type.getDefaultState(); + } + if (state == null) { + throw new NoMatchException( + "Does not match a valid block type: '" + input + "'"); } } if (nbt == null) nbt = state.getNbtData(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlockCategoryMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlockCategoryMaskParser.java index 5001d2c38..5fa9033b2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlockCategoryMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlockCategoryMaskParser.java @@ -26,7 +26,6 @@ import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.function.mask.BlockCategoryMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.internal.registry.InputParser; -import com.sk89q.worldedit.session.request.RequestExtent; import com.sk89q.worldedit.world.block.BlockCategory; import java.util.Locale; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlocksMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlocksMaskParser.java index 1a8b6e0b7..c4208dd94 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlocksMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlocksMaskParser.java @@ -26,7 +26,6 @@ import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.function.mask.BlockMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.internal.registry.InputParser; -import com.sk89q.worldedit.session.request.RequestExtent; import com.sk89q.worldedit.world.block.BaseBlock; import java.util.Set; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/OutputExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/OutputExtent.java index 41b2d1b46..6e60a7e9c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/OutputExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/OutputExtent.java @@ -24,8 +24,6 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.math.MutableBlockVector2; -import com.sk89q.worldedit.math.MutableBlockVector3; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -52,16 +50,12 @@ public interface OutputExtent { * @param block block to set * @return true if the block was successfully set (return value may not be accurate) * @throws WorldEditException thrown on an error - * @deprecated Use {@link #setBlock(int, int, int, BlockStateHolder)} + * @deprecated It is recommended that you use {@link #setBlock(int, int, int, BlockStateHolder)} in FAWE */ @Deprecated - default > boolean setBlock(BlockVector3 position, T block) throws WorldEditException { - return setBlock(position.getX(), position.getY(), position.getZ(), block); - } + > boolean setBlock(BlockVector3 position, T block) throws WorldEditException; - default > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { - return setBlock(MutableBlockVector3.get(x, y, z), block); - } + > boolean setBlock(int x, int y, int z, T block) throws WorldEditException; boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException; @@ -72,13 +66,9 @@ public interface OutputExtent { * @param biome the biome to set to * @return true if the biome was successfully set (return value may not be accurate) */ - default boolean setBiome(BlockVector2 position, BiomeType biome) { - return setBiome(position.getX(), 0, position.getBlockZ(), biome); - } + boolean setBiome(BlockVector2 position, BiomeType biome); - default boolean setBiome(int x, int y, int z, BiomeType biome) { - return setBiome(MutableBlockVector2.get(x, z), biome); - } + boolean setBiome(int x, int y, int z, BiomeType biome); /** * Return an {@link Operation} that should be called to tie up loose ends diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/PassthroughExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/PassthroughExtent.java index 7f4523005..3766e00b7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/PassthroughExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/PassthroughExtent.java @@ -175,6 +175,7 @@ public class PassthroughExtent extends AbstractDelegateExtent { return getExtent().getBlockDistributionWithData(region); } + @Override @Nullable public Operation commit() { return getExtent().commit(); @@ -271,6 +272,7 @@ public class PassthroughExtent extends AbstractDelegateExtent { return getExtent().setBlock(position, block); } + @Override public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { return getExtent().setBlock(x, y, z, block); } @@ -285,6 +287,7 @@ public class PassthroughExtent extends AbstractDelegateExtent { return getExtent().setBiome(position, biome); } + @Override public boolean setBiome(int x, int y, int z, BiomeType biome) { return getExtent().setBiome(x, y, z, biome); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ForgetfulExtentBuffer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ForgetfulExtentBuffer.java index 274e7d03d..2dfff0aef 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ForgetfulExtentBuffer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ForgetfulExtentBuffer.java @@ -25,16 +25,20 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.function.mask.Masks; +import com.sk89q.worldedit.function.pattern.BiomePattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.AbstractRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionOperationException; +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.BlockTypes; - import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; @@ -46,12 +50,16 @@ import java.util.Map; *

This buffer will not attempt to return results from the buffer when * accessor methods (such as {@link #getBlock(BlockVector3)}) are called.

*/ -public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pattern { +public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pattern, BiomePattern { private final Map buffer = new LinkedHashMap<>(); + private final Map biomeBuffer = new LinkedHashMap<>(); private final Mask mask; + private final Mask2D biomeMask; private BlockVector3 min = null; + private BlockVector2 min2d = null; private BlockVector3 max = null; + private BlockVector2 max2d = null; /** * Create a new extent buffer that will buffer every change. @@ -79,6 +87,8 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat checkNotNull(delegate); checkNotNull(mask); this.mask = mask; + Mask2D bmask = mask.toMask2D(); + this.biomeMask = bmask == null ? Masks.alwaysTrue2D() : bmask; } @Override @@ -105,6 +115,54 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat } } + @Override + public boolean setBiome(BlockVector2 position, BiomeType biome) { + // Update minimum + if (min2d == null) { + min2d = position; + } else { + min2d = min2d.getMinimum(position); + } + + // Update maximum + if (max2d == null) { + max2d = position; + } else { + max2d = max2d.getMaximum(position); + } + + if (biomeMask.test(position)) { + biomeBuffer.put(position, biome); + return true; + } else { + return getExtent().setBiome(position, biome); + } + } + + @Override + public boolean setBiome(int x, int y, int z, BiomeType biome) { + // Update minimum + if (min2d == null) { + min2d = BlockVector2.at(x, z); + } else { + min2d = min2d.getMinimum(BlockVector2.at(x,z)); + } + + // Update maximum + if (max2d == null) { + max2d = BlockVector2.at(x,z); + } else { + max2d = max2d.getMaximum(BlockVector2.at(x,z)); + } + + if (biomeMask.test(BlockVector2.at(x,z))) { + biomeBuffer.put(BlockVector2.at(x,z), biome); + return true; + } else { + return getExtent().setBiome(x, y, z, biome); + } } + + @Override public BaseBlock apply(BlockVector3 pos) { BaseBlock block = buffer.get(pos); @@ -115,6 +173,16 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat } } + @Override + public BiomeType apply(BlockVector2 pos) { + BiomeType biome = biomeBuffer.get(pos); + if (biome != null) { + return biome; + } else { + return BiomeTypes.OCEAN; + } + } + /** * Return a region representation of this buffer. * @@ -151,6 +219,10 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat public Iterator iterator() { return buffer.keySet().iterator(); } + + public Iterable asFlatRegion() { + return biomeBuffer.keySet(); + } }; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java index 22369ec10..2c5c42fbe 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java @@ -216,6 +216,7 @@ public class BlockArrayClipboard implements Clipboard, Closeable { return false; } + @Override public boolean setTile(int x, int y, int z, CompoundTag tag) { x -= mx; y -= my; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java index cdffa1aa3..e79c0ade6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java @@ -19,10 +19,27 @@ package com.sk89q.worldedit.extent.transform; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.sk89q.worldedit.util.Direction.ASCENDING_EAST; +import static com.sk89q.worldedit.util.Direction.ASCENDING_NORTH; +import static com.sk89q.worldedit.util.Direction.ASCENDING_SOUTH; +import static com.sk89q.worldedit.util.Direction.ASCENDING_WEST; +import static com.sk89q.worldedit.util.Direction.DOWN; +import static com.sk89q.worldedit.util.Direction.EAST; +import static com.sk89q.worldedit.util.Direction.Flag; +import static com.sk89q.worldedit.util.Direction.NORTH; +import static com.sk89q.worldedit.util.Direction.NORTHEAST; +import static com.sk89q.worldedit.util.Direction.NORTHWEST; +import static com.sk89q.worldedit.util.Direction.SOUTH; +import static com.sk89q.worldedit.util.Direction.SOUTHEAST; +import static com.sk89q.worldedit.util.Direction.SOUTHWEST; +import static com.sk89q.worldedit.util.Direction.UP; +import static com.sk89q.worldedit.util.Direction.WEST; +import static com.sk89q.worldedit.util.Direction.findClosest; +import static com.sk89q.worldedit.util.Direction.values; + import com.boydti.fawe.object.extent.ResettableExtent; import com.boydti.fawe.util.ReflectionUtils; - -import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.jnbt.ByteTag; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.Tag; @@ -38,21 +55,19 @@ import com.sk89q.worldedit.registry.state.DirectionalProperty; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.PropertyKey; import com.sk89q.worldedit.util.Direction; -import static com.sk89q.worldedit.util.Direction.*; 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 org.jetbrains.annotations.NotNull; - -import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Locale; import java.util.Map; +import javax.annotation.Nullable; +import org.jetbrains.annotations.NotNull; /** * Transforms blocks themselves (but not their position) according to a @@ -87,11 +102,8 @@ public class BlockTransformExtent extends ResettableExtent { private static long combine(Direction... directions) { - long mask = 0; - for (Direction dir : directions) { - mask = mask | (1L << dir.ordinal()); - } - return mask; + return Arrays.stream(directions).mapToLong(dir -> (1L << dir.ordinal())) + .reduce(0, (a, b) -> a | b); } private static long[] adapt(Direction... dirs) { @@ -497,7 +509,7 @@ public class BlockTransformExtent extends ResettableExtent { } @Override - public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { return super.setBlock(x, y, z, transformInverse(block)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/CombinedRegionFunction.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/CombinedRegionFunction.java index f6f24051f..3ea4c642e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/CombinedRegionFunction.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/CombinedRegionFunction.java @@ -23,11 +23,9 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.math.BlockVector3; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.List; /** * Executes several region functions in order. @@ -49,7 +47,7 @@ public class CombinedRegionFunction implements RegionFunction { */ public CombinedRegionFunction(Collection functions) { checkNotNull(functions); - this.functions = functions.toArray(new RegionFunction[functions.size()]); + this.functions = functions.toArray(new RegionFunction[0]); } /** @@ -84,7 +82,7 @@ public class CombinedRegionFunction implements RegionFunction { checkNotNull(functions); ArrayList functionsList = new ArrayList<>(Arrays.asList(this.functions)); functionsList.addAll(functions); - this.functions = functionsList.toArray(new RegionFunction[functionsList.size()]); + this.functions = functionsList.toArray(new RegionFunction[0]); } /** @@ -105,4 +103,4 @@ public class CombinedRegionFunction implements RegionFunction { return ret; } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionFunction.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionFunction.java index 25f5f22d7..332565e35 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionFunction.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionFunction.java @@ -35,4 +35,5 @@ public interface RegionFunction { * @throws WorldEditException thrown on an error */ boolean apply(BlockVector3 position) throws WorldEditException; + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/biome/BiomeReplace.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/biome/BiomeReplace.java index efa53f45a..9b98bd48d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/biome/BiomeReplace.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/biome/BiomeReplace.java @@ -24,6 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.FlatRegionFunction; +import com.sk89q.worldedit.function.pattern.BiomePattern; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.world.biome.BiomeType; @@ -33,7 +34,7 @@ import com.sk89q.worldedit.world.biome.BiomeType; public class BiomeReplace implements FlatRegionFunction { private final Extent extent; - private BiomeType biome; + private BiomePattern biome; /** * Create a new instance. @@ -42,15 +43,25 @@ public class BiomeReplace implements FlatRegionFunction { * @param biome a biome */ public BiomeReplace(Extent extent, BiomeType biome) { + this(extent, (BiomePattern) biome); + } + + /** + * Create a new instance. + * + * @param extent the extent to apply this function to + * @param pattern the biome pattern to set + */ + public BiomeReplace(Extent extent, BiomePattern pattern) { checkNotNull(extent); - checkNotNull(biome); + checkNotNull(pattern); this.extent = extent; - this.biome = biome; + this.biome = pattern; } @Override public boolean apply(BlockVector2 position) throws WorldEditException { - return extent.setBiome(position, biome); + return extent.setBiome(position, biome.apply(position)); } } 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/block/Naturalizer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/Naturalizer.java index 929863bc5..2242e83a7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/Naturalizer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/Naturalizer.java @@ -80,7 +80,14 @@ public class Naturalizer implements LayerFunction { } private boolean naturalize(BlockVector3 position, int depth) throws WorldEditException { - return editSession.setBlock(position, getTargetBlock(depth)); + BlockState block = editSession.getBlock(position); + BlockState targetBlock = getTargetBlock(depth); + + if (block.equalsFuzzy(targetBlock)) { + return false; + } + + return editSession.setBlock(position, targetBlock); } @Override 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 ae028db56..2ce4e64e4 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 @@ -157,10 +157,10 @@ public class ExtentEntityCopy implements EntityFunction { 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() + .putInt("X", newLeash.getBlockX()) + .putInt("Y", newLeash.getBlockY()) + .putInt("Z", newLeash.getBlockZ()) + .build() ).build()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java index e45acd24b..4510c2432 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java @@ -53,7 +53,7 @@ public class ForestGenerator implements RegionFunction { BlockState block = editSession.getBlock(position); BlockType t = block.getBlockType(); - if (t == BlockTypes.GRASS_BLOCK || t == BlockTypes.DIRT) { + if (t == BlockTypes.GRASS_BLOCK || t == BlockTypes.DIRT || t == BlockTypes.PODZOL || t == BlockTypes.COARSE_DIRT) { return treeType.generate(editSession, position.add(0, 1, 0)); } else if (t.getMaterial().isReplacedDuringPlacement()) { // since the implementation's tree generators generally don't generate in non-air spots, 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 bb6923e24..302c2ed7a 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 @@ -69,6 +69,7 @@ public class BlockMask extends ABlockMask { @Deprecated public BlockMask(Extent extent, Collection blocks) { this(extent); + checkNotNull(blocks); add(blocks); } @@ -149,9 +150,8 @@ public class BlockMask extends ABlockMask { */ @Deprecated public void add(Collection blocks) { - for (BaseBlock block : blocks) { - add(block.toBlockState()); - } + checkNotNull(blocks); + blocks.forEach(baseBlock -> add(baseBlock.toBlockState())); } /** @@ -235,7 +235,7 @@ public class BlockMask extends ABlockMask { setType = type; setStates += all.size(); setState = type.getDefaultState(); - } else if (hasAny) { + } else { for (BlockState state : all) { if (test(state)) { setStates++; @@ -244,8 +244,6 @@ public class BlockMask extends ABlockMask { unsetState = state; } } - } else { - unsetType = type; } } } @@ -269,11 +267,7 @@ public class BlockMask extends ABlockMask { } if (setTypes == totalTypes - 1) { - if (unsetType != null) { - return new InverseSingleBlockTypeMask(getExtent(), unsetType); - } else { - throw new IllegalArgumentException("unsetType cannot be null when passed to InverseSingleBlockTypeMask"); - } + throw new IllegalArgumentException("unsetType cannot be null when passed to InverseSingleBlockTypeMask"); } 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 364cb4cfe..108fcbe76 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 @@ -55,4 +55,5 @@ public class BoundedHeightMask extends AbstractMask { 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 9c10590d9..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 @@ -40,7 +40,7 @@ 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 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 c939208f4..c289ad0cc 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 @@ -38,17 +38,6 @@ public interface Mask { */ boolean test(BlockVector3 vector); - default Filter toFilter(Runnable run) { - return new Filter() { - @Override - public void applyBlock(FilterBlock block) { - if (test(block)) { - run.run(); - } - } - }; - } - default DelegateFilter toFilter(T filter) { return new DelegateFilter(filter) { @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java index 8dea4f786..a6a91513c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java @@ -37,7 +37,6 @@ import java.util.Set; import java.util.function.Function; import javax.annotation.Nullable; - /** * Combines several masks and requires that all masks return true * when a certain position is tested. It serves as a logical AND operation @@ -223,6 +222,10 @@ public class MaskIntersection extends AbstractMask { @Override public boolean test(BlockVector3 vector) { + if (masksArray.length == 0) { + return false; + } + for (Mask mask : masksArray) { if (!mask.test(vector)) { return false; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java index ade00728c..3b743d13b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java @@ -21,7 +21,6 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; -import com.boydti.fawe.beta.FilterBlock; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; @@ -32,8 +31,8 @@ import javax.annotation.Nullable; */ public final class Masks { - protected static final AlwaysTrue ALWAYS_TRUE = new AlwaysTrue(); - protected static final AlwaysFalse ALWAYS_FALSE = new AlwaysFalse(); + static final AlwaysTrue ALWAYS_TRUE = new AlwaysTrue(); + static final AlwaysFalse ALWAYS_FALSE = new AlwaysFalse(); private Masks() { } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask.java index a5d40b12f..e5df3b153 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask.java @@ -21,7 +21,6 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; -import com.boydti.fawe.beta.FilterBlock; import com.sk89q.worldedit.math.BlockVector3; import javax.annotation.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 ca1da29b5..5ac7721e1 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 @@ -70,4 +70,5 @@ public class RegionMask extends AbstractMask { public Mask2D toMask2D() { return null; } + } 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 65e56707c..41418430f 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 @@ -66,16 +66,15 @@ public class ChangeSetExecutor implements Operation { @Override public Operation resume(RunContext run) throws WorldEditException { - Change change = iterator.next(); - if (type == Type.UNDO) { - while (iterator.hasNext()) { + while (iterator.hasNext()) { + Change change = iterator.next(); + if (type == Type.UNDO) { change.undo(context); - } - } else { - while (iterator.hasNext()) { + } else { change.redo(context); } } + return null; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/BiomePattern.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/BiomePattern.java new file mode 100644 index 000000000..82147f392 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/BiomePattern.java @@ -0,0 +1,37 @@ +/* + * 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.function.pattern; + +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.world.biome.BiomeType; + +/** + * Returns a {@link BiomeType} for a given position. + */ +public interface BiomePattern { + + /** + * Return a {@link BiomeType} for the given position. + * + * @param position the position + * @return a block + */ + BiomeType apply(BlockVector2 position); +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/BlockPattern.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/BlockPattern.java index 118492bde..a934bc17a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/BlockPattern.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/BlockPattern.java @@ -67,4 +67,5 @@ public class BlockPattern extends AbstractPattern { public BaseBlock apply(BlockVector3 position) { return block; } + } 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 6d9a787e5..9fed46511 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 @@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.pattern; import com.sk89q.worldedit.extent.Extent; 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; @@ -64,9 +65,10 @@ public class WaterloggedRemover extends AbstractExtentPattern { @Override public BaseBlock apply(BlockVector3 position) { BaseBlock block = getExtent().getFullBlock(position); - BlockState newState = remap[block.getOrdinal()]; - if (newState != null) { - return newState.toBaseBlock(block.getNbtData()); + @SuppressWarnings("unchecked") + Property prop = (Property) remap[block.getOrdinal()].getBlockType().getPropertyMap().getOrDefault("waterlogged", null); + if (prop != null) { + return block.with(prop, false); } return BlockTypes.AIR.getDefaultState().toBaseBlock(); } 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 304e81e21..f0b407092 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 @@ -78,9 +78,9 @@ public abstract class BreadthFirstSearch implements Operation { } private final RegionFunction function; + private BlockVectorSet queue = new BlockVectorSet(); + private BlockVectorSet visited = new BlockVectorSet(); private BlockVector3[] directions; - private BlockVectorSet visited; - private BlockVectorSet queue; private int affected = 0; private int currentDepth = 0; private final int maxDepth; @@ -98,8 +98,6 @@ public abstract class BreadthFirstSearch implements Operation { public BreadthFirstSearch(RegionFunction function, int maxDepth) { checkNotNull(function); - this.queue = new BlockVectorSet(); - this.visited = new BlockVectorSet(); this.function = function; this.directions = DEFAULT_DIRECTIONS; this.maxDepth = maxDepth; @@ -121,6 +119,8 @@ public abstract class BreadthFirstSearch implements Operation { * unit vectors. An example of a valid direction is * {@code BlockVector3.at(1, 0, 1)}.

* + *

The list of directions can be cleared.

+ * * @return the list of directions */ public Collection getDirections() { @@ -260,6 +260,7 @@ public abstract class BreadthFirstSearch implements Operation { tmp.clear(); tempQueue = tmp; } + return null; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java index 17628b763..b31257769 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java @@ -70,6 +70,7 @@ public class FlatRegionVisitor implements Operation { affected++; } } + 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 bda40ee93..97fe6ec80 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 @@ -20,14 +20,12 @@ package com.sk89q.worldedit.function.visitor; import com.boydti.fawe.config.BBC; -import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.RunContext; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; - import java.util.List; /** @@ -42,17 +40,12 @@ public class RegionVisitor implements Operation { public int affected = 0; public final Iterable iterable; - /** - * Deprecated in favor of the other constructors which will preload chunks during iteration - * - * @param region - * @param function - */ + + @Deprecated public RegionVisitor(Region region, RegionFunction function) { this((Iterable) region, function); } - @Deprecated public RegionVisitor(Iterable iterable, RegionFunction function) { this.region = iterable instanceof Region ? (Region) iterable : null; this.function = function; @@ -75,6 +68,7 @@ public class RegionVisitor implements Operation { affected++; } } + return null; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandRegistrationHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandRegistrationHandler.java index 032d0d03f..b628e2aa4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandRegistrationHandler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandRegistrationHandler.java @@ -46,7 +46,7 @@ public class CommandRegistrationHandler { .listeners(callListeners); if (registration instanceof CommandPermissionsConditionGenerator.Registration) { ((CommandPermissionsConditionGenerator.Registration) registration).commandPermissionsConditionGenerator( - PERM_GEN + PERM_GEN ); } if (registration instanceof CommandQueuedConditionGenerator.Registration) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/exception/WorldEditExceptionConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/exception/WorldEditExceptionConverter.java index f9b68cbb6..b015a5658 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/exception/WorldEditExceptionConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/exception/WorldEditExceptionConverter.java @@ -85,6 +85,7 @@ public class WorldEditExceptionConverter extends ExceptionConverterHelper { public void convert(MissingWorldException e) throws CommandException { throw newCommandException("You need to provide a world (Try //world)", e); } + @ExceptionMatch public void convert(UnknownItemException e) throws CommandException { throw newCommandException("Block name '" + e.getID() + "' was not recognized.", e); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java index 7de5f28d9..db404f03e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java @@ -86,7 +86,6 @@ public class Expression { .build()); private final Map variables = new HashMap<>(); - private final String[] variableNames; private Variable[] variableArray; private RValue root; private final Functions functions = new Functions(); @@ -97,7 +96,6 @@ public class Expression { } public Expression(double constant) { - variableNames = null; root = new Constant(0, constant); } @@ -106,7 +104,6 @@ public class Expression { } private Expression(List tokens, String... variableNames) throws ExpressionException { - this.variableNames = variableNames; variables.put("e", new Constant(-1, Math.E)); variables.put("pi", new Constant(-1, Math.PI)); @@ -115,12 +112,11 @@ public class Expression { variableArray = new Variable[variableNames.length]; for (int i = 0; i < variableNames.length; i++) { - String variableName = variableNames[i]; - if (variables.containsKey(variableName)) { - throw new ExpressionException(-1, "Tried to overwrite identifier '" + variableName + "'"); + if (variables.containsKey(variableNames[i])) { + throw new ExpressionException(-1, "Tried to overwrite identifier '" + variableNames[i] + "'"); } Variable var = new Variable(0); - variables.put(variableName, var); + variables.put(variableNames[i], var); variableArray[i] = var; } @@ -139,14 +135,7 @@ public class Expression { return evaluateTimeout(WorldEdit.getInstance().getConfiguration().calculationTimeout, values); } - public double evaluateTimeout(int timeout, double x, double y) throws EvaluationException { - if (root instanceof Constant) return root.getValue(); - variableArray[0].value = x; - variableArray[1].value = y; - return evaluateFinal(timeout); - } - - public double evaluateTimeout(int timeout, double x, double y, double z) throws EvaluationException { + private double evaluateTimeout(int timeout, double x, double y, double z) throws EvaluationException { if (root instanceof Constant) return root.getValue(); variableArray[0].value = x; variableArray[1].value = y; @@ -156,8 +145,8 @@ public class Expression { public double evaluateTimeout(int timeout, double... values) throws EvaluationException { if (root instanceof Constant) return root.getValue(); - for (int i = 0; i < values.length; i++) { - Variable var = variableArray[i]; + for (int i = 0; i < values.length; ++i) { + final Variable var = variableArray[i]; var.value = values[i]; } return evaluateFinal(timeout); @@ -167,7 +156,7 @@ public class Expression { if (root instanceof Constant) { return root.getValue(); } - for (int i = 0; i < values.length; i++) { + for (int i = 0; i < values.length; ++i) { Variable var = variableArray[i]; var.value = values[i]; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/ReturnException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/ReturnException.java index c5b2b27f0..84b60021b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/ReturnException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/ReturnException.java @@ -38,4 +38,4 @@ public class ReturnException extends EvaluationException { return value; } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/Substring.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/Substring.java index fa4049cda..592d2b22f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/Substring.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/Substring.java @@ -19,6 +19,8 @@ package com.sk89q.worldedit.internal.util; +import static com.google.common.base.Preconditions.checkArgument; + import java.util.Objects; /** @@ -31,7 +33,7 @@ public final class Substring { * a Substring. */ public static Substring from(String original, int start) { - return wrap(original.substring(start), start, original.length()); + return new Substring(original.substring(start), start, original.length()); } /** @@ -39,13 +41,15 @@ public final class Substring { * a Substring. */ public static Substring from(String original, int start, int end) { - return wrap(original.substring(start, end), start, end); + return new Substring(original.substring(start, end), start, end); } /** * Wrap the given parameters into a Substring instance. */ public static Substring wrap(String substring, int start, int end) { + checkArgument(0 <= start, "Start must be greater than or equal to zero"); + checkArgument(start <= end, "End must be greater than or equal to start"); return new Substring(substring, start, end); } 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 a940da291..db39ad5e7 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 @@ -98,7 +98,6 @@ public abstract class BlockVector3 { // thread-safe initialization idiom private static final class YzxOrderComparator { - private static final Comparator YZX_ORDER = Comparator.comparingInt(BlockVector3::getY) .thenComparingInt(BlockVector3::getZ) @@ -151,38 +150,6 @@ public abstract class BlockVector3 { return BlockVector3.at(getX(), getY(), getZ()); } -// /** -// * Get the BlockVector3 to the north
-// * Normal use you would use north(this), -// * To avoid constructing a new Vector, pass e.g. north(some MutableBlockVector3) -// * There is no gaurantee it will use this provided vector -// * @param orDefault the vector to use as the result
-// * @return BlockVector3 -// */ -// public BlockVector3 north(BlockVector3 orDefault) { -// return orDefault.setComponents(getX(), getY(), getZ() - 1); -// } -// -// public BlockVector3 east(BlockVector3 orDefault) { -// return orDefault.setComponents(getX() + 1, getY(), getZ()); -// } -// -// public BlockVector3 south(BlockVector3 orDefault) { -// return orDefault.setComponents(getX(), getY(), getZ() + 1); -// } -// -// public BlockVector3 west(BlockVector3 orDefault) { -// return orDefault.setComponents(getX() - 1, getY(), getZ()); -// } -// -// public BlockVector3 up(BlockVector3 orDefault) { -// return orDefault.setComponents(getX(), getY() + 1, getZ()); -// } -// -// public BlockVector3 down(BlockVector3 orDefault) { -// return orDefault.setComponents(getX(), getY() - 1, getZ()); -// } - public long toLongPackedForm() { checkLongPackable(this); return (getX() & BITS_26) | ((getZ() & BITS_26) << 26) | (((getY() & (long) BITS_12) << (26 + 26))); @@ -289,7 +256,8 @@ 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 @@ -307,7 +275,8 @@ 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 @@ -317,7 +286,8 @@ 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 @@ -329,7 +299,8 @@ 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 @@ -514,7 +485,8 @@ 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 */ @@ -613,7 +585,8 @@ 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 */ @@ -624,16 +597,15 @@ 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; @@ -691,9 +663,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()) ); } @@ -705,9 +677,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()) ); } @@ -788,7 +760,8 @@ public abstract class BlockVector3 { return false; } - return equals((BlockVector3) obj); + BlockVector3 other = (BlockVector3) obj; + return other.getX() == this.getX() && other.getY() == this.getY() && other.getZ() == this.getZ(); } public final boolean equals(BlockVector3 other) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/KochanekBartelsInterpolation.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/KochanekBartelsInterpolation.java index d9d15008c..91b899ebb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/KochanekBartelsInterpolation.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/KochanekBartelsInterpolation.java @@ -31,8 +31,8 @@ import java.util.List; /** * A Kochanek-Bartels interpolation; continuous in the 2nd derivative. * - *

Supports Node#tension tension, Node#bias bias and - * Node#continuity continuity parameters per {@link Node}.

+ *

Supports {@link Node#tension tension}, {@link Node#bias bias} and + * {@link Node#continuity continuity} parameters per {@link Node}.

*/ public class KochanekBartelsInterpolation implements Interpolation { 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 381403e1b..b79dbca1c 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 @@ -120,6 +120,7 @@ public abstract class AbstractRegion extends AbstractSet implement (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 ac268256c..7135a6528 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 @@ -412,6 +412,11 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { return x >= this.minX && x <= this.maxX && z >= this.minZ && z <= this.maxZ; } + @Override + public boolean contains(BlockVector3 position) { + return contains(position.getX(), position.getY(), position.getZ()); + } + @Override public Iterator iterator() { if (Settings.IMP.HISTORY.COMPRESSION_LEVEL >= 9 || useOldIterator) { 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 4e3a9a6e0..53f48baf9 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 @@ -35,7 +35,6 @@ import com.sk89q.worldedit.math.geom.Polygons; import com.sk89q.worldedit.regions.iterator.FlatRegion3DIterator; import com.sk89q.worldedit.regions.iterator.FlatRegionIterator; import com.sk89q.worldedit.world.World; - import java.util.Iterator; import java.util.List; @@ -327,6 +326,11 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { return dx * dx + dz * dz <= 1; } + @Override + public boolean contains(BlockVector3 position) { + return contains(position.getX(), position.getY(), position.getZ()); + } + /** * Sets the height of the cylinder to fit the specified Y. * @@ -411,7 +415,8 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { } @Override - public void filter(final IChunk chunk, final Filter filter, final ChunkFilterBlock block, final IChunkGet get, final IChunkSet set) { + public void filter(final IChunk chunk, final Filter filter, final ChunkFilterBlock block, + final IChunkGet get, final IChunkSet set) { int bcx = chunk.getX() >> 4; int bcz = chunk.getZ() >> 4; int tcx = bcx + 15; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java index 679047abf..09368b52a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java @@ -104,7 +104,7 @@ public class EllipsoidRegion extends AbstractRegion { @Override public int getHeight() { - return Math.max((int) (2 * radius.getY()), 256); + return (int) (2 * radius.getY()); } @Override @@ -246,6 +246,11 @@ public class EllipsoidRegion extends AbstractRegion { return cxd + cyd + czd <= 1; } + @Override + public boolean contains(BlockVector3 position) { + return position.subtract(center).toVector3().divide(radius).lengthSq() <= 1; + } + @Override public boolean contains(int x, int z) { int cx = x - center.getBlockX(); 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 1406b94e8..6dccae560 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 @@ -141,9 +141,7 @@ public interface Region extends Iterable, Cloneable { * @param position the position * @return true if contained */ - default boolean contains(BlockVector3 position) { - return contains(position.getX(), position.getY(), position.getZ()); - } + boolean contains(BlockVector3 position); /** * Get a list of chunks. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java index 79d51cefb..8cad2670b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java @@ -50,6 +50,7 @@ public class RhinoCraftScriptEngine implements CraftScriptEngine { throws ScriptException, Throwable { RhinoContextFactory factory = new RhinoContextFactory(timeLimit); Context cx = factory.enterContext(); + cx.setClassShutter(new MinecraftHidingClassShutter()); ScriptableObject scriptable = new ImporterTopLevel(cx); Scriptable scope = cx.initStandardObjects(scriptable); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/ClipboardHolder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/ClipboardHolder.java index a4d6b5631..faf7db200 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/session/ClipboardHolder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/ClipboardHolder.java @@ -62,8 +62,8 @@ public class ClipboardHolder { } /** - * Get all currently held clipboards - * @return + * Gets all currently held clipboards. + * @return all clipboards being held. */ public List getClipboards() { return Collections.singletonList(getClipboard()); @@ -74,10 +74,10 @@ public class ClipboardHolder { } /** - * Get all end ClipboardHolders
+ * Gets all end ClipboardHolders
* - Usually this will return itself.
* - If this is a multi clipboard, it will return the children - * @return Set of end ClipboardHolders + * @return a List of end ClipboardHolders */ public List getHolders() { return Collections.singletonList(this); 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 70dd62256..d13c58c98 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 @@ -65,9 +65,10 @@ import org.slf4j.LoggerFactory; */ public class SessionManager { - public static int EXPIRATION_GRACE = 0; - private static final int FLUSH_PERIOD = 1000 * 60; - private static final ListeningExecutorService executorService = MoreExecutors.listeningDecorator(EvenMoreExecutors.newBoundedCachedThreadPool(0, 1, 5)); + public static int EXPIRATION_GRACE = 10 * 60 * 1000; + private static final int FLUSH_PERIOD = 1000 * 30; + private static final ListeningExecutorService executorService = MoreExecutors.listeningDecorator( + EvenMoreExecutors.newBoundedCachedThreadPool(0, 1, 5, "WorldEdit Session Saver - %s")); private static final Logger log = LoggerFactory.getLogger(SessionManager.class); private static boolean warnedInvalidTool; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/request/RequestSelection.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/request/RequestSelection.java index 7645154f8..9e37e4da0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/session/request/RequestSelection.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/request/RequestSelection.java @@ -23,7 +23,6 @@ import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; 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.regions.NullRegion; import com.sk89q.worldedit.regions.Region; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/paste/EngineHubPaste.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/paste/EngineHubPaste.java index ab8ebe029..3a5e01b6e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/paste/EngineHubPaste.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/paste/EngineHubPaste.java @@ -54,7 +54,7 @@ public class EngineHubPaste implements Paster { form.add("content", content); form.add("from", "enginehub"); - URL url = HttpRequest.url("http://paste.enginehub.org/paste"); + URL url = HttpRequest.url("https://paste.enginehub.org/paste"); String result = HttpRequest.post(url) .bodyForm(form) .execute() diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java index f6ed36737..5cc6a232e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java @@ -47,8 +47,8 @@ import javax.annotation.Nullable; */ public class BaseBlock implements BlockStateHolder, TileEntityBlock { - private final BlockState blockState; - private final CompoundTag nbtData; + private BlockState blockState; + @Nullable private CompoundTag nbtData; @Deprecated public BaseBlock() { @@ -105,25 +105,6 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { return blockState; } - protected BaseBlock(int internalId, CompoundTag nbtData) { - this(BlockState.getFromInternalId(internalId), nbtData); - } - - @Deprecated - public static BaseBlock getFromInternalId(int internalId, CompoundTag nbtData) { - return BlockState.getFromInternalId(internalId).toBaseBlock(nbtData); - } - - /** - * Create a clone of another block. - * - * @param other the other block - */ - @Deprecated - public BaseBlock(BaseBlock other) { - this(other.toImmutableState(), other.getNbtData()); - } - /** * Gets a map of state to statevalue * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java index 5b8e12032..e76db1bb1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java @@ -34,11 +34,6 @@ import java.util.stream.Collectors; public interface BlockStateHolder> extends FawePattern, TileEntityBlock { - @Override - default BaseBlock apply(BlockVector3 position) { - return this.toBaseBlock(); - } - /** * Get the block type * @@ -68,13 +63,13 @@ public interface BlockStateHolder> extends FawePat char getOrdinalChar(); BlockMaterial getMaterial(); + /** * Get type id (legacy uses) * @return */ @Deprecated int getInternalBlockTypeId(); - /** * Get the block data (legacy uses) * @return @@ -153,6 +148,11 @@ public interface BlockStateHolder> extends FawePat */ BaseBlock toBaseBlock(CompoundTag compoundTag); + @Override + default BaseBlock apply(BlockVector3 position) { + return toBaseBlock(); + } + /** * Return the name of the title entity ID. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java index 2b6b1c155..11302a619 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java @@ -37,12 +37,10 @@ import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.LegacyMapper; - import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.IntStream; import javax.annotation.Nullable; @@ -103,18 +101,6 @@ public class BlockType implements FawePattern, Keyed { } } - public BlockState withProperties(String properties) { // - int id = getInternalId(); - for (String keyPair : properties.split(",")) { - String[] split = keyPair.split("="); - String name = split[0]; - String value = split[1]; - AbstractProperty btp = settings.propertiesMap.get(name); - id = btp.modify(id, btp.getValueFor(value)); - } - return withStateId(id); - } - @Deprecated public BlockState withPropertyId(int propertyId) { if (settings.stateOrdinals == null) return settings.defaultState; @@ -177,14 +163,10 @@ public class BlockType implements FawePattern, Keyed { * * @return The default state */ - public final BlockState getDefaultState() { + public BlockState getDefaultState() { return this.settings.defaultState; } - /** - * @Deprecated use a Mask instead - * @return - */ @Deprecated public FuzzyBlockState getFuzzyMatcher() { return new FuzzyBlockState(this); @@ -305,10 +287,6 @@ public class BlockType implements FawePattern, Keyed { return this.getDefaultState().toBaseBlock(); } - public SingleBlockTypeMask toMask() { - return toMask(null); - } - public SingleBlockTypeMask toMask(Extent extent) { return new SingleBlockTypeMask(extent, this); } diff --git a/worldedit-libs/core/ap/build.gradle.kts b/worldedit-libs/core/ap/build.gradle.kts index 10c52bd7b..cfac0cf24 100644 --- a/worldedit-libs/core/ap/build.gradle.kts +++ b/worldedit-libs/core/ap/build.gradle.kts @@ -4,6 +4,6 @@ dependencies { "shade"("FAWE-Piston:core/build/libs/core-${Versions.PISTON}:lastSuccessfulBuild@jar") "shade"("FAWE-Piston:core-ap/annotations/build/libs/annotations-${Versions.PISTON}:lastSuccessfulBuild@jar") "shade"("FAWE-Piston:core-ap/processor/build/libs/processor-${Versions.PISTON}:lastSuccessfulBuild@jar") - "shade"("org.enginehub.piston.core-ap:annotations:0.4.3") - "shade"("org.enginehub.piston.core-ap:processor:0.4.3") + "shade"("org.enginehub.piston.core-ap:annotations:${Versions.PISTON}") + "shade"("org.enginehub.piston.core-ap:processor:${Versions.PISTON}") }