Search in sources :

Example 1 with BlockCache

use of fr.neatmonster.nocheatplus.utilities.map.BlockCache in project NoCheatPlus by NoCheatPlus.

the class MoveInfo method set.

/**
 * Initialize from, and if given to. Note that useLoc and data are left
 * untouched.
 *
 * @param entity
 * @param from
 *            Must not be null.
 * @param to
 *            Can be null.
 * @param yOnGround
 */
public final void set(final E entity, final Location from, final Location to, final double yOnGround) {
    final BlockCache cache = wrapCache.getBlockCache();
    cache.setAccess(from.getWorld());
    this.from.setBlockCache(cache);
    set(this.from, from, entity, yOnGround);
    if (to != null) {
        this.to.setBlockCache(cache);
        set(this.to, to, entity, yOnGround);
    }
// Note: using set to reset to by passing null won't work.
}
Also used : BlockCache(fr.neatmonster.nocheatplus.utilities.map.BlockCache) WrapBlockCache(fr.neatmonster.nocheatplus.utilities.map.WrapBlockCache)

Example 2 with BlockCache

use of fr.neatmonster.nocheatplus.utilities.map.BlockCache in project NoCheatPlus by NoCheatPlus.

the class HotFixFallingBlockPortalEnter method onEntityPortalEnter.

@EventHandler(priority = EventPriority.MONITOR)
public void onEntityPortalEnter(EntityPortalEnterEvent event) {
    final Entity entity = event.getEntity();
    final Material mat;
    if (entity instanceof FallingBlock) {
        mat = ((FallingBlock) entity).getMaterial();
    } else if (entity instanceof Item) {
        // TODO: Not sure if needed.
        if (((Item) entity).getItemStack().getType().hasGravity()) {
            mat = ((Item) entity).getItemStack().getType();
        } else {
            mat = null;
        }
    } else {
        mat = null;
    }
    if (mat != null) {
        final Location loc = entity.getLocation(useLoc);
        final World world = loc.getWorld();
        final IWorldData worldData = NCPAPIProvider.getNoCheatPlusAPI().getWorldDataManager().getWorldData(world);
        if (worldData.getGenericInstance(InventoryConfig.class).hotFixFallingBlockEndPortalActive) {
            final BlockCache blockCache = wrapBlockCache.getBlockCache();
            blockCache.setAccess(world);
            final boolean nearbyPortal = BlockProperties.collidesId(blockCache, loc.getX() - 2.0, loc.getY() - 2.0, loc.getZ() - 2.0, loc.getX() + 3.0, loc.getY() + 3.0, loc.getZ() + 3.0, Material.ENDER_PORTAL);
            blockCache.cleanup();
            if (nearbyPortal) {
                // Likely spigot currently removes entities entering portals anyway (cross-world teleport issues).
                // On remove: Looks like setDropItem(false) wouldn't suffice.
                entity.remove();
                // TODO: STATUS: should have another stream for violations/protection.
                final String message = "[INVENTORY_HOTFIX] Remove falling block entering a portal near an end portal: " + mat + " at " + world.getName() + "/" + LocUtil.simpleFormatPosition(loc);
                NCPAPIProvider.getNoCheatPlusAPI().getLogManager().info(Streams.STATUS, message);
            }
        }
        useLoc.setWorld(null);
    }
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) Entity(org.bukkit.entity.Entity) Item(org.bukkit.entity.Item) BlockCache(fr.neatmonster.nocheatplus.utilities.map.BlockCache) WrapBlockCache(fr.neatmonster.nocheatplus.utilities.map.WrapBlockCache) Material(org.bukkit.Material) IWorldData(fr.neatmonster.nocheatplus.worlds.IWorldData) World(org.bukkit.World) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 3 with BlockCache

use of fr.neatmonster.nocheatplus.utilities.map.BlockCache in project NoCheatPlus by NoCheatPlus.

the class BlockChangeTracker method addPistonBlocks.

/*
     * TODO: Consider tracking regions of player activity (chunk sections, with
     * a margin around the player) and filter.
     */
/**
 * Process the data, as given by a BlockPistonExtendEvent or
 * BlockPistonRetractEvent.
 *
 * @param pistonBlock
 *            This block is added directly, unless null.
 * @param blockFace
 * @param movedBlocks
 *            Unless null, each block and the relative block in the given
 *            direction (!) are added.
 */
public void addPistonBlocks(final Block pistonBlock, final BlockFace blockFace, final List<Block> movedBlocks) {
    // TODO: Remove, once sure, that processing never ever generates an exception.
    checkProcessBlocks();
    final int tick = TickTask.getTick();
    final World world = pistonBlock.getWorld();
    final WorldNode worldNode = getOrCreateWorldNode(world, tick);
    // TODO: Could set preferKeep.
    final long changeId = getNewChangeId(tick, false);
    // Avoid duplicates by adding to a set.
    if (pistonBlock != null) {
        processBlocks.add(pistonBlock);
    }
    if (movedBlocks != null) {
        for (final Block movedBlock : movedBlocks) {
            processBlocks.add(movedBlock);
            processBlocks.add(movedBlock.getRelative(blockFace));
        }
    }
    // Process queued blocks.
    final BlockCache blockCache = blockCacheHandle.getHandle();
    // Assume all users always clean up after use :).
    blockCache.setAccess(world);
    for (final Block block : processBlocks) {
        addPistonBlock(changeId, tick, worldNode, block.getX(), block.getY(), block.getZ(), blockFace, blockCache);
    }
    blockCache.cleanup();
    processBlocks.clear();
}
Also used : BlockCache(fr.neatmonster.nocheatplus.utilities.map.BlockCache) Block(org.bukkit.block.Block) World(org.bukkit.World)

Example 4 with BlockCache

use of fr.neatmonster.nocheatplus.utilities.map.BlockCache in project NoCheatPlus by NoCheatPlus.

the class BlockChangeTracker method addBlocks.

/**
 * Add blocks as neutral past states (no moving direction). All blocks are
 * to be in the same world (no consistency checks!), the world of the first
 * block is used.
 *
 * @param blocks
 *            Could be/have empty / null / null entries, duplicate blocks
 *            will be ignored.
 */
public void addBlocks(final Collection<Block> blocks) {
    if (blocks == null || blocks.isEmpty()) {
        return;
    }
    // TODO: Remove, once sure, that processing never ever generates an exception.
    checkProcessBlocks();
    // Collect non null blocks first, set world.
    World world = null;
    for (final Block block : blocks) {
        if (block != null) {
            if (world == null) {
                world = block.getWorld();
            }
            processBlocks.add(block);
        }
    }
    if (world == null || processBlocks.isEmpty()) {
        // In case the world is null (unlikely).
        processBlocks.clear();
        return;
    }
    // Add blocks.
    final int tick = TickTask.getTick();
    final WorldNode worldNode = getOrCreateWorldNode(world, tick);
    // TODO: Could set preferKeep.
    final long changeId = getNewChangeId(tick, false);
    // Process queued blocks.
    final BlockCache blockCache = blockCacheHandle.getHandle();
    // Assume all users always clean up after use :).
    blockCache.setAccess(world);
    for (final Block block : processBlocks) {
        addBlock(changeId, tick, worldNode, block.getX(), block.getY(), block.getZ(), blockCache);
    }
    blockCache.cleanup();
    processBlocks.clear();
}
Also used : BlockCache(fr.neatmonster.nocheatplus.utilities.map.BlockCache) Block(org.bukkit.block.Block) World(org.bukkit.World)

Example 5 with BlockCache

use of fr.neatmonster.nocheatplus.utilities.map.BlockCache in project NoCheatPlus by NoCheatPlus.

the class Visible method check.

public boolean check(final Player player, final Location loc, final double eyeHeight, final Block block, final BlockFace face, final Action action, final FlyingQueueHandle flyingHandle, final BlockInteractData data, final BlockInteractConfig cc, final IPlayerData pData) {
    // TODO: This check might make parts of interact/blockbreak/... + direction (+?) obsolete.
    // TODO: Might confine what to check for (left/right-click, target blocks depending on item in hand, container blocks).
    boolean collides;
    final int blockX = block.getX();
    final int blockY = block.getY();
    final int blockZ = block.getZ();
    final double eyeX = loc.getX();
    final double eyeY = loc.getY() + eyeHeight;
    final double eyeZ = loc.getZ();
    final boolean debug = pData.isDebugActive(type);
    tags.clear();
    if (TrigUtil.isSameBlock(blockX, blockY, blockZ, eyeX, eyeY, eyeZ)) {
        // Player is interacting with the block their head is in.
        // TODO: Should the reachable-face-check be done here too (if it is added at all)?
        collides = false;
    } else {
        // Ray-tracing.
        // Initialize.
        final BlockCache blockCache = this.wrapBlockCache.getBlockCache();
        blockCache.setAccess(loc.getWorld());
        rayTracing.setBlockCache(blockCache);
        collides = !checker.checkFlyingQueue(eyeX, eyeY, eyeZ, loc.getYaw(), loc.getPitch(), blockX, blockY, blockZ, flyingHandle, face, tags, debug, player);
        checker.cleanup();
        useLoc.setWorld(null);
        // Cleanup.
        rayTracing.cleanup();
        blockCache.cleanup();
    }
    // Actions ?
    boolean cancel = false;
    if (collides) {
        data.visibleVL += 1;
        final ViolationData vd = new ViolationData(this, player, data.visibleVL, 1, cc.visibleActions);
        // }
        if (executeActions(vd).willCancel()) {
            cancel = true;
        }
    } else {
        data.visibleVL *= 0.99;
        data.addPassedCheck(this.type);
        if (debug) {
            debug(player, "pitch=" + loc.getPitch() + ",yaw=" + loc.getYaw() + " tags=" + StringUtil.join(tags, "+"));
        }
    }
    return cancel;
}
Also used : BlockCache(fr.neatmonster.nocheatplus.utilities.map.BlockCache) WrapBlockCache(fr.neatmonster.nocheatplus.utilities.map.WrapBlockCache) ViolationData(fr.neatmonster.nocheatplus.checks.ViolationData)

Aggregations

BlockCache (fr.neatmonster.nocheatplus.utilities.map.BlockCache)5 WrapBlockCache (fr.neatmonster.nocheatplus.utilities.map.WrapBlockCache)3 World (org.bukkit.World)3 Block (org.bukkit.block.Block)2 ViolationData (fr.neatmonster.nocheatplus.checks.ViolationData)1 IWorldData (fr.neatmonster.nocheatplus.worlds.IWorldData)1 Location (org.bukkit.Location)1 Material (org.bukkit.Material)1 Entity (org.bukkit.entity.Entity)1 FallingBlock (org.bukkit.entity.FallingBlock)1 Item (org.bukkit.entity.Item)1 EventHandler (org.bukkit.event.EventHandler)1