Search in sources :

Example 1 with CaptureContainer

use of com.ichorpowered.guardianapi.detection.capture.CaptureContainer in project guardian by ichorpowered.

the class FlightCheck method getSequence.

@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 analysisIntercept = detection.getContentContainer().get(ContentKeys.ANALYSIS_INTERCEPT).orElse(GuardianValue.empty()).getDirect().orElse(0d);
    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 AltitudeCapture(detection.getPlugin(), detection)).capture(new MaterialCapture(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;
        final Player player = entityEntry.getEntity(Player.class).get();
        /*
                         * Capture Collection
                         */
        final CaptureContainer captureContainer = captureRegistry.getContainer();
        final Optional<Location> initial = captureContainer.get(GuardianSequence.INITIAL_LOCATION);
        final Optional<Double> effectLiftAmplifier = captureContainer.get(PotionEffectCapture.VERTICAL_SPEED_MODIFIER);
        final Optional<Double> materialSpeedAmplifier = captureContainer.get(MaterialCapture.SPEED_MODIFIER);
        final Optional<Double> altitude = captureContainer.get(AltitudeCapture.RELATIVE_ALTITUDE);
        final Optional<Map<String, Integer>> materialStateTicks = captureContainer.get(MaterialCapture.ACTIVE_MATERIAL_TICKS);
        final Optional<Map<String, Integer>> controlStateTicks = captureContainer.get(ControlCapture.ACTIVE_CONTROL_TICKS);
        if (!initial.isPresent() || !materialSpeedAmplifier.isPresent() || !altitude.isPresent() || !materialStateTicks.isPresent())
            return false;
        final Value<Double> playerBoxWidth = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_WIDTH, entityEntry, detection.getContentContainer()).orElse(GuardianValue.empty());
        final Value<Double> playerBoxHeight = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_HEIGHT, entityEntry, detection.getContentContainer()).orElse(GuardianValue.empty());
        final Value<Double> playerBoxSafety = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_SAFETY, entityEntry, detection.getContentContainer()).orElse(GuardianValue.empty());
        final double playerWidth = playerBoxWidth.getDirect().orElse(1.2) + playerBoxSafety.getDirect().orElse(0.05);
        final double playerHeight = playerBoxHeight.getDirect().orElse(1.8) + playerBoxSafety.getDirect().orElse(0.05);
        final boolean isSneaking = player.get(Keys.IS_SNEAKING).isPresent() && player.get(Keys.IS_SNEAKING).get();
        final BoundingBox playerBox = WorldUtil.getBoundingBox(playerWidth, isSneaking ? (playerHeight - 0.15) : playerHeight);
        long current = System.currentTimeMillis();
        // Gets the average time between now and the last action.
        double averageActionTime = ((current - lastActionTime) / 1000) / 0.05;
        if (averageActionTime < minimumTickRate) {
            detection.getLogger().warn("The server may be overloaded. A check could not be completed.");
            return false;
        } else if (averageActionTime > maximumTickRate) {
            return false;
        }
        if (player.get(Keys.VEHICLE).isPresent() || (player.get(Keys.IS_FLYING).isPresent() && player.get(Keys.IS_FLYING).get()) || player.getLocation().getY() < 1)
            return false;
        final double intercept = analysisIntercept + (effectLiftAmplifier.orElse(0d) / analysisTime);
        // Gets the players vertical displacement in the world.
        final double verticalDisplacement = ((player.getLocation().getY() - initial.get().getY()) == 0) ? intercept : player.getLocation().getY() - initial.get().getY();
        // Gets the players relative altitude to the ground.
        final double averageAltitude = altitude.get() / averageActionTime;
        // Gets the time the player is on solid ground or a liquid.
        final int solidMaterialTime = materialStateTicks.get().get(MaterialCapture.SOLID);
        final int liquidMaterialTime = materialStateTicks.get().get(MaterialCapture.LIQUID);
        // Gets the time the player is using flight.
        final int flightControlTime = controlStateTicks.get().get(ControlCapture.FLY);
        if (verticalDisplacement <= 1 || averageAltitude <= 1 || WorldUtil.containsBlocksUnder(player.getLocation(), playerBox, 1d) || solidMaterialTime > 1 || liquidMaterialTime > 1 || flightControlTime > 1)
            return false;
        if (((verticalDisplacement / averageAltitude) + averageAltitude) > intercept) {
            // ------------------------- DEBUG -----------------------------
            System.out.println(player.getName() + " has been caught using fly hacks. (" + ((verticalDisplacement / averageAltitude) + averageAltitude) + ")");
            // -------------------------------------------------------------
            SequenceReport report = new SequenceReport(true, Origin.source(sequenceContext.getRoot()).owner(entityEntry).build());
            report.put("type", "Flight");
            report.put("information", Collections.singletonList("Gained altitude over " + ((verticalDisplacement / averageAltitude) + averageAltitude) + "."));
            report.put("initial_location", initial.get());
            report.put("final_location", player.getLocation());
            report.put("severity", ((verticalDisplacement / averageAltitude) + averageAltitude) / (verticalDisplacement + averageAltitude));
            summary.set(SequenceReport.class, report);
            return true;
        }
        return false;
    }, ConditionType.NORMAL).build(SequenceContext.builder().owner(detection).root(this).build());
}
Also used : 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) Value(com.ichorpowered.guardianapi.util.item.value.mutable.Value) SequenceReport(com.ichorpowered.guardian.sequence.SequenceReport) Map(java.util.Map) ConditionType(com.abilityapi.sequenceapi.action.condition.ConditionType) Location(org.spongepowered.api.world.Location) GuardianSequence(com.ichorpowered.guardian.sequence.GuardianSequence) ContentUtil(com.ichorpowered.guardian.util.ContentUtil) Event(org.spongepowered.api.event.Event) Set(java.util.Set) AltitudeCapture(com.ichorpowered.guardian.common.capture.player.AltitudeCapture) SequenceContext(com.abilityapi.sequenceapi.SequenceContext) Sets(com.google.common.collect.Sets) BoundingBox(com.ichorpowered.guardian.util.entity.BoundingBox) Check(com.ichorpowered.guardianapi.detection.check.Check) GuardianPlayerEntry(com.ichorpowered.guardian.entry.GuardianPlayerEntry) Detection(com.ichorpowered.guardianapi.detection.Detection) 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) WorldUtil(com.ichorpowered.guardian.util.WorldUtil) Player(org.spongepowered.api.entity.living.player.Player) SequenceBlueprint(com.abilityapi.sequenceapi.SequenceBlueprint) MaterialCapture(com.ichorpowered.guardian.common.capture.world.MaterialCapture) Collections(java.util.Collections) MoveEntityEvent(org.spongepowered.api.event.entity.MoveEntityEvent) Player(org.spongepowered.api.entity.living.player.Player) Optional(java.util.Optional) AltitudeCapture(com.ichorpowered.guardian.common.capture.player.AltitudeCapture) ControlCapture(com.ichorpowered.guardian.common.capture.player.ControlCapture) SequenceReport(com.ichorpowered.guardian.sequence.SequenceReport) GuardianPlayerEntry(com.ichorpowered.guardian.entry.GuardianPlayerEntry) MaterialCapture(com.ichorpowered.guardian.common.capture.world.MaterialCapture) PotionEffectCapture(com.ichorpowered.guardian.common.capture.player.PotionEffectCapture) CaptureContainer(com.ichorpowered.guardianapi.detection.capture.CaptureContainer) BoundingBox(com.ichorpowered.guardian.util.entity.BoundingBox) GuardianValue(com.ichorpowered.guardian.util.item.mutable.GuardianValue) Value(com.ichorpowered.guardianapi.util.item.value.mutable.Value) Summary(com.ichorpowered.guardianapi.detection.report.Summary) GuardianSequenceBuilder(com.ichorpowered.guardian.sequence.GuardianSequenceBuilder) GuardianCaptureRegistry(com.ichorpowered.guardian.sequence.capture.GuardianCaptureRegistry)

Example 2 with CaptureContainer

use of com.ichorpowered.guardianapi.detection.capture.CaptureContainer in project guardian by ichorpowered.

the class PotionEffectCapture method update.

@Override
public void update(@Nonnull PlayerEntry entry, @Nonnull CaptureContainer captureContainer) {
    if (!entry.getEntity(Player.class).isPresent() || !captureContainer.get(GuardianSequence.INITIAL_LOCATION).isPresent())
        return;
    final Player player = entry.getEntity(Player.class).get();
    captureContainer.offerIfEmpty(GuardianValue.builder(PotionEffectCapture.HORIZONTAL_SPEED_MODIFIER).defaultElement(1d).element(1d).create());
    captureContainer.offerIfEmpty(GuardianValue.builder(PotionEffectCapture.VERTICAL_SPEED_MODIFIER).defaultElement(1d).element(1d).create());
    final List<PotionEffect> potionEffects = player.get(Keys.POTION_EFFECTS).orElse(Lists.newArrayList());
    if (!potionEffects.isEmpty()) {
        for (PotionEffect potionEffect : potionEffects) {
            final String potionName = potionEffect.getType().getName().toLowerCase();
            if (this.effectSpeed.containsKey(potionName)) {
                final double effectValue = this.effectSpeed.get(potionName);
                captureContainer.getValue(PotionEffectCapture.HORIZONTAL_SPEED_MODIFIER).ifPresent(value -> value.transform(original -> original + ((potionEffect.getAmplifier() + 1) * effectValue)));
            }
            if (this.effectLift.containsKey(potionName)) {
                final double effectValue = this.effectLift.get(potionName);
                captureContainer.getValue(PotionEffectCapture.VERTICAL_SPEED_MODIFIER).ifPresent(value -> value.transform(original -> original + ((potionEffect.getAmplifier() + 1) * effectValue)));
            }
        }
    }
}
Also used : GuardianSequence(com.ichorpowered.guardian.sequence.GuardianSequence) ContentKeys(com.ichorpowered.guardianapi.content.ContentKeys) Keys(org.spongepowered.api.data.key.Keys) CaptureKey(com.ichorpowered.guardianapi.detection.capture.CaptureKey) GuardianCaptureKey(com.ichorpowered.guardian.sequence.capture.GuardianCaptureKey) TypeToken(com.google.common.reflect.TypeToken) Maps(com.google.common.collect.Maps) GuardianValue(com.ichorpowered.guardian.util.item.mutable.GuardianValue) GuardianMapValue(com.ichorpowered.guardian.util.item.mutable.GuardianMapValue) Detection(com.ichorpowered.guardianapi.detection.Detection) List(java.util.List) Lists(com.google.common.collect.Lists) AbstractCapture(com.ichorpowered.guardian.sequence.capture.AbstractCapture) Value(com.ichorpowered.guardianapi.util.item.value.mutable.Value) CaptureContainer(com.ichorpowered.guardianapi.detection.capture.CaptureContainer) Map(java.util.Map) PlayerEntry(com.ichorpowered.guardianapi.entry.entity.PlayerEntry) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) Player(org.spongepowered.api.entity.living.player.Player) Nonnull(javax.annotation.Nonnull) Player(org.spongepowered.api.entity.living.player.Player) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect)

Example 3 with CaptureContainer

use of com.ichorpowered.guardianapi.detection.capture.CaptureContainer in project guardian by ichorpowered.

the class MaterialCapture method update.

@Override
public void update(@Nonnull PlayerEntry entry, @Nonnull CaptureContainer captureContainer) {
    if (!entry.getEntity(Player.class).isPresent() || !captureContainer.get(GuardianSequence.INITIAL_LOCATION).isPresent())
        return;
    final Player player = entry.getEntity(Player.class).get();
    final Location<World> location = player.getLocation();
    final MapValue<String, Integer> activeMaterials = GuardianMapValue.builder(MaterialCapture.ACTIVE_MATERIAL_TICKS).defaultElement(Maps.newHashMap()).element(Maps.newHashMap()).create();
    activeMaterials.put(GAS, 0);
    activeMaterials.put(LIQUID, 0);
    activeMaterials.put(SOLID, 0);
    captureContainer.offerIfEmpty(activeMaterials);
    captureContainer.offerIfEmpty(GuardianValue.builder(MaterialCapture.SPEED_MODIFIER).defaultElement(1d).element(1d).create());
    final Value<Double> playerBoxWidth = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_WIDTH, entry, this.getDetection().getContentContainer()).orElse(GuardianValue.empty());
    final Value<Double> playerBoxHeight = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_HEIGHT, entry, this.getDetection().getContentContainer()).orElse(GuardianValue.empty());
    final Value<Double> playerBoxSafety = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_SAFETY, entry, this.getDetection().getContentContainer()).orElse(GuardianValue.empty());
    final double playerWidth = playerBoxWidth.getDirect().orElse(1.2) + playerBoxSafety.getDirect().orElse(0.05);
    final double playerHeight = playerBoxHeight.getDirect().orElse(1.8) + playerBoxSafety.getDirect().orElse(0.05);
    final boolean isSneaking = player.get(Keys.IS_SNEAKING).isPresent() && player.get(Keys.IS_SNEAKING).get();
    final BoundingBox playerBox = WorldUtil.getBoundingBox(playerWidth, isSneaking ? (playerHeight - 0.15) : playerHeight);
    if (!WorldUtil.containsBlocksUnder(location, playerBox, 1.25)) {
        final double gasSpeed = this.matterSpeed.get(GAS);
        captureContainer.getValue(MaterialCapture.SPEED_MODIFIER).ifPresent(value -> value.transform(original -> original * gasSpeed));
        captureContainer.getValue(MaterialCapture.ACTIVE_MATERIAL_TICKS).ifPresent(value -> value.put(GAS, value.get().get(GAS) + 1));
    } else if (WorldUtil.anyLiquidAtDepth(location, playerBox, 1d) || WorldUtil.anyLiquidAtDepth(location, playerBox, 0) || WorldUtil.anyLiquidAtDepth(location, playerBox, isSneaking ? -(playerHeight - 0.25) : -playerHeight)) {
        final double liquidSpeed = this.matterSpeed.get(LIQUID);
        captureContainer.getValue(MaterialCapture.SPEED_MODIFIER).ifPresent(value -> value.transform(original -> original * liquidSpeed));
        captureContainer.getValue(MaterialCapture.ACTIVE_MATERIAL_TICKS).ifPresent(value -> value.put(LIQUID, value.get().get(LIQUID) + 1));
    } else {
        final List<BlockType> surroundingBlockTypes = WorldUtil.getBlocksUnder(location, playerBox, 1.25);
        for (final BlockType blockType : surroundingBlockTypes) {
            final double speedModifier = this.materialSpeed.getOrDefault(blockType.getName().toLowerCase(), this.matterSpeed.get(SOLID));
            captureContainer.getValue(MaterialCapture.SPEED_MODIFIER).ifPresent(value -> value.transform(original -> original * speedModifier));
        }
        captureContainer.getValue(MaterialCapture.ACTIVE_MATERIAL_TICKS).ifPresent(value -> value.put(SOLID, value.get().get(SOLID) + 1));
    }
}
Also used : ContentKeys(com.ichorpowered.guardianapi.content.ContentKeys) Keys(org.spongepowered.api.data.key.Keys) GuardianCaptureKey(com.ichorpowered.guardian.sequence.capture.GuardianCaptureKey) TypeToken(com.google.common.reflect.TypeToken) GuardianValue(com.ichorpowered.guardian.util.item.mutable.GuardianValue) GuardianMapValue(com.ichorpowered.guardian.util.item.mutable.GuardianMapValue) Value(com.ichorpowered.guardianapi.util.item.value.mutable.Value) Map(java.util.Map) Nonnull(javax.annotation.Nonnull) Location(org.spongepowered.api.world.Location) GuardianSequence(com.ichorpowered.guardian.sequence.GuardianSequence) ContentUtil(com.ichorpowered.guardian.util.ContentUtil) CaptureKey(com.ichorpowered.guardianapi.detection.capture.CaptureKey) Maps(com.google.common.collect.Maps) BoundingBox(com.ichorpowered.guardian.util.entity.BoundingBox) Detection(com.ichorpowered.guardianapi.detection.Detection) List(java.util.List) AbstractCapture(com.ichorpowered.guardian.sequence.capture.AbstractCapture) CaptureContainer(com.ichorpowered.guardianapi.detection.capture.CaptureContainer) MapValue(com.ichorpowered.guardianapi.util.item.value.mutable.MapValue) World(org.spongepowered.api.world.World) BlockType(org.spongepowered.api.block.BlockType) PlayerEntry(com.ichorpowered.guardianapi.entry.entity.PlayerEntry) WorldUtil(com.ichorpowered.guardian.util.WorldUtil) Player(org.spongepowered.api.entity.living.player.Player) Player(org.spongepowered.api.entity.living.player.Player) World(org.spongepowered.api.world.World) BlockType(org.spongepowered.api.block.BlockType) BoundingBox(com.ichorpowered.guardian.util.entity.BoundingBox) List(java.util.List)

Example 4 with CaptureContainer

use of com.ichorpowered.guardianapi.detection.capture.CaptureContainer in project guardian by ichorpowered.

the class AltitudeCapture method update.

@Override
public void update(PlayerEntry entry, CaptureContainer captureContainer) {
    if (!entry.getEntity(Player.class).isPresent() || !captureContainer.get(GuardianSequence.INITIAL_LOCATION).isPresent())
        return;
    final Player player = entry.getEntity(Player.class).get();
    final Value<Double> playerBoxWidth = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_WIDTH, entry, this.getDetection().getContentContainer()).orElse(GuardianValue.empty());
    final Value<Double> playerBoxHeight = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_HEIGHT, entry, this.getDetection().getContentContainer()).orElse(GuardianValue.empty());
    final Value<Double> playerBoxSafety = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_SAFETY, entry, this.getDetection().getContentContainer()).orElse(GuardianValue.empty());
    final double playerWidth = playerBoxWidth.getDirect().orElse(1.2) + playerBoxSafety.getDirect().orElse(0.05);
    final double playerHeight = playerBoxHeight.getDirect().orElse(1.8) + playerBoxSafety.getDirect().orElse(0.05);
    final boolean isSneaking = player.get(Keys.IS_SNEAKING).isPresent() && player.get(Keys.IS_SNEAKING).get();
    final BoundingBox playerBox = WorldUtil.getBoundingBox(playerWidth, isSneaking ? (playerHeight - 0.15) : playerHeight);
    final Location location = player.getLocation();
    Location relativeAltitude = null;
    double blockDepthOffset = 0;
    captureContainer.offerIfEmpty(GuardianValue.builder(AltitudeCapture.RELATIVE_ALTITUDE).defaultElement(1d).element(1d).create());
    for (int n = 0; n < Math.abs(location.getY()); n++) {
        double i = this.amount * n;
        Optional<Location> maximumDepth = captureContainer.get(AltitudeCapture.INITIAL_DEPTH);
        Location currentDepth = location.sub(0, i, 0);
        if (!WorldUtil.isEmptyAtDepth(location, playerBox, i)) {
            if (maximumDepth.isPresent() && maximumDepth.get().getY() == currentDepth.getY()) {
                relativeAltitude = currentDepth.add(0, this.amount, 0);
                blockDepthOffset = 1;
                break;
            } else if (maximumDepth.isPresent() && maximumDepth.get().getY() < currentDepth.getY()) {
                relativeAltitude = currentDepth.add(0, this.amount, 0);
                blockDepthOffset = (currentDepth.getY() - maximumDepth.get().getY()) > -1 ? -1 : currentDepth.getY() - maximumDepth.get().getY();
                break;
            } else if (maximumDepth.isPresent() && maximumDepth.get().getY() > currentDepth.getY()) {
                relativeAltitude = currentDepth.add(0, this.amount, 0);
                blockDepthOffset = (maximumDepth.get().getY() - currentDepth.getY()) < 1 ? 1 : maximumDepth.get().getY() - currentDepth.getY();
                break;
            } else if (!maximumDepth.isPresent()) {
                captureContainer.offer(GuardianValue.builder(AltitudeCapture.INITIAL_DEPTH).defaultElement(currentDepth).element(currentDepth).create());
                relativeAltitude = currentDepth.add(0, this.amount, 0);
                break;
            }
        } else if ((currentDepth.getY() - 1) < 0) {
            if (!maximumDepth.isPresent()) {
                captureContainer.offer(GuardianValue.builder(AltitudeCapture.INITIAL_DEPTH).defaultElement(location.getExtent().getLocation(currentDepth.getX(), -256, currentDepth.getZ())).element(location.getExtent().getLocation(currentDepth.getX(), -256, currentDepth.getZ())).create());
            }
            if (maximumDepth.isPresent() && maximumDepth.get().getY() == currentDepth.getY()) {
                relativeAltitude = currentDepth.add(0, this.amount, 0);
                blockDepthOffset = -1;
                break;
            }
        }
    }
    if (!captureContainer.get(AltitudeCapture.INITIAL_DEPTH).isPresent() || relativeAltitude == null) {
        relativeAltitude = player.getLocation().setPosition(new Vector3d(player.getLocation().getX(), 0, player.getLocation().getZ()));
    }
    double relativeAltitudeOffset = (player.getLocation().getY() - relativeAltitude.getY()) - Math.abs(blockDepthOffset);
    if (this.liftOnly && relativeAltitudeOffset < 0)
        return;
    final double offset = relativeAltitudeOffset;
    captureContainer.getValue(AltitudeCapture.RELATIVE_ALTITUDE).ifPresent(value -> value.transform(original -> original + offset));
    captureContainer.getValue(AltitudeCapture.LAST_ALTITUDE).ifPresent(value -> value.set(offset));
}
Also used : Location(org.spongepowered.api.world.Location) GuardianSequence(com.ichorpowered.guardian.sequence.GuardianSequence) ContentKeys(com.ichorpowered.guardianapi.content.ContentKeys) Keys(org.spongepowered.api.data.key.Keys) ContentUtil(com.ichorpowered.guardian.util.ContentUtil) CaptureKey(com.ichorpowered.guardianapi.detection.capture.CaptureKey) GuardianCaptureKey(com.ichorpowered.guardian.sequence.capture.GuardianCaptureKey) Vector3d(com.flowpowered.math.vector.Vector3d) TypeToken(com.google.common.reflect.TypeToken) BoundingBox(com.ichorpowered.guardian.util.entity.BoundingBox) GuardianValue(com.ichorpowered.guardian.util.item.mutable.GuardianValue) Detection(com.ichorpowered.guardianapi.detection.Detection) AbstractCapture(com.ichorpowered.guardian.sequence.capture.AbstractCapture) Value(com.ichorpowered.guardianapi.util.item.value.mutable.Value) CaptureContainer(com.ichorpowered.guardianapi.detection.capture.CaptureContainer) Optional(java.util.Optional) PlayerEntry(com.ichorpowered.guardianapi.entry.entity.PlayerEntry) WorldUtil(com.ichorpowered.guardian.util.WorldUtil) Player(org.spongepowered.api.entity.living.player.Player) Nonnull(javax.annotation.Nonnull) Player(org.spongepowered.api.entity.living.player.Player) Vector3d(com.flowpowered.math.vector.Vector3d) BoundingBox(com.ichorpowered.guardian.util.entity.BoundingBox) Location(org.spongepowered.api.world.Location)

Example 5 with CaptureContainer

use of com.ichorpowered.guardianapi.detection.capture.CaptureContainer in project guardian by ichorpowered.

the class ControlCapture method update.

@Override
public void update(@Nonnull PlayerEntry entry, @Nonnull CaptureContainer captureContainer) {
    if (!entry.getEntity(Player.class).isPresent() || !captureContainer.get(GuardianSequence.INITIAL_LOCATION).isPresent())
        return;
    final Player player = entry.getEntity(Player.class).get();
    final MapValue<String, Integer> activeControls = GuardianMapValue.builder(ControlCapture.ACTIVE_CONTROL_TICKS).defaultElement(Maps.newHashMap()).element(Maps.newHashMap()).create();
    activeControls.put(FLY, 0);
    activeControls.put(WALK, 0);
    activeControls.put(SNEAK, 0);
    activeControls.put(SPRINT, 0);
    captureContainer.offerIfEmpty(activeControls);
    captureContainer.offerIfEmpty(GuardianValue.builder(ControlCapture.HORIZONTAL_DISTANCE).defaultElement(1d).element(1d).create());
    captureContainer.offerIfEmpty(GuardianValue.builder(ControlCapture.VERTICAL_DISTANCE).defaultElement(1d).element(1d).create());
    double walkSpeedData = player.get(Keys.WALKING_SPEED).orElse(1d) * 10;
    double flySpeedData = player.get(Keys.FLYING_SPEED).orElse(0.5) * 10;
    if (player.getLocation().getY() != captureContainer.get(GuardianSequence.INITIAL_LOCATION).get().getY()) {
        captureContainer.getValue(ControlCapture.VERTICAL_DISTANCE).ifPresent(value -> value.transform(original -> original * this.liftOffset));
    }
    if ((player.get(Keys.IS_FLYING).isPresent() && player.get(Keys.IS_FLYING).get())) {
        captureContainer.getValue(ControlCapture.HORIZONTAL_DISTANCE).ifPresent(value -> value.transform(original -> original * (this.flyOffset * flySpeedData)));
        captureContainer.getValue(ControlCapture.ACTIVE_CONTROL_TICKS).ifPresent(value -> value.put(FLY, value.get().get(FLY) + 1));
    } else if (player.get(Keys.IS_SPRINTING).isPresent() && player.get(Keys.IS_SPRINTING).get()) {
        captureContainer.getValue(ControlCapture.HORIZONTAL_DISTANCE).ifPresent(value -> value.transform(original -> original * (this.sprintOffset * walkSpeedData)));
        captureContainer.getValue(ControlCapture.ACTIVE_CONTROL_TICKS).ifPresent(value -> value.put(SPRINT, value.get().get(SPRINT) + 1));
    } else if (player.get(Keys.IS_SNEAKING).isPresent() && player.get(Keys.IS_SNEAKING).get()) {
        captureContainer.getValue(ControlCapture.HORIZONTAL_DISTANCE).ifPresent(value -> value.transform(original -> original * (this.sneakOffset * walkSpeedData)));
        captureContainer.getValue(ControlCapture.ACTIVE_CONTROL_TICKS).ifPresent(value -> value.put(SNEAK, value.get().get(SNEAK) + 1));
    } else {
        captureContainer.getValue(ControlCapture.HORIZONTAL_DISTANCE).ifPresent(value -> value.transform(original -> original * (this.walkOffset * walkSpeedData)));
        captureContainer.getValue(ControlCapture.ACTIVE_CONTROL_TICKS).ifPresent(value -> value.put(WALK, value.get().get(WALK) + 1));
    }
}
Also used : GuardianSequence(com.ichorpowered.guardian.sequence.GuardianSequence) ContentKeys(com.ichorpowered.guardianapi.content.ContentKeys) Keys(org.spongepowered.api.data.key.Keys) CaptureKey(com.ichorpowered.guardianapi.detection.capture.CaptureKey) GuardianCaptureKey(com.ichorpowered.guardian.sequence.capture.GuardianCaptureKey) TypeToken(com.google.common.reflect.TypeToken) Maps(com.google.common.collect.Maps) GuardianValue(com.ichorpowered.guardian.util.item.mutable.GuardianValue) GuardianMapValue(com.ichorpowered.guardian.util.item.mutable.GuardianMapValue) Detection(com.ichorpowered.guardianapi.detection.Detection) AbstractCapture(com.ichorpowered.guardian.sequence.capture.AbstractCapture) Value(com.ichorpowered.guardianapi.util.item.value.mutable.Value) CaptureContainer(com.ichorpowered.guardianapi.detection.capture.CaptureContainer) MapValue(com.ichorpowered.guardianapi.util.item.value.mutable.MapValue) Map(java.util.Map) PlayerEntry(com.ichorpowered.guardianapi.entry.entity.PlayerEntry) Player(org.spongepowered.api.entity.living.player.Player) Nonnull(javax.annotation.Nonnull) Player(org.spongepowered.api.entity.living.player.Player)

Aggregations

GuardianSequence (com.ichorpowered.guardian.sequence.GuardianSequence)8 GuardianValue (com.ichorpowered.guardian.util.item.mutable.GuardianValue)8 ContentKeys (com.ichorpowered.guardianapi.content.ContentKeys)8 Detection (com.ichorpowered.guardianapi.detection.Detection)8 CaptureContainer (com.ichorpowered.guardianapi.detection.capture.CaptureContainer)8 Keys (org.spongepowered.api.data.key.Keys)8 Player (org.spongepowered.api.entity.living.player.Player)8 Nonnull (javax.annotation.Nonnull)6 Location (org.spongepowered.api.world.Location)6 Value (com.ichorpowered.guardianapi.util.item.value.mutable.Value)5 Map (java.util.Map)5 SequenceBlueprint (com.abilityapi.sequenceapi.SequenceBlueprint)4 SequenceContext (com.abilityapi.sequenceapi.SequenceContext)4 ConditionType (com.abilityapi.sequenceapi.action.condition.ConditionType)4 Sets (com.google.common.collect.Sets)4 TypeToken (com.google.common.reflect.TypeToken)4 GuardianPlayerEntry (com.ichorpowered.guardian.entry.GuardianPlayerEntry)4 GuardianSequenceBuilder (com.ichorpowered.guardian.sequence.GuardianSequenceBuilder)4 SequenceReport (com.ichorpowered.guardian.sequence.SequenceReport)4 AbstractCapture (com.ichorpowered.guardian.sequence.capture.AbstractCapture)4