use of com.google.common.eventbus.Subscribe in project MinecraftForge by MinecraftForge.
the class FMLModContainer method constructMod.
@Subscribe
public void constructMod(FMLConstructionEvent event) {
try {
BlamingTransformer.addClasses(getModId(), candidate.getClassList());
ModClassLoader modClassLoader = event.getModClassLoader();
modClassLoader.addFile(source);
modClassLoader.clearNegativeCacheFor(candidate.getClassList());
//Only place I could think to add this...
MinecraftForge.preloadCrashClasses(event.getASMHarvestedData(), getModId(), candidate.getClassList());
Class<?> clazz = Class.forName(className, true, modClassLoader);
Certificate[] certificates = clazz.getProtectionDomain().getCodeSource().getCertificates();
int len = 0;
if (certificates != null) {
len = certificates.length;
}
Builder<String> certBuilder = ImmutableList.builder();
for (int i = 0; i < len; i++) {
certBuilder.add(CertificateHelper.getFingerprint(certificates[i]));
}
ImmutableList<String> certList = certBuilder.build();
sourceFingerprints = ImmutableSet.copyOf(certList);
String expectedFingerprint = (String) descriptor.get("certificateFingerprint");
fingerprintNotPresent = true;
if (expectedFingerprint != null && !expectedFingerprint.isEmpty()) {
if (!sourceFingerprints.contains(expectedFingerprint)) {
Level warnLevel = Level.ERROR;
if (source.isDirectory()) {
warnLevel = Level.TRACE;
}
FMLLog.log(getModId(), warnLevel, "The mod %s is expecting signature %s for source %s, however there is no signature matching that description", getModId(), expectedFingerprint, source.getName());
} else {
certificate = certificates[certList.indexOf(expectedFingerprint)];
fingerprintNotPresent = false;
}
}
@SuppressWarnings("unchecked") List<Map<String, Object>> props = (List<Map<String, Object>>) descriptor.get("customProperties");
if (props != null) {
com.google.common.collect.ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
for (Map<String, Object> p : props) {
builder.put((String) p.get("k"), (String) p.get("v"));
}
customModProperties = builder.build();
} else {
customModProperties = EMPTY_PROPERTIES;
}
Boolean hasDisableableFlag = (Boolean) descriptor.get("canBeDeactivated");
boolean hasReverseDepends = !event.getReverseDependencies().get(getModId()).isEmpty();
if (hasDisableableFlag != null && hasDisableableFlag) {
disableability = hasReverseDepends ? Disableable.DEPENDENCIES : Disableable.YES;
} else {
disableability = hasReverseDepends ? Disableable.DEPENDENCIES : Disableable.RESTART;
}
Method factoryMethod = gatherAnnotations(clazz);
modInstance = getLanguageAdapter().getNewInstance(this, clazz, modClassLoader, factoryMethod);
NetworkRegistry.INSTANCE.register(this, clazz, (String) (descriptor.containsKey("acceptableRemoteVersions") ? descriptor.get("acceptableRemoteVersions") : null), event.getASMHarvestedData());
if (fingerprintNotPresent) {
eventBus.post(new FMLFingerprintViolationEvent(source.isDirectory(), source, ImmutableSet.copyOf(this.sourceFingerprints), expectedFingerprint));
}
ProxyInjector.inject(this, event.getASMHarvestedData(), FMLCommonHandler.instance().getSide(), getLanguageAdapter());
AutomaticEventSubscriber.inject(this, event.getASMHarvestedData(), FMLCommonHandler.instance().getSide());
ConfigManager.load(this.getModId(), Config.Type.INSTANCE);
processFieldAnnotations(event.getASMHarvestedData());
} catch (Throwable e) {
controller.errorOccurred(this, e);
}
}
use of com.google.common.eventbus.Subscribe in project MinecraftForge by MinecraftForge.
the class LoadController method buildModList.
@Subscribe
public void buildModList(FMLLoadEvent event) {
Builder<String, EventBus> eventBus = ImmutableMap.builder();
for (final ModContainer mod : loader.getModList()) {
//Create mod logger, and make the EventBus logger a child of it.
EventBus bus = new EventBus(new SubscriberExceptionHandler() {
@Override
public void handleException(final Throwable exception, final SubscriberExceptionContext context) {
LoadController.this.errorOccurred(mod, exception);
}
});
boolean isActive = mod.registerBus(bus, this);
if (isActive) {
activeModList.add(mod);
modStates.put(mod.getModId(), ModState.UNLOADED);
eventBus.put(mod.getModId(), bus);
FMLCommonHandler.instance().addModToResourcePack(mod);
} else {
FMLLog.log(mod.getModId(), Level.WARN, "Mod %s has been disabled through configuration", mod.getModId());
modStates.put(mod.getModId(), ModState.UNLOADED);
modStates.put(mod.getModId(), ModState.DISABLED);
}
modNames.put(mod.getModId(), mod.getName());
}
eventChannels = eventBus.build();
}
use of com.google.common.eventbus.Subscribe in project MinecraftForge by MinecraftForge.
the class LoadController method propogateStateMessage.
@Subscribe
public void propogateStateMessage(FMLEvent stateEvent) {
if (stateEvent instanceof FMLPreInitializationEvent) {
modObjectList = buildModObjectList();
}
ProgressBar bar = ProgressManager.push(stateEvent.description(), activeModList.size(), true);
for (ModContainer mc : activeModList) {
bar.step(mc.getName());
sendEventToModContainer(stateEvent, mc);
}
ProgressManager.pop(bar);
}
use of com.google.common.eventbus.Subscribe in project killbill by killbill.
the class PushNotificationListener method triggerPushNotifications.
@AllowConcurrentEvents
@Subscribe
public void triggerPushNotifications(final ExtBusEvent event) {
final TenantContext context = contextFactory.createTenantContext(event.getTenantId());
try {
final List<String> callbacks = getCallbacksForTenant(context);
if (callbacks.isEmpty()) {
// Optimization - see https://github.com/killbill/killbill/issues/297
return;
}
dispatchCallback(event.getTenantId(), event, callbacks);
} catch (final TenantApiException e) {
log.warn("Failed to retrieve push notification callback for tenant {}", event.getTenantId());
} catch (final IOException e) {
log.warn("Failed to retrieve push notification callback for tenant {}", event.getTenantId());
}
}
use of com.google.common.eventbus.Subscribe in project randomizedtesting by randomizedtesting.
the class AggregatingListener method slowHeartBeat.
/**
* Detect slow heartbeat (long time without any events) from the forked JVM.
*/
@Subscribe
public void slowHeartBeat(LowLevelHeartBeatEvent e) {
Description current = null;
if (tests != null && !tests.isEmpty()) {
current = tests.peek().getDescription();
} else {
// may be null.
current = lastSuite;
}
target.post(new HeartBeatEvent(slave, current, e.lastActivity, e.currentTime));
}
Aggregations