Search in sources :

Example 46 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project SpongeVanilla by SpongePowered.

the class VanillaPluginManager method checkRequirements.

private Set<PluginCandidate> checkRequirements(Map<String, PluginCandidate> candidates) {
    // Collect all versions of already loaded plugins
    Map<String, String> loadedPlugins = new HashMap<>();
    for (PluginContainer container : this.plugins.values()) {
        loadedPlugins.put(container.getId(), container.getVersion().orElse(null));
    }
    Set<PluginCandidate> successfulCandidates = new HashSet<>(candidates.size());
    List<PluginCandidate> failedCandidates = new ArrayList<>();
    for (PluginCandidate candidate : candidates.values()) {
        if (candidate.collectDependencies(loadedPlugins, candidates)) {
            successfulCandidates.add(candidate);
        } else {
            failedCandidates.add(candidate);
        }
    }
    if (failedCandidates.isEmpty()) {
        // Nothing to do, all requirements satisfied
        return successfulCandidates;
    }
    PluginCandidate candidate;
    boolean updated;
    while (true) {
        updated = false;
        Iterator<PluginCandidate> itr = successfulCandidates.iterator();
        while (itr.hasNext()) {
            candidate = itr.next();
            if (candidate.updateRequirements()) {
                updated = true;
                itr.remove();
                failedCandidates.add(candidate);
            }
        }
        if (updated) {
            // Update failed candidates as well
            failedCandidates.forEach(PluginCandidate::updateRequirements);
        } else {
            break;
        }
    }
    for (PluginCandidate failed : failedCandidates) {
        if (failed.isInvalid()) {
            SpongeImpl.getLogger().error("Plugin '{}' from {} cannot be loaded because it is invalid", failed.getId(), failed.getSource());
        } else {
            SpongeImpl.getLogger().error("Cannot load plugin '{}' from {} because it is missing the required dependencies {}", failed.getId(), failed.getSource(), PluginReporter.formatRequirements(failed.getMissingRequirements()));
        }
    }
    return successfulCandidates;
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) PluginCandidate(org.spongepowered.server.launch.plugin.PluginCandidate) HashSet(java.util.HashSet)

Example 47 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project SpongeVanilla by SpongePowered.

the class VanillaPluginManager method loadPlugin.

private void loadPlugin(PluginCandidate candidate) {
    final String id = candidate.getId();
    candidate.getSource().addToClasspath();
    final PluginMetadata metadata = candidate.getMetadata();
    final String name = firstNonNull(metadata.getName(), id);
    final String version = firstNonNull(metadata.getVersion(), "unknown");
    try {
        Class<?> pluginClass = Class.forName(candidate.getPluginClass());
        Optional<Path> source = candidate.getSource().getPath();
        if (!source.isPresent()) {
            source = PluginSource.find(pluginClass);
        }
        PluginContainer container = new VanillaPluginContainer(this.rootInjector, pluginClass, metadata, source);
        registerPlugin(container);
        Sponge.getEventManager().registerListeners(container, container.getInstance().get());
        SpongeImpl.getLogger().info("Loaded plugin: {} {} (from {})", name, version, candidate.getSource());
    } catch (Throwable e) {
        SpongeImpl.getLogger().error("Failed to load plugin: {} {} (from {})", name, version, candidate.getSource(), e);
    }
}
Also used : Path(java.nio.file.Path) PluginContainer(org.spongepowered.api.plugin.PluginContainer) PluginMetadata(org.spongepowered.plugin.meta.PluginMetadata)

Example 48 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project SpongeVanilla by SpongePowered.

the class VanillaChannelRegistrar method createChannel.

@Override
public ChannelBinding.IndexedMessageChannel createChannel(Object plugin, String name) throws ChannelRegistrationException {
    PluginContainer container = checkCreateChannelArgs(plugin, name);
    validateChannel(name);
    VanillaIndexedMessageChannel channel = new VanillaIndexedMessageChannel(this, name, container);
    registerChannel(channel);
    return channel;
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer)

Example 49 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project SpongeAPI by SpongePowered.

the class SimpleServiceManager method setProvider.

@Override
public <T> void setProvider(Object plugin, Class<T> service, T provider) {
    checkNotNull(plugin, "plugin");
    checkNotNull(service, "service");
    checkNotNull(provider, "provider");
    Optional<PluginContainer> containerOptional = this.pluginManager.fromInstance(plugin);
    if (!containerOptional.isPresent()) {
        throw new IllegalArgumentException("The provided plugin object does not have an associated plugin container " + "(in other words, is 'plugin' actually your plugin object?)");
    }
    PluginContainer container = containerOptional.get();
    ProviderRegistration<?> oldProvider = this.providers.put(service, new Provider<>(container, service, provider));
    try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        frame.addContext(EventContextKeys.SERVICE_MANAGER, this);
        frame.pushCause(container);
        Sponge.getEventManager().post(SpongeEventFactory.createChangeServiceProviderEvent(frame.getCurrentCause(), this.providers.get(service), Optional.ofNullable(oldProvider)));
    }
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) CauseStackManager(org.spongepowered.api.event.CauseStackManager)

Example 50 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project SpongeForge by SpongePowered.

the class MixinEntityAIBase method addModAIType.

@SuppressWarnings({ "unchecked", "ConstantConditions" })
@Inject(method = "<init>", at = @At(value = "RETURN"))
public void addModAIType(CallbackInfo ci) {
    // Only set a type if we have none
    if (((AITask<Agent>) this).getType() != null) {
        return;
    }
    // API custom tasks handle types differently, ignore
    if (AbstractAITask.class.isAssignableFrom(getClass())) {
        return;
    }
    // Handle adding mod/un-implemented Minecraft tasks.
    final Optional<AITaskType> optModType = AITaskTypeModule.getInstance().getByAIClass(getClass());
    if (!optModType.isPresent()) {
        PluginContainer container = (PluginContainer) Loader.instance().activeModContainer();
        // FML couldn't figure out the mod...give the task to Minecraft
        if (container == null) {
            // May need to log this...
            container = SpongeImpl.getMinecraftPlugin();
        }
        final String idAndName = getClass().getSimpleName();
        ((IMixinEntityAIBase) this).setType(AITaskTypeModule.getInstance().createAITaskType(container, idAndName, idAndName, (Class<? extends AITask<? extends Agent>>) getClass()));
    }
}
Also used : Agent(org.spongepowered.api.entity.living.Agent) PluginContainer(org.spongepowered.api.plugin.PluginContainer) AITaskType(org.spongepowered.api.entity.ai.task.AITaskType) IMixinEntityAIBase(org.spongepowered.common.interfaces.ai.IMixinEntityAIBase) AbstractAITask(org.spongepowered.api.entity.ai.task.AbstractAITask) AITask(org.spongepowered.api.entity.ai.task.AITask) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

PluginContainer (org.spongepowered.api.plugin.PluginContainer)77 Text (org.spongepowered.api.text.Text)15 CommandResult (org.spongepowered.api.command.CommandResult)13 GenericArguments (org.spongepowered.api.command.args.GenericArguments)13 CommandSpec (org.spongepowered.api.command.spec.CommandSpec)13 List (java.util.List)12 TranslationHelper.t (org.lanternpowered.server.text.translation.TranslationHelper.t)11 CommandException (org.spongepowered.api.command.CommandException)11 ArrayList (java.util.ArrayList)10 Optional (java.util.Optional)10 Collectors (java.util.stream.Collectors)9 Sponge (org.spongepowered.api.Sponge)9 Player (org.spongepowered.api.entity.living.player.Player)8 Collection (java.util.Collection)7 Map (java.util.Map)7 Nullable (javax.annotation.Nullable)7 CommandSource (org.spongepowered.api.command.CommandSource)7 GenericArguments2 (org.lanternpowered.server.command.element.GenericArguments2)6 CommandMapping (org.spongepowered.api.command.CommandMapping)6 ArgumentParseException (org.spongepowered.api.command.args.ArgumentParseException)6