use of org.bukkit.block.BlockState in project Prism-Bukkit by prism.
the class PrismInventoryMoveItemEvent method onInventoryMoveItem.
/**
*
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryMoveItem(final InventoryMoveItemEvent event) {
// Hopper inserted
if (Prism.getIgnore().event("item-insert") && event.getDestination() != null) {
// Get container
final InventoryHolder ih = event.getDestination().getHolder();
Location containerLoc = null;
if (ih instanceof BlockState) {
final BlockState eventChest = (BlockState) ih;
containerLoc = eventChest.getLocation();
}
if (containerLoc == null)
return;
if (event.getSource().getType().equals(InventoryType.HOPPER)) {
RecordingQueue.addToQueue(ActionFactory.createItemStack("item-insert", event.getItem(), event.getItem().getAmount(), 0, null, containerLoc, "hopper"));
}
}
// Hopper removed
if (Prism.getIgnore().event("item-remove") && event.getSource() != null) {
// Get container
final InventoryHolder ih = event.getSource().getHolder();
Location containerLoc = null;
if (ih instanceof BlockState) {
final BlockState eventChest = (BlockState) ih;
containerLoc = eventChest.getLocation();
}
if (containerLoc == null)
return;
if (event.getDestination().getType().equals(InventoryType.HOPPER)) {
RecordingQueue.addToQueue(ActionFactory.createItemStack("item-remove", event.getItem(), event.getItem().getAmount(), 0, null, containerLoc, "hopper"));
}
}
}
use of org.bukkit.block.BlockState in project Prism-Bukkit by prism.
the class PrismMiscEvents method onPrismBlocksExtinguishEvent.
/**
*
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPrismBlocksExtinguishEvent(final PrismBlocksExtinguishEvent event) {
// Get all block changes for this event
final ArrayList<BlockStateChange> blockStateChanges = event.getBlockStateChanges();
if (!blockStateChanges.isEmpty()) {
// Create an entry for the rollback as a whole
final Handler primaryAction = ActionFactory.createPrismProcess("prism-process", PrismProcessType.EXTINGUISH, event.onBehalfOf(), "" + event.getRadius());
final int id = RecordingTask.insertActionIntoDatabase(primaryAction);
if (id == 0) {
return;
}
for (final BlockStateChange stateChange : blockStateChanges) {
final BlockState orig = stateChange.getOriginalBlock();
final BlockState newBlock = stateChange.getNewBlock();
// Build the action
RecordingQueue.addToQueue(ActionFactory.createPrismRollback("prism-extinguish", orig, newBlock, event.onBehalfOf().getName(), id));
}
// ActionQueue.save();
}
}
use of org.bukkit.block.BlockState in project Prism-Bukkit by prism.
the class PrismBlockEvents method onBlockForm.
/**
*
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockForm(final BlockFormEvent event) {
if (!Prism.getIgnore().event("block-form", event.getBlock()))
return;
final Block b = event.getBlock();
final BlockState s = event.getNewState();
RecordingQueue.addToQueue(ActionFactory.createBlockChange("block-form", b.getLocation(), b.getTypeId(), b.getData(), s.getTypeId(), s.getRawData(), "Environment"));
}
use of org.bukkit.block.BlockState in project Prism-Bukkit by prism.
the class PrismBlockEvents method onBlockFromTo.
/**
*
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockFromTo(final BlockFromToEvent event) {
// Ignore blocks that aren't liquid. @todo what else triggers this?
if (!event.getBlock().isLiquid())
return;
final BlockState from = event.getBlock().getState();
final BlockState to = event.getToBlock().getState();
// Watch for blocks that the liquid can break
if (me.botsko.elixr.BlockUtils.canFlowBreakMaterial(to.getType())) {
if (from.getType() == Material.STATIONARY_WATER || from.getType() == Material.WATER) {
if (Prism.getIgnore().event("water-break", event.getBlock())) {
RecordingQueue.addToQueue(ActionFactory.createBlock("water-break", event.getToBlock(), "Water"));
}
} else if (from.getType() == Material.STATIONARY_LAVA || from.getType() == Material.LAVA) {
if (Prism.getIgnore().event("lava-break", event.getBlock())) {
RecordingQueue.addToQueue(ActionFactory.createBlock("lava-break", event.getToBlock(), "Lava"));
}
}
}
// Record water flow
if (from.getType() == Material.STATIONARY_WATER || from.getType() == Material.WATER) {
if (Prism.getIgnore().event("water-flow", event.getBlock())) {
RecordingQueue.addToQueue(ActionFactory.createBlock("water-flow", event.getBlock(), "Water"));
}
}
// Record lava flow
if (from.getType() == Material.STATIONARY_LAVA || from.getType() == Material.LAVA) {
if (Prism.getIgnore().event("lava-flow", event.getBlock())) {
RecordingQueue.addToQueue(ActionFactory.createBlock("lava-flow", event.getBlock(), "Lava"));
}
}
/**
* Predict the forming of Stone, Obsidian, Cobblestone because of
* lava/water flowing into each other. Boy, I wish bukkit used
* block_form for this.
*/
if (!Prism.getIgnore().event("block-form", event.getBlock()))
return;
// Lava flows to water. STONE forms
if (from.getType().equals(Material.STATIONARY_LAVA) && to.getType().equals(Material.STATIONARY_WATER)) {
final Block newTo = event.getToBlock();
newTo.setType(Material.STONE);
RecordingQueue.addToQueue(ActionFactory.createBlock("block-form", newTo, "Environment"));
}
// // int id = event.getBlock().getTypeId();
//
// // If moving to air
// Block b = event.getToBlock();
// if(b.getType().equals(Material.AIR)){
//
// // formed sat/lava = cobble
// // formed stationary_water = stone
//
// // Are we moving from a water block
// Material fromM = event.getBlock().getType();
// if(fromM.equals(Material.WATER) ||
// fromM.equals(Material.STATIONARY_WATER)){
// // Check all sides
// for(BlockFace face : BlockFace.values()){
// Block r = b.getRelative(face, 1);
// // If the side is lava, cobble shall form.
// // Note: if stationary_lava, stone will form. Seems to always be
// captured above.
// if(r.getType().equals(Material.LAVA) ||
// r.getType().equals(Material.STATIONARY_LAVA)){
// String coordsKey = r.getX()+":"+r.getY()+":"+r.getZ();
// if(coordsUsed.contains(coordsKey)) continue;
// coordsUsed.add(coordsKey);
// Prism.debug("COBBLE FORMED " + r.getType().name());
// // r.setType(Material.COBBLESTONE);
// plugin.actionsRecorder.addToQueue( new
// BlockAction(ActionType.BLOCK_FORM, r, "Environment") );
// }
// }
// }
// }
//
//
// // Water flowing into lava forms obsidian or cobble
// if ( from.getType().equals(Material.STATIONARY_WATER) &&
// to.getType().equals(Material.STATIONARY_LAVA) ) {
// Prism.debug("FROM WATER to " + to.getType().name());
// BlockState lower =
// event.getToBlock().getRelative(BlockFace.DOWN).getState();
// // Obsidian can form below
// if( lower.getType().equals(Material.OBSIDIAN) ){
// String coordsKey = lower.getX()+":"+lower.getY()+":"+lower.getZ();
// if(coordsUsed.contains(coordsKey)) return;
// // Add coords to list the event has already fired for
// coordsUsed.add(coordsKey);
// Prism.debug("COBBLE/OBY FORMED BELOW " + coordsKey);
// plugin.actionsRecorder.addToQueue( new
// BlockAction(ActionType.BLOCK_FORM, lower.getBlock(), "Environment")
// );
// }
//
// }
}
use of org.bukkit.block.BlockState in project Prism-Bukkit by prism.
the class PrismBlockEvents method onBlockPlace.
/**
*
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(final BlockPlaceEvent event) {
final Player player = event.getPlayer();
final Block block = event.getBlock();
if (!Prism.getIgnore().event("block-place", player))
return;
if (block.getType().equals(Material.AIR))
return;
final BlockState s = event.getBlockReplacedState();
RecordingQueue.addToQueue(ActionFactory.createBlockChange("block-place", block.getLocation(), s.getTypeId(), s.getRawData(), block.getTypeId(), block.getData(), player.getName()));
// Pass to the placement alerter
if (!player.hasPermission("prism.alerts.use.place.ignore") && !player.hasPermission("prism.alerts.ignore")) {
plugin.useMonitor.alertOnBlockPlacement(player, block);
}
}
Aggregations