Set applicable issue type for project context in groovy

I am creating my own script plugin which sets up several instances of ScriptField fields. The ScriptField fields currently all “live” in the GlobalContext, which is not really what I would like to have.

In Jira I also have the possibility to choose the applicable issue types inside of a project context for every custom field. But how do I do this in groovy?

I extended the ProjectContext, set the IssueType to my desired type and overwrote the methods returning the information.

This is what I currently have:

public class CustomIssueContext extends ProjectContext {

    private Project project;
    private IssueType issueType;

    @JiraImport
    private ComponentAccessor accessor;

    public CustomIssueContext(Long projectId, Long issueTypeId) {
        super(projectId);
        project = ComponentAccessor.getProjectManager().getProjectObj(projectId);
        Collection<IssueType> types = accessor.getIssueTypeSchemeManager().getIssueTypesForProject(project);
        for(IssueType it : types){
            if(it.getId().equalsIgnoreCase(""+issueTypeId)){
                issueType = it;
                break;
            }
        }
    }

    @Nullable
    @Override
    public Project getProjectObject() {
        return project;
    }

    @Nullable
    @Override
    public Long getProjectId() {
        return project.getId();
    }

    @Nullable
    @Override
    public IssueType getIssueType() {
        return issueType;
    }

    @Nullable
    @Override
    public String getIssueTypeId() {
        return issueType.getId();
    }
}

And I use it like this in another class (not mentioned variables are declared earlier):

ScriptFieldCreationInfo.Builder builder = ScriptFieldCreationInfo.Builder.newBuilder()
builder.setName(fieldName)
if (searcher) {
    builder.setSearcherKey(searcher)
}

CustomIssueContext ic = new CustomIssueContext(10247L, 10144L)

builder.setContexts([ic])
builder.setTemplate(template)
if (template == "custom") {
    builder.setCustomTemplate(Helper.getTemplate(templateFileName))
}
builder.setScriptFile(scriptFilePath)
CustomFieldCreationInfo info = builder.build()

But this is not working. I am able to set the project context but not the applicable issue type. How do I do this correctly?