use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class BaseSpell method finalizeCast.
protected boolean finalizeCast(ConfigurationSection parameters) {
SpellResult result = null;
// Global parameters
controller.disablePhysics(parameters.getInt("disable_physics", 0));
if (!mage.isSuperPowered()) {
if (backfireChance > 0 && random.nextDouble() < backfireChance) {
backfire();
} else if (fizzleChance > 0 && random.nextDouble() < fizzleChance) {
result = SpellResult.FIZZLE;
}
}
if (result == null) {
result = onCast(parameters);
}
if (backfired) {
result = SpellResult.BACKFIRE;
}
if (result == SpellResult.CAST) {
LivingEntity sourceEntity = mage.getLivingEntity();
Entity targetEntity = getTargetEntity();
if (sourceEntity == targetEntity) {
result = SpellResult.CAST_SELF;
}
}
processResult(result, parameters);
boolean success = result.isSuccess();
boolean free = result.isFree(castOnNoTarget);
if (!free) {
if (costs != null && !mage.isCostFree()) {
UndoList undoList = currentCast.getUndoList();
for (CastingCost cost : costs) {
if (undoList != null && cost.isItem() && currentCast != null) {
undoList.setConsumed(true);
}
cost.use(this);
}
}
updateCooldown();
}
if (success && toggle != ToggleType.NONE) {
activate();
}
sendCastMessage(result, " (" + success + ")");
return success;
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class BlockController method onBlockFromTo.
@EventHandler
public void onBlockFromTo(BlockFromToEvent event) {
Block targetBlock = event.getToBlock();
Block sourceBlock = event.getBlock();
UndoList undoList = controller.getPendingUndo(sourceBlock.getLocation());
if (undoList != null) {
undoList.add(targetBlock);
} else {
undoList = controller.getPendingUndo(targetBlock.getLocation());
if (undoList != null) {
undoList.add(targetBlock);
}
}
if (undoList != null && undoList.isScheduled()) {
// Avoid dropping broken items!
MaterialSet doubles = com.elmakers.mine.bukkit.block.UndoList.attachablesDouble;
if (doubles.testBlock(targetBlock)) {
Block upBlock = targetBlock.getRelative(BlockFace.UP);
while (doubles.testBlock(upBlock)) {
undoList.add(upBlock);
DeprecatedUtils.setTypeIdAndData(upBlock, Material.AIR.ordinal(), (byte) 0, false);
upBlock = upBlock.getRelative(BlockFace.UP);
}
Block downBlock = targetBlock.getRelative(BlockFace.DOWN);
while (doubles.testBlock(downBlock)) {
undoList.add(downBlock);
DeprecatedUtils.setTypeIdAndData(downBlock, Material.AIR.ordinal(), (byte) 0, false);
downBlock = downBlock.getRelative(BlockFace.DOWN);
}
}
DeprecatedUtils.setTypeIdAndData(targetBlock, Material.AIR.ordinal(), (byte) 0, false);
event.setCancelled(true);
}
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class BlockController method onPistonExtend.
@EventHandler
public void onPistonExtend(BlockPistonExtendEvent event) {
Block piston = event.getBlock();
Block block = piston.getRelative(event.getDirection());
UndoList undoList = controller.getPendingUndo(block.getLocation());
if (undoList != null) {
undoList.add(block);
undoList.add(piston);
}
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class BlockController method onEntityChangeBlockEvent.
@EventHandler
public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) {
Entity entity = event.getEntity();
if (entity instanceof FallingBlock) {
if (event.getTo() == Material.AIR) {
// Block is falling, register it
controller.registerFallingBlock(entity, event.getBlock());
} else {
// Block is landing, convert it
UndoList blockList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(entity);
if (blockList != null) {
com.elmakers.mine.bukkit.api.action.CastContext context = blockList.getContext();
if (context != null && !context.hasBuildPermission(entity.getLocation().getBlock())) {
event.setCancelled(true);
} else {
Block block = event.getBlock();
blockList.convert(entity, block);
if (!blockList.getApplyPhysics()) {
FallingBlock falling = (FallingBlock) entity;
DeprecatedUtils.setTypeIdAndData(block, DeprecatedUtils.getId(falling.getMaterial()), DeprecatedUtils.getBlockData(falling), false);
event.setCancelled(true);
}
}
}
}
}
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class EntityController method onEntityDamageByEntity.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity();
if (entity instanceof Projectile || entity instanceof TNTPrimed)
return;
Entity damager = event.getDamager();
/*
if (damager instanceof Projectile) {
Projectile projectile = (Projectile)damager;
ProjectileSource source = projectile.getShooter();
if (source instanceof LivingEntity) {
damager = (Entity)source;
}
}
if (entity instanceof Creature && damager instanceof LivingEntity) {
Creature creature = (Creature)entity;
creature.setTarget((LivingEntity)damager);
}
*/
UndoList undoList = controller.getEntityUndo(damager);
if (undoList != null) {
// Prevent dropping items from frames,
if (event.getCause() != EntityDamageEvent.DamageCause.ENTITY_ATTACK || undoList.isScheduled()) {
undoList.damage(entity);
if (!entity.isValid()) {
event.setCancelled(true);
}
} else {
undoList.modify(entity);
}
}
}
Aggregations