use of org.spongepowered.plugin.PluginContainer in project SpongeCommon by SpongePowered.
the class PluginModContainer method constructPlugin.
private void constructPlugin() {
final FMLModContainerAccessor accessor = (FMLModContainerAccessor) (Object) this;
try {
PluginModContainer.LOGGER.trace(Logging.LOADING, "Loading plugin instance {} of type {}", getModId(), accessor.accessor$modClass().getName());
final Injector childInjector = Launch.instance().lifecycle().platformInjector().createChildInjector(new PluginModule((PluginContainer) (Object) this, accessor.accessor$modClass()));
final Object instance = childInjector.getInstance(accessor.accessor$modClass());
accessor.accessor$setModInstance(instance);
((ForgeEventManager) MinecraftForge.EVENT_BUS).registerListeners((PluginContainer) (Object) this, instance);
PluginModContainer.LOGGER.trace(Logging.LOADING, "Loaded plugin instance {} of type {}", getModId(), accessor.accessor$modClass().getName());
} catch (final Throwable e) {
PluginModContainer.LOGGER.error(Logging.LOADING, "Failed to create plugin instance. PluginID: {}, class {}", getModId(), accessor.accessor$modClass().getName(), e);
throw new ModLoadingException(this.modInfo, ModLoadingStage.CONSTRUCT, "fml.modloading.failedtoloadmod", e, accessor.accessor$modClass());
}
try {
PluginModContainer.LOGGER.trace(Logging.LOADING, "Injecting Automatic event subscribers for {}", getModId());
AutomaticEventSubscriber.inject(this, accessor.accessor$scanResults(), accessor.accessor$modClass().getClassLoader());
PluginModContainer.LOGGER.trace(Logging.LOADING, "Completed Automatic event subscribers for {}", getModId());
} catch (final Throwable e) {
LOGGER.error(LOADING, "Failed to register automatic subscribers. PluginID: {}, class {}", getModId(), accessor.accessor$modClass().getName(), e);
throw new ModLoadingException(this.modInfo, ModLoadingStage.CONSTRUCT, "fml.modloading.failedtoloadmod", e, accessor.accessor$modClass());
}
}
use of org.spongepowered.plugin.PluginContainer in project SpongeCommon by SpongePowered.
the class SpongeServiceProvider method attemptRegistration.
@Nullable
private <T> Registration<T> attemptRegistration(final Collection<PluginContainer> pluginContainers, final Service<T> service) {
Registration<T> registration = null;
final Iterator<PluginContainer> pluginContainerIterator = pluginContainers.iterator();
while (registration == null && pluginContainerIterator.hasNext()) {
final PluginContainer pluginContainer = pluginContainerIterator.next();
if (!Launch.instance().launcherPlugins().contains(pluginContainer)) {
// If this succeeds, the while loop will end.
registration = this.getSpecificRegistration(pluginContainer, service);
}
}
return registration;
}
use of org.spongepowered.plugin.PluginContainer in project SpongeCommon by SpongePowered.
the class SnapshotGenerationTest method init.
@Before
public void init() {
PluginManager manager = Mockito.mock(PluginManager.class);
this.eventManager = new SpongeEventManager(this.logger, manager);
try {
Field field = Timings.class.getDeclaredField("factory");
field.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(null, Mockito.mock(TimingsFactory.class));
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
this.plugin = new Object();
PluginContainer container = Mockito.mock(PluginContainer.class);
Mockito.when(manager.fromInstance(this.plugin)).thenReturn(Optional.of(container));
Cause cause = Cause.of(EventContext.empty(), this);
this.entity = Mockito.mock(Entity.class, withSettings().defaultAnswer(Mockito.RETURNS_MOCKS));
this.event = SpongeEventFactory.createSpawnEntityEvent(cause, Lists.newArrayList(this.entity));
Game game = mock(Game.class);
CauseStackManager csm = mock(CauseStackManager.class);
Mockito.when(game.getCauseStackManager()).thenReturn(csm);
}
use of org.spongepowered.plugin.PluginContainer in project SpongeCommon by SpongePowered.
the class TestImplementationModule method configure.
@Override
protected void configure() {
super.configure();
this.bind(Server.class).to(TestServer.class);
this.bind(SpongeGame.class).to(TestGame.class);
Platform platform = mock(Platform.class);
when(platform.getExecutionType()).thenReturn(Platform.Type.SERVER);
PluginContainer mock = mock(PluginContainer.class);
when(platform.getContainer(any())).thenReturn(mock);
this.bind(Platform.class).toInstance(platform);
PluginManager manager = mock(PluginManager.class);
when(mock.getId()).thenReturn("sponge");
when(manager.getPlugin(anyString())).thenReturn(Optional.of(mock));
when(manager.fromInstance(any())).thenReturn(Optional.of(mock));
this.bind(PluginManager.class).toInstance(manager);
PluginContainer common = mock(PluginContainer.class);
SpongeImpl.setSpongePlugin(common);
this.bind(EventManager.class).toInstance(mock(EventManager.class));
this.bind(ChannelRegistrar.class).toInstance(mock(ChannelRegistrar.class));
}
use of org.spongepowered.plugin.PluginContainer in project SpongeCommon by SpongePowered.
the class EventManagerRegistrationTest method successRegistration.
@Test
public void successRegistration() {
final EventManager eventManager = new TestEventManager();
final PluginContainer mock = Mockito.mock(PluginContainer.class);
eventManager.registerListeners(mock, new Dummy());
}
Aggregations