Search in sources :

Example 6 with FallingBlock

use of org.bukkit.entity.FallingBlock in project MagicPlugin by elBukkit.

the class ThrowBlockAction method start.

@Override
public SpellResult start(CastContext context) {
    Location location = context.getLocation();
    if (!context.hasBuildPermission(location.getBlock())) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    location.setY(location.getY() - 1);
    MaterialBrush buildWith = context.getBrush();
    buildWith.setTarget(location);
    if (buildWith.isErase() || buildWith.getMaterial() == Material.AIR) {
        return SpellResult.NO_TARGET;
    }
    if (consumeBlocks && !context.isConsumeFree()) {
        Mage mage = context.getMage();
        UndoList undoList = context.getUndoList();
        if (undoList != null) {
            undoList.setConsumed(true);
        }
        ItemStack requires = buildWith.getItemStack(1);
        if (!mage.hasItem(requires, consumeVariants)) {
            String requiresMessage = context.getMessage("insufficient_resources");
            context.sendMessage(requiresMessage.replace("$cost", buildWith.getName()));
            return SpellResult.STOP;
        }
        mage.removeItem(requires, consumeVariants);
    }
    Material material = buildWith.getMaterial();
    byte data = buildWith.getBlockData();
    location = sourceLocation.getLocation(context);
    Vector direction = location.getDirection();
    double speed = context.getRandom().nextDouble() * (speedMax - speedMin) + speedMin;
    direction.normalize().multiply(speed);
    Vector up = new Vector(0, 1, 0);
    Vector perp = new Vector();
    perp.copy(direction);
    perp.crossProduct(up);
    FallingBlock falling = DeprecatedUtils.spawnFallingBlock(location, material, data);
    if (falling == null) {
        return SpellResult.FAIL;
    }
    track(context, falling);
    if (!consumeBlocks) {
        falling.setDropItem(false);
    }
    SafetyUtils.setVelocity(falling, direction);
    if (maxDamage > 0 && fallDamage > 0) {
        CompatibilityUtils.setFallingBlockDamage(falling, fallDamage, maxDamage);
    } else {
        falling.setHurtEntities(hurts);
    }
    return checkTracking(context);
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) MaterialBrush(com.elmakers.mine.bukkit.api.block.MaterialBrush) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) SourceLocation(com.elmakers.mine.bukkit.magic.SourceLocation)

Example 7 with FallingBlock

use of org.bukkit.entity.FallingBlock in project MagicPlugin by elBukkit.

the class ConstructBatch method modifyWith.

protected void modifyWith(Block block, MaterialAndData brush) {
    Material previousMaterial = block.getType();
    byte previousData = DeprecatedUtils.getData(block);
    if (brush.isValid() && (brush.isDifferent(block) || commit)) {
        if (consume && !context.isConsumeFree() && brush.getMaterial() != Material.AIR) {
            ItemStack requires = brush.getItemStack(1);
            if (!mage.hasItem(requires, consumeVariants)) {
                String requiresMessage = context.getMessage("insufficient_resources");
                context.sendMessage(requiresMessage.replace("$cost", brush.getName()));
                finish();
                return;
            }
            mage.removeItem(requires, consumeVariants);
        }
        if (!commit) {
            registerForUndo(block);
        }
        // Check for command overrides
        if (commandMap != null && brush.getMaterial() == Material.COMMAND) {
            String commandKey = brush.getCommandLine();
            if (commandKey != null && commandKey.length() > 0 && commandMap.containsKey(commandKey)) {
                brush.setCommandLine(commandMap.get(commandKey));
            }
        }
        brush.modify(block, applyPhysics);
        if (breakable > 0) {
            spell.getCurrentCast().registerBreakable(block, breakable);
        }
        if (backfireChance > 0) {
            spell.getCurrentCast().registerReflective(block, backfireChance);
        }
        if (spawnFallingBlocks) {
            FallingBlock falling = DeprecatedUtils.spawnFallingBlock(block.getLocation(), previousMaterial, previousData);
            falling.setDropItem(false);
            if (fallingBlockSpeed != 0) {
                Vector direction = this.fallingDirection != null ? this.fallingDirection : falling.getLocation().subtract(center).toVector();
                direction = direction.normalize().multiply(fallingBlockSpeed);
                SafetyUtils.setVelocity(falling, direction);
            }
            registerForUndo(falling);
        }
        if (commit) {
            com.elmakers.mine.bukkit.api.block.BlockData blockData = UndoList.register(block);
            blockData.commit();
        }
    }
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) PistonBaseMaterial(org.bukkit.material.PistonBaseMaterial) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector)

Example 8 with FallingBlock

use of org.bukkit.entity.FallingBlock in project MagicPlugin by elBukkit.

the class FillBatch method process.

@Override
@SuppressWarnings("deprecation")
public int process(int maxBlocks) {
    int processedBlocks = 0;
    while (processedBlocks <= maxBlocks && ix < absx) {
        Block block = world.getBlockAt(x + ix * dx, y + iy * dy, z + iz * dz);
        brush.update(mage, block.getLocation());
        if (!block.getChunk().isLoaded()) {
            block.getChunk().load();
            return processedBlocks;
        }
        if (!brush.isReady()) {
            brush.prepare();
            return processedBlocks;
        }
        processedBlocks++;
        boolean hasPermission = brush.isErase() ? spell.hasBreakPermission(block) : spell.hasBuildPermission(block);
        if (hasPermission && !spell.isIndestructible(block)) {
            Material previousMaterial = block.getType();
            byte previousData = block.getData();
            if (brush.isDifferent(block)) {
                if (consume && !context.isConsumeFree() && brush.getMaterial() != Material.AIR) {
                    ItemStack requires = brush.getItemStack(1);
                    if (!mage.hasItem(requires, consumeVariants)) {
                        String requiresMessage = context.getMessage("insufficient_resources");
                        context.sendMessage(requiresMessage.replace("$cost", brush.getName()));
                        finish();
                        return processedBlocks;
                    }
                    mage.removeItem(requires, consumeVariants);
                }
                registerForUndo(block);
                brush.modify(block);
                if (spawnFallingBlocks) {
                    FallingBlock falling = block.getWorld().spawnFallingBlock(block.getLocation(), previousMaterial, previousData);
                    falling.setDropItem(false);
                }
            }
        }
        iy++;
        if (iy >= absy) {
            iy = 0;
            iz++;
            if (iz >= absz) {
                iz = 0;
                ix++;
            }
        }
    }
    if (ix >= absx) {
        finish();
    }
    return processedBlocks;
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack)

Example 9 with FallingBlock

use of org.bukkit.entity.FallingBlock in project MagicPlugin by elBukkit.

the class BlockController method onEntityChangeBlockEvent.

@EventHandler
public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) {
    Entity entity = event.getEntity();
    if (entity instanceof FallingBlock) {
        if (event.getTo() == Material.AIR) {
            // Block is falling, register it
            controller.registerFallingBlock(entity, event.getBlock());
        } else {
            // Block is landing, convert it
            UndoList blockList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(entity);
            if (blockList != null) {
                com.elmakers.mine.bukkit.api.action.CastContext context = blockList.getContext();
                if (context != null && !context.hasBuildPermission(entity.getLocation().getBlock())) {
                    event.setCancelled(true);
                } else {
                    Block block = event.getBlock();
                    blockList.convert(entity, block);
                    if (!blockList.getApplyPhysics()) {
                        FallingBlock falling = (FallingBlock) entity;
                        DeprecatedUtils.setTypeIdAndData(block, DeprecatedUtils.getId(falling.getMaterial()), DeprecatedUtils.getBlockData(falling), false);
                        event.setCancelled(true);
                    }
                }
            }
        }
    }
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) Entity(org.bukkit.entity.Entity) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) EventHandler(org.bukkit.event.EventHandler)

Example 10 with FallingBlock

use of org.bukkit.entity.FallingBlock 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)

Aggregations

FallingBlock (org.bukkit.entity.FallingBlock)10 Location (org.bukkit.Location)7 Material (org.bukkit.Material)6 Block (org.bukkit.block.Block)6 Vector (org.bukkit.util.Vector)5 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)4 ItemStack (org.bukkit.inventory.ItemStack)4 MaterialBrush (com.elmakers.mine.bukkit.api.block.MaterialBrush)3 EventHandler (org.bukkit.event.EventHandler)3 Mage (com.elmakers.mine.bukkit.api.magic.Mage)2 Entity (org.bukkit.entity.Entity)2 SourceLocation (com.elmakers.mine.bukkit.magic.SourceLocation)1 BlockCache (fr.neatmonster.nocheatplus.utilities.map.BlockCache)1 WrapBlockCache (fr.neatmonster.nocheatplus.utilities.map.WrapBlockCache)1 IWorldData (fr.neatmonster.nocheatplus.worlds.IWorldData)1 World (org.bukkit.World)1 Item (org.bukkit.entity.Item)1 ThrownPotion (org.bukkit.entity.ThrownPotion)1 PistonBaseMaterial (org.bukkit.material.PistonBaseMaterial)1 PotionEffect (org.bukkit.potion.PotionEffect)1