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;
}
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);
}
}
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;
}
Aggregations