Search in sources :

Example 1 with PlayerSignBreak

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

the class ActionBlock method setBlock.

protected boolean setBlock(BlockSection blockData, Location loc, LogAttachment attachment, boolean force, boolean preview, boolean rollback) {
    Block block = loc.getBlock();
    BlockState state = loc.getBlock().getState();
    state.setType(blockData.material);
    if (blockData.material == IRON_DOOR_BLOCK || blockData.material == WOODEN_DOOR) {
        // TODO correct?
        byte data = (byte) (blockData.data & ~8);
        state.setRawData(data);
    } else {
        state.setRawData(blockData.data);
    }
    if (!force && (// TODO correct?
    state.getData() instanceof Attachable || BlockUtil.isDetachableFromBelow(blockData.material))) {
        return false;
    }
    if (state.getData() instanceof Bed) {
        Bed bed = (Bed) state.getData();
        Block headBed = block.getRelative(bed.getFacing());
        BlockState headState = headBed.getState();
        headState.setType(AIR);
        if (preview) {
            attachment.addToPreview(headState);
        } else {
            headState.update(true, false);
        }
    } else if (state.getType() == WOOD_DOOR || state.getType() == IRON_DOOR_BLOCK) {
        Block topDoor = block.getRelative(UP);
        if (topDoor.getType() == state.getType()) {
            BlockState topState = topDoor.getState();
            topState.setType(AIR);
            if (preview) {
                attachment.addToPreview(topState);
            } else {
                topState.update(true, false);
            }
        }
    }
    if (preview) {
        attachment.addToPreview(state);
    } else {
        state.update(true, false);
    }
    if (rollback) {
        if (this instanceof SignBreak || this instanceof PlayerSignBreak) {
            String[] lines = this instanceof SignBreak ? ((SignBreak) this).oldLines : ((PlayerSignBreak) this).oldLines;
            if (preview) {
                attachment.addToPreview(state.getLocation(), lines);
            } else {
                Sign sign = (Sign) state.getBlock().getState();
                int i = 0;
                for (String line : lines) {
                    sign.setLine(i++, line);
                }
                sign.update();
            }
        } else if (blockData.is(BED_BLOCK)) {
            Bed bed = (Bed) state.getData();
            BlockState headBed = block.getRelative(bed.getFacing()).getState();
            headBed.setType(BED_BLOCK);
            Bed bedhead = (Bed) headBed.getData();
            bedhead.setHeadOfBed(true);
            bedhead.setFacingDirection(bed.getFacing());
            if (preview) {
                attachment.addToPreview(headBed);
            } else {
                headBed.update(true);
            }
        } else if (blockData.is(WOOD_DOOR, IRON_DOOR_BLOCK)) {
            byte data = (byte) (((blockData.data & 8) == 8) ? 9 : 8);
            BlockState topDoor = block.getRelative(UP).getState();
            topDoor.setType(state.getType());
            topDoor.setRawData(data);
            if (preview) {
                attachment.addToPreview(topDoor);
            } else {
                topDoor.update(true);
            }
        } else if (!preview) {
            if (this instanceof PlayerNoteBlockBreak) {
                NoteBlock noteblock = (NoteBlock) state.getBlock().getState();
                noteblock.setNote(((PlayerNoteBlockBreak) this).note);
                noteblock.update();
            } else if (this instanceof PlayerJukeboxBreak) {
                Jukebox jukebox = (Jukebox) state.getBlock().getState();
                jukebox.setPlaying(((PlayerJukeboxBreak) this).disc);
                jukebox.update();
            } else if (this instanceof PlayerContainerBreak) {
                InventoryHolder inventoryHolder = (InventoryHolder) state.getBlock().getState();
                inventoryHolder.getInventory().setContents(((PlayerContainerBreak) this).contents);
                ((BlockState) inventoryHolder).update();
            }
        }
    }
    return true;
}
Also used : Bed(org.bukkit.material.Bed) Jukebox(org.bukkit.block.Jukebox) PlayerSignBreak(org.cubeengine.module.log.action.block.player.destroy.PlayerSignBreak) NoteBlock(org.bukkit.block.NoteBlock) PlayerContainerBreak(org.cubeengine.module.log.action.block.player.destroy.PlayerContainerBreak) PlayerNoteBlockBreak(org.cubeengine.module.log.action.block.player.destroy.PlayerNoteBlockBreak) BlockState(org.bukkit.block.BlockState) PlayerJukeboxBreak(org.cubeengine.module.log.action.block.player.destroy.PlayerJukeboxBreak) Block(org.bukkit.block.Block) NoteBlock(org.bukkit.block.NoteBlock) Sign(org.bukkit.block.Sign) PlayerSignBreak(org.cubeengine.module.log.action.block.player.destroy.PlayerSignBreak) Attachable(org.bukkit.material.Attachable) InventoryHolder(org.bukkit.inventory.InventoryHolder)

Example 2 with PlayerSignBreak

use of org.cubeengine.module.log.action.block.player.destroy.PlayerSignBreak 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)2 BlockState (org.bukkit.block.BlockState)2 Sign (org.bukkit.block.Sign)2 Attachable (org.bukkit.material.Attachable)2 PlayerSignBreak (org.cubeengine.module.log.action.block.player.destroy.PlayerSignBreak)2 Jukebox (org.bukkit.block.Jukebox)1 NoteBlock (org.bukkit.block.NoteBlock)1 EventHandler (org.bukkit.event.EventHandler)1 InventoryHolder (org.bukkit.inventory.InventoryHolder)1 Bed (org.bukkit.material.Bed)1 ActionPlayerBlock (org.cubeengine.module.log.action.block.player.ActionPlayerBlock)1 PlayerBlockBreak (org.cubeengine.module.log.action.block.player.destroy.PlayerBlockBreak)1 PlayerContainerBreak (org.cubeengine.module.log.action.block.player.destroy.PlayerContainerBreak)1 PlayerJukeboxBreak (org.cubeengine.module.log.action.block.player.destroy.PlayerJukeboxBreak)1 PlayerNoteBlockBreak (org.cubeengine.module.log.action.block.player.destroy.PlayerNoteBlockBreak)1 Location (org.spongepowered.api.world.Location)1