fix //cut -e

This commit is contained in:
wea_ondara 2020-07-29 22:43:52 +02:00
parent 26110d336b
commit ae23794b43
7 changed files with 89 additions and 35 deletions

View File

@ -78,6 +78,7 @@ import java.util.function.Supplier;
import java.util.stream.Stream; import java.util.stream.Stream;
import static com.google.common.base.Preconditions.checkNotNull; 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<NBTBase> { public final class FAWE_Spigot_v1_14_R4 extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter<NBTBase> {
private final Spigot_v1_14_R4 parent; private final Spigot_v1_14_R4 parent;
@ -235,7 +236,11 @@ public final class FAWE_Spigot_v1_14_R4 extends CachedBukkitAdapter implements I
Supplier<CompoundTag> saveTag = () -> { Supplier<CompoundTag> saveTag = () -> {
NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
readEntityIntoTag(mcEntity, tag); 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); return new LazyBaseEntity(type, saveTag);
} else { } else {

View File

@ -48,7 +48,6 @@ import com.sk89q.worldedit.registry.state.Property;
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.world.biome.BiomeType; 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.BlockState;
import com.sk89q.worldedit.world.block.*; import com.sk89q.worldedit.world.block.*;
import com.sk89q.worldedit.world.entity.EntityType; import com.sk89q.worldedit.world.entity.EntityType;
@ -82,6 +81,7 @@ import java.util.function.Supplier;
import java.util.stream.Stream; import java.util.stream.Stream;
import static com.google.common.base.Preconditions.checkNotNull; 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<NBTBase> { public final class FAWE_Spigot_v1_15_R2 extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter<NBTBase> {
private final Spigot_v1_15_R2 parent; private final Spigot_v1_15_R2 parent;
@ -245,7 +245,11 @@ public final class FAWE_Spigot_v1_15_R2 extends CachedBukkitAdapter implements I
Supplier<CompoundTag> saveTag = () -> { Supplier<CompoundTag> saveTag = () -> {
NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
readEntityIntoTag(mcEntity, tag); 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); return new LazyBaseEntity(type, saveTag);
} else { } else {

View File

@ -22,17 +22,12 @@ package com.sk89q.worldedit.bukkit.adapter.impl;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.IChunkGet; 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.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.*;
import com.boydti.fawe.bukkit.adapter.mc1_16_1.nbt.LazyCompoundTag_1_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.CompoundTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
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;
@ -42,7 +37,6 @@ import com.sk89q.worldedit.bukkit.adapter.IDelegateBukkitImplAdapter;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.LazyBaseEntity; import com.sk89q.worldedit.entity.LazyBaseEntity;
import com.sk89q.worldedit.internal.wna.WorldNativeAccess; import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.SideEffect; 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 net.minecraft.server.v1_16_R1.*;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World.Environment;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_16_R1.CraftChunk; import org.bukkit.craftbukkit.v1_16_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld; 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.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.generator.ChunkGenerator;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.Map; import java.util.Map;
import java.util.OptionalInt; import java.util.OptionalInt;
import java.util.Set; 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.function.Supplier;
import java.util.stream.Stream; import java.util.stream.Stream;
import static com.google.common.base.Preconditions.checkNotNull; 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<NBTBase> { public final class FAWE_Spigot_v1_16_R1 extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter<NBTBase> {
private final Spigot_v1_16_R1 parent; private final Spigot_v1_16_R1 parent;
@ -244,7 +232,11 @@ public final class FAWE_Spigot_v1_16_R1 extends CachedBukkitAdapter implements I
Supplier<CompoundTag> saveTag = () -> { Supplier<CompoundTag> saveTag = () -> {
NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
readEntityIntoTag(mcEntity, tag); 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); return new LazyBaseEntity(type, saveTag);
} else { } else {

View File

@ -20,6 +20,7 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -111,7 +112,7 @@ public interface IChunkExtent<T extends IChunk> extends Extent {
default Entity createEntity(Location location, BaseEntity entity) { default Entity createEntity(Location location, BaseEntity entity) {
final IChunk chunk = getOrCreateChunk(location.getBlockX() >> 4, location.getBlockZ() >> 4); final IChunk chunk = getOrCreateChunk(location.getBlockX() >> 4, location.getBlockZ() >> 4);
CompoundTag tag = entity.getNbtData(); CompoundTag tag = entity.getNbtData();
Map<String, Tag> map = ReflectionUtils.getMap(tag.getValue()); Map<String, Tag> map = new HashMap<>(tag.getValue()); //do not modify original entity data
map.put("Id", new StringTag(entity.getType().getName())); map.put("Id", new StringTag(entity.getType().getName()));
//Set pos //Set pos
@ -147,8 +148,11 @@ public interface IChunkExtent<T extends IChunk> extends Extent {
map.put("UUIDMost", new LongTag(newuuid.getMostSignificantBits())); map.put("UUIDMost", new LongTag(newuuid.getMostSignificantBits()));
map.put("UUIDLeast", new LongTag(newuuid.getLeastSignificantBits())); map.put("UUIDLeast", new LongTag(newuuid.getLeastSignificantBits()));
map.put("PersistentIDMSB", new LongTag(newuuid.getMostSignificantBits()));
map.put("PersistentIDLSB", new LongTag(newuuid.getLeastSignificantBits()));
chunk.setEntity(tag); chunk.setEntity(tag);
return null; return new IChunkEntity(this, location, newuuid, entity);
} }
@Override @Override
@ -156,4 +160,50 @@ public interface IChunkExtent<T extends IChunk> extends Extent {
final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4);
chunk.removeEntity(uuid); 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> T getFacet(Class<? extends T> cls) {
return null;
}
@Override
public Location getLocation() {
return location;
}
@Override
public boolean setLocation(Location location) {
return false;
}
@Override
public Extent getExtent() {
return extent;
}
}
} }

View File

@ -90,19 +90,6 @@ public class ReflectionUtils {
} }
private static Class<?> UNMODIFIABLE_MAP = Collections.unmodifiableMap(Collections.EMPTY_MAP).getClass(); private static Class<?> UNMODIFIABLE_MAP = Collections.unmodifiableMap(Collections.EMPTY_MAP).getClass();
public static <T, V> Map<T, V> getMap(Map<T, V> map) {
try {
Class<? extends Map> clazz = map.getClass();
if (clazz != UNMODIFIABLE_MAP) return map;
Field m = clazz.getDeclaredField("m");
m.setAccessible(true);
return (Map<T, V>) m.get(map);
} catch (Throwable e) {
e.printStackTrace();
return map;
}
}
public static Object getHandle(Object wrapper) { public static Object getHandle(Object wrapper) {
final Method getHandle = makeMethod(wrapper.getClass(), "getHandle"); final Method getHandle = makeMethod(wrapper.getClass(), "getHandle");
return callMethod(getHandle, wrapper); return callMethod(getHandle, wrapper);

View File

@ -37,6 +37,8 @@ import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.entity.EntityTypes; import com.sk89q.worldedit.world.entity.EntityTypes;
import static com.google.common.base.Preconditions.checkNotNull; 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 * 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 { public class ExtentEntityCopy implements EntityFunction {
private final Extent source;
private final Extent destination; private final Extent destination;
private final Vector3 from; private final Vector3 from;
private final Vector3 to; private final Vector3 to;
@ -58,11 +61,13 @@ public class ExtentEntityCopy implements EntityFunction {
* @param to the destination position * @param to the destination position
* @param transform the transformation to apply to both position and orientation * @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(from);
checkNotNull(destination); checkNotNull(destination);
checkNotNull(to); checkNotNull(to);
checkNotNull(transform); checkNotNull(transform);
this.source = source;
this.destination = destination; this.destination = destination;
this.from = from; this.from = from;
this.to = to; this.to = to;
@ -119,7 +124,18 @@ public class ExtentEntityCopy implements EntityFunction {
// Remove // Remove
if (isRemoving() && success) { 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; return success;

View File

@ -393,7 +393,7 @@ public class ForwardExtentCopy implements Operation {
Operations.completeBlindly(blockCopy); Operations.completeBlindly(blockCopy);
if (!entities.isEmpty()) { 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); entityCopy.setRemoving(removingEntities);
List<? extends Entity> entities2 = Lists.newArrayList(source.getEntities(region)); List<? extends Entity> entities2 = Lists.newArrayList(source.getEntities(region));
entities2.removeIf(entity -> { entities2.removeIf(entity -> {