use of com.elmakers.mine.bukkit.batch.UndoBatch in project MagicPlugin by elBukkit.
the class Mage method cancelPending.
@Nullable
@Override
public Batch cancelPending(String spellKey, boolean force) {
Batch stoppedPending = null;
if (pendingBatches.size() > 0) {
List<Batch> batches = new ArrayList<>();
batches.addAll(pendingBatches);
for (Batch batch : batches) {
if (spellKey != null || !force) {
if (!(batch instanceof SpellBatch)) {
continue;
}
SpellBatch spellBatch = (SpellBatch) batch;
Spell spell = spellBatch.getSpell();
if (spell == null) {
continue;
}
if (!force && !spell.isCancellable()) {
continue;
}
if (spellKey != null && !spell.getSpellKey().getBaseKey().equalsIgnoreCase(spellKey)) {
continue;
}
}
if (!(batch instanceof UndoBatch)) {
if (batch instanceof SpellBatch) {
SpellBatch spellBatch = (SpellBatch) batch;
Spell spell = spellBatch.getSpell();
if (spell != null) {
spell.cancel();
}
}
batch.finish();
pendingBatches.remove(batch);
stoppedPending = batch;
}
}
}
return stoppedPending;
}
use of com.elmakers.mine.bukkit.batch.UndoBatch in project MagicPlugin by elBukkit.
the class Mage method finishPendingUndo.
@Override
public int finishPendingUndo() {
int finished = 0;
if (pendingBatches.size() > 0) {
List<Batch> batches = new ArrayList<>();
batches.addAll(pendingBatches);
for (Batch batch : batches) {
if (batch instanceof UndoBatch) {
while (!batch.isFinished()) {
batch.process(1000);
}
pendingBatches.remove(batch);
finished++;
}
}
}
return finished;
}
use of com.elmakers.mine.bukkit.batch.UndoBatch in project MagicPlugin by elBukkit.
the class UndoList method undo.
public void undo(boolean blocking, boolean undoEntities) {
if (undone)
return;
undone = true;
if (batch != null && !batch.isFinished()) {
batch.finish();
}
// This is a hack to make forced-undo happen instantly
if (undoEntities) {
this.speed = 0;
}
undoEntityEffects = undoEntityEffects || undoEntities;
unlink();
CastContext context = getContext();
if (context != null) {
context.cancelEffects();
}
if (runnables != null) {
for (Runnable runnable : runnables) {
runnable.run();
}
runnables = null;
}
if (blockList == null) {
undoEntityEffects();
return;
}
// Block changes will be performed in a batch
UndoBatch batch = new UndoBatch(this);
if (blocking) {
while (!batch.isFinished()) {
batch.process(1000);
}
} else {
owner.addUndoBatch(batch);
}
}
Aggregations