Search in sources :

Example 1 with PlayerBlockBreak

use of org.cubeengine.module.log.action.block.player.destroy.PlayerBlockBreak in project modules-extra by CubeEngine.

the class ListenerPlayerBlock method onBlockPlace.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
    Block blockPlaced = event.getBlockPlaced();
    PlayerBlockPlace action = this.newAction(PlayerBlockPlace.class, blockPlaced.getWorld());
    if (action != null) {
        action.setLocation(event.getBlock().getLocation());
        action.setPlayer(event.getPlayer());
        action.setOldBlock(event.getBlockReplacedState());
        action.setNewBlock(blockPlaced.getState());
        this.logAction(action);
        if (this.isActive(BlockFall.class, blockPlaced.getWorld()) && blockPlaced.getRelative(DOWN).getType() == AIR && (blockPlaced.getType().hasGravity() || blockPlaced.getType() == DRAGON_EGG)) {
            this.module.getCore().getEventManager().fireEvent(new BlockPreFallEvent(blockPlaced.getLocation(), action));
        }
    }
    Block lily = blockPlaced.getRelative(UP);
    if (blockPlaced.getType() != STATIONARY_WATER && lily.getType() == WATER_LILY) {
        PlayerBlockBreak wAction = this.newAction(PlayerBlockBreak.class);
        if (wAction != null) {
            wAction.setPlayer(event.getPlayer());
            wAction.setLocation(lily.getLocation());
            wAction.setOldBlock(lily.getState());
            wAction.setNewBlock(AIR);
            wAction.reference = this.reference(action);
            this.logAction(wAction);
        }
    }
}
Also used : PlayerBlockBreak(org.cubeengine.module.log.action.block.player.destroy.PlayerBlockBreak) BlockPreFallEvent(org.cubeengine.module.log.action.block.BlockPreFallEvent) ListenerBlock(org.cubeengine.module.log.action.block.ListenerBlock) Block(org.bukkit.block.Block) NoteBlock(org.bukkit.block.NoteBlock) EventHandler(org.bukkit.event.EventHandler)

Example 2 with PlayerBlockBreak

use of org.cubeengine.module.log.action.block.player.destroy.PlayerBlockBreak in project modules-extra by CubeEngine.

the class ListenerPlayerBlock method onBlockBreak.

// Doors / Beds only logged bottom / feet
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
    if (event.getBlock().getType() == AIR) {
        // breaking air !? -> no logging
        return;
    }
    if (!this.isActive(PlayerBlockBreak.class, event.getBlock().getWorld())) {
        return;
    }
    BlockState blockState = event.getBlock().getState();
    PlayerBlockBreak action;
    if (blockState instanceof NoteBlock) {
        action = this.newAction(PlayerNoteBlockBreak.class);
        ((PlayerNoteBlockBreak) action).setNote(((NoteBlock) blockState).getNote());
    } else if (blockState instanceof Sign) {
        action = this.newAction(PlayerSignBreak.class);
        ((PlayerSignBreak) action).setLines(((Sign) blockState).getLines());
    } else if (blockState instanceof Jukebox && ((Jukebox) blockState).getPlaying() != null) {
        action = this.newAction(PlayerJukeboxBreak.class);
        ((PlayerJukeboxBreak) action).setDisc(((Jukebox) blockState).getPlaying());
    } else if (blockState instanceof InventoryHolder) {
        action = this.newAction(PlayerContainerBreak.class, event.getBlock().getWorld());
        if (action == null) {
            action = this.newAction(PlayerBlockBreak.class);
        } else {
            ((PlayerContainerBreak) action).setContents(((InventoryHolder) blockState).getInventory().getContents());
        }
    // TODO item drops
    // itemDrop.logDropsFromChest((InventoryHolder)blockState,location,event.getPlayer());
    } else {
        action = this.newAction(PlayerBlockBreak.class);
        // WOOD_DOOR IRON_DOOR OR BED_BLOCK
        blockState = adjustBlockForDoubleBlocks(blockState);
    }
    action.setPlayer(event.getPlayer());
    action.setLocation(event.getBlock().getLocation());
    action.setOldBlock(blockState);
    action.setNewBlock(AIR);
    this.logAction(action);
    if (// portal?
    blockState.getType() == OBSIDIAN) {
        // TODO better & complete
        Block block = blockState.getBlock();
        for (BlockFace face : BLOCK_FACES) {
            if (block.getRelative(face).getType() == PORTAL) {
                Block portal = block.getRelative(face);
                PlayerBlockBreak pAction = this.newAction(PlayerBlockBreak.class);
                pAction.setPlayer(event.getPlayer());
                pAction.setLocation(portal.getLocation());
                pAction.setOldBlock(portal.getState());
                pAction.setNewBlock(AIR);
                pAction.reference = this.reference(action);
                this.logAction(pAction);
                break;
            }
        }
    }
    // TODO attached & falling
    ListenerBlock.logAttachedBlocks(this, module.getCore().getEventManager(), event.getBlock(), action);
    ListenerBlock.logFallingBlocks(this, module.getCore().getEventManager(), event.getBlock(), action);
}
Also used : PlayerBlockBreak(org.cubeengine.module.log.action.block.player.destroy.PlayerBlockBreak) Jukebox(org.bukkit.block.Jukebox) BlockState(org.bukkit.block.BlockState) PlayerJukeboxBreak(org.cubeengine.module.log.action.block.player.destroy.PlayerJukeboxBreak) NoteBlock(org.bukkit.block.NoteBlock) BlockFace(org.bukkit.block.BlockFace) ListenerBlock(org.cubeengine.module.log.action.block.ListenerBlock) Block(org.bukkit.block.Block) NoteBlock(org.bukkit.block.NoteBlock) Sign(org.bukkit.block.Sign) InventoryHolder(org.bukkit.inventory.InventoryHolder) PlayerNoteBlockBreak(org.cubeengine.module.log.action.block.player.destroy.PlayerNoteBlockBreak) EventHandler(org.bukkit.event.EventHandler)

Example 3 with PlayerBlockBreak

use of org.cubeengine.module.log.action.block.player.destroy.PlayerBlockBreak in project modules-extra by CubeEngine.

the class ListenerBlock method onBlockPhysicsBreak.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPhysicsBreak(final BlockPhysicsEvent event) {
    BlockState oldState = event.getBlock().getState();
    Block blockAttachedTo;
    if (oldState.getData() instanceof Attachable) {
        Attachable attachable = (Attachable) oldState.getData();
        if (attachable.getAttachedFace() == null) {
            // is not attached !?
            return;
        }
        blockAttachedTo = event.getBlock().getRelative(attachable.getAttachedFace());
    } else // block on bottom missing
    {
        if (!BlockUtil.isDetachableFromBelow(oldState.getType())) {
            return;
        }
        blockAttachedTo = event.getBlock().getRelative(BlockFace.DOWN);
    }
    if (blockAttachedTo == null) {
        return;
    }
    if (!blockAttachedTo.getType().isSolid()) {
        Location loc = oldState.getLocation();
        ActionBlock cause = this.plannedPyhsics.remove(loc);
        oldState = adjustBlockForDoubleBlocks(oldState);
        if (cause instanceof ActionPlayerBlock) {
            PlayerBlockBreak action;
            if (oldState instanceof Sign) {
                action = this.set(PlayerSignBreak.class, oldState, null);
                if (action != null) {
                    ((PlayerSignBreak) action).setLines(((Sign) oldState).getLines());
                }
            } else {
                action = this.set(PlayerBlockBreak.class, oldState, null);
            }
            if (action != null) {
                action.setNewBlock(AIR);
                action.player = ((ActionPlayerBlock) cause).player;
                action.reference = this.reference(cause);
                this.logAction(action);
            }
        } else {
            BlockBreak action;
            if (oldState instanceof Sign) {
                action = this.set(SignBreak.class, oldState, null);
                if (action != null) {
                    ((SignBreak) action).setLines(((Sign) oldState).getLines());
                }
            } else {
                action = this.set(BlockBreak.class, oldState, null);
            }
            if (action != null) {
                action.setNewBlock(AIR);
                this.logAction(action);
            }
        }
    }
}
Also used : PlayerBlockBreak(org.cubeengine.module.log.action.block.player.destroy.PlayerBlockBreak) BlockState(org.bukkit.block.BlockState) ActionPlayerBlock(org.cubeengine.module.log.action.block.player.ActionPlayerBlock) PlayerBlockBreak(org.cubeengine.module.log.action.block.player.destroy.PlayerBlockBreak) PlayerSignBreak(org.cubeengine.module.log.action.block.player.destroy.PlayerSignBreak) Block(org.bukkit.block.Block) ActionPlayerBlock(org.cubeengine.module.log.action.block.player.ActionPlayerBlock) Sign(org.bukkit.block.Sign) PlayerSignBreak(org.cubeengine.module.log.action.block.player.destroy.PlayerSignBreak) Attachable(org.bukkit.material.Attachable) Location(org.spongepowered.api.world.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Block (org.bukkit.block.Block)3 EventHandler (org.bukkit.event.EventHandler)3 PlayerBlockBreak (org.cubeengine.module.log.action.block.player.destroy.PlayerBlockBreak)3 BlockState (org.bukkit.block.BlockState)2 NoteBlock (org.bukkit.block.NoteBlock)2 Sign (org.bukkit.block.Sign)2 ListenerBlock (org.cubeengine.module.log.action.block.ListenerBlock)2 BlockFace (org.bukkit.block.BlockFace)1 Jukebox (org.bukkit.block.Jukebox)1 InventoryHolder (org.bukkit.inventory.InventoryHolder)1 Attachable (org.bukkit.material.Attachable)1 BlockPreFallEvent (org.cubeengine.module.log.action.block.BlockPreFallEvent)1 ActionPlayerBlock (org.cubeengine.module.log.action.block.player.ActionPlayerBlock)1 PlayerJukeboxBreak (org.cubeengine.module.log.action.block.player.destroy.PlayerJukeboxBreak)1 PlayerNoteBlockBreak (org.cubeengine.module.log.action.block.player.destroy.PlayerNoteBlockBreak)1 PlayerSignBreak (org.cubeengine.module.log.action.block.player.destroy.PlayerSignBreak)1 Location (org.spongepowered.api.world.Location)1