use of com.ichorpowered.guardian.event.GuardianPostInitialization in project guardian by ichorpowered.
the class InternalPluginFacet method startup.
public Boolean startup() {
this.facetState = FacetState.PREPARE;
PropertyInjector propertyInjector = this.plugin.getPropertyInjector();
propertyInjector.inject("state", GuardianState.POST_INITIALIZATION);
// STATE: POST_INITIALIZATION
this.plugin.getCommon().registerPermissions();
this.plugin.getCommon().loadPenalties();
this.plugin.getCommon().loadHeuristics();
this.plugin.getCommon().loadChecks();
this.plugin.getCommon().loadModules(this.plugin.getModuleController());
this.logger.info(ConsoleUtil.of(this.facetPrefix + " Preparing modules."));
this.logger.info(ConsoleUtil.of(Ansi.Color.YELLOW, "Discovered {} module(s).", String.valueOf(this.plugin.getModuleController().getModules().size())));
this.plugin.getModuleController().enableModules(moduleWrapper -> {
try {
if (this.plugin.getConfiguration().getEnabledModules().contains(moduleWrapper.getId()))
return true;
} catch (ObjectMappingException e) {
this.logger.error("Failed to acquire enable modules list from the configuration.", e);
}
return false;
});
AtomicInteger detections = new AtomicInteger(0);
AtomicInteger checks = new AtomicInteger(0);
AtomicInteger heuristics = new AtomicInteger(0);
AtomicInteger penalties = new AtomicInteger(0);
this.plugin.getModuleController().getModules().stream().filter(ModuleWrapper::isEnabled).forEach(moduleWrapper -> {
if (!moduleWrapper.getModule().isPresent())
return;
if (moduleWrapper.getModule().get() instanceof Detection) {
AbstractDetection detection = (AbstractDetection) moduleWrapper.getModule().get();
// Precogs detection registration.
Sponge.getRegistry().register(DetectionType.class, detection);
// Register event listeners and provide detection to the manager.
this.plugin.getEventBus().register(detection);
this.plugin.getDetectionManager().provideDetection(detection.getClass(), detection);
// Register the detection and inject its properties.
detection.register(this.plugin.getDetectionManager());
// Call the load method.
detection.onLoad();
if (this.plugin.getDetectionManager().getStageModel(CheckModel.class).isPresent())
checks.addAndGet(detection.getStageCycle().sizeFor(this.plugin.getDetectionManager().getStageModel(CheckModel.class).get()));
if (this.plugin.getDetectionManager().getStageModel(HeuristicModel.class).isPresent())
heuristics.addAndGet(detection.getStageCycle().sizeFor(this.plugin.getDetectionManager().getStageModel(HeuristicModel.class).get()));
if (this.plugin.getDetectionManager().getStageModel(PenaltyModel.class).isPresent())
penalties.addAndGet(detection.getStageCycle().sizeFor(this.plugin.getDetectionManager().getStageModel(PenaltyModel.class).get()));
detections.incrementAndGet();
}
});
this.logger.info(ConsoleUtil.of(Ansi.Color.YELLOW, "Loaded {} punishment(s), {} heuristic(s) and " + "{} check(s) for {} detection(s).", String.valueOf(penalties.get()), String.valueOf(heuristics.get()), String.valueOf(checks.get()), String.valueOf(detections.get())));
this.plugin.getEventBus().post(new GuardianPostInitialization(this.plugin, Origin.source(this.plugin.getPluginContainer()).build()));
Sponge.getEventManager().registerListeners(this.plugin, this.plugin.getSequenceListener());
this.facetState = FacetState.START;
return true;
}
Aggregations