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);
}
}
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;
}
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);
}
}
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);
}
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);
}
}
Aggregations