Search in sources :

Example 1 with AbstractDetection

use of com.ichorpowered.guardian.detection.AbstractDetection 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)

Example 2 with AbstractDetection

use of com.ichorpowered.guardian.detection.AbstractDetection in project guardian by ichorpowered.

the class GuardianBypassTicket method close.

@Override
public void close() {
    this.closed = true;
    this.detectionTypes.forEach(detectionType -> {
        if (detectionType instanceof AbstractDetection) {
            AbstractDetection detection = (AbstractDetection) detectionType;
            while (detection.getStageCycle().next()) {
                if (detection.getStageCycle().getModel().isPresent() && CheckModel.class.isAssignableFrom(detection.getStageCycle().getModel().get().getClass())) {
                    if (!detection.getStageCycle().<Check<Event>>getStage().isPresent())
                        continue;
                    final Check<Event> check = detection.getStageCycle().<Check<Event>>getStage().get();
                    final GuardianPlayerEntry<Player> playerEntry = GuardianPlayerEntry.of(this.player, this.player.getUniqueId());
                    for (long id : this.blockId) {
                        this.plugin.getSequenceManager().unblock(SequenceContext.builder().id(id).owner(playerEntry.getUniqueId()).root(check.getSequenceTrigger()).custom(CommonContextKeys.ENTITY_ENTRY, playerEntry).build());
                    }
                }
            }
        }
    });
}
Also used : AbstractDetection(com.ichorpowered.guardian.detection.AbstractDetection) Player(org.spongepowered.api.entity.living.player.Player) Check(com.ichorpowered.guardianapi.detection.check.Check) Event(org.spongepowered.api.event.Event) CheckModel(com.ichorpowered.guardianapi.detection.check.CheckModel)

Aggregations

AbstractDetection (com.ichorpowered.guardian.detection.AbstractDetection)2 CheckModel (com.ichorpowered.guardianapi.detection.check.CheckModel)2 GuardianPostInitialization (com.ichorpowered.guardian.event.GuardianPostInitialization)1 PropertyInjector (com.ichorpowered.guardian.util.property.PropertyInjector)1 Detection (com.ichorpowered.guardianapi.detection.Detection)1 Check (com.ichorpowered.guardianapi.detection.check.Check)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 Player (org.spongepowered.api.entity.living.player.Player)1 Event (org.spongepowered.api.event.Event)1