Search in sources :

Example 1 with ActionPlayerBlock

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

the class ListenerBlock method onBlockFall.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockFall(final BlockPhysicsEvent event) {
    if (!this.isActive(BlockFall.class, event.getBlock().getWorld())) {
        return;
    }
    BlockState state = event.getBlock().getState();
    if (state.getType().hasGravity() || state.getType() == DRAGON_EGG) {
        if (event.getBlock().getRelative(DOWN).getType() == AIR) {
            Location loc = state.getLocation();
            BlockFall action = this.set(BlockFall.class, state, null);
            ActionBlock cause = this.plannedFall.remove(loc);
            if (cause instanceof ActionPlayerBlock) {
                action.cause = this.reference((ActionPlayerBlock) cause);
            }
            action.setNewBlock(AIR);
            this.logAction(action);
            Block onTop = state.getBlock().getRelative(UP);
            if (onTop.getType().hasGravity() || onTop.getType() == DRAGON_EGG) {
                this.preplanBlockFall(new BlockPreFallEvent(onTop.getLocation(), cause));
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) ActionPlayerBlock(org.cubeengine.module.log.action.block.player.ActionPlayerBlock) Block(org.bukkit.block.Block) ActionPlayerBlock(org.cubeengine.module.log.action.block.player.ActionPlayerBlock) Location(org.spongepowered.api.world.Location) EventHandler(org.bukkit.event.EventHandler)

Example 2 with ActionPlayerBlock

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

the class ListenerHanging method onHangingBreak.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHangingBreak(HangingBreakEvent event) {
    if (event.getCause() == HangingBreakEvent.RemoveCause.PHYSICS) {
        Hanging hanging = event.getEntity();
        Location location = hanging.getLocation();
        BaseAction cause = this.plannedHangingBreak.get(location);
        if (cause != null) {
            if (cause instanceof ActionPlayerBlock) {
                HangingBreak action;
                if (hanging instanceof ItemFrame) {
                    action = this.newAction(ItemframeBreak.class, location.getWorld());
                    ItemStack item = ((ItemFrame) hanging).getItem();
                    if (action != null && item != null) {
                        ((ItemframeBreak) action).item = item;
                    }
                } else if (hanging instanceof Painting) {
                    action = this.newAction(PaintingBreak.class, location.getWorld());
                    ((PaintingBreak) action).art = ((Painting) hanging).getArt();
                } else {
                    action = this.newAction(HangingBreak.class, location.getWorld());
                }
                if (action != null) {
                    action.setLocation(location);
                    action.setHanging(hanging);
                    action.player = ((ActionPlayerBlock) cause).player;
                    action.setCause(cause);
                    this.logAction(action);
                }
            }
        // else // TODO
        }
    // else TODO this.module.getLog().info("Unexpected HangingBreakEvent");
    }
}
Also used : ActionPlayerBlock(org.cubeengine.module.log.action.block.player.ActionPlayerBlock) Hanging(org.bukkit.entity.Hanging) BaseAction(org.cubeengine.module.log.action.BaseAction) ItemFrame(org.bukkit.entity.ItemFrame) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Location(org.spongepowered.api.world.Location) Painting(org.bukkit.entity.Painting) EventHandler(org.bukkit.event.EventHandler)

Example 3 with ActionPlayerBlock

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

the class ListenerBucket method setAndLog.

private void setAndLog(Class<? extends ActionPlayerBlock> clazz, Player player, BlockState oldState, Material newMat) {
    ActionPlayerBlock action = this.newAction(clazz, player.getWorld());
    if (action != null) {
        action.setPlayer(player);
        action.setLocation(oldState.getLocation());
        action.setOldBlock(oldState);
        action.setNewBlock(newMat);
        this.logAction(action);
    }
}
Also used : ActionPlayerBlock(org.cubeengine.module.log.action.block.player.ActionPlayerBlock)

Example 4 with ActionPlayerBlock

use of org.cubeengine.module.log.action.block.player.ActionPlayerBlock 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)

Example 5 with ActionPlayerBlock

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

the class ListenerPlayerBlockInteract method onPlayerInteract.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) {
    // TODO put item into itemframe
    if (event.getAction() == RIGHT_CLICK_BLOCK) {
        ItemStack itemInHand = event.getPlayer().getItemInHand();
        Location location = event.getClickedBlock().getLocation();
        BlockState state = event.getClickedBlock().getState();
        ActionPlayerBlock action;
        BlockState newState = state.getBlock().getState();
        if (state instanceof InventoryHolder) {
            action = this.newAction(UseContainer.class, state.getWorld());
        } else if (state.getData() instanceof Openable) {
            action = this.newAction(UseDoor.class, state.getWorld());
            if (action != null) {
                state = adjustBlockForDoubleBlocks(state);
                Openable openable = (Openable) state.getBlock().getState().getData();
                openable.setOpen(!openable.isOpen());
                newState.setData((MaterialData) openable);
            }
        } else if (state.getData() instanceof Lever) {
            action = this.newAction(UseLever.class, state.getWorld());
            if (action != null) {
                Lever leverData = (Lever) state.getBlock().getState().getData();
                leverData.setPowered(!leverData.isPowered());
                newState.setData(leverData);
            }
        } else if (state.getType() == REDSTONE_COMPARATOR_ON || state.getType() == REDSTONE_COMPARATOR_OFF) {
            action = this.newAction(UseComparator.class, state.getWorld());
            if (action != null) {
                newState.setType(state.getType() == REDSTONE_COMPARATOR_ON ? REDSTONE_COMPARATOR_OFF : REDSTONE_COMPARATOR_ON);
            }
        } else if (state.getData() instanceof Button) {
            action = this.newAction(UseButton.class, state.getWorld());
            if (action != null) {
                Button button = (Button) state.getBlock().getState().getData();
                button.setPowered(true);
                newState.setData(button);
            }
        } else if (state.getData() instanceof Rails) {
            if (itemInHand.getType() == MINECART || itemInHand.getType() == STORAGE_MINECART || itemInHand.getType() == POWERED_MINECART || itemInHand.getType() == HOPPER_MINECART || // BOAT is done down below
            itemInHand.getType() == EXPLOSIVE_MINECART) {
                VehiclePrePlaceEvent vEvent = new VehiclePrePlaceEvent(event.getClickedBlock().getRelative(UP).getLocation(), event.getPlayer());
                this.module.getCore().getEventManager().fireEvent(vEvent);
            }
            action = null;
        } else if (itemInHand.getType().equals(BOAT)) {
            VehiclePrePlaceEvent vEvent = new VehiclePrePlaceEvent(event.getClickedBlock().getRelative(UP).getLocation(), event.getPlayer());
            this.module.getCore().getEventManager().fireEvent(vEvent);
            action = null;
        } else if (state.getData() instanceof Cake) {
            action = null;
            if (event.getPlayer().getFoodLevel() < 20 && !(event.getPlayer().getGameMode() == CREATIVE)) {
                action = this.newAction(UseCake.class, state.getWorld());
                if (action != null) {
                    Cake cake = (Cake) state.getBlock().getState().getData();
                    cake.setSlicesEaten(cake.getSlicesEaten() + 1);
                    if (cake.getSlicesRemaining() == 0) {
                        action.setNewBlock(AIR);
                        newState = null;
                    } else {
                        newState.setData(cake);
                    }
                }
            }
        } else if (state instanceof NoteBlock) {
            action = this.newAction(UseNoteblock.class, state.getWorld());
            if (action != null) {
                try {
                    ((NoteBlock) newState).setNote(((NoteBlock) newState).getNote().sharped());
                } catch (IllegalArgumentException e) {
                    ((NoteBlock) newState).setNote(new Note(1, Tone.F, true));
                }
            }
        } else if (state.getData() instanceof Diode) {
            action = this.newAction(UseRepeater.class, state.getWorld());
            if (action != null) {
                Diode diode = (Diode) state.getBlock().getState().getData();
                Integer delay = diode.getDelay() + 1;
                if (delay == 5) {
                    delay = 1;
                }
                diode.setDelay(delay);
                newState.setData(diode);
            }
        } else if (state.getType() == TNT) {
            action = null;
            if (itemInHand.getType() == FLINT_AND_STEEL) {
                action = this.newAction(UseTnt.class, state.getWorld());
                if (action != null) {
                    action.setNewBlock(AIR);
                    newState = null;
                }
            }
        } else if (state.getData() instanceof Crops || state.getType() == GRASS) {
            if (itemInHand.getData() instanceof Dye && ((Dye) itemInHand.getData()).getColor() == WHITE) {
                // TODO THIS IS BULLSHIT I need an event for bonemealUse...
                action = this.newAction(UseBonemeal.class, state.getWorld());
                if (action != null) {
                    // TODO adjust growth stage
                    // TODO do not log if fully grown
                    action.setNewBlock(state);
                    action.setLocation(state.getLocation());
                    action.setOldBlock(state);
                    action.setPlayer(event.getPlayer());
                    this.logAction(action);
                }
            }
            return;
        } else if (state instanceof Jukebox) {
            // TODO
            action = null;
        } else {
            action = null;
        }
        if (action != null) {
            action.setLocation(state.getLocation());
            action.setOldBlock(state);
            if (newState != null) {
                action.setNewBlock(newState);
            }
            action.setPlayer(event.getPlayer());
            this.logAction(action);
        }
    } else if (event.getAction() == PHYSICAL) {
        Block block = event.getClickedBlock();
        if (block.getType() == SOIL) {
            BlockTrample action = this.newAction(BlockTrample.class, block.getWorld());
            if (action != null) {
                BlockState stateUp = block.getRelative(UP).getState();
                if (stateUp.getData() instanceof Crops) {
                    BlockTrample actionUp = this.newAction(BlockTrample.class, block.getWorld());
                    actionUp.setLocation(stateUp.getLocation());
                    actionUp.setOldBlock(stateUp);
                    actionUp.setNewBlock(AIR);
                    actionUp.setPlayer(event.getPlayer());
                    this.logAction(actionUp);
                }
                action.setLocation(block.getLocation());
                action.setOldBlock(block.getState());
                action.setNewBlock(DIRT);
                action.setPlayer(event.getPlayer());
                this.logAction(action);
            }
        } else if (block.getState().getData() instanceof PressurePlate) {
            UsePlate action = this.newAction(UsePlate.class, block.getWorld());
            if (action != null) {
                // BlockState newState = block.getState();
                // PressurePlate plate = (PressurePlate)newState.getData();
                action.setLocation(block.getLocation());
                action.setOldBlock(block.getState());
                action.setNewBlock(block.getState());
                action.setPlayer(event.getPlayer());
                this.logAction(action);
            }
        }
    }
}
Also used : Diode(org.bukkit.material.Diode) Cake(org.bukkit.material.Cake) Openable(org.bukkit.material.Openable) Dye(org.bukkit.material.Dye) Button(org.bukkit.material.Button) PressurePlate(org.bukkit.material.PressurePlate) InventoryHolder(org.bukkit.inventory.InventoryHolder) Jukebox(org.bukkit.block.Jukebox) ActionPlayerBlock(org.cubeengine.module.log.action.block.player.ActionPlayerBlock) NoteBlock(org.bukkit.block.NoteBlock) Crops(org.bukkit.material.Crops) Rails(org.bukkit.material.Rails) BlockState(org.bukkit.block.BlockState) Lever(org.bukkit.material.Lever) Note(org.bukkit.Note) VehiclePrePlaceEvent(org.cubeengine.module.log.action.vehicle.VehiclePrePlaceEvent) Block(org.bukkit.block.Block) NoteBlock(org.bukkit.block.NoteBlock) ActionPlayerBlock(org.cubeengine.module.log.action.block.player.ActionPlayerBlock) MaterialData(org.bukkit.material.MaterialData) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Location(org.spongepowered.api.world.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ActionPlayerBlock (org.cubeengine.module.log.action.block.player.ActionPlayerBlock)5 EventHandler (org.bukkit.event.EventHandler)4 Location (org.spongepowered.api.world.Location)4 Block (org.bukkit.block.Block)3 BlockState (org.bukkit.block.BlockState)3 ItemStack (org.spongepowered.api.item.inventory.ItemStack)2 Note (org.bukkit.Note)1 Jukebox (org.bukkit.block.Jukebox)1 NoteBlock (org.bukkit.block.NoteBlock)1 Sign (org.bukkit.block.Sign)1 Hanging (org.bukkit.entity.Hanging)1 ItemFrame (org.bukkit.entity.ItemFrame)1 Painting (org.bukkit.entity.Painting)1 InventoryHolder (org.bukkit.inventory.InventoryHolder)1 Attachable (org.bukkit.material.Attachable)1 Button (org.bukkit.material.Button)1 Cake (org.bukkit.material.Cake)1 Crops (org.bukkit.material.Crops)1 Diode (org.bukkit.material.Diode)1 Dye (org.bukkit.material.Dye)1