com.sk89q.worldedit.entity.BaseEntity Java Examples

The following examples show how to use com.sk89q.worldedit.entity.BaseEntity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Spigot_v1_13_R2_2.java    From worldedit-adapters with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public BaseEntity getEntity(org.bukkit.entity.Entity entity) {
    checkNotNull(entity);

    CraftEntity craftEntity = ((CraftEntity) entity);
    Entity mcEntity = craftEntity.getHandle();

    String id = getEntityId(mcEntity);

    if (id != null) {
        NBTTagCompound tag = new NBTTagCompound();
        readEntityIntoTag(mcEntity, tag);
        return new BaseEntity(com.sk89q.worldedit.world.entity.EntityTypes.get(id), (CompoundTag) toNative(tag));
    } else {
        return null;
    }
}
 
Example #2
Source File: FastWorldEditExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Entity createEntity(final Location loc, final BaseEntity entity) {
    if (entity != null) {
        CompoundTag tag = entity.getNbtData();
        Map<String, Tag> map = ReflectionUtils.getMap(tag.getValue());
        map.put("Id", new StringTag(entity.getTypeId()));
        ListTag pos = (ListTag) map.get("Pos");
        if (pos != null) {
            List<Tag> posList = ReflectionUtils.getList(pos.getValue());
            posList.set(0, new DoubleTag(loc.getX()));
            posList.set(1, new DoubleTag(loc.getY()));
            posList.set(2, new DoubleTag(loc.getZ()));
        }
        queue.setEntity(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), tag);
    }
    return null;
}
 
Example #3
Source File: FaweAdapter_1_10.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public BaseEntity getEntity(org.bukkit.entity.Entity entity)
{
    Preconditions.checkNotNull(entity);

    CraftEntity craftEntity = (CraftEntity)entity;
    net.minecraft.server.v1_10_R1.Entity mcEntity = craftEntity.getHandle();

    String id = getEntityId(mcEntity);
    if (id != null)
    {
        NBTTagCompound tag = new NBTTagCompound();
        readEntityIntoTag(mcEntity, tag);
        return new BaseEntity(id, (CompoundTag)toNative(tag));
    }
    return null;
}
 
Example #4
Source File: Spigot_v1_14_R4.java    From worldedit-adapters with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public BaseEntity getEntity(org.bukkit.entity.Entity entity) {
    checkNotNull(entity);

    CraftEntity craftEntity = ((CraftEntity) entity);
    Entity mcEntity = craftEntity.getHandle();

    String id = getEntityId(mcEntity);

    if (id != null) {
        NBTTagCompound tag = new NBTTagCompound();
        readEntityIntoTag(mcEntity, tag);
        return new BaseEntity(com.sk89q.worldedit.world.entity.EntityTypes.get(id), (CompoundTag) toNative(tag));
    } else {
        return null;
    }
}
 
Example #5
Source File: FaweAdapter_1_12.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public BaseEntity getEntity(org.bukkit.entity.Entity entity)
{
    Preconditions.checkNotNull(entity);

    CraftEntity craftEntity = (CraftEntity)entity;
    Entity mcEntity = craftEntity.getHandle();

    String id = getEntityId(mcEntity);
    if (id != null) {
        NBTTagCompound tag = new NBTTagCompound();
        readEntityIntoTag(mcEntity, tag);
        CompoundTag weTag = (CompoundTag) toNative(tag);
        return new BaseEntity(id, weTag);
    }
    return null;
}
 
Example #6
Source File: FaweAdapter_1_9.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public BaseEntity getEntity(org.bukkit.entity.Entity entity)
{
    Preconditions.checkNotNull(entity);

    CraftEntity craftEntity = (CraftEntity)entity;
    net.minecraft.server.v1_9_R2.Entity mcEntity = craftEntity.getHandle();

    String id = getEntityId(mcEntity);
    if (id != null)
    {
        NBTTagCompound tag = new NBTTagCompound();
        readEntityIntoTag(mcEntity, tag);
        return new BaseEntity(id, (CompoundTag)toNative(tag));
    }
    return null;
}
 
Example #7
Source File: Spigot_v1_15_R2.java    From worldedit-adapters with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public BaseEntity getEntity(org.bukkit.entity.Entity entity) {
    checkNotNull(entity);

    CraftEntity craftEntity = ((CraftEntity) entity);
    Entity mcEntity = craftEntity.getHandle();

    String id = getEntityId(mcEntity);

    if (id != null) {
        NBTTagCompound tag = new NBTTagCompound();
        readEntityIntoTag(mcEntity, tag);
        return new BaseEntity(com.sk89q.worldedit.world.entity.EntityTypes.get(id), (CompoundTag) toNative(tag));
    } else {
        return null;
    }
}
 
Example #8
Source File: FaweAdapter_1_11.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public BaseEntity getEntity(org.bukkit.entity.Entity entity)
{
    Preconditions.checkNotNull(entity);

    CraftEntity craftEntity = (CraftEntity)entity;
    Entity mcEntity = craftEntity.getHandle();

    String id = getEntityId(mcEntity);
    if (id != null) {
        NBTTagCompound tag = new NBTTagCompound();
        readEntityIntoTag(mcEntity, tag);
        CompoundTag weTag = (CompoundTag) toNative(tag);
        return new BaseEntity(id, weTag);
    }
    return null;
}
 
Example #9
Source File: FaweAdapter_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
@Override
public BaseEntity getEntity(Entity entity) {
    try {
        if (classEntity == null) return null;
        Object nmsEntity = getHandleEntity.invoke(entity);

        String id = getEntityId(nmsEntity);

        if (id != null) {
            Object tag = newNBTTagCompound.newInstance();
            readEntityIntoTag.invoke(nmsEntity, tag);
            return new BaseEntity(id, (CompoundTag) toNative(tag));
        }
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
    return null;
}
 
Example #10
Source File: Spigot_v1_16_R1.java    From worldedit-adapters with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public BaseEntity getEntity(org.bukkit.entity.Entity entity) {
    checkNotNull(entity);

    CraftEntity craftEntity = ((CraftEntity) entity);
    Entity mcEntity = craftEntity.getHandle();

    String id = getEntityId(mcEntity);

    if (id != null) {
        NBTTagCompound tag = new NBTTagCompound();
        readEntityIntoTag(mcEntity, tag);
        return new BaseEntity(com.sk89q.worldedit.world.entity.EntityTypes.get(id), (CompoundTag) toNative(tag));
    } else {
        return null;
    }
}
 
Example #11
Source File: FaweRegionExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity) {
    if (!contains(location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
        if (!limit.MAX_FAILS()) {
            WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
        }
        return null;
    }
    return super.createEntity(location, entity);
}
 
Example #12
Source File: Spigot_v1_13_R2_2.java    From worldedit-adapters with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state) {
    checkNotNull(location);
    checkNotNull(state);

    CraftWorld craftWorld = ((CraftWorld) location.getWorld());
    WorldServer worldServer = craftWorld.getHandle();

    Entity createdEntity = createEntityFromId(state.getType().getId(), craftWorld.getHandle());

    if (createdEntity != null) {
        CompoundTag nativeTag = state.getNbtData();
        if (nativeTag != null) {
            NBTTagCompound tag = (NBTTagCompound) fromNative(nativeTag);
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            readTagIntoEntity(tag, createdEntity);
        }

        createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

        worldServer.addEntity(createdEntity, SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    } else {
        return null;
    }
}
 
Example #13
Source File: MultiTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity) {
    Entity created = null;
    for (AbstractDelegateExtent extent : extents) created = extent.createEntity(location, entity);
    return created;
}
 
Example #14
Source File: FaweAdapter_1_11.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state)
{
    Preconditions.checkNotNull(location);
    Preconditions.checkNotNull(state);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    WorldServer worldServer = craftWorld.getHandle();

    Entity createdEntity = createEntityFromId(state.getTypeId(), craftWorld.getHandle());
    if (createdEntity != null)
    {
        CompoundTag nativeTag = state.getNbtData();
        if (nativeTag != null)
        {
            NBTTagCompound tag = (NBTTagCompound)fromNative(nativeTag);
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            readTagIntoEntity(tag, createdEntity);
        }
        createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

        worldServer.addEntity(createdEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    }
    return null;
}
 
Example #15
Source File: FaweAdapter_1_9.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state)
{
    Preconditions.checkNotNull(location);
    Preconditions.checkNotNull(state);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    WorldServer worldServer = craftWorld.getHandle();

    net.minecraft.server.v1_9_R2.Entity createdEntity = createEntityFromId(state.getTypeId(), craftWorld.getHandle());
    if (createdEntity != null)
    {
        CompoundTag nativeTag = state.getNbtData();
        if (nativeTag != null)
        {
            NBTTagCompound tag = (NBTTagCompound)fromNative(nativeTag);
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            readTagIntoEntity(tag, createdEntity);
        }
        createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

        worldServer.addEntity(createdEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    }
    return null;
}
 
Example #16
Source File: FaweAdapter_1_12.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state)
{
    Preconditions.checkNotNull(location);
    Preconditions.checkNotNull(state);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    WorldServer worldServer = craftWorld.getHandle();

    Entity createdEntity = createEntityFromId(state.getTypeId(), craftWorld.getHandle());
    if (createdEntity != null)
    {
        CompoundTag nativeTag = state.getNbtData();
        if (nativeTag != null)
        {
            NBTTagCompound tag = (NBTTagCompound)fromNative(nativeTag);
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            readTagIntoEntity(tag, createdEntity);
        }
        createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

        worldServer.addEntity(createdEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    }
    return null;
}
 
Example #17
Source File: FaweAdapter_1_10.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state)
{
    Preconditions.checkNotNull(location);
    Preconditions.checkNotNull(state);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    WorldServer worldServer = craftWorld.getHandle();

    net.minecraft.server.v1_10_R1.Entity createdEntity = createEntityFromId(state.getTypeId(), craftWorld.getHandle());
    if (createdEntity != null)
    {
        CompoundTag nativeTag = state.getNbtData();
        if (nativeTag != null)
        {
            NBTTagCompound tag = (NBTTagCompound)fromNative(nativeTag);
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            readTagIntoEntity(tag, createdEntity);
        }
        createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

        worldServer.addEntity(createdEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    }
    return null;
}
 
Example #18
Source File: NukkitEntity.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BaseEntity getState() {
    Entity entity = entityRef.get();
    if (entity != null) {
        if (entity instanceof Player) {
            return null;
        }
        CompoundTag tag = NBTConverter.fromNative(entity.namedTag);
        return new BaseEntity(entity.getSaveId(), tag);
    } else {
        return null;
    }
}
 
Example #19
Source File: FaweAdapter_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public Entity createEntity(Location location, BaseEntity state) {
    try {
        if (classEntity == null) return null;
        World world = location.getWorld();
        Object nmsWorld = getHandleWorld.invoke(world);

        Object createdEntity = createEntityFromId(state.getTypeId(), nmsWorld);

        if (createdEntity != null) {
            CompoundTag nativeTag = state.getNbtData();
            Map<String, Tag> rawMap = ReflectionUtils.getMap(nativeTag.getValue());
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                rawMap.remove(name);
            }
            if (nativeTag != null) {
                Object tag = fromNative(nativeTag);
                readTagIntoEntity.invoke(createdEntity, tag);
            }

            setLocation.invoke(createdEntity, location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

            addEntity.invoke(nmsWorld, createdEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
            return (Entity) getBukkitEntity.invoke(createdEntity);
        }
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
    return null;
}
 
Example #20
Source File: ProcessedWEExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Entity createEntity(final Location location, final BaseEntity entity) {
    if (entity == null) {
        return null;
    }
    if (!limit.MAX_ENTITIES()) {
        WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_ENTITIES);
        return null;
    }
    return super.createEntity(location, entity);
}
 
Example #21
Source File: HistoryExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean remove() {
    final Location location = this.entity.getLocation();
    final BaseEntity state = this.entity.getState();
    final boolean success = this.entity.remove();
    if ((state != null) && success) {
        HistoryExtent.this.changeSet.addEntityRemove(state.getNbtData());
    }
    return success;
}
 
Example #22
Source File: FaweClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public ClipboardEntity(Extent world, double x, double y, double z, float yaw, float pitch, BaseEntity entity) {
    checkNotNull(entity);
    checkNotNull(world);
    this.world = world;
    this.x = x;
    this.y = y;
    this.z = z;
    this.yaw = yaw;
    this.pitch = pitch;
    this.entity = new BaseEntity(entity);
}
 
Example #23
Source File: EntityCreate.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new instance.
 *
 * @param location the location
 * @param state    the state of the created entity
 * @param entity   the entity that was created
 */
public EntityCreate(Location location, BaseEntity state, Entity entity) {
    checkNotNull(location);
    checkNotNull(state);
    checkNotNull(entity);
    this.location = location;
    this.state = state;
    this.entity = entity;
}
 
Example #24
Source File: EntityRemove.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new instance.
 *
 * @param location the location
 * @param state    the state of the created entity
 */
public EntityRemove(Location location, BaseEntity state) {
    checkNotNull(location);
    checkNotNull(state);
    this.location = location;
    this.state = state;
}
 
Example #25
Source File: Spigot_v1_16_R1.java    From worldedit-adapters with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state) {
    checkNotNull(location);
    checkNotNull(state);

    CraftWorld craftWorld = ((CraftWorld) location.getWorld());
    WorldServer worldServer = craftWorld.getHandle();

    Entity createdEntity = createEntityFromId(state.getType().getId(), craftWorld.getHandle());

    if (createdEntity != null) {
        CompoundTag nativeTag = state.getNbtData();
        if (nativeTag != null) {
            NBTTagCompound tag = (NBTTagCompound) fromNative(nativeTag);
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            readTagIntoEntity(tag, createdEntity);
        }

        createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

        worldServer.addEntity(createdEntity, SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    } else {
        return null;
    }
}
 
Example #26
Source File: Spigot_v1_15_R2.java    From worldedit-adapters with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state) {
    checkNotNull(location);
    checkNotNull(state);

    CraftWorld craftWorld = ((CraftWorld) location.getWorld());
    WorldServer worldServer = craftWorld.getHandle();

    Entity createdEntity = createEntityFromId(state.getType().getId(), craftWorld.getHandle());

    if (createdEntity != null) {
        CompoundTag nativeTag = state.getNbtData();
        if (nativeTag != null) {
            NBTTagCompound tag = (NBTTagCompound) fromNative(nativeTag);
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            readTagIntoEntity(tag, createdEntity);
        }

        createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

        worldServer.addEntity(createdEntity, SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    } else {
        return null;
    }
}
 
Example #27
Source File: Spigot_v1_14_R4.java    From worldedit-adapters with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state) {
    checkNotNull(location);
    checkNotNull(state);

    CraftWorld craftWorld = ((CraftWorld) location.getWorld());
    WorldServer worldServer = craftWorld.getHandle();

    Entity createdEntity = createEntityFromId(state.getType().getId(), craftWorld.getHandle());

    if (createdEntity != null) {
        CompoundTag nativeTag = state.getNbtData();
        if (nativeTag != null) {
            NBTTagCompound tag = (NBTTagCompound) fromNative(nativeTag);
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            readTagIntoEntity(tag, createdEntity);
        }

        createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());

        worldServer.addEntity(createdEntity, SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    } else {
        return null;
    }
}
 
Example #28
Source File: HistoryExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public Entity createEntity(final Location location, final BaseEntity state) {
    final Entity entity = super.createEntity(location, state);
    if ((state != null)) {
        this.changeSet.addEntityCreate(state.getNbtData());
    }
    return entity;
}
 
Example #29
Source File: PlayerWrapper.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
@Nullable
public BaseEntity getState() {
    return parent.getState();
}
 
Example #30
Source File: EditSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
@Nullable
public Entity createEntity(final com.sk89q.worldedit.util.Location location, final BaseEntity entity) {
    Entity result = this.extent.createEntity(location, entity);
    return result;
}