Search in sources :

Example 1 with GuardianPostInitialization

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;
}
Also used : AbstractDetection(com.ichorpowered.guardian.detection.AbstractDetection) HeuristicModel(com.ichorpowered.guardianapi.detection.heuristic.HeuristicModel) PropertyInjector(com.ichorpowered.guardian.util.property.PropertyInjector) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PenaltyModel(com.ichorpowered.guardianapi.detection.penalty.PenaltyModel) GuardianPostInitialization(com.ichorpowered.guardian.event.GuardianPostInitialization) AbstractDetection(com.ichorpowered.guardian.detection.AbstractDetection) Detection(com.ichorpowered.guardianapi.detection.Detection) CheckModel(com.ichorpowered.guardianapi.detection.check.CheckModel) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException)

Aggregations

AbstractDetection (com.ichorpowered.guardian.detection.AbstractDetection)1 GuardianPostInitialization (com.ichorpowered.guardian.event.GuardianPostInitialization)1 PropertyInjector (com.ichorpowered.guardian.util.property.PropertyInjector)1 Detection (com.ichorpowered.guardianapi.detection.Detection)1 CheckModel (com.ichorpowered.guardianapi.detection.check.CheckModel)1 HeuristicModel (com.ichorpowered.guardianapi.detection.heuristic.HeuristicModel)1 PenaltyModel (com.ichorpowered.guardianapi.detection.penalty.PenaltyModel)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ObjectMappingException (ninja.leaping.configurate.objectmapping.ObjectMappingException)1