Search in sources :

Example 1 with SpongeScoreCriterionProgress

use of org.spongepowered.common.advancement.criterion.SpongeScoreCriterionProgress in project SpongeCommon by SpongePowered.

the class AdvancementProgressMixin method impl$revokeCriterion.

private boolean impl$revokeCriterion(String rawCriterion) {
    final net.minecraft.advancements.CriterionProgress criterionProgress = this.criteria.get(rawCriterion);
    if (criterionProgress == null || !criterionProgress.isDone()) {
        return false;
    }
    if (SpongeScoreCriterion.BYPASS_EVENT) {
        criterionProgress.revoke();
        return true;
    }
    final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
    final ServerPlayer player = ((PlayerAdvancementsBridge) this.impl$playerAdvancements).bridge$getPlayer();
    final CriterionProgress progress = (CriterionProgress) criterionProgress;
    final AdvancementCriterion criterion = progress.criterion();
    final CriterionBridge criterionBridge = (CriterionBridge) criterion;
    // The score criterion needs special care
    final SpongeScoreCriterion scoreCriterion = criterionBridge.bridge$getScoreCriterion();
    final CriterionEvent event;
    final Advancement advancement = ((org.spongepowered.api.advancement.AdvancementProgress) this).advancement();
    if (scoreCriterion != null) {
        final SpongeScoreCriterionProgress scoreProgress = (SpongeScoreCriterionProgress) this.impl$progressMap.get(scoreCriterion.name());
        final int lastScore = scoreProgress.score();
        final int score = lastScore + 1;
        if (lastScore == scoreCriterion.goal()) {
            event = SpongeEventFactory.createCriterionEventScoreRevoke(cause, advancement, scoreCriterion, player, lastScore, score);
        } else if (score == scoreCriterion.goal()) {
            event = SpongeEventFactory.createCriterionEventScoreGrant(cause, advancement, scoreCriterion, player, Instant.now(), lastScore, score);
        } else {
            event = SpongeEventFactory.createCriterionEventScoreChange(cause, advancement, scoreCriterion, player, lastScore, score);
        }
    } else {
        event = SpongeEventFactory.createCriterionEventRevoke(cause, advancement, criterion, player);
    }
    if (SpongeCommon.post(event)) {
        return false;
    }
    criterionProgress.revoke();
    return true;
}
Also used : AdvancementProgress(net.minecraft.advancements.AdvancementProgress) CriterionEvent(org.spongepowered.api.event.advancement.CriterionEvent) PlayerAdvancementsBridge(org.spongepowered.common.bridge.server.PlayerAdvancementsBridge) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) SpongeScoreCriterion(org.spongepowered.common.advancement.criterion.SpongeScoreCriterion) SpongeScoreCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeScoreCriterionProgress) Cause(org.spongepowered.api.event.Cause) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) Advancement(org.spongepowered.api.advancement.Advancement) SpongeAndCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeAndCriterionProgress) SpongeOrCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeOrCriterionProgress) SpongeScoreCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeScoreCriterionProgress) ImplementationBackedCriterionProgress(org.spongepowered.common.advancement.criterion.ImplementationBackedCriterionProgress) CriterionProgress(org.spongepowered.api.advancement.criteria.CriterionProgress) CriterionBridge(org.spongepowered.common.bridge.advancements.CriterionBridge)

Example 2 with SpongeScoreCriterionProgress

use of org.spongepowered.common.advancement.criterion.SpongeScoreCriterionProgress in project SpongeCommon by SpongePowered.

the class AdvancementProgressMixin method impl$processProgressMap.

private void impl$processProgressMap(AdvancementCriterion criterion, Map<String, ImplementationBackedCriterionProgress> progressMap) {
    if (criterion instanceof OperatorCriterion) {
        ((OperatorCriterion) criterion).criteria().forEach(child -> this.impl$processProgressMap(child, progressMap));
        if (criterion instanceof AndCriterion) {
            progressMap.put(criterion.name(), new SpongeAndCriterionProgress((org.spongepowered.api.advancement.AdvancementProgress) this, (SpongeAndCriterion) criterion));
        } else if (criterion instanceof OrCriterion) {
            progressMap.put(criterion.name(), new SpongeOrCriterionProgress((org.spongepowered.api.advancement.AdvancementProgress) this, (SpongeOrCriterion) criterion));
        }
    } else if (criterion instanceof SpongeScoreCriterion) {
        final SpongeScoreCriterion scoreCriterion = (SpongeScoreCriterion) criterion;
        for (final AdvancementCriterion internalCriterion : scoreCriterion.internalCriteria) {
            final CriterionProgressBridge progress = (CriterionProgressBridge) this.criteria.get(internalCriterion.name());
            progress.bridge$setCriterion(internalCriterion);
            progress.bridge$setAdvancementProgress((org.spongepowered.api.advancement.AdvancementProgress) this);
            progressMap.put(internalCriterion.name(), (ImplementationBackedCriterionProgress) progress);
        }
        progressMap.put(scoreCriterion.name(), new SpongeScoreCriterionProgress((org.spongepowered.api.advancement.AdvancementProgress) this, scoreCriterion));
    } else if (!(criterion instanceof SpongeEmptyCriterion)) {
        final CriterionProgressBridge progress = (CriterionProgressBridge) this.criteria.get(criterion.name());
        progress.bridge$setCriterion(criterion);
        progress.bridge$setAdvancementProgress((org.spongepowered.api.advancement.AdvancementProgress) this);
        progressMap.put(criterion.name(), (ImplementationBackedCriterionProgress) progress);
    }
}
Also used : AdvancementProgress(net.minecraft.advancements.AdvancementProgress) SpongeOrCriterion(org.spongepowered.common.advancement.criterion.SpongeOrCriterion) OrCriterion(org.spongepowered.api.advancement.criteria.OrCriterion) SpongeAndCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeAndCriterionProgress) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) SpongeScoreCriterion(org.spongepowered.common.advancement.criterion.SpongeScoreCriterion) ImplementationBackedCriterionProgress(org.spongepowered.common.advancement.criterion.ImplementationBackedCriterionProgress) AndCriterion(org.spongepowered.api.advancement.criteria.AndCriterion) SpongeAndCriterion(org.spongepowered.common.advancement.criterion.SpongeAndCriterion) SpongeScoreCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeScoreCriterionProgress) SpongeAndCriterion(org.spongepowered.common.advancement.criterion.SpongeAndCriterion) SpongeEmptyCriterion(org.spongepowered.common.advancement.criterion.SpongeEmptyCriterion) CriterionProgressBridge(org.spongepowered.common.bridge.advancements.CriterionProgressBridge) OperatorCriterion(org.spongepowered.api.advancement.criteria.OperatorCriterion) SpongeOrCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeOrCriterionProgress)

Example 3 with SpongeScoreCriterionProgress

use of org.spongepowered.common.advancement.criterion.SpongeScoreCriterionProgress in project SpongeCommon by SpongePowered.

the class AdvancementProgressMixin method impl$grantCriterion.

private boolean impl$grantCriterion(String rawCriterion) {
    final net.minecraft.advancements.CriterionProgress criterionProgress = this.criteria.get(rawCriterion);
    if (criterionProgress == null || criterionProgress.isDone()) {
        return false;
    }
    if (SpongeScoreCriterion.BYPASS_EVENT) {
        criterionProgress.grant();
        return true;
    }
    final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
    final ServerPlayer player = ((PlayerAdvancementsBridge) this.impl$playerAdvancements).bridge$getPlayer();
    final CriterionProgress progress = (CriterionProgress) criterionProgress;
    final AdvancementCriterion criterion = progress.criterion();
    final CriterionBridge criterionBridge = (CriterionBridge) criterion;
    // The score criterion needs special care
    final SpongeScoreCriterion scoreCriterion = criterionBridge.bridge$getScoreCriterion();
    final CriterionEvent event;
    if (scoreCriterion != null) {
        final SpongeScoreCriterionProgress scoreProgress = (SpongeScoreCriterionProgress) this.impl$progressMap.get(scoreCriterion.name());
        final int lastScore = scoreProgress.score();
        final int score = lastScore + 1;
        if (lastScore == scoreCriterion.goal()) {
            event = SpongeEventFactory.createCriterionEventScoreRevoke(cause, this.bridge$getAdvancement(), scoreCriterion, player, lastScore, score);
        } else if (score == scoreCriterion.goal()) {
            event = SpongeEventFactory.createCriterionEventScoreGrant(cause, this.bridge$getAdvancement(), scoreCriterion, player, Instant.now(), lastScore, score);
        } else {
            event = SpongeEventFactory.createCriterionEventScoreChange(cause, this.bridge$getAdvancement(), scoreCriterion, player, lastScore, score);
        }
    } else {
        event = SpongeEventFactory.createCriterionEventGrant(cause, this.bridge$getAdvancement(), criterion, player, Instant.now());
    }
    if (SpongeCommon.post(event)) {
        return false;
    }
    criterionProgress.grant();
    return true;
}
Also used : CriterionEvent(org.spongepowered.api.event.advancement.CriterionEvent) PlayerAdvancementsBridge(org.spongepowered.common.bridge.server.PlayerAdvancementsBridge) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) SpongeScoreCriterion(org.spongepowered.common.advancement.criterion.SpongeScoreCriterion) SpongeScoreCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeScoreCriterionProgress) Cause(org.spongepowered.api.event.Cause) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) SpongeAndCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeAndCriterionProgress) SpongeOrCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeOrCriterionProgress) SpongeScoreCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeScoreCriterionProgress) ImplementationBackedCriterionProgress(org.spongepowered.common.advancement.criterion.ImplementationBackedCriterionProgress) CriterionProgress(org.spongepowered.api.advancement.criteria.CriterionProgress) CriterionBridge(org.spongepowered.common.bridge.advancements.CriterionBridge)

Aggregations

AdvancementCriterion (org.spongepowered.api.advancement.criteria.AdvancementCriterion)3 ImplementationBackedCriterionProgress (org.spongepowered.common.advancement.criterion.ImplementationBackedCriterionProgress)3 SpongeAndCriterionProgress (org.spongepowered.common.advancement.criterion.SpongeAndCriterionProgress)3 SpongeOrCriterionProgress (org.spongepowered.common.advancement.criterion.SpongeOrCriterionProgress)3 SpongeScoreCriterion (org.spongepowered.common.advancement.criterion.SpongeScoreCriterion)3 SpongeScoreCriterionProgress (org.spongepowered.common.advancement.criterion.SpongeScoreCriterionProgress)3 AdvancementProgress (net.minecraft.advancements.AdvancementProgress)2 CriterionProgress (org.spongepowered.api.advancement.criteria.CriterionProgress)2 ServerPlayer (org.spongepowered.api.entity.living.player.server.ServerPlayer)2 Cause (org.spongepowered.api.event.Cause)2 CriterionEvent (org.spongepowered.api.event.advancement.CriterionEvent)2 CriterionBridge (org.spongepowered.common.bridge.advancements.CriterionBridge)2 PlayerAdvancementsBridge (org.spongepowered.common.bridge.server.PlayerAdvancementsBridge)2 Advancement (org.spongepowered.api.advancement.Advancement)1 AndCriterion (org.spongepowered.api.advancement.criteria.AndCriterion)1 OperatorCriterion (org.spongepowered.api.advancement.criteria.OperatorCriterion)1 OrCriterion (org.spongepowered.api.advancement.criteria.OrCriterion)1 SpongeAndCriterion (org.spongepowered.common.advancement.criterion.SpongeAndCriterion)1 SpongeEmptyCriterion (org.spongepowered.common.advancement.criterion.SpongeEmptyCriterion)1 SpongeOrCriterion (org.spongepowered.common.advancement.criterion.SpongeOrCriterion)1