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