Search in sources :

Example 1 with IsCancelled

use of org.spongepowered.api.event.filter.IsCancelled in project Skree by Skelril.

the class AntiJumpListener method onBlockPlace.

@Listener(order = Order.POST)
@IsCancelled(value = Tristate.TRUE)
public void onBlockPlace(ChangeBlockEvent.Place event, @Root Player player) {
    final Location<World> playerLoc = player.getLocation();
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        Optional<Location<World>> optLoc = transaction.getOriginal().getLocation();
        if (!optLoc.isPresent()) {
            continue;
        }
        Location<World> blockLoc = optLoc.get();
        final int blockY = blockLoc.getBlockY();
        if (Math.abs(player.getVelocity().getY()) > UPWARDS_VELOCITY && playerLoc.getY() > blockY) {
            Task.builder().execute(() -> {
                Vector3d position = player.getLocation().getPosition();
                if (position.getY() >= (blockY + LEAP_DISTANCE)) {
                    if (playerLoc.getPosition().distanceSquared(blockLoc.getPosition()) > Math.pow(RADIUS, 2)) {
                        return;
                    }
                    player.sendMessage(Text.of(TextColors.RED, "Hack jumping detected."));
                    player.setLocation(playerLoc.setPosition(new Vector3d(position.getX(), blockY, position.getZ())));
                }
            }).delayTicks(4).submit(SkreePlugin.inst());
        }
    }
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener) IsCancelled(org.spongepowered.api.event.filter.IsCancelled)

Aggregations

Vector3d (com.flowpowered.math.vector.Vector3d)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 Listener (org.spongepowered.api.event.Listener)1 IsCancelled (org.spongepowered.api.event.filter.IsCancelled)1 Location (org.spongepowered.api.world.Location)1 World (org.spongepowered.api.world.World)1