Search in sources :

Example 1 with BlockUpdateManager

use of com.easterlyn.util.BlockUpdateManager in project Easterlyn by Easterlyn.

the class EffectTunnelBore method applyEffect.

@Override
public void applyEffect(@NotNull LivingEntity entity, int level, @Nullable Event event) {
    if (!(event instanceof BlockBreakEvent) || event instanceof IndirectBreakEvent) {
        return;
    }
    BlockBreakEvent breakEvent = (BlockBreakEvent) event;
    Player player = breakEvent.getPlayer();
    if (player.isSneaking()) {
        // Sneak to mine single blocks
        return;
    }
    Block block = breakEvent.getBlock();
    if (!BlockUtil.isCorrectTool(player.getInventory().getItemInMainHand(), breakEvent.getBlock().getType())) {
        // Require correct tool used
        return;
    }
    RegisteredServiceProvider<EasterlynCore> registration = getPlugin().getServer().getServicesManager().getRegistration(EasterlynCore.class);
    if (registration == null) {
        return;
    }
    BlockUpdateManager budManager = registration.getProvider().getBlockUpdateManager();
    /*
     * Forgiveness of .25 hardness allows indirect breaking of most common related materials
     * while not excessively increasing risk of accidents inside builds. Allows for mining gravel
     * via sand and dirt, etc.
     */
    float hardness = block.getType().getHardness() + 0.25F;
    for (BlockFace yLevel : levels) {
        if (block.getY() == 0 && yLevel == BlockFace.DOWN) {
            continue;
        }
        Block relativeCenter = block.getRelative(yLevel);
        if (yLevel != BlockFace.SELF) {
            if (handleBlock(hardness, relativeCenter, player, budManager)) {
                return;
            }
        }
        for (BlockFace face : faces) {
            if (handleBlock(hardness, relativeCenter.getRelative(face), player, budManager)) {
                return;
            }
        }
    }
    player.updateInventory();
}
Also used : Player(org.bukkit.entity.Player) EasterlynCore(com.easterlyn.EasterlynCore) IndirectBreakEvent(com.easterlyn.effect.event.IndirectBreakEvent) BlockFace(org.bukkit.block.BlockFace) BlockUpdateManager(com.easterlyn.util.BlockUpdateManager) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) Block(org.bukkit.block.Block)

Example 2 with BlockUpdateManager

use of com.easterlyn.util.BlockUpdateManager in project Easterlyn by Easterlyn.

the class EffectAdjacentBlockModifier method applyEffect.

@Override
public void applyEffect(@NotNull LivingEntity entity, int level, @Nullable Event event) {
    if (!(event instanceof BlockBreakEvent)) {
        return;
    }
    RegisteredServiceProvider<EasterlynCore> registration = getPlugin().getServer().getServicesManager().getRegistration(EasterlynCore.class);
    if (registration == null) {
        return;
    }
    BlockUpdateManager budManager = registration.getProvider().getBlockUpdateManager();
    BlockBreakEvent breakEvent = (BlockBreakEvent) event;
    Player player = breakEvent.getPlayer();
    int currentCount = 0;
    for (BlockFace face : faces) {
        Block relative = breakEvent.getBlock().getRelative(face);
        if (handleAdjacentBlock(player, relative, currentCount)) {
            budManager.queueBlock(relative);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) EasterlynCore(com.easterlyn.EasterlynCore) BlockFace(org.bukkit.block.BlockFace) BlockUpdateManager(com.easterlyn.util.BlockUpdateManager) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) Block(org.bukkit.block.Block)

Aggregations

EasterlynCore (com.easterlyn.EasterlynCore)2 BlockUpdateManager (com.easterlyn.util.BlockUpdateManager)2 Block (org.bukkit.block.Block)2 BlockFace (org.bukkit.block.BlockFace)2 Player (org.bukkit.entity.Player)2 BlockBreakEvent (org.bukkit.event.block.BlockBreakEvent)2 IndirectBreakEvent (com.easterlyn.effect.event.IndirectBreakEvent)1