use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class UndoAction method performNew.
protected SpellResult performNew(CastContext context) {
UndoList undoList = context.getUndoList();
int totalSize = undoList.size() + undoList.getRunnableCount();
if (totalSize == 0) {
return SpellResult.NO_ACTION;
}
boolean undid = false;
while (context.getWorkAllowed() > 0) {
if (undoToSize > 0 && totalSize <= undoToSize)
break;
if (undoList.size() == 0) {
if (undoList.undoNextRunnable() == null)
break;
} else {
if (undoList.undoNext(false) == null)
break;
}
undid = true;
undone++;
context.addWork(10);
if (undoOldest > 0 && undone > undoOldest) {
break;
}
}
if (!undid)
return SpellResult.NO_ACTION;
return undoOldest == 0 || undone >= undoOldest ? SpellResult.CAST : SpellResult.PENDING;
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class UndoAction method perform.
@Override
public SpellResult perform(CastContext context) {
// Start of new functionality
if (undoOldest > 0 || undoToSize > 0) {
return performNew(context);
}
// Old functionality- this should be converted into an action that processes
// blocks instead of creating a separate batch.
Entity targetEntity = context.getTargetEntity();
SpellResult result = SpellResult.CAST;
Mage mage = context.getMage();
if (targetSelf) {
targetEntity = context.getEntity();
context.setTargetName(mage.getName());
result = SpellResult.ALTERNATE_UP;
}
MageController controller = context.getController();
if (targetEntity != null && controller.isMage(targetEntity)) {
Mage targetMage = controller.getMage(targetEntity);
mage.sendDebugMessage(ChatColor.AQUA + "Undo checking last spell of " + ChatColor.GOLD + targetMage + ChatColor.AQUA + " with timeout of " + ChatColor.YELLOW + timeout + ChatColor.AQUA + " for target spellKey" + ChatColor.BLUE + targetSpellKey, 2);
Batch batch = targetMage.cancelPending(targetSpellKey);
if (batch != null) {
undoListName = batch.getName();
if (cancel) {
return SpellResult.DEACTIVATE;
}
}
UndoQueue queue = targetMage.getUndoQueue();
UndoList undoList = queue.undoRecent(timeout, targetSpellKey);
if (undoList != null) {
undoListName = undoList.getName();
}
return undoList != null ? result : SpellResult.NO_TARGET;
}
if (!targetBlocks) {
return SpellResult.NO_TARGET;
}
Block targetBlock = context.getTargetBlock();
if (targetDown) {
targetBlock = context.getLocation().getBlock();
}
if (targetBlock != null) {
boolean undoAny = targetOtherBlocks;
undoAny = undoAny || (adminPermission != null && context.getController().hasPermission(context.getMage().getCommandSender(), adminPermission));
undoAny = undoAny || mage.isSuperPowered();
if (undoAny) {
mage.sendDebugMessage(ChatColor.AQUA + "Looking for recent cast at " + ChatColor.GOLD + targetBlock + ChatColor.AQUA + " with timeout of " + ChatColor.YELLOW + blockTimeout, 2);
UndoList undid = controller.undoRecent(targetBlock, blockTimeout);
if (undid != null) {
Mage targetMage = undid.getOwner();
undoListName = undid.getName();
if (targetMage != null) {
context.setTargetName(targetMage.getName());
}
return result;
}
} else {
mage.sendDebugMessage(ChatColor.AQUA + "Looking for recent self-cast at " + ChatColor.GOLD + targetBlock, 2);
context.setTargetName(mage.getName());
UndoList undoList = mage.undo(targetBlock);
if (undoList != null) {
undoListName = undoList.getName();
return result;
}
}
}
return SpellResult.NO_TARGET;
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class BlockRecurse method recurse.
protected void recurse(Block block, ActionContext recurseAction, CastContext context, BlockFace nextFace, int rDepth) {
if (nextFace != null) {
block = block.getRelative(nextFace);
}
if (replaceable != null && !replaceable.contains(new MaterialAndData(block))) {
return;
}
UndoList undoList = context.getUndoList();
if (undoList != null) {
if (undoList.contains(block)) {
return;
}
undoList.add(block);
}
context.setTargetLocation(block.getLocation());
if (recurseAction.perform(context) != SpellResult.CAST) {
return;
}
if (rDepth < maxRecursion) {
for (BlockFace face : BlockData.FACES) {
if (nextFace == null || nextFace != BlockData.getReverseFace(face)) {
recurse(block, recurseAction, context, face, rDepth + 1);
}
}
}
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class ExplosionController method getExplosionUndo.
@Nullable
protected UndoList getExplosionUndo(Entity explodingEntity) {
UndoList blockList = controller.getEntityUndo(explodingEntity);
if (blockList == null && autoRollbackDuration > 0 && rollbackExplosions.contains(explodingEntity.getType())) {
Mage mage = controller.getMage(explodingEntity);
blockList = new com.elmakers.mine.bukkit.block.UndoList(mage, "Explosion (" + explodingEntity.getType().name() + ")");
blockList.setScheduleUndo(autoRollbackDuration);
blockList.setUndoSpeed(autoRollbackSpeed);
mage.prepareForUndo(blockList);
}
return blockList;
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class HangingController method onHangingBreakByEntity.
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onHangingBreakByEntity(HangingBreakByEntityEvent event) {
Entity breakingEntity = event.getRemover();
if (breakingEntity == null)
return;
Hanging entity = event.getEntity();
UndoList undoList = controller.getEntityUndo(breakingEntity);
if (undoList != null && undoList.isScheduled()) {
undoList.damage(entity);
// Prevent item drops, but still remove it
// Else it'll probably just break again.
event.setCancelled(true);
}
}
Aggregations