From 4af7316118c2969c49a7396c8976db6f43b4da26 Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Thu, 25 Mar 2021 08:40:09 +0100 Subject: [PATCH] Remove freebuild regions (#991) * Remove freebuild regions * Remove configuration option of freebuild Co-authored-by: Matt <4009945+MattBDev@users.noreply.github.com> --- .../com/boydti/fawe/bukkit/FaweBukkit.java | 9 - .../fawe/bukkit/regions/FreeBuildRegion.java | 116 -- .../fawe/bukkit/wrapper/AsyncBlock.java | 458 ----- .../fawe/bukkit/wrapper/AsyncBlockState.java | 228 --- .../fawe/bukkit/wrapper/AsyncChunk.java | 209 --- .../fawe/bukkit/wrapper/AsyncWorld.java | 1551 ----------------- .../wrapper/state/AsyncDataContainer.java | 150 -- .../fawe/bukkit/wrapper/state/AsyncSign.java | 125 -- .../java/com/boydti/fawe/config/Settings.java | 7 - 9 files changed, 2853 deletions(-) delete mode 100644 worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java delete mode 100644 worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java delete mode 100644 worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlockState.java delete mode 100644 worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncChunk.java delete mode 100644 worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java delete mode 100644 worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncDataContainer.java delete mode 100644 worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncSign.java diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java index be3473b80..ad8584343 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 @@ -13,7 +13,6 @@ import com.boydti.fawe.bukkit.listener.BukkitImageListener; import com.boydti.fawe.bukkit.listener.CFIPacketListener; import com.boydti.fawe.bukkit.listener.ChunkListener9; import com.boydti.fawe.bukkit.listener.RenderListener; -import com.boydti.fawe.bukkit.regions.FreeBuildRegion; import com.boydti.fawe.bukkit.regions.GriefPreventionFeature; import com.boydti.fawe.bukkit.regions.ResidenceFeature; import com.boydti.fawe.bukkit.regions.TownyFeature; @@ -239,14 +238,6 @@ public class FaweBukkit implements IFawe, Listener { } } - if (Settings.IMP.EXPERIMENTAL.FREEBUILD) { - try { - managers.add(new FreeBuildRegion()); - log.debug("Attempting to use plugin ''"); - } catch (Throwable ignored) { - } - } - return managers; } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java deleted file mode 100644 index 134c8c270..000000000 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.boydti.fawe.bukkit.regions; - -import com.boydti.fawe.bukkit.wrapper.AsyncBlock; -import com.boydti.fawe.bukkit.wrapper.AsyncWorld; -import com.boydti.fawe.regions.FaweMask; -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.bukkit.BukkitPlayer; -import com.sk89q.worldedit.entity.Player; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.regions.CuboidRegion; -import com.sk89q.worldedit.regions.Region; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.event.EventException; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.plugin.RegisteredListener; - -import java.util.ArrayList; -import java.util.Locale; - -public class FreeBuildRegion extends BukkitMaskManager { - private final ArrayList listeners; - - public FreeBuildRegion() { - super("freebuild"); - this.listeners = new ArrayList<>(); - RegisteredListener[] listeners = BlockBreakEvent.getHandlerList().getRegisteredListeners(); - for (RegisteredListener listener : listeners) { - if (listener.getPriority() == EventPriority.MONITOR) { - continue; - } - if (!listener.isIgnoringCancelled()) { - continue; - } - this.listeners.add(listener); - } - } - - @Override - public boolean isExclusive() { - return true; - } - - @Override - public FaweMask getMask(Player player, MaskType type) { - if (type != MaskType.MEMBER) { - return null; - } - ArrayList currRegList = new ArrayList<>(); - for (RegisteredListener listener : this.listeners) { - String name = listener.getPlugin().getName(); - if (!player.hasPermission("fawe.freebuild." + name.toLowerCase(Locale.ROOT))) { - continue; - } - currRegList.add(listener); - } - if (currRegList.isEmpty()) { - return null; - } - RegisteredListener[] listeners = currRegList.toArray(new RegisteredListener[0]); - - World bukkitWorld = BukkitAdapter.adapt(player.getWorld()); - AsyncWorld asyncWorld = AsyncWorld.wrap(bukkitWorld); - - BlockVector3 pos1 = BlockVector3.ZERO; - BlockVector3 pos2 = BlockVector3.ZERO; - - AsyncBlock block = new AsyncBlock(asyncWorld, 0, 0, 0); - BlockBreakEvent event = new BlockBreakEvent(block, ((BukkitPlayer) player).getPlayer()); - - return new FaweMask(new CuboidRegion(pos1, pos2)) { - - @Override - public boolean isValid(Player player, MaskType type) { - return bukkitWorld == BukkitAdapter.adapt(player.getWorld()) && type == MaskType.MEMBER; - } - - @Override - public Region getRegion() { - return new CuboidRegion(BlockVector3.ZERO, BlockVector3.ZERO) { - - @Override - public boolean contains(int x, int z) { - return contains(x, 127, z); - } - - private int lastX = Integer.MIN_VALUE; - private int lastZ = Integer.MIN_VALUE; - private boolean lastResult; - - @Override - public boolean contains(int x, int y, int z) { - if (x == lastX && z == lastZ) { - return lastResult; - } - lastX = x; - lastZ = z; - event.setCancelled(false); - block.setPosition(x, y, z); - try { - synchronized (Bukkit.getPluginManager()) { - for (RegisteredListener listener : listeners) { - listener.callEvent(event); - } - } - } catch (EventException e) { - throw new RuntimeException(e); - } - return lastResult = !event.isCancelled(); - } - }; - } - }; - } -} diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java deleted file mode 100644 index 20c7abe1f..000000000 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java +++ /dev/null @@ -1,458 +0,0 @@ -package com.boydti.fawe.bukkit.wrapper; - -import com.boydti.fawe.bukkit.wrapper.state.AsyncSign; -import com.boydti.fawe.util.TaskManager; -import com.destroystokyo.paper.block.BlockSoundGroup; -import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.world.biome.BiomeType; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockID; -import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockTypes; -import com.sk89q.worldedit.world.block.BlockTypesCache; -import org.bukkit.FluidCollisionMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.PistonMoveReaction; -import org.bukkit.block.data.BlockData; -import org.bukkit.entity.Entity; -import org.bukkit.inventory.ItemStack; -import org.bukkit.metadata.MetadataValue; -import org.bukkit.plugin.Plugin; -import org.bukkit.util.BoundingBox; -import org.bukkit.util.RayTraceResult; -import org.bukkit.util.Vector; - -import javax.annotation.Nonnull; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -public class AsyncBlock implements Block { - - public int z; - public int y; - public int x; - public final AsyncWorld world; - - public AsyncBlock(AsyncWorld world, int x, int y, int z) { - this.world = world; - this.x = x; - this.y = Math.max(0, Math.min(255, y)); - this.z = z; - } - - public void setPosition(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - @Override - @Deprecated - public byte getData() { - return (byte) getPropertyId(); - } - - public int getPropertyId() { - return world.getBlock(x, y, z).getInternalId() >> BlockTypesCache.BIT_OFFSET; - } - - public int getCombinedId() { - return world.getBlock(x, y, z).getInternalId(); - } - - public int getTypeId() { - return world.getBlock(x, y, z).getBlockType().getInternalId(); - } - - @Nonnull - @Override - public AsyncBlock getRelative(int modX, int modY, int modZ) { - return new AsyncBlock(world, x + modX, y + modY, z + modZ); - } - - @Nonnull - @Override - public AsyncBlock getRelative(BlockFace face) { - return this.getRelative(face.getModX(), face.getModY(), face.getModZ()); - } - - @Nonnull - @Override - public AsyncBlock getRelative(BlockFace face, int distance) { - return this.getRelative(face.getModX() * distance, face.getModY() * distance, - face.getModZ() * distance); - } - - @Nonnull - @Override - public Material getType() { - return getBlockData().getMaterial(); - } - - @Nonnull - @Override - public BlockData getBlockData() { - return BukkitAdapter.adapt(world.getBlock(x, y, z)); - } - - @Deprecated - public boolean setTypeIdAndPropertyId(int id, int propertyId, boolean physics) { - return setTypeIdAndPropertyId(id, propertyId); - } - - @Deprecated - public boolean setTypeIdAndPropertyId(int id, int propertyId) { - return setCombinedId(id + (propertyId << BlockTypesCache.BIT_OFFSET)); - } - - @Deprecated - public boolean setCombinedId(int combinedId) { - return world.setBlock(x, y, z, BlockState.getFromInternalId(combinedId)); - } - - @Deprecated - public boolean setTypeId(int typeId) { - return world.setBlock(x, y, z, BlockTypes.get(typeId).getDefaultState()); - } - - @Deprecated - public boolean setPropertyId(int propertyId) { - return setTypeIdAndPropertyId(getTypeId(), propertyId); - } - - @Override - public byte getLightLevel() { - return (byte) 15; - } - - @Override - public byte getLightFromSky() { - return (byte) 15; - } - - @Override - public byte getLightFromBlocks() { - return (byte) 15; - } - - @Nonnull - @Override - public AsyncWorld getWorld() { - return world; - } - - @Override - public int getX() { - return x; - } - - @Override - public int getY() { - return y; - } - - @Override - public int getZ() { - return z; - } - - @Override - public boolean isValidTool(@Nonnull ItemStack itemStack) { - return getDrops(itemStack).size() !=0; - } - - @Nonnull - @Override - public Location getLocation() { - return new Location(world, x, y, z); - } - - @Override - public Location getLocation(Location loc) { - if (loc != null) { - loc.setWorld(this.getWorld()); - loc.setX(this.x); - loc.setY(this.y); - loc.setZ(this.z); - } - return loc; - } - - @Nonnull - @Override - public AsyncChunk getChunk() { - return world.getChunkAt(x >> 4, z >> 4); - } - - @Override - public void setBlockData(@Nonnull BlockData blockData) { - try { - world.setBlock(x, y, z, BukkitAdapter.adapt(blockData)); - } catch (WorldEditException e) { - throw new RuntimeException(e); - } - } - - @Override - public void setBlockData(@Nonnull BlockData blockData, boolean b) { - setBlockData(blockData); - } - - @Override - public void setType(@Nonnull Material type) { - try { - world.setBlock(x, y, z, BukkitAdapter.asBlockType(type).getDefaultState()); - } catch (WorldEditException e) { - throw new RuntimeException(e); - } - } - - @Override - public void setType(@Nonnull Material type, boolean applyPhysics) { - setType(type); - } - - @Override - public BlockFace getFace(@Nonnull Block block) { - BlockFace[] directions = BlockFace.values(); - for (BlockFace face : directions) { - if (this.getX() + face.getModX() == block.getX() - && this.getY() + face.getModY() == block.getY() - && this.getZ() + face.getModZ() == block.getZ()) { - return face; - } - } - return null; - } - - @Nonnull - @Override - public AsyncBlockState getState() { - BaseBlock state = world.getFullBlock(x, y, z); - switch (state.getBlockType().getInternalId()) { - case BlockID.ACACIA_SIGN: - case BlockID.SPRUCE_SIGN: - case BlockID.ACACIA_WALL_SIGN: - case BlockID.BIRCH_SIGN: - case BlockID.SPRUCE_WALL_SIGN: - case BlockID.BIRCH_WALL_SIGN: - case BlockID.DARK_OAK_SIGN: - case BlockID.DARK_OAK_WALL_SIGN: - case BlockID.JUNGLE_SIGN: - case BlockID.JUNGLE_WALL_SIGN: - case BlockID.OAK_SIGN: - case BlockID.OAK_WALL_SIGN: - return new AsyncSign(this, state); - default: - return new AsyncBlockState(this, state); - } - } - - @Override - @Nonnull - public AsyncBlockState getState(boolean useSnapshot) { - return getState(); - } - - @Nonnull - @Override - public Biome getBiome() { - return world.getAdapter().adapt(world.getBiomeType(x, y, z)); - } - - @Override - public void setBiome(@Nonnull Biome bio) { - BiomeType biome = world.getAdapter().adapt(bio); - world.setBiome(x, 0, z, biome); - } - - @Override - public boolean isBlockPowered() { - return false; - } - - @Override - public boolean isBlockIndirectlyPowered() { - return false; - } - - @Override - public boolean isBlockFacePowered(@Nonnull BlockFace face) { - return false; - } - - @Override - public boolean isBlockFaceIndirectlyPowered(@Nonnull BlockFace face) { - return false; - } - - @Override - public int getBlockPower(@Nonnull BlockFace face) { - return 0; - } - - @Override - public int getBlockPower() { - return 0; - } - - @Override - public boolean isEmpty() { - switch (getType()) { - case AIR: - case CAVE_AIR: - case VOID_AIR: - return true; - default: - return false; - } - } - - @Override - public boolean isLiquid() { - return world.getBlock(x, y, z).getMaterial().isLiquid(); - } - - @Override - public boolean isBuildable() { - return this.getUnsafeBlock().isBuildable(); - } - - @Override - public boolean isBurnable() { - return this.getType().isBurnable(); - } - - @Override - public boolean isReplaceable() { - return this.getUnsafeBlock().isReplaceable(); - } - - @Override - public double getTemperature() { - return this.getWorld().getTemperature(this.getX(), this.getZ()); - } - - @Override - public double getHumidity() { - return this.getWorld().getHumidity(this.getX(), this.getZ()); - } - - @Nonnull - @Override - public PistonMoveReaction getPistonMoveReaction() { - return PistonMoveReaction.IGNORE; - } - - @Deprecated - private Block getUnsafeBlock() { - return world.getBukkitWorld().getBlockAt(x, y, z); - } - - @Override - public boolean breakNaturally() { - return TaskManager.IMP.sync(() -> getUnsafeBlock().breakNaturally()); - } - - @Override - public boolean breakNaturally(@Nonnull ItemStack tool) { - return TaskManager.IMP.sync(() -> getUnsafeBlock().breakNaturally(tool)); - } - - public boolean breakNaturally(@Nonnull ItemStack tool, boolean value) { - return TaskManager.IMP.sync(() -> getUnsafeBlock().breakNaturally(tool)); - } - - @Nonnull - @Override - public Collection getDrops() { - return TaskManager.IMP.sync(() -> getUnsafeBlock().getDrops()); - } - - @Nonnull - @Override - public Collection getDrops(@Nonnull ItemStack tool) { - return TaskManager.IMP.sync(() -> getUnsafeBlock().getDrops(tool)); - } - - public Collection getDrops(ItemStack tool, Entity entity) { - return Collections.emptyList(); //todo - } - - @Override - public void setMetadata(@Nonnull String metadataKey, @Nonnull MetadataValue newMetadataValue) { - this.getUnsafeBlock().setMetadata(metadataKey, newMetadataValue); - } - - @Nonnull - @Override - public List getMetadata(@Nonnull String metadataKey) { - return this.getUnsafeBlock().getMetadata(metadataKey); - } - - @Override - public boolean hasMetadata(@Nonnull String metadataKey) { - return this.getUnsafeBlock().hasMetadata(metadataKey); - } - - @Override - public void removeMetadata(@Nonnull String metadataKey, @Nonnull Plugin owningPlugin) { - this.getUnsafeBlock().removeMetadata(metadataKey, owningPlugin); - } - - @Override - public boolean isPassable() { - return this.getUnsafeBlock().isPassable(); - } - - @Override - public RayTraceResult rayTrace(@Nonnull Location arg0, @Nonnull Vector arg1, double arg2, - @Nonnull FluidCollisionMode arg3) { - return this.getUnsafeBlock().rayTrace(arg0, arg1, arg2, arg3); - } - - public boolean applyBoneMeal(@Nonnull BlockFace face) { - throw new UnsupportedOperationException("FAWE does not support this yet"); - } - - public String getTranslationKey() { - throw new UnsupportedOperationException("FAWE does not support this yet"); - } - - @Nonnull - @Override - public float getDestroySpeed(@Nonnull ItemStack itemStack) { - throw new UnsupportedOperationException("FAWE does not support this yet"); - } - - @Nonnull - @Override - public float getDestroySpeed(@Nonnull ItemStack itemStack, boolean considerEnchants) { - throw new UnsupportedOperationException("FAWE does not support this yet"); - } - - @Nonnull - @Override - public BoundingBox getBoundingBox() { - return this.getUnsafeBlock().getBoundingBox(); - } - - @Override - @Nonnull - public BlockSoundGroup getSoundGroup() { - return TaskManager.IMP.sync(() -> getUnsafeBlock().getSoundGroup()); - } - - @Override - @Nonnull - public boolean isSolid() { - return this.getType().isSolid(); - } - -} diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlockState.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlockState.java deleted file mode 100644 index 03d1dd07c..000000000 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlockState.java +++ /dev/null @@ -1,228 +0,0 @@ -package com.boydti.fawe.bukkit.wrapper; - -import com.sk89q.jnbt.CompoundTag; -import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockType; -import com.sk89q.worldedit.world.block.BlockTypesCache; -import org.bukkit.Chunk; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockState; -import org.bukkit.block.data.BlockData; -import org.bukkit.material.MaterialData; -import org.bukkit.metadata.MetadataValue; -import org.bukkit.plugin.Plugin; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -public class AsyncBlockState implements BlockState { - - private BaseBlock state; - private BlockData blockData; - private final AsyncBlock block; - - public AsyncBlockState(AsyncBlock block, BaseBlock state) { - this.state = state; - this.block = block; - this.blockData = BukkitAdapter.adapt(state); - } - - public int getTypeId() { - return state.getBlockType().getInternalId(); - } - - public int getPropertyId() { - return state.getInternalId() >> BlockTypesCache.BIT_OFFSET; - } - - @Override - public Block getBlock() { - return block; - } - - @Override - public BlockData getBlockData() { - return blockData; - } - - @Override - public MaterialData getData() { - return new MaterialData(blockData.getMaterial()); - } - - @Override - public Material getType() { - return blockData.getMaterial(); - } - - @Override - public byte getLightLevel() { - return (byte) state.getMaterial().getLightValue(); - } - - @Override - public AsyncWorld getWorld() { - return block.world; - } - - @Override - public int getX() { - return block.x; - } - - @Override - public int getY() { - return block.y; - } - - @Override - public int getZ() { - return block.z; - } - - @Override - public Location getLocation() { - return block.getLocation(); - } - - @Override - public Location getLocation(Location loc) { - return block.getLocation(loc); - } - - @NotNull - @Override - public Chunk getChunk() { - return block.getChunk(); - } - - @Override - public void setData(MaterialData data) { - setBlockData(data.getItemType().createBlockData()); - } - - @Override - public void setBlockData(BlockData blockData) { - this.blockData = blockData; - CompoundTag nbt = this.getNbtData(); - BlockType oldType = state.getBlockType(); - com.sk89q.worldedit.world.block.BlockState newState = BukkitAdapter.adapt(blockData); - if (nbt != null && newState.getBlockType() == oldType) { - this.setNbtData(nbt); - } else { - state = newState.toBaseBlock(); - } - } - - @Override - public void setType(Material type) { - setBlockData(type.createBlockData()); - } - - @Override - public boolean update() { - return update(false); - } - - @Override - public boolean update(boolean force) { - return update(force, true); - } - - @Override - public boolean update(boolean force, boolean applyPhysics) { - try { - return block.world.setBlock(block.x, block.y, block.z, state); - } catch (WorldEditException e) { - throw new RuntimeException(e); - } - } - - /** - * Returns the (unmodifiable) tag compound that belongs to this block state. - * If the block state is null, this will return null. - * - * @return NBT data - */ - public synchronized @Nullable CompoundTag getNbtData() { - if (this.state == null) { - return null; - } - return state.getNbtData(); - } - - /** - * Clone the NBT {@link CompoundTag} into a new {@link Map}. - * - * @return Modifiable clone of NBT data - */ - public @NotNull Map cloneNbtMap() { - return Optional.ofNullable(this.getNbtData()).map(CompoundTag::getValue) - .map(HashMap::new).orElse(new HashMap<>()); - } - - /** - * Set the NBT data of the block. - * - * @param nbt New NBT data - */ - public synchronized void setNbtData(@Nullable final CompoundTag nbt) { - state = this.state.toBaseBlock(nbt); - } - - /** - * Set the NBT data of the block. - * - * @param map New NBT data - */ - public void setNbtData(@NotNull final Map map) { - this.setNbtData(new CompoundTag(map)); - } - - @Override - public byte getRawData() { - return (byte) (state.getInternalId() >> BlockTypesCache.BIT_OFFSET); - } - - @Override - public void setRawData(byte data) { - int combinedId = getTypeId() + (data << BlockTypesCache.BIT_OFFSET); - state = com.sk89q.worldedit.world.block.BlockState.getFromInternalId(combinedId) - .toBaseBlock(this.getNbtData()); - this.blockData = BukkitAdapter.adapt(state); - } - - @Override - public boolean isPlaced() { - return true; - } - - @Override - public void setMetadata(String key, MetadataValue value) { - block.setMetadata(key, value); - } - - @Override - public List getMetadata(String key) { - return block.getMetadata(key); - } - - @Override - public boolean hasMetadata(String key) { - return block.hasMetadata(key); - } - - @Override - public void removeMetadata(String key, Plugin plugin) { - block.removeMetadata(key, plugin); - } -} diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncChunk.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncChunk.java deleted file mode 100644 index 030e86c78..000000000 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncChunk.java +++ /dev/null @@ -1,209 +0,0 @@ -package com.boydti.fawe.bukkit.wrapper; - -import com.boydti.fawe.Fawe; -import com.boydti.fawe.util.MathMan; -import com.boydti.fawe.util.TaskManager; -import org.bukkit.Chunk; -import org.bukkit.ChunkSnapshot; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.BlockState; -import org.bukkit.block.data.BlockData; -import org.bukkit.entity.Entity; -import org.bukkit.persistence.PersistentDataContainer; -import org.bukkit.plugin.Plugin; -import org.jetbrains.annotations.NotNull; - -import java.util.Collection; -import java.util.Collections; -import java.util.function.Predicate; -import java.util.function.Supplier; - -public class AsyncChunk implements Chunk { - - private final AsyncWorld world; - private final int z; - private final int x; - - public AsyncChunk(World world, int x, int z) { - this.world = world instanceof AsyncWorld ? (AsyncWorld) world : new AsyncWorld(world, true); - this.x = x; - this.z = z; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Chunk)) { - return false; - } - Chunk other = (Chunk) obj; - return other.getX() == x && other.getZ() == z && world.equals(other.getWorld()); - } - - @Override - public int hashCode() { - return MathMan.pair((short) x, (short) z); - } - - @Override - public int getX() { - return x; - } - - @Override - public int getZ() { - return z; - } - - @Override - public long getChunkKey() { - return Chunk.getChunkKey(getX(), getZ()); - } - - @Override - public AsyncWorld getWorld() { - return world; - } - - @Override - public AsyncBlock getBlock(int x, int y, int z) { - return new AsyncBlock(world, (this.x << 4) + x, y, (this.z << 4) + z); - } - - @Override - public ChunkSnapshot getChunkSnapshot() { - return getChunkSnapshot(false, true, false); - } - - @Override - public ChunkSnapshot getChunkSnapshot(boolean includeMaxblocky, boolean includeBiome, - boolean includeBiomeTempRain) { - if (Fawe.isMainThread()) { - return world.getChunkAt(x, z) - .getChunkSnapshot(includeMaxblocky, includeBiome, includeBiomeTempRain); - } - return whenLoaded(() -> world.getChunkAt(x, z) - .getChunkSnapshot(includeBiome, includeBiome, includeBiomeTempRain)); - } - - private T whenLoaded(Supplier task) { - if (Fawe.isMainThread()) { - return task.get(); - } - if (world.isWorld()) { - if (world.isChunkLoaded(x, z)) { - return task.get(); - } - } - return TaskManager.IMP.sync(task); - } - - @Override - public Entity[] getEntities() { - if (!isLoaded()) { - return new Entity[0]; - } - return whenLoaded(() -> world.getChunkAt(x, z).getEntities()); - } - - @Override - public BlockState[] getTileEntities() { - if (!isLoaded()) { - return new BlockState[0]; - } - return TaskManager.IMP.sync(() -> world.getChunkAt(x, z).getTileEntities()); - } - - @Override - @NotNull - public BlockState[] getTileEntities(boolean useSnapshot) { - if (!isLoaded()) { - return new BlockState[0]; - } - return TaskManager.IMP.sync(() -> world.getChunkAt(x, z).getTileEntities(useSnapshot)); - } - - @NotNull @Override - public Collection getTileEntities(@NotNull Predicate blockPredicate, - boolean useSnapshot) { - if (!isLoaded()) { - return Collections.emptyList(); - } - return TaskManager.IMP.sync(() -> world.getChunkAt(x, z) - .getTileEntities(blockPredicate, useSnapshot)); - } - - @Override - public boolean isLoaded() { - return world.isChunkLoaded(x, z); - } - - @Override - public boolean load(final boolean generate) { - return TaskManager.IMP.sync(() -> world.loadChunk(x, z, generate)); - } - - @Override - public boolean load() { - return load(false); - } - - public boolean unload(boolean save) { - return world.unloadChunk(x, z, save); - } - - @Override - public boolean unload() { - return unload(true); - } - - @Override - public boolean isSlimeChunk() { - return TaskManager.IMP.sync(() -> world.getChunkAt(x, z).isSlimeChunk()); - } - - @Override - public boolean isForceLoaded() { - return world.isChunkForceLoaded(x, z); - } - - @Override - public void setForceLoaded(boolean arg0) { - world.getChunkAt(x, z).setForceLoaded(arg0); - } - - @Override - public boolean addPluginChunkTicket(final Plugin plugin) { - return world.addPluginChunkTicket(this.getX(), this.getZ(), plugin); - } - - @Override - public boolean removePluginChunkTicket(final Plugin plugin) { - return world.removePluginChunkTicket(this.getX(), this.getZ(), plugin); - } - - @Override - public Collection getPluginChunkTickets() { - return world.getPluginChunkTickets(this.getX(), this.getZ()); - } - - @Override - public long getInhabitedTime() { - return TaskManager.IMP.sync(() -> world.getChunkAt(x, z).getInhabitedTime()); - } - - @Override - public void setInhabitedTime(long ticks) { - world.getChunkAt(x, z).setInhabitedTime(ticks); - } - - @Override - public boolean contains(@NotNull BlockData block) { - return TaskManager.IMP.sync(() -> world.getChunkAt(x, z).contains(block)); - } - - @Override - public @NotNull PersistentDataContainer getPersistentDataContainer() { - return TaskManager.IMP.sync(() -> world.getChunkAt(x, z).getPersistentDataContainer()); - } -} diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java deleted file mode 100644 index 0beb65f7a..000000000 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java +++ /dev/null @@ -1,1551 +0,0 @@ -package com.boydti.fawe.bukkit.wrapper; - -import com.boydti.fawe.FaweAPI; -import com.boydti.fawe.object.RunnableVal; -import com.boydti.fawe.util.StringMan; -import com.boydti.fawe.util.TaskManager; -import com.destroystokyo.paper.HeightmapType; -import com.google.common.annotations.Beta; -import com.sk89q.worldedit.bukkit.BukkitWorld; -import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; -import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.extent.PassthroughExtent; -import com.sk89q.worldedit.function.operation.Operation; -import com.sk89q.worldedit.world.biome.BiomeType; -import com.sk89q.worldedit.world.block.BlockState; -import io.papermc.paper.world.MoonPhase; -import org.bukkit.BlockChangeDelegate; -import org.bukkit.Bukkit; -import org.bukkit.Chunk; -import org.bukkit.ChunkSnapshot; -import org.bukkit.Difficulty; -import org.bukkit.Effect; -import org.bukkit.FluidCollisionMode; -import org.bukkit.GameRule; -import org.bukkit.HeightMap; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.NamespacedKey; -import org.bukkit.Particle; -import org.bukkit.Raid; -import org.bukkit.Sound; -import org.bukkit.SoundCategory; -import org.bukkit.StructureType; -import org.bukkit.TreeType; -import org.bukkit.World; -import org.bukkit.WorldBorder; -import org.bukkit.WorldCreator; -import org.bukkit.WorldType; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.boss.DragonBattle; -import org.bukkit.entity.AbstractArrow; -import org.bukkit.entity.Arrow; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.FallingBlock; -import org.bukkit.entity.Item; -import org.bukkit.entity.LightningStrike; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.generator.BlockPopulator; -import org.bukkit.generator.ChunkGenerator; -import org.bukkit.inventory.ItemStack; -import org.bukkit.material.MaterialData; -import org.bukkit.metadata.MetadataValue; -import org.bukkit.plugin.Plugin; -import org.bukkit.util.BoundingBox; -import org.bukkit.util.Consumer; -import org.bukkit.util.RayTraceResult; -import org.bukkit.util.Vector; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import java.util.function.Predicate; - -/** - * Modify the world from an async thread
- * - Use world.commit() to execute all the changes
- * - Any Chunk/Block/BlockState objects returned should also be safe to use from the same async thread
- * - Only block read,write and biome write are fast, other methods will perform slower async
- * - - * - * @see #wrap(World) - * @see #create(WorldCreator) - */ -@SuppressWarnings("deprecation") -public class AsyncWorld extends PassthroughExtent implements World { - - private World parent; - private BukkitImplAdapter adapter; - - @Override - public void spawnParticle(@NotNull Particle particle, double v, double v1, double v2, int i, - double v3, double v4, double v5, double v6, T t) { - parent.spawnParticle(particle, v, v1, v2, i, v3, v4, v5, v6, t); - } - - /** - * An internal constructor for using a world asynchronously in FAWE. Do not use! - */ - @Deprecated - public AsyncWorld(World parent, boolean autoQueue) { - this(parent, FaweAPI.createQueue(new BukkitWorld(parent), autoQueue)); - } - - public AsyncWorld(String world, boolean autoQueue) { - this(Bukkit.getWorld(world), autoQueue); - } - - /** - * An internal constructor for using a world asynchronously in FAWE. Do not use! - */ - @Deprecated - public AsyncWorld(World parent, Extent extent) { - super(extent); - this.parent = parent; - this.adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); - } - - /** - * Wrap a world for async usage. - */ - public static AsyncWorld wrap(World world) { - if (world instanceof AsyncWorld) { - return (AsyncWorld) world; - } - return new AsyncWorld(world, false); - } - - @Override - public String toString() { - return getName(); - } - - public World getBukkitWorld() { - return parent; - } - - /** - * Create a world async. This is not tested and may be removed in the future due to - * synchronization problems. - */ - @Beta - public static synchronized AsyncWorld create(final WorldCreator creator) { - BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); - @Nullable World world = adapter.createWorld(creator); - return wrap(world); - } - - @Override - public Operation commit() { - flush(); - return null; - } - - public void flush() { - getExtent().commit(); - } - - @Override - @NotNull - public WorldBorder getWorldBorder() { - return TaskManager.IMP.sync(() -> parent.getWorldBorder()); - } - - @Override - public void spawnParticle(@NotNull Particle particle, @NotNull Location location, int i) { - parent.spawnParticle(particle, location, i); - } - - @Override - public void spawnParticle(@NotNull Particle particle, double v, double v1, double v2, int i) { - parent.spawnParticle(particle, v, v1, v2, i); - } - - @Override - public void spawnParticle(@NotNull Particle particle, @NotNull Location location, int i, - T t) { - parent.spawnParticle(particle, location, i, t); - } - - @Override - public void spawnParticle(@NotNull Particle particle, double x, double y, double z, - int count, T data) { - parent.spawnParticle(particle, x, y, z, count, data); - } - - @Override - public void spawnParticle(@NotNull Particle particle, @NotNull Location location, int count, - double offsetX, double offsetY, double offsetZ) { - parent.spawnParticle(particle, location, count, offsetX, offsetY, offsetZ); - } - - @Override - public void spawnParticle(@NotNull Particle particle, double v, double v1, double v2, int i, - double v3, double v4, double v5) { - parent.spawnParticle(particle, v, v1, v2, i, v3, v4, v5); - } - - @Override - public void spawnParticle(@NotNull Particle particle, @NotNull Location location, int i, - double v, double v1, double v2, T t) { - parent.spawnParticle(particle, location, i, v, v1, v2, t); - } - - @Override - public void spawnParticle(@NotNull Particle particle, double v, double v1, double v2, int i, - double v3, double v4, double v5, T t) { - parent.spawnParticle(particle, v, v1, v2, i, v3, v4, v5, t); - } - - @Override - public void spawnParticle(@NotNull Particle particle, @NotNull Location location, int i, - double v, double v1, double v2, double v3) { - parent.spawnParticle(particle, location, i, v, v1, v2, v3); - } - - @Override - public void spawnParticle(@NotNull Particle particle, double v, double v1, double v2, int i, - double v3, double v4, double v5, double v6) { - parent.spawnParticle(particle, v, v1, v2, i, v3, v4, v5, v6); - } - - @Override - public void spawnParticle(@NotNull Particle particle, @NotNull Location location, int i, - double v, double v1, double v2, double v3, T t) { - parent.spawnParticle(particle, location, i, v, v1, v2, v3, t); - } - - @Override - public boolean setSpawnLocation(@NotNull Location location) { - return parent.setSpawnLocation(location); - } - - @Override - @NotNull - public AsyncBlock getBlockAt(final int x, final int y, final int z) { - return new AsyncBlock(this, x, y, z); - } - - @Override - @NotNull - public AsyncBlock getBlockAt(Location loc) { - return getBlockAt(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); - } - - @Override - public int getHighestBlockYAt(int x, int z) { - for (int y = getMaxHeight() - 1; y >= 0; y--) { - BlockState state = this.getBlock(x, y, z); - if (!state.getMaterial().isAir()) { - return y; - } - } - return 0; - } - - @Override - public int getHighestBlockYAt(Location loc) { - return getHighestBlockYAt(loc.getBlockX(), loc.getBlockZ()); - } - - @Override - @NotNull - public AsyncBlock getHighestBlockAt(int x, int z) { - int y = getHighestBlockYAt(x, z); - return getBlockAt(x, y, z); - } - - @Override - @NotNull - public AsyncBlock getHighestBlockAt(Location loc) { - return getHighestBlockAt(loc.getBlockX(), loc.getBlockZ()); - } - - @Override - public int getHighestBlockYAt(int i, int i1, @NotNull HeightMap heightMap) { - return parent.getHighestBlockYAt(i, i1, heightMap); - } - - @Override - public int getHighestBlockYAt(@NotNull Location location, @NotNull HeightMap heightMap) { - return parent.getHighestBlockYAt(location, heightMap); - } - - @Override - @NotNull - public Block getHighestBlockAt(int i, int i1, @NotNull HeightMap heightMap) { - return parent.getHighestBlockAt(i, i1, heightMap); - } - - @Override - @NotNull - public Block getHighestBlockAt(@NotNull Location location, - @NotNull HeightMap heightMap) { - return parent.getHighestBlockAt(location, heightMap); - } - - @Override - @NotNull - public AsyncChunk getChunkAt(int x, int z) { - return new AsyncChunk(this, x, z); - } - - @Override - @NotNull - public AsyncChunk getChunkAt(Location location) { - return getChunkAt(location.getBlockX(), location.getBlockZ()); - } - - @Override - @NotNull - public AsyncChunk getChunkAt(Block block) { - return getChunkAt(block.getX(), block.getZ()); - } - - @Override - public boolean isChunkGenerated(int x, int z) { - return parent.isChunkGenerated(x, z); - } - - @Override - public boolean isChunkLoaded(Chunk chunk) { - return chunk.isLoaded(); - } - - @NotNull - @Override - public Chunk[] getLoadedChunks() { - return parent.getLoadedChunks(); - } - - @Override - public void loadChunk(final Chunk chunk) { - if (!chunk.isLoaded()) { - TaskManager.IMP.sync(new RunnableVal() { - @Override - public void run(Object value) { - parent.loadChunk(chunk); - } - }); - } - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof World)) { - return false; - } - World other = (World) obj; - return StringMan.isEqual(other.getName(), getName()); - } - - @Override - public int hashCode() { - return this.getUID().hashCode(); - } - - @Override - public boolean isChunkLoaded(int x, int z) { - return parent.isChunkLoaded(x, z); - } - - @Override - @Deprecated - public boolean isChunkInUse(int x, int z) { - return parent.isChunkInUse(x, z); - } - - @Override - public void loadChunk(final int x, final int z) { - if (!isChunkLoaded(x, z)) { - TaskManager.IMP.sync(new RunnableVal() { - @Override - public void run(Object value) { - parent.loadChunk(x, z); - } - }); - } - } - - @Override - public boolean loadChunk(final int x, final int z, final boolean generate) { - if (!isChunkLoaded(x, z)) { - return TaskManager.IMP.sync(() -> parent.loadChunk(x, z, generate)); - } - return true; - } - - @Override - public boolean unloadChunk(final Chunk chunk) { - if (chunk.isLoaded()) { - return TaskManager.IMP.sync(() -> parent.unloadChunk(chunk)); - } - return true; - } - - @Override - public boolean unloadChunk(int x, int z) { - return unloadChunk(x, z, true); - } - - @Override - public boolean unloadChunk(int x, int z, boolean save) { - if (isChunkLoaded(x, z)) { - return TaskManager.IMP.sync(() -> parent.unloadChunk(x, z, save)); - } - return true; - } - - @Override - public boolean unloadChunkRequest(int x, int z) { - if (isChunkLoaded(x, z)) { - return TaskManager.IMP.sync(() -> parent.unloadChunkRequest(x, z)); - } - return true; - } - - @Override - @Deprecated - public boolean regenerateChunk(final int x, final int z) { - return TaskManager.IMP.sync(() -> parent.regenerateChunk(x, z)); - } - - @Override - @Deprecated - public boolean refreshChunk(int x, int z) { - return parent.refreshChunk(x, z); - } - - @Override - @NotNull - public Item dropItem( - @NotNull - final Location location, @NotNull - final ItemStack item) { - return TaskManager.IMP.sync(() -> parent.dropItem(location, item)); - } - - @Override - @NotNull - public Item dropItem( - @NotNull Location location, - @NotNull ItemStack item, - @Nullable Consumer function) { - return TaskManager.IMP.sync(() -> parent.dropItem(location, item)); - } - - @Override - @NotNull - public Item dropItemNaturally( - @NotNull - final Location location, - @NotNull - final ItemStack item) { - return TaskManager.IMP.sync(() -> parent.dropItemNaturally(location, item)); - } - - @Override - @NotNull - public Item dropItemNaturally( - @NotNull - Location location, - @NotNull ItemStack item, - @Nullable Consumer function) { - return TaskManager.IMP.sync(() -> parent.dropItemNaturally(location, item)); - } - - @Override - @NotNull - public Arrow spawnArrow( - @NotNull - final Location location, - @NotNull - final Vector direction, final float speed, final float spread) { - return TaskManager.IMP.sync(() -> parent.spawnArrow(location, direction, speed, spread)); - } - - @NotNull - @Override - public T spawnArrow(@NotNull Location location, - @NotNull Vector direction, float speed, float spread, @NotNull Class clazz) { - return parent.spawnArrow(location, direction, speed, spread, clazz); - } - - @Override - public boolean generateTree( - @NotNull - final Location location, @NotNull - final TreeType type) { - return TaskManager.IMP.sync(() -> parent.generateTree(location, type)); - } - - @Override - public boolean generateTree( - @NotNull - final Location loc, @NotNull - final TreeType type, - @NotNull - final BlockChangeDelegate delegate) { - return TaskManager.IMP.sync(() -> parent.generateTree(loc, type, delegate)); - } - - @Override - @NotNull - public Entity spawnEntity(@NotNull Location loc, EntityType type) { - return spawn(loc, type.getEntityClass()); - } - - @Override - @NotNull - public LightningStrike strikeLightning( - @NotNull - final Location loc) { - return TaskManager.IMP.sync(() -> parent.strikeLightning(loc)); - } - - @Override - @NotNull - public LightningStrike strikeLightningEffect( - @NotNull - final Location loc) { - return TaskManager.IMP.sync(() -> parent.strikeLightningEffect(loc)); - } - - @Override - @NotNull - public List getEntities() { - return TaskManager.IMP.sync(() -> parent.getEntities()); - } - - @Override - @NotNull - public List getLivingEntities() { - return TaskManager.IMP.sync(() -> parent.getLivingEntities()); - } - - @NotNull - @Override - @Deprecated - public Collection getEntitiesByClass( - @NotNull - final Class... classes) { - return TaskManager.IMP.sync(() -> parent.getEntitiesByClass(classes)); - } - - @NotNull - @Override - public Collection getEntitiesByClass( - @NotNull - final Class cls) { - return TaskManager.IMP.sync(() -> parent.getEntitiesByClass(cls)); - } - - @Override - @NotNull - public Collection getEntitiesByClasses( - @NotNull - final Class... classes) { - return TaskManager.IMP.sync(() -> parent.getEntitiesByClasses(classes)); - } - - @Override - @NotNull - public List getPlayers() { - return TaskManager.IMP.sync(() -> parent.getPlayers()); - } - - @Override - @NotNull - public Collection getNearbyEntities( - @NotNull - final Location location, - final double x, final double y, final double z) { - return TaskManager.IMP.sync(() -> parent.getNearbyEntities(location, x, y, z)); - } - - @Override - @NotNull - public String getName() { - return parent.getName(); - } - - @Override - @NotNull - public UUID getUID() { - return parent.getUID(); - } - - @Override - @NotNull - public Location getSpawnLocation() { - return parent.getSpawnLocation(); - } - - @Override - public boolean setSpawnLocation(final int x, final int y, final int z) { - return TaskManager.IMP.sync(() -> parent.setSpawnLocation(x, y, z)); - } - - @Override - public boolean setSpawnLocation(final int x, final int y, final int z, final float angle) { - return TaskManager.IMP.sync(() -> parent.setSpawnLocation(x, y, z, angle)); - } - - @Override - @NotNull - public MoonPhase getMoonPhase() { - return parent.getMoonPhase(); - } - - @Override - public long getTime() { - return parent.getTime(); - } - - @Override - public void setTime(long time) { - parent.setTime(time); - } - - @Override - public long getFullTime() { - return parent.getFullTime(); - } - - @Override - public void setFullTime(long time) { - parent.setFullTime(time); - } - - @Override - public boolean hasStorm() { - return parent.hasStorm(); - } - - @Override - public void setStorm(boolean hasStorm) { - parent.setStorm(hasStorm); - } - - @Override - public int getWeatherDuration() { - return parent.getWeatherDuration(); - } - - @Override - public void setWeatherDuration(int duration) { - parent.setWeatherDuration(duration); - } - - @Override - public boolean isThundering() { - return parent.isThundering(); - } - - @Override - public void setThundering(boolean thundering) { - parent.setThundering(thundering); - } - - @Override - public int getThunderDuration() { - return parent.getThunderDuration(); - } - - @Override - public void setThunderDuration(int duration) { - parent.setThunderDuration(duration); - } - - @Override - public boolean isClearWeather() { - return parent.isClearWeather(); - } - - @Override - public void setClearWeatherDuration(int duration) { - parent.setClearWeatherDuration(duration); - } - - @Override - public int getClearWeatherDuration() { - return parent.getClearWeatherDuration(); - } - - @Override - public boolean createExplosion(double x, double y, double z, float power) { - return this.createExplosion(x, y, z, power, false, true); - } - - @Override - public boolean createExplosion(double x, double y, double z, float power, boolean setFire) { - return this.createExplosion(x, y, z, power, setFire, true); - } - - @Override - public boolean createExplosion(final double x, final double y, final double z, - final float power, final boolean setFire, final boolean breakBlocks) { - return TaskManager.IMP - .sync(() -> parent.createExplosion(x, y, z, power, setFire, breakBlocks)); - } - - @Override - public boolean createExplosion(double x, double y, double z, float power, boolean setFire, - boolean breakBlocks, @Nullable Entity source) { - return TaskManager.IMP - .sync(() -> parent.createExplosion(x, y, z, power, setFire, breakBlocks, source)); - } - - @Override - public boolean createExplosion(@NotNull Location loc, float power) { - return this.createExplosion(loc, power, false); - } - - @Override - public boolean createExplosion(Location loc, float power, boolean setFire) { - return this.createExplosion(loc.getX(), loc.getY(), loc.getZ(), power, setFire); - } - - @NotNull - @Override - public Environment getEnvironment() { - return parent.getEnvironment(); - } - - @Override - public long getSeed() { - return parent.getSeed(); - } - - @Override - public boolean getPVP() { - return parent.getPVP(); - } - - @Override - public void setPVP(boolean pvp) { - parent.setPVP(pvp); - } - - @Override - public ChunkGenerator getGenerator() { - return parent.getGenerator(); - } - - @Override - public void save() { - TaskManager.IMP.sync(new RunnableVal() { - @Override - public void run(Object value) { - parent.save(); - } - }); - } - - @Override - @NotNull - public List getPopulators() { - return parent.getPopulators(); - } - - @NotNull - @Override - public T spawn(@NotNull final Location location, @NotNull final Class clazz) throws IllegalArgumentException { - return TaskManager.IMP.sync(() -> parent.spawn(location, clazz)); - } - - @NotNull - @Override - public T spawn(@NotNull Location location, @NotNull Class clazz, - Consumer function) throws IllegalArgumentException { - return TaskManager.IMP.sync(() -> parent.spawn(location, clazz, function)); - } - - @NotNull - @Override - public T spawn(@NotNull Location location, @NotNull Class clazz, - @Nullable Consumer function, @NotNull - CreatureSpawnEvent.SpawnReason reason) - throws IllegalArgumentException { - return TaskManager.IMP.sync(() -> parent.spawn(location, clazz, function, reason)); - } - - @Override - @NotNull - public FallingBlock spawnFallingBlock(@NotNull Location location, - @NotNull MaterialData data) throws IllegalArgumentException { - return TaskManager.IMP.sync(() -> parent.spawnFallingBlock(location, data)); - } - - @Override - @Deprecated - @NotNull - public FallingBlock spawnFallingBlock(@NotNull Location location, - @NotNull Material material, byte data) throws IllegalArgumentException { - return TaskManager.IMP.sync(() -> parent.spawnFallingBlock(location, material, data)); - } - - @Override - @NotNull - public FallingBlock spawnFallingBlock(@NotNull Location location, - @NotNull BlockData blockData) throws IllegalArgumentException { - return TaskManager.IMP.sync(() -> parent.spawnFallingBlock(location, blockData)); - } - - @Override - public void playEffect(@NotNull Location location, @NotNull Effect effect, int data) { - this.playEffect(location, effect, data, 64); - } - - @Override - public void playEffect( - @NotNull - final Location location, @NotNull - final Effect effect, - final int data, final int radius) { - TaskManager.IMP.sync(new RunnableVal() { - @Override - public void run(Object value) { - parent.playEffect(location, effect, data, radius); - } - }); - } - - @Override - public void playEffect(@NotNull Location loc, @NotNull Effect effect, T data) { - this.playEffect(loc, effect, data, 64); - } - - @Override - public void playEffect( - @NotNull - final Location location, @NotNull - final Effect effect, - final T data, final int radius) { - TaskManager.IMP.sync(new RunnableVal() { - @Override - public void run(Object value) { - parent.playEffect(location, effect, data, radius); - } - }); - } - - @Override - @NotNull - public ChunkSnapshot getEmptyChunkSnapshot(final int x, final int z, - final boolean includeBiome, final boolean includeBiomeTempRain) { - return TaskManager.IMP - .sync(() -> parent.getEmptyChunkSnapshot(x, z, includeBiome, includeBiomeTempRain)); - } - - @Override - public void setSpawnFlags(boolean allowMonsters, boolean allowAnimals) { - parent.setSpawnFlags(allowMonsters, allowAnimals); - } - - @Override - public boolean getAllowAnimals() { - return parent.getAllowAnimals(); - } - - @Override - public boolean getAllowMonsters() { - return parent.getAllowMonsters(); - } - - @Override - @NotNull - public Biome getBiome(int x, int z) { - return adapter.adapt(getExtent().getBiomeType(x, 0, z)); - } - - @Override - @NotNull - public Biome getBiome(int x, int y, int z) { - return adapter.adapt(getExtent().getBiomeType(x, y, z)); - } - - @Override - public void setBiome(int x, int z, @NotNull Biome bio) { - BiomeType biome = adapter.adapt(bio); - getExtent().setBiome(x, 0, z, biome); - } - - @Override - public void setBiome(int x, int y, int z, @NotNull Biome bio) { - BiomeType biome = adapter.adapt(bio); - getExtent().setBiome(x, y, z, biome); - } - - @Override - @Deprecated - public double getTemperature(int x, int z) { - return parent.getTemperature(x, z); - } - - @Override - public double getTemperature(int x, int y, int z) { - return parent.getTemperature(x, y, z); - } - - @Override - @Deprecated - public double getHumidity(int x, int z) { - return parent.getHumidity(x, z); - } - - @Override - public double getHumidity(int x, int y, int z) { - return parent.getHumidity(x, y, z); - } - - @Override - public int getMaxHeight() { - return parent.getMaxHeight(); - } - - @Override - public int getSeaLevel() { - return parent.getSeaLevel(); - } - - @Override - public boolean getKeepSpawnInMemory() { - return parent.getKeepSpawnInMemory(); - } - - @Override - public void setKeepSpawnInMemory(final boolean keepLoaded) { - TaskManager.IMP.sync(new RunnableVal() { - @Override - public void run(Object value) { - parent.setKeepSpawnInMemory(keepLoaded); - } - }); - } - - @Override - public boolean isAutoSave() { - return parent.isAutoSave(); - } - - @Override - public void setAutoSave(boolean value) { - parent.setAutoSave(value); - } - - @Override - public void setDifficulty(@NotNull Difficulty difficulty) { - parent.setDifficulty(difficulty); - } - - @Override - @NotNull - public Difficulty getDifficulty() { - return parent.getDifficulty(); - } - - @Override - @NotNull - public File getWorldFolder() { - return parent.getWorldFolder(); - } - - @Override - @Deprecated - public WorldType getWorldType() { - return parent.getWorldType(); - } - - @Override - public boolean canGenerateStructures() { - return parent.canGenerateStructures(); - } - - @Override - public void setHardcore(boolean hardcore) { - parent.setHardcore(hardcore); - } - - @Override - public boolean isHardcore() { - return parent.isHardcore(); - } - - @Override - public long getTicksPerAnimalSpawns() { - return parent.getTicksPerAnimalSpawns(); - } - - @Override - public void setTicksPerAnimalSpawns(int ticksPerAnimalSpawns) { - parent.setTicksPerAnimalSpawns(ticksPerAnimalSpawns); - } - - @Override - public long getTicksPerMonsterSpawns() { - return parent.getTicksPerMonsterSpawns(); - } - - @Override - public void setTicksPerMonsterSpawns(int ticksPerMonsterSpawns) { - parent.setTicksPerMonsterSpawns(ticksPerMonsterSpawns); - } - - @Override - public int getMonsterSpawnLimit() { - return parent.getMonsterSpawnLimit(); - } - - @Override - public void setMonsterSpawnLimit(int limit) { - parent.setMonsterSpawnLimit(limit); - } - - @Override - public int getAnimalSpawnLimit() { - return parent.getAnimalSpawnLimit(); - } - - @Override - public void setAnimalSpawnLimit(int limit) { - parent.setAnimalSpawnLimit(limit); - } - - @Override - public int getWaterAnimalSpawnLimit() { - return parent.getWaterAnimalSpawnLimit(); - } - - @Override - public void setWaterAnimalSpawnLimit(int limit) { - parent.setWaterAnimalSpawnLimit(limit); - } - - @Override - public int getWaterAmbientSpawnLimit() { - return parent.getWaterAmbientSpawnLimit(); - } - - @Override - public void setWaterAmbientSpawnLimit(int limit) { - parent.setWaterAmbientSpawnLimit(limit); - } - - @Override - public int getAmbientSpawnLimit() { - return parent.getAmbientSpawnLimit(); - } - - @Override - public void setAmbientSpawnLimit(int limit) { - parent.setAmbientSpawnLimit(limit); - } - - @Override - public void playSound( - @NotNull - final Location location, @NotNull - final Sound sound, - final float volume, final float pitch) { - TaskManager.IMP.sync(new RunnableVal() { - @Override - public void run(Object value) { - parent.playSound(location, sound, volume, pitch); - } - }); - } - - @Override - public void playSound( - @NotNull - final Location location, @NotNull - final String sound, - final float volume, final float pitch) { - TaskManager.IMP.sync(new RunnableVal() { - @Override - public void run(Object value) { - parent.playSound(location, sound, volume, pitch); - } - }); - } - - @Override - public void playSound(@NotNull Location location, @NotNull Sound sound, - @NotNull SoundCategory category, float volume, float pitch) { - TaskManager.IMP.sync(new RunnableVal() { - @Override - public void run(Object value) { - parent.playSound(location, sound, category, volume, pitch); - } - }); - } - - @Override - public void playSound(@NotNull Location location, @NotNull String sound, - @NotNull SoundCategory category, float volume, float pitch) { - TaskManager.IMP.sync(new RunnableVal() { - @Override - public void run(Object value) { - parent.playSound(location, sound, category, volume, pitch); - } - }); - } - - @NotNull - @Override - public String[] getGameRules() { - return parent.getGameRules(); - } - - @Override - @Deprecated - public String getGameRuleValue(String rule) { - return parent.getGameRuleValue(rule); - } - - @Override - @Deprecated - public boolean setGameRuleValue(@NotNull String rule, @NotNull String value) { - return parent.setGameRuleValue(rule, value); - } - - @Override - public boolean isGameRule(@NotNull String rule) { - return parent.isGameRule(rule); - } - - @Override - @Deprecated - public T getGameRuleValue(@NotNull GameRule gameRule) { - return parent.getGameRuleValue(gameRule); - } - - @Override - public T getGameRuleDefault(@NotNull GameRule gameRule) { - return parent.getGameRuleDefault(gameRule); - } - - @Override - public boolean setGameRule(@NotNull GameRule gameRule, @NotNull T t) { - return parent.setGameRule(gameRule, t); - } - - @Override - @NotNull - public Spigot spigot() { - return parent.spigot(); - } - - @Override - @Nullable - public Raid locateNearestRaid(@NotNull Location location, int i) { - return parent.locateNearestRaid(location, i); - } - - @Override - @NotNull - public List getRaids() { - return parent.getRaids(); - } - - @Override - public void setMetadata( - @NotNull - final String key, @NotNull - final MetadataValue meta) { - TaskManager.IMP.sync(new RunnableVal() { - @Override - public void run(Object value) { - parent.setMetadata(key, meta); - } - }); - } - - @Override - @NotNull - public List getMetadata(@NotNull String key) { - return parent.getMetadata(key); - } - - @Override - public boolean hasMetadata(@NotNull String key) { - return parent.hasMetadata(key); - } - - @Override - public void removeMetadata( - @NotNull - final String key, @NotNull - final Plugin plugin) { - TaskManager.IMP.sync(new RunnableVal() { - @Override - public void run(Object value) { - parent.removeMetadata(key, plugin); - } - }); - } - - @Override - public void sendPluginMessage(@NotNull Plugin source, @NotNull String channel, @NotNull - byte[] message) { - parent.sendPluginMessage(source, channel, message); - } - - @Override - @NotNull - public Set getListeningPluginChannels() { - return parent.getListeningPluginChannels(); - } - - public BukkitImplAdapter getAdapter() { - return adapter; - } - - @Override - @NotNull - public Collection getNearbyEntities(@NotNull BoundingBox arg0) { - return parent.getNearbyEntities(arg0); - } - - @Override - @NotNull - public Collection getNearbyEntities(@NotNull BoundingBox arg0, - Predicate arg1) { - return parent.getNearbyEntities(arg0, arg1); - } - - @Override - @NotNull - public Collection getNearbyEntities(@NotNull Location arg0, double arg1, - double arg2, double arg3, Predicate arg4) { - return parent.getNearbyEntities(arg0, arg1, arg2, arg3, arg4); - } - - @Override - public boolean isChunkForceLoaded(int arg0, int arg1) { - return parent.isChunkForceLoaded(arg0, arg1); - } - - @Override - public Location locateNearestStructure(@NotNull Location arg0, @NotNull StructureType arg1, - int arg2, boolean arg3) { - return parent.locateNearestStructure(arg0, arg1, arg2, arg3); - } - - @Override - public int getViewDistance() { - return parent.getViewDistance(); - } - - @Override - public void setViewDistance(int viewDistance) { - - } - - @Override - public int getNoTickViewDistance() { - return 0; - } - - @Override - public void setNoTickViewDistance(int viewDistance) { - - } - - @Override - public RayTraceResult rayTrace(@NotNull Location arg0, @NotNull Vector arg1, double arg2, - @NotNull FluidCollisionMode arg3, boolean arg4, double arg5, Predicate arg6) { - return parent.rayTrace(arg0, arg1, arg2, arg3, arg4, arg5, arg6); - } - - @Override - public RayTraceResult rayTraceBlocks(@NotNull Location arg0, @NotNull Vector arg1, - double arg2) { - return parent.rayTraceBlocks(arg0, arg1, arg2); - } - - @Override - public RayTraceResult rayTraceBlocks(@NotNull Location start, @NotNull Vector direction, - double maxDistance, @NotNull FluidCollisionMode fluidCollisionMode) { - return parent.rayTraceBlocks(start, direction, maxDistance, fluidCollisionMode); - } - - @Override - public RayTraceResult rayTraceBlocks(@NotNull Location start, @NotNull Vector direction, - double arg2, @NotNull FluidCollisionMode fluidCollisionMode, boolean ignorePassableBlocks) { - return parent - .rayTraceBlocks(start, direction, arg2, fluidCollisionMode, ignorePassableBlocks); - } - - @Override - public RayTraceResult rayTraceEntities(@NotNull Location start, @NotNull Vector direction, - double maxDistance) { - return parent.rayTraceEntities(start, direction, maxDistance); - } - - @Override - public RayTraceResult rayTraceEntities(@NotNull Location arg0, @NotNull Vector arg1, - double arg2, double arg3) { - return parent.rayTraceEntities(arg0, arg1, arg2, arg3); - } - - @Override - public RayTraceResult rayTraceEntities(@NotNull Location arg0, @NotNull Vector arg1, - double arg2, Predicate arg3) { - return parent.rayTraceEntities(arg0, arg1, arg2, arg3); - } - - @Override - public RayTraceResult rayTraceEntities(@NotNull Location arg0, @NotNull Vector arg1, - double arg2, double arg3, Predicate arg4) { - return parent.rayTraceEntities(arg0, arg1, arg2, arg3, arg4); - } - - - @Override - public void spawnParticle(@NotNull Particle particle, double x, double y, double z, - int count, double offsetX, double offsetY, double offsetZ, double extra, @Nullable T data, - boolean force) { - - } - - @Override - public void setChunkForceLoaded(int x, int z, boolean forced) { - parent.setChunkForceLoaded(x, z, forced); - } - - @Override - @NotNull - public Collection getForceLoadedChunks() { - return parent.getForceLoadedChunks(); - } - - @Override - public boolean addPluginChunkTicket(int x, int z, @NotNull Plugin plugin) { - return getBukkitWorld().addPluginChunkTicket(x, z, plugin); - } - - @Override - public boolean removePluginChunkTicket(int x, int z, @NotNull Plugin plugin) { - return getBukkitWorld().removePluginChunkTicket(x, z, plugin); - } - - @Override - public void removePluginChunkTickets(@NotNull Plugin plugin) { - getBukkitWorld().removePluginChunkTickets(plugin); - } - - @Override - @NotNull - public Collection getPluginChunkTickets(int x, int z) { - return getBukkitWorld().getPluginChunkTickets(x, z); - } - - @Override - @NotNull - public Map> getPluginChunkTickets() { - return getBukkitWorld().getPluginChunkTickets(); - } - - @Override - @Deprecated - public int getHighestBlockYAt(int x, int z, - @NotNull - com.destroystokyo.paper.HeightmapType heightmap) - throws UnsupportedOperationException { - return TaskManager.IMP.sync(() -> parent.getHighestBlockYAt(x, z, heightmap)); - } - - @Override - public int getEntityCount() { - return TaskManager.IMP.sync(() -> parent.getEntityCount()); - } - - @Override - public int getTileEntityCount() { - return TaskManager.IMP.sync(() -> parent.getTileEntityCount()); - } - - @Override - public int getTickableTileEntityCount() { - return TaskManager.IMP.sync(() -> parent.getTickableTileEntityCount()); - } - - @Override - public int getChunkCount() { - return TaskManager.IMP.sync(() -> parent.getChunkCount()); - } - - @Override - public int getPlayerCount() { - return TaskManager.IMP.sync(() -> parent.getPlayerCount()); - } - - @Override - @NotNull - public CompletableFuture getChunkAtAsync(int x, int z, boolean gen) { - return parent.getChunkAtAsync(x, z, gen); - } - - @Override - @NotNull - public CompletableFuture getChunkAtAsync(int x, int z, boolean gen, - boolean urgent) { - return parent.getChunkAtAsync(x, z, gen, urgent); - } - - @Override - @NotNull - public NamespacedKey getKey() { - throw new UnsupportedOperationException("FAWE does not support this yet"); - } - - @Override - public boolean isDayTime() { - return parent.isDayTime(); - } - - @Override - public long getGameTime() { - return parent.getGameTime(); - } - - @Override - @Deprecated - public void getChunkAtAsync(int x, int z, @NotNull ChunkLoadCallback cb) { - parent.getChunkAtAsync(x, z, cb); - } - - @Override - @Deprecated - public void getChunkAtAsync(@NotNull Location location, @NotNull ChunkLoadCallback cb) { - parent.getChunkAtAsync(location, cb); - } - - @Override - @Deprecated - public void getChunkAtAsync(@NotNull Block block, @NotNull ChunkLoadCallback cb) { - parent.getChunkAtAsync(block, cb); - } - - @Override - public Entity getEntity(@NotNull UUID uuid) { - return TaskManager.IMP.sync(() -> parent.getEntity(uuid)); - } - - @Nullable - @Override - public DragonBattle getEnderDragonBattle() { - return TaskManager.IMP.sync(() -> parent.getEnderDragonBattle()); - } - - @Override - public boolean createExplosion(Entity source, @NotNull Location loc, float power, - boolean setFire, boolean breakBlocks) { - return TaskManager.IMP - .sync(() -> parent.createExplosion(source, loc, power, setFire, breakBlocks)); - } - - @Override - public boolean createExplosion(@NotNull Location loc, float power, boolean setFire, - boolean breakBlocks) { - return false; - } - - @Override - public boolean createExplosion(@NotNull Location loc, float power, boolean setFire, - boolean breakBlocks, @Nullable Entity source) { - return false; - } - - - @Override - public void spawnParticle(@NotNull Particle particle, List receivers, - @NotNull Player source, double x, double y, double z, int count, double offsetX, - double offsetY, double offsetZ, double extra, T data) { - parent.spawnParticle(particle, receivers, source, x, y, z, count, offsetX, offsetY, offsetZ, - extra, data); - } - - @Override - public void spawnParticle(@NotNull Particle particle, List list, Player player, - double v, double v1, double v2, int i, double v3, double v4, double v5, double v6, T t, - boolean b) { - parent.spawnParticle(particle, list, player, v, v1, v2, i, v3, v4, v5, v6, t, b); - } - - @Override - public void spawnParticle(@NotNull Particle particle, @NotNull Location location, int count, - double offsetX, double offsetY, double offsetZ, double extra, @Nullable T data, - boolean force) { - parent.spawnParticle(particle, location, count, offsetX, offsetY, offsetZ, extra, data, - force); - } - - @Override - @Deprecated - public int getHighestBlockYAt(@NotNull Location location, @NotNull HeightmapType heightmap) - throws UnsupportedOperationException { - return parent.getHighestBlockYAt(location, heightmap); - } - - @Override - @NotNull - @Deprecated - public Block getHighestBlockAt(int x, int z, @NotNull HeightmapType heightmap) - throws UnsupportedOperationException { - return parent.getHighestBlockAt(x, z, heightmap); - } - - @Override - @NotNull - @Deprecated - public Block getHighestBlockAt(@NotNull Location location, - @NotNull HeightmapType heightmap) throws UnsupportedOperationException { - return parent.getHighestBlockAt(location, heightmap); - } - - @Override - public long getTicksPerWaterSpawns() { - return parent.getTicksPerWaterSpawns(); - } - - @Override - public void setTicksPerWaterSpawns(int ticksPerWaterSpawns) { - parent.setTicksPerWaterSpawns(ticksPerWaterSpawns); - } - - @Override - public long getTicksPerWaterAmbientSpawns() { - return parent.getTicksPerWaterAmbientSpawns(); - } - - @Override - public void setTicksPerWaterAmbientSpawns(int ticksPerAmbientSpawns) { - parent.setTicksPerWaterAmbientSpawns(ticksPerAmbientSpawns); - } - - @Override - public long getTicksPerAmbientSpawns() { - return parent.getTicksPerAmbientSpawns(); - } - - @Override - public void setTicksPerAmbientSpawns(int ticksPerAmbientSpawns) { - parent.setTicksPerAmbientSpawns(ticksPerAmbientSpawns); - } - -} diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncDataContainer.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncDataContainer.java deleted file mode 100644 index f57ca8553..000000000 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncDataContainer.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.boydti.fawe.bukkit.wrapper.state; - -import com.boydti.fawe.FaweCache; -import com.sk89q.jnbt.CompoundTag; -import com.sk89q.jnbt.Tag; -import org.apache.commons.lang.Validate; -import org.bukkit.NamespacedKey; -import org.bukkit.persistence.PersistentDataAdapterContext; -import org.bukkit.persistence.PersistentDataContainer; -import org.bukkit.persistence.PersistentDataType; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.function.Consumer; -import java.util.function.Supplier; - -public final class AsyncDataContainer implements PersistentDataContainer { - - private final Supplier supplier; - private final Consumer consumer; - - public AsyncDataContainer( - final @NotNull Supplier supplier, - final @NotNull Consumer consumer - ) { - this.supplier = supplier; - this.consumer = consumer; - } - - private CompoundTag root() { - return (CompoundTag) supplier.get().getValue().get("PublicBukkitValues"); - } - - private Map get() { - return get(true); - } - - private Map get(boolean create) { - CompoundTag tag = root(); - Map raw; - if (tag == null) { - if (!create) { - return Collections.emptyMap(); - } - final Map map = new HashMap<>(root().getValue()); - map.put("PublicBukkitValues", new CompoundTag(raw = new HashMap<>())); - this.consumer.accept(new CompoundTag(map)); - } else { - raw = tag.getValue(); - } - return raw; - } - - public void set(NamespacedKey key, PersistentDataType type, Z value) { - Validate.notNull(key, "The provided key for the custom value was null"); - Validate.notNull(type, "The provided type for the custom value was null"); - Validate.notNull(value, "The provided value for the custom value was null"); - // Modify public values - final Map publicValues = new HashMap<>(this.get()); - publicValues.put(key.toString(), FaweCache.IMP.asTag(type.toPrimitive(value, null))); - // Modify the root tag - final Map map = new HashMap<>(root().getValue()); - map.put("PublicBukkitValues", new CompoundTag(publicValues)); - // Update the owning object - this.consumer.accept(new CompoundTag(map)); - } - - public boolean has(NamespacedKey key, PersistentDataType type) { - Validate.notNull(key, "The provided key for the custom value was null"); - Validate.notNull(type, "The provided type for the custom value was null"); - Tag value = get(false).get(key.toString()); - if (value == null) { - return false; - } - return type.getPrimitiveType() == value.getValue().getClass(); - } - - public Z get(NamespacedKey key, PersistentDataType type) { - Validate.notNull(key, "The provided key for the custom value was null"); - Validate.notNull(type, "The provided type for the custom value was null"); - Tag value = get(false).get(key.toString()); - return (Z) value.toRaw(); - } - - public Z getOrDefault(NamespacedKey key, PersistentDataType type, Z defaultValue) { - Z z = this.get(key, type); - return z != null ? z : defaultValue; - } - - @NotNull - @Override - public Set getKeys() { - Set keys = new HashSet<>(); - this.get(false).keySet().forEach(key -> { - String[] keyData = key.split(":", 2); - if (keyData.length == 2) { - keys.add(new NamespacedKey(keyData[0], keyData[1])); - } - - }); - return keys; - } - - public void remove(NamespacedKey key) { - Validate.notNull(key, "The provided key for the custom value was null"); - // Modify public values - final Map publicValues = new HashMap<>(this.get(false)); - publicValues.remove(key.toString()); - // Modify the root tag - final Map map = new HashMap<>(root().getValue()); - map.put("PublicBukkitValues", new CompoundTag(publicValues)); - // Update the owning object - this.consumer.accept(new CompoundTag(map)); - } - - public boolean isEmpty() { - return get(false).isEmpty(); - } - - public PersistentDataAdapterContext getAdapterContext() { - return null; - } - - public boolean equals(Object obj) { - if (!(obj instanceof AsyncDataContainer)) { - return false; - } else { - Map myRawMap = this.getRaw(); - Map theirRawMap = ((AsyncDataContainer) obj).getRaw(); - return Objects.equals(myRawMap, theirRawMap); - } - } - - public Map getRaw() { - return get(false); - } - - public int hashCode() { - return get(false).hashCode(); - } - - public Map serialize() { - return new CompoundTag(get(false)).toRaw(); - } -} diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncSign.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncSign.java deleted file mode 100644 index c28482fe7..000000000 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncSign.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.boydti.fawe.bukkit.wrapper.state; - -import com.boydti.fawe.bukkit.wrapper.AsyncBlock; -import com.boydti.fawe.bukkit.wrapper.AsyncBlockState; -import com.sk89q.jnbt.CompoundTag; -import com.sk89q.jnbt.StringTag; -import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer; -import com.sk89q.worldedit.util.formatting.text.serializer.legacy.LegacyComponentSerializer; -import com.sk89q.worldedit.world.block.BaseBlock; -import org.bukkit.DyeColor; -import org.bukkit.block.Sign; -import org.bukkit.persistence.PersistentDataContainer; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.Locale; -import java.util.Map; - -public class AsyncSign extends AsyncBlockState implements Sign { - - public AsyncSign(AsyncBlock block, BaseBlock state) { - super(block, state); - } - - private boolean isEditable = false; - - @Override - public @NotNull List lines() { - throw new UnsupportedOperationException(); - } - - @Override - public net.kyori.adventure.text.@NotNull Component line(int index) throws IndexOutOfBoundsException { - throw new UnsupportedOperationException(); - } - - @Override - public void line(int index, net.kyori.adventure.text.@NotNull Component line) throws IndexOutOfBoundsException { - - } - - @Override - public String[] getLines() { - CompoundTag nbt = getNbtData(); - String[] data = new String[4]; - if (nbt != null) { - for (int i = 1; i <= 4; i++) { - data[i - 1] = fromJson(nbt.getString("Text" + i)); - } - } - return data; - } - - private String fromJson(String jsonInput) { - if (jsonInput == null || jsonInput.isEmpty()) { - return ""; - } - return GsonComponentSerializer.INSTANCE.deserialize(jsonInput).toString(); - } - - private String toJson(String oldInput) { - if (oldInput == null || oldInput.isEmpty()) { - return ""; - } - return LegacyComponentSerializer.INSTANCE.serialize(TextComponent.of(oldInput)); - } - - @Override - public String getLine(int index) throws IndexOutOfBoundsException { - CompoundTag nbt = getNbtData(); - return nbt == null ? "" : fromJson(nbt.getString("Text" + (index + 1))); - } - - @Override - public void setLine(int index, String line) throws IndexOutOfBoundsException { - final Map map = this.cloneNbtMap(); - if (map.isEmpty()) { - return; - } - map.put("Text" + (index + 1), new StringTag(toJson(line))); - this.setNbtData(map); - } - - @Override - public boolean isEditable() { - return this.isEditable; - } - - @Override - public void setEditable(boolean arg0) { - this.isEditable = arg0; - } - - @Override - @NotNull - public PersistentDataContainer getPersistentDataContainer() { - return new AsyncDataContainer(this::getNbtData, this::setNbtData); - } - - @Override - @Nullable - public DyeColor getColor() { - CompoundTag nbt = this.getNbtData(); - if (nbt != null) { - String color = nbt.getString("Color").toUpperCase(Locale.ROOT); - if (!color.isEmpty()) { - return DyeColor.valueOf(color); - } - } - return DyeColor.BLACK; - } - - @Override - public void setColor(DyeColor color) { - final Map map = this.cloneNbtMap(); - if (map.isEmpty()) { - return; - } - map.put("Color", new StringTag(color.name().toLowerCase(Locale.ROOT))); - this.setNbtData(map); - } -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/config/Settings.java b/worldedit-core/src/main/java/com/boydti/fawe/config/Settings.java index ae335a8e8..d33804bdb 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/config/Settings.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/config/Settings.java @@ -365,13 +365,6 @@ public class Settings extends Config { }) public boolean KEEP_ENTITIES_IN_BLOCKS = false; - @Comment({ - "[SAFE] Experimental freebuild region restrictions", - " - PERM: fawe.freebuild", - " - PERM: fawe.freebuild." - }) - public boolean FREEBUILD = false; - @Comment({ "Other experimental features" })