From ae23794b436601bc86dd55fb1e4eed98e347a22b Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Wed, 29 Jul 2020 22:43:52 +0200 Subject: [PATCH] fix //cut -e --- .../adapter/impl/FAWE_Spigot_v1_14_R4.java | 7 ++- .../adapter/impl/FAWE_Spigot_v1_15_R2.java | 8 ++- .../adapter/impl/FAWE_Spigot_v1_16_R1.java | 20 +++---- .../beta/implementation/IChunkExtent.java | 54 ++++++++++++++++++- .../com/boydti/fawe/util/ReflectionUtils.java | 13 ----- .../function/entity/ExtentEntityCopy.java | 20 ++++++- .../function/operation/ForwardExtentCopy.java | 2 +- 7 files changed, 89 insertions(+), 35 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_14_R4.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_14_R4.java index 35778d1fd..8eed58bbf 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_14_R4.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_14_R4.java @@ -78,6 +78,7 @@ import java.util.function.Supplier; import java.util.stream.Stream; import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.jnbt.StringTag; public final class FAWE_Spigot_v1_14_R4 extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter { private final Spigot_v1_14_R4 parent; @@ -235,7 +236,11 @@ public final class FAWE_Spigot_v1_14_R4 extends CachedBukkitAdapter implements I Supplier saveTag = () -> { NBTTagCompound tag = new NBTTagCompound(); readEntityIntoTag(mcEntity, tag); - return (CompoundTag) toNative(tag); + + //add Id for AbstractChangeSet to work + CompoundTag natve = (CompoundTag) toNative(tag); + natve.getValue().put("Id", new StringTag(id)); + return natve; }; return new LazyBaseEntity(type, saveTag); } else { diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_15_R2.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_15_R2.java index 85dd26089..febca28de 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_15_R2.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_15_R2.java @@ -48,7 +48,6 @@ import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.SideEffect; import com.sk89q.worldedit.util.SideEffectSet; import com.sk89q.worldedit.world.biome.BiomeType; -import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.*; import com.sk89q.worldedit.world.entity.EntityType; @@ -82,6 +81,7 @@ import java.util.function.Supplier; import java.util.stream.Stream; import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.jnbt.StringTag; public final class FAWE_Spigot_v1_15_R2 extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter { private final Spigot_v1_15_R2 parent; @@ -245,7 +245,11 @@ public final class FAWE_Spigot_v1_15_R2 extends CachedBukkitAdapter implements I Supplier saveTag = () -> { NBTTagCompound tag = new NBTTagCompound(); readEntityIntoTag(mcEntity, tag); - return (CompoundTag) toNative(tag); + + //add Id for AbstractChangeSet to work + CompoundTag natve = (CompoundTag) toNative(tag); + natve.getValue().put("Id", new StringTag(id)); + return natve; }; return new LazyBaseEntity(type, saveTag); } else { diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R1.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R1.java index 3a5f2af11..10eb88d51 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R1.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R1.java @@ -22,17 +22,12 @@ package com.sk89q.worldedit.bukkit.adapter.impl; import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.beta.IChunkGet; -import com.boydti.fawe.beta.IQueueChunk; -import com.boydti.fawe.beta.IQueueExtent; import com.boydti.fawe.beta.implementation.packet.ChunkPacket; -import com.boydti.fawe.beta.implementation.queue.SingleThreadQueueExtent; import com.boydti.fawe.bukkit.adapter.mc1_16_1.*; import com.boydti.fawe.bukkit.adapter.mc1_16_1.nbt.LazyCompoundTag_1_16_1; -import com.google.common.io.Files; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.blocks.TileEntityBlock; import com.sk89q.worldedit.bukkit.BukkitAdapter; @@ -42,7 +37,6 @@ import com.sk89q.worldedit.bukkit.adapter.IDelegateBukkitImplAdapter; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.LazyBaseEntity; import com.sk89q.worldedit.internal.wna.WorldNativeAccess; -import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.SideEffect; @@ -55,7 +49,6 @@ import com.sk89q.worldedit.world.registry.BlockMaterial; import net.minecraft.server.v1_16_R1.*; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.World.Environment; import org.bukkit.block.data.BlockData; import org.bukkit.craftbukkit.v1_16_R1.CraftChunk; import org.bukkit.craftbukkit.v1_16_R1.CraftWorld; @@ -65,22 +58,17 @@ import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.generator.ChunkGenerator; import javax.annotation.Nullable; -import java.io.File; -import java.io.IOException; import java.lang.ref.WeakReference; import java.util.Map; import java.util.OptionalInt; import java.util.Set; -import java.util.UUID; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; import java.util.function.Supplier; import java.util.stream.Stream; import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.jnbt.StringTag; public final class FAWE_Spigot_v1_16_R1 extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter { private final Spigot_v1_16_R1 parent; @@ -244,7 +232,11 @@ public final class FAWE_Spigot_v1_16_R1 extends CachedBukkitAdapter implements I Supplier saveTag = () -> { NBTTagCompound tag = new NBTTagCompound(); readEntityIntoTag(mcEntity, tag); - return (CompoundTag) toNative(tag); + + //add Id for AbstractChangeSet to work + CompoundTag natve = (CompoundTag) toNative(tag); + natve.getValue().put("Id", new StringTag(id)); + return natve; }; return new LazyBaseEntity(type, saveTag); } else { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java index 40815ab67..f355cecea 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java @@ -20,6 +20,7 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; @@ -111,7 +112,7 @@ public interface IChunkExtent extends Extent { default Entity createEntity(Location location, BaseEntity entity) { final IChunk chunk = getOrCreateChunk(location.getBlockX() >> 4, location.getBlockZ() >> 4); CompoundTag tag = entity.getNbtData(); - Map map = ReflectionUtils.getMap(tag.getValue()); + Map map = new HashMap<>(tag.getValue()); //do not modify original entity data map.put("Id", new StringTag(entity.getType().getName())); //Set pos @@ -147,8 +148,11 @@ public interface IChunkExtent extends Extent { map.put("UUIDMost", new LongTag(newuuid.getMostSignificantBits())); map.put("UUIDLeast", new LongTag(newuuid.getLeastSignificantBits())); + map.put("PersistentIDMSB", new LongTag(newuuid.getMostSignificantBits())); + map.put("PersistentIDLSB", new LongTag(newuuid.getLeastSignificantBits())); + chunk.setEntity(tag); - return null; + return new IChunkEntity(this, location, newuuid, entity); } @Override @@ -156,4 +160,50 @@ public interface IChunkExtent extends Extent { final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); chunk.removeEntity(uuid); } + + class IChunkEntity implements Entity { + + private final Extent extent; + private final Location location; + private final UUID uuid; + private final BaseEntity base; + + public IChunkEntity(Extent extent, Location location, UUID uuid, BaseEntity base) { + this.extent = extent; + this.location = location; + this.uuid = uuid; + this.base = base; + } + + @Override + public BaseEntity getState() { + return base; + } + + @Override + public boolean remove() { + extent.removeEntity(location.getBlockX(), location.getBlockY(), location.getBlockZ(), uuid); + return true; + } + + @Override + public T getFacet(Class cls) { + return null; + } + + @Override + public Location getLocation() { + return location; + } + + @Override + public boolean setLocation(Location location) { + return false; + } + + @Override + public Extent getExtent() { + return extent; + } + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java index eb44ba67e..f55c8651e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java @@ -90,19 +90,6 @@ public class ReflectionUtils { } private static Class UNMODIFIABLE_MAP = Collections.unmodifiableMap(Collections.EMPTY_MAP).getClass(); - public static Map getMap(Map map) { - try { - Class clazz = map.getClass(); - if (clazz != UNMODIFIABLE_MAP) return map; - Field m = clazz.getDeclaredField("m"); - m.setAccessible(true); - return (Map) m.get(map); - } catch (Throwable e) { - e.printStackTrace(); - return map; - } - } - public static Object getHandle(Object wrapper) { final Method getHandle = makeMethod(wrapper.getClass(), "getHandle"); return callMethod(getHandle, wrapper); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java index b097b9eca..0b38902da 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java @@ -37,6 +37,8 @@ import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.entity.EntityTypes; import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.jnbt.LongTag; +import java.util.UUID; /** * Copies entities provided to the function to the provided destination @@ -44,6 +46,7 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class ExtentEntityCopy implements EntityFunction { + private final Extent source; private final Extent destination; private final Vector3 from; private final Vector3 to; @@ -58,11 +61,13 @@ public class ExtentEntityCopy implements EntityFunction { * @param to the destination position * @param transform the transformation to apply to both position and orientation */ - public ExtentEntityCopy(Vector3 from, Extent destination, Vector3 to, Transform transform) { + public ExtentEntityCopy(Extent source, Vector3 from, Extent destination, Vector3 to, Transform transform) { + checkNotNull(source); checkNotNull(from); checkNotNull(destination); checkNotNull(to); checkNotNull(transform); + this.source = source; this.destination = destination; this.from = from; this.to = to; @@ -119,7 +124,18 @@ public class ExtentEntityCopy implements EntityFunction { // Remove if (isRemoving() && success) { - entity.remove(); + //todo remove from source with Extent i guess? im confused now + UUID uuid = null; + if (tag.containsKey("UUID")) { + int[] arr = tag.getIntArray("UUID"); + uuid = new UUID((long)arr[0] << 32 | (arr[1] & 0xFFFFFFFFL), (long)arr[2] << 32 | (arr[3] & 0xFFFFFFFFL)); + } else if (tag.containsKey("UUIDMost")) { + uuid = new UUID(tag.getLong("UUIDMost"), tag.getLong("UUIDLeast")); + } else if (tag.containsKey("PersistentIDMSB")) { + uuid = new UUID(tag.getLong("PersistentIDMSB"), tag.getLong("PersistentIDLSB")); + } + if (uuid != null) + source.removeEntity(entity.getLocation().getBlockX(), entity.getLocation().getBlockY(), entity.getLocation().getBlockZ(), uuid); } return success; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java index 5c8f188c4..55948f63e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java @@ -393,7 +393,7 @@ public class ForwardExtentCopy implements Operation { Operations.completeBlindly(blockCopy); if (!entities.isEmpty()) { - ExtentEntityCopy entityCopy = new ExtentEntityCopy(from.toVector3(), destination, to.toVector3(), currentTransform); + ExtentEntityCopy entityCopy = new ExtentEntityCopy(source, from.toVector3(), destination, to.toVector3(), currentTransform); entityCopy.setRemoving(removingEntities); List entities2 = Lists.newArrayList(source.getEntities(region)); entities2.removeIf(entity -> {