Search in sources :

Example 1 with SkullType

use of org.bukkit.SkullType 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)

Aggregations

ItemType (ch.njol.skript.aliases.ItemType)1 CreeperData (ch.njol.skript.entity.CreeperData)1 EntityData (ch.njol.skript.entity.EntityData)1 PlayerData (ch.njol.skript.entity.PlayerData)1 SkeletonData (ch.njol.skript.entity.SkeletonData)1 OfflinePlayer (org.bukkit.OfflinePlayer)1 SkullType (org.bukkit.SkullType)1 Creeper (org.bukkit.entity.Creeper)1 Skeleton (org.bukkit.entity.Skeleton)1 Zombie (org.bukkit.entity.Zombie)1 SkullMeta (org.bukkit.inventory.meta.SkullMeta)1 Nullable (org.eclipse.jdt.annotation.Nullable)1