diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 9ea58be60..48a0371a3 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -8,18 +8,18 @@ plugins { repositories { jcenter() gradlePluginPortal() - maven { - name = "Forge Maven" - url = uri("https://files.minecraftforge.net/maven") - } - maven { - name = "Fabric" - url = uri("https://maven.fabricmc.net/") - } - maven { - name = "sponge" - url = uri("https://repo.spongepowered.org/maven") - } +// maven { +// name = "Forge Maven" +// url = uri("https://files.minecraftforge.net/maven") +// } +// maven { +// name = "Fabric" +// url = uri("https://maven.fabricmc.net/") +// } +// maven { +// name = "sponge" +// url = uri("https://repo.spongepowered.org/maven") +// } } configurations.all { @@ -43,14 +43,14 @@ val mixinVersion: String = properties.getProperty("mixin.version") dependencies { implementation(gradleApi()) - implementation("gradle.plugin.net.minecrell:licenser:0.4.1") +// implementation("gradle.plugin.net.minecrell:licenser:0.4.1") implementation("org.ajoberstar.grgit:grgit-gradle:3.1.1") implementation("com.github.jengelman.gradle.plugins:shadow:5.1.0") implementation("net.ltgt.apt-eclipse:net.ltgt.apt-eclipse.gradle.plugin:0.21") implementation("net.ltgt.apt-idea:net.ltgt.apt-idea.gradle.plugin:0.21") implementation("org.jfrog.buildinfo:build-info-extractor-gradle:4.9.7") - implementation("gradle.plugin.org.spongepowered:spongegradle:0.9.0") - implementation("net.minecraftforge.gradle:ForgeGradle:3.0.143") - implementation("net.fabricmc:fabric-loom:$loomVersion") - implementation("net.fabricmc:sponge-mixin:$mixinVersion") +// implementation("gradle.plugin.org.spongepowered:spongegradle:0.9.0") +// implementation("net.minecraftforge.gradle:ForgeGradle:3.0.143") +// implementation("net.fabricmc:fabric-loom:$loomVersion") +// implementation("net.fabricmc:sponge-mixin:$mixinVersion") } \ No newline at end of file diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java index c0f66fd83..d061f468c 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 @@ -31,7 +31,6 @@ import com.sk89q.worldedit.bukkit.adapter.IBukkitAdapter; import com.sk89q.worldedit.bukkit.adapter.SimpleBukkitAdapter; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extension.input.ParserContext; -import com.sk89q.worldedit.internal.block.BlockStateIdAccess; import com.sk89q.worldedit.extension.platform.PlayerProxy; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; @@ -52,431 +51,15 @@ import com.sk89q.worldedit.world.item.ItemTypes; import java.util.HashMap; import java.util.Locale; import java.util.Map; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import java.util.Objects; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; - -import java.util.EnumMap; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -/** - * Adapts between Bukkit and WorldEdit equivalent objects. - */ -public class BukkitAdapter { - - private BukkitAdapter() { - } - - private static final ParserContext TO_BLOCK_CONTEXT = new ParserContext(); - - static { - TO_BLOCK_CONTEXT.setRestricted(false); - } - - /** - * 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 - */ - public static boolean equals(BlockType blockType, Material type) { - return Objects.equals(blockType.getId(), type.getKey().toString()); - } - - /** - * Convert any WorldEdit world into an equivalent wrapped Bukkit world. - * - *

If a matching world cannot be found, a {@link RuntimeException} - * will be thrown.

- * - * @param world the world - * @return a wrapped Bukkit world - */ - public static BukkitWorld asBukkitWorld(World 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; - } - } - - /** - * Create a WorldEdit world from a Bukkit world. - * - * @param world the Bukkit world - * @return a WorldEdit world - */ - public static World adapt(org.bukkit.World world) { - checkNotNull(world); - return new BukkitWorld(world); - } - - /** - * Create a WorldEdit Player from a Bukkit Player. - * - * @param player The Bukkit player - * @return The WorldEdit player - */ - public static BukkitPlayer adapt(Player player) { - return WorldEditPlugin.getInstance().wrapPlayer(player); - } - - /** - * Create a Bukkit Player from a WorldEdit Player. - * - * @param player The WorldEdit player - * @return The Bukkit player - */ - public static Player adapt(com.sk89q.worldedit.entity.Player 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()); - } - } - } - - /** - * Create a WorldEdit location from a Bukkit location. - * - * @param location the Bukkit location - * @return a WorldEdit location - */ - public static Location adapt(org.bukkit.Location location) { - checkNotNull(location); - Vector3 position = asVector(location); - return new com.sk89q.worldedit.util.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 - */ - public static org.bukkit.Location adapt(Location location) { - checkNotNull(location); - Vector3 position = location.toVector(); - 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. - * - * @param world the Bukkit world - * @param position the WorldEdit position - * @return a Bukkit location - */ - public static org.bukkit.Location adapt(org.bukkit.World world, Vector3 position) { - checkNotNull(world); - checkNotNull(position); - return new org.bukkit.Location( - world, - position.getX(), position.getY(), position.getZ()); - } - - /** - * Create a Bukkit location from a WorldEdit position with a Bukkit world. - * - * @param world the Bukkit world - * @param position the WorldEdit position - * @return a Bukkit location - */ - public static org.bukkit.Location adapt(org.bukkit.World world, BlockVector3 position) { - checkNotNull(world); - checkNotNull(position); - return new org.bukkit.Location( - world, - position.getX(), position.getY(), position.getZ()); - } - - /** - * Create a Bukkit location from a WorldEdit location with a Bukkit world. - * - * @param world the Bukkit world - * @param location the WorldEdit location - * @return a Bukkit location - */ - public static org.bukkit.Location adapt(org.bukkit.World world, Location location) { - checkNotNull(world); - checkNotNull(location); - return new org.bukkit.Location( - world, - location.getX(), location.getY(), location.getZ(), - location.getYaw(), - location.getPitch()); - } - - /** - * Create a WorldEdit Vector from a Bukkit location. - * - * @param location The Bukkit location - * @return a WorldEdit vector - */ - public static Vector3 asVector(org.bukkit.Location location) { - checkNotNull(location); - return Vector3.at(location.getX(), location.getY(), location.getZ()); - } - - /** - * Create a WorldEdit BlockVector from a Bukkit location. - * - * @param location The Bukkit location - * @return a WorldEdit vector - */ - public static BlockVector3 asBlockVector(org.bukkit.Location location) { - checkNotNull(location); - return BlockVector3.at(location.getX(), location.getY(), location.getZ()); - } - - /** - * Create a WorldEdit entity from a Bukkit entity. - * - * @param entity the Bukkit entity - * @return a WorldEdit entity - */ - public static Entity adapt(org.bukkit.entity.Entity entity) { - checkNotNull(entity); - return new BukkitEntity(entity); - } - - /** - * Create a Bukkit Material form a WorldEdit ItemType - * - * @param itemType The WorldEdit ItemType - * @return The Bukkit Material - */ - public static Material adapt(ItemType itemType) { - checkNotNull(itemType); - if (!itemType.getId().startsWith("minecraft:")) { - throw new IllegalArgumentException("Bukkit only supports Minecraft items"); - } - return Material.getMaterial(itemType.getId().substring(10).toUpperCase(Locale.ROOT)); - } - - /** - * Create a Bukkit Material form a WorldEdit BlockType - * - * @param blockType The WorldEdit BlockType - * @return The Bukkit Material - */ - 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)); - } - - /** - * Create a WorldEdit GameMode from a Bukkit one. - * - * @param gameMode Bukkit GameMode - * @return WorldEdit GameMode - */ - public static GameMode adapt(org.bukkit.GameMode gameMode) { - checkNotNull(gameMode); - return GameModes.get(gameMode.name().toLowerCase(Locale.ROOT)); - } - - /** - * Create a WorldEdit BiomeType from a Bukkit one. - * - * @param biome Bukkit Biome - * @return WorldEdit BiomeType - */ - public static BiomeType adapt(Biome biome) { - return BiomeTypes.get(biome.name().toLowerCase(Locale.ROOT)); - } - - public static Biome adapt(BiomeType 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; - } - } - - /** - * Create a WorldEdit EntityType from a Bukkit one. - * - * @param entityType Bukkit EntityType - * @return WorldEdit EntityType - */ - public static EntityType adapt(org.bukkit.entity.EntityType 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) { - if (!entityType.getId().startsWith("minecraft:")) { - throw new IllegalArgumentException("Bukkit only supports vanilla entities"); - } - return org.bukkit.entity.EntityType.fromName(entityType.getId().substring(10)); - } - - private static EnumMap materialBlockTypeCache = new EnumMap<>(Material.class); - private static EnumMap materialItemTypeCache = new EnumMap<>(Material.class); - - /** - * Converts a Material to a BlockType - * - * @param material The material - * @return The blocktype - */ - @Nullable - public static BlockType asBlockType(Material material) { - checkNotNull(material); - return materialBlockTypeCache.computeIfAbsent(material, input -> BlockTypes.get(material.getKey().toString())); - } - - /** - * Converts a Material to a ItemType - * - * @param material The material - * @return The itemtype - */ - @Nullable - public static ItemType asItemType(Material material) { - checkNotNull(material); - return materialItemTypeCache.computeIfAbsent(material, input -> ItemTypes.get(material.getKey().toString())); - } - - private static Int2ObjectMap blockStateCache = new Int2ObjectOpenHashMap<>(); - private static Map blockStateStringCache = new HashMap<>(); - - /** - * Create a WorldEdit BlockState from a Bukkit BlockData - * - * @param blockData The Bukkit BlockData - * @return The WorldEdit BlockState - */ - public static BlockState adapt(BlockData blockData) { - checkNotNull(blockData); - - if (WorldEditPlugin.getInstance().getBukkitImplAdapter() == null) { - return blockStateStringCache.computeIfAbsent(blockData.getAsString(), input -> { - try { - return WorldEdit.getInstance().getBlockFactory().parseFromInput(input, TO_BLOCK_CONTEXT).toImmutableState(); - } catch (InputParseException e) { - e.printStackTrace(); - return null; - } - }); - } else { - return blockStateCache.computeIfAbsent( - WorldEditPlugin.getInstance().getBukkitImplAdapter().getInternalBlockStateId(blockData).orElseGet( - () -> blockData.getAsString().hashCode() - ), input -> { - try { - return WorldEdit.getInstance().getBlockFactory().parseFromInput(blockData.getAsString(), TO_BLOCK_CONTEXT).toImmutableState(); - } catch (InputParseException e) { - e.printStackTrace(); - return null; - } - }); - } - } - - private static Int2ObjectMap blockDataCache = new Int2ObjectOpenHashMap<>(); - - /** - * Create a Bukkit BlockData from a WorldEdit BlockStateHolder - * - * @param block The WorldEdit BlockStateHolder - * @return The Bukkit BlockData - */ - public static > BlockData adapt(B block) { - checkNotNull(block); - // Should never not have an ID for this BlockState. - int cacheKey = BlockStateIdAccess.getBlockStateId(block.toImmutableState()).orElseGet(block::hashCode); - return blockDataCache.computeIfAbsent(cacheKey, input -> Bukkit.createBlockData(block.getAsString())).clone(); - } - - /** - * Create a WorldEdit BlockState from a Bukkit ItemStack - * - * @param itemStack The Bukkit ItemStack - * @return The WorldEdit BlockState - */ - public static BlockState asBlockState(ItemStack itemStack) throws WorldEditException { - checkNotNull(itemStack); - if (itemStack.getType().isBlock()) { - return adapt(itemStack.getType().createBlockData()); - } else { - throw new NotABlockException(); - } - } - - /** - * Create a WorldEdit BaseItemStack from a Bukkit ItemStack - * - * @param itemStack The Bukkit ItemStack - * @return The WorldEdit BaseItemStack - */ - public static BaseItemStack adapt(ItemStack itemStack) { - checkNotNull(itemStack); - if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) { - return WorldEditPlugin.getInstance().getBukkitImplAdapter().adapt(itemStack); - } - return new BaseItemStack(ItemTypes.get(itemStack.getType().getKey().toString()), itemStack.getAmount()); - } - - /** - * Create a Bukkit ItemStack from a WorldEdit BaseItemStack - * - * @param item The WorldEdit BaseItemStack - * @return The Bukkit ItemStack - */ - public static ItemStack adapt(BaseItemStack item) { - checkNotNull(item); - if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) { - return WorldEditPlugin.getInstance().getBukkitImplAdapter().adapt(item); - } - return new ItemStack(adapt(item.getType()), item.getAmount()); - } -} - /** * Adapts between Bukkit and WorldEdit equivalent objects. */ @@ -812,4 +395,4 @@ public enum BukkitAdapter { public static ItemStack adapt(BaseItemStack item) { return getAdapter().adapt(item); } -} +} \ No newline at end of file diff --git a/worldedit-core/build.gradle.kts b/worldedit-core/build.gradle.kts index e4f65dd27..dfe9f42b6 100644 --- a/worldedit-core/build.gradle.kts +++ b/worldedit-core/build.gradle.kts @@ -34,8 +34,8 @@ dependencies { val antlrVersion = "4.7.2" "antlr"("org.antlr:antlr4:$antlrVersion") "implementation"("org.antlr:antlr4-runtime:$antlrVersion") - - "compile"("com.googlecode.json-simple:json-simple:1.3.9") { isTransitive = false } + + "compile"("com.googlecode.json-simple:json-simple:1.1.1") { isTransitive = false } "compileOnly"(project(":worldedit-libs:core:ap")) "annotationProcessor"(project(":worldedit-libs:core:ap")) // ensure this is on the classpath for the AP diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index b6b05dac7..b8e9fd545 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -68,6 +68,7 @@ import com.sk89q.worldedit.function.block.BlockReplace; import com.sk89q.worldedit.function.block.Naturalizer; import com.sk89q.worldedit.function.generator.ForestGenerator; import com.sk89q.worldedit.function.generator.GardenPatchGenerator; +import com.sk89q.worldedit.function.mask.BlockMask; import com.sk89q.worldedit.function.mask.BlockTypeMask; import com.sk89q.worldedit.function.mask.BoundedHeightMask; import com.sk89q.worldedit.function.mask.ExistingBlockMask; @@ -94,9 +95,9 @@ import com.sk89q.worldedit.function.visitor.RecursiveVisitor; import com.sk89q.worldedit.function.visitor.RegionVisitor; import com.sk89q.worldedit.history.UndoContext; import com.sk89q.worldedit.history.changeset.ChangeSet; +import com.sk89q.worldedit.internal.expression.EvaluationException; import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.ExpressionException; -import com.sk89q.worldedit.internal.expression.runtime.EvaluationException; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MathUtils; @@ -1168,18 +1169,6 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { return this.changes = visitor.getAffected(); } - /** - * Count the number of blocks of a list of types in a region. - * - * @param region the region - * @param searchBlocks the list of blocks to search - * @return the number of blocks that matched the block - */ - public int countBlocks(Region region, Set searchBlocks) { - BlockMask mask = new BlockMask(this, searchBlocks); - return countBlocks(region, mask); - } - /** * Remove a cuboid above the given position with a given apothem and a given height. * @@ -1222,26 +1211,6 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { return setBlocks(region, BlockTypes.AIR.getDefaultState()); } - /** - * Remove blocks of a certain type nearby a given position. - * - * @param position center position of cuboid - * @param mask the mask to match - * @param apothem an apothem of the cuboid, where the minimum is 1 - * @return number of blocks affected - * @throws MaxChangedBlocksException thrown if too many blocks are changed - */ - public int removeNear(BlockVector3 position, Mask mask, int apothem) throws MaxChangedBlocksException { - checkNotNull(position); - checkArgument(apothem >= 1, "apothem >= 1"); - - final BlockVector3 adjustment = BlockVector3.at(1, 1, 1).multiply(apothem - 1); - final Region region = new CuboidRegion(this.getWorld(), // Causes clamping of Y range - position.add(adjustment.multiply(-1)), position.add(adjustment)); - final Pattern pattern = BlockTypes.AIR.getDefaultState(); - return this.replaceBlocks(region, mask, pattern); - } - /** * Remove blocks of a certain type nearby a given position. * @@ -1495,6 +1464,15 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { return this.changes = copy.getAffected(); } + public int moveRegion(Region region, BlockVector3 dir, int distance, boolean copyAir, + boolean moveEntities, boolean copyBiomes, Pattern replacement) throws MaxChangedBlocksException { + Mask mask = null; + if (!copyAir) { + mask = new ExistingBlockMask(this); + } + return moveRegion(region, dir, distance, moveEntities, copyBiomes, mask, replacement); + } + /** * Move the blocks in a region a certain direction. * @@ -1509,8 +1487,8 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { * @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws IllegalArgumentException thrown if the region is not a flat region, but copyBiomes is true */ - public int moveRegion(Region region, BlockVector3 dir, int distance, boolean copyAir, - boolean moveEntities, boolean copyBiomes, Pattern replacement) throws MaxChangedBlocksException { + public int moveRegion(Region region, BlockVector3 dir, int distance, + boolean moveEntities, boolean copyBiomes, Mask mask, Pattern replacement) throws MaxChangedBlocksException { checkNotNull(region); checkNotNull(dir); checkArgument(distance >= 1, "distance >= 1 required"); @@ -1538,14 +1516,12 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { copy.setRemovingEntities(moveEntities); copy.setCopyingBiomes(copyBiomes); copy.setRepetitions(1); - Mask sourceMask = getSourceMask(); - if (sourceMask != null) { - new MaskTraverser(sourceMask).reset(this); - copy.setSourceMask(sourceMask); - setSourceMask(null); - } - if (!copyAir) { - copy.setSourceMask(new ExistingBlockMask(this)); + if (mask != null) { + new MaskTraverser(mask).reset(this); + copy.setSourceMask(mask); + if (this.getSourceMask() == mask) { + setSourceMask(null); + } } Operations.completeBlindly(copy); @@ -1699,21 +1675,6 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { return makeCylinder(pos, block, radiusX, radiusZ, height, thickness, false); } - /** - * Stack a cuboid region. For compatibility, entities are copied by biomes are not. - * Use {@link #stackCuboidRegion(Region, BlockVector3, int, boolean, boolean, Mask)} to fine tune. - * - * @param region the region to stack - * @param dir the direction to stack - * @param count the number of times to stack - * @param copyAir true to also copy air blocks - * @return number of blocks affected - * @throws MaxChangedBlocksException thrown if too many blocks are changed - */ - public int stackCuboidRegion(Region region, BlockVector3 dir, int count, boolean copyAir) throws MaxChangedBlocksException { - return stackCuboidRegion(region, dir, count, true, false, copyAir ? null : new ExistingBlockMask(this)); - } - private int makeCylinder(BlockVector3 pos, Pattern block, double radiusX, double radiusZ, int height, double thickness, boolean filled) throws MaxChangedBlocksException { int affected = 0;