Search in sources :

Example 1 with IConfigurable

use of net.minecraftforge.forgespi.language.IConfigurable in project SpongeCommon by SpongePowered.

the class PluginFileConfigurable method getConfigList.

@Override
public List<? extends IConfigurable> getConfigList(final String... key) {
    if (key.length < 1) {
        return Collections.emptyList();
    }
    final String query = key[0];
    if (key.length != this.requiredConfigElements(query)) {
        return Collections.emptyList();
    }
    if ("mods".equals(query)) {
        final Set<PluginMetadata> metadataById = this.container.metadata();
        if (metadataById.isEmpty()) {
            return Collections.emptyList();
        }
        final List<IConfigurable> metadataConfigurables = new ArrayList<>();
        metadataById.forEach((metadata) -> metadataConfigurables.add(new PluginMetadataConfigurable(metadata)));
        return metadataConfigurables;
    }
    if (key.length != 2) {
        return Collections.emptyList();
    }
    final String plugin = key[1];
    final PluginMetadata metadata = this.container.metadata(plugin).orElse(null);
    if (metadata == null) {
        return Collections.emptyList();
    }
    if ("dependencies".equals(query)) {
        // TODO Should we inject a dependency on SpongeForge?
        final Set<PluginDependency> dependencies = metadata.dependencies();
        if (dependencies.isEmpty()) {
            return Collections.emptyList();
        }
        final List<IConfigurable> depConfigurables = new ArrayList<>();
        for (final PluginDependency dependency : dependencies) {
            depConfigurables.add(new PluginDependencyConfigurable(metadata, dependency));
        }
        return depConfigurables;
    }
    return Collections.emptyList();
}
Also used : PluginDependency(org.spongepowered.plugin.metadata.model.PluginDependency) ArrayList(java.util.ArrayList) PluginMetadata(org.spongepowered.plugin.metadata.PluginMetadata) IConfigurable(net.minecraftforge.forgespi.language.IConfigurable)

Aggregations

ArrayList (java.util.ArrayList)1 IConfigurable (net.minecraftforge.forgespi.language.IConfigurable)1 PluginMetadata (org.spongepowered.plugin.metadata.PluginMetadata)1 PluginDependency (org.spongepowered.plugin.metadata.model.PluginDependency)1