Search in sources :

Example 41 with PluginContainer

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

the class SpongeAdvancementTreeBuilder method build.

@Override
public AdvancementTree build() {
    checkState(this.id != null, "The id must be set");
    checkState(this.rootAdvancement != null, "The root advancement must be set");
    final PluginContainer plugin = Sponge.getCauseStackManager().getCurrentCause().first(PluginContainer.class).get();
    final String name = StringUtils.isEmpty(this.name) ? this.rootAdvancement.getDisplayInfo().map(DisplayInfo::getTitle).map(Text::toPlain).orElse(this.id) : this.name;
    final SpongeAdvancementTree advancementTree = new SpongeAdvancementTree(this.rootAdvancement, plugin.getId() + ':' + this.id, name);
    ((IMixinDisplayInfo) this.rootAdvancement.getDisplayInfo().get()).setBackground(this.background);
    ((IMixinAdvancement) this.rootAdvancement).setParent(null);
    applyTree(this.rootAdvancement, advancementTree);
    return advancementTree;
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) IMixinDisplayInfo(org.spongepowered.common.interfaces.advancement.IMixinDisplayInfo) Text(org.spongepowered.api.text.Text) IMixinAdvancement(org.spongepowered.common.interfaces.advancement.IMixinAdvancement)

Example 42 with PluginContainer

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

the class SpongeTaskBuilder method submit.

@Override
public Task submit(Object plugin) {
    PluginContainer pluginContainer = this.scheduler.checkPluginInstance(plugin);
    checkState(this.consumer != null, "Runnable task not set");
    String name;
    if (this.name == null) {
        name = this.scheduler.getNameFor(pluginContainer, this.syncType);
    } else {
        name = this.name;
    }
    long delay = this.delay;
    long interval = this.interval;
    boolean delayIsTicks = this.delayIsTicks;
    boolean intervalIsTicks = this.intervalIsTicks;
    if (this.syncType == ScheduledTask.TaskSynchronicity.ASYNCHRONOUS) {
        delay = delayIsTicks ? delay * SpongeScheduler.TICK_DURATION_NS : delay;
        interval = intervalIsTicks ? interval * SpongeScheduler.TICK_DURATION_NS : interval;
        delayIsTicks = intervalIsTicks = false;
    }
    ScheduledTask task = new ScheduledTask(this.syncType, this.consumer, name, delay, delayIsTicks, interval, intervalIsTicks, pluginContainer);
    this.scheduler.submit(task);
    return task;
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer)

Example 43 with PluginContainer

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

the class SqlServiceImpl method getDataSource.

@Override
public DataSource getDataSource(@Nullable Object plugin, String jdbcConnection) throws SQLException {
    jdbcConnection = getConnectionUrlFromAlias(jdbcConnection).orElse(jdbcConnection);
    PluginContainer container = null;
    if (plugin != null) {
        container = Sponge.getPluginManager().fromInstance(plugin).orElseThrow(() -> {
            return new IllegalArgumentException("The provided plugin object does not have an associated plugin container " + "(in other words, is 'plugin' actually your plugin object?");
        });
    }
    ConnectionInfo info = ConnectionInfo.fromUrl(container, jdbcConnection);
    try {
        return this.connectionCache.get(info);
    } catch (ExecutionException e) {
        throw new SQLException(e);
    }
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) SQLException(java.sql.SQLException) ExecutionException(java.util.concurrent.ExecutionException)

Example 44 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 45 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)

Aggregations

PluginContainer (org.spongepowered.api.plugin.PluginContainer)75 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