use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class Targeting method breakBlockRecursively.
protected int breakBlockRecursively(CastContext context, Block block, int depth) {
if (depth <= 0)
return 0;
if (!context.isBreakable(block))
return 0;
// Play break FX
Location blockLocation = block.getLocation();
Location effectLocation = blockLocation.add(0.5, 0.5, 0.5);
context.playEffects("break", 1, context.getLocation(), null, effectLocation, null);
// TODO: Re-examime this?
UndoList undoList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(blockLocation);
if (undoList != null) {
undoList.add(block);
}
context.clearBreakable(block);
context.clearReflective(block);
block.setType(Material.AIR);
int broken = 1;
if (depth > broken) {
broken += breakBlockRecursively(context, block.getRelative(BlockFace.UP), Math.min(targetBreakableDepth, depth - broken));
broken += breakBlockRecursively(context, block.getRelative(BlockFace.DOWN), Math.min(targetBreakableDepth, depth - broken));
broken += breakBlockRecursively(context, block.getRelative(BlockFace.EAST), Math.min(targetBreakableDepth, depth - broken));
broken += breakBlockRecursively(context, block.getRelative(BlockFace.WEST), Math.min(targetBreakableDepth, depth - broken));
broken += breakBlockRecursively(context, block.getRelative(BlockFace.NORTH), Math.min(targetBreakableDepth, depth - broken));
broken += breakBlockRecursively(context, block.getRelative(BlockFace.SOUTH), Math.min(targetBreakableDepth, depth - broken));
}
return broken;
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class MagicController method getEntityUndo.
@Nullable
public UndoList getEntityUndo(Entity entity) {
UndoList blockList = null;
if (entity == null)
return null;
Mage mage = getRegisteredMage(entity);
if (mage == null && entity instanceof Projectile) {
Projectile projectile = (Projectile) entity;
ProjectileSource source = projectile.getShooter();
if (source instanceof LivingEntity) {
entity = (LivingEntity) source;
mage = getRegisteredMage(entity);
}
}
if (mage != null) {
UndoList undoList = mage.getLastUndoList();
if (undoList != null) {
long now = System.currentTimeMillis();
if (undoList.getModifiedTime() > now - undoTimeWindow) {
blockList = undoList;
}
}
} else {
blockList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(entity);
}
return blockList;
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class MagicController method processUndo.
protected void processUndo() {
long now = System.currentTimeMillis();
while (scheduledUndo.size() > 0) {
UndoList undo = scheduledUndo.peek();
if (now < undo.getScheduledTime()) {
break;
}
scheduledUndo.poll();
undo.undoScheduled();
}
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class MagicController method undoScheduled.
public void undoScheduled() {
int undid = 0;
while (!scheduledUndo.isEmpty()) {
UndoList undoList = scheduledUndo.poll();
undoList.undoScheduled(true);
}
if (undid > 0) {
info("Undid " + undid + " pending spells");
}
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class ShrinkSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
String giveName = parameters.getString("name");
if (giveName != null) {
String itemName = giveName + "'s Head";
Player player = Bukkit.getPlayer(giveName);
if (player != null) {
dropPlayerHead(getLocation(), player, itemName);
} else {
dropPlayerHead(getLocation(), giveName, itemName);
}
return SpellResult.CAST;
}
Target target = getTarget();
if (target.hasEntity()) {
Entity targetEntity = target.getEntity();
if (controller.isElemental(targetEntity)) {
double elementalSize = controller.getElementalScale(targetEntity);
if (elementalSize < 0.1) {
int elementalDamage = parameters.getInt("elemental_damage", DEFAULT_ENTITY_DAMAGE);
controller.damageElemental(targetEntity, elementalDamage, 0, mage.getCommandSender());
} else {
elementalSize /= 2;
controller.setElementalScale(targetEntity, elementalSize);
}
return SpellResult.CAST;
}
if (!(targetEntity instanceof LivingEntity))
return SpellResult.NO_TARGET;
// Register for undo in advance to catch entity death.
registerForUndo();
int damage = parameters.getInt("entity_damage", DEFAULT_ENTITY_DAMAGE);
LivingEntity li = (LivingEntity) targetEntity;
boolean alreadyDead = li.isDead() || li.getHealth() <= 0;
String ownerName = null;
String itemName = null;
byte data = 3;
if (li instanceof Player) {
damage = parameters.getInt("player_damage", DEFAULT_PLAYER_DAMAGE);
ownerName = ((Player) li).getName();
} else {
itemName = li.getType().getName() + " Head";
switch(li.getType()) {
case CREEPER:
data = 4;
break;
case ZOMBIE:
data = 2;
break;
case SKELETON:
Skeleton skeleton = (Skeleton) li;
data = (byte) (skeleton.getSkeletonType() == SkeletonType.NORMAL ? 0 : 1);
break;
default:
ownerName = getMobSkin(li.getType());
}
}
if (itemName == null && ownerName != null) {
itemName = ownerName + "'s Head";
}
Location targetLocation = targetEntity.getLocation();
if (li instanceof Player) {
CompatibilityUtils.magicDamage(li, damage, mage.getEntity());
if (li.isDead() && !alreadyDead) {
dropPlayerHead(targetEntity.getLocation(), (Player) li, itemName);
}
} else if (li.getType() == EntityType.GIANT) {
UndoList spawnedList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(li);
registerModified(li);
li.remove();
Entity zombie = targetLocation.getWorld().spawnEntity(targetLocation, EntityType.ZOMBIE);
if (zombie instanceof Zombie) {
((Zombie) zombie).setBaby(false);
}
registerForUndo(zombie);
if (spawnedList != null) {
spawnedList.add(zombie);
}
} else if (li instanceof Ageable && ((Ageable) li).isAdult() && !(li instanceof Player)) {
registerModified(li);
((Ageable) li).setBaby();
} else if (li instanceof Zombie && !((Zombie) li).isBaby()) {
registerModified(li);
((Zombie) li).setBaby(true);
} else if (li instanceof PigZombie && !((PigZombie) li).isBaby()) {
registerModified(li);
((PigZombie) li).setBaby(true);
} else if (li instanceof Slime && ((Slime) li).getSize() > 1) {
registerModified(li);
Slime slime = (Slime) li;
slime.setSize(slime.getSize() - 1);
} else {
CompatibilityUtils.magicDamage(li, damage, mage.getEntity());
if ((ownerName != null || data != 3) && (li.isDead() || li.getHealth() == 0) && !alreadyDead) {
dropHead(targetEntity.getLocation(), ownerName, itemName, data);
}
}
} else {
Block targetBlock = target.getBlock();
if (targetBlock == null) {
return SpellResult.NO_TARGET;
}
String blockSkin = getBlockSkin(targetBlock.getType());
if (blockSkin == null)
return SpellResult.NO_TARGET;
if (!hasBreakPermission(targetBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
if (mage.isIndestructible(targetBlock)) {
return SpellResult.NO_TARGET;
}
registerForUndo(targetBlock);
registerForUndo();
dropHead(targetBlock.getLocation(), blockSkin, targetBlock.getType().name(), (byte) 3);
targetBlock.setType(Material.AIR);
}
return SpellResult.CAST;
}
Aggregations