Java Code Examples for org.bukkit.entity.EntityType#getTypeId()

The following examples show how to use org.bukkit.entity.EntityType#getTypeId() . 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: SpawnEggMeta.java    From ShopChest with MIT License 4 votes vote down vote up
/**	
 * @param plugin An instance of the {@link ShopChest} plugin
 * @param stack {@link ItemStack} (Spawn Egg) of which the Entity should be gotten	
 * @return The {@link EntityType} the Spawn Egg will spawn or <b>null</b> if <i>nbtEntityID</i> is null	
 */	
public static EntityType getEntityTypeFromItemStack(ShopChest plugin, ItemStack stack) {	
    if (Utils.getMajorVersion() == 8) {	
        EntityType type = null;	
	
        for (EntityType entityType : EntityType.values()) {	
            if (entityType.getTypeId() == stack.getDurability()) {	
                type = entityType;	
                break;	
            }	
        }	
	
        return type;	
    }	
	
    String nbtEntityID = getNBTEntityID(plugin, stack);	
	
    if (nbtEntityID == null) return null;	
	
    if (Utils.getMajorVersion() >= 11) {	
        if (nbtEntityID.contains(":")) nbtEntityID = nbtEntityID.split(":")[1];	
        return EntityType.fromName(nbtEntityID);	
    }	
	
    switch (nbtEntityID) {	
        case "PigZombie":	
            return EntityType.valueOf("PIG_ZOMBIE");	
        case "CaveSpider":	
            return EntityType.CAVE_SPIDER;	
        case "LavaSlime":	
            return EntityType.MAGMA_CUBE;	
        case "MushroomCow":	
            return EntityType.MUSHROOM_COW;	
        case "EntityHorse":	
            return EntityType.HORSE;	
        case "PolarBear":	
            return EntityType.POLAR_BEAR;	
        case "Ozelot":	
            return EntityType.OCELOT;	
        default:	
            return EntityType.valueOf(nbtEntityID.toUpperCase());	
	
    }	
}
 
Example 2
Source File: ItemManager.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public static short getId(EntityType entity) {
	return entity.getTypeId();
}
 
Example 3
Source File: LegacyEntityId.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public static int getIntId(NetworkEntityType type) {
	EntityType btype = type.getBukkitType();
	return btype != null ? btype.getTypeId() : -1;
}