Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-20 09:50:06 +01:00
Merge branch 'main' into feat/improved-entity-operations
Dieser Commit ist enthalten in:
Commit
69e815e241
@ -1,7 +1,6 @@
|
|||||||
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_17_R1_2;
|
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_17_R1_2;
|
||||||
|
|
||||||
import com.fastasyncworldedit.bukkit.adapter.CachedBukkitAdapter;
|
import com.fastasyncworldedit.bukkit.adapter.FaweAdapter;
|
||||||
import com.fastasyncworldedit.bukkit.adapter.IDelegateBukkitImplAdapter;
|
|
||||||
import com.fastasyncworldedit.bukkit.adapter.NMSRelighterFactory;
|
import com.fastasyncworldedit.bukkit.adapter.NMSRelighterFactory;
|
||||||
import com.fastasyncworldedit.core.FaweCache;
|
import com.fastasyncworldedit.core.FaweCache;
|
||||||
import com.fastasyncworldedit.core.entity.LazyBaseEntity;
|
import com.fastasyncworldedit.core.entity.LazyBaseEntity;
|
||||||
@ -10,16 +9,13 @@ import com.fastasyncworldedit.core.queue.IBatchProcessor;
|
|||||||
import com.fastasyncworldedit.core.queue.IChunkGet;
|
import com.fastasyncworldedit.core.queue.IChunkGet;
|
||||||
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
||||||
import com.fastasyncworldedit.core.util.NbtUtils;
|
import com.fastasyncworldedit.core.util.NbtUtils;
|
||||||
import com.fastasyncworldedit.core.util.TaskManager;
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.sk89q.jnbt.Tag;
|
import com.sk89q.jnbt.Tag;
|
||||||
import com.sk89q.worldedit.EditSession;
|
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
import com.sk89q.worldedit.blocks.TileEntityBlock;
|
import com.sk89q.worldedit.blocks.TileEntityBlock;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
|
||||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.ext.fawe.PaperweightAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.ext.fawe.PaperweightAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_17_R1_2.nbt.PaperweightLazyCompoundTag;
|
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_17_R1_2.nbt.PaperweightLazyCompoundTag;
|
||||||
@ -39,7 +35,6 @@ import com.sk89q.worldedit.registry.state.Property;
|
|||||||
import com.sk89q.worldedit.util.Direction;
|
import com.sk89q.worldedit.util.Direction;
|
||||||
import com.sk89q.worldedit.util.SideEffect;
|
import com.sk89q.worldedit.util.SideEffect;
|
||||||
import com.sk89q.worldedit.util.SideEffectSet;
|
import com.sk89q.worldedit.util.SideEffectSet;
|
||||||
import com.sk89q.worldedit.util.TreeGenerator;
|
|
||||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.nbt.BinaryTag;
|
import com.sk89q.worldedit.util.nbt.BinaryTag;
|
||||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||||
@ -79,14 +74,12 @@ import net.minecraft.world.level.chunk.LevelChunkSection;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.TreeType;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.craftbukkit.v1_17_R1.CraftChunk;
|
import org.bukkit.craftbukkit.v1_17_R1.CraftChunk;
|
||||||
import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
|
import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
|
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.v1_17_R1.block.CraftBlockState;
|
|
||||||
import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData;
|
import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData;
|
||||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer;
|
||||||
@ -110,8 +103,7 @@ import java.util.function.Supplier;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.Tag, ServerLevel> {
|
||||||
IDelegateBukkitImplAdapter<net.minecraft.nbt.Tag> {
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
||||||
|
|
||||||
@ -235,11 +227,10 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
public BlockState getBlock(Location location) {
|
public BlockState getBlock(Location location) {
|
||||||
Preconditions.checkNotNull(location);
|
Preconditions.checkNotNull(location);
|
||||||
|
|
||||||
CraftWorld craftWorld = ((CraftWorld) location.getWorld());
|
|
||||||
int x = location.getBlockX();
|
int x = location.getBlockX();
|
||||||
int y = location.getBlockY();
|
int y = location.getBlockY();
|
||||||
int z = location.getBlockZ();
|
int z = location.getBlockZ();
|
||||||
final ServerLevel handle = craftWorld.getHandle();
|
final ServerLevel handle = getServerLevel(location.getWorld());
|
||||||
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
||||||
final BlockPos blockPos = new BlockPos(x, y, z);
|
final BlockPos blockPos = new BlockPos(x, y, z);
|
||||||
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
||||||
@ -255,12 +246,11 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
public BaseBlock getFullBlock(final Location location) {
|
public BaseBlock getFullBlock(final Location location) {
|
||||||
Preconditions.checkNotNull(location);
|
Preconditions.checkNotNull(location);
|
||||||
|
|
||||||
CraftWorld craftWorld = ((CraftWorld) location.getWorld());
|
|
||||||
int x = location.getBlockX();
|
int x = location.getBlockX();
|
||||||
int y = location.getBlockY();
|
int y = location.getBlockY();
|
||||||
int z = location.getBlockZ();
|
int z = location.getBlockZ();
|
||||||
|
|
||||||
final ServerLevel handle = craftWorld.getHandle();
|
final ServerLevel handle = getServerLevel(location.getWorld());
|
||||||
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
||||||
final BlockPos blockPos = new BlockPos(x, y, z);
|
final BlockPos blockPos = new BlockPos(x, y, z);
|
||||||
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
||||||
@ -344,10 +334,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorldNativeAccess<?, ?, ?> createWorldNativeAccess(org.bukkit.World world) {
|
public WorldNativeAccess<?, ?, ?> createWorldNativeAccess(org.bukkit.World world) {
|
||||||
return new PaperweightFaweWorldNativeAccess(
|
return new PaperweightFaweWorldNativeAccess(this, new WeakReference<>(getServerLevel(world)));
|
||||||
this,
|
|
||||||
new WeakReference<>(((CraftWorld) world).getHandle())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -492,7 +479,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendFakeChunk(org.bukkit.World world, Player player, ChunkPacket chunkPacket) {
|
public void sendFakeChunk(org.bukkit.World world, Player player, ChunkPacket chunkPacket) {
|
||||||
ServerLevel nmsWorld = ((CraftWorld) world).getHandle();
|
ServerLevel nmsWorld = getServerLevel(world);
|
||||||
ChunkHolder map = PaperweightPlatformAdapter.getPlayerChunk(nmsWorld, chunkPacket.getChunkX(), chunkPacket.getChunkZ());
|
ChunkHolder map = PaperweightPlatformAdapter.getPlayerChunk(nmsWorld, chunkPacket.getChunkX(), chunkPacket.getChunkZ());
|
||||||
if (map != null && map.wasAccessibleSinceLastSave()) {
|
if (map != null && map.wasAccessibleSinceLastSave()) {
|
||||||
boolean flag = false;
|
boolean flag = false;
|
||||||
@ -530,7 +517,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
int internalId = BlockStateIdAccess.getBlockStateId(blockState);
|
int internalId = BlockStateIdAccess.getBlockStateId(blockState);
|
||||||
net.minecraft.world.level.block.state.BlockState blockState1 = Block.stateById(internalId);
|
net.minecraft.world.level.block.state.BlockState blockState1 = Block.stateById(internalId);
|
||||||
return blockState1.hasPostProcess(
|
return blockState1.hasPostProcess(
|
||||||
((CraftWorld) world).getHandle(),
|
getServerLevel(world),
|
||||||
new BlockPos(blockVector3.getX(), blockVector3.getY(), blockVector3.getZ())
|
new BlockPos(blockVector3.getX(), blockVector3.getY(), blockVector3.getZ())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -546,54 +533,33 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean generateTree(
|
protected void preCaptureStates(final ServerLevel serverLevel) {
|
||||||
TreeGenerator.TreeType treeType, EditSession editSession, BlockVector3 blockVector3,
|
serverLevel.captureTreeGeneration = true;
|
||||||
org.bukkit.World bukkitWorld
|
serverLevel.captureBlockStates = true;
|
||||||
) {
|
}
|
||||||
TreeType bukkitType = BukkitWorld.toBukkitTreeType(treeType);
|
|
||||||
if (bukkitType == TreeType.CHORUS_PLANT) {
|
@Override
|
||||||
blockVector3 = blockVector3.add(
|
protected List<org.bukkit.block.BlockState> getCapturedBlockStatesCopy(final ServerLevel serverLevel) {
|
||||||
0,
|
return new ArrayList<>(serverLevel.capturedBlockStates.values());
|
||||||
1,
|
}
|
||||||
0
|
|
||||||
); // bukkit skips the feature gen which does this offset normally, so we have to add it back
|
@Override
|
||||||
}
|
protected void postCaptureBlockStates(final ServerLevel serverLevel) {
|
||||||
ServerLevel serverLevel = ((CraftWorld) bukkitWorld).getHandle();
|
serverLevel.captureBlockStates = false;
|
||||||
final BlockVector3 finalBlockVector = blockVector3;
|
serverLevel.captureTreeGeneration = false;
|
||||||
// Sync to main thread to ensure no clashes occur
|
serverLevel.capturedBlockStates.clear();
|
||||||
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
|
}
|
||||||
serverLevel.captureTreeGeneration = true;
|
|
||||||
serverLevel.captureBlockStates = true;
|
@Override
|
||||||
try {
|
protected ServerLevel getServerLevel(final World world) {
|
||||||
if (!bukkitWorld.generateTree(BukkitAdapter.adapt(bukkitWorld, finalBlockVector), bukkitType)) {
|
return ((CraftWorld) world).getHandle();
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return ImmutableMap.copyOf(serverLevel.capturedBlockStates);
|
|
||||||
} finally {
|
|
||||||
serverLevel.captureBlockStates = false;
|
|
||||||
serverLevel.captureTreeGeneration = false;
|
|
||||||
serverLevel.capturedBlockStates.clear();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (placed == null || placed.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (CraftBlockState craftBlockState : placed.values()) {
|
|
||||||
if (craftBlockState == null || craftBlockState.getType() == Material.AIR) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
editSession.setBlock(craftBlockState.getX(), craftBlockState.getY(), craftBlockState.getZ(),
|
|
||||||
BukkitAdapter.adapt(((org.bukkit.block.BlockState) craftBlockState).getBlockData())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<org.bukkit.entity.Entity> getEntities(org.bukkit.World world) {
|
public List<org.bukkit.entity.Entity> getEntities(org.bukkit.World world) {
|
||||||
// Quickly add each entity to a list copy.
|
// Quickly add each entity to a list copy.
|
||||||
List<Entity> mcEntities = new ArrayList<>();
|
List<Entity> mcEntities = new ArrayList<>();
|
||||||
((CraftWorld) world).getHandle().entityManager.getEntityGetter().getAll().forEach(mcEntities::add);
|
getServerLevel(world).entityManager.getEntityGetter().getAll().forEach(mcEntities::add);
|
||||||
|
|
||||||
List<org.bukkit.entity.Entity> list = new ArrayList<>();
|
List<org.bukkit.entity.Entity> list = new ArrayList<>();
|
||||||
mcEntities.forEach((mcEnt) -> {
|
mcEntities.forEach((mcEnt) -> {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R2;
|
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R2;
|
||||||
|
|
||||||
import com.fastasyncworldedit.bukkit.adapter.CachedBukkitAdapter;
|
import com.fastasyncworldedit.bukkit.adapter.FaweAdapter;
|
||||||
import com.fastasyncworldedit.bukkit.adapter.IDelegateBukkitImplAdapter;
|
|
||||||
import com.fastasyncworldedit.bukkit.adapter.NMSRelighterFactory;
|
import com.fastasyncworldedit.bukkit.adapter.NMSRelighterFactory;
|
||||||
import com.fastasyncworldedit.core.FaweCache;
|
import com.fastasyncworldedit.core.FaweCache;
|
||||||
import com.fastasyncworldedit.core.entity.LazyBaseEntity;
|
import com.fastasyncworldedit.core.entity.LazyBaseEntity;
|
||||||
@ -10,16 +9,13 @@ import com.fastasyncworldedit.core.queue.IBatchProcessor;
|
|||||||
import com.fastasyncworldedit.core.queue.IChunkGet;
|
import com.fastasyncworldedit.core.queue.IChunkGet;
|
||||||
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
||||||
import com.fastasyncworldedit.core.util.NbtUtils;
|
import com.fastasyncworldedit.core.util.NbtUtils;
|
||||||
import com.fastasyncworldedit.core.util.TaskManager;
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.sk89q.jnbt.Tag;
|
import com.sk89q.jnbt.Tag;
|
||||||
import com.sk89q.worldedit.EditSession;
|
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
import com.sk89q.worldedit.blocks.TileEntityBlock;
|
import com.sk89q.worldedit.blocks.TileEntityBlock;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
|
||||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_18_R2.PaperweightAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_18_R2.PaperweightAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R2.nbt.PaperweightLazyCompoundTag;
|
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R2.nbt.PaperweightLazyCompoundTag;
|
||||||
@ -39,7 +35,6 @@ import com.sk89q.worldedit.registry.state.Property;
|
|||||||
import com.sk89q.worldedit.util.Direction;
|
import com.sk89q.worldedit.util.Direction;
|
||||||
import com.sk89q.worldedit.util.SideEffect;
|
import com.sk89q.worldedit.util.SideEffect;
|
||||||
import com.sk89q.worldedit.util.SideEffectSet;
|
import com.sk89q.worldedit.util.SideEffectSet;
|
||||||
import com.sk89q.worldedit.util.TreeGenerator;
|
|
||||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.nbt.BinaryTag;
|
import com.sk89q.worldedit.util.nbt.BinaryTag;
|
||||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||||
@ -80,14 +75,12 @@ import net.minecraft.world.level.chunk.LevelChunkSection;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.TreeType;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.craftbukkit.v1_18_R2.CraftChunk;
|
import org.bukkit.craftbukkit.v1_18_R2.CraftChunk;
|
||||||
import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
|
import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
|
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState;
|
|
||||||
import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData;
|
import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData;
|
||||||
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;
|
||||||
@ -111,8 +104,7 @@ import java.util.function.Supplier;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.Tag, ServerLevel> {
|
||||||
IDelegateBukkitImplAdapter<net.minecraft.nbt.Tag> {
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
||||||
|
|
||||||
@ -235,11 +227,10 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
public BlockState getBlock(Location location) {
|
public BlockState getBlock(Location location) {
|
||||||
Preconditions.checkNotNull(location);
|
Preconditions.checkNotNull(location);
|
||||||
|
|
||||||
CraftWorld craftWorld = ((CraftWorld) location.getWorld());
|
|
||||||
int x = location.getBlockX();
|
int x = location.getBlockX();
|
||||||
int y = location.getBlockY();
|
int y = location.getBlockY();
|
||||||
int z = location.getBlockZ();
|
int z = location.getBlockZ();
|
||||||
final ServerLevel handle = craftWorld.getHandle();
|
final ServerLevel handle = getServerLevel(location.getWorld());
|
||||||
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
||||||
final BlockPos blockPos = new BlockPos(x, y, z);
|
final BlockPos blockPos = new BlockPos(x, y, z);
|
||||||
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
||||||
@ -255,12 +246,11 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
public BaseBlock getFullBlock(final Location location) {
|
public BaseBlock getFullBlock(final Location location) {
|
||||||
Preconditions.checkNotNull(location);
|
Preconditions.checkNotNull(location);
|
||||||
|
|
||||||
CraftWorld craftWorld = ((CraftWorld) location.getWorld());
|
|
||||||
int x = location.getBlockX();
|
int x = location.getBlockX();
|
||||||
int y = location.getBlockY();
|
int y = location.getBlockY();
|
||||||
int z = location.getBlockZ();
|
int z = location.getBlockZ();
|
||||||
|
|
||||||
final ServerLevel handle = craftWorld.getHandle();
|
final ServerLevel handle = getServerLevel(location.getWorld());
|
||||||
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
||||||
final BlockPos blockPos = new BlockPos(x, y, z);
|
final BlockPos blockPos = new BlockPos(x, y, z);
|
||||||
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
||||||
@ -337,10 +327,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorldNativeAccess<?, ?, ?> createWorldNativeAccess(org.bukkit.World world) {
|
public WorldNativeAccess<?, ?, ?> createWorldNativeAccess(org.bukkit.World world) {
|
||||||
return new PaperweightFaweWorldNativeAccess(
|
return new PaperweightFaweWorldNativeAccess(this, new WeakReference<>(getServerLevel(world)));
|
||||||
this,
|
|
||||||
new WeakReference<>(((CraftWorld) world).getHandle())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -485,7 +472,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendFakeChunk(org.bukkit.World world, Player player, ChunkPacket chunkPacket) {
|
public void sendFakeChunk(org.bukkit.World world, Player player, ChunkPacket chunkPacket) {
|
||||||
ServerLevel nmsWorld = ((CraftWorld) world).getHandle();
|
ServerLevel nmsWorld = getServerLevel(world);
|
||||||
ChunkHolder map = PaperweightPlatformAdapter.getPlayerChunk(nmsWorld, chunkPacket.getChunkX(), chunkPacket.getChunkZ());
|
ChunkHolder map = PaperweightPlatformAdapter.getPlayerChunk(nmsWorld, chunkPacket.getChunkX(), chunkPacket.getChunkZ());
|
||||||
if (map != null && map.wasAccessibleSinceLastSave()) {
|
if (map != null && map.wasAccessibleSinceLastSave()) {
|
||||||
// PlayerChunk.d players = map.players;
|
// PlayerChunk.d players = map.players;
|
||||||
@ -522,7 +509,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
int internalId = BlockStateIdAccess.getBlockStateId(blockState);
|
int internalId = BlockStateIdAccess.getBlockStateId(blockState);
|
||||||
net.minecraft.world.level.block.state.BlockState blockState1 = Block.stateById(internalId);
|
net.minecraft.world.level.block.state.BlockState blockState1 = Block.stateById(internalId);
|
||||||
return blockState1.hasPostProcess(
|
return blockState1.hasPostProcess(
|
||||||
((CraftWorld) world).getHandle(),
|
getServerLevel(world),
|
||||||
new BlockPos(blockVector3.getX(), blockVector3.getY(), blockVector3.getZ())
|
new BlockPos(blockVector3.getX(), blockVector3.getY(), blockVector3.getZ())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -538,54 +525,33 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean generateTree(
|
protected void preCaptureStates(final ServerLevel serverLevel) {
|
||||||
TreeGenerator.TreeType treeType, EditSession editSession, BlockVector3 blockVector3,
|
serverLevel.captureTreeGeneration = true;
|
||||||
org.bukkit.World bukkitWorld
|
serverLevel.captureBlockStates = true;
|
||||||
) {
|
}
|
||||||
TreeType bukkitType = BukkitWorld.toBukkitTreeType(treeType);
|
|
||||||
if (bukkitType == TreeType.CHORUS_PLANT) {
|
@Override
|
||||||
blockVector3 = blockVector3.add(
|
protected List<org.bukkit.block.BlockState> getCapturedBlockStatesCopy(final ServerLevel serverLevel) {
|
||||||
0,
|
return new ArrayList<>(serverLevel.capturedBlockStates.values());
|
||||||
1,
|
}
|
||||||
0
|
|
||||||
); // bukkit skips the feature gen which does this offset normally, so we have to add it back
|
@Override
|
||||||
}
|
protected void postCaptureBlockStates(final ServerLevel serverLevel) {
|
||||||
ServerLevel serverLevel = ((CraftWorld) bukkitWorld).getHandle();
|
serverLevel.captureBlockStates = false;
|
||||||
final BlockVector3 finalBlockVector = blockVector3;
|
serverLevel.captureTreeGeneration = false;
|
||||||
// Sync to main thread to ensure no clashes occur
|
serverLevel.capturedBlockStates.clear();
|
||||||
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
|
}
|
||||||
serverLevel.captureTreeGeneration = true;
|
|
||||||
serverLevel.captureBlockStates = true;
|
@Override
|
||||||
try {
|
protected ServerLevel getServerLevel(final World world) {
|
||||||
if (!bukkitWorld.generateTree(BukkitAdapter.adapt(bukkitWorld, finalBlockVector), bukkitType)) {
|
return ((CraftWorld) world).getHandle();
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return ImmutableMap.copyOf(serverLevel.capturedBlockStates);
|
|
||||||
} finally {
|
|
||||||
serverLevel.captureBlockStates = false;
|
|
||||||
serverLevel.captureTreeGeneration = false;
|
|
||||||
serverLevel.capturedBlockStates.clear();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (placed == null || placed.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (CraftBlockState craftBlockState : placed.values()) {
|
|
||||||
if (craftBlockState == null || craftBlockState.getType() == Material.AIR) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
editSession.setBlock(craftBlockState.getX(), craftBlockState.getY(), craftBlockState.getZ(),
|
|
||||||
BukkitAdapter.adapt(((org.bukkit.block.BlockState) craftBlockState).getBlockData())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<org.bukkit.entity.Entity> getEntities(org.bukkit.World world) {
|
public List<org.bukkit.entity.Entity> getEntities(org.bukkit.World world) {
|
||||||
// Quickly add each entity to a list copy.
|
// Quickly add each entity to a list copy.
|
||||||
List<Entity> mcEntities = new ArrayList<>();
|
List<Entity> mcEntities = new ArrayList<>();
|
||||||
((CraftWorld) world).getHandle().entityManager.getEntityGetter().getAll().forEach(mcEntities::add);
|
getServerLevel(world).entityManager.getEntityGetter().getAll().forEach(mcEntities::add);
|
||||||
|
|
||||||
List<org.bukkit.entity.Entity> list = new ArrayList<>();
|
List<org.bukkit.entity.Entity> list = new ArrayList<>();
|
||||||
mcEntities.forEach((mcEnt) -> {
|
mcEntities.forEach((mcEnt) -> {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_19_R3;
|
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_19_R3;
|
||||||
|
|
||||||
import com.fastasyncworldedit.bukkit.adapter.CachedBukkitAdapter;
|
import com.fastasyncworldedit.bukkit.adapter.FaweAdapter;
|
||||||
import com.fastasyncworldedit.bukkit.adapter.IDelegateBukkitImplAdapter;
|
|
||||||
import com.fastasyncworldedit.bukkit.adapter.NMSRelighterFactory;
|
import com.fastasyncworldedit.bukkit.adapter.NMSRelighterFactory;
|
||||||
import com.fastasyncworldedit.core.FaweCache;
|
import com.fastasyncworldedit.core.FaweCache;
|
||||||
import com.fastasyncworldedit.core.entity.LazyBaseEntity;
|
import com.fastasyncworldedit.core.entity.LazyBaseEntity;
|
||||||
@ -10,15 +9,12 @@ import com.fastasyncworldedit.core.queue.IBatchProcessor;
|
|||||||
import com.fastasyncworldedit.core.queue.IChunkGet;
|
import com.fastasyncworldedit.core.queue.IChunkGet;
|
||||||
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
||||||
import com.fastasyncworldedit.core.util.NbtUtils;
|
import com.fastasyncworldedit.core.util.NbtUtils;
|
||||||
import com.fastasyncworldedit.core.util.TaskManager;
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.sk89q.jnbt.Tag;
|
import com.sk89q.jnbt.Tag;
|
||||||
import com.sk89q.worldedit.EditSession;
|
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
|
||||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_19_R3.PaperweightAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_19_R3.PaperweightAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_19_R3.nbt.PaperweightLazyCompoundTag;
|
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_19_R3.nbt.PaperweightLazyCompoundTag;
|
||||||
@ -38,7 +34,6 @@ import com.sk89q.worldedit.registry.state.Property;
|
|||||||
import com.sk89q.worldedit.util.Direction;
|
import com.sk89q.worldedit.util.Direction;
|
||||||
import com.sk89q.worldedit.util.SideEffect;
|
import com.sk89q.worldedit.util.SideEffect;
|
||||||
import com.sk89q.worldedit.util.SideEffectSet;
|
import com.sk89q.worldedit.util.SideEffectSet;
|
||||||
import com.sk89q.worldedit.util.TreeGenerator;
|
|
||||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.nbt.BinaryTag;
|
import com.sk89q.worldedit.util.nbt.BinaryTag;
|
||||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||||
@ -77,13 +72,11 @@ import net.minecraft.world.level.chunk.LevelChunk;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.TreeType;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.craftbukkit.v1_19_R3.CraftServer;
|
import org.bukkit.craftbukkit.v1_19_R3.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
|
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.v1_19_R3.block.CraftBlockState;
|
|
||||||
import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData;
|
import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData;
|
||||||
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer;
|
||||||
@ -111,8 +104,7 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
import static net.minecraft.core.registries.Registries.BIOME;
|
import static net.minecraft.core.registries.Registries.BIOME;
|
||||||
|
|
||||||
public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.Tag, ServerLevel> {
|
||||||
IDelegateBukkitImplAdapter<net.minecraft.nbt.Tag> {
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
||||||
private static Method CHUNK_HOLDER_WAS_ACCESSIBLE_SINCE_LAST_SAVE;
|
private static Method CHUNK_HOLDER_WAS_ACCESSIBLE_SINCE_LAST_SAVE;
|
||||||
@ -244,11 +236,10 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
public BlockState getBlock(Location location) {
|
public BlockState getBlock(Location location) {
|
||||||
Preconditions.checkNotNull(location);
|
Preconditions.checkNotNull(location);
|
||||||
|
|
||||||
CraftWorld craftWorld = ((CraftWorld) location.getWorld());
|
|
||||||
int x = location.getBlockX();
|
int x = location.getBlockX();
|
||||||
int y = location.getBlockY();
|
int y = location.getBlockY();
|
||||||
int z = location.getBlockZ();
|
int z = location.getBlockZ();
|
||||||
final ServerLevel handle = craftWorld.getHandle();
|
final ServerLevel handle = getServerLevel(location.getWorld());
|
||||||
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
||||||
final BlockPos blockPos = new BlockPos(x, y, z);
|
final BlockPos blockPos = new BlockPos(x, y, z);
|
||||||
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
||||||
@ -264,12 +255,11 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
public BaseBlock getFullBlock(final Location location) {
|
public BaseBlock getFullBlock(final Location location) {
|
||||||
Preconditions.checkNotNull(location);
|
Preconditions.checkNotNull(location);
|
||||||
|
|
||||||
CraftWorld craftWorld = ((CraftWorld) location.getWorld());
|
|
||||||
int x = location.getBlockX();
|
int x = location.getBlockX();
|
||||||
int y = location.getBlockY();
|
int y = location.getBlockY();
|
||||||
int z = location.getBlockZ();
|
int z = location.getBlockZ();
|
||||||
|
|
||||||
final ServerLevel handle = craftWorld.getHandle();
|
final ServerLevel handle = getServerLevel(location.getWorld());
|
||||||
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
||||||
final BlockPos blockPos = new BlockPos(x, y, z);
|
final BlockPos blockPos = new BlockPos(x, y, z);
|
||||||
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
||||||
@ -298,10 +288,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorldNativeAccess<?, ?, ?> createWorldNativeAccess(org.bukkit.World world) {
|
public WorldNativeAccess<?, ?, ?> createWorldNativeAccess(org.bukkit.World world) {
|
||||||
return new PaperweightFaweWorldNativeAccess(
|
return new PaperweightFaweWorldNativeAccess(this, new WeakReference<>(getServerLevel(world)));
|
||||||
this,
|
|
||||||
new WeakReference<>(((CraftWorld) world).getHandle())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -446,7 +433,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendFakeChunk(org.bukkit.World world, Player player, ChunkPacket chunkPacket) {
|
public void sendFakeChunk(org.bukkit.World world, Player player, ChunkPacket chunkPacket) {
|
||||||
ServerLevel nmsWorld = ((CraftWorld) world).getHandle();
|
ServerLevel nmsWorld = getServerLevel(world);
|
||||||
ChunkHolder map = PaperweightPlatformAdapter.getPlayerChunk(nmsWorld, chunkPacket.getChunkX(), chunkPacket.getChunkZ());
|
ChunkHolder map = PaperweightPlatformAdapter.getPlayerChunk(nmsWorld, chunkPacket.getChunkX(), chunkPacket.getChunkZ());
|
||||||
if (map != null && wasAccessibleSinceLastSave(map)) {
|
if (map != null && wasAccessibleSinceLastSave(map)) {
|
||||||
boolean flag = false;
|
boolean flag = false;
|
||||||
@ -484,7 +471,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
int internalId = BlockStateIdAccess.getBlockStateId(blockState);
|
int internalId = BlockStateIdAccess.getBlockStateId(blockState);
|
||||||
net.minecraft.world.level.block.state.BlockState blockState1 = Block.stateById(internalId);
|
net.minecraft.world.level.block.state.BlockState blockState1 = Block.stateById(internalId);
|
||||||
return blockState1.hasPostProcess(
|
return blockState1.hasPostProcess(
|
||||||
((CraftWorld) world).getHandle(),
|
getServerLevel(world),
|
||||||
new BlockPos(blockVector3.getX(), blockVector3.getY(), blockVector3.getZ())
|
new BlockPos(blockVector3.getX(), blockVector3.getY(), blockVector3.getZ())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -501,47 +488,26 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean generateTree(
|
protected void preCaptureStates(final ServerLevel serverLevel) {
|
||||||
TreeGenerator.TreeType treeType, EditSession editSession, BlockVector3 blockVector3,
|
serverLevel.captureTreeGeneration = true;
|
||||||
org.bukkit.World bukkitWorld
|
serverLevel.captureBlockStates = true;
|
||||||
) {
|
}
|
||||||
TreeType bukkitType = BukkitWorld.toBukkitTreeType(treeType);
|
|
||||||
if (bukkitType == TreeType.CHORUS_PLANT) {
|
@Override
|
||||||
blockVector3 = blockVector3.add(
|
protected List<org.bukkit.block.BlockState> getCapturedBlockStatesCopy(final ServerLevel serverLevel) {
|
||||||
0,
|
return new ArrayList<>(serverLevel.capturedBlockStates.values());
|
||||||
1,
|
}
|
||||||
0
|
|
||||||
); // bukkit skips the feature gen which does this offset normally, so we have to add it back
|
@Override
|
||||||
}
|
protected void postCaptureBlockStates(final ServerLevel serverLevel) {
|
||||||
ServerLevel serverLevel = ((CraftWorld) bukkitWorld).getHandle();
|
serverLevel.captureBlockStates = false;
|
||||||
final BlockVector3 finalBlockVector = blockVector3;
|
serverLevel.captureTreeGeneration = false;
|
||||||
// Sync to main thread to ensure no clashes occur
|
serverLevel.capturedBlockStates.clear();
|
||||||
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
|
}
|
||||||
serverLevel.captureTreeGeneration = true;
|
|
||||||
serverLevel.captureBlockStates = true;
|
@Override
|
||||||
try {
|
protected ServerLevel getServerLevel(final World world) {
|
||||||
if (!bukkitWorld.generateTree(BukkitAdapter.adapt(bukkitWorld, finalBlockVector), bukkitType)) {
|
return ((CraftWorld) world).getHandle();
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return ImmutableMap.copyOf(serverLevel.capturedBlockStates);
|
|
||||||
} finally {
|
|
||||||
serverLevel.captureBlockStates = false;
|
|
||||||
serverLevel.captureTreeGeneration = false;
|
|
||||||
serverLevel.capturedBlockStates.clear();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (placed == null || placed.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (CraftBlockState craftBlockState : placed.values()) {
|
|
||||||
if (craftBlockState == null || craftBlockState.getType() == Material.AIR) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
editSession.setBlock(craftBlockState.getX(), craftBlockState.getY(), craftBlockState.getZ(),
|
|
||||||
BukkitAdapter.adapt(((org.bukkit.block.BlockState) craftBlockState).getBlockData())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R1;
|
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R1;
|
||||||
|
|
||||||
import com.fastasyncworldedit.bukkit.adapter.CachedBukkitAdapter;
|
import com.fastasyncworldedit.bukkit.adapter.FaweAdapter;
|
||||||
import com.fastasyncworldedit.bukkit.adapter.IDelegateBukkitImplAdapter;
|
|
||||||
import com.fastasyncworldedit.bukkit.adapter.NMSRelighterFactory;
|
import com.fastasyncworldedit.bukkit.adapter.NMSRelighterFactory;
|
||||||
import com.fastasyncworldedit.core.FaweCache;
|
import com.fastasyncworldedit.core.FaweCache;
|
||||||
import com.fastasyncworldedit.core.entity.LazyBaseEntity;
|
import com.fastasyncworldedit.core.entity.LazyBaseEntity;
|
||||||
@ -10,15 +9,12 @@ import com.fastasyncworldedit.core.queue.IBatchProcessor;
|
|||||||
import com.fastasyncworldedit.core.queue.IChunkGet;
|
import com.fastasyncworldedit.core.queue.IChunkGet;
|
||||||
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
||||||
import com.fastasyncworldedit.core.util.NbtUtils;
|
import com.fastasyncworldedit.core.util.NbtUtils;
|
||||||
import com.fastasyncworldedit.core.util.TaskManager;
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.sk89q.jnbt.Tag;
|
import com.sk89q.jnbt.Tag;
|
||||||
import com.sk89q.worldedit.EditSession;
|
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
|
||||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_20_R1.PaperweightAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_20_R1.PaperweightAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R1.nbt.PaperweightLazyCompoundTag;
|
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R1.nbt.PaperweightLazyCompoundTag;
|
||||||
@ -38,7 +34,6 @@ import com.sk89q.worldedit.registry.state.Property;
|
|||||||
import com.sk89q.worldedit.util.Direction;
|
import com.sk89q.worldedit.util.Direction;
|
||||||
import com.sk89q.worldedit.util.SideEffect;
|
import com.sk89q.worldedit.util.SideEffect;
|
||||||
import com.sk89q.worldedit.util.SideEffectSet;
|
import com.sk89q.worldedit.util.SideEffectSet;
|
||||||
import com.sk89q.worldedit.util.TreeGenerator;
|
|
||||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.nbt.BinaryTag;
|
import com.sk89q.worldedit.util.nbt.BinaryTag;
|
||||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||||
@ -77,13 +72,11 @@ import net.minecraft.world.level.chunk.LevelChunk;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.TreeType;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.CraftServer;
|
import org.bukkit.craftbukkit.v1_20_R1.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
|
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlockState;
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData;
|
import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData;
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
|
||||||
@ -111,8 +104,7 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
import static net.minecraft.core.registries.Registries.BIOME;
|
import static net.minecraft.core.registries.Registries.BIOME;
|
||||||
|
|
||||||
public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.Tag, ServerLevel> {
|
||||||
IDelegateBukkitImplAdapter<net.minecraft.nbt.Tag> {
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
||||||
private static Method CHUNK_HOLDER_WAS_ACCESSIBLE_SINCE_LAST_SAVE;
|
private static Method CHUNK_HOLDER_WAS_ACCESSIBLE_SINCE_LAST_SAVE;
|
||||||
@ -244,11 +236,10 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
public BlockState getBlock(Location location) {
|
public BlockState getBlock(Location location) {
|
||||||
Preconditions.checkNotNull(location);
|
Preconditions.checkNotNull(location);
|
||||||
|
|
||||||
CraftWorld craftWorld = ((CraftWorld) location.getWorld());
|
|
||||||
int x = location.getBlockX();
|
int x = location.getBlockX();
|
||||||
int y = location.getBlockY();
|
int y = location.getBlockY();
|
||||||
int z = location.getBlockZ();
|
int z = location.getBlockZ();
|
||||||
final ServerLevel handle = craftWorld.getHandle();
|
final ServerLevel handle = getServerLevel(location.getWorld());
|
||||||
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
||||||
final BlockPos blockPos = new BlockPos(x, y, z);
|
final BlockPos blockPos = new BlockPos(x, y, z);
|
||||||
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
||||||
@ -264,12 +255,11 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
public BaseBlock getFullBlock(final Location location) {
|
public BaseBlock getFullBlock(final Location location) {
|
||||||
Preconditions.checkNotNull(location);
|
Preconditions.checkNotNull(location);
|
||||||
|
|
||||||
CraftWorld craftWorld = ((CraftWorld) location.getWorld());
|
|
||||||
int x = location.getBlockX();
|
int x = location.getBlockX();
|
||||||
int y = location.getBlockY();
|
int y = location.getBlockY();
|
||||||
int z = location.getBlockZ();
|
int z = location.getBlockZ();
|
||||||
|
|
||||||
final ServerLevel handle = craftWorld.getHandle();
|
final ServerLevel handle = getServerLevel(location.getWorld());
|
||||||
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
||||||
final BlockPos blockPos = new BlockPos(x, y, z);
|
final BlockPos blockPos = new BlockPos(x, y, z);
|
||||||
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
||||||
@ -298,10 +288,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorldNativeAccess<?, ?, ?> createWorldNativeAccess(org.bukkit.World world) {
|
public WorldNativeAccess<?, ?, ?> createWorldNativeAccess(org.bukkit.World world) {
|
||||||
return new PaperweightFaweWorldNativeAccess(
|
return new PaperweightFaweWorldNativeAccess(this, new WeakReference<>(getServerLevel(world)));
|
||||||
this,
|
|
||||||
new WeakReference<>(((CraftWorld) world).getHandle())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -446,7 +433,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendFakeChunk(org.bukkit.World world, Player player, ChunkPacket chunkPacket) {
|
public void sendFakeChunk(org.bukkit.World world, Player player, ChunkPacket chunkPacket) {
|
||||||
ServerLevel nmsWorld = ((CraftWorld) world).getHandle();
|
ServerLevel nmsWorld = getServerLevel(world);
|
||||||
ChunkHolder map = PaperweightPlatformAdapter.getPlayerChunk(nmsWorld, chunkPacket.getChunkX(), chunkPacket.getChunkZ());
|
ChunkHolder map = PaperweightPlatformAdapter.getPlayerChunk(nmsWorld, chunkPacket.getChunkX(), chunkPacket.getChunkZ());
|
||||||
if (map != null && wasAccessibleSinceLastSave(map)) {
|
if (map != null && wasAccessibleSinceLastSave(map)) {
|
||||||
boolean flag = false;
|
boolean flag = false;
|
||||||
@ -484,7 +471,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
int internalId = BlockStateIdAccess.getBlockStateId(blockState);
|
int internalId = BlockStateIdAccess.getBlockStateId(blockState);
|
||||||
net.minecraft.world.level.block.state.BlockState blockState1 = Block.stateById(internalId);
|
net.minecraft.world.level.block.state.BlockState blockState1 = Block.stateById(internalId);
|
||||||
return blockState1.hasPostProcess(
|
return blockState1.hasPostProcess(
|
||||||
((CraftWorld) world).getHandle(),
|
getServerLevel(world),
|
||||||
new BlockPos(blockVector3.getX(), blockVector3.getY(), blockVector3.getZ())
|
new BlockPos(blockVector3.getX(), blockVector3.getY(), blockVector3.getZ())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -501,47 +488,26 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean generateTree(
|
protected void preCaptureStates(final ServerLevel serverLevel) {
|
||||||
TreeGenerator.TreeType treeType, EditSession editSession, BlockVector3 blockVector3,
|
serverLevel.captureTreeGeneration = true;
|
||||||
org.bukkit.World bukkitWorld
|
serverLevel.captureBlockStates = true;
|
||||||
) {
|
}
|
||||||
TreeType bukkitType = BukkitWorld.toBukkitTreeType(treeType);
|
|
||||||
if (bukkitType == TreeType.CHORUS_PLANT) {
|
@Override
|
||||||
blockVector3 = blockVector3.add(
|
protected List<org.bukkit.block.BlockState> getCapturedBlockStatesCopy(final ServerLevel serverLevel) {
|
||||||
0,
|
return new ArrayList<>(serverLevel.capturedBlockStates.values());
|
||||||
1,
|
}
|
||||||
0
|
|
||||||
); // bukkit skips the feature gen which does this offset normally, so we have to add it back
|
@Override
|
||||||
}
|
protected void postCaptureBlockStates(final ServerLevel serverLevel) {
|
||||||
ServerLevel serverLevel = ((CraftWorld) bukkitWorld).getHandle();
|
serverLevel.captureBlockStates = false;
|
||||||
final BlockVector3 finalBlockVector = blockVector3;
|
serverLevel.captureTreeGeneration = false;
|
||||||
// Sync to main thread to ensure no clashes occur
|
serverLevel.capturedBlockStates.clear();
|
||||||
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
|
}
|
||||||
serverLevel.captureTreeGeneration = true;
|
|
||||||
serverLevel.captureBlockStates = true;
|
@Override
|
||||||
try {
|
protected ServerLevel getServerLevel(final World world) {
|
||||||
if (!bukkitWorld.generateTree(BukkitAdapter.adapt(bukkitWorld, finalBlockVector), bukkitType)) {
|
return ((CraftWorld) world).getHandle();
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return ImmutableMap.copyOf(serverLevel.capturedBlockStates);
|
|
||||||
} finally {
|
|
||||||
serverLevel.captureBlockStates = false;
|
|
||||||
serverLevel.captureTreeGeneration = false;
|
|
||||||
serverLevel.capturedBlockStates.clear();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (placed == null || placed.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (CraftBlockState craftBlockState : placed.values()) {
|
|
||||||
if (craftBlockState == null || craftBlockState.getType() == Material.AIR) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
editSession.setBlock(craftBlockState.getX(), craftBlockState.getY(), craftBlockState.getZ(),
|
|
||||||
BukkitAdapter.adapt(((org.bukkit.block.BlockState) craftBlockState).getBlockData())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -12,6 +12,6 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// https://repo.papermc.io/service/rest/repository/browse/maven-public/io/papermc/paper/dev-bundle/
|
// https://repo.papermc.io/service/rest/repository/browse/maven-public/io/papermc/paper/dev-bundle/
|
||||||
the<PaperweightUserDependenciesExtension>().paperDevBundle("1.20.2-R0.1-20231029.153906-63")
|
the<PaperweightUserDependenciesExtension>().paperDevBundle("1.20.2-R0.1-20231125.095734-103")
|
||||||
compileOnly(libs.paperlib)
|
compileOnly(libs.paperlib)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2;
|
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2;
|
||||||
|
|
||||||
import com.fastasyncworldedit.bukkit.adapter.CachedBukkitAdapter;
|
import com.fastasyncworldedit.bukkit.adapter.FaweAdapter;
|
||||||
import com.fastasyncworldedit.bukkit.adapter.IDelegateBukkitImplAdapter;
|
|
||||||
import com.fastasyncworldedit.bukkit.adapter.NMSRelighterFactory;
|
import com.fastasyncworldedit.bukkit.adapter.NMSRelighterFactory;
|
||||||
import com.fastasyncworldedit.core.FaweCache;
|
import com.fastasyncworldedit.core.FaweCache;
|
||||||
import com.fastasyncworldedit.core.entity.LazyBaseEntity;
|
import com.fastasyncworldedit.core.entity.LazyBaseEntity;
|
||||||
@ -10,15 +9,12 @@ import com.fastasyncworldedit.core.queue.IBatchProcessor;
|
|||||||
import com.fastasyncworldedit.core.queue.IChunkGet;
|
import com.fastasyncworldedit.core.queue.IChunkGet;
|
||||||
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
||||||
import com.fastasyncworldedit.core.util.NbtUtils;
|
import com.fastasyncworldedit.core.util.NbtUtils;
|
||||||
import com.fastasyncworldedit.core.util.TaskManager;
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.sk89q.jnbt.Tag;
|
import com.sk89q.jnbt.Tag;
|
||||||
import com.sk89q.worldedit.EditSession;
|
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
|
||||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2.nbt.PaperweightLazyCompoundTag;
|
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2.nbt.PaperweightLazyCompoundTag;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2.regen.PaperweightRegen;
|
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2.regen.PaperweightRegen;
|
||||||
@ -37,7 +33,6 @@ import com.sk89q.worldedit.registry.state.Property;
|
|||||||
import com.sk89q.worldedit.util.Direction;
|
import com.sk89q.worldedit.util.Direction;
|
||||||
import com.sk89q.worldedit.util.SideEffect;
|
import com.sk89q.worldedit.util.SideEffect;
|
||||||
import com.sk89q.worldedit.util.SideEffectSet;
|
import com.sk89q.worldedit.util.SideEffectSet;
|
||||||
import com.sk89q.worldedit.util.TreeGenerator;
|
|
||||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.nbt.BinaryTag;
|
import com.sk89q.worldedit.util.nbt.BinaryTag;
|
||||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||||
@ -76,13 +71,11 @@ import net.minecraft.world.level.chunk.LevelChunk;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.TreeType;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.CraftServer;
|
import org.bukkit.craftbukkit.v1_20_R2.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
|
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.block.CraftBlockState;
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData;
|
import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData;
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer;
|
||||||
@ -110,8 +103,7 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
import static net.minecraft.core.registries.Registries.BIOME;
|
import static net.minecraft.core.registries.Registries.BIOME;
|
||||||
|
|
||||||
public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.Tag, ServerLevel> {
|
||||||
IDelegateBukkitImplAdapter<net.minecraft.nbt.Tag> {
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
||||||
private static Method CHUNK_HOLDER_WAS_ACCESSIBLE_SINCE_LAST_SAVE;
|
private static Method CHUNK_HOLDER_WAS_ACCESSIBLE_SINCE_LAST_SAVE;
|
||||||
@ -247,11 +239,10 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
public BlockState getBlock(Location location) {
|
public BlockState getBlock(Location location) {
|
||||||
Preconditions.checkNotNull(location);
|
Preconditions.checkNotNull(location);
|
||||||
|
|
||||||
CraftWorld craftWorld = ((CraftWorld) location.getWorld());
|
|
||||||
int x = location.getBlockX();
|
int x = location.getBlockX();
|
||||||
int y = location.getBlockY();
|
int y = location.getBlockY();
|
||||||
int z = location.getBlockZ();
|
int z = location.getBlockZ();
|
||||||
final ServerLevel handle = craftWorld.getHandle();
|
final ServerLevel handle = getServerLevel(location.getWorld());
|
||||||
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
||||||
final BlockPos blockPos = new BlockPos(x, y, z);
|
final BlockPos blockPos = new BlockPos(x, y, z);
|
||||||
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
||||||
@ -267,12 +258,11 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
public BaseBlock getFullBlock(final Location location) {
|
public BaseBlock getFullBlock(final Location location) {
|
||||||
Preconditions.checkNotNull(location);
|
Preconditions.checkNotNull(location);
|
||||||
|
|
||||||
CraftWorld craftWorld = ((CraftWorld) location.getWorld());
|
|
||||||
int x = location.getBlockX();
|
int x = location.getBlockX();
|
||||||
int y = location.getBlockY();
|
int y = location.getBlockY();
|
||||||
int z = location.getBlockZ();
|
int z = location.getBlockZ();
|
||||||
|
|
||||||
final ServerLevel handle = craftWorld.getHandle();
|
final ServerLevel handle = getServerLevel(location.getWorld());
|
||||||
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
||||||
final BlockPos blockPos = new BlockPos(x, y, z);
|
final BlockPos blockPos = new BlockPos(x, y, z);
|
||||||
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
||||||
@ -301,10 +291,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorldNativeAccess<?, ?, ?> createWorldNativeAccess(org.bukkit.World world) {
|
public WorldNativeAccess<?, ?, ?> createWorldNativeAccess(org.bukkit.World world) {
|
||||||
return new PaperweightFaweWorldNativeAccess(
|
return new PaperweightFaweWorldNativeAccess(this, new WeakReference<>(getServerLevel(world)));
|
||||||
this,
|
|
||||||
new WeakReference<>(((CraftWorld) world).getHandle())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -449,7 +436,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendFakeChunk(org.bukkit.World world, Player player, ChunkPacket chunkPacket) {
|
public void sendFakeChunk(org.bukkit.World world, Player player, ChunkPacket chunkPacket) {
|
||||||
ServerLevel nmsWorld = ((CraftWorld) world).getHandle();
|
ServerLevel nmsWorld = getServerLevel(world);
|
||||||
ChunkHolder map = PaperweightPlatformAdapter.getPlayerChunk(nmsWorld, chunkPacket.getChunkX(), chunkPacket.getChunkZ());
|
ChunkHolder map = PaperweightPlatformAdapter.getPlayerChunk(nmsWorld, chunkPacket.getChunkX(), chunkPacket.getChunkZ());
|
||||||
if (map != null && wasAccessibleSinceLastSave(map)) {
|
if (map != null && wasAccessibleSinceLastSave(map)) {
|
||||||
boolean flag = false;
|
boolean flag = false;
|
||||||
@ -487,7 +474,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
int internalId = BlockStateIdAccess.getBlockStateId(blockState);
|
int internalId = BlockStateIdAccess.getBlockStateId(blockState);
|
||||||
net.minecraft.world.level.block.state.BlockState blockState1 = Block.stateById(internalId);
|
net.minecraft.world.level.block.state.BlockState blockState1 = Block.stateById(internalId);
|
||||||
return blockState1.hasPostProcess(
|
return blockState1.hasPostProcess(
|
||||||
((CraftWorld) world).getHandle(),
|
getServerLevel(world),
|
||||||
new BlockPos(blockVector3.getX(), blockVector3.getY(), blockVector3.getZ())
|
new BlockPos(blockVector3.getX(), blockVector3.getY(), blockVector3.getZ())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -504,47 +491,26 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean generateTree(
|
protected void preCaptureStates(final ServerLevel serverLevel) {
|
||||||
TreeGenerator.TreeType treeType, EditSession editSession, BlockVector3 blockVector3,
|
serverLevel.captureTreeGeneration = true;
|
||||||
org.bukkit.World bukkitWorld
|
serverLevel.captureBlockStates = true;
|
||||||
) {
|
}
|
||||||
TreeType bukkitType = BukkitWorld.toBukkitTreeType(treeType);
|
|
||||||
if (bukkitType == TreeType.CHORUS_PLANT) {
|
@Override
|
||||||
blockVector3 = blockVector3.add(
|
protected List<org.bukkit.block.BlockState> getCapturedBlockStatesCopy(final ServerLevel serverLevel) {
|
||||||
0,
|
return new ArrayList<>(serverLevel.capturedBlockStates.values());
|
||||||
1,
|
}
|
||||||
0
|
|
||||||
); // bukkit skips the feature gen which does this offset normally, so we have to add it back
|
@Override
|
||||||
}
|
protected void postCaptureBlockStates(final ServerLevel serverLevel) {
|
||||||
ServerLevel serverLevel = ((CraftWorld) bukkitWorld).getHandle();
|
serverLevel.captureBlockStates = false;
|
||||||
final BlockVector3 finalBlockVector = blockVector3;
|
serverLevel.captureTreeGeneration = false;
|
||||||
// Sync to main thread to ensure no clashes occur
|
serverLevel.capturedBlockStates.clear();
|
||||||
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
|
}
|
||||||
serverLevel.captureTreeGeneration = true;
|
|
||||||
serverLevel.captureBlockStates = true;
|
@Override
|
||||||
try {
|
protected ServerLevel getServerLevel(final World world) {
|
||||||
if (!bukkitWorld.generateTree(BukkitAdapter.adapt(bukkitWorld, finalBlockVector), bukkitType)) {
|
return ((CraftWorld) world).getHandle();
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return ImmutableMap.copyOf(serverLevel.capturedBlockStates);
|
|
||||||
} finally {
|
|
||||||
serverLevel.captureBlockStates = false;
|
|
||||||
serverLevel.captureTreeGeneration = false;
|
|
||||||
serverLevel.capturedBlockStates.clear();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (placed == null || placed.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (CraftBlockState craftBlockState : placed.values()) {
|
|
||||||
if (craftBlockState == null || craftBlockState.getType() == Material.AIR) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
editSession.setBlock(craftBlockState.getX(), craftBlockState.getY(), craftBlockState.getZ(),
|
|
||||||
BukkitAdapter.adapt(((org.bukkit.block.BlockState) craftBlockState).getBlockData())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
package com.fastasyncworldedit.bukkit.adapter;
|
||||||
|
|
||||||
|
import com.fastasyncworldedit.core.util.TaskManager;
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
|
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.util.TreeGenerator;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.TreeType;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A base class for version-specific implementations of the BukkitImplAdapter
|
||||||
|
*
|
||||||
|
* @param <TAG> the version-specific NBT tag type
|
||||||
|
* @param <SERVER_LEVEL> the version-specific ServerLevel type
|
||||||
|
*/
|
||||||
|
public abstract class FaweAdapter<TAG, SERVER_LEVEL> extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter<TAG> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generateTree(
|
||||||
|
final TreeGenerator.TreeType treeType,
|
||||||
|
final EditSession editSession,
|
||||||
|
BlockVector3 blockVector3,
|
||||||
|
final World world
|
||||||
|
) {
|
||||||
|
TreeType bukkitType = BukkitWorld.toBukkitTreeType(treeType);
|
||||||
|
if (bukkitType == TreeType.CHORUS_PLANT) {
|
||||||
|
// bukkit skips the feature gen which does this offset normally, so we have to add it back
|
||||||
|
blockVector3 = blockVector3.add(BlockVector3.UNIT_Y);
|
||||||
|
}
|
||||||
|
BlockVector3 target = blockVector3;
|
||||||
|
SERVER_LEVEL serverLevel = getServerLevel(world);
|
||||||
|
List<BlockState> placed = TaskManager.taskManager().sync(() -> {
|
||||||
|
preCaptureStates(serverLevel);
|
||||||
|
try {
|
||||||
|
if (!world.generateTree(BukkitAdapter.adapt(world, target), bukkitType)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return getCapturedBlockStatesCopy(serverLevel);
|
||||||
|
} finally {
|
||||||
|
postCaptureBlockStates(serverLevel);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (placed == null || placed.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (BlockState blockState : placed) {
|
||||||
|
if (blockState == null || blockState.getType() == Material.AIR) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
editSession.setBlock(blockState.getX(), blockState.getY(), blockState.getZ(),
|
||||||
|
BukkitAdapter.adapt(blockState.getBlockData())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void preCaptureStates(SERVER_LEVEL serverLevel);
|
||||||
|
|
||||||
|
protected abstract List<BlockState> getCapturedBlockStatesCopy(SERVER_LEVEL serverLevel);
|
||||||
|
|
||||||
|
protected abstract void postCaptureBlockStates(SERVER_LEVEL serverLevel);
|
||||||
|
|
||||||
|
protected abstract SERVER_LEVEL getServerLevel(World world);
|
||||||
|
|
||||||
|
}
|
@ -159,15 +159,20 @@ public class RollbackDatabase extends AsyncNotifyQueue {
|
|||||||
Future<Integer> future = call(() -> {
|
Future<Integer> future = call(() -> {
|
||||||
try {
|
try {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
String stmtStr = ascending ? uuid == null ? "SELECT * FROM`" + this.prefix + "edits` WHERE `time`>? AND `x2`>=? AND" +
|
String stmtStr;
|
||||||
" `x1`<=? AND `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? ORDER BY `time` , `id`" :
|
if (ascending) {
|
||||||
"SELECT * FROM`" + this.prefix + "edits` WHERE `time`>? AND" +
|
if (uuid == null) {
|
||||||
" `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? AND `player`=? ORDER BY `time` ASC, `id` ASC" :
|
stmtStr = "SELECT * FROM`%sedits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND " +
|
||||||
uuid == null ? "SELECT * FROM`" + this.prefix + "edits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND `z2`>=? " +
|
"`y2`>=? AND `y1`<=? ORDER BY `time` , `id`";
|
||||||
"AND `z1`<=? AND `y2`>=? AND `y1`<=? ORDER BY `time` DESC, `id` DESC" :
|
} else {
|
||||||
"SELECT * FROM`" + this.prefix + "edits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND" +
|
stmtStr = "SELECT * FROM`%sedits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND " +
|
||||||
" `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? AND `player`=? ORDER BY `time` DESC, `id` DESC";
|
"`y2`>=? AND `y1`<=? AND `player`=? ORDER BY `time` ASC, `id` ASC";
|
||||||
try (PreparedStatement stmt = connection.prepareStatement(stmtStr)) {
|
}
|
||||||
|
} else {
|
||||||
|
stmtStr = "SELECT * FROM`%sedits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND " +
|
||||||
|
"`y2`>=? AND `y1`<=? AND `player`=? ORDER BY `time` DESC, `id` DESC";
|
||||||
|
}
|
||||||
|
try (PreparedStatement stmt = connection.prepareStatement(stmtStr.formatted(this.prefix))) {
|
||||||
stmt.setInt(1, (int) (minTime / 1000));
|
stmt.setInt(1, (int) (minTime / 1000));
|
||||||
stmt.setInt(2, pos1.getBlockX());
|
stmt.setInt(2, pos1.getBlockX());
|
||||||
stmt.setInt(3, pos2.getBlockX());
|
stmt.setInt(3, pos2.getBlockX());
|
||||||
@ -193,20 +198,20 @@ public class RollbackDatabase extends AsyncNotifyQueue {
|
|||||||
if (delete && uuid != null) {
|
if (delete && uuid != null) {
|
||||||
try (PreparedStatement stmt = connection.prepareStatement("DELETE FROM`" + this.prefix +
|
try (PreparedStatement stmt = connection.prepareStatement("DELETE FROM`" + this.prefix +
|
||||||
"edits` WHERE `player`=? AND `time`>? AND `x2`>=? AND `x1`<=? AND `y2`>=? AND `y1`<=? AND `z2`>=? AND `z1`<=?")) {
|
"edits` WHERE `player`=? AND `time`>? AND `x2`>=? AND `x1`<=? AND `y2`>=? AND `y1`<=? AND `z2`>=? AND `z1`<=?")) {
|
||||||
stmt.setInt(1, (int) (minTime / 1000));
|
|
||||||
stmt.setInt(2, pos1.getBlockX());
|
|
||||||
stmt.setInt(3, pos2.getBlockX());
|
|
||||||
stmt.setInt(4, pos1.getBlockZ());
|
|
||||||
stmt.setInt(5, pos2.getBlockZ());
|
|
||||||
// Keep 128 offset for backwards-compatibility
|
|
||||||
stmt.setInt(6, pos1.getBlockY() - 128);
|
|
||||||
stmt.setInt(7, pos2.getBlockY() - 128);
|
|
||||||
byte[] uuidBytes = ByteBuffer
|
byte[] uuidBytes = ByteBuffer
|
||||||
.allocate(16)
|
.allocate(16)
|
||||||
.putLong(uuid.getMostSignificantBits())
|
.putLong(uuid.getMostSignificantBits())
|
||||||
.putLong(uuid.getLeastSignificantBits())
|
.putLong(uuid.getLeastSignificantBits())
|
||||||
.array();
|
.array();
|
||||||
stmt.setBytes(8, uuidBytes);
|
stmt.setBytes(1, uuidBytes);
|
||||||
|
stmt.setInt(2, (int) (minTime / 1000));
|
||||||
|
stmt.setInt(3, pos1.getBlockX());
|
||||||
|
stmt.setInt(4, pos2.getBlockX());
|
||||||
|
stmt.setInt(5, pos1.getBlockZ());
|
||||||
|
stmt.setInt(6, pos2.getBlockZ());
|
||||||
|
// Keep 128 offset for backwards-compatibility
|
||||||
|
stmt.setInt(7, pos1.getBlockY() - 128);
|
||||||
|
stmt.setInt(8, pos2.getBlockY() - 128);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
|
@ -15,8 +15,10 @@ import com.sk89q.jnbt.NBTOutputStream;
|
|||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.function.operation.ChangeSetExecutor;
|
import com.sk89q.worldedit.function.operation.ChangeSetExecutor;
|
||||||
|
import com.sk89q.worldedit.internal.util.LogManagerCompat;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@ -35,6 +37,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
*/
|
*/
|
||||||
public class DiskStorageHistory extends FaweStreamChangeSet {
|
public class DiskStorageHistory extends FaweStreamChangeSet {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
||||||
private static final Map<String, Map<UUID, Integer>> NEXT_INDEX = new ConcurrentHashMap<>();
|
private static final Map<String, Map<UUID, Integer>> NEXT_INDEX = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
@ -141,9 +144,9 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EditSession session = toEditSession(actor, regions);
|
try (EditSession session = toEditSession(actor, regions)) {
|
||||||
session.setBlocks(this, ChangeSetExecutor.Type.UNDO);
|
session.setBlocks(this, ChangeSetExecutor.Type.UNDO);
|
||||||
deleteFiles();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void undo(Actor actor) {
|
public void undo(Actor actor) {
|
||||||
@ -371,9 +374,14 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
|||||||
if (!bdFile.exists()) {
|
if (!bdFile.exists()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
FaweInputStream is = MainUtil.getCompressedIS(new FileInputStream(bdFile));
|
try {
|
||||||
readHeader(is);
|
FaweInputStream is = MainUtil.getCompressedIS(new FileInputStream(bdFile));
|
||||||
return is;
|
readHeader(is);
|
||||||
|
return is;
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.error("Could not load block history file {}", bdFile);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -381,7 +389,12 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
|||||||
if (!bioFile.exists()) {
|
if (!bioFile.exists()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return MainUtil.getCompressedIS(new FileInputStream(bioFile));
|
try {
|
||||||
|
return MainUtil.getCompressedIS(new FileInputStream(bioFile));
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.error("Could not load biome history file {}", bdFile);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -389,7 +402,12 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
|||||||
if (!enttFile.exists()) {
|
if (!enttFile.exists()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new NBTInputStream(MainUtil.getCompressedIS(new FileInputStream(enttFile)));
|
try {
|
||||||
|
return new NBTInputStream(MainUtil.getCompressedIS(new FileInputStream(enttFile)));
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.error("Could not load entity create history file {}", bdFile);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -397,7 +415,12 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
|||||||
if (!entfFile.exists()) {
|
if (!entfFile.exists()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new NBTInputStream(MainUtil.getCompressedIS(new FileInputStream(entfFile)));
|
try {
|
||||||
|
return new NBTInputStream(MainUtil.getCompressedIS(new FileInputStream(entfFile)));
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.error("Could not load entity remove history file {}", bdFile);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -405,7 +428,12 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
|||||||
if (!nbttFile.exists()) {
|
if (!nbttFile.exists()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new NBTInputStream(MainUtil.getCompressedIS(new FileInputStream(nbttFile)));
|
try {
|
||||||
|
return new NBTInputStream(MainUtil.getCompressedIS(new FileInputStream(nbttFile)));
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.error("Could not load tile create history file {}", bdFile);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -413,7 +441,12 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
|||||||
if (!nbtfFile.exists()) {
|
if (!nbtfFile.exists()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new NBTInputStream(MainUtil.getCompressedIS(new FileInputStream(nbtfFile)));
|
try {
|
||||||
|
return new NBTInputStream(MainUtil.getCompressedIS(new FileInputStream(nbtfFile)));
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.error("Could not load tile remove history file {}", bdFile);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,6 +7,7 @@ import com.sk89q.worldedit.internal.util.LogManagerCompat;
|
|||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -125,6 +126,26 @@ public class RollbackOptimizedHistory extends DiskStorageHistory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addBiomeChange(int x, int y, int z, BiomeType from, BiomeType to) {
|
||||||
|
super.addBiomeChange(x, y, z, from, to);
|
||||||
|
if (x < minX) {
|
||||||
|
minX = x;
|
||||||
|
} else if (x > maxX) {
|
||||||
|
maxX = x;
|
||||||
|
}
|
||||||
|
if (y < minY) {
|
||||||
|
minY = y;
|
||||||
|
} else if (y > maxY) {
|
||||||
|
maxY = y;
|
||||||
|
}
|
||||||
|
if (z < minZ) {
|
||||||
|
minZ = z;
|
||||||
|
} else if (z > maxZ) {
|
||||||
|
maxZ = z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeHeader(OutputStream os, int x, int y, int z) throws IOException {
|
public void writeHeader(OutputStream os, int x, int y, int z) throws IOException {
|
||||||
minX = x;
|
minX = x;
|
||||||
|
@ -257,12 +257,14 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public EditSession toEditSession(Actor actor, Region[] regions) {
|
public EditSession toEditSession(Actor actor, Region[] regions) {
|
||||||
EditSessionBuilder builder = WorldEdit.getInstance().newEditSessionBuilder().world(getWorld()).actor(actor).
|
EditSessionBuilder builder = WorldEdit.getInstance().newEditSessionBuilder().world(world)
|
||||||
fastMode(false).checkMemory(false).changeSet(this).limitUnlimited();
|
.checkMemory(false)
|
||||||
if (regions != null) {
|
.changeSetNull()
|
||||||
builder.allowedRegions(regions);
|
.fastMode(false)
|
||||||
} else {
|
.limitUnprocessed(actor)
|
||||||
builder.allowedRegionsEverywhere();
|
.actor(actor);
|
||||||
|
if (!actor.getLimit().RESTRICT_HISTORY_TO_REGIONS) {
|
||||||
|
builder = builder.allowedRegionsEverywhere();
|
||||||
}
|
}
|
||||||
EditSession editSession = builder.build();
|
EditSession editSession = builder.build();
|
||||||
editSession.setSize(1);
|
editSession.setSize(1);
|
||||||
|
@ -167,7 +167,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
|
|||||||
@Override
|
@Override
|
||||||
public int readX(FaweInputStream in) throws IOException {
|
public int readX(FaweInputStream in) throws IOException {
|
||||||
in.readFully(buffer);
|
in.readFully(buffer);
|
||||||
return lx = lx + ((((buffer[1] & 0xFF) + ((MathMan.unpair16x(buffer[3])) << 8)) << 20) >> 20);
|
return lx = lx + ((((buffer[1] & 0xFF) | ((MathMan.unpair16x(buffer[3])) << 8)) << 20) >> 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -177,7 +177,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int readZ(FaweInputStream in) throws IOException {
|
public int readZ(FaweInputStream in) throws IOException {
|
||||||
return lz = lz + ((((buffer[2] & 0xFF) + ((MathMan.unpair16y(buffer[3])) << 8)) << 20) >> 20);
|
return lz = lz + ((((buffer[2] & 0xFF) | ((MathMan.unpair16y(buffer[3])) << 8)) << 20) >> 20);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
@ -203,17 +203,17 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
|
|||||||
@Override
|
@Override
|
||||||
public int readX(FaweInputStream is) throws IOException {
|
public int readX(FaweInputStream is) throws IOException {
|
||||||
is.readFully(buffer);
|
is.readFully(buffer);
|
||||||
return lx = (lx + (buffer[0] & 0xFF) + (buffer[1] << 8));
|
return lx = lx + ((buffer[0] & 0xFF) | (buffer[1] << 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int readY(FaweInputStream is) throws IOException {
|
public int readY(FaweInputStream is) throws IOException {
|
||||||
return ly = (ly + (buffer[4] & 0xFF) + (buffer[5] << 8));
|
return ly = ly + ((buffer[4] & 0xFF) | (buffer[5]) << 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int readZ(FaweInputStream is) throws IOException {
|
public int readZ(FaweInputStream is) throws IOException {
|
||||||
return lz = (lz + (buffer[2] & 0xFF) + (buffer[3] << 8));
|
return lz = lz + ((buffer[2] & 0xFF) | (buffer[3]) << 8);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -353,7 +353,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
|
|||||||
os.write((byte) (z));
|
os.write((byte) (z));
|
||||||
// only need to store biomes in the 4x4x4 chunks so only need one byte for y still (signed byte -128 -> 127)
|
// only need to store biomes in the 4x4x4 chunks so only need one byte for y still (signed byte -128 -> 127)
|
||||||
// means -512 -> 508. Add 128 to avoid negative value casting.
|
// means -512 -> 508. Add 128 to avoid negative value casting.
|
||||||
os.write((byte) (y + 128));
|
os.write((byte) (y + 32));
|
||||||
os.writeVarInt(from.getInternalId());
|
os.writeVarInt(from.getInternalId());
|
||||||
os.writeVarInt(to.getInternalId());
|
os.writeVarInt(to.getInternalId());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -2,7 +2,6 @@ package com.fastasyncworldedit.core.queue;
|
|||||||
|
|
||||||
import com.fastasyncworldedit.core.extent.filter.block.FilterBlock;
|
import com.fastasyncworldedit.core.extent.filter.block.FilterBlock;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import org.jetbrains.annotations.Range;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -19,6 +19,20 @@ public interface IChunk extends Trimable, IChunkGet, IChunkSet {
|
|||||||
default <V extends IChunk> void init(IQueueExtent<V> extent, int x, int z) {
|
default <V extends IChunk> void init(IQueueExtent<V> extent, int x, int z) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get chunkX
|
||||||
|
*
|
||||||
|
* @return the x coordinate of the chunk
|
||||||
|
*/
|
||||||
|
int getX();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get chunkZ
|
||||||
|
*
|
||||||
|
* @return the z coordinate of the chunk
|
||||||
|
*/
|
||||||
|
int getZ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the chunk is a delegate, returns its parent's root
|
* If the chunk is a delegate, returns its parent's root
|
||||||
*
|
*
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package com.fastasyncworldedit.core.queue;
|
package com.fastasyncworldedit.core.queue;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Range;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IGetBlocks may be cached by the WorldChunkCache so that it can be used between multiple
|
* IGetBlocks may be cached by the WorldChunkCache so that it can be used between multiple
|
||||||
* IQueueExtents - avoids conversion between a palette and raw data on every block get
|
* IQueueExtents - avoids conversion between a palette and raw data on every block get
|
||||||
|
@ -7,7 +7,6 @@ import com.sk89q.worldedit.function.operation.Operation;
|
|||||||
import com.sk89q.worldedit.math.BlockVector2;
|
import com.sk89q.worldedit.math.BlockVector2;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import org.jetbrains.annotations.Range;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.io.Flushable;
|
import java.io.Flushable;
|
||||||
|
@ -13,20 +13,22 @@ import com.fastasyncworldedit.core.util.MainUtil;
|
|||||||
import com.fastasyncworldedit.core.util.StringMan;
|
import com.fastasyncworldedit.core.util.StringMan;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.EditSessionBuilder;
|
||||||
import com.sk89q.worldedit.LocalSession;
|
import com.sk89q.worldedit.LocalSession;
|
||||||
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.command.argument.Arguments;
|
import com.sk89q.worldedit.command.argument.Arguments;
|
||||||
import com.sk89q.worldedit.command.util.CommandPermissions;
|
import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||||
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
||||||
import com.sk89q.worldedit.command.util.annotation.AllowedRegion;
|
|
||||||
import com.sk89q.worldedit.command.util.annotation.Confirm;
|
import com.sk89q.worldedit.command.util.annotation.Confirm;
|
||||||
import com.sk89q.worldedit.command.util.annotation.Time;
|
import com.sk89q.worldedit.command.util.annotation.Time;
|
||||||
import com.sk89q.worldedit.entity.Player;
|
import com.sk89q.worldedit.entity.Player;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
|
import com.sk89q.worldedit.function.operation.ChangeSetExecutor;
|
||||||
import com.sk89q.worldedit.history.changeset.ChangeSet;
|
import com.sk89q.worldedit.history.changeset.ChangeSet;
|
||||||
import com.sk89q.worldedit.math.BlockVector2;
|
import com.sk89q.worldedit.math.BlockVector2;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
|
||||||
import com.sk89q.worldedit.util.Countable;
|
import com.sk89q.worldedit.util.Countable;
|
||||||
import com.sk89q.worldedit.util.Direction;
|
import com.sk89q.worldedit.util.Direction;
|
||||||
import com.sk89q.worldedit.util.Identifiable;
|
import com.sk89q.worldedit.util.Identifiable;
|
||||||
@ -80,7 +82,6 @@ public class HistorySubCommands {
|
|||||||
@Confirm
|
@Confirm
|
||||||
public synchronized void rerun(
|
public synchronized void rerun(
|
||||||
Player player, World world, RollbackDatabase database,
|
Player player, World world, RollbackDatabase database,
|
||||||
@AllowedRegion Region[] allowedRegions,
|
|
||||||
@ArgFlag(name = 'u', desc = "String user", def = "me")
|
@ArgFlag(name = 'u', desc = "String user", def = "me")
|
||||||
UUID other,
|
UUID other,
|
||||||
@ArgFlag(name = 'r', def = "0", desc = "radius")
|
@ArgFlag(name = 'r', def = "0", desc = "radius")
|
||||||
@ -90,7 +91,7 @@ public class HistorySubCommands {
|
|||||||
@Time
|
@Time
|
||||||
long timeDiff
|
long timeDiff
|
||||||
) throws WorldEditException {
|
) throws WorldEditException {
|
||||||
rollback(player, world, database, allowedRegions, other, radius, timeDiff, true);
|
rollback(player, world, database, other, radius, timeDiff, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
@ -102,7 +103,6 @@ public class HistorySubCommands {
|
|||||||
@Confirm
|
@Confirm
|
||||||
public synchronized void rollback(
|
public synchronized void rollback(
|
||||||
Player player, World world, RollbackDatabase database,
|
Player player, World world, RollbackDatabase database,
|
||||||
@AllowedRegion Region[] allowedRegions,
|
|
||||||
@ArgFlag(name = 'u', desc = "String user", def = "")
|
@ArgFlag(name = 'u', desc = "String user", def = "")
|
||||||
UUID other,
|
UUID other,
|
||||||
@ArgFlag(name = 'r', def = "0", desc = "radius")
|
@ArgFlag(name = 'r', def = "0", desc = "radius")
|
||||||
@ -149,9 +149,9 @@ public class HistorySubCommands {
|
|||||||
count++;
|
count++;
|
||||||
RollbackOptimizedHistory edit = supplier.get();
|
RollbackOptimizedHistory edit = supplier.get();
|
||||||
if (restore) {
|
if (restore) {
|
||||||
edit.redo(player, allowedRegions);
|
edit.redo(player);
|
||||||
} else {
|
} else {
|
||||||
edit.undo(player, allowedRegions);
|
edit.undo(player);
|
||||||
}
|
}
|
||||||
String path = edit.getWorld().getName() + "/" + finalOther + "-" + edit.getIndex();
|
String path = edit.getWorld().getName() + "/" + finalOther + "-" + edit.getIndex();
|
||||||
player.print(Caption.of("fawe.worldedit.rollback.rollback.element", path));
|
player.print(Caption.of("fawe.worldedit.rollback.rollback.element", path));
|
||||||
@ -201,8 +201,7 @@ public class HistorySubCommands {
|
|||||||
.at(summary.maxX, world.getMaxY(), summary.maxZ)
|
.at(summary.maxX, world.getMaxY(), summary.maxZ)
|
||||||
);
|
);
|
||||||
rollback.setTime(historyFile.lastModified());
|
rollback.setTime(historyFile.lastModified());
|
||||||
RollbackDatabase db = DBHandler.dbHandler()
|
RollbackDatabase db = DBHandler.dbHandler().getDatabase(world);
|
||||||
.getDatabase(world);
|
|
||||||
db.logEdit(rollback);
|
db.logEdit(rollback);
|
||||||
actor.print(TextComponent.of("Logging: " + historyFile));
|
actor.print(TextComponent.of("Logging: " + historyFile));
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class BoundedHeightMask extends AbstractMask {
|
|||||||
* @param maxY the maximum Y (must be equal to or greater than minY)
|
* @param maxY the maximum Y (must be equal to or greater than minY)
|
||||||
*/
|
*/
|
||||||
public BoundedHeightMask(int minY, int maxY) {
|
public BoundedHeightMask(int minY, int maxY) {
|
||||||
checkArgument(minY <= maxY, "minY <= maxY required");
|
checkArgument(minY <= maxY, "minY <= maxY required. minY:" + minY + " and maxY:" + maxY + " were given.");
|
||||||
this.minY = minY;
|
this.minY = minY;
|
||||||
this.maxY = maxY;
|
this.maxY = maxY;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,8 @@
|
|||||||
"fawe.worldedit.brush.brush.source.mask": "Brush source mask set",
|
"fawe.worldedit.brush.brush.source.mask": "Brush source mask set",
|
||||||
"fawe.worldedit.brush.brush.transform.disabled": "Brush transform disabled",
|
"fawe.worldedit.brush.brush.transform.disabled": "Brush transform disabled",
|
||||||
"fawe.worldedit.brush.brush.transform": "Brush transform set",
|
"fawe.worldedit.brush.brush.transform": "Brush transform set",
|
||||||
"fawe.worldedit.rollback.rollback.element": "Undoing {0}",
|
"fawe.worldedit.rollback.rollingback.index": "Undoing {0} ...",
|
||||||
|
"fawe.worldedit.rollback.rollback.element": "{0} undone.",
|
||||||
"fawe.worldedit.tool.tool.inspect": "Inspect tool bound to {0}.",
|
"fawe.worldedit.tool.tool.inspect": "Inspect tool bound to {0}.",
|
||||||
"fawe.worldedit.tool.tool.inspect.info": "{0} changed {1} to {2} {3} ago",
|
"fawe.worldedit.tool.tool.inspect.info": "{0} changed {1} to {2} {3} ago",
|
||||||
"fawe.worldedit.tool.tool.inspect.info.footer": "Total: {0} changes",
|
"fawe.worldedit.tool.tool.inspect.info.footer": "Total: {0} changes",
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren