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);
}
}
}
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);
}
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);
}
}
}
}
Aggregations