Search in sources :

Example 11 with Event

use of org.spongepowered.api.event.Event in project guardian by ichorpowered.

the class VerticalSpeedCheck method getSequence.

@Nonnull
@Override
public SequenceBlueprint<Event> getSequence(final Detection detection) {
    final Double analysisTime = detection.getContentContainer().get(ContentKeys.ANALYSIS_TIME).orElse(GuardianValue.empty()).getDirect().orElse(0d) / 0.05;
    final Double minimumTickRate = detection.getContentContainer().get(ContentKeys.ANALYSIS_MINIMUM_TICK).orElse(GuardianValue.empty()).getDirect().orElse(0d) / 0.05;
    final Double maximumTickRate = detection.getContentContainer().get(ContentKeys.ANALYSIS_MAXIMUM_TICK).orElse(GuardianValue.empty()).getDirect().orElse(0d) / 0.05;
    return new GuardianSequenceBuilder().capture(new ControlCapture(detection.getPlugin(), detection)).capture(new PotionEffectCapture(detection.getPlugin(), detection)).observe(MoveEntityEvent.class).after().delay(analysisTime.intValue()).condition(sequenceContext -> {
        final GuardianPlayerEntry<Player> entityEntry = sequenceContext.get(CommonContextKeys.ENTITY_ENTRY);
        final Summary summary = sequenceContext.get(CommonContextKeys.SUMMARY);
        final GuardianCaptureRegistry captureRegistry = sequenceContext.get(CommonContextKeys.CAPTURE_REGISTRY);
        final long lastActionTime = sequenceContext.get(CommonContextKeys.LAST_ACTION_TIME);
        summary.set(SequenceReport.class, new SequenceReport(false, Origin.source(sequenceContext.getRoot()).owner(entityEntry).build()));
        if (!entityEntry.getEntity(Player.class).isPresent())
            return false;
        Player player = entityEntry.getEntity(Player.class).get();
        /*
                         * Capture Collection
                         */
        final CaptureContainer captureContainer = captureRegistry.getContainer();
        Optional<Location> initial = captureContainer.get(GuardianSequence.INITIAL_LOCATION);
        Optional<Double> verticalOffset = captureContainer.get(ControlCapture.VERTICAL_DISTANCE);
        if (!initial.isPresent() || !verticalOffset.isPresent())
            return false;
        long current = System.currentTimeMillis();
        // Finds the average between now and the last action.
        double averageClockRate = ((current - lastActionTime) / 1000) / 0.05;
        if (averageClockRate < minimumTickRate) {
            detection.getLogger().warn("The server may be overloaded. A check could not be completed.");
            return false;
        } else if (averageClockRate > maximumTickRate) {
            return false;
        }
        if (player.get(Keys.VEHICLE).isPresent())
            return false;
        double verticalDisplacement = MathUtil.truncateDownTo(player.getLocation().getY() - initial.get().getY(), 4);
        double verticalPlacement = MathUtil.truncateDownTo((verticalOffset.get() * (verticalOffset.get() / 0.2)) / averageClockRate + 0.1, 4);
        if (verticalDisplacement < 1 || verticalOffset.get() < 1)
            return false;
        if (verticalDisplacement > verticalPlacement) {
            // ------------------------- DEBUG -----------------------------
            System.out.println(player.getName() + " has been caught using vertical speed hacks. (" + (verticalDisplacement - verticalPlacement) + ")");
            // -------------------------------------------------------------
            SequenceReport report = new SequenceReport(true, Origin.source(sequenceContext.getRoot()).owner(entityEntry).build());
            report.put("type", "Vertical Speed");
            report.put("information", Collections.singletonList("Overshot maximum movement by " + (verticalDisplacement - verticalPlacement) + "."));
            report.put("initial_location", initial.get());
            report.put("final_location", player.getLocation());
            report.put("severity", (verticalDisplacement - verticalPlacement) / verticalDisplacement);
            summary.set(SequenceReport.class, report);
            return true;
        }
        return false;
    }, ConditionType.NORMAL).build(SequenceContext.builder().owner(detection).root(this).build());
}
Also used : ControlCapture(com.ichorpowered.guardian.common.capture.player.ControlCapture) GuardianSequenceBuilder(com.ichorpowered.guardian.sequence.GuardianSequenceBuilder) Summary(com.ichorpowered.guardianapi.detection.report.Summary) ContentKeys(com.ichorpowered.guardianapi.content.ContentKeys) Keys(org.spongepowered.api.data.key.Keys) GuardianValue(com.ichorpowered.guardian.util.item.mutable.GuardianValue) Origin(com.ichorpowered.guardianapi.event.origin.Origin) PotionEffectCapture(com.ichorpowered.guardian.common.capture.player.PotionEffectCapture) GuardianCaptureRegistry(com.ichorpowered.guardian.sequence.capture.GuardianCaptureRegistry) SequenceReport(com.ichorpowered.guardian.sequence.SequenceReport) Nonnull(javax.annotation.Nonnull) ConditionType(com.abilityapi.sequenceapi.action.condition.ConditionType) Location(org.spongepowered.api.world.Location) GuardianSequence(com.ichorpowered.guardian.sequence.GuardianSequence) Event(org.spongepowered.api.event.Event) Set(java.util.Set) SequenceContext(com.abilityapi.sequenceapi.SequenceContext) Sets(com.google.common.collect.Sets) Check(com.ichorpowered.guardianapi.detection.check.Check) GuardianPlayerEntry(com.ichorpowered.guardian.entry.GuardianPlayerEntry) Detection(com.ichorpowered.guardianapi.detection.Detection) MathUtil(com.ichorpowered.guardian.util.MathUtil) CommonContextKeys(com.ichorpowered.guardian.sequence.context.CommonContextKeys) CaptureContainer(com.ichorpowered.guardianapi.detection.capture.CaptureContainer) ControlCapture(com.ichorpowered.guardian.common.capture.player.ControlCapture) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) SequenceBlueprint(com.abilityapi.sequenceapi.SequenceBlueprint) Collections(java.util.Collections) MoveEntityEvent(org.spongepowered.api.event.entity.MoveEntityEvent) SequenceReport(com.ichorpowered.guardian.sequence.SequenceReport) Player(org.spongepowered.api.entity.living.player.Player) GuardianPlayerEntry(com.ichorpowered.guardian.entry.GuardianPlayerEntry) Optional(java.util.Optional) PotionEffectCapture(com.ichorpowered.guardian.common.capture.player.PotionEffectCapture) CaptureContainer(com.ichorpowered.guardianapi.detection.capture.CaptureContainer) Summary(com.ichorpowered.guardianapi.detection.report.Summary) GuardianSequenceBuilder(com.ichorpowered.guardian.sequence.GuardianSequenceBuilder) GuardianCaptureRegistry(com.ichorpowered.guardian.sequence.capture.GuardianCaptureRegistry) Nonnull(javax.annotation.Nonnull)

Example 12 with Event

use of org.spongepowered.api.event.Event 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)

Example 13 with Event

use of org.spongepowered.api.event.Event in project LanternServer by LanternPowered.

the class BanConfig method addBan.

@Override
public Optional<? extends Ban> addBan(Ban ban) {
    checkNotNull(ban, "ban");
    final Optional<Ban> oldBan;
    if (ban instanceof Ban.Ip) {
        oldBan = (Optional) getBanFor(((Ban.Ip) ban).getAddress());
    } else {
        oldBan = (Optional) getBanFor(((Ban.Profile) ban).getProfile());
    }
    oldBan.ifPresent(this.entries0::remove);
    this.entries0.add((BanEntry) ban);
    if (!oldBan.isPresent() || !oldBan.get().equals(ban)) {
        final CauseStack causeStack = CauseStack.currentOrEmpty();
        // Post the ban events
        final Event event;
        final Cause cause = causeStack.getCurrentCause();
        if (ban instanceof Ban.Ip) {
            event = SpongeEventFactory.createBanIpEvent(cause, (Ban.Ip) ban);
        } else {
            final Ban.Profile profileBan = (Ban.Profile) ban;
            // Check if the pardoned player is online (not yet been kicked)
            final Optional<Player> optTarget = Sponge.getServer().getPlayer(profileBan.getProfile().getUniqueId());
            if (optTarget.isPresent()) {
                event = SpongeEventFactory.createBanUserEventTargetPlayer(cause, profileBan, optTarget.get(), optTarget.get());
            } else {
                event = SpongeEventFactory.createBanUserEvent(cause, profileBan, Lantern.getGame().getServiceManager().provideUnchecked(UserStorageService.class).getOrCreate(profileBan.getProfile()));
            }
        }
        // Just ignore for now the fact that they may be cancellable,
        // only the PardonIpEvent seems to be cancellable
        // TODO: Should they all be cancellable or none of them?
        Sponge.getEventManager().post(event);
    }
    return oldBan;
}
Also used : UserStorageService(org.spongepowered.api.service.user.UserStorageService) CauseStack(org.lanternpowered.server.event.CauseStack) Player(org.spongepowered.api.entity.living.player.Player) Ip(org.spongepowered.api.util.ban.Ban.Ip) Cause(org.spongepowered.api.event.cause.Cause) Event(org.spongepowered.api.event.Event) Ban(org.spongepowered.api.util.ban.Ban) GameProfile(org.spongepowered.api.profile.GameProfile)

Aggregations

Event (org.spongepowered.api.event.Event)13 Player (org.spongepowered.api.entity.living.player.Player)7 SequenceBlueprint (com.abilityapi.sequenceapi.SequenceBlueprint)5 SequenceContext (com.abilityapi.sequenceapi.SequenceContext)5 GuardianCaptureRegistry (com.ichorpowered.guardian.sequence.capture.GuardianCaptureRegistry)5 Origin (com.ichorpowered.guardianapi.event.origin.Origin)5 ConditionType (com.abilityapi.sequenceapi.action.condition.ConditionType)4 Sets (com.google.common.collect.Sets)4 GuardianPlayerEntry (com.ichorpowered.guardian.entry.GuardianPlayerEntry)4 GuardianSequence (com.ichorpowered.guardian.sequence.GuardianSequence)4 GuardianSequenceBuilder (com.ichorpowered.guardian.sequence.GuardianSequenceBuilder)4 SequenceReport (com.ichorpowered.guardian.sequence.SequenceReport)4 CommonContextKeys (com.ichorpowered.guardian.sequence.context.CommonContextKeys)4 Check (com.ichorpowered.guardianapi.detection.check.Check)4 ControlCapture (com.ichorpowered.guardian.common.capture.player.ControlCapture)3 PotionEffectCapture (com.ichorpowered.guardian.common.capture.player.PotionEffectCapture)3 GuardianValue (com.ichorpowered.guardian.util.item.mutable.GuardianValue)3 ContentKeys (com.ichorpowered.guardianapi.content.ContentKeys)3 Detection (com.ichorpowered.guardianapi.detection.Detection)3 CaptureContainer (com.ichorpowered.guardianapi.detection.capture.CaptureContainer)3