Search in sources :

Example 1 with EntityData

use of ch.njol.skript.entity.EntityData in project Skript by SkriptLang.

the class ExprVehicle method change.

@Override
public void change(final Event e, @Nullable final Object[] delta, final ChangeMode mode) {
    if (mode == ChangeMode.SET) {
        assert delta != null;
        final Entity[] ps = getExpr().getArray(e);
        if (ps.length == 0)
            return;
        final Object o = delta[0];
        if (o instanceof Entity) {
            ((Entity) o).eject();
            final Entity p = CollectionUtils.getRandom(ps);
            assert p != null;
            p.leaveVehicle();
            ((Entity) o).setPassenger(p);
        } else if (o instanceof EntityData) {
            for (final Entity p : ps) {
                final Entity v = ((EntityData<?>) o).spawn(p.getLocation());
                if (v == null)
                    continue;
                v.setPassenger(p);
            }
        } else {
            assert false;
        }
    } else {
        super.change(e, delta, mode);
    }
}
Also used : Entity(org.bukkit.entity.Entity) EntityData(ch.njol.skript.entity.EntityData)

Example 2 with EntityData

use of ch.njol.skript.entity.EntityData in project LifeSkript by LifeMC.

the class ExprSkull method convert.

@Override
@Nullable
public ItemType convert(final Object o) {
    final SkullType type;
    if (o instanceof Skeleton || o instanceof SkeletonData) {
        if (o instanceof SkeletonData ? ((SkeletonData) o).isWither() : ((Skeleton) o).getSkeletonType() == SkeletonType.WITHER) {
            type = SkullType.WITHER;
        } else {
            type = SkullType.SKELETON;
        }
    } else if (o instanceof Zombie || o instanceof EntityData && Zombie.class.isAssignableFrom(((EntityData<?>) o).getType())) {
        type = SkullType.ZOMBIE;
    } else if (o instanceof OfflinePlayer || o instanceof PlayerData) {
        type = SkullType.PLAYER;
    } else if (o instanceof Creeper || o instanceof CreeperData) {
        type = SkullType.CREEPER;
    } else {
        return null;
    }
    @SuppressWarnings("deprecation") final ItemType i = new ItemType(Material.SKULL_ITEM.getId(), (short) type.ordinal());
    if (o instanceof OfflinePlayer) {
        final SkullMeta s = (SkullMeta) Bukkit.getItemFactory().getItemMeta(Material.SKULL_ITEM);
        s.setOwner(((OfflinePlayer) o).getName());
        i.setItemMeta(s);
    }
    return i;
}
Also used : Zombie(org.bukkit.entity.Zombie) Creeper(org.bukkit.entity.Creeper) CreeperData(ch.njol.skript.entity.CreeperData) ItemType(ch.njol.skript.aliases.ItemType) EntityData(ch.njol.skript.entity.EntityData) OfflinePlayer(org.bukkit.OfflinePlayer) Skeleton(org.bukkit.entity.Skeleton) SkullMeta(org.bukkit.inventory.meta.SkullMeta) SkullType(org.bukkit.SkullType) PlayerData(ch.njol.skript.entity.PlayerData) SkeletonData(ch.njol.skript.entity.SkeletonData) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 3 with EntityData

use of ch.njol.skript.entity.EntityData in project LifeSkript by LifeMC.

the class ExprPassenger method change.

@Override
public void change(final Event e, @Nullable final Object[] delta, final ChangeMode mode) {
    if (mode == ChangeMode.SET) {
        assert delta != null;
        final Entity[] vs = getExpr().getArray(e);
        if (vs.length == 0)
            return;
        final Object o = delta[0];
        if (o instanceof Entity) {
            ((Entity) o).leaveVehicle();
            final Entity v = CollectionUtils.getRandom(vs);
            assert v != null;
            v.eject();
            v.setPassenger((Entity) o);
        } else if (o instanceof EntityData) {
            for (final Entity v : vs) {
                @SuppressWarnings("null") final Entity p = ((EntityData<?>) o).spawn(v.getLocation());
                if (p == null)
                    continue;
                v.setPassenger(p);
            }
        } else {
            assert false;
        }
    } else {
        super.change(e, delta, mode);
    }
}
Also used : Entity(org.bukkit.entity.Entity) EntityData(ch.njol.skript.entity.EntityData)

Example 4 with EntityData

use of ch.njol.skript.entity.EntityData in project LifeSkript by LifeMC.

the class ExprEntities method iterator.

@Override
@Nullable
@SuppressWarnings("null")
public Iterator<? extends Entity> iterator(final Event e) {
    if (matchedPattern >= 2) {
        final Location l;
        if (centerEntity != null) {
            final Entity en = centerEntity.getSingle(e);
            if (en == null)
                return null;
            l = en.getLocation();
        } else {
            assert center != null;
            l = center.getSingle(e);
            if (l == null)
                return null;
        }
        assert radius != null;
        final Number n = radius.getSingle(e);
        if (n == null)
            return null;
        final double d = n.doubleValue();
        final Collection<Entity> es = getNearbyEntities(l, d, d, d);
        final double radiusSquared = d * d * Skript.EPSILON_MULT;
        final EntityData<?>[] ts = types.getAll(e);
        return new CheckedIterator<>(es.iterator(), e1 -> {
            if (e1 == null || e1.getLocation().distanceSquared(l) > radiusSquared)
                return false;
            for (final EntityData<?> t : ts) {
                if (t.isInstance(e1))
                    return true;
            }
            return false;
        });
    }
    if (worlds == null && returnType == Player.class)
        return super.iterator(e);
    return new EntityIterator(returnType, worlds, e, types);
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) EntityData(ch.njol.skript.entity.EntityData) CheckedIterator(ch.njol.util.coll.iterator.CheckedIterator) Location(org.bukkit.Location) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 5 with EntityData

use of ch.njol.skript.entity.EntityData in project LifeSkript by LifeMC.

the class ExprVehicle method change.

@Override
public void change(final Event e, @Nullable final Object[] delta, final ChangeMode mode) {
    if (mode == ChangeMode.SET) {
        assert delta != null;
        final Entity[] ps = getExpr().getArray(e);
        if (ps.length == 0)
            return;
        final Object o = delta[0];
        if (o instanceof Entity) {
            ((Entity) o).eject();
            final Entity p = CollectionUtils.getRandom(ps);
            assert p != null;
            p.leaveVehicle();
            ((Entity) o).setPassenger(p);
        } else if (o instanceof EntityData) {
            for (final Entity p : ps) {
                @SuppressWarnings("null") final Entity v = ((EntityData<?>) o).spawn(p.getLocation());
                if (v == null)
                    continue;
                v.setPassenger(p);
            }
        } else {
            assert false;
        }
    } else {
        super.change(e, delta, mode);
    }
}
Also used : Entity(org.bukkit.entity.Entity) EntityData(ch.njol.skript.entity.EntityData)

Aggregations

EntityData (ch.njol.skript.entity.EntityData)14 Entity (org.bukkit.entity.Entity)11 ItemType (ch.njol.skript.aliases.ItemType)4 Player (org.bukkit.entity.Player)4 Nullable (org.eclipse.jdt.annotation.Nullable)4 Location (org.bukkit.Location)3 Block (org.bukkit.block.Block)3 Literal (ch.njol.skript.lang.Literal)2 CheckedIterator (ch.njol.util.coll.iterator.CheckedIterator)2 OfflinePlayer (org.bukkit.OfflinePlayer)2 Action (org.bukkit.event.block.Action)2 PlayerInteractEntityEvent (org.bukkit.event.player.PlayerInteractEntityEvent)2 PlayerInteractEvent (org.bukkit.event.player.PlayerInteractEvent)2 ItemStack (org.bukkit.inventory.ItemStack)2 Skript (ch.njol.skript.Skript)1 Relation (ch.njol.skript.classes.Comparator.Relation)1 DefaultComparators (ch.njol.skript.classes.data.DefaultComparators)1 CreeperData (ch.njol.skript.entity.CreeperData)1 EntityType (ch.njol.skript.entity.EntityType)1 PlayerData (ch.njol.skript.entity.PlayerData)1