Search in sources :

Example 1 with TrackingPhase

use of org.spongepowered.common.event.tracking.phase.TrackingPhase in project SpongeCommon by SpongePowered.

the class PhaseTracker method completePhase.

@SuppressWarnings({ "rawtypes", "unused", "try" })
public void completePhase(IPhaseState<?> prevState) {
    final PhaseData currentPhaseData = this.stack.peek();
    final IPhaseState<?> state = currentPhaseData.state;
    final boolean isEmpty = this.stack.isEmpty();
    if (isEmpty) {
        // The random occurrence that we're told to complete a phase
        // while a world is being changed unknowingly.
        this.printEmptyStackOnCompletion();
        return;
    }
    if (prevState != state) {
        this.printIncorrectPhaseCompletion(prevState, state);
        // The phase on the top of the stack was most likely never completed.
        // Since we don't know when and where completePhase was intended to be called for it,
        // we simply pop it to allow processing to continue (somewhat) as normal
        this.stack.pop();
    }
    if (SpongeImpl.getGlobalConfig().getConfig().getPhaseTracker().isVerbose() && this.stack.size() > 6 && state != GeneralPhase.Post.UNWINDING && !state.isExpectedForReEntrance()) {
        // This printing is to detect possibilities of a phase not being cleared properly
        // and resulting in a "runaway" phase state accumulation.
        this.printRunnawayPhaseCompletion(state);
    }
    this.stack.pop();
    // If pop is called, the Deque will already throw an exception if there is no element
    // so it's an error properly handled.
    final TrackingPhase phase = state.getPhase();
    final PhaseContext<?> context = currentPhaseData.context;
    try (final UnwindingPhaseContext unwinding = UnwindingPhaseContext.unwind(state, context)) {
        // a new list of capture lists
        try {
            // Yes this is a nested try, but in the event the current phase cannot be unwound, at least unwind UNWINDING
            ((IPhaseState) state).unwind(context);
        } catch (Exception e) {
            this.printMessageWithCaughtException("Exception Exiting Phase", "Something happened when trying to unwind", state, context, e);
        }
    } catch (Exception e) {
        this.printMessageWithCaughtException("Exception Post Dispatching Phase", "Something happened when trying to post dispatch state", state, context, e);
    }
}
Also used : TrackingPhase(org.spongepowered.common.event.tracking.phase.TrackingPhase) UnwindingPhaseContext(org.spongepowered.common.event.tracking.phase.general.UnwindingPhaseContext) ReportedException(net.minecraft.util.ReportedException)

Aggregations

ReportedException (net.minecraft.util.ReportedException)1 TrackingPhase (org.spongepowered.common.event.tracking.phase.TrackingPhase)1 UnwindingPhaseContext (org.spongepowered.common.event.tracking.phase.general.UnwindingPhaseContext)1