use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class BlockController method onBlockIgnite.
@EventHandler
public void onBlockIgnite(BlockIgniteEvent event) {
BlockIgniteEvent.IgniteCause cause = event.getCause();
if (cause == BlockIgniteEvent.IgniteCause.ENDER_CRYSTAL || cause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) {
return;
}
Entity entity = event.getIgnitingEntity();
UndoList entityList = controller.getEntityUndo(entity);
if (entityList != null) {
entityList.add(event.getBlock());
return;
}
Block ignitingBlock = event.getIgnitingBlock();
Block targetBlock = event.getBlock();
if (ignitingBlock != null) {
UndoList undoList = controller.getPendingUndo(ignitingBlock.getLocation());
if (undoList != null) {
undoList.add(event.getBlock());
return;
}
}
UndoList undoList = controller.getPendingUndo(targetBlock.getLocation());
if (undoList != null) {
undoList.add(targetBlock);
}
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class BlockController method onBlockBreak.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
Player player = event.getPlayer();
if (creativeBreakFrequency > 0 && player.getGameMode() == GameMode.CREATIVE) {
com.elmakers.mine.bukkit.magic.Mage mage = controller.getMage(event.getPlayer());
if (mage.checkLastClick(creativeBreakFrequency)) {
event.setCancelled(true);
return;
}
}
if (controller.areLocksProtected() && controller.isContainer(block) && !event.getPlayer().hasPermission("Magic.bypass")) {
String lockKey = CompatibilityUtils.getLock(block);
if (lockKey != null && !lockKey.isEmpty()) {
Inventory inventory = player.getInventory();
Mage mage = controller.getRegisteredMage(event.getPlayer());
if (mage != null) {
inventory = mage.getInventory();
}
if (!InventoryUtils.hasItem(inventory, lockKey)) {
String message = controller.getMessages().get("general.locked_chest");
if (mage != null) {
mage.sendMessage(message);
} else {
player.sendMessage(message);
}
event.setCancelled(true);
return;
}
}
}
com.elmakers.mine.bukkit.api.block.BlockData modifiedBlock = com.elmakers.mine.bukkit.block.UndoList.getBlockData(block.getLocation());
if (modifiedBlock != null) {
UndoList undoList = modifiedBlock.getUndoList();
if (undoList != null) {
if (!undoList.isConsumed()) {
event.setCancelled(true);
block.setType(Material.AIR);
}
com.elmakers.mine.bukkit.block.UndoList.commit(modifiedBlock);
}
}
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class BlockController method onBlockFade.
@EventHandler
public void onBlockFade(BlockFadeEvent event) {
Block block = event.getBlock();
UndoList undoList = controller.getPendingUndo(block.getLocation());
if (undoList != null) {
undoList.add(block);
}
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class BlockController method onBlockBurn.
@EventHandler
public void onBlockBurn(BlockBurnEvent event) {
Block targetBlock = event.getBlock();
UndoList undoList = controller.getPendingUndo(targetBlock.getLocation());
if (undoList == null) {
// 6) Fire B rolls back, leaving burning blocks that continue to spread.
for (BlockFace face : blockBurnDirections) {
Block sourceBlock = targetBlock.getRelative(face);
if (sourceBlock.getType() != Material.FIRE)
continue;
undoList = controller.getPendingUndo(sourceBlock.getLocation());
if (undoList != null) {
break;
}
}
}
if (undoList != null) {
undoList.add(targetBlock);
}
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class EntityController method onEntityCombust.
@EventHandler
public void onEntityCombust(EntityCombustEvent event) {
Entity entity = event.getEntity();
com.elmakers.mine.bukkit.magic.Mage mage = controller.getRegisteredMage(entity);
if (mage != null) {
mage.onCombust(event);
}
if (!event.isCancelled()) {
UndoList undoList = controller.getPendingUndo(entity.getLocation());
if (undoList != null) {
undoList.modify(entity);
}
}
}
Aggregations