Remove freebuild regions (#991)

* Remove freebuild regions

* Remove configuration option of freebuild

Co-authored-by: Matt <4009945+MattBDev@users.noreply.github.com>
Dieser Commit ist enthalten in:
NotMyFault 2021-03-25 08:40:09 +01:00 committet von GitHub
Ursprung 680ddc97a1
Commit 4af7316118
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
9 geänderte Dateien mit 0 neuen und 2853 gelöschten Zeilen

Datei anzeigen

@ -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 '<internal.freebuild>'");
} catch (Throwable ignored) {
}
}
return managers;
}

Datei anzeigen

@ -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<RegisteredListener> 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<RegisteredListener> 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();
}
};
}
};
}
}

Datei anzeigen

@ -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<ItemStack> getDrops() {
return TaskManager.IMP.sync(() -> getUnsafeBlock().getDrops());
}
@Nonnull
@Override
public Collection<ItemStack> getDrops(@Nonnull ItemStack tool) {
return TaskManager.IMP.sync(() -> getUnsafeBlock().getDrops(tool));
}
public Collection<ItemStack> 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<MetadataValue> 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();
}
}

Datei anzeigen

@ -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<String, Tag> 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<String, Tag> 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<MetadataValue> 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);
}
}

Datei anzeigen

@ -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> T whenLoaded(Supplier<T> 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<BlockState> getTileEntities(@NotNull Predicate<Block> 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<Plugin> 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());
}
}

Datei anzeigen

@ -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<CompoundTag> supplier;
private final Consumer<CompoundTag> consumer;
public AsyncDataContainer(
final @NotNull Supplier<CompoundTag> supplier,
final @NotNull Consumer<CompoundTag> consumer
) {
this.supplier = supplier;
this.consumer = consumer;
}
private CompoundTag root() {
return (CompoundTag) supplier.get().getValue().get("PublicBukkitValues");
}
private Map<String, Tag> get() {
return get(true);
}
private Map<String, Tag> get(boolean create) {
CompoundTag tag = root();
Map<String, Tag> raw;
if (tag == null) {
if (!create) {
return Collections.emptyMap();
}
final Map<String, Tag> 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 <T, Z> void set(NamespacedKey key, PersistentDataType<T, Z> 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<String, Tag> publicValues = new HashMap<>(this.get());
publicValues.put(key.toString(), FaweCache.IMP.asTag(type.toPrimitive(value, null)));
// Modify the root tag
final Map<String, Tag> map = new HashMap<>(root().getValue());
map.put("PublicBukkitValues", new CompoundTag(publicValues));
// Update the owning object
this.consumer.accept(new CompoundTag(map));
}
public <T, Z> boolean has(NamespacedKey key, PersistentDataType<T, Z> 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 <T, Z> Z get(NamespacedKey key, PersistentDataType<T, Z> 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 <T, Z> Z getOrDefault(NamespacedKey key, PersistentDataType<T, Z> type, Z defaultValue) {
Z z = this.get(key, type);
return z != null ? z : defaultValue;
}
@NotNull
@Override
public Set<NamespacedKey> getKeys() {
Set<NamespacedKey> 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<String, Tag> publicValues = new HashMap<>(this.get(false));
publicValues.remove(key.toString());
// Modify the root tag
final Map<String, Tag> 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<String, Tag> myRawMap = this.getRaw();
Map<String, Tag> theirRawMap = ((AsyncDataContainer) obj).getRaw();
return Objects.equals(myRawMap, theirRawMap);
}
}
public Map<String, Tag> getRaw() {
return get(false);
}
public int hashCode() {
return get(false).hashCode();
}
public Map<String, Object> serialize() {
return new CompoundTag(get(false)).toRaw();
}
}

Datei anzeigen

@ -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<net.kyori.adventure.text.Component> 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<String, Tag> 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<String, Tag> map = this.cloneNbtMap();
if (map.isEmpty()) {
return;
}
map.put("Color", new StringTag(color.name().toLowerCase(Locale.ROOT)));
this.setNbtData(map);
}
}

Datei anzeigen

@ -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.<plugin>"
})
public boolean FREEBUILD = false;
@Comment({
"Other experimental features"
})