Search in sources :

Example 1 with UndoBatch

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;
}
Also used : SpellBatch(com.elmakers.mine.bukkit.api.batch.SpellBatch) Batch(com.elmakers.mine.bukkit.api.batch.Batch) UndoBatch(com.elmakers.mine.bukkit.batch.UndoBatch) SpellBatch(com.elmakers.mine.bukkit.api.batch.SpellBatch) UndoBatch(com.elmakers.mine.bukkit.batch.UndoBatch) ArrayList(java.util.ArrayList) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) ActionSpell(com.elmakers.mine.bukkit.spell.ActionSpell) Spell(com.elmakers.mine.bukkit.api.spell.Spell) BaseSpell(com.elmakers.mine.bukkit.spell.BaseSpell) Nullable(javax.annotation.Nullable)

Example 2 with UndoBatch

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;
}
Also used : Batch(com.elmakers.mine.bukkit.api.batch.Batch) UndoBatch(com.elmakers.mine.bukkit.batch.UndoBatch) SpellBatch(com.elmakers.mine.bukkit.api.batch.SpellBatch) UndoBatch(com.elmakers.mine.bukkit.batch.UndoBatch) ArrayList(java.util.ArrayList)

Example 3 with UndoBatch

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);
    }
}
Also used : CastContext(com.elmakers.mine.bukkit.api.action.CastContext) UndoBatch(com.elmakers.mine.bukkit.batch.UndoBatch)

Aggregations

UndoBatch (com.elmakers.mine.bukkit.batch.UndoBatch)3 Batch (com.elmakers.mine.bukkit.api.batch.Batch)2 SpellBatch (com.elmakers.mine.bukkit.api.batch.SpellBatch)2 ArrayList (java.util.ArrayList)2 CastContext (com.elmakers.mine.bukkit.api.action.CastContext)1 MageSpell (com.elmakers.mine.bukkit.api.spell.MageSpell)1 Spell (com.elmakers.mine.bukkit.api.spell.Spell)1 ActionSpell (com.elmakers.mine.bukkit.spell.ActionSpell)1 BaseSpell (com.elmakers.mine.bukkit.spell.BaseSpell)1 Nullable (javax.annotation.Nullable)1