From 19fe2efb6e4974dd52c1d4d6760d6ffa0e60d73c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Wed, 13 May 2020 14:11:17 +0200 Subject: [PATCH] Fix the WE extent and add our own tile entity list --- .../plotsquared/bukkit/util/BukkitUtil.java | 31 +++++++++++++++++++ .../com/plotsquared/core/command/Set.java | 3 +- .../core/listener/ProcessedWEExtent.java | 5 +-- .../com/plotsquared/core/util/WorldUtil.java | 4 +++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java index 2371fe799..b1ec78382 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -44,7 +44,10 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.block.BlockCategories; import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockType; +import com.sk89q.worldedit.world.block.BlockTypes; import io.papermc.lib.PaperLib; import lombok.NonNull; import org.bukkit.Bukkit; @@ -95,10 +98,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.function.Consumer; import java.util.function.IntConsumer; +import java.util.stream.Stream; @SuppressWarnings({"unused", "WeakerAccess"}) public class BukkitUtil extends WorldUtil { @@ -638,6 +643,32 @@ public class BukkitUtil extends WorldUtil { return types; } + private final Collection tileEntityTypes = new HashSet<>(); + @Override public Collection getTileEntityTypes() { + if (this.tileEntityTypes.isEmpty()) { + // Categories + tileEntityTypes.addAll(BlockCategories.BANNERS.getAll()); + tileEntityTypes.addAll(BlockCategories.SIGNS.getAll()); + tileEntityTypes.addAll(BlockCategories.BEDS.getAll()); + tileEntityTypes.addAll(BlockCategories.FLOWER_POTS.getAll()); + // Individual Types + // Add these from strings + Stream.of("barrel", "beacon", "beehive", "bell", "blast_furnace", + "brewing_stand", "campfire", "chest", "ender_chest", "trapped_chest", + "command_block", "end_gateway", "hopper", "jigsaw", "jubekox", + "lectern", "note_block", "black_shulker_box", "blue_shulker_box", + "brown_shulker_box", "cyan_shulker_box", "gray_shulker_box", "green_shulker_box", + "light_blue_shulker_box", "light_gray_shulker_box", "lime_shulker_box", + "magenta_shulker_box", "orange_shulker_box", "pink_shulker_box", + "purple_shulker_box", "red_shulker_box", "shulker_box", "white_shulker_box", + "yellow_shulker_box", "smoker", "structure") + .map(BlockTypes::get) + .filter(Objects::nonNull) + .forEach(tileEntityTypes::add); + } + return this.tileEntityTypes; + } + private static void ensureLoaded(final String world, final int x, final int z, final Consumer chunkConsumer) { PaperLib.getChunkAtAsync(getWorld(world), x >> 4, z >> 4, true) diff --git a/Core/src/main/java/com/plotsquared/core/command/Set.java b/Core/src/main/java/com/plotsquared/core/command/Set.java index c6c2b67f3..54befdec9 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Set.java +++ b/Core/src/main/java/com/plotsquared/core/command/Set.java @@ -96,7 +96,8 @@ public class Set extends SubCommand { if (blockType.startsWith("##")) { try { - final BlockCategory category = BlockCategory.REGISTRY.get(blockType.substring(2).toLowerCase(Locale.ENGLISH)); + final BlockCategory category = BlockCategory.REGISTRY.get(blockType.substring(2) + .replaceAll("[*^|]+", "").toLowerCase(Locale.ENGLISH)); if (category == null || !category.contains(BlockTypes.get(forbiddenType))) { continue; } diff --git a/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java b/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java index 5e3f0af8e..ca7eb60e5 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java +++ b/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java @@ -29,6 +29,7 @@ import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.util.WEManager; +import com.plotsquared.core.util.WorldUtil; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; @@ -90,12 +91,12 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { public > boolean setBlock(BlockVector3 location, T block) throws WorldEditException { - final boolean isTile = block.toBaseBlock().getNbtData() != null; + final boolean isTile = WorldUtil.IMP.getTileEntityTypes().contains(block.getBlockType()); if (isTile) { if (this.BSblocked) { return false; } - if (++this.BScount > Settings.Chunk_Processor.MAX_TILES) { + if (++this.BScount >= Settings.Chunk_Processor.MAX_TILES) { this.BSblocked = true; PlotSquared.debug(Captions.PREFIX + "&cDetected unsafe WorldEdit: " + location.getX() + "," + location.getZ()); diff --git a/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java b/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java index 9c7730703..940e908eb 100644 --- a/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java @@ -39,6 +39,7 @@ import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.entity.EntityType; import org.jetbrains.annotations.NotNull; @@ -48,6 +49,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import java.net.URL; +import java.util.Collection; import java.util.Map; import java.util.Set; import java.util.UUID; @@ -216,4 +218,6 @@ public abstract class WorldUtil { public abstract Set getTypesInCategory(final String category); + public abstract Collection getTileEntityTypes(); + }