Search in sources :

Example 1 with PackRepositoryBridge_Vanilla

use of org.spongepowered.vanilla.bridge.server.packs.repository.PackRepositoryBridge_Vanilla in project SpongeCommon by SpongePowered.

the class PluginRepositorySource method loadPacks.

@Override
public void loadPacks(final Consumer<Pack> callback, final Pack.PackConstructor constructor) {
    final VanillaPluginManager pluginManager = (VanillaPluginManager) Launch.instance().pluginManager();
    // For each plugin, we create a pack. That pack might be empty.
    for (final PluginContainer pluginContainer : pluginManager.plugins()) {
        // The pack ID is prepended with "plugin-", as this will be the namespace we have to use a valid
        // character as a separator
        final String id = "plugin-" + pluginContainer.metadata().id();
        final PluginResource resource = pluginManager.resource(pluginContainer);
        // TODO: provide hook in the resource to return the file system for all resource types?
        // Also -- can we fake a FileSystem for a non-Jar (needs thinking about)....
        @Nullable Supplier<FileSystem> fileSystemSupplier = null;
        if (resource instanceof JVMPluginResource) {
            final String extension = FilenameUtils.getExtension(resource.path().getFileName().toString());
            if ("jar".equals(extension)) {
                fileSystemSupplier = ((JVMPluginResource) resource)::fileSystem;
            }
        }
        final PluginPackResources packResources = new PluginPackResources(id, pluginContainer, fileSystemSupplier);
        final Pack pack = Pack.create(id, true, () -> packResources, constructor, Pack.Position.BOTTOM, PackSource.DEFAULT);
        ((PackRepositoryBridge_Vanilla) this.repository).bridge$registerResourcePack(pluginContainer, pack);
        callback.accept(pack);
    }
}
Also used : PluginContainer(org.spongepowered.plugin.PluginContainer) JVMPluginResource(org.spongepowered.plugin.builtin.jvm.locator.JVMPluginResource) JVMPluginResource(org.spongepowered.plugin.builtin.jvm.locator.JVMPluginResource) PluginResource(org.spongepowered.plugin.PluginResource) PackRepositoryBridge_Vanilla(org.spongepowered.vanilla.bridge.server.packs.repository.PackRepositoryBridge_Vanilla) FileSystem(java.nio.file.FileSystem) VanillaPluginManager(org.spongepowered.vanilla.launch.plugin.VanillaPluginManager) Pack(net.minecraft.server.packs.repository.Pack) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Aggregations

FileSystem (java.nio.file.FileSystem)1 Pack (net.minecraft.server.packs.repository.Pack)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 PluginContainer (org.spongepowered.plugin.PluginContainer)1 PluginResource (org.spongepowered.plugin.PluginResource)1 JVMPluginResource (org.spongepowered.plugin.builtin.jvm.locator.JVMPluginResource)1 PackRepositoryBridge_Vanilla (org.spongepowered.vanilla.bridge.server.packs.repository.PackRepositoryBridge_Vanilla)1 VanillaPluginManager (org.spongepowered.vanilla.launch.plugin.VanillaPluginManager)1