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;
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations